cancel
Showing results for 
Search instead for 
Did you mean: 

malloc on NUCLEOSTM32F429ZI

yang hong
Associate II

I want to use malloc to dynamically open a data buffer for my program.

my code is followed:

uint8_t *pModbus_Memory;

pModbus_Memory=malloc(2048*sizeof(uint8_t));

memset(pModbus_Memory,6,2048);

I can't set value for my opened memory. and also memcpy doesn't work either.

Does anybody know why?

Thank you for any advice.

4 REPLIES 4

Using what tool? Keil needs you to define the heap size in startup.s

You should also NULL check the returned pointer to see if malloc() actually has memory to give you.

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

In addition - if you don't port code that makes frequent use of the clib malloc functionaliy, better avoid it.

Use a static memory layout instead.

yang hong
Associate II

I am using SW4STM32. In fact I only get 0 as return value. If I need, how can i do it?

ok, I know it looks like I try to open free memory on flash memory, I think that is why malloc or calloc can't work, could I use ram for these my memory ? how can i do it?