cancel
Showing results for 
Search instead for 
Did you mean: 

Linker script not placing MB_MEM2 in SRAM2

EBotö.1
Associate II

I'm using a NUCLEO-WB55RG board and if I create a new project in STM32CubeIDE 1.12.0 and enable the STM32_WPAN and HeartRate example it doesn't work because the different buffers that need to be in SRAM2 is not placed there.

The app_entry.c defines these buffers like this:

PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t EvtPool[POOL_SIZE];
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static TL_CmdPacket_t SystemCmdBuffer;
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t SystemSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255U];
PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t BleSpareEvtBuffer[sizeof(TL_PacketHeader_t) + TL_EVT_HDR_SIZE + 255];

The automatically generated linker script contains the following, which ends up placing the buffers in RAM1 if I look at the address at runtime using the debugger.

/* Specify the memory areas */
MEMORY
{
FLASH (rx)                 : ORIGIN = 0x08000000, LENGTH = 512K
RAM1 (xrw)                 : ORIGIN = 0x20000008, LENGTH = 0x2FFF8
RAM_SHARED (xrw)           : ORIGIN = 0x20030000, LENGTH = 10K
}
 
<--snipped-->
 
   MB_MEM1 (NOLOAD)       : { *(MB_MEM1) } >RAM_SHARED
 
   /* used by the startup to initialize .MB_MEM2 data */
  _siMB_MEM2 = LOADADDR(.MB_MEM2);
  .MB_MEM2 :
  {
    _sMB_MEM2 = . ;
    *(.MB_MEM2) ;
    _eMB_MEM2 = . ;
  } >RAM_SHARED AT> FLASH

If I instead create a new project based on the BLE_HeartRate example from "Example Selector", the linker script instead contain:

/* Specify the memory areas */
MEMORY
{
FLASH (rx)                 : ORIGIN = 0x08000000, LENGTH = 512K
RAM1 (xrw)                 : ORIGIN = 0x20000008, LENGTH = 0x2FFF8
RAM_SHARED (xrw)           : ORIGIN = 0x20030000, LENGTH = 10K
}
 
<--snipped-->
 
   MB_MEM1 (NOLOAD)       : { *(MB_MEM1) } >RAM_SHARED
   MB_MEM2 (NOLOAD)       : { _sMB_MEM2 = . ; *(MB_MEM2) ; _eMB_MEM2 = . ; } >RAM_SHARED

And this works just fine, and the buffers are placed in SRAM2.

I can solve the issue by creating my own section, placing it in RAM_SHARED, or by just editing app_entry.c to place them in MB_RAM1 which is also correctly placed in RAM_SHARED / SRAM2, but if feels like this is a bug that will probably confuse a lot of other people as well.

(My linked script knowledge is a bit limited, so I don't really understand why the auto-generated linker script ends up placing the section in the wrong place.)

1 ACCEPTED SOLUTION

Accepted Solutions

That makes sense, and if I change it the linker script works as intended. Thanks for pointing it out!

I guess this is a bug in the auto-generated linker script then? Since the code generator generated code that is marked to go into the "MB_MEM2" without the dot, it would make sense if this is what the linker script used as well.

View solution in original post

4 REPLIES 4
Pavel A.
Evangelist III

> I don't really understand why the auto-generated linker script ends up placing the section in the wrong place

Because in the 1st link script snippet the section name is ".MB_MEM2" (note the dot) but it should be "MB_MEM2" without dot.

That makes sense, and if I change it the linker script works as intended. Thanks for pointing it out!

I guess this is a bug in the auto-generated linker script then? Since the code generator generated code that is marked to go into the "MB_MEM2" without the dot, it would make sense if this is what the linker script used as well.

Remy ISSALYS
ST Employee

Hello,

Thanks for your feedback, indeed there is an extra dot in auto-generated linker script. It will be corrected in the next release.

Best Regards

NA.7
Associate

Faced the same issue with STM32WB10CC which was not entering Low-power mode, turns out having this section in wrong place was creating issue with LPM. Changed in a similar fashion as mentioned in STM32WB15CC example and worked afterwards.