diff --git a/os/common/startup/ARMCMx/compilers/GCC/ld/NUC123xD4xx0.ld b/os/common/startup/ARMCMx/compilers/GCC/ld/NUC123xD4xx0.ld index 53867912..86c61bc6 100644 --- a/os/common/startup/ARMCMx/compilers/GCC/ld/NUC123xD4xx0.ld +++ b/os/common/startup/ARMCMx/compilers/GCC/ld/NUC123xD4xx0.ld @@ -20,15 +20,15 @@ */ MEMORY { - flash0 (rx) : org = 0x00000000, len = 64k - flash1 (rx) : org = 0x00000000, len = 0 - flash2 (rx) : org = 0x00000000, len = 0 - flash3 (rx) : org = 0x00000000, len = 0 - flash4 (rx) : org = 0x00000000, len = 0 + flash0 (rx) : org = 0x00000000, len = 0x11000 /* APROM */ + flash1 (rx) : org = 0x00000000, len = 0 /* Data flash placeholder */ + flash2 (rx) : org = 0x00100000, len = 0x1000 /* LDROM */ + flash3 (rx) : org = 0x00300000, len = 4 /* Config0 */ + flash4 (rx) : org = 0x00300004, len = 4 /* Config1 */ flash5 (rx) : org = 0x00000000, len = 0 flash6 (rx) : org = 0x00000000, len = 0 flash7 (rx) : org = 0x00000000, len = 0 - ram0 (wx) : org = 0x20000000, len = 20k + ram0 (wx) : org = 0x20000000, len = 0x5000 ram1 (wx) : org = 0x00000000, len = 0 ram2 (wx) : org = 0x00000000, len = 0 ram3 (wx) : org = 0x00000000, len = 0 @@ -38,6 +38,22 @@ MEMORY ram7 (wx) : org = 0x00000000, len = 0 } +REGION_ALIAS("CONFIG0", flash3); +REGION_ALIAS("CONFIG1", flash4); + +SECTIONS +{ + .nuc123_config0 : ALIGN(4) + { + KEEP(*(.nuc123_config0)) + } > CONFIG0 + + .nuc123_config1 : ALIGN(4) + { + KEEP(*(.nuc123_config1)) + } > CONFIG1 +} + /* For each data/text section two region are defined, a virtual region and a load region (_LMA suffix).*/ diff --git a/os/hal/ports/NUMICRO/NUC123/hal_lld.c b/os/hal/ports/NUMICRO/NUC123/hal_lld.c index 26e18d0d..32862515 100644 --- a/os/hal/ports/NUMICRO/NUC123/hal_lld.c +++ b/os/hal/ports/NUMICRO/NUC123/hal_lld.c @@ -50,6 +50,9 @@ uint32_t SystemCoreClock = __HSI; /* System Clock Frequency (Core Clock)*/ uint32_t CyclesPerUs = (__HSI / 1000000); /* Cycles per micro second */ uint32_t PllClock = __HSI; /*!< PLL Clock Frequency */ +volatile const uint32_t config0 __attribute__((used, unused, section(".nuc123_config0"))) = NUC123_CONFIG0; +volatile const uint32_t config1 __attribute__((used, unused, section(".nuc123_config1"))) = NUC123_CONFIG1; + /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ diff --git a/os/hal/ports/NUMICRO/NUC123/hal_lld.h b/os/hal/ports/NUMICRO/NUC123/hal_lld.h index 639c77b6..8c14bcd9 100644 --- a/os/hal/ports/NUMICRO/NUC123/hal_lld.h +++ b/os/hal/ports/NUMICRO/NUC123/hal_lld.h @@ -114,6 +114,23 @@ #define NUC123_PLLSRC_HSI (1 << CLK_PLLCON_PLL_SRC_Pos) /**< PLL source is HSI. */ /** @} */ +/** + * @name User config bit definitions + * @{ + */ +#define NUC123_CONFIG0_DFEN_Pos 0 +#define NUC123_CONFIG0_DFEN_Msk (1 << NUC123_CONFIG0_DFEN_Pos) + +#define NUC123_CONFIG0_LOCK_Pos 1 +#define NUC123_CONFIG0_LOCK_Msk (1 << NUC123_CONFIG0_LOCK_Pos) + +#define NUC123_CONFIG0_DFVSEN_Pos 2 +#define NUC123_CONFIG0_DFVSEN_Msk (1 << NUC123_CONFIG0_DFVSEN_Pos) + +#define NUC123_CONFIG0_CGPFMFP_Pos 27 +#define NUC123_CONFIG0_CGPFMFP_Msk (1 << NUC123_CONFIG0_CGPFMFP_Pos) +/** @} */ + /*===========================================================================*/ /* Driver pre-compile time settings. */ /*===========================================================================*/ @@ -159,11 +176,26 @@ #endif /** - * @brief Clock source for the PLL. + * @brief Core clock speed. */ #if !defined(NUC123_HCLK) || defined(__DOXYGEN__) #define NUC123_HCLK 72000000UL #endif + +/** + * @brief Enables or disables data flash + */ +#if !defined(NUC123_DATAFLASH_ENABLED) || defined(__DOXYGEN__) +#define NUC123_DATAFLASH_ENABLED FALSE +#endif + +/** + * @brief Sets the data flash size. This is ignored if data flash is disabled. + */ +#if !defined(NUC123_DATAFLASH_SIZE) || defined(__DOXYGEN__) +#define NUC123_DATAFLASH_SIZE 4096 +#endif + /** @} */ /*===========================================================================*/ @@ -187,10 +219,39 @@ #elif (NUC123_HSECLK < NUC123_HSECLK_MIN) || (NUC123_HSECLK > NUC123_HSECLK_MAX) #error "NUC123_HSECLK outside acceptable range (NUC123_HSECLK_MIN...NUC123_HSECLK_MAX)" #endif +#define NUC123_CONFIG0_HSE_PINS 0 +#else +#define NUC123_CONFIG0_HSE_PINS NUC123_CONFIG0_CGPFMFP_Msk #endif #define NUC123_PLLCLK (NUC123_HCLK * 2) +/* +* Persistant configuration settings. +*/ +#if NUC123_DATAFLASH_ENABLE + +#if (NUC123_DATAFLASH_SIZE == 4096) +/* DFVSEN = 1, nothing else matters */ +#define NUC123_CONFIG0_DATAFLASH 0UL +/* NUC123_DFBADDR doesn't actually control anything here, but convenient for flash drivers +which need the starting address */ +#define NUC123_DFBADDR 0x1F000UL +#else +/* DFVSEN = 0, DFEN = 0 */ +#define NUC123_CONFIG0_DATAFLASH (NUC123_CONFIG0_DFVSEN_Msk | NUC123_CONFIG0_DFEN_Msk) +#define NUC123_DFBADDR ((0x11000UL - NUC123_DATAFLASH_SIZE) & ~(0xFFUL)) +#endif +#else +/* DFVSEN = 0, DFEN = 1 */ +#define NUC123_CONFIG0_DATAFLASH NUC123_CONFIG0_DFVSEN_Msk +#define NUC123_DFBADDR 0xFFFFFF00UL +#endif + +#define NUC123_CONFIG0 \ + 0xFFFFFFFFUL & (~NUC123_CONFIG0_DATAFLASH) & (~NUC123_CONFIG0_HSE_PINS) +#define NUC123_CONFIG1 NUC123_DFBADDR + /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ @@ -198,6 +259,7 @@ /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ + /* Alias for compatibility */ #define SystemUnlockReg() UNLOCKREG() diff --git a/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/Blinky/Makefile b/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/Blinky/Makefile index 1b9b70fb..f61599c6 100644 --- a/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/Blinky/Makefile +++ b/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/Blinky/Makefile @@ -196,4 +196,4 @@ connect: openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg flash: $(BUILDDIR)/$(PROJECT).elf - openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg -c "program $< verify reset exit" + openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg -c "program $< reset exit" diff --git a/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/PWM/Makefile b/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/PWM/Makefile index 1854bc2d..275dc748 100644 --- a/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/PWM/Makefile +++ b/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/PWM/Makefile @@ -196,7 +196,7 @@ connect: openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg flash: $(BUILDDIR)/$(PROJECT).elf - openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg -c "program $< verify reset exit" + openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg -c "program $< reset exit" # # Custom rules diff --git a/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/SERIAL/Makefile b/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/SERIAL/Makefile index 81242908..95ea9145 100644 --- a/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/SERIAL/Makefile +++ b/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/SERIAL/Makefile @@ -193,4 +193,4 @@ connect: openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg flash: $(BUILDDIR)/$(PROJECT).elf - openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg -c "program $< verify reset exit" + openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg -c "program $< reset exit" diff --git a/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/USB_HID/Makefile b/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/USB_HID/Makefile index be859ed7..79010635 100644 --- a/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/USB_HID/Makefile +++ b/testhal/NUMICRO/NUC123/NUTINY-SDK-NUC123-V2.0/USB_HID/Makefile @@ -197,7 +197,7 @@ connect: openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg flash: $(BUILDDIR)/$(PROJECT).elf - openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg -c "program $< verify reset exit" + openocd -f ../scripts/interface/nulink.cfg -f ../scripts/target/numicroM0.cfg -c "program $< reset exit" #