Has anyone ported heap_useNewlib (for FreeRTOS) to PSoC 6?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
CaKu_4284131
Level 5
Level 5
50 replies posted 25 replies posted 10 likes received

I'm suddenly having to learn about newlib the hard way. I fell into a pitfall involving concurrency protection for malloc/free/etc. inside of sprintf using %f, [See long saga at Intermittent CM4 FAULT! Bus Fault! in floating point app - Kernel - FreeRTOS Community Forums]​ 

I think the main thing I needed is:

#define configUSE_NEWLIB_REENTRANT              1

in  FreeRTOSConfig.h. But now I'm having trouble with "ERROR: region RAM overflowed with stack."

I'm interested in trying Dave Nadler's heap_useNewlib. (See newlib and FreeRTOS ). I tried heap_useNewlib_NXP.c but it needs HEAP_SIZE in the linker file:

extern char __HeapBase, __HeapLimit, HEAP_SIZE;  // make sure to define these symbols in linker command file

static int heapBytesRemaining = (int)&HEAP_SIZE; // that's (&__HeapLimit)-(&__HeapBase)

__HeapBase and __HeapLimit are in cy8c6xx7_cm4_dual.ld, but not HEAP_SIZE. I imagine it's a simple thing to add, but I've never worked with ld files before, and my first attempt failed. Has anyone already been down this road?

0 Likes
1 Solution

That's where I got heap_useNewlib_NXP.c.

I did some reading about ld files. Here is the section of interest in cy8c6xx7_cm4_dual.ld:

    .heap (NOLOAD):

    {

        __HeapBase = .;

        __end__ = .;

        end = __end__;

        KEEP(*(.heap*))

        __HeapLimit = .;

    } > ram

I think I need to change that to something like this, and swap heap_4.c for heap_useNewlib_NXP.c:

   HEAP_SIZE = 0x7000; /* 28 kB */

    .heap (NOLOAD):

    {

        __HeapBase = .;

        __end__ = .;

        end = __end__;

        KEEP(*(.heap*))

        . = ALIGN(8);

        . = . + HEAP_SIZE;

        . = ALIGN(8);

        __HeapLimit = .;

    } > ram

However, I don't understand under what conditions PSoC Creator will regenerate cy8c6xx7_cm4_dual.ld and overwrite my changes.

View solution in original post

0 Likes
4 Replies
RiBa_4055821
Level 1
Level 1

Does the code linked from this FreeRTOS support forum post help?  Dave's FreeRTOS Helpers now on GitHub - Kernel - FreeRTOS Community Forums

0 Likes

That's where I got heap_useNewlib_NXP.c.

I did some reading about ld files. Here is the section of interest in cy8c6xx7_cm4_dual.ld:

    .heap (NOLOAD):

    {

        __HeapBase = .;

        __end__ = .;

        end = __end__;

        KEEP(*(.heap*))

        __HeapLimit = .;

    } > ram

I think I need to change that to something like this, and swap heap_4.c for heap_useNewlib_NXP.c:

   HEAP_SIZE = 0x7000; /* 28 kB */

    .heap (NOLOAD):

    {

        __HeapBase = .;

        __end__ = .;

        end = __end__;

        KEEP(*(.heap*))

        . = ALIGN(8);

        . = . + HEAP_SIZE;

        . = ALIGN(8);

        __HeapLimit = .;

    } > ram

However, I don't understand under what conditions PSoC Creator will regenerate cy8c6xx7_cm4_dual.ld and overwrite my changes.

0 Likes

Hi CaKu_4284131​,

However, I don't understand under what conditions PSoC Creator will regenerate cy8c6xx7_cm4_dual.ld and overwrite my changes.

PSoC Creator does try to overwrite the linker file when you change the PDL version used in the project. But it will ask for your permission before doing so.

You can also modify the linker script and create a custom linker script and provide the path in the Build Settings. This way the custom linker script will not be replaced even when you change the PDL version.

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B

Ah, great, thanks!

0 Likes