Skip to main content
Associate II
August 7, 2026
Question

How to put LPBAM link list variables in SRAM4 alone

  • August 7, 2026
  • 0 replies
  • 24 views

While using LPBAM in U5 series, it can only access to the SRAM4, but the official course of LPBAM just gives a solution of changing the address of RAM to SRAM4 in ld file. But this makes us can only use 16k SRAM4, not enough for many applications. 

And the cubeMX code is not setting in SRAM4 as default, is there any setting that I missed to set those?

I have a solution in code but not a very perfect one.

Put these to .ld file before  “_sidata = LOADADDR(.data)”, this will put all variables of LPBAM in SRAM4:

 .lpbam_sram4 :
{
. = ALIGN(4);
__lpbam_sram4_start = .;
./LPBAM*.o(.data .data* .bss .bss* COMMON)
. = ALIGN(4);
__lpbam_sram4_end = .;
} > SRAM4

the ./LPBAM* is used to match the LPBAM application folder.

 

And I found another problem, for the SRAM4 is not initiated in startup. so we need to put those before main(){}, to initiate the SRAM4 variables, or there will be errors:

/* USER CODE BEGIN PV */

extern uint8_t __lpbam_sram4_start;
extern uint8_t __lpbam_sram4_end;

/* USER CODE END PV */

/* USER CODE BEGIN 0 */

static void sram4_preinit(void)
{
uint32_t size = (uint32_t)&__lpbam_sram4_end - (uint32_t)&__lpbam_sram4_start;
if(size > 0U)
{
memset(&__lpbam_sram4_start, 0, size);
}
}

__attribute__((section(".preinit_array"))) void (*preinit_ptr)(void) = sram4_preinit;


/* USER CODE END 0 */

I think my solution is not the best one, it adds more steps to code planting and don’t know if there is risk. Is there any better solution? does ST provide any official solution to this problem?