Skip to content

[NUC472/M453] Support Bootloader and FlashIAP #4008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#! armcc -E

LR_IROM1 0x00000000 {
ER_IROM1 0x00000000 { ; load address = execution address
#if !defined(MBED_APP_START)
#define MBED_APP_START 0x00000000
#endif

#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x00040000
#endif

LR_IROM1 MBED_APP_START {
ER_IROM1 MBED_APP_START { ; load address = execution address
*(RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
Expand All @@ -23,6 +32,6 @@ LR_IROM1 0x00000000 {
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (0x20000000 + 0x8000 - AlignExpr(ImageLimit(RW_IRAM1), 16)) {
}
}
ScatterAssert(LoadLimit(LR_IROM1) <= 0x00040000) ; 256 KB APROM
ScatterAssert(LoadLimit(LR_IROM1) <= (MBED_APP_START + MBED_APP_SIZE)) ; 256 KB APROM
ScatterAssert(ImageLimit(ARM_LIB_HEAP) <= 0x20008000) ; 32 KB SRAM

Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#! armcc -E

LR_IROM1 0x00000000 {
ER_IROM1 0x00000000 { ; load address = execution address
#if !defined(MBED_APP_START)
#define MBED_APP_START 0x00000000
#endif

#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x00040000
#endif

LR_IROM1 MBED_APP_START {
ER_IROM1 MBED_APP_START { ; load address = execution address
*(RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
Expand All @@ -23,6 +32,6 @@ LR_IROM1 0x00000000 {
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (0x20000000 + 0x8000 - AlignExpr(ImageLimit(RW_IRAM1), 16)) {
}
}
ScatterAssert(LoadLimit(LR_IROM1) <= 0x00040000) ; 256 KB APROM
ScatterAssert(LoadLimit(LR_IROM1) <= (MBED_APP_START + MBED_APP_SIZE)) ; 256 KB APROM
ScatterAssert(ImageLimit(ARM_LIB_HEAP) <= 0x20008000) ; 32 KB SRAM

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
* Nuvoton M453 GCC linker script file
*/

#if !defined(MBED_APP_START)
#define MBED_APP_START 0x00000000
#endif

#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x00040000
#endif

StackSize = 0x800;

MEMORY
{
VECTORS (rx) : ORIGIN = 0x00000000, LENGTH = 0x00000400
FLASH (rx) : ORIGIN = 0x00000400, LENGTH = 0x00040000 - 0x00000400
VECTORS (rx) : ORIGIN = MBED_APP_START, LENGTH = 0x00000400
FLASH (rx) : ORIGIN = MBED_APP_START + 0x400, LENGTH = MBED_APP_SIZE - 0x00000400
RAM_INTERN (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 - 0x00000000
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x00000000; }
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0x00040000; }
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
define symbol __ICFEDIT_intvec_start__ = MBED_APP_START;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x00040000;
define symbol __ICFEDIT_region_ROM_start__ = MBED_APP_START;
define symbol __ICFEDIT_region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
define symbol __ICFEDIT_region_IRAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_IRAM_end__ = 0x20008000;
/*-Sizes-*/
Expand Down
14 changes: 12 additions & 2 deletions targets/TARGET_NUVOTON/TARGET_M451/device/cmsis_nvic.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@
# define NVIC_RAM_VECTOR_ADDRESS ((uint32_t) &__start_vector_table__)
#endif


#define NVIC_FLASH_VECTOR_ADDRESS 0
#if defined(__CC_ARM)
extern uint32_t Load$$LR$$LR_IROM1$$Base[];
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t)Load$$LR$$LR_IROM1$$Base)
#elif defined(__ICCARM__)
#pragma section=".intvec"
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t)__section_begin(".intvec"))
#elif defined(__GNUC__)
extern uint32_t __vector_table;
#define NVIC_FLASH_VECTOR_ADDRESS ((uint32_t)&__vector_table)
#else
#error "Flash vector address not set for this toolchain"
#endif

#ifdef __cplusplus
extern "C" {
Expand Down
79 changes: 79 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_M451/flash_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "flash_api.h"
#include "flash_data.h"
#include "mbed_critical.h"

// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
// NOTE: On ARMv7-M/ARMv8-M, instruction fetches are always little-endian.
static uint32_t FLASH_ALGO[] = {
0x4603b530, 0x2164460c, 0x4dd72059, 0x20166028, 0xf8c5070d, 0x20880100, 0x0100f8c5, 0xf8d006c0,
0xf0000100, 0xb9080001, 0xbd302001, 0x680048cf, 0x0004f040, 0x4580f04f, 0x0200f8c5, 0xf8d04628,
0xf0400204, 0xf8c50004, 0xbf000204, 0xf1a11e08, 0xd1fb0101, 0x680048c6, 0x002df040, 0x60284dc4,
0x68004628, 0x0001f000, 0x2001b908, 0x48c0e7dd, 0xf0406800, 0x4dbe0040, 0x20006028, 0x4601e7d5,
0x48bbbf00, 0xf0006900, 0x28000001, 0x48b8d1f9, 0xf0206800, 0x4ab6002d, 0x20006010, 0x60104ab2,
0x46014770, 0x48b2bf00, 0xf0006900, 0x28000001, 0x48afd1f9, 0xf0406800, 0x4aad0040, 0x20226010,
0xf02160d0, 0x60500003, 0x61102001, 0x8f60f3bf, 0x48a7bf00, 0xf0006900, 0x28000001, 0x48a4d1f9,
0xf0006800, 0xb1380040, 0x680048a1, 0x0040f040, 0x60104a9f, 0x47702001, 0xe7fc2000, 0x4604b570,
0x4615460b, 0x46292200, 0x000ff103, 0x030ff020, 0x4897bf00, 0xf0006900, 0x28000001, 0x4894d1f9,
0xf0406800, 0x4e920040, 0xf0246030, 0x6070000f, 0x60f02027, 0x1c524610, 0x0020f851, 0x36804e8c,
0x46106030, 0xf8511c52, 0x4e890020, 0x0084f8c6, 0x1c524610, 0x0020f851, 0x36884e85, 0x46106030,
0xf8511c52, 0x1d360020, 0x20016030, 0x61304e80, 0xe02c3b10, 0x487ebf00, 0x680030c0, 0x0030f000,
0xd1f82800, 0x1c524610, 0x0020f851, 0x36804e78, 0x46106030, 0xf8511c52, 0x4e750020, 0x0084f8c6,
0x4873bf00, 0x680030c0, 0x00c0f000, 0xd1f82800, 0x1c524610, 0x0020f851, 0x36884e6d, 0x46106030,
0xf8511c52, 0x4e6a0020, 0x008cf8c6, 0x2b003b10, 0xbf00d1d0, 0x69004866, 0x0001f000, 0xd1f92800,
0xb510bd70, 0x1cc84603, 0x0103f020, 0x4860bf00, 0xf0006900, 0x28000001, 0x485dd1f9, 0xf0406800,
0x4c5b0040, 0x20216020, 0xe02060e0, 0x0003f023, 0x60604c57, 0x60a06810, 0x61202001, 0x8f60f3bf,
0x4853bf00, 0xf0006900, 0x28000001, 0x4850d1f9, 0xf0006800, 0xb1380040, 0x6800484d, 0x0040f040,
0x60204c4b, 0xbd102001, 0x1d121d1b, 0x29001f09, 0x2000d1dc, 0xe92de7f7, 0x460547f0, 0x4616460c,
0x0800f04f, 0xbf0046c2, 0x69004841, 0x0001f000, 0xd1f92800, 0x6800483e, 0x0040f040, 0x6008493c,
0xf0201ce0, 0xe02d0403, 0xb958b2e8, 0xd9092cff, 0x7780f44f, 0x0208eb06, 0x46284639, 0xff2ef7ff,
0xe0164682, 0x0008f3c5, 0x2c10b958, 0xf024d309, 0xeb06070f, 0x46390208, 0xf7ff4628, 0x4682ff1f,
0x4627e007, 0x0208eb06, 0x46284639, 0xff89f7ff, 0x443d4682, 0x1be444b8, 0x0f00f1ba, 0x2001d002,
0x87f0e8bd, 0xd1cf2c00, 0xe7f92000, 0x1ccbb510, 0x0103f023, 0x4b1ebf00, 0xf003691b, 0x2b000301,
0x4b1bd1f9, 0xf043681b, 0x4c190340, 0x23006023, 0xe02560e3, 0x0303f020, 0x60634c15, 0x60a32300,
0x61232301, 0x8f60f3bf, 0x4b11bf00, 0xf003691b, 0x2b000301, 0x4b0ed1f9, 0xf003681b, 0xb1330340,
0x681b4b0b, 0x0340f043, 0x60234c09, 0x4b08bd10, 0x6814689b, 0xd00042a3, 0x1d00e7f8, 0x1f091d12,
0xd1d72900, 0xe7f1bf00, 0x40000100, 0x40000200, 0x4000c000, 0x00000000,
};

static const flash_algo_t flash_algo_config = {
.init = 0x00000001,
.uninit = 0x0000007f,
.erase_sector = 0x000000a3,
.program_page = 0x00000257,
.static_base = 0x00000374,
.algo_blob = FLASH_ALGO
};

static const sector_info_t sectors_info[] = {
{0x0, 0x800}, // (start, sector size)
};

static const flash_target_config_t flash_target_config = {
.page_size = 0x800, // 2 KB
.flash_start = 0x0,
.flash_size = 0x40000, // 256 KB
.sectors = sectors_info,
.sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t)
};

void flash_set_target_config(flash_t *obj)
{
obj->flash_algo = &flash_algo_config;
obj->target_config = &flash_target_config;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#! armcc -E

LR_IROM1 0x00000000 {
ER_IROM1 0x00000000 { ; load address = execution address
#if !defined(MBED_APP_START)
#define MBED_APP_START 0x00000000
#endif

#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x00080000
#endif

LR_IROM1 MBED_APP_START {
ER_IROM1 MBED_APP_START { ; load address = execution address
*(RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
Expand Down Expand Up @@ -29,7 +38,7 @@ LR_IROM1 0x00000000 {
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (0x60000000 + 0x100000 - AlignExpr(ImageLimit(ER_XRAM1), 16)) {
}
}
ScatterAssert(LoadLimit(LR_IROM1) <= 0x00080000) ; 512 KB APROM
ScatterAssert(LoadLimit(LR_IROM1) <= (MBED_APP_START + MBED_APP_SIZE)) ; 512 KB APROM
ScatterAssert(ImageLimit(RW_IRAM1) <= 0x20010000) ; 64 KB SRAM (internal)
ScatterAssert(ImageLimit(ARM_LIB_HEAP) <= 0x60100000) ; 1 MB SRAM (external)

Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#! armcc -E

LR_IROM1 0x00000000 {
ER_IROM1 0x00000000 { ; load address = execution address
#if !defined(MBED_APP_START)
#define MBED_APP_START 0x00000000
#endif

#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x00080000
#endif

LR_IROM1 MBED_APP_START {
ER_IROM1 MBED_APP_START { ; load address = execution address
*(RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
Expand All @@ -24,6 +33,6 @@ LR_IROM1 0x00000000 {
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (0x20000000 + 0x10000 - AlignExpr(ImageLimit(RW_IRAM1), 16)) {
}
}
ScatterAssert(LoadLimit(LR_IROM1) <= 0x00080000) ; 512 KB APROM
ScatterAssert(LoadLimit(LR_IROM1) <= (MBED_APP_START + MBED_APP_SIZE)) ; 512 KB APROM
ScatterAssert(ImageLimit(RW_IRAM1) <= 0x20010000) ; 64 KB SRAM (internal)

Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#! armcc -E

LR_IROM1 0x00000000 {
ER_IROM1 0x00000000 { ; load address = execution address
#if !defined(MBED_APP_START)
#define MBED_APP_START 0x00000000
#endif

#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x00080000
#endif

LR_IROM1 MBED_APP_START {
ER_IROM1 MBED_APP_START { ; load address = execution address
*(RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
Expand Down Expand Up @@ -31,7 +40,7 @@ LR_IROM1 0x00000000 {
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (0x60000000 + 0x100000 - AlignExpr(ImageLimit(ER_XRAM1), 16)) {
}
}
ScatterAssert(LoadLimit(LR_IROM1) <= 0x00080000) ; 512 KB APROM
ScatterAssert(LoadLimit(LR_IROM1) <= (MBED_APP_START + MBED_APP_SIZE)) ; 512 KB APROM
ScatterAssert(ImageLimit(RW_IRAM1) <= 0x20010000) ; 64 KB SRAM (internal)
ScatterAssert(ImageLimit(ARM_LIB_HEAP) <= 0x60100000) ; 1 MB SRAM (external)

Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#! armcc -E

LR_IROM1 0x00000000 {
ER_IROM1 0x00000000 { ; load address = execution address
#if !defined(MBED_APP_START)
#define MBED_APP_START 0x00000000
#endif

#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x00080000
#endif

LR_IROM1 MBED_APP_START {
ER_IROM1 MBED_APP_START { ; load address = execution address
*(RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
Expand All @@ -24,6 +33,6 @@ LR_IROM1 0x00000000 {
ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (0x20000000 + 0x10000 - AlignExpr(ImageLimit(RW_IRAM1), 16)) {
}
}
ScatterAssert(LoadLimit(LR_IROM1) <= 0x00080000) ; 512 KB APROM
ScatterAssert(LoadLimit(LR_IROM1) <= (MBED_APP_START + MBED_APP_SIZE)) ; 512 KB APROM
ScatterAssert(ImageLimit(RW_IRAM1) <= 0x20010000) ; 64 KB SRAM (internal)

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
* Nuvoton NUC472 GCC linker script file
*/

#if !defined(MBED_APP_START)
#define MBED_APP_START 0x00000000
#endif

#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x00080000
#endif

StackSize = 0x800;

MEMORY
{

VECTORS (rx) : ORIGIN = 0x00000000, LENGTH = 0x00000400
FLASH (rx) : ORIGIN = 0x00000400, LENGTH = 0x00080000 - 0x00000400
VECTORS (rx) : ORIGIN = MBED_APP_START, LENGTH = 0x00000400
FLASH (rx) : ORIGIN = MBED_APP_START + 0x400, LENGTH = MBED_APP_SIZE - 0x00000400
RAM_INTERN (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 - 0x00000000
RAM_EXTERN (rwx) : ORIGIN = 0x60000000, LENGTH = 0x00100000
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
* Nuvoton NUC472 GCC linker script file
*/

#if !defined(MBED_APP_START)
#define MBED_APP_START 0x00000000
#endif

#if !defined(MBED_APP_SIZE)
#define MBED_APP_SIZE 0x00080000
#endif

StackSize = 0x800;

MEMORY
{

VECTORS (rx) : ORIGIN = 0x00000000, LENGTH = 0x00000400
FLASH (rx) : ORIGIN = 0x00000400, LENGTH = 0x00080000 - 0x00000400
VECTORS (rx) : ORIGIN = MBED_APP_START, LENGTH = 0x00000400
FLASH (rx) : ORIGIN = MBED_APP_START + 0x400, LENGTH = MBED_APP_SIZE - 0x00000400
RAM_INTERN (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 - 0x00000000
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x00000000; }
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0x00080000; }
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
define symbol __ICFEDIT_intvec_start__ = MBED_APP_START;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x00080000;
define symbol __ICFEDIT_region_ROM_start__ = MBED_APP_START;
define symbol __ICFEDIT_region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
define symbol __ICFEDIT_region_IRAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_IRAM_end__ = 0x20010000;
define symbol __ICFEDIT_region_XRAM_start__ = 0x60000000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/*###ICF### Section handled by ICF editor, don't touch! ****/
/*-Editor annotation file-*/
/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */
if (!isdefinedsymbol(MBED_APP_START)) { define symbol MBED_APP_START = 0x00000000; }
if (!isdefinedsymbol(MBED_APP_SIZE)) { define symbol MBED_APP_SIZE = 0x00080000; }
/*-Specials-*/
define symbol __ICFEDIT_intvec_start__ = 0x00000000;
define symbol __ICFEDIT_intvec_start__ = MBED_APP_START;
/*-Memory Regions-*/
define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
define symbol __ICFEDIT_region_ROM_end__ = 0x00080000;
define symbol __ICFEDIT_region_ROM_start__ = MBED_APP_START;
define symbol __ICFEDIT_region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
define symbol __ICFEDIT_region_IRAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_IRAM_end__ = 0x20010000;
/*-Sizes-*/
Expand Down
Loading