Skip to content

Commit

Permalink
Nuvoton: Migrate to new style memory bank information
Browse files Browse the repository at this point in the history
Change memory bank symbols:
1. MBED_APP_START/SIZE -> MBED_CONFIGURED_ROM_BANK_IROM1_START/SIZE
2. MBED_RAM_APP_START/SIZE -> MBED_CONFIGURED_RAM_BANK_IRAM1_START/SIZE
3. APPLICATION_ADDR/SIZE -> MBED_CONFIGURED_ROM_BANK_IROM1_START/SIZE
4. APPLICATION_RAM_ADDR/SIZE -> MBED_CONFIGURED_RAM_BANK_IRAM1_START/SIZE
5. -> MBED_CONFIGURED_RAM_BANK_XRAM1_START/SIZE
   NOTE: Specific to NUC472
6. NU_HYPERRAM_START/SIZE -> MBED_CONFIGURED_RAM_BANK_HYPERRAM1_START/SIZE
   NOTE: Specific to M467
  • Loading branch information
ccli8 committed Nov 18, 2024
1 parent 67a1942 commit c827166
Show file tree
Hide file tree
Showing 23 changed files with 293 additions and 734 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ StackSize = MBED_CONF_TARGET_BOOT_STACK_SIZE;

MEMORY
{
VECTORS (rx) : ORIGIN = MBED_APP_START, LENGTH = 0x00000400
FLASH (rx) : ORIGIN = MBED_APP_START + 0x400, LENGTH = MBED_APP_SIZE - 0x400
RAM_INTERN (rwx) : ORIGIN = MBED_RAM_APP_START, LENGTH = MBED_RAM_APP_SIZE
VECTORS (rx) : ORIGIN = MBED_CONFIGURED_ROM_BANK_IROM1_START, LENGTH = 0x00000400
FLASH (rx) : ORIGIN = MBED_CONFIGURED_ROM_BANK_IROM1_START + 0x400, LENGTH = MBED_CONFIGURED_ROM_BANK_IROM1_SIZE - 0x400
RAM_INTERN (rwx) : ORIGIN = MBED_CONFIGURED_RAM_BANK_IRAM1_START, LENGTH = MBED_CONFIGURED_RAM_BANK_IRAM1_SIZE
}

/**
Expand Down
126 changes: 25 additions & 101 deletions targets/TARGET_NUVOTON/TARGET_M2354/device/partition_M2354_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,113 +19,37 @@
#ifndef __PARTITION_M2354_MEM_H__
#define __PARTITION_M2354_MEM_H__

/* About partition_M2354_mem.h/partition_M2354_mem.icf.h
*
* 1. partition_M2354_mem.h is created for centralizing memory partition configuration. It will be
* included by C/C++ files and linker files (except IAR linker file).
* 2. IAR linker doesn't support preprocessor, so partition_M2354_mem.icf.h, duplicate of partition_M2354_mem.h
* is created for IAR linker file.
* 3. To continue above, we name partition_M2354_mem.icf.h instead of partition_M2354_mem.icf because:
* (1) Mbed OS build tool may mis-regard partition_M2354_mem.icf as the main linker configuration file.
* (2) *.icf files may not be present in search directories for "include" directive. Per observation,
* the search directories are inconsistent among normal example build and test code build. To address
* it, we name partition_M2354_mem.icf.h instead because *.h files are always present in these builds
* (already there or via copy).
*/

#include "nu_tfm_import_define.h"
#include NU_TFM_S_REGION_DEFS_H_PATH
#include "nu_tfm_import_undefine.h"

/* Resolve MBED_ROM_START and friends
/* Resolve MBED_ROM_BANK_IROM1_START and friends
*
* TF-M exported region_defs.h essentially resolves MBED_ROM_START and friends.
* target.mbed_rom_start and friends get unnecessary.
* TF-M exported region_defs.h essentially resolves MBED_ROM_BANK_IROM1_START and friends.
*/
/* Resolve non-secure ROM start */
#undef MBED_ROM_START
#define MBED_ROM_START NS_CODE_START

