LPC 1758 1768 IAP (In Application Programming)

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by m20003293 on Mon Mar 28 12:17:27 MST 2011
[FONT=Courier New][SIZE=2]I am using FreeRTOS, and it needs to load variables from Flash before starting tasks.[/SIZE][/FONT]

[SIZE=2][FONT=Courier New]The main entry code for FreeRTOS looks as follows:[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]int main(void)[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]/* Call SystemCoreClockUpdate such that SystemCoreClock holds correct[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]* value.[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]*/[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]SystemCoreClockUpdate();[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]__disable_irq();[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]// This stores variables to flash, then reads them using IAP, so far so good...[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]SaveDefaultValues();[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]LoadAllValues();[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]__enable_irq();[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]// Every module has at least the following tasks running:[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]xQ_MODBUS_UART_S = xQueueCreate( QS_MODBUS_UART_S, sizeof(Q_MESSAGE));[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]vMBPInit( );[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]vTaskStartScheduler( );[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]return 0 ;[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]}[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]For testing, the code first saves the default values to flash, (Bank 15 at 0x0000F000) using code derived from the Flash USB boot functions (IAP).[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]The strange thing is, when stepping through the code, all flash functions are executed successfully.[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]If I look in the Flash Memory at the specified location, it shows the correct values, and after reading from flash the correct values reside in RAM.[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]So far so good,[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]BUT: When the vTaskStartScheduler is called, the tasks should start running, but they never enter running state.[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]When I suspend the code, it always resides in:[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]static void prvCheckTasksWaitingTermination( void )[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]#if ( INCLUDE_vTaskDelete == 1 )[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]portBASE_TYPE xListIsEmpty;[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]/* ucTasksDeleted is used to prevent vTaskSuspendAll() being called[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]too often in the idle task. */[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]if( uxTasksDeleted > ( unsigned portBASE_TYPE ) 0 )[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]vTaskSuspendAll();[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination );[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]xTaskResumeAll();[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]if( !xListIsEmpty )[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]tskTCB *pxTCB;[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) );[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]vListRemove( &( pxTCB->xGenericListItem ) );[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]--uxCurrentNumberOfTasks;[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]--uxTasksDeleted;[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]portEXIT_CRITICAL();[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]prvDeleteTCB( pxTCB );[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]#endif[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]}[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]The value of uxTasksDeleted = 0.[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]The code never leaves this function, so it seems the scheduler cannot function properly anymore.[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]When I remove the Flash related code from the startup code (SaveDefaultValues and LoadAllValues), the system starts normally with tasks running as they should.[/FONT][/SIZE]

[SIZE=2][FONT=Courier New]Is it possible using IAP changes something in the system state, preventing FreeRTOS to schedule normally ?[/FONT][/SIZE]
[SIZE=2][FONT=Courier New]Is there some information on how to use IAP in combination with FreeRTOS ?[/FONT][/SIZE]
[FONT=Courier New][SIZE=2]According to Code Red (the programming environment is theirs) it should reserve 32 bytes from the start of RAM in order to properly use the IAP functions. [/SIZE][/FONT]
[SIZE=2][FONT=Courier New]I have enabled the GUI setting in Code Red for this.[/FONT][/SIZE]
[FONT=Courier New][SIZE=2]However, perhaps there is something else I need to do (in FreeRTOS settings??) to reserve those bytes...[/SIZE][/FONT]

[SIZE=2][FONT=Courier New]Any help is appreciated[/FONT][/SIZE]