LPC 1758 1768 IAP (In Application Programming

m20003294 wrote on Monday, March 28, 2011:

I am using FreeRTOS, and it needs to load variables from Flash before starting tasks.

The main entry code for FreeRTOS looks as follows:
int main(void)
    /* Call SystemCoreClockUpdate such that SystemCoreClock holds correct
     * value.

    // This stores variables to flash, then reads them using IAP, so far so good…

   // Every module has at least the following tasks running:

     xQ_MODBUS_UART_S = xQueueCreate( QS_MODBUS_UART_S, sizeof(Q_MESSAGE));
     vMBPInit(  );
     vTaskStartScheduler(  );

      return 0 ;

For testing, the code first saves the default values to flash, (Bank 15 at 0x0000F000)
The strange thing is, when stepping through the code, all flash functions are executed successfully.
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.

So far so good,

BUT: When the vTaskStartScheduler is called, the tasks should start running, but they never enter running state.

When I suspend the code, it always resides in:

static void prvCheckTasksWaitingTermination( void )
      #if ( INCLUDE_vTaskDelete == 1 )
            portBASE_TYPE xListIsEmpty;

            /* ucTasksDeleted is used to prevent vTaskSuspendAll() being called
            too often in the idle task. */
            if( uxTasksDeleted > ( unsigned portBASE_TYPE ) 0 )
                  xListIsEmpty = listLIST_IS_EMPTY( &xTasksWaitingTermination );

                  if( !xListIsEmpty )
                        tskTCB *pxTCB;

                             pxTCB = ( tskTCB * ) listGET_OWNER_OF_HEAD_ENTRY( ( ( xList * ) &xTasksWaitingTermination ) );
                             vListRemove( &( pxTCB->xGenericListItem ) );

                        prvDeleteTCB( pxTCB );

The value of uxTasksDeleted = 0.
The code never leaves this function, so it seems the scheduler cannot function properly anymore.

When I remove the Flash related code from the startup code (SaveDefaultValues and LoadAllValues), the system starts normally with tasks running as they should.

Is it possible using IAP changes something in the system state, preventing FreeRTOS to schedule normally ?
Is there some information on how to use IAP in combination with FreeRTOS ?

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.
I have enabled the GUI setting in Code Red for this.

However, perhaps there is something else I need to do (in FreeRTOS settings??) to reserve those bytes…

Any help is appreciated,

davedoors wrote on Monday, March 28, 2011:

I have never used IAP, but it does sound like it is causing data corruption somewhere. Your IAP routines are called between the RAM being initialized by the C start code, and the kernel being used, so I would guess that something initialized in the start code is clobbered by the IAP code. It is just a guess.