2020-03-10 08:18 AM
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.
2020-03-10 08:22 AM
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.
2020-03-10 08:37 AM
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.
2020-03-10 09:07 AM
I am using SW4STM32. In fact I only get 0 as return value. If I need, how can i do it?
2020-03-10 10:41 AM
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?