Skip to content

Commit d554f6e

Browse files
ccli8cyliangtw
authored andcommitted
[NUC472/M453] Support flash
1 parent 75f6f2d commit d554f6e

File tree

3 files changed

+171
-4
lines changed

3 files changed

+171
-4
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2015-2016 Nuvoton
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "flash_api.h"
18+
#include "flash_data.h"
19+
#include "mbed_critical.h"
20+
21+
// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
22+
// NOTE: On ARMv7-M/ARMv8-M, instruction fetches are always little-endian.
23+
static uint32_t FLASH_ALGO[] = {
24+
// FIXME
25+
0x4603b530, 0x2164460c, 0x4dd72059, 0x20166028, 0xf8c5070d, 0x20880100, 0x0100f8c5, 0xf8d006c0,
26+
0xf0000100, 0xb9080001, 0xbd302001, 0x680048cf, 0x0004f040, 0x4580f04f, 0x0200f8c5, 0xf8d04628,
27+
0xf0400204, 0xf8c50004, 0xbf000204, 0xf1a11e08, 0xd1fb0101, 0x680048c6, 0x002df040, 0x60284dc4,
28+
0x68004628, 0x0001f000, 0x2001b908, 0x48c0e7dd, 0xf0406800, 0x4dbe0040, 0x20006028, 0x4601e7d5,
29+
0x48bbbf00, 0xf0006900, 0x28000001, 0x48b8d1f9, 0xf0206800, 0x4ab6002d, 0x20006010, 0x60104ab2,
30+
0x46014770, 0x48b2bf00, 0xf0006900, 0x28000001, 0x48afd1f9, 0xf0406800, 0x4aad0040, 0x20226010,
31+
0xf02160d0, 0x60500003, 0x61102001, 0x8f60f3bf, 0x48a7bf00, 0xf0006900, 0x28000001, 0x48a4d1f9,
32+
0xf0006800, 0xb1380040, 0x680048a1, 0x0040f040, 0x60104a9f, 0x47702001, 0xe7fc2000, 0x4604b570,
33+
0x4615460b, 0x46292200, 0x000ff103, 0x030ff020, 0x4897bf00, 0xf0006900, 0x28000001, 0x4894d1f9,
34+
0xf0406800, 0x4e920040, 0xf0246030, 0x6070000f, 0x60f02027, 0x1c524610, 0x0020f851, 0x36804e8c,
35+
0x46106030, 0xf8511c52, 0x4e890020, 0x0084f8c6, 0x1c524610, 0x0020f851, 0x36884e85, 0x46106030,
36+
0xf8511c52, 0x1d360020, 0x20016030, 0x61304e80, 0xe02c3b10, 0x487ebf00, 0x680030c0, 0x0030f000,
37+
0xd1f82800, 0x1c524610, 0x0020f851, 0x36804e78, 0x46106030, 0xf8511c52, 0x4e750020, 0x0084f8c6,
38+
0x4873bf00, 0x680030c0, 0x00c0f000, 0xd1f82800, 0x1c524610, 0x0020f851, 0x36884e6d, 0x46106030,
39+
0xf8511c52, 0x4e6a0020, 0x008cf8c6, 0x2b003b10, 0xbf00d1d0, 0x69004866, 0x0001f000, 0xd1f92800,
40+
0xb510bd70, 0x1cc84603, 0x0103f020, 0x4860bf00, 0xf0006900, 0x28000001, 0x485dd1f9, 0xf0406800,
41+
0x4c5b0040, 0x20216020, 0xe02060e0, 0x0003f023, 0x60604c57, 0x60a06810, 0x61202001, 0x8f60f3bf,
42+
0x4853bf00, 0xf0006900, 0x28000001, 0x4850d1f9, 0xf0006800, 0xb1380040, 0x6800484d, 0x0040f040,
43+
0x60204c4b, 0xbd102001, 0x1d121d1b, 0x29001f09, 0x2000d1dc, 0xe92de7f7, 0x460547f0, 0x4616460c,
44+
0x0800f04f, 0xbf0046c2, 0x69004841, 0x0001f000, 0xd1f92800, 0x6800483e, 0x0040f040, 0x6008493c,
45+
0xf0201ce0, 0xe02d0403, 0xb958b2e8, 0xd9092cff, 0x7780f44f, 0x0208eb06, 0x46284639, 0xff2ef7ff,
46+
0xe0164682, 0x0008f3c5, 0x2c10b958, 0xf024d309, 0xeb06070f, 0x46390208, 0xf7ff4628, 0x4682ff1f,
47+
0x4627e007, 0x0208eb06, 0x46284639, 0xff89f7ff, 0x443d4682, 0x1be444b8, 0x0f00f1ba, 0x2001d002,
48+
0x87f0e8bd, 0xd1cf2c00, 0xe7f92000, 0x1ccbb510, 0x0103f023, 0x4b1ebf00, 0xf003691b, 0x2b000301,
49+
0x4b1bd1f9, 0xf043681b, 0x4c190340, 0x23006023, 0xe02560e3, 0x0303f020, 0x60634c15, 0x60a32300,
50+
0x61232301, 0x8f60f3bf, 0x4b11bf00, 0xf003691b, 0x2b000301, 0x4b0ed1f9, 0xf003681b, 0xb1330340,
51+
0x681b4b0b, 0x0340f043, 0x60234c09, 0x4b08bd10, 0x6814689b, 0xd00042a3, 0x1d00e7f8, 0x1f091d12,
52+
0xd1d72900, 0xe7f1bf00, 0x40000100, 0x40000200, 0x4000c000, 0x00000000,
53+
};
54+
55+
static const flash_algo_t flash_algo_config = {
56+
// FIXME
57+
.init = 0x00000001,
58+
.uninit = 0x0000007f,
59+
.erase_sector = 0x000000a3,
60+
.program_page = 0x00000257,
61+
.static_base = 0x00000374,
62+
.algo_blob = FLASH_ALGO
63+
};
64+
65+
static const sector_info_t sectors_info[] = {
66+
{0x0, 0x800}, // (start, sector size)
67+
};
68+
69+
static const flash_target_config_t flash_target_config = {
70+
// FIXME
71+
.page_size = 0x800, // 2 KB
72+
.flash_start = 0x0,
73+
.flash_size = 0x40000, // 256 KB
74+
.sectors = sectors_info,
75+
.sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t)
76+
};
77+
78+
void flash_set_target_config(flash_t *obj)
79+
{
80+
obj->flash_algo = &flash_algo_config;
81+
obj->target_config = &flash_target_config;
82+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2015-2016 Nuvoton
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "flash_api.h"
18+
#include "flash_data.h"
19+
#include "mbed_critical.h"
20+
21+
// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
22+
// NOTE: On ARMv7-M/ARMv8-M, instruction fetches are always little-endian.
23+
static uint32_t FLASH_ALGO[] = {
24+
// FIXME
25+
0x4603b530, 0x2164460c, 0x4dec2059, 0x20166028, 0xf8c5070d, 0x20880100, 0x0100f8c5, 0xf8d006c0,
26+
0xf0000100, 0xb9080001, 0xbd302001, 0x680048e4, 0x0004f040, 0x4580f04f, 0x0200f8c5, 0xf8d04628,
27+
0xf0400204, 0xf8c50004, 0xbf000204, 0xf1a11e08, 0xd1fb0101, 0x680048db, 0x0021f040, 0x60284dd9,
28+
0x69c04628, 0x0001f040, 0x462861e8, 0xf0006800, 0xb9080001, 0xe7d82001, 0x30fff04f, 0x64684dd1,
29+
0x6c404628, 0xb1081c40, 0xe7ce2001, 0x680048cd, 0x0040f040, 0x60284dcb, 0xe7c62000, 0xbf004601,
30+
0x690048c8, 0x0001f000, 0xd1f92800, 0x680048c5, 0x0021f020, 0x60104ac3, 0x69c04610, 0x0001f020,
31+
0x200061d0, 0x60104abd, 0x46014770, 0x48bdbf00, 0xf0006900, 0x28000001, 0x48bad1f9, 0xf0406800,
32+
0x4ab80040, 0x20226010, 0xf02160d0, 0x60500003, 0x61102001, 0x8f60f3bf, 0x48b2bf00, 0xf0006900,
33+
0x28000001, 0x48afd1f9, 0xf0006800, 0xb1380040, 0x680048ac, 0x0040f040, 0x60104aaa, 0x47702001,
34+
0xe7fc2000, 0x4603b570, 0x2500460c, 0x4629e009, 0xf8531c6d, 0xf7ff0021, 0x1e06ffc8, 0x4630d001,
35+
0x42a5bd70, 0x2000d3f3, 0xb570e7fa, 0x460b4604, 0x22004615, 0xf1034629, 0xf020000f, 0xbf00030f,
36+
0x69004898, 0x0001f000, 0xd1f92800, 0x68004895, 0x0040f040, 0x60304e93, 0x000ff024, 0x20276070,
37+
0x461060f0, 0xf8511c52, 0x4e8e0020, 0x60303680, 0x1c524610, 0x0020f851, 0xf8c64e8a, 0x46100084,
38+
0xf8511c52, 0x4e870020, 0x60303688, 0x1c524610, 0x0020f851, 0x60301d36, 0x4e822001, 0x3b106130,
39+
0xbf00e02c, 0x30c0487f, 0xf0006800, 0x28000030, 0x4610d1f8, 0xf8511c52, 0x4e7a0020, 0x60303680,
40+
0x1c524610, 0x0020f851, 0xf8c64e76, 0xbf000084, 0x30c04874, 0xf0006800, 0x280000c0, 0x4610d1f8,
41+
0xf8511c52, 0x4e6f0020, 0x60303688, 0x1c524610, 0x0020f851, 0xf8c64e6b, 0x3b10008c, 0xd1d02b00,
42+
0x4868bf00, 0xf0006900, 0x28000001, 0xbd70d1f9, 0x4603b510, 0xf0201cc8, 0xbf000103, 0x69004861,
43+
0x0001f000, 0xd1f92800, 0x6800485e, 0x0040f040, 0x60204c5c, 0x60e02021, 0xf023e020, 0x4c590003,
44+
0x68106060, 0x200160a0, 0xf3bf6120, 0xbf008f60, 0x69004854, 0x0001f000, 0xd1f92800, 0x68004851,
45+
0x0040f000, 0x484fb138, 0xf0406800, 0x4c4d0040, 0x20016020, 0x1d1bbd10, 0x1f091d12, 0xd1dc2900,
46+
0xe7f72000, 0x47f0e92d, 0x460c4605, 0xf04f4616, 0x46c20800, 0x4843bf00, 0xf0006900, 0x28000001,
47+
0x4840d1f9, 0xf0406800, 0x493e0040, 0x1ce06008, 0x0403f020, 0xf3c5e02f, 0xb9600008, 0x7f00f5b4,
48+
0xf44fd309, 0xeb067700, 0x46390208, 0xf7ff4628, 0x4682ff2c, 0xf3c5e016, 0xb9580008, 0xd3092c10,
49+
0x070ff024, 0x0208eb06, 0x46284639, 0xff1df7ff, 0xe0074682, 0xeb064627, 0x46390208, 0xf7ff4628,
50+
0x4682ff87, 0x44b8443d, 0xf1ba1be4, 0xd0020f00, 0xe8bd2001, 0x2c0087f0, 0x2000d1cd, 0xb510e7f9,
51+
0xf0231ccb, 0xbf000103, 0x691b4b1e, 0x0301f003, 0xd1f92b00, 0x681b4b1b, 0x0340f043, 0x60234c19,
52+
0x60e32300, 0xf020e025, 0x4c160303, 0x23006063, 0x230160a3, 0xf3bf6123, 0xbf008f60, 0x691b4b11,
53+
0x0301f003, 0xd1f92b00, 0x681b4b0e, 0x0340f003, 0x4b0cb133, 0xf043681b, 0x4c0a0340, 0xbd106023,
54+
0x689b4b08, 0x42a36814, 0xe7f8d000, 0x1d121d00, 0x29001f09, 0xbf00d1d7, 0x0000e7f1, 0x40000100,
55+
0x40000200, 0x4000c000, 0x00000000,
56+
};
57+
58+
static const flash_algo_t flash_algo_config = {
59+
// FIXME
60+
.init = 0x00000001,
61+
.uninit = 0x0000009d,
62+
.erase_sector = 0x000000cb,
63+
.program_page = 0x000002a5,
64+
.static_base = 0x000003c8,
65+
.algo_blob = FLASH_ALGO
66+
};
67+
68+
static const sector_info_t sectors_info[] = {
69+
{0x0, 0x800}, // (start, sector size)
70+
};
71+
72+
static const flash_target_config_t flash_target_config = {
73+
// FIXME
74+
.page_size = 0x800, // 2 KB
75+
.flash_start = 0x0,
76+
.flash_size = 0x80000, // 512 KB
77+
.sectors = sectors_info,
78+
.sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t)
79+
};
80+
81+
void flash_set_target_config(flash_t *obj)
82+
{
83+
obj->flash_algo = &flash_algo_config;
84+
obj->target_config = &flash_target_config;
85+
}

