FreeRTOS, Sleep Modes, And The PSoC 5

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 Hi,

   

I am having difficulty implenting low power modes combined with using the FreeRTOS platform and the PSoC 5. Specifically, UART comms are getting corrupted.

   

I have a task which receives messages to send to the UART. When it receives a message, it prevents the uC from sleeping, wakes the uart up, and then sends the message using the API (Uart_PutSring()). It then waits until the message is sent before allowing the micro to sleep and sleeping the uart itself.

   

Some messages are getting through un-corrupted, others are a horrible mess...

   

Here is a code snippet of the UART task...

   

 

   

//! @brief Main debug uart task

   

//! @param *pvParameters Void pointer (not used)

   

//! @note Not thread-safe. Do not call from any task, this function is a task that

   

//! is called by the FreeRTOS kernel

   

//! @public

   

void vDebugUart_MainTask(void *pvParameters)

   

{

   

// Sleep uart

   

UART_DEBUG_Sleep();

   

 

   

uint8 *message;

   

for(;;)

   

{

   

// Wait for a message pointer to arrive in the queue

   

xQueueReceive(xDebugUartTxQueue, &message, portMAX_DELAY);

   

 

   

#if(DEBUG_LEDS == 1)

   

DebugUart_FlashLed();

   

#endif

   

 

   

// Message must of been received, so now prevent micro from sleeping and send

   

PowerMgmt_SleepLock();

   

 

   

// Wakeup UART

   

UART_DEBUG_Wakeup();

   

 

   

UART_DEBUG_PutString(message);

   

 

   

//vTaskDelay(200/portTICK_RATE_MS);

   

// Wait until UART has completely finished sending the message

   

// (both the hardware buffer and the byte sent flag are set)

   

while(!(UART_DEBUG_ReadTxStatus() & (UART_DEBUG_TX_STS_FIFO_EMPTY | UART_DEBUG_TX_STS_COMPLETE))); //(software wait)

   

//while(!(UART_DEBUG_ReadTxStatus() & UART_DEBUG_TX_STS_COMPLETE));

   

 

   

// Sleep uart

   

UART_DEBUG_Sleep();

   

 

   

// Now it is safe to unlock the micro to allow for sleeping

   

PowerMgmt_SleepUnlock();

   

// Finished, now loop for next message

   

}

   

}

   

 

   

Cheers, Geoff

0 Likes
4 Replies
Anonymous
Not applicable

hey gbmhunter

   

 

   

you havent used SaveConfig() API before putting the device to sleep and RestoreConfig() API immediately after wake up. that could be a potential reason why the uart data is getting corrupted.

0 Likes
Anonymous
Not applicable

 The save clocks API call for the enitre device?

0 Likes
Anonymous
Not applicable

 This is the typical sequence for you to put PSoC to sleep properly, wake it up and restore it to normal operation.

   
        
  1. First save all the component configuration using the component_SaveConfig() API or component_Sleep() API (Some components may not have the sleep API). The Sleep API will actually be calling the component_Stop() API, followed by component_SaveConfig(). In case of UART, it is is sufficient to call UART_Sleep() API.
  2.     
  3. Follow step 1 for all the components in your design which has some amount of configuration. Please go through individual component datasheet for for Sleep related information.
  4.     
  5. Now call CyPmSaveClocks(). Saves all state of the clocking system that doesn’t persist during sleep/hibernate or that needs to be altered in preparation for sleep/hibernate. Shuts down all the digital and analog clock dividers. Switches the master clock over to the IMO and shuts down the PLL and MHz Crystal.
  6.     
  7. Now enter sleep by calling CyPmSleep() API.
  8.     
  9. Restore all clock configuration, CyPmRestoreClocks()     
            
    • Restore the component configuration. In your case UART. UART_Wakeup(void). I hope this helps.
    •      
  10.    
0 Likes
Anonymous
Not applicable

Hello,

   

I would recommend you to contact the cypress tech support team to look in to this issue and get it resolved. You can raise a request for the same here, https://secure.cypress.com/myaccount/?id=25&techSupport=1&CFID=807385&CFTOKEN=26807991

0 Likes