1717#include "fsl_clock_config.h"
1818#include "fsl_clock.h"
1919#include "fsl_xbara.h"
20+ #include "fsl_iomuxc.h"
21+ #include "fsl_gpio.h"
2022#include "lpm.h"
2123
2224#define LPSPI_CLOCK_SOURCE_DIVIDER (7U)
@@ -40,10 +42,10 @@ void BOARD_ConfigMPU(void)
4042
4143 /* MPU configure:
4244 * Use ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size)
43- * API in core_cm7 .h.
45+ * API in mpu_armv7 .h.
4446 * param DisableExec Instruction access (XN) disable bit,0=instruction fetches enabled, 1=instruction fetches disabled.
4547 * param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
46- * Use MACROS defined in core_cm7 .h: ARM_MPU_AP_NONE/ARM_MPU_AP_PRIV/ARM_MPU_AP_URO/ARM_MPU_AP_FULL/ARM_MPU_AP_PRO/ARM_MPU_AP_RO
48+ * Use MACROS defined in mpu_armv7 .h: ARM_MPU_AP_NONE/ARM_MPU_AP_PRIV/ARM_MPU_AP_URO/ARM_MPU_AP_FULL/ARM_MPU_AP_PRO/ARM_MPU_AP_RO
4749 * Combine TypeExtField/IsShareable/IsCacheable/IsBufferable to configure MPU memory access attributes.
4850 * TypeExtField IsShareable IsCacheable IsBufferable Memory Attribtue Shareability Cache
4951 * 0 x 0 0 Strongly Ordered shareable
@@ -60,26 +62,22 @@ void BOARD_ConfigMPU(void)
6062 * Above are normal use settings, if your want to see more details or want to config different inner/outter cache policy.
6163 * please refer to Table 4-55 /4-56 in arm cortex-M7 generic user guide <dui0646b_cortex_m7_dgug.pdf>
6264 * param SubRegionDisable Sub-region disable field. 0=sub-region is enabled, 1=sub-region is disabled.
63- * param Size Region size of the region to be configured. use ARM_MPU_REGION_SIZE_xxx MACRO in core_cm7 .h.
65+ * param Size Region size of the region to be configured. use ARM_MPU_REGION_SIZE_xxx MACRO in mpu_armv7 .h.
6466 */
6567
6668 /* Region 0 setting: Memory with Device type, not shareable, non-cacheable. */
67- MPU -> RBAR = ARM_MPU_RBAR (0 , 0xC0000000U );
69+ MPU -> RBAR = ARM_MPU_RBAR (0 , 0x80000000U );
6870 MPU -> RASR = ARM_MPU_RASR (0 , ARM_MPU_AP_FULL , 2 , 0 , 0 , 0 , 0 , ARM_MPU_REGION_SIZE_512MB );
6971
7072 /* Region 1 setting: Memory with Device type, not shareable, non-cacheable. */
71- MPU -> RBAR = ARM_MPU_RBAR (1 , 0x80000000U );
72- MPU -> RASR = ARM_MPU_RASR (0 , ARM_MPU_AP_FULL , 2 , 0 , 0 , 0 , 0 , ARM_MPU_REGION_SIZE_1GB );
73+ MPU -> RBAR = ARM_MPU_RBAR (1 , 0x60000000U );
74+ MPU -> RASR = ARM_MPU_RASR (0 , ARM_MPU_AP_FULL , 2 , 0 , 0 , 0 , 0 , ARM_MPU_REGION_SIZE_512MB );
7375
74- /* Region 2 setting */
76+ /* Region 2 setting */
7577#if defined(XIP_EXTERNAL_FLASH ) && (XIP_EXTERNAL_FLASH == 1 )
7678 /* Setting Memory with Normal type, not shareable, outer/inner write back. */
7779 MPU -> RBAR = ARM_MPU_RBAR (2 , 0x60000000U );
78- MPU -> RASR = ARM_MPU_RASR (0 , ARM_MPU_AP_FULL , 0 , 0 , 1 , 1 , 0 , ARM_MPU_REGION_SIZE_512MB );
79- #else
80- /* Setting Memory with Device type, not shareable, non-cacheable. */
81- MPU -> RBAR = ARM_MPU_RBAR (2 , 0x60000000U );
82- MPU -> RASR = ARM_MPU_RASR (0 , ARM_MPU_AP_FULL , 2 , 0 , 0 , 0 , 0 , ARM_MPU_REGION_SIZE_512MB );
80+ MPU -> RASR = ARM_MPU_RASR (0 , ARM_MPU_AP_RO , 0 , 0 , 1 , 1 , 0 , ARM_MPU_REGION_SIZE_64MB );
8381#endif
8482
8583 /* Region 3 setting: Memory with Device type, not shareable, non-cacheable. */
@@ -98,9 +96,9 @@ void BOARD_ConfigMPU(void)
9896 MPU -> RBAR = ARM_MPU_RBAR (6 , 0x20200000U );
9997 MPU -> RASR = ARM_MPU_RASR (0 , ARM_MPU_AP_FULL , 0 , 0 , 1 , 1 , 0 , ARM_MPU_REGION_SIZE_256KB );
10098
101- /* The define sets the cacheable memory to shareable,
102- * this suggestion is referred from chapter 2.2.1 Memory regions,
103- * types and attributes in Cortex-M7 Devices, Generic User Guide */
99+ /* The define sets the cacheable memory to shareable,
100+ * this suggestion is referred from chapter 2.2.1 Memory regions,
101+ * types and attributes in Cortex-M7 Devices, Generic User Guide */
104102#if defined(SDRAM_IS_SHAREABLE )
105103 /* Region 7 setting: Memory with Normal type, shareable, outer/inner write back, write/read allocate */
106104 MPU -> RBAR = ARM_MPU_RBAR (7 , 0x80000000U );
@@ -125,38 +123,44 @@ void BOARD_ConfigMPU(void)
125123 SCB_EnableICache ();
126124}
127125
128- #if defined(TOOLCHAIN_GCC_ARM )
129- extern uint32_t __ram_function_flash_start [];
130- #define __RAM_FUNCTION_FLASH_START __ram_function_flash_start
131- extern uint32_t __ram_function_ram_start [];
132- #define __RAM_FUNCTION_RAM_START __ram_function_ram_start
133- extern uint32_t __ram_function_size [];
134- #define __RAM_FUNCTION_SIZE __ram_function_size
135- void Board_CopyToRam ()
136- {
137- unsigned char * source ;
138- unsigned char * destiny ;
139- unsigned int size ;
140-
141- source = (unsigned char * )(__RAM_FUNCTION_FLASH_START );
142- destiny = (unsigned char * )(__RAM_FUNCTION_RAM_START );
143- size = (unsigned long )(__RAM_FUNCTION_SIZE );
144-
145- while (size -- )
146- {
147- * destiny ++ = * source ++ ;
148- }
126+ void BOARD_Init_PMIC_STBY_REQ (void ) {
127+ CLOCK_EnableClock (kCLOCK_IomuxcSnvs ); /* iomuxc_snvs clock (iomuxc_snvs_clk_enable): 0x03U */
128+
129+ /* GPIO configuration of PERI_PWREN on PMIC_STBY_REQ (pin L7) */
130+ gpio_pin_config_t PERI_PWREN_config = {
131+ .direction = kGPIO_DigitalOutput ,
132+ .outputLogic = 0U ,
133+ .interruptMode = kGPIO_NoIntmode
134+ };
135+ /* Initialize GPIO functionality on PMIC_STBY_REQ (pin L7) */
136+ GPIO_PinInit (GPIO5 , 2U , & PERI_PWREN_config );
137+
138+ IOMUXC_SetPinMux (
139+ IOMUXC_SNVS_PMIC_STBY_REQ_GPIO5_IO02 , /* PMIC_STBY_REQ is configured as GPIO5_IO02 */
140+ 0U ); /* Software Input On Field: Input Path is determined by functionality */
141+ IOMUXC_SetPinConfig (
142+ IOMUXC_SNVS_PMIC_STBY_REQ_GPIO5_IO02 , /* PMIC_STBY_REQ PAD functional properties : */
143+ 0x10B0U ); /* Slew Rate Field: Slow Slew Rate
144+ Drive Strength Field: R0/6
145+ Speed Field: medium(100MHz)
146+ Open Drain Enable Field: Open Drain Disabled
147+ Pull / Keep Enable Field: Pull/Keeper Enabled
148+ Pull / Keep Select Field: Keeper
149+ Pull Up / Down Config. Field: 100K Ohm Pull Down
150+ Hyst. Enable Field: Hysteresis Disabled */
149151}
150- #endif
151152
152153// called before main
153154void mbed_sdk_init ()
154155{
155156 BOARD_ConfigMPU ();
156157 BOARD_BootClockRUN ();
157- #if defined(TOOLCHAIN_GCC_ARM )
158- Board_CopyToRam ();
159- #endif
158+
159+ /* Since SNVS_PMIC_STBY_REQ_GPIO5_IO02 will output a high-level signal under Stop Mode(Suspend Mode) and this pin is
160+ * connected to LCD power switch circuit. So it needs to be configured as a low-level output GPIO to reduce the
161+ * current. */
162+ BOARD_Init_PMIC_STBY_REQ ();
163+
160164 LPM_Init ();
161165}
162166
@@ -187,16 +191,15 @@ uint32_t us_ticker_get_clock()
187191
188192void serial_setup_clock (void )
189193{
190- /* We assume default PLL and divider settings */
194+ /* Configure UART divider to default */
195+ CLOCK_SetMux (kCLOCK_UartMux , 1 ); /* Set UART source to OSC 24M */
196+ CLOCK_SetDiv (kCLOCK_UartDiv , 0 ); /* Set UART divider to 1 */
191197}
192198
193199uint32_t serial_get_clock (void )
194200{
195201 uint32_t clock_freq ;
196202
197- /* We assume default PLL and divider settings, and the only variable
198- * from application is use PLL3 source or OSC source
199- */
200203 if (CLOCK_GetMux (kCLOCK_UartMux ) == 0 ) /* PLL3 div6 80M */ {
201204 clock_freq = (CLOCK_GetPllFreq (kCLOCK_PllUsb1 ) / 6U ) / (CLOCK_GetDiv (kCLOCK_UartDiv ) + 1U );
202205 } else {
0 commit comments