Skip to main content
yang hong
Associate III
March 10, 2020
Question

malloc on NUCLEOSTM32F429ZI

  • March 10, 2020
  • 3 replies
  • 956 views

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.

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
March 10, 2020

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 VenmoUp vote any posts that you find helpful, it shows what's working..
yang hong
yang hongAuthor
Associate III
March 10, 2020

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?

Ozone
Principal
March 10, 2020

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
yang hongAuthor
Associate III
March 10, 2020

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