/* Resolve non-secure ROM size */
#undef MBED_ROM_SIZE
#define MBED_ROM_SIZE NS_CODE_SIZE

/* Resolve non-secure RAM start */
#undef MBED_RAM_START
#define MBED_RAM_START NS_DATA_START

/* Resolve non-secure RAM size */
#undef MBED_RAM_SIZE
#define MBED_RAM_SIZE NS_DATA_SIZE

/* Mbed build tool passes just APPLICATION_xxx macros to C/C++ files and just
* MBED_APP_xxx macros to linker files even though they mean the same thing.
* Because this file is to include by both C/C++ files and linker files, we add
* these macros according to the others for consistency when they are missing
* in compile or link stage. */

#ifndef APPLICATION_ADDR
#ifdef MBED_APP_START
#define APPLICATION_ADDR MBED_APP_START
#else
#define APPLICATION_ADDR MBED_ROM_START
#endif
#endif

#ifndef APPLICATION_SIZE
#ifdef MBED_APP_SIZE
#define APPLICATION_SIZE MBED_APP_SIZE
#else
#define APPLICATION_SIZE MBED_ROM_SIZE
#endif
#endif

#ifndef APPLICATION_RAM_ADDR
#ifdef MBED_RAM_APP_START
#define APPLICATION_RAM_ADDR MBED_RAM_APP_START
#else
#define APPLICATION_RAM_ADDR MBED_RAM_START
#endif
#endif

#ifndef APPLICATION_RAM_SIZE
#ifdef MBED_RAM_APP_SIZE
#define APPLICATION_RAM_SIZE MBED_RAM_APP_SIZE
#else
#define APPLICATION_RAM_SIZE MBED_RAM_SIZE
#endif
#endif

#ifndef MBED_APP_START
#define MBED_APP_START APPLICATION_ADDR
#endif

#ifndef MBED_APP_SIZE
#define MBED_APP_SIZE APPLICATION_SIZE
#endif

#ifndef MBED_RAM_APP_START
#define MBED_RAM_APP_START APPLICATION_RAM_ADDR
#endif

#ifndef MBED_RAM_APP_SIZE
#define MBED_RAM_APP_SIZE APPLICATION_RAM_SIZE
#endif

#if (APPLICATION_ADDR != MBED_APP_START)
#error("APPLICATION_ADDR and MBED_APP_START are not the same!!!")
#endif

#if (APPLICATION_SIZE != MBED_APP_SIZE)
#error("APPLICATION_SIZE and MBED_APP_SIZE are not the same!!!")
#endif

#if (APPLICATION_RAM_ADDR != MBED_RAM_APP_START)
#error("APPLICATION_RAM_ADDR and MBED_RAM_APP_START are not the same!!!")
#endif

#if (APPLICATION_RAM_SIZE != MBED_RAM_APP_SIZE)
#error("APPLICATION_RAM_SIZE and MBED_RAM_APP_SIZE are not the same!!!")
#endif
/* Physical IROM1 start/size */
#undef MBED_ROM_BANK_IROM1_START
#define MBED_ROM_BANK_IROM1_START NS_CODE_START
#undef MBED_ROM_BANK_IROM1_SIZE
#define MBED_ROM_BANK_IROM1_SIZE NS_CODE_SIZE

/* Physical IRAM1 start/size */
#undef MBED_RAM_BANK_IRAM1_START
#define MBED_RAM_BANK_IRAM1_START NS_DATA_START
#undef MBED_RAM_BANK_IRAM1_SIZE
#define MBED_RAM_BANK_IRAM1_SIZE NS_DATA_SIZE

/* Configured IROM1 start/size */
#undef MBED_CONFIGURED_ROM_BANK_IROM1_START
#define MBED_CONFIGURED_ROM_BANK_IROM1_START MBED_ROM_BANK_IROM1_START
#undef MBED_CONFIGURED_ROM_BANK_IROM1_SIZE
#define MBED_CONFIGURED_ROM_BANK_IROM1_SIZE MBED_ROM_BANK_IROM1_SIZE

