Skip to content

Commit

Permalink
heap-management: Use C memory management APIs
Browse files Browse the repository at this point in the history
We shouldn't be allocating heap using C and FreeRTOS
heap management APIs as we might end up with both FreeRTOS heap
and C heap. This can lead to several unexpected issues.

C standard heap functions are used to unify heap allocations
as we can't use FreeRTOS heap management APIs because this
would require patching lots of file as part of
ml-embedded-evaluation-kit library which use C standard heap
functions for heap allocations.

Heap space is increased by `0x10000` as C standard heap
management APIs requires more heap space for the existing
FRI applications because it is less optimised than FreeRTOS heap
management APIS (heap_4).

Signed-off-by: Ahmed Ismail <[email protected]>
  • Loading branch information
AhmedIsmail02 committed Mar 1, 2024
1 parent 148e59d commit b5f3193
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern uint32_t SystemCoreClock;
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE 720896
#define configTOTAL_HEAP_SIZE 0
#define configAPPLICATION_ALLOCATED_HEAP 0

#define configENABLE_MVE 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern uint32_t SystemCoreClock;
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE 720896
#define configTOTAL_HEAP_SIZE 0
#define configAPPLICATION_ALLOCATED_HEAP 0

#define configENABLE_MVE 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern uint32_t SystemCoreClock;
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE 720896
#define configTOTAL_HEAP_SIZE 0
#define configAPPLICATION_ALLOCATED_HEAP 0

#define configENABLE_MVE 0
Expand Down
2 changes: 1 addition & 1 deletion bsp/corstone300/an552_ns.ld
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ __RAM_SIZE = (0x00200000 - PROVISIONING_SIZE);
</h>
-----------------------------------------------------------------------------*/
__STACK_SIZE = 0x00001000;
__HEAP_SIZE = 0x000B0000;
__HEAP_SIZE = 0x000C0000;

/*
*-------------------- <<< end of configuration section >>> -------------------
Expand Down
2 changes: 1 addition & 1 deletion bsp/corstone300/an552_ns.sct
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LR_CODE (0x28000000 + ((((0) + (0x40000)) + (0x400)))) {

ARM_LIB_STACK +0 ALIGN 32 EMPTY (0x0001000) {
}
ARM_LIB_HEAP +0 ALIGN 8 EMPTY (0x00b0000) {
ARM_LIB_HEAP +0 ALIGN 8 EMPTY (0x00C0000) {
}

;-----------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion bsp/corstone310/an555_ns.ld
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ __RAM_SIZE = (ISRAM1_SIZE - PROVISIONING_SIZE);
</h>
-----------------------------------------------------------------------------*/
__STACK_SIZE = 0x00001000;
__HEAP_SIZE = 0x000B0000;
__HEAP_SIZE = 0x000C0000;

/*
*-------------------- <<< end of configuration section >>> -------------------
Expand Down
2 changes: 1 addition & 1 deletion bsp/corstone310/an555_ns.sct
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define ISRAM1_SIZE 0x00200000
#define PROVISIONING_SIZE 0x1000
#define STACK_SIZE 0x00001000
#define HEAP_SIZE 0x000B0000
#define HEAP_SIZE 0x000C0000

LR_CODE (ROM_START + ((((0) + (FLASH_S_PARTITION_SIZE)) + BL2_HEADER_SIZE))) {
ER_CODE (ROM_START + ((((0) + (FLASH_S_PARTITION_SIZE)) + BL2_HEADER_SIZE))) (((FLASH_NS_PARTITION_SIZE) - BL2_HEADER_SIZE - BL2_TRAILER_SIZE)) {
Expand Down
2 changes: 1 addition & 1 deletion components/freertos_kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(freertos_kernel_SOURCE_DIR
"Path to FreeRTOS-Kernel source code"
)

set(FREERTOS_HEAP "4" CACHE STRING "" FORCE)
set(FREERTOS_HEAP "${CMAKE_CURRENT_LIST_DIR}/integration/src/heap_management.c" CACHE STRING "" FORCE)

if(ARM_CORSTONE_BSP_TARGET_PLATFORM STREQUAL "corstone300")
set(FREERTOS_PORT GCC_ARM_CM55_TFM)
Expand Down
37 changes: 37 additions & 0 deletions components/freertos_kernel/integration/src/heap_management.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Copyright 2024 Arm Limited and/or its affiliates
* <[email protected]>
* SPDX-License-Identifier: MIT
*/

#include <stdlib.h>

void * pvPortMalloc( size_t xWantedSize )
{
return malloc( xWantedSize );
}

void vPortFree( void * pv )
{
free( pv );
}

void * pvPortCalloc( size_t xNum,
size_t xSize )
{
return calloc( xNum, xSize );
}

/* These are dummy implementations as C standard library does not provide
* functions to get the statistics of heap memory. These dummy implementation are needed
* as these APIs are used as part of FreeRTOS Plus TCP code which is unused in the FRI code (removed by the linker)
* but ARMClang linker requires all the compiled symbols to be defined.
*/
size_t xPortGetFreeHeapSize( void )
{
return 0;
}

size_t xPortGetMinimumEverFreeHeapSize( void )
{
return 0;
}
1 change: 1 addition & 0 deletions release_changes/202402261352.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
heap-management: Use C memory management APIs.

0 comments on commit b5f3193

Please sign in to comment.