cancel
Showing results for 
Search instead for 
Did you mean: 

malloc issue with 4K allocation in STM32F091CC

Youssouf Coulibaly
Associate II
Posted on November 09, 2017 at 11:14

Hi all,

I have an application when I need to reserve 4Kbytes of memory. This size is fixed during the whole life cycle of my application.

Therefore my first idea was to create a static memory allocation. But I also tried to use the malloc function to reserve 4K memory. I am using C++ and I am calling free function in my Class destructor.

But the problem I am facing is that my application rises a hard fault when i am calling other task (no operating system).

- Task 1 is for memory management function. 

- Task 2 is for UART communication.

So I have general question since that is my first time I am working on huge memory allocation is embedded device.

Is with malloc function in STM32F091 we can allocate 4kbytes of memory ?

What is about eh default heap size ? How can I explicitely increase the heap size ?

Thanks for your help.

Regards

4 REPLIES 4
Andrew Neil
Evangelist III
Posted on November 09, 2017 at 11:35

my first idea was to create a static memory allocation

So why don't you just do that?

Is with malloc function in STM32F091 we can allocate 4kbytes of memory ?

What is about eh default heap size ? How can I explicitely increase the heap size ?

These have nothing specifically to do with the chip - they depend on the particular toolchain you are using.

So - what 

toolchain

you are using?  Have you checked its documentation?
Andrew Neil
Evangelist III
Posted on November 09, 2017 at 11:38

The chip has 32K RAM. So 4K is not exactly 'huge' - though not insignificant ...

Youssouf Coulibaly
Associate II
Posted on November 09, 2017 at 11:58

Hello Andrew,

Thanks for your reply.

Yes the chip has 32K RAM and I double check in the linker script (defined addresses OK).

Even if I use static allocation, I have the same issue.

SCENARIO 1 : Error in execution

static const uint16_t SECTOR_LENGTH = 4096

//static uint8_t ptrSectorRAMSpace[SECTOR_LENGTH];     // Methode 1 static

uint8_t* ptrSectorRAMSpace = (uint8_t*)malloc(SECTOR_LENGTH); // Methode 2 dynamic

SCENARIO 2 : Error in excution

static const uint16_t SECTOR_LENGTH = 3840

//static uint8_t ptrSectorRAMSpace[SECTOR_LENGTH];     // Methode 1 static

uint8_t* ptrSectorRAMSpace = (uint8_t*)malloc(SECTOR_LENGTH); // Methode 2 dynamic

SCENARIO 3 : NO ERROR

static const uint16_t SECTOR_LENGTH = 3548

//static uint8_t ptrSectorRAMSpace[SECTOR_LENGTH];     // Methode 1 static

uint8_t* ptrSectorRAMSpace = (uint8_t*)malloc(SECTOR_LENGTH); // Methode 2 dynamic

TOOLCHAIN:

I am developing under TrueStudio using arm-atollic-eabi-g++ compiler.  

Posted on November 09, 2017 at 12:04

Youssouf Coulibaly wrote:

Even if I use static allocation, I have the same issue. 

So the issue is not to do with the dynamic allocation, then - is it?

Review standard techniques for debugging a Hard Fault; eg,

https://community.arm.com/iot/embedded/f/discussions/3257/debugging-a-cortex-m0-hard-fault

 

https://www.embedded.com/design/mcus-processors-and-socs/4457540/Debugging-hard-faults-in-ARM-Cortex-M0-based-SoCs

 

etc, ...