/* Configured IRAM1 start/size */
#undef MBED_CONFIGURED_RAM_BANK_IRAM1_START
#define MBED_CONFIGURED_RAM_BANK_IRAM1_START MBED_RAM_BANK_IRAM1_START
#undef MBED_CONFIGURED_RAM_BANK_IRAM1_SIZE
#define MBED_CONFIGURED_RAM_BANK_IRAM1_SIZE MBED_RAM_BANK_IRAM1_SIZE

#endif /* __PARTITION_M2354_MEM_H__ */
117 changes: 22 additions & 95 deletions targets/TARGET_NUVOTON/TARGET_M251/device/M251_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,115 +19,42 @@
#ifndef __M251_MEM_H__
#define __M251_MEM_H__

/* About M251_mem.h/M251_mem.icf.h
*
* 1. M251_mem.h is created for centralizing memory configuration. It will be included by C/C++ files
* and linker files (except IAR linker file).
* 2. IAR linker doesn't support preprocessor, so M251_mem.icf.h, duplicate of M251_mem.h
* is created for IAR linker file.
* 3. To continue above, we name M251_mem.icf.h instead of M251_mem.icf because:
* (1) Mbed OS build tool may mis-regard M251_mem.icf as the main linker configuration file.
* (2) *.icf files may not be present in search directories for "include" directive. Per observation,
* the search directories are inconsistent among normal example build and test code build. To address
* it, we name M251_mem.icf.h instead because *.h files are always present in these builds
* (already there or via copy).
*/

/* Default memory specification
*
* Flash size: 256KiB
* SRAM size: 32KiB
*/

/* Resolve ROM start */
#ifndef MBED_ROM_START
#define MBED_ROM_START (0x0)
#endif

/* Resolve ROM size */
#ifndef MBED_ROM_SIZE
#define MBED_ROM_SIZE (0x40000)
#endif

/* Resolve RAM start */
#ifndef MBED_RAM_START
#define MBED_RAM_START (0x20000000)
#endif

/* Resolve RAM size */
#ifndef MBED_RAM_SIZE
#define MBED_RAM_SIZE (0x8000)
#endif


/* Mbed build tool passes just APPLICATION_xxx macros to C/C++ files and just
* MBED_APP_xxx macros to linker files even though they mean the same thing.
* Because this file is to include by both C/C++ files and linker files, we add
* these macros according to the others for consistency when they are missing
* in compile or link stage. */

#ifndef APPLICATION_ADDR
#ifdef MBED_APP_START
#define APPLICATION_ADDR MBED_APP_START
#else
#define APPLICATION_ADDR MBED_ROM_START
#endif
/* Physical IROM1 start/size */
#if !defined(MBED_ROM_BANK_IROM1_START)
#define MBED_ROM_BANK_IROM1_START 0x0
#endif
#if !defined(MBED_ROM_BANK_IROM1_SIZE)
#define MBED_ROM_BANK_IROM1_SIZE 0x40000
#endif

#ifndef APPLICATION_SIZE
#ifdef MBED_APP_SIZE
#define APPLICATION_SIZE MBED_APP_SIZE
#else
#define APPLICATION_SIZE MBED_ROM_SIZE
/* Physical IRAM1 start/size */
#if !defined(MBED_RAM_BANK_IRAM1_START)
#define MBED_RAM_BANK_IRAM1_START 0x20000000
#endif
#if !defined(MBED_RAM_BANK_IRAM1_SIZE)
#define MBED_RAM_BANK_IRAM1_SIZE 0x8000
#endif

#ifndef APPLICATION_RAM_ADDR
#ifdef MBED_RAM_APP_START
#define APPLICATION_RAM_ADDR MBED_RAM_APP_START
#else
#define APPLICATION_RAM_ADDR MBED_RAM_START
#endif
/* Configured IROM1 start/size */
#if !defined(MBED_CONFIGURED_ROM_BANK_IROM1_START)
#define MBED_CONFIGURED_ROM_BANK_IROM1_START MBED_ROM_BANK_IROM1_START
#endif
#if !defined(MBED_CONFIGURED_ROM_BANK_IROM1_SIZE)
#define MBED_CONFIGURED_ROM_BANK_IROM1_SIZE MBED_ROM_BANK_IROM1_SIZE
#endif

