![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/targets/TARGET_NUVOTON/TARGET_M2351/flash_api.c@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2017-2018 Nuvoton |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | */ |
kadonotakashi | 0:8fdf9a60065b | 16 | |
kadonotakashi | 0:8fdf9a60065b | 17 | #include "flash_api.h" |
kadonotakashi | 0:8fdf9a60065b | 18 | |
kadonotakashi | 0:8fdf9a60065b | 19 | #if DEVICE_FLASH |
kadonotakashi | 0:8fdf9a60065b | 20 | |
kadonotakashi | 0:8fdf9a60065b | 21 | #include <string.h> |
kadonotakashi | 0:8fdf9a60065b | 22 | #include "flash_data.h" |
kadonotakashi | 0:8fdf9a60065b | 23 | #include "mbed_critical.h" |
kadonotakashi | 0:8fdf9a60065b | 24 | #include "partition_M2351.h" |
kadonotakashi | 0:8fdf9a60065b | 25 | |
kadonotakashi | 0:8fdf9a60065b | 26 | #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) |
kadonotakashi | 0:8fdf9a60065b | 27 | |
kadonotakashi | 0:8fdf9a60065b | 28 | #ifndef MBED_ROM_START |
kadonotakashi | 0:8fdf9a60065b | 29 | #define MBED_ROM_START 0x0 |
kadonotakashi | 0:8fdf9a60065b | 30 | #endif |
kadonotakashi | 0:8fdf9a60065b | 31 | |
kadonotakashi | 0:8fdf9a60065b | 32 | #ifndef MBED_ROM_SIZE |
kadonotakashi | 0:8fdf9a60065b | 33 | #define MBED_ROM_SIZE 0x40000 |
kadonotakashi | 0:8fdf9a60065b | 34 | #endif |
kadonotakashi | 0:8fdf9a60065b | 35 | |
kadonotakashi | 0:8fdf9a60065b | 36 | #define NU_SECURE_FLASH_START MBED_ROM_START |
kadonotakashi | 0:8fdf9a60065b | 37 | #define NU_SECURE_FLASH_SIZE MBED_ROM_SIZE |
kadonotakashi | 0:8fdf9a60065b | 38 | |
kadonotakashi | 0:8fdf9a60065b | 39 | // This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM |
kadonotakashi | 0:8fdf9a60065b | 40 | // NOTE: On ARMv7-M/ARMv8-M, instruction fetches are always little-endian. |
kadonotakashi | 0:8fdf9a60065b | 41 | static uint32_t FLASH_ALGO[] = { |
kadonotakashi | 0:8fdf9a60065b | 42 | 0x460ab085, 0x90034603, 0x7001a802, 0x93009201, 0xf24ce7ff, 0xf2c400c0, 0x68000000, 0x42082101, |
kadonotakashi | 0:8fdf9a60065b | 43 | 0xe7ffd001, 0xf24ce7f5, 0xf2c40000, 0x68010000, 0x43112240, 0xf24c6001, 0xf2c4000c, 0x21220000, |
kadonotakashi | 0:8fdf9a60065b | 44 | 0x98036001, 0x0104f24c, 0x0100f2c4, 0xa8026008, 0x28007800, 0xe7ffd108, 0x43c02000, 0x0108f24c, |
kadonotakashi | 0:8fdf9a60065b | 45 | 0x0100f2c4, 0xe0096008, 0x0008f24c, 0x0000f2c4, 0x2103f64a, 0x0155f2c0, 0xe7ff6001, 0x0010f24c, |
kadonotakashi | 0:8fdf9a60065b | 46 | 0x0000f2c4, 0x60012101, 0x8f6ff3bf, 0xf24ce7ff, 0xf2c400c0, 0x68000000, 0x42082101, 0xe7ffd001, |
kadonotakashi | 0:8fdf9a60065b | 47 | 0xf24ce7f5, 0xf2c40000, 0x68000000, 0x42082140, 0xe7ffd00b, 0x0000f24c, 0x0000f2c4, 0x22406801, |
kadonotakashi | 0:8fdf9a60065b | 48 | 0x60014311, 0x90042001, 0x2000e002, 0xe7ff9004, 0xb0059804, 0xb5b04770, 0x4613b087, 0x4605460c, |
kadonotakashi | 0:8fdf9a60065b | 49 | 0x91049005, 0xf2409203, 0xf2c41000, 0x21590000, 0x21166001, 0x21886001, 0x68006001, 0x42082101, |
kadonotakashi | 0:8fdf9a60065b | 50 | 0x94019302, 0xd1039500, 0x2001e7ff, 0xe0389006, 0x2000f240, 0x0000f2c4, 0x22046801, 0x60014311, |
kadonotakashi | 0:8fdf9a60065b | 51 | 0x2004f240, 0x0000f2c4, 0x43116801, 0xe7ff6001, 0x2050f240, 0x0000f2c4, 0x21106800, 0xd1014208, |
kadonotakashi | 0:8fdf9a60065b | 52 | 0xe7f5e7ff, 0x0000f24c, 0x0000f2c4, 0x22016801, 0x60014311, 0x011cf24c, 0x0100f2c4, 0x6800600a, |
kadonotakashi | 0:8fdf9a60065b | 53 | 0xd1034210, 0x2001e7ff, 0xe00a9006, 0x0000f24c, 0x0000f2c4, 0x22406801, 0x60014311, 0x90062000, |
kadonotakashi | 0:8fdf9a60065b | 54 | 0x9806e7ff, 0xbdb0b007, 0x4601b082, 0x91009001, 0xf24ce7ff, 0xf2c400c0, 0x68000000, 0x42082101, |
kadonotakashi | 0:8fdf9a60065b | 55 | 0xe7ffd001, 0xf24ce7f5, 0xf2c40000, 0x68010000, 0x43912201, 0xf24c6001, 0xf2c4001c, 0x21000000, |
kadonotakashi | 0:8fdf9a60065b | 56 | 0x46086001, 0x4770b002, 0xe7ffb081, 0x00c0f24c, 0x0000f2c4, 0x21016800, 0xd0014208, 0xe7f5e7ff, |
kadonotakashi | 0:8fdf9a60065b | 57 | 0x0000f24c, 0x0000f2c4, 0x22406801, 0x60014311, 0x000cf24c, 0x0000f2c4, 0x60012126, 0x0004f24c, |
kadonotakashi | 0:8fdf9a60065b | 58 | 0x0000f2c4, 0x60012100, 0xf24c43c8, 0xf2c40108, 0x60080100, 0x0010f24c, 0x0000f2c4, 0x60012101, |
kadonotakashi | 0:8fdf9a60065b | 59 | 0x8f6ff3bf, 0xf24ce7ff, 0xf2c400c0, 0x68000000, 0x42082101, 0xe7ffd001, 0xf24ce7f5, 0xf2c40000, |
kadonotakashi | 0:8fdf9a60065b | 60 | 0x68000000, 0x42082140, 0xe7ffd00b, 0x0000f24c, 0x0000f2c4, 0x22406801, 0x60014311, 0x90002001, |
kadonotakashi | 0:8fdf9a60065b | 61 | 0x2000e002, 0xe7ff9000, 0xb0019800, 0xb5804770, 0x4601b084, 0x98029002, 0x72fff64f, 0x72fff6ce, |
kadonotakashi | 0:8fdf9a60065b | 62 | 0x90024010, 0xf64f9802, 0xf6cf0200, 0x401072ff, 0x98029002, 0x0512220f, 0x22014010, 0x42900552, |
kadonotakashi | 0:8fdf9a60065b | 63 | 0xd10b9101, 0x9802e7ff, 0x0100f240, 0x71e0f6cf, 0x21011840, 0xfea4f7ff, 0xe0059003, 0x21009802, |
kadonotakashi | 0:8fdf9a60065b | 64 | 0xfe9ef7ff, 0xe7ff9003, 0xb0049803, 0xb580bd80, 0x460ab086, 0x90044603, 0x20009103, 0x92019002, |
kadonotakashi | 0:8fdf9a60065b | 65 | 0xe7ff9300, 0x99039802, 0xd20f4288, 0x9804e7ff, 0x1c4a9902, 0x00899202, 0xf7ff5840, 0x2800ffb8, |
kadonotakashi | 0:8fdf9a60065b | 66 | 0xe7ffd003, 0x90052001, 0xe7ebe003, 0x90052000, 0x9805e7ff, 0xbd80b006, 0xb088b5b0, 0x460c4613, |
kadonotakashi | 0:8fdf9a60065b | 67 | 0x90064605, 0x92049105, 0x1cc09805, 0x43882103, 0x98069005, 0x71fff64f, 0x71fff6ce, 0x90064008, |
kadonotakashi | 0:8fdf9a60065b | 68 | 0x94029303, 0xe7ff9501, 0x00c0f24c, 0x0000f2c4, 0x21016800, 0xd0014208, 0xe7f5e7ff, 0x0000f24c, |
kadonotakashi | 0:8fdf9a60065b | 69 | 0x0000f2c4, 0x22406801, 0x60014311, 0x000cf24c, 0x0000f2c4, 0x60012121, 0x9805e7ff, 0xd03f2800, |
kadonotakashi | 0:8fdf9a60065b | 70 | 0x9806e7ff, 0x0104f24c, 0x0100f2c4, 0x98046008, 0xf83cf000, 0x0108f24c, 0x0100f2c4, 0xf24c6008, |
kadonotakashi | 0:8fdf9a60065b | 71 | 0xf2c40010, 0x21010000, 0xf3bf6001, 0xe7ff8f6f, 0x00c0f24c, 0x0000f2c4, 0x21016800, 0xd0014208, |
kadonotakashi | 0:8fdf9a60065b | 72 | 0xe7f5e7ff, 0x0000f24c, 0x0000f2c4, 0x21406800, 0xd00b4208, 0xf24ce7ff, 0xf2c40000, 0x68010000, |
kadonotakashi | 0:8fdf9a60065b | 73 | 0x43112240, 0x20016001, 0xe00c9007, 0x1d009806, 0x98049006, 0x90041d00, 0x1f009805, 0xe7bc9005, |
kadonotakashi | 0:8fdf9a60065b | 74 | 0x90072000, 0x9807e7ff, 0xbdb0b008, 0x4601b083, 0x98029002, 0x92021c42, 0x90017800, 0x1c429802, |
kadonotakashi | 0:8fdf9a60065b | 75 | 0x78009202, 0x9a010200, 0x90011810, 0x1c429802, 0x78009202, 0x9a010400, 0x90011810, 0x1c429802, |
kadonotakashi | 0:8fdf9a60065b | 76 | 0x78009202, 0x9a010600, 0x90011810, 0x91009801, 0x4770b003, 0xb088b5b0, 0x460c4613, 0x90064605, |
kadonotakashi | 0:8fdf9a60065b | 77 | 0x92049105, 0x1cc09805, 0x43882103, 0x93039005, 0x95019402, 0xf24ce7ff, 0xf2c400c0, 0x68000000, |
kadonotakashi | 0:8fdf9a60065b | 78 | 0x42082101, 0xe7ffd001, 0xf24ce7f5, 0xf2c40000, 0x68010000, 0x43112240, 0xf24c6001, 0xf2c4000c, |
kadonotakashi | 0:8fdf9a60065b | 79 | 0x21000000, 0xe7ff6001, 0x28009805, 0xe7ffd053, 0xf64f9806, 0xf6ce71ff, 0x400871ff, 0x0104f24c, |
kadonotakashi | 0:8fdf9a60065b | 80 | 0x0100f2c4, 0xf24c6008, 0xf2c40008, 0x21000000, 0xf24c6001, 0xf2c40010, 0x21010000, 0xf3bf6001, |
kadonotakashi | 0:8fdf9a60065b | 81 | 0xe7ff8f6f, 0x00c0f24c, 0x0000f2c4, 0x21016800, 0xd0014208, 0xe7f5e7ff, 0x0000f24c, 0x0000f2c4, |
kadonotakashi | 0:8fdf9a60065b | 82 | 0x21406800, 0xd00b4208, 0xf24ce7ff, 0xf2c40000, 0x68010000, 0x43112240, 0x98066001, 0xe01d9007, |
kadonotakashi | 0:8fdf9a60065b | 83 | 0x0008f24c, 0x0000f2c4, 0x99046800, 0x46089000, 0xff6cf7ff, 0x42819900, 0xe7ffd003, 0x90079806, |
kadonotakashi | 0:8fdf9a60065b | 84 | 0x9806e00c, 0x90061d00, 0x1d009804, 0x98059004, 0x90051f00, 0x9806e7a8, 0xe7ff9007, 0xb0089807, |
kadonotakashi | 0:8fdf9a60065b | 85 | 0x0000bdb0, 0x00000000, |
kadonotakashi | 0:8fdf9a60065b | 86 | }; |
kadonotakashi | 0:8fdf9a60065b | 87 | |
kadonotakashi | 0:8fdf9a60065b | 88 | static const flash_algo_t flash_algo_config = { |
kadonotakashi | 0:8fdf9a60065b | 89 | .init = 0x000000d7, |
kadonotakashi | 0:8fdf9a60065b | 90 | .uninit = 0x00000189, |
kadonotakashi | 0:8fdf9a60065b | 91 | .erase_sector = 0x0000026f, |
kadonotakashi | 0:8fdf9a60065b | 92 | .program_page = 0x00000319, |
kadonotakashi | 0:8fdf9a60065b | 93 | .static_base = 0x00000564, |
kadonotakashi | 0:8fdf9a60065b | 94 | .algo_blob = FLASH_ALGO |
kadonotakashi | 0:8fdf9a60065b | 95 | }; |
kadonotakashi | 0:8fdf9a60065b | 96 | |
kadonotakashi | 0:8fdf9a60065b | 97 | /* Secure flash */ |
kadonotakashi | 0:8fdf9a60065b | 98 | static const sector_info_t sectors_info[] = { |
kadonotakashi | 0:8fdf9a60065b | 99 | {NU_SECURE_FLASH_START, 0x800}, // (start, sector size) |
kadonotakashi | 0:8fdf9a60065b | 100 | }; |
kadonotakashi | 0:8fdf9a60065b | 101 | |
kadonotakashi | 0:8fdf9a60065b | 102 | /* Secure flash */ |
kadonotakashi | 0:8fdf9a60065b | 103 | static const flash_target_config_t flash_target_config = { |
kadonotakashi | 0:8fdf9a60065b | 104 | .page_size = 4, // 4 bytes |
kadonotakashi | 0:8fdf9a60065b | 105 | // Here page_size is program unit, which is different |
kadonotakashi | 0:8fdf9a60065b | 106 | // than FMC definition. |
kadonotakashi | 0:8fdf9a60065b | 107 | .flash_start = NU_SECURE_FLASH_START, |
kadonotakashi | 0:8fdf9a60065b | 108 | .flash_size = NU_SECURE_FLASH_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 109 | .sectors = sectors_info, |
kadonotakashi | 0:8fdf9a60065b | 110 | .sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t) |
kadonotakashi | 0:8fdf9a60065b | 111 | }; |
kadonotakashi | 0:8fdf9a60065b | 112 | |
kadonotakashi | 0:8fdf9a60065b | 113 | /* Non-secure flash */ |
kadonotakashi | 0:8fdf9a60065b | 114 | static const sector_info_t sectors_info_ns[] = { |
kadonotakashi | 0:8fdf9a60065b | 115 | {(NS_OFFSET + NU_SECURE_FLASH_SIZE), 0x800}, // (start, sector size) |
kadonotakashi | 0:8fdf9a60065b | 116 | }; |
kadonotakashi | 0:8fdf9a60065b | 117 | |
kadonotakashi | 0:8fdf9a60065b | 118 | /* Non-secure flash */ |
kadonotakashi | 0:8fdf9a60065b | 119 | static const flash_target_config_t flash_target_config_ns = { |
kadonotakashi | 0:8fdf9a60065b | 120 | .page_size = 4, // 4 bytes |
kadonotakashi | 0:8fdf9a60065b | 121 | // Here page_size is program unit, which is different |
kadonotakashi | 0:8fdf9a60065b | 122 | // than FMC definition. |
kadonotakashi | 0:8fdf9a60065b | 123 | .flash_start = NS_OFFSET + NU_SECURE_FLASH_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 124 | .flash_size = 0x80000 - NU_SECURE_FLASH_SIZE, |
kadonotakashi | 0:8fdf9a60065b | 125 | .sectors = sectors_info_ns, |
kadonotakashi | 0:8fdf9a60065b | 126 | .sector_info_count = sizeof(sectors_info_ns) / sizeof(sector_info_t) |
kadonotakashi | 0:8fdf9a60065b | 127 | }; |
kadonotakashi | 0:8fdf9a60065b | 128 | |
kadonotakashi | 0:8fdf9a60065b | 129 | void flash_set_target_config(flash_t *obj) |
kadonotakashi | 0:8fdf9a60065b | 130 | { |
kadonotakashi | 0:8fdf9a60065b | 131 | obj->flash_algo = &flash_algo_config; |
kadonotakashi | 0:8fdf9a60065b | 132 | obj->target_config = &flash_target_config; |
kadonotakashi | 0:8fdf9a60065b | 133 | obj->target_config_ns = &flash_target_config_ns; |
kadonotakashi | 0:8fdf9a60065b | 134 | } |
kadonotakashi | 0:8fdf9a60065b | 135 | |
kadonotakashi | 0:8fdf9a60065b | 136 | #endif // #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) |
kadonotakashi | 0:8fdf9a60065b | 137 | #endif // #if DEVICE_FLASH |