Skip to main content
larenge
Associate II
April 2, 2019
Solved

Usage SRAM1, SRAM2, SRAM3 with initialized arrays

  • April 2, 2019
  • 8 replies
  • 2633 views

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

This topic has been closed for replies.
Best answer by Tesla DeLorean

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.

8 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
April 2, 2019

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
April 2, 2019
Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
After Forever
Senior III
April 2, 2019

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 (:

Tesla DeLorean
Guru
April 2, 2019

You appear to be my doppelganger

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
After Forever
Senior III
April 2, 2019

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

S.Ma
Principal
April 2, 2019

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
larengeAuthor
Associate II
April 2, 2019

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
larengeAuthor
Associate II
April 2, 2019

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

Fast fast community :)

Best regards