Skip to main content
EBotö.1
Associate II
Mar 14, 2023 10:40 AM UTC
Solved

Linker script not placing MB_MEM2 in SRAM2

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.)

This topic has been closed for replies.
EBotö.1
EBotö.1Best answer
Associate II
Mar 14, 2023 3:53 PM UTC

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.

4 replies

Pavel A.
Mar 14, 2023 12:38 PM UTC

> 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.

EBotö.1
EBotö.1AuthorBest answer
Associate II
Mar 14, 2023 3:53 PM UTC

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 Technical Moderator
Mar 24, 2023 6:51 PM UTC

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
Visitor II
May 11, 2023 11:56 PM UTC

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.