Hi,
How to receive multiple bytes using UART when in VRPR mode (or VRPS mode)?
When I try to receive multiple bytes, I get a status = STATUS_UART_RX_OVERRUN.
I am writing this based on lpuart_echo_s32k144 in Example Projects.
Here's the code.
#include "Cpu.h"
#include "pin_mux.h"
#include "dmaController1.h"
#include "clockMan1.h"
#include "lpuart1.h"
#include "pwrMan1.h"
volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
/* Welcome message displayed at the console */
#define welcomeMsg "This example is an simple echo using LPUART\r\n\
it will send back any character you send to it.\r\n\
The board will greet you if you send 'Hello Board'\r\
\nNow you can begin typing:\r\n"
/* Error message displayed at the console, in case data is received erroneously */
#define errorMsg "An error occurred! The application will stop!\r\n"
/* Timeout in ms for blocking operations */
#define TIMEOUT 100U
/* Receive buffer size */
#define BUFFER_SIZE 256U
#define RUN (0u) /* High speed run */
#define VLPR (1u) /* Run */
#define VLPS (2u) /* Very low power run */
/* Buffer used to receive data from the console */
uint8_t buffer[BUFFER_SIZE];
uint8_t bufferIdx;
/* UART rx callback for continuous reception, byte by byte */
void rxCallback(void *driverState, uart_event_t event, void *userData)
{
/* Unused parameters */
(void)driverState;
(void)userData;
/* Check the event type */
if (event == UART_EVENT_RX_FULL)
{
/* The reception stops when newline is received or the buffer is full */
if ((buffer[bufferIdx] != '\n') && (bufferIdx != (BUFFER_SIZE - 2U)))
{
/* Update the buffer index and the rx buffer */
bufferIdx++;
LPUART_DRV_SetRxBuffer(INST_LPUART1, &buffer[bufferIdx], 1U);
}
}
}
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
/* Write your local variable definition here */
status_t status;
/* Declare a buffer used to store the received data */
uint32_t bytesRemaining;
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
/* Initialize and configure clocks
* - see clock manager component for details
*/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
/* Initialize pins
* - See PinSettings component for more info
*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
/* Initialize LPUART instance */
LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0);
/* Install the callback for rx events */
LPUART_DRV_InstallRxCallback(INST_LPUART1, rxCallback, NULL);
/* Send a welcome message */
LPUART_DRV_SendDataBlocking(INST_LPUART1, (uint8_t *)welcomeMsg, strlen(welcomeMsg), TIMEOUT);
/* Infinite loop:
* - Receive data from user
* - Echo the received data back
*/
POWER_SYS_Init(&powerConfigsArr, POWER_MANAGER_CONFIG_CNT, &powerStaticCallbacksConfigsArr, POWER_MANAGER_CALLBACK_CNT);
POWER_SYS_SetMode(VLPR, POWER_MANAGER_POLICY_AGREEMENT);
//POWER_SYS_SetMode(VLPS, POWER_MANAGER_POLICY_AGREEMENT);
while (1)
{
/* Receive and store data byte by byte until new line character is received,
* or the buffer becomes full (256 characters received)
*/
LPUART_DRV_ReceiveData(INST_LPUART1, buffer, 3U);
/* Wait for transfer to be completed */
while(LPUART_DRV_GetReceiveStatus(INST_LPUART1, &bytesRemaining) == STATUS_BUSY);
/* Check the status */
status = LPUART_DRV_GetReceiveStatus(INST_LPUART1, &bytesRemaining);
if (status != STATUS_SUCCESS)
{
/* If an error occurred, send the error message and exit the loop */
LPUART_DRV_SendData(INST_LPUART1, (uint8_t *)errorMsg, strlen(errorMsg));
break;
}
/* Append string terminator to the received data */
bufferIdx++;
buffer[bufferIdx] = 0U;
/* Send the received data back */
LPUART_DRV_SendData(INST_LPUART1, buffer, bufferIdx);
/* Reset the buffer index to start a new reception */
bufferIdx = 0U;
}
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
}
best regards