cancel
Showing results for 
Search instead for 
Did you mean: 

Usage SRAM1, SRAM2, SRAM3 with initialized arrays

larenge
Associate II

I changed linker to use all of these three memories in domain D2. Problem is next :

When i put for example

uint32_t tempArray[4] = {0x2B7E1516 ,0x28AED2A6 ,0xABF71588 ,0x09CF4F3C} __attribute__((section(".sram1")));

this line in my code, when MCU is in debug mode firstly on address of this array i see all zeroes. After calling __HAL_RCC_TIM2_CLK_ENABLE() macro, i can see data in those sram's but it is wrong initialized (random data).

Am I missing something? I read thru all documents RF, DS, AN's but neither one says that this memory is something specific. I used this part's of memory as DMA buffers for SDMMC2 and everything is working fine. Only problem is in initialized data.

I tried same code - just changed section to AXISRAM and everything is working as expected. So not problem in code.

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

You must enable the RAM clocks, and modify your startup code to deal with multiple section initialization, GNU/GCC does a crap job at this. Keil has table driven initialization which works properly/effectively for embedded.

I posted code to start SRAM clocks in Reset_Handler, will go dig for it.

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

8 REPLIES 8

You must enable the RAM clocks, and modify your startup code to deal with multiple section initialization, GNU/GCC does a crap job at this. Keil has table driven initialization which works properly/effectively for embedded.

I posted code to start SRAM clocks in Reset_Handler, will go dig for it.

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

https://community.st.com/s/question/0D50X0000A7XIH1SQO/want-to-store-data-in-sram-d2-domain-what-is-missing-to-avoid-hard-fault

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

Are you sure the SRAM1 is active when the startup script is copying your data from flash into there?

Edit: Clive was faster and with more information (:

You appear to be my doppelganger

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

Each compiler has a kind of startup() function to initialize the default values in RAM.

If the linker can't do properly the intialisation (because a clock enable is required prior to write to memory) or else, the RAM maybe random or previous hot reset values. In this case, to initialize from const to RAM by memcpy(), which was the service the statup was doing for you when ram were simple.

larenge
Associate II

I am not sure, and i see that clocks aren't enabled 🙂 but didn't know where to put it. Thanks @Community member​ for fast response. I will post results.

larenge
Associate II

@Community member​ @After Forever​ thanks both for quick reply. I added lines in SystemInit and everything OK.

Fast fast community 🙂

Best regards

That, my friend, would be an honour, but realistically, nobody here can compete with your consistency and knowledge (and your experience with Demogorgons) (: