soc: arm: nxp_lpc: convert NXP LPC SOCs to use CMSIS SystemInit

Convert NXP LPC SOCs to use CMSIS SystemInit, and remove redundant code
where it exists. This will enable initialization flows to be more
standardized across all platforms.

Since LPC54xxx and LPC55xxx series enables SRAM banks in SystemInit,
provide Kconfigs to bypass this setting and keep additional SRAM
banks unclocked.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
Daniel DeGrasse 2022-11-30 16:06:40 -06:00 committed by Carles Cufí
commit 3b59b495b7
18 changed files with 112 additions and 0 deletions

View file

@ -103,4 +103,11 @@ config IMAGE_VECTOR_TABLE_OFFSET
endif # NXP_IMX_RT5XX_BOOT_HEADER endif # NXP_IMX_RT5XX_BOOT_HEADER
config IMXRT5XX_ENABLE_CODE_CACHE
bool "Enable code cache"
default y
help
Enable code cache for FlexSPI region at boot. If this Kconfig is
cleared, the CACHE64 controller will be disabled during SOC init
endif # SOC_SERIES_IMX_RT5XX endif # SOC_SERIES_IMX_RT5XX

View file

@ -20,6 +20,7 @@
#include <soc.h> #include <soc.h>
#include "fsl_power.h" #include "fsl_power.h"
#include "fsl_clock.h" #include "fsl_clock.h"
#include <fsl_cache.h>
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_XIP #ifdef CONFIG_FLASH_MCUX_FLEXSPI_XIP
#include "flash_clock_setup.h" #include "flash_clock_setup.h"
@ -374,6 +375,10 @@ static int nxp_rt500_init(const struct device *arg)
*/ */
NMI_INIT(); NMI_INIT();
#ifndef CONFIG_IMXRT5XX_ENABLE_CODE_CACHE
CACHE64_DisableCache(CACHE64_CTRL0);
#endif
/* restore interrupt state */ /* restore interrupt state */
irq_unlock(oldLevel); irq_unlock(oldLevel);

View file

@ -109,4 +109,11 @@ config IMAGE_VECTOR_TABLE_OFFSET
endif # NXP_IMX_RT6XX_BOOT_HEADER endif # NXP_IMX_RT6XX_BOOT_HEADER
config IMXRT6XX_ENABLE_CODE_CACHE
bool "Enable code cache"
default y
help
Enable code cache for FlexSPI region at boot. If this Kconfig is
cleared, the CACHE64 controller will be disabled during SOC init
endif # SOC_SERIES_IMX_RT6XX endif # SOC_SERIES_IMX_RT6XX

View file

@ -24,6 +24,7 @@
#include <fsl_clock.h> #include <fsl_clock.h>
#include <fsl_common.h> #include <fsl_common.h>
#include <fsl_device_registers.h> #include <fsl_device_registers.h>
#include <fsl_cache.h>
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_XIP #ifdef CONFIG_FLASH_MCUX_FLEXSPI_XIP
#include "flash_clock_setup.h" #include "flash_clock_setup.h"
@ -385,6 +386,10 @@ static int nxp_rt600_init(const struct device *arg)
*/ */
NMI_INIT(); NMI_INIT();
#ifndef CONFIG_IMXRT6XX_ENABLE_CODE_CACHE
CACHE64_DisableCache(CACHE64);
#endif
/* restore interrupt state */ /* restore interrupt state */
irq_unlock(oldLevel); irq_unlock(oldLevel);

View file

@ -13,5 +13,6 @@ config SOC_SERIES_LPC51U68
select HAS_MCUX_SCTIMER select HAS_MCUX_SCTIMER
select SOC_FAMILY_LPC select SOC_FAMILY_LPC
select CPU_CORTEX_M_HAS_SYSTICK select CPU_CORTEX_M_HAS_SYSTICK
select PLATFORM_SPECIFIC_INIT
help help
Enable support for LPC LPC51U68 MCU Series Enable support for LPC LPC51U68 MCU Series

