Skip to content

Commit 53f88b5

Browse files
committed
Support USARTs up to USART5 in serial
1 parent 3d4cae8 commit 53f88b5

File tree

1 file changed

+144
-5
lines changed

1 file changed

+144
-5
lines changed

targets/TARGET_Silicon_Labs/TARGET_EFM32/serial_api.c

Lines changed: 144 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static uint32_t serial_irq_ids[MODULES_SIZE_SERIAL] = { 0 };
7878
/* Interrupt handler from mbed common */
7979
static uart_irq_handler irq_handler;
8080
/* Keep track of incoming DMA IRQ's */
81-
static bool serial_dma_irq_fired[DMACTRL_CH_CNT] = { false };
81+
static bool serial_dma_irq_fired[DMA_CHAN_COUNT] = { false };
8282

8383
/* Serial interface on USBTX/USBRX retargets stdio */
8484
int stdio_uart_inited = 0;
@@ -120,6 +120,18 @@ static void usart1_tx_irq() { uart_irq(USART_1, TxIrq); USART_IntClear((USART_Ty
120120
static void usart2_rx_irq() { uart_irq(USART_2, RxIrq); }
121121
static void usart2_tx_irq() { uart_irq(USART_2, TxIrq); USART_IntClear((USART_TypeDef*)USART_2, USART_IFC_TXC);}
122122
#endif
123+
#ifdef USART3
124+
static void usart3_rx_irq() { uart_irq(USART_3, RxIrq); }
125+
static void usart3_tx_irq() { uart_irq(USART_3, TxIrq); USART_IntClear((USART_TypeDef*)USART_3, USART_IFC_TXC);}
126+
#endif
127+
#ifdef USART4
128+
static void usart4_rx_irq() { uart_irq(USART_4, RxIrq); }
129+
static void usart4_tx_irq() { uart_irq(USART_4, TxIrq); USART_IntClear((USART_TypeDef*)USART_4, USART_IFC_TXC);}
130+
#endif
131+
#ifdef USART5
132+
static void usart5_rx_irq() { uart_irq(USART_5, RxIrq); }
133+
static void usart5_tx_irq() { uart_irq(USART_5, TxIrq); USART_IntClear((USART_TypeDef*)USART_5, USART_IFC_TXC);}
134+
#endif
123135
#ifdef LEUART0
124136
static void leuart0_irq()
125137
{
@@ -250,6 +262,18 @@ static inline uint8_t serial_pointer_get_index(uint32_t serial_ptr)
250262
if (serial_ptr == USART_2) return index;
251263
index++;
252264
#endif
265+
#ifdef USART3
266+
if (serial_ptr == USART_3) return index;
267+
index++;
268+
#endif
269+
#ifdef USART4
270+
if (serial_ptr == USART_4) return index;
271+
index++;
272+
#endif
273+
#ifdef USART5
274+
if (serial_ptr == USART_5) return index;
275+
index++;
276+
#endif
253277
#ifdef LEUART0
254278
if (serial_ptr == LEUART_0) return index;
255279
index++;
@@ -301,6 +325,18 @@ static inline IRQn_Type serial_get_rx_irq_index(serial_t *obj)
301325
case USART_2:
302326
return USART2_RX_IRQn;
303327
#endif
328+
#ifdef USART3
329+
case USART_3:
330+
return USART3_RX_IRQn;
331+
#endif
332+
#ifdef USART4
333+
case USART_4:
334+
return USART4_RX_IRQn;
335+
#endif
336+
#ifdef USART5
337+
case USART_5:
338+
return USART5_RX_IRQn;
339+
#endif
304340
#ifdef LEUART0
305341
case LEUART_0:
306342
return LEUART0_IRQn;
@@ -344,6 +380,18 @@ static inline IRQn_Type serial_get_tx_irq_index(serial_t *obj)
344380
case USART_2:
345381
return USART2_TX_IRQn;
346382
#endif
383+
#ifdef USART3
384+
case USART_3:
385+
return USART3_TX_IRQn;
386+
#endif
387+
#ifdef USART4
388+
case USART_4:
389+
return USART4_TX_IRQn;
390+
#endif
391+
#ifdef USART5
392+
case USART_5:
393+
return USART5_TX_IRQn;
394+
#endif
347395
#ifdef LEUART0
348396
case LEUART_0:
349397
return LEUART0_IRQn;
@@ -387,6 +435,18 @@ inline CMU_Clock_TypeDef serial_get_clock(serial_t *obj)
387435
case USART_2:
388436
return cmuClock_USART2;
389437
#endif
438+
#ifdef USART3
439+
case USART_3:
440+
return cmuClock_USART3;
441+
#endif
442+
#ifdef USART4
443+
case USART_4:
444+
return cmuClock_USART4;
445+
#endif
446+
#ifdef USART5
447+
case USART_5:
448+
return cmuClock_USART5;
449+
#endif
390450
#ifdef LEUART0
391451
case LEUART_0:
392452
return cmuClock_LEUART0;
@@ -466,6 +526,27 @@ void serial_preinit(serial_t *obj, PinName tx, PinName rx)
466526
NVIC_SetPriority(USART2_TX_IRQn, 1);
467527
break;
468528
#endif
529+
#ifdef USART3
530+
case USART_3:
531+
NVIC_SetVector(USART3_RX_IRQn, (uint32_t) &usart3_rx_irq);
532+
NVIC_SetVector(USART3_TX_IRQn, (uint32_t) &usart3_tx_irq);
533+
NVIC_SetPriority(USART3_TX_IRQn, 1);
534+
break;
535+
#endif
536+
#ifdef USART4
537+
case USART_4:
538+
NVIC_SetVector(USART4_RX_IRQn, (uint32_t) &usart4_rx_irq);
539+
NVIC_SetVector(USART4_TX_IRQn, (uint32_t) &usart4_tx_irq);
540+
NVIC_SetPriority(USART4_TX_IRQn, 1);
541+
break;
542+
#endif
543+
#ifdef USART5
544+
case USART_5:
545+
NVIC_SetVector(USART5_RX_IRQn, (uint32_t) &usart5_rx_irq);
546+
NVIC_SetVector(USART5_TX_IRQn, (uint32_t) &usart5_tx_irq);
547+
NVIC_SetPriority(USART5_TX_IRQn, 1);
548+
break;
549+
#endif
469550
#ifdef LEUART0
470551
case LEUART_0:
471552
NVIC_SetVector(LEUART0_IRQn, (uint32_t) &leuart0_irq);
@@ -519,13 +600,13 @@ static void serial_set_route(serial_t *obj)
519600
obj->serial.periph.leuart->ROUTE &= ~LEUART_ROUTE_RXPEN;
520601
}
521602
#else
522-
if(obj->serial.location_tx != NC) {
603+
if(obj->serial.location_tx != (uint32_t)NC) {
523604
obj->serial.periph.leuart->ROUTELOC0 = (obj->serial.periph.leuart->ROUTELOC0 & (~_LEUART_ROUTELOC0_TXLOC_MASK)) | (obj->serial.location_tx << _LEUART_ROUTELOC0_TXLOC_SHIFT);
524605
obj->serial.periph.leuart->ROUTEPEN = (obj->serial.periph.leuart->ROUTEPEN & (~_LEUART_ROUTEPEN_TXPEN_MASK)) | LEUART_ROUTEPEN_TXPEN;
525606
} else {
526607
obj->serial.periph.leuart->ROUTEPEN = (obj->serial.periph.leuart->ROUTEPEN & (~_LEUART_ROUTEPEN_TXPEN_MASK));
527608
}
528-
if(obj->serial.location_rx != NC) {
609+
if(obj->serial.location_rx != (uint32_t)NC) {
529610
obj->serial.periph.leuart->ROUTELOC0 = (obj->serial.periph.leuart->ROUTELOC0 & (~_LEUART_ROUTELOC0_RXLOC_MASK)) | (obj->serial.location_rx << _LEUART_ROUTELOC0_RXLOC_SHIFT);
530611
obj->serial.periph.leuart->ROUTEPEN = (obj->serial.periph.leuart->ROUTEPEN & (~_LEUART_ROUTEPEN_RXPEN_MASK)) | LEUART_ROUTEPEN_RXPEN;
531612
} else {
@@ -548,13 +629,13 @@ static void serial_set_route(serial_t *obj)
548629
obj->serial.periph.uart->ROUTE &= ~USART_ROUTE_RXPEN;
549630
}
550631
#else
551-
if(obj->serial.location_tx != NC) {
632+
if(obj->serial.location_tx != (uint32_t)NC) {
552633
obj->serial.periph.uart->ROUTELOC0 = (obj->serial.periph.uart->ROUTELOC0 & (~_USART_ROUTELOC0_TXLOC_MASK)) | (obj->serial.location_tx << _USART_ROUTELOC0_TXLOC_SHIFT);
553634
obj->serial.periph.uart->ROUTEPEN = (obj->serial.periph.uart->ROUTEPEN & (~_USART_ROUTEPEN_TXPEN_MASK)) | USART_ROUTEPEN_TXPEN;
554635
} else {
555636
obj->serial.periph.uart->ROUTEPEN = (obj->serial.periph.uart->ROUTEPEN & (~_USART_ROUTEPEN_TXPEN_MASK));
556637
}
557-
if(obj->serial.location_rx != NC) {
638+
if(obj->serial.location_rx != (uint32_t)NC) {
558639
obj->serial.periph.uart->ROUTELOC0 = (obj->serial.periph.uart->ROUTELOC0 & (~_USART_ROUTELOC0_RXLOC_MASK)) | (obj->serial.location_rx << _USART_ROUTELOC0_RXLOC_SHIFT);
559640
obj->serial.periph.uart->ROUTEPEN = (obj->serial.periph.uart->ROUTEPEN & (~_USART_ROUTEPEN_RXPEN_MASK)) | USART_ROUTEPEN_RXPEN;
560641
} else {
@@ -1174,6 +1255,21 @@ static void serial_dmaSetupChannel(serial_t *obj, bool tx_nrx)
11741255
channelConfig.select = DMAREQ_USART2_TXBL;
11751256
break;
11761257
#endif
1258+
#ifdef USART3
1259+
case USART_3:
1260+
channelConfig.select = DMAREQ_USART3_TXBL;
1261+
break;
1262+
#endif
1263+
#ifdef USART4
1264+
case USART_4:
1265+
channelConfig.select = DMAREQ_USART4_TXBL;
1266+
break;
1267+
#endif
1268+
#ifdef USART5
1269+
case USART_5:
1270+
channelConfig.select = DMAREQ_USART5_TXBL;
1271+
break;
1272+
#endif
11771273
#ifdef LEUART0
11781274
case LEUART_0:
11791275
channelConfig.select = DMAREQ_LEUART0_TXBL;
@@ -1219,6 +1315,21 @@ static void serial_dmaSetupChannel(serial_t *obj, bool tx_nrx)
12191315
channelConfig.select = DMAREQ_USART2_RXDATAV;
12201316
break;
12211317
#endif
1318+
#ifdef USART3
1319+
case USART_3:
1320+
channelConfig.select = DMAREQ_USART3_RXDATAV;
1321+
break;
1322+
#endif
1323+
#ifdef USART4
1324+
case USART_4:
1325+
channelConfig.select = DMAREQ_USART4_RXDATAV;
1326+
break;
1327+
#endif
1328+
#ifdef USART5
1329+
case USART_5:
1330+
channelConfig.select = DMAREQ_USART5_RXDATAV;
1331+
break;
1332+
#endif
12221333
#ifdef LEUART0
12231334
case LEUART_0:
12241335
channelConfig.select = DMAREQ_LEUART0_RXDATAV;
@@ -1453,6 +1564,34 @@ static void serial_dmaActivate(serial_t *obj, void* cb, void* buffer, int length
14531564
obj->serial.periph.uart->CMD = USART_CMD_RXEN | USART_CMD_CLEARRX;
14541565
break;
14551566
#endif
1567+
#ifdef USART2
1568+
case USART_2:
1569+
dma_periph = ldmaPeripheralSignal_USART2_RXDATAV;
1570+
source_addr = &USART2->RXDATA;
1571+
obj->serial.periph.uart->CMD = USART_CMD_RXEN | USART_CMD_CLEARRX;
1572+
break;
1573+
#endif
1574+
#ifdef USART3
1575+
case USART_3:
1576+
dma_periph = ldmaPeripheralSignal_USART3_RXDATAV;
1577+
source_addr = &USART3->RXDATA;
1578+
obj->serial.periph.uart->CMD = USART_CMD_RXEN | USART_CMD_CLEARRX;
1579+
break;
1580+
#endif
1581+
#ifdef USART4
1582+
case USART_4:
1583+
dma_periph = ldmaPeripheralSignal_USART4_RXDATAV;
1584+
source_addr = &USART4->RXDATA;
1585+
obj->serial.periph.uart->CMD = USART_CMD_RXEN | USART_CMD_CLEARRX;
1586+
break;
1587+
#endif
1588+
#ifdef USART5
1589+
case USART_5:
1590+
dma_periph = ldmaPeripheralSignal_USART5_RXDATAV;
1591+
source_addr = &USART5->RXDATA;
1592+
obj->serial.periph.uart->CMD = USART_CMD_RXEN | USART_CMD_CLEARRX;
1593+
break;
1594+
#endif
14561595
#ifdef LEUART0
14571596
case LEUART_0:
14581597
dma_periph = ldmaPeripheralSignal_LEUART0_RXDATAV;

0 commit comments

Comments
 (0)