Skip to main content
CedricB
Associate
February 7, 2022
Question

SDRAM Malloc and printf / sinit crash

  • February 7, 2022
  • 2 replies
  • 1223 views

Hello,

I'm using an STM32H743-EVAL2 board, I want to access the LCD screen to draw a PNG image, so I'm using a png library to load the image, and this library use "malloc".

Unfortunately the RAM of the H743 is too small for handling large pictures, so I redirected the malloc heap to SDRAM by modifying the function _sbrk.

This is working fine, however when I try to use printf to output to UART1, the prinf calls _puts_r, which call __sinit, __sfp, __sfmoreglue, _malloc_r, _sbrk_r, and that returns an address in SDRAM, but it seems like this space allocated in SDRAM is not suitable for the function sinit because it crash (OnError_Handler is called)

If the malloc is not redirected to SDRAM, then printf is working fine.

Can someone tell me why ? and how can I make the 2 work from SDRAM ?

Thank you

This topic has been closed for replies.

2 replies

Paul1
Senior III
February 7, 2022

Suggest: Two different malloc

Rename malloc in the new code to something like malloc_sdram() so it doesn't conflict with other code.

Paul

Tesla DeLorean
Guru
February 8, 2022

Perhaps instrument malloc/free to understand what's happening there, and debug what's actually failing in the C libraries.

Validate the SDRAM thoroughly, especially unaligned accesses.

Make sure the SDRAM is up early, in SystemInit() no halfway thru main()

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