View file

@ -4,4 +4,9 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
/* The SDK CMIS SystemInit function sets VTOR equal to &__Vectors,
* so we create an alias for the symbol to Zephyr's vector table
*/
__Vectors = _vector_table;
#include <zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld> #include <zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld>

View file

@ -52,4 +52,13 @@ int soc_init(const struct device *arg)
return 0; return 0;
} }
#ifdef CONFIG_PLATFORM_SPECIFIC_INIT
void z_arm_platform_init(void)
{
SystemInit();
}
#endif /* CONFIG_PLATFORM_SPECIFIC_INIT */
SYS_INIT(soc_init, PRE_KERNEL_1, 0); SYS_INIT(soc_init, PRE_KERNEL_1, 0);

View file

@ -12,3 +12,10 @@ zephyr_library_include_directories(
${ZEPHYR_BASE}/kernel/include ${ZEPHYR_BASE}/kernel/include
${ZEPHYR_BASE}/arch/${ARCH}/include ${ZEPHYR_BASE}/arch/${ARCH}/include
) )
# CMSIS SystemInit allows us to skip enabling clock to SRAM2 bank via
# this compiler definition
if(NOT DEFINED CONFIG_LPC54XXX_SRAM2_CLOCK)
zephyr_compile_definitions(DONT_ENABLE_DISABLED_RAMBANKS=1)
endif()

View file

@ -11,5 +11,6 @@ config SOC_SERIES_LPC54XXX
select HAS_MCUX_SYSCON select HAS_MCUX_SYSCON
select SOC_FAMILY_LPC select SOC_FAMILY_LPC
select CPU_CORTEX_M_HAS_SYSTICK select CPU_CORTEX_M_HAS_SYSTICK
select PLATFORM_SPECIFIC_INIT
help help
Enable support for LPC LPC54XXX MCU series Enable support for LPC LPC54XXX MCU series

View file

@ -66,4 +66,12 @@ config BUILD_OUTPUT_INFO_HEADER
default y default y
depends on SECOND_CORE_MCUX && SOC_LPC54114_M0 depends on SECOND_CORE_MCUX && SOC_LPC54114_M0
config LPC54XXX_SRAM2_CLOCK
bool "Clock LPC54XXX SRAM2"
default y
help
SRAM2 ram bank is disabled out of reset. By default, CMSIS SystemInit
will enable the clock to this RAM bank. Disable this Kconfig to leave
this ram bank untouched out of reset.
endif # SOC_SERIES_LPC54XXX endif # SOC_SERIES_LPC54XXX

View file

@ -40,6 +40,9 @@ shared_boot_entry:
/* Flag for slave core (0) */ /* Flag for slave core (0) */
movs r4, 0 movs r4, 0
movs r5, 1 movs r5, 1
push {lr}
bl SystemInit
pop {lr}
/* Determine which core (M0+ or M4) this code is running on */ /* Determine which core (M0+ or M4) this code is running on */
/* r2 = (((*cpu_id) >> 4) & 0xFFF); (M4 core == 0xC24) */ /* r2 = (((*cpu_id) >> 4) & 0xFFF); (M4 core == 0xC24) */

View file

@ -11,5 +11,9 @@
* This is the linker script for both standard images and XIP images. * This is the linker script for both standard images and XIP images.
*/ */
/* The SDK CMIS SystemInit function sets VTOR equal to &__Vectors,
* so we create an alias for the symbol to Zephyr's vector table
*/
__Vectors = _vector_table;
#include <zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld> #include <zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld>

View file

