cancel
Showing results for 
Search instead for 
Did you mean: 

SDRAM Malloc and printf / sinit crash

CedricB
Associate II

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

2 REPLIES 2
Paul1
Lead

Suggest: Two different malloc

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

Paul

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
Up vote any posts that you find helpful, it shows what's working..