cancel
Showing results for 
Search instead for 
Did you mean: 

How to initialize external SRAM in system_stm32l4xx.c

Aaron McNeil
Associate III

I am trying to initialize my external SRAM before the main loop runs. Using the STCubeMX it generated the code for me to have me FMC controller initialized after Hal_init() and Hal_GPIO_Init() in Main.c. However, I need the SRAM to be initialized before this.

Doing some research I found that there is a SystemInit_ExtMemCtl() function inside System_init in STM32F4xx.c but I do not seem to have this function in the L4.

Any guidance or example for doing this would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions

Probably, but that's not the path I'd take.

Here doing QSPI, but illustrative of register level initialization

STM32Cube_FW_L4_V1.8.0\Projects\STM32L476G-Discovery\Examples\QSPI\QSPI_PreInitConfig\Src\system_stm32l4xx.c

STM32Cube_FW_L4_V1.8.0\Projects\STM32L476G_EVAL\Examples\QSPI\QSPI_PreInitConfig\Src\system_stm32l4xx.c

A way to get to the solution more simply is to configure the RCC, GPIO and FMC as you do currently, and dump out the register settings for the working configurations, noting the pins you're actually using, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

6 REPLIES 6

You can still call things in SystemInit(), but do have to be wary that the C runtime statics haven't been initialized. The CMSIS model was to do it there.

The CubeMX/HAL stuff move clock and board level initialization SystemClockConfiguration(), arguably this is too late. The HAL also has dependencies on SysTick and other things.

My approach would be to bring up the Clocks, PLL, pins and memory interfaces up in SystemInit() and avoid the bloat. The memories expect things to be clocking properly, and don't need to be initialized twice.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Aaron McNeil
Associate III

Thank you for the response.

So in order to initialize everything in SystemInit(), is it possible to still use the HAL Interface to do so?

Probably, but that's not the path I'd take.

Here doing QSPI, but illustrative of register level initialization

STM32Cube_FW_L4_V1.8.0\Projects\STM32L476G-Discovery\Examples\QSPI\QSPI_PreInitConfig\Src\system_stm32l4xx.c

STM32Cube_FW_L4_V1.8.0\Projects\STM32L476G_EVAL\Examples\QSPI\QSPI_PreInitConfig\Src\system_stm32l4xx.c

A way to get to the solution more simply is to configure the RCC, GPIO and FMC as you do currently, and dump out the register settings for the working configurations, noting the pins you're actually using, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Aaron McNeil
Associate III

Great info. Thank you.

One question with this method. Is it good practice to initialize the rcc and only the GPIO I am using with the external SRAM in System_Init and then in the main.c file still call Hal_GPIO_Init() to initialize the rest of my GPIO lines as well as the other Hal initialization functions for all my other peripherals?

I would still like to use the Hal library for everything else in my project, I just need to initialize the SRAM earlier.

When you're coming out of reset nothing is up, I would generally initialize things based on the board hw I'm working on. So you can enable all GPIO you're going to be using normally.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..