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);
}