Skip to content

Commit 469c623

Browse files
committed
cc3200: Shrink the FreeRTOS heap and place TCB+stack in freed location.
The 16k FreeRTOS heap originally had all TCBs and stacks dynamically allocated within it (plus semaphores and some other things). Now that xTaskCreateStatic is used instead of xTaskCreate, the TCBs and stacks are allocated statically and no longer use any of the FreeRTOS heap. Therefore, the FreeRTOS stack can be shrunk by the amount that has been made static. Furthermore, the TCBs and stack that are now static should be placed in the .rtos_heaps section of RAM because this RAM is treated specially by the bootloader (the bootloader executes from the first 16k of RAM and loads the firmware into the section starting after the 16k). After this patch the FreeRTOS heap (ucHeap) is 7200 bytes. The memory available for the MicroPython heap is 54936 bytes (including GC overhead).
1 parent e098eac commit 469c623

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

cc3200/FreeRTOS/FreeRTOSConfig.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@
8484
#define configCPU_CLOCK_HZ ( ( unsigned long ) 80000000 )
8585
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
8686
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 72 )
87-
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 16384 ) )
87+
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( \
88+
16384 /* 16kbytes for FreeRTOS data structures and heap */ \
89+
- sizeof(StaticTask_t) - configMINIMAL_STACK_SIZE * sizeof(StackType_t) /* TCB+stack for idle task */ \
90+
- sizeof(StaticTask_t) - 1024 /* TCB+stack for servers task */ \
91+
- sizeof(StaticTask_t) - 6656 /* TCB+stack for main MicroPython task */ \
92+
- sizeof(StaticTask_t) - 896 /* TCB+stack for simplelink spawn task */ \
93+
) )
8894
#define configMAX_TASK_NAME_LEN ( 8 )
8995
#define configUSE_TRACE_FACILITY 0
9096
#define configUSE_16_BIT_TICKS 0

cc3200/main.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
DECLARE PRIVATE DATA
5151
******************************************************************************/
5252

53+
// This is the static memory (TCB and stack) for the idle task
54+
static StaticTask_t xIdleTaskTCB __attribute__ ((section (".rtos_heap")));
55+
static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
56+
5357
/******************************************************************************
5458
DECLARE PUBLIC DATA
5559
******************************************************************************/
@@ -61,8 +65,8 @@ OsiTaskHandle mpTaskHandle;
6165
uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
6266

6367
// This is the static memory (TCB and stack) for the main MicroPython task
64-
StaticTask_t mpTaskTCB;
65-
StackType_t mpTaskStack[MICROPY_TASK_STACK_LEN] __attribute__((aligned (8)));
68+
StaticTask_t mpTaskTCB __attribute__ ((section (".rtos_heap")));
69+
StackType_t mpTaskStack[MICROPY_TASK_STACK_LEN] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
6670

6771
/******************************************************************************
6872
DEFINE PUBLIC FUNCTIONS
@@ -105,9 +109,6 @@ void stoupper (char *str) {
105109
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer,
106110
StackType_t **ppxIdleTaskStackBuffer,
107111
uint32_t *pulIdleTaskStackSize ) {
108-
static StaticTask_t xIdleTaskTCB;
109-
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
110-
111112
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
112113
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
113114
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;

cc3200/serverstask.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,11 @@ static volatile bool sleep_sockets = false;
6767
/******************************************************************************
6868
DECLARE PUBLIC DATA
6969
******************************************************************************/
70-
StaticTask_t svTaskTCB;
71-
StackType_t svTaskStack[SERVERS_STACK_LEN] __attribute__((aligned (8)));
70+
71+
// This is the static memory (TCB and stack) for the servers task
72+
StaticTask_t svTaskTCB __attribute__ ((section (".rtos_heap")));
73+
StackType_t svTaskStack[SERVERS_STACK_LEN] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
74+
7275
char servers_user[SERVERS_USER_PASS_LEN_MAX + 1];
7376
char servers_pass[SERVERS_USER_PASS_LEN_MAX + 1];
7477

cc3200/simplelink/oslib/osi_freertos.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ TaskHandle_t xSimpleLinkSpawnTaskHndl = NULL;
6262
#define SL_SPAWN_MAX_WAIT_MS ( 200 )
6363

6464
// This is the static memory (TCB and stack) for the SL spawn task
65-
static StaticTask_t spawnTaskTCB;
66-
static portSTACK_TYPE spawnTaskStack[896 / sizeof(portSTACK_TYPE)] __attribute__((aligned (8)));
65+
static StaticTask_t spawnTaskTCB __attribute__ ((section (".rtos_heap")));
66+
static portSTACK_TYPE spawnTaskStack[896 / sizeof(portSTACK_TYPE)] __attribute__ ((section (".rtos_heap"))) __attribute__((aligned (8)));
6767

6868
/*!
6969
\brief This function registers an interrupt in NVIC table

0 commit comments

Comments
 (0)