I don't see any examples (or much documentation for that matter) on the FreeRTOS version of the LPUART driver. I've got the driver setup and can transmit and receive data. What I'm not understanding though, is how do I know when there is data to receive, without calling the LPUART_RTOS_Receive function.
The problem is that the LPUART_RTOS_Receive waits/sleeps forever at
ev = xEventGroupWaitBits(handle->rx_event, RTOS_UART_COMPLETE, pdTRUE, pdFALSE, portMAX_DELAY);
until is receives the number of bytes originally requested (which is signaled through the interrupt).
What if I don't want to block forever? Obviously I can modify the driver, but what is the intended use of this driver? An example would be nice.
Hi, Kenneth,
I do not know the part number you are using, anyway, i think the SDK2.0 has the example of lpuart driver example.
I have downloaded the KSDK2.0 driver for the Kl27, this is the example directory:
D:\Freescale\KSDK2.0_KL27\boards\frdmkl27z\rtos_examples\freertos_lpuart\kds
Hope it can help you.
BR
Xiangjun Rong
I paste the code in freertos_lpuart.c:
/* FreeRTOS kernel includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "timers.h"
/* Freescale includes. */
#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "board.h"
#include "fsl_lpuart_freertos.h"
#include "fsl_lpuart.h"
#include "pin_mux.h"
#include "clock_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define DEMO_LPUART LPUART0
#define DEMO_LPUART_CLKSRC kCLOCK_McgIrc48MClk
#define DEMO_LPUART_RX_TX_IRQn LPUART0_IRQn
/* Task priorities. */
#define uart_task_PRIORITY (configMAX_PRIORITIES - 1)
/*******************************************************************************
* Prototypes
******************************************************************************/
static void uart_task(void *pvParameters);
/*******************************************************************************
* Code
******************************************************************************/
const char *to_send = "Hello, world!\r\n";
uint8_t background_buffer[32];
uint8_t recv_buffer[4];
lpuart_rtos_handle_t handle;
struct _lpuart_handle t_handle;
struct rtos_lpuart_config lpuart_config = {
.baudrate = 115200,
.parity = kLPUART_ParityDisabled,
.stopbits = kLPUART_OneStopBit,
.buffer = background_buffer,
.buffer_size = sizeof(background_buffer),
};
/*!
* @brief Application entry point.
*/
int main(void)
{
/* Init board hardware. */
BOARD_InitPins();
BOARD_BootClockRUN();
CLOCK_SetLpuart0Clock(0x1U);
NVIC_SetPriority(DEMO_LPUART_RX_TX_IRQn, 5);
xTaskCreate(uart_task, "Uart_task", configMINIMAL_STACK_SIZE, NULL, uart_task_PRIORITY, NULL);
vTaskStartScheduler();
for (;;)
;
}
/*!
* @brief Task responsible for printing of "Hello world." message.
*/
static void uart_task(void *pvParameters)
{
int error;
size_t n;
lpuart_config.srcclk = CLOCK_GetFreq(DEMO_LPUART_CLKSRC);
lpuart_config.base = DEMO_LPUART;
// PRINTF("Test");
if (0 > LPUART_RTOS_Init(&handle, &t_handle, &lpuart_config))
{
PRINTF("Error during UART initialization.\r\n");
vTaskSuspend(NULL);
}
/* Send some data */
if (0 > LPUART_RTOS_Send(&handle, (uint8_t *)to_send, strlen(to_send)))
{
PRINTF("Error during UART send.\r\n");
vTaskSuspend(NULL);
}
/* Send data */
do
{
error = LPUART_RTOS_Receive(&handle, recv_buffer, sizeof(recv_buffer), &n);
if (n > 0)
{
/* send back the received data */
LPUART_RTOS_Send(&handle, (uint8_t *)recv_buffer, n);
}
} while (kStatus_Success == error);
LPUART_RTOS_Deinit(&handle);
vTaskSuspend(NULL);
}
Hi XiangJun,
I am testing LPUART and UART examples on FRDM-KL43Z boards and I am trying to understand the subtle difference between the two and the reason for it. Specifically, why UART example uses IRQ handler but LPUART does not, as listed below from freertos_uart.c
void UART2_FLEXIO_IRQHandler(void)
{
UART_TransferHandleIRQ(UART2, (uart_handle_t *)(handle.t_state));
}
/*!
* @brief Application entry point.
*/
int main(void)
{
....
Is there an overall description of how this works and why LPUART and UART examples have this difference?
Thanks,
-Irwin