#ifndef APPLICATION_RAM_SIZE
#ifdef MBED_RAM_APP_SIZE
#define APPLICATION_RAM_SIZE MBED_RAM_APP_SIZE
#else
#define APPLICATION_RAM_SIZE MBED_RAM_SIZE
#endif
/* Configured IRAM1 start/size */
#if !defined(MBED_CONFIGURED_RAM_BANK_IRAM1_START)
#define MBED_CONFIGURED_RAM_BANK_IRAM1_START MBED_RAM_BANK_IRAM1_START
#endif

#ifndef MBED_APP_START
#define MBED_APP_START APPLICATION_ADDR
#endif

#ifndef MBED_APP_SIZE
#define MBED_APP_SIZE APPLICATION_SIZE
#endif

#ifndef MBED_RAM_APP_START
#define MBED_RAM_APP_START APPLICATION_RAM_ADDR
#endif

#ifndef MBED_RAM_APP_SIZE
#define MBED_RAM_APP_SIZE APPLICATION_RAM_SIZE
#endif

#if (APPLICATION_ADDR != MBED_APP_START)
#error("APPLICATION_ADDR and MBED_APP_START are not the same!!!")
#endif

#if (APPLICATION_SIZE != MBED_APP_SIZE)
#error("APPLICATION_SIZE and MBED_APP_SIZE are not the same!!!")
#endif

#if (APPLICATION_RAM_ADDR != MBED_RAM_APP_START)
#error("APPLICATION_RAM_ADDR and MBED_RAM_APP_START are not the same!!!")
#endif

#if (APPLICATION_RAM_SIZE != MBED_RAM_APP_SIZE)
#error("APPLICATION_RAM_SIZE and MBED_RAM_APP_SIZE are not the same!!!")
#if !defined(MBED_CONFIGURED_RAM_BANK_IRAM1_SIZE)
#define MBED_CONFIGURED_RAM_BANK_IRAM1_SIZE MBED_RAM_BANK_IRAM1_SIZE
#endif

#endif /* __M251_MEM_H__ */
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ StackSize = MBED_CONF_TARGET_BOOT_STACK_SIZE;

MEMORY
{
VECTORS (rx) : ORIGIN = MBED_APP_START, LENGTH = 0x00000400
FLASH (rx) : ORIGIN = MBED_APP_START + 0x400, LENGTH = MBED_APP_SIZE - 0x400
RAM_INTERN (rwx) : ORIGIN = MBED_RAM_APP_START, LENGTH = MBED_RAM_APP_SIZE
VECTORS (rx) : ORIGIN = MBED_CONFIGURED_ROM_BANK_IROM1_START, LENGTH = 0x00000400
FLASH (rx) : ORIGIN = MBED_CONFIGURED_ROM_BANK_IROM1_START + 0x400, LENGTH = MBED_CONFIGURED_ROM_BANK_IROM1_SIZE - 0x400
RAM_INTERN (rwx) : ORIGIN = MBED_CONFIGURED_RAM_BANK_IRAM1_START, LENGTH = MBED_CONFIGURED_RAM_BANK_IRAM1_SIZE
}

/* Must match cmsis_nvic.h */
Expand Down
6 changes: 3 additions & 3 deletions targets/TARGET_NUVOTON/TARGET_M251/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ static const flash_algo_t flash_algo_config = {

/* Secure flash */
static const sector_info_t sectors_info[] = {
{MBED_ROM_START, 0x200}, // (start, sector size)
{MBED_ROM_BANK_IROM1_START, 0x200}, // (start, sector size)
};

/* Secure flash */
static const flash_target_config_t flash_target_config = {
.page_size = 4, // 4 bytes
// Here page_size is program unit, which is different
// than FMC definition.
.flash_start = MBED_ROM_START,
.flash_size = MBED_ROM_SIZE,
.flash_start = MBED_ROM_BANK_IROM1_START,
.flash_size = MBED_ROM_BANK_IROM1_SIZE,
.sectors = sectors_info,
.sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t)
};
Expand Down
Loading

0 comments on commit c827166

Please sign in to comment.