mirror of https://github.com/ARMmbed/mbed-os.git
Added Serial support for K22F and fixed overal serial
First part is pretty obvious, added some pin defines, and some ifdefs in serial_api.c to make it compile (they all use KSDK macros, so goes automatically, and not that many ifdefs). Second part is that in the new version of the hal files you apparantly got to manually enable the uart transmitter/receiver. This wasn't in there yet, so it did very little. Now it works fine on a K22F (well minus the part where the first char in a program isn't transmitted, but thats alot better than nothing being transmitted)pull/476/head
parent
50ce80b7d2
commit
d35e9bbe27
|
@ -30,13 +30,11 @@ typedef enum {
|
|||
UART_0 = 0,
|
||||
UART_1 = 1,
|
||||
UART_2 = 2,
|
||||
UART_3 = 3,
|
||||
UART_4 = 4,
|
||||
} UARTName;
|
||||
|
||||
#define STDIO_UART_TX USBTX
|
||||
#define STDIO_UART_RX USBRX
|
||||
#define STDIO_UART UART_0
|
||||
#define STDIO_UART UART_1
|
||||
|
||||
typedef enum {
|
||||
I2C_0 = 0,
|
||||
|
|
|
@ -46,12 +46,16 @@ const PinMap PinMap_I2C_SCL[] = {
|
|||
|
||||
/************UART***************/
|
||||
const PinMap PinMap_UART_TX[] = {
|
||||
{PTA2, UART_0, 2},
|
||||
{PTE0, UART_1, 3},
|
||||
{PTD3, UART_2, 3},
|
||||
{NC , NC , 0}
|
||||
};
|
||||
|
||||
const PinMap PinMap_UART_RX[] = {
|
||||
{PTA1, UART_0, 2},
|
||||
{PTE1, UART_1, 3},
|
||||
{PTD2, UART_2, 3},
|
||||
{NC , NC , 0}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#define DEVICE_ANALOGIN 0
|
||||
#define DEVICE_ANALOGOUT 0
|
||||
|
||||
#define DEVICE_SERIAL 0
|
||||
#define DEVICE_SERIAL 1
|
||||
|
||||
#define DEVICE_I2C 0
|
||||
#define DEVICE_I2CSLAVE 0
|
||||
|
@ -49,7 +49,7 @@
|
|||
|
||||
#define DEVICE_DEBUG_AWARENESS 0
|
||||
|
||||
#define DEVICE_STDIO_MESSAGES 0
|
||||
#define DEVICE_STDIO_MESSAGES 1
|
||||
|
||||
#define DEVICE_ERROR_RED 1
|
||||
|
||||
|
|
|
@ -33,8 +33,11 @@
|
|||
/* TODO:
|
||||
putchar/getchar 9 and 10 bits support
|
||||
*/
|
||||
|
||||
#define UART_NUM 4
|
||||
#ifndef UART3_BASE
|
||||
#define UART_NUM 3
|
||||
#else
|
||||
#define UART_NUM 5
|
||||
#endif
|
||||
|
||||
static uint32_t serial_irq_ids[UART_NUM] = {0};
|
||||
static uart_irq_handler irq_handler;
|
||||
|
@ -45,7 +48,7 @@ serial_t stdio_uart;
|
|||
void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
||||
uint32_t uart_tx = pinmap_peripheral(tx, PinMap_UART_TX);
|
||||
uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX);
|
||||
obj->index = (UARTName)pinmap_merge(uart_tx, uart_rx);
|
||||
obj->index = pinmap_merge(uart_tx, uart_rx);
|
||||
MBED_ASSERT((int)obj->index != NC);
|
||||
|
||||
uint32_t uartSourceClock = CLOCK_SYS_GetUartFreq(obj->index);
|
||||
|
@ -55,8 +58,12 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
UART_HAL_Init(uart_addrs[obj->index]);
|
||||
UART_HAL_SetBaudRate(uart_addrs[obj->index], uartSourceClock, 9600);
|
||||
UART_HAL_SetParityMode(uart_addrs[obj->index], kUartParityDisabled);
|
||||
#if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
|
||||
UART_HAL_SetStopBitCount(uart_addrs[obj->index], kUartOneStopBit);
|
||||
#endif
|
||||
UART_HAL_SetBitCountPerChar(uart_addrs[obj->index], kUart8BitsPerChar);
|
||||
UART_HAL_EnableTransmitter(uart_addrs[obj->index]);
|
||||
UART_HAL_EnableReceiver(uart_addrs[obj->index]);
|
||||
|
||||
pinmap_pinout(tx, PinMap_UART_TX);
|
||||
pinmap_pinout(rx, PinMap_UART_RX);
|
||||
|
@ -83,7 +90,9 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
|
|||
uint32_t uart_addrs[] = UART_BASE_ADDRS;
|
||||
UART_HAL_SetBitCountPerChar(uart_addrs[obj->index], (uart_bit_count_per_char_t)data_bits);
|
||||
UART_HAL_SetParityMode(uart_addrs[obj->index], (uart_parity_mode_t)parity);
|
||||
#if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
|
||||
UART_HAL_SetStopBitCount(uart_addrs[obj->index], (uart_stop_bit_count_t)stop_bits);
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -112,6 +121,8 @@ void uart2_irq() {
|
|||
uart_irq(UART_HAL_IsTxDataRegEmpty(UART2_BASE), UART_HAL_IsRxDataRegFull(UART2_BASE), 2);
|
||||
}
|
||||
|
||||
#if (UART_NUM > 3)
|
||||
|
||||
void uart3_irq() {
|
||||
uart_irq(UART_HAL_IsTxDataRegEmpty(UART3_BASE), UART_HAL_IsRxDataRegFull(UART3_BASE), 3);
|
||||
}
|
||||
|
@ -119,6 +130,7 @@ void uart3_irq() {
|
|||
void uart4_irq() {
|
||||
uart_irq(UART_HAL_IsTxDataRegEmpty(UART4_BASE), UART_HAL_IsRxDataRegFull(UART4_BASE), 4);
|
||||
}
|
||||
#endif
|
||||
|
||||
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
|
||||
irq_handler = handler;
|
||||
|
@ -133,8 +145,10 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) {
|
|||
case 0: irq_n=UART0_RX_TX_IRQn; vector = (uint32_t)&uart0_irq; break;
|
||||
case 1: irq_n=UART1_RX_TX_IRQn; vector = (uint32_t)&uart1_irq; break;
|
||||
case 2: irq_n=UART2_RX_TX_IRQn; vector = (uint32_t)&uart2_irq; break;
|
||||
#if (NUM_UART > 3)
|
||||
case 3: irq_n=UART3_RX_TX_IRQn; vector = (uint32_t)&uart3_irq; break;
|
||||
case 4: irq_n=UART4_RX_TX_IRQn; vector = (uint32_t)&uart4_irq; break;
|
||||
#endif
|
||||
}
|
||||
uint32_t uart_addrs[] = UART_BASE_ADDRS;
|
||||
if (enable) {
|
||||
|
|
Loading…
Reference in New Issue