@ -139,6 +139,18 @@ static int nxp_lpc54114_init(const struct device *arg)
SYS_INIT(nxp_lpc54114_init, PRE_KERNEL_1, 0); SYS_INIT(nxp_lpc54114_init, PRE_KERNEL_1, 0);
#if defined(CONFIG_PLATFORM_SPECIFIC_INIT) && defined(CONFIG_SOC_LPC54114_M0)
/* M4 core has a custom platform initialization routine in assembly,
* but M0 core does not. install one here to call SystemInit.
*/
void z_arm_platform_init(void)
{
SystemInit();
}
#endif /* CONFIG_PLATFORM_SPECIFIC_INIT */
#if defined(CONFIG_SECOND_CORE_MCUX) && defined(CONFIG_SOC_LPC54114_M4) #if defined(CONFIG_SECOND_CORE_MCUX) && defined(CONFIG_SOC_LPC54114_M4)

View file

@ -16,3 +16,9 @@ zephyr_linker_sources_ifdef(CONFIG_USB_DEVICE_DRIVER
SECTIONS usb.ld) SECTIONS usb.ld)
zephyr_compile_definitions_ifdef(CONFIG_USB_DEVICE_DRIVER USB_STACK_USE_DEDICATED_RAM=1) zephyr_compile_definitions_ifdef(CONFIG_USB_DEVICE_DRIVER USB_STACK_USE_DEDICATED_RAM=1)
# CMSIS SystemInit allows us to skip enabling clock to SRAM banks via
# this compiler definition
if(NOT DEFINED CONFIG_LPC55XXX_SRAM_CLOCKS)
zephyr_compile_definitions(DONT_ENABLE_DISABLED_RAMBANKS=1)
endif()

View file

@ -13,5 +13,6 @@ config SOC_SERIES_LPC55XXX
select SOC_FAMILY_LPC select SOC_FAMILY_LPC
select CPU_CORTEX_M_HAS_SYSTICK select CPU_CORTEX_M_HAS_SYSTICK
select CPU_CORTEX_M_HAS_DWT select CPU_CORTEX_M_HAS_DWT
select PLATFORM_SPECIFIC_INIT
help help
Enable support for LPC5500 Series MCU series Enable support for LPC5500 Series MCU series

View file

@ -139,4 +139,12 @@ config BUILD_OUTPUT_ADJUST_LMA
depends on SECOND_CORE_MCUX && SOC_LPC55S69_CPU1 depends on SECOND_CORE_MCUX && SOC_LPC55S69_CPU1
default "0x10000000" default "0x10000000"
config LPC55XXX_SRAM_CLOCKS
bool "CLock LPC SRAM banks"
default y
help
SRAM controllers 1,2,3, and 4 are disabled at reset.
By default, CMSIS SystemInit will enable the clock to these RAM banks.
Disable this Kconfig to leave the ram banks untouched out of reset.
endif # SOC_SERIES_LPC55XXX endif # SOC_SERIES_LPC55XXX

View file

@ -11,5 +11,10 @@
* This is the linker script for both standard images and XIP images. * This is the linker script for both standard images and XIP images.
*/ */
/* The SDK CMIS SystemInit function sets VTOR equal to &__Vectors,
* so we create an alias for the symbol to Zephyr's vector table
*/
__Vectors = _vector_table;
#include <zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld> #include <zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld>

View file

@ -264,6 +264,24 @@ static int nxp_lpc55xxx_init(const struct device *arg)
return 0; return 0;
} }
#ifdef CONFIG_PLATFORM_SPECIFIC_INIT
void z_arm_platform_init(void)
{
SystemInit();
#ifndef CONFIG_LOG_BACKEND_SWO
/*
* SystemInit unconditionally enables the trace clock.
* Disable the trace clock unless SWO is used
*/
SYSCON->TRACECLKDIV = 0x4000000;
#endif
}
#endif /* CONFIG_PLATFORM_SPECIFIC_INIT */
SYS_INIT(nxp_lpc55xxx_init, PRE_KERNEL_1, 0); SYS_INIT(nxp_lpc55xxx_init, PRE_KERNEL_1, 0);
#if defined(CONFIG_SECOND_CORE_MCUX) && defined(CONFIG_SOC_LPC55S69_CPU0) #if defined(CONFIG_SECOND_CORE_MCUX) && defined(CONFIG_SOC_LPC55S69_CPU0)