targets/targets.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,11 +2568,11 @@
25682568
"NUMAKER_PFM_NUC472": {
25692569
"core": "Cortex-M4F",
25702570
"default_toolchain": "ARM",
2571-
"extra_labels": ["NUVOTON", "NUC472", "NU_XRAM_SUPPORTED"],
2571+
"extra_labels": ["NUVOTON", "NUC472", "NU_XRAM_SUPPORTED", "FLASH_CMSIS_ALGO"],
25722572
"is_disk_virtual": true,
25732573
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
25742574
"inherits": ["Target"],
2575-
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "TRNG", "CAN"],
2575+
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "TRNG", "CAN", "FLASH"],
25762576
"features": ["LWIP"],
25772577
"release_versions": ["5"],
25782578
"device_name": "NUC472HI8AE"
@@ -2616,12 +2616,12 @@
26162616
"NUMAKER_PFM_M453": {
26172617
"core": "Cortex-M4F",
26182618
"default_toolchain": "ARM",
2619-
"extra_labels": ["NUVOTON", "M451", "NUMAKER_PFM_M453"],
2619+
"extra_labels": ["NUVOTON", "M451", "NUMAKER_PFM_M453", "FLASH_CMSIS_ALGO"],
26202620
"is_disk_virtual": true,
26212621
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
26222622
"inherits": ["Target"],
26232623
"progen": {"target": "numaker-pfm-m453"},
2624-
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "CAN"],
2624+
"device_has": ["ANALOGIN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "STDIO_MESSAGES", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "CAN", "FLASH"],
26252625
"release_versions": ["2", "5"],
26262626
"device_name": "M453VG6AE"
26272627
},

0 commit comments

Comments
 (0)