Let me add some more details from experimentation. I believe that the first thing I need to do is configure the pins I want to use for UART0:
PORT_HAL_SetMuxMode(PORTA_BASE,14u,kPortMuxAlt3); // UART0_TX
PORT_HAL_SetMuxMode(PORTA_BASE,15u,kPortMuxAlt3); // UART0_RX
PORT_HAL_SetMuxMode(PORTA_BASE,16u,kPortMuxAlt3); // UART0_CTS_b
PORT_HAL_SetMuxMode(PORTA_BASE,17u,kPortMuxAlt3); // UART0_RTS_b
I also need to allocate space for the UART configuration and state info, and then initialize the UART configuration:
uart_user_config_t uart0Config; // UART configuration for PC comms
uart_state_t uart0State; // Memory for UART driver state structure
uart0Config.baudRate = 115200;
uart0Config.bitCountPerChar = kUart8BitsPerChar;
uart0Config.parityMode = kUartParityDisabled;
uart0Config.stopBitCount = kUartOneStopBit;
Then, I call the driver initialization function for the UART:
UART_DRV_Init(HW_UART0, &uart0State, &uart0Config);
Here's where I get lost. I'd like to do a non-blocking transmit, for example. I can define a buffer to transmit, and then call the non-blocking driver function to send it:
char *txBuffer = "Hello from UART0\n\r";
size_t txLen = strlen(txBuffer);
UART_DRV_SendData(HW_UART0, (const uint8_t *)txBuffer, txLen);
The documentation shows that I should be able to check the status of the transmit by calling another driver function, e.g.:
uint32_t txBytesRemaining;
while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(HW_UART0, &txBytesRemaining))
{
// Can do something else instead of just busy-waiting here.
}
Presumably this starts sending data and will use a Tx interrupt to handle sending the remaining bytes via the uart_state_t structure as the transmitter empties. However, it appears that the interrupt handler is not being installed correctly. In IAR, I end up at the DefaultISR handler, which just keeps branching back to itself.
File fsl_uart_driver.c has the IRQ handler for the UART, but I do not see where it gets installed, or how I should install it:
void UART_DRV_IRQHandler(uint32_t instance)
This function looks like it has the code to handle pending transmits and receives using the uart_state_t structure, but it must get called from some actual ISR, and I do not see where that happens.
What do I need to do to install the UART's IRQ handler correctly? There is a function in fsl_interrupt_manager.c to install an interrupt handler and IRQ, but the handler does not take a parameter (instance):
void * INT_SYS_InstallHandler(IRQn_Type irqNumber, void (*handler)(void))
So, after I call UART_DRV_Init(), is there something I have to do to install the IRQ handler for the UART?
Your help is greatly appreciated, and I hope this example will help others struggling to use the drivers provided by Freescale.
Thanks!
Scott