Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed_blinky-bmd-200 bmd-200_accel_demo firstRig
Fork of mbed-src by
Revision 575:1f7ee966c9ea, committed 2015-06-17
- Comitter:
- mbed_official
- Date:
- Wed Jun 17 09:00:08 2015 +0100
- Parent:
- 574:e6ed7264c56c
- Child:
- 576:c6226b743616
- Commit message:
- Synchronized with git revision b583f22771ff3a95879587f55a8f9392cfac2955
Full URL: https://github.com/mbedmicro/mbed/commit/b583f22771ff3a95879587f55a8f9392cfac2955/
Fix handling of Serial NC pins in K64F,K22F,KL25Z, and KL46Z
Changed in this revision
--- a/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/serial_api.c Wed Jun 17 08:15:08 2015 +0100
+++ b/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/serial_api.c Wed Jun 17 09:00:08 2015 +0100
@@ -33,6 +33,7 @@
#define UARTLP_BDH_SBNS_MASK UART0_BDH_SBNS_MASK
#define UARTLP_BDH_SBNS_SHIFT UART0_BDH_SBNS_SHIFT
#define UARTLP_S1_TDRE_MASK UART0_S1_TDRE_MASK
+ #define UARTLP_S1_TC_MASK UART0_S1_TC_MASK
#define UARTLP_S1_OR_MASK UART0_S1_OR_MASK
#define UARTLP_C2_RIE_MASK UART0_C2_RIE_MASK
#define UARTLP_C2_TIE_MASK UART0_C2_TIE_MASK
@@ -78,7 +79,17 @@
}
// Disable UART before changing registers
obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
-
+
+ // Enable UART transmitter to ensure TX activity is finished
+ obj->uart->C2 |= UARTLP_C2_TE_MASK;
+
+ // Wait for TX activity to finish
+ while(!(obj->uart->S1 & UARTLP_S1_TC_MASK));
+
+ // Disbale UARTs again
+ obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
+
+
switch (uart) {
case UART_0: obj->index = 0; break;
#if UART_NUM > 1
@@ -95,16 +106,16 @@
pinmap_pinout(tx, PinMap_UART_TX);
pinmap_pinout(rx, PinMap_UART_RX);
- // set rx/tx pins in PullUp mode
+ // set rx/tx pins in PullUp mode and enable TX/RX
if (tx != NC) {
+ obj->uart->C2 |= UARTLP_C2_TE_MASK;
pin_mode(tx, PullUp);
}
if (rx != NC) {
+ obj->uart->C2 |= UARTLP_C2_RE_MASK;
pin_mode(rx, PullUp);
}
- obj->uart->C2 |= (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
-
if (uart == STDIO_UART) {
stdio_uart_inited = 1;
memcpy(&stdio_uart, obj, sizeof(serial_t));
@@ -119,13 +130,13 @@
//
// set the baud rate, taking in to account the current SystemFrequency
void serial_baud(serial_t *obj, int baudrate) {
-
+
// save C2 state
uint8_t c2_state = (obj->uart->C2 & (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK));
-
+
// Disable UART before changing registers
obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
-
+
uint32_t PCLK;
if (obj->uart == UART0) {
if (mcgpllfll_frequency() != 0)
@@ -146,7 +157,7 @@
// set BDH and BDL
obj->uart->BDH = (obj->uart->BDH & ~(0x1f)) | ((DL >> 8) & 0x1f);
obj->uart->BDL = (obj->uart->BDL & ~(0xff)) | ((DL >> 0) & 0xff);
-
+
// restore C2 state
obj->uart->C2 |= c2_state;
}
@@ -158,10 +169,10 @@
// save C2 state
uint8_t c2_state = (obj->uart->C2 & (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK));
-
+
// Disable UART before changing registers
obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
-
+
uint8_t parity_enable, parity_select;
switch (parity) {
@@ -177,11 +188,11 @@
// data bits, parity and parity mode
obj->uart->C1 = ((parity_enable << 1)
| (parity_select << 0));
-
+
// stop bits
obj->uart->BDH &= ~UARTLP_BDH_SBNS_MASK;
obj->uart->BDH |= (stop_bits << UARTLP_BDH_SBNS_SHIFT);
-
+
// restore C2 state
obj->uart->C2 |= c2_state;
}
@@ -292,4 +303,3 @@
void serial_break_clear(serial_t *obj) {
obj->uart->C2 &= ~UARTLP_C2_SBK_MASK;
}
-
--- a/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/serial_api.c Wed Jun 17 08:15:08 2015 +0100
+++ b/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/serial_api.c Wed Jun 17 09:00:08 2015 +0100
@@ -33,6 +33,7 @@
#define UARTLP_BDH_SBNS_MASK UART0_BDH_SBNS_MASK
#define UARTLP_BDH_SBNS_SHIFT UART0_BDH_SBNS_SHIFT
#define UARTLP_S1_TDRE_MASK UART0_S1_TDRE_MASK
+ #define UARTLP_S1_TC_MASK UART0_S1_TC_MASK
#define UARTLP_S1_OR_MASK UART0_S1_OR_MASK
#define UARTLP_C2_RIE_MASK UART0_C2_RIE_MASK
#define UARTLP_C2_TIE_MASK UART0_C2_TIE_MASK
@@ -78,7 +79,17 @@
}
// Disable UART before changing registers
obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
-
+
+ // Enable UART transmitter to ensure TX activity is finished
+ obj->uart->C2 |= UARTLP_C2_TE_MASK;
+
+ // Wait for TX activity to finish
+ while(!(obj->uart->S1 & UARTLP_S1_TC_MASK));
+
+ // Disbale UARTs again
+ obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
+
+
switch (uart) {
case UART_0: obj->index = 0; break;
#if UART_NUM > 1
@@ -95,16 +106,16 @@
pinmap_pinout(tx, PinMap_UART_TX);
pinmap_pinout(rx, PinMap_UART_RX);
- // set rx/tx pins in PullUp mode
+ // set rx/tx pins in PullUp mode and enable TX/RX
if (tx != NC) {
+ obj->uart->C2 |= UARTLP_C2_TE_MASK;
pin_mode(tx, PullUp);
}
if (rx != NC) {
+ obj->uart->C2 |= UARTLP_C2_RE_MASK;
pin_mode(rx, PullUp);
}
- obj->uart->C2 |= (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
-
if (uart == STDIO_UART) {
stdio_uart_inited = 1;
memcpy(&stdio_uart, obj, sizeof(serial_t));
@@ -119,13 +130,13 @@
//
// set the baud rate, taking in to account the current SystemFrequency
void serial_baud(serial_t *obj, int baudrate) {
-
+
// save C2 state
uint8_t c2_state = (obj->uart->C2 & (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK));
-
+
// Disable UART before changing registers
obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
-
+
uint32_t PCLK;
if (obj->uart == UART0) {
if (mcgpllfll_frequency() != 0)
@@ -146,7 +157,7 @@
// set BDH and BDL
obj->uart->BDH = (obj->uart->BDH & ~(0x1f)) | ((DL >> 8) & 0x1f);
obj->uart->BDL = (obj->uart->BDL & ~(0xff)) | ((DL >> 0) & 0xff);
-
+
// restore C2 state
obj->uart->C2 |= c2_state;
}
@@ -158,10 +169,10 @@
// save C2 state
uint8_t c2_state = (obj->uart->C2 & (UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK));
-
+
// Disable UART before changing registers
obj->uart->C2 &= ~(UARTLP_C2_RE_MASK | UARTLP_C2_TE_MASK);
-
+
uint8_t parity_enable, parity_select;
switch (parity) {
@@ -177,11 +188,11 @@
// data bits, parity and parity mode
obj->uart->C1 = ((parity_enable << 1)
| (parity_select << 0));
-
+
// stop bits
obj->uart->BDH &= ~UARTLP_BDH_SBNS_MASK;
obj->uart->BDH |= (stop_bits << UARTLP_BDH_SBNS_SHIFT);
-
+
// restore C2 state
obj->uart->C2 |= c2_state;
}
@@ -292,4 +303,3 @@
void serial_break_clear(serial_t *obj) {
obj->uart->C2 &= ~UARTLP_C2_SBK_MASK;
}
-
--- a/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/serial_api.c Wed Jun 17 08:15:08 2015 +0100
+++ b/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/serial_api.c Wed Jun 17 09:00:08 2015 +0100
@@ -62,16 +62,20 @@
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]);
+ UART_HAL_DisableTransmitter(uart_addrs[obj->index]);
+ UART_HAL_DisableReceiver(uart_addrs[obj->index]);
pinmap_pinout(tx, PinMap_UART_TX);
pinmap_pinout(rx, PinMap_UART_RX);
if (tx != NC) {
+ UART_HAL_FlushTxFifo(uart_addrs[obj->index]);
+ UART_HAL_EnableTransmitter(uart_addrs[obj->index]);
+
pin_mode(tx, PullUp);
}
if (rx != NC) {
+ UART_HAL_EnableReceiver(uart_addrs[obj->index]);
pin_mode(rx, PullUp);
}
@@ -79,7 +83,6 @@
stdio_uart_inited = 1;
memcpy(&stdio_uart, obj, sizeof(serial_t));
}
- while(!UART_HAL_IsTxDataRegEmpty(uart_addrs[obj->index]));
}
void serial_free(serial_t *obj) {
