Skip to content

Commit 26cbc91

Browse files
committed
cc3200: Place functions only used while booting in a special section.
Such functions are never used after MicroPython has started, and they remain in RAM wasting space. Now they are placed in a special section named "boot" which sits just before the heap, allowing us to extend the effective heap area up to the new boot section. Right now, this gives us back ~1K, but in the future, more functions might end up in there as well.
1 parent 02fda44 commit 26cbc91

File tree

11 files changed

+71
-38
lines changed

11 files changed

+71
-38
lines changed

cc3200/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ static void prvTaskExitError( void );
202202
/*
203203
* See header file for description.
204204
*/
205+
__attribute__ ((section (".boot")))
205206
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
206207
{
207208
/* Simulate the stack frame as it would be created by a context switch
@@ -220,6 +221,7 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
220221
}
221222
/*-----------------------------------------------------------*/
222223

224+
__attribute__ ((section (".boot")))
223225
static void prvTaskExitError( void )
224226
{
225227
/* A function that implements a task must not exit or attempt to return to
@@ -254,6 +256,7 @@ void vPortSVCHandler( void )
254256
}
255257
/*-----------------------------------------------------------*/
256258

259+
__attribute__ ((section (".boot")))
257260
static void prvPortStartFirstTask( void )
258261
{
259262
__asm volatile(
@@ -274,6 +277,7 @@ static void prvPortStartFirstTask( void )
274277
/*
275278
* See header file for description.
276279
*/
280+
__attribute__ ((section (".boot")))
277281
BaseType_t xPortStartScheduler( void )
278282
{
279283
/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.
@@ -643,6 +647,7 @@ void xPortSysTickHandler( void )
643647
* Setup the systick timer to generate the tick interrupts at the required
644648
* frequency.
645649
*/
650+
__attribute__ ((section (".boot")))
646651
__attribute__(( weak )) void vPortSetupTimerInterrupt( void )
647652
{
648653
/* Calculate the constants required to configure the tick interrupt. */

cc3200/FreeRTOS/Source/tasks.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ static void prvResetNextTaskUnblockTime( void );
515515

516516
/*-----------------------------------------------------------*/
517517

518+
__attribute__ ((section (".boot")))
518519
BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, const MemoryRegion_t * const xRegions ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
519520
{
520521
BaseType_t xReturn;
@@ -1454,6 +1455,7 @@ TCB_t * pxNewTCB;
14541455
#endif /* ( ( INCLUDE_xTaskResumeFromISR == 1 ) && ( INCLUDE_vTaskSuspend == 1 ) ) */
14551456
/*-----------------------------------------------------------*/
14561457

1458+
__attribute__ ((section (".boot")))
14571459
void vTaskStartScheduler( void )
14581460
{
14591461
BaseType_t xReturn;
@@ -2700,7 +2702,7 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
27002702
}
27012703
#endif /* configUSE_TICKLESS_IDLE */
27022704
/*-----------------------------------------------------------*/
2703-
2705+
__attribute__ ((section (".boot")))
27042706
static void prvInitialiseTCBVariables( TCB_t * const pxTCB, const char * const pcName, UBaseType_t uxPriority, const MemoryRegion_t * const xRegions, const uint16_t usStackDepth ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
27052707
{
27062708
UBaseType_t x;
@@ -2809,7 +2811,7 @@ UBaseType_t x;
28092811

28102812
#endif /* portUSING_MPU_WRAPPERS */
28112813
/*-----------------------------------------------------------*/
2812-
2814+
__attribute__ ((section (".boot")))
28132815
static void prvInitialiseTaskLists( void )
28142816
{
28152817
UBaseType_t uxPriority;
@@ -2912,7 +2914,7 @@ static void prvAddCurrentTaskToDelayedList( const TickType_t xTimeToWake )
29122914
}
29132915
}
29142916
/*-----------------------------------------------------------*/
2915-
2917+
__attribute__ ((section (".boot")))
29162918
static TCB_t *prvAllocateTCBAndStack( const uint16_t usStackDepth, StackType_t * const puxStackBuffer )
29172919
{
29182920
TCB_t *pxNewTCB;

cc3200/application.lds

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ SECTIONS
8989
. = ALIGN(8);
9090
_ebss = .;
9191
} > SRAM
92+
93+
/* place here functions that are only called during boot up, */
94+
/* that way, we can re-use this area for the micropython heap */
95+
.boot :
96+
{
97+
. = ALIGN(8);
98+
_boot = .;
99+
*(.boot*)
100+
. = ALIGN(8);
101+
_eboot = .;
102+
} > SRAM
92103

93104
/* allocate the micropython heap */
94105
.heap :

cc3200/hal/cc3200_hal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ extern void (* const g_pfnVectors[256])(void);
7878
/******************************************************************************
7979
DEFINE PUBLIC FUNCTIONS
8080
******************************************************************************/
81-
81+
82+
__attribute__ ((section (".boot")))
8283
void HAL_SystemInit (void) {
8384
MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);
8485

cc3200/hal/startup_gcc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern uint32_t __init_data;
6060
// Forward declaration of the default fault handlers.
6161
//
6262
//*****************************************************************************
63+
__attribute__ ((section (".boot")))
6364
void ResetISR(void);
6465
#ifdef DEBUG
6566
static void NmiSR(void) __attribute__( ( naked ) );

cc3200/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ OsiTaskHandle mpTaskHandle;
5959
DEFINE PUBLIC FUNCTIONS
6060
******************************************************************************/
6161

62+
__attribute__ ((section (".boot")))
6263
int main (void) {
6364

6465
// Initialize the clocks and the interrupt system
@@ -82,7 +83,6 @@ int main (void) {
8283
for ( ; ; );
8384
}
8485

85-
8686
void stoupper (char *str) {
8787
while (str && *str != '\0') {
8888
*str = (char)toupper((int)(*str));

cc3200/mods/pybrtc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
/// rtc.datetime((2014, 5, 1, 4, 13, 0, 0, 0))
5252
/// print(rtc.datetime())
5353

54+
__attribute__ ((section (".boot")))
5455
void pybrtc_init(void) {
5556
// if RTC was previously set leave it alone
5657
if (MAP_PRCMSysResetCauseGet() == PRCM_POWER_ON) {

cc3200/mods/pybsd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ STATIC mp_obj_t pybsd_enable (mp_obj_t self_in);
7979
/******************************************************************************
8080
DECLARE PUBLIC FUNCTIONS
8181
******************************************************************************/
82+
__attribute__ ((section (".boot")))
8283
void pybsd_init0 (void) {
8384
// allocate memory for the sd file system
8485
ASSERT ((pybsd_obj.fatfs = mem_Malloc(sizeof(FATFS))) != NULL);

cc3200/mptask.c

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@
6969
/******************************************************************************
7070
DECLARE PRIVATE FUNCTIONS
7171
******************************************************************************/
72-
STATIC void main_init_sflash_filesystem (void);
73-
STATIC void main_enter_ap_mode (void);
74-
STATIC void main_create_main_py (void);
72+
STATIC void mptask_pre_init (void);
73+
STATIC void mptask_init_sflash_filesystem (void);
74+
STATIC void mptask_enter_ap_mode (void);
75+
STATIC void mptask_create_main_py (void);
7576

7677
/******************************************************************************
7778
DECLARE PUBLIC DATA
@@ -100,39 +101,18 @@ void TASK_Micropython (void *pvParameters) {
100101
bool safeboot;
101102
FRESULT res;
102103

103-
#if MICROPY_HW_ENABLE_RTC
104-
pybrtc_init();
105-
#endif
106-
107104
#ifdef DEBUG
108105
safeboot = false;
109106
#else
110107
safeboot = mperror_safe_boot_requested();
111108
#endif
112109

113-
// Create the simple link spawn task
114-
ASSERT (OSI_OK == VStartSimpleLinkSpawnTask(SIMPLELINK_SPAWN_TASK_PRIORITY));
115-
116-
// Allocate memory for the flash file system
117-
ASSERT ((sflash_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
118-
#if MICROPY_HW_HAS_SDCARD
119-
pybsd_init0();
120-
#endif
121-
122-
#ifdef DEBUG
123-
ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers,
124-
(const signed char *)"Servers",
125-
SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, &svTaskHandle));
126-
#else
127-
ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers,
128-
(const signed char *)"Servers",
129-
SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, NULL));
130-
#endif
110+
mptask_pre_init ();
131111

132112
soft_reset:
133113

134114
// GC init
135-
gc_init(&_heap, &_eheap);
115+
gc_init(&_boot, &_eheap);
136116

137117
// Micro Python init
138118
mp_init();
@@ -167,13 +147,13 @@ void TASK_Micropython (void *pvParameters) {
167147

168148
mperror_enable_heartbeat();
169149

170-
main_enter_ap_mode();
150+
mptask_enter_ap_mode();
171151

172152
// enable telnet and ftp servers
173153
servers_enable();
174154

175155
// initialize the serial flash file system
176-
main_init_sflash_filesystem();
156+
mptask_init_sflash_filesystem();
177157

178158
// append the SFLASH paths to the system path
179159
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_SFLASH));
@@ -268,8 +248,34 @@ void TASK_Micropython (void *pvParameters) {
268248
/******************************************************************************
269249
DEFINE PRIVATE FUNCTIONS
270250
******************************************************************************/
251+
__attribute__ ((section (".boot")))
252+
STATIC void mptask_pre_init (void) {
253+
#if MICROPY_HW_ENABLE_RTC
254+
pybrtc_init();
255+
#endif
256+
257+
// Create the simple link spawn task
258+
ASSERT (OSI_OK == VStartSimpleLinkSpawnTask(SIMPLELINK_SPAWN_TASK_PRIORITY));
259+
260+
// Allocate memory for the flash file system
261+
ASSERT ((sflash_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);
262+
263+
#if MICROPY_HW_HAS_SDCARD
264+
pybsd_init0();
265+
#endif
266+
267+
#ifdef DEBUG
268+
ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers,
269+
(const signed char *)"Servers",
270+
SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, &svTaskHandle));
271+
#else
272+
ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers,
273+
(const signed char *)"Servers",
274+
SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, NULL));
275+
#endif
276+
}
271277

272-
STATIC void main_init_sflash_filesystem (void) {
278+
STATIC void mptask_init_sflash_filesystem (void) {
273279
// Initialise the local flash filesystem.
274280
// Create it if needed, and mount in on /sflash.
275281
// try to mount the flash
@@ -283,13 +289,13 @@ STATIC void main_init_sflash_filesystem (void) {
283289
__fatal_error("could not create /SFLASH file system");
284290
}
285291
// create empty main.py
286-
main_create_main_py();
292+
mptask_create_main_py();
287293
} else if (res == FR_OK) {
288294
// mount sucessful
289295
FILINFO fno;
290296
if (FR_OK != f_stat("/SFLASH/MAIN.PY", &fno)) {
291297
// create empty main.py
292-
main_create_main_py();
298+
mptask_create_main_py();
293299
}
294300
} else {
295301
__fatal_error("could not create /SFLASH file system");
@@ -321,14 +327,14 @@ STATIC void main_init_sflash_filesystem (void) {
321327
}
322328
}
323329

324-
STATIC void main_enter_ap_mode (void) {
330+
STATIC void mptask_enter_ap_mode (void) {
325331
// Enable simplelink in low power mode
326332
wlan_sl_enable (ROLE_AP, SERVERS_DEF_AP_SSID, strlen(SERVERS_DEF_AP_SSID), SERVERS_DEF_AP_SECURITY,
327333
SERVERS_DEF_AP_KEY, strlen(SERVERS_DEF_AP_KEY), SERVERS_DEF_AP_CHANNEL);
328334
wlan_set_pm_policy (SL_NORMAL_POLICY);
329335
}
330336

331-
STATIC void main_create_main_py (void) {
337+
STATIC void mptask_create_main_py (void) {
332338
// create empty main.py
333339
FIL fp;
334340
f_open(&fp, "/SFLASH/MAIN.PY", FA_WRITE | FA_CREATE_ALWAYS);

cc3200/simplelink/oslib/osi_freertos.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ OsiReturnVal_e osi_LockObjCreate(OsiLockObj_t* pLockObj)
275275
\note
276276
\warning
277277
*/
278+
__attribute__ ((section (".boot")))
278279
OsiReturnVal_e osi_TaskCreate(P_OSI_TASK_ENTRY pEntry,const signed char * const pcName,
279280
unsigned short usStackDepth, void *pvParameters,
280281
unsigned long uxPriority,OsiTaskHandle* pTaskHandle)
@@ -449,6 +450,7 @@ void vSimpleLinkSpawnTask(void *pvParameters)
449450
\note
450451
\warning
451452
*/
453+
__attribute__ ((section (".boot")))
452454
OsiReturnVal_e VStartSimpleLinkSpawnTask(unsigned portBASE_TYPE uxPriority)
453455
{
454456
xSimpleLinkSpawnQueue = xQueueCreate( slQUEUE_SIZE, sizeof( tSimpleLinkSpawnMsg ) );
@@ -666,6 +668,7 @@ void osi_ExitCritical(void)
666668
\note
667669
\warning
668670
*/
671+
__attribute__ ((section (".boot")))
669672
void osi_start()
670673
{
671674
vTaskStartScheduler();

0 commit comments

Comments
 (0)