From 19ae097c62efb66eeaa7c8ba8778a9b26d092fe3 Mon Sep 17 00:00:00 2001 From: Sissors Date: Sat, 1 Mar 2014 16:38:03 +0100 Subject: [PATCH 1/4] Fixed writable for LPC1768 Bit 6 (0x40) is true if the peripheral is completely empty. Bit 5 (0x20) is true if the transmit hold register is empty, which is sufficient for it to be writable. The TxIrq uses the same requirement, so now it works together and BufferedSerial doesn't go haywire on LPC1768 --- .../mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c index 2a06b61c31..56c00414d9 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c @@ -368,7 +368,7 @@ int serial_writable(serial_t *obj) { if (NC != uart_data[obj->index].sw_cts.pin) isWritable = gpio_read(&uart_data[obj->index].sw_cts) == 0; if (isWritable) - isWritable = obj->uart->LSR & 0x40; + isWritable = obj->uart->LSR & 0x20; return isWritable; } From ace842b1f1e796191a5a9309a74436cf4162ccad Mon Sep 17 00:00:00 2001 From: Sissors Date: Sat, 1 Mar 2014 16:40:32 +0100 Subject: [PATCH 2/4] Fixed KL25Z/KL46Z RTC-IN pin function It used to set it to alternate function 2, which is I2C, and still works fine in all my tests. Not intended though, and might be giving others issues. 1 is the RTC_CLKIN --- .../TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PeripheralPins.c | 2 +- .../TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/PeripheralPins.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PeripheralPins.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PeripheralPins.c index a6ac2855df..86e0556ea6 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PeripheralPins.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL25Z/PeripheralPins.c @@ -19,7 +19,7 @@ /************RTC***************/ const PinMap PinMap_RTC[] = { - {PTC1, RTC_CLKIN, 2}, + {PTC1, RTC_CLKIN, 1}, }; /************ADC***************/ diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/PeripheralPins.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/PeripheralPins.c index 362b0e2f02..569f40c82c 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/PeripheralPins.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/PeripheralPins.c @@ -18,7 +18,7 @@ /************RTC***************/ const PinMap PinMap_RTC[] = { - {PTC1, RTC_CLKIN, 2}, + {PTC1, RTC_CLKIN, 1}, }; /************ADC***************/ From baa4003b9527d59b6d6caa6ab1b408e50a7659c5 Mon Sep 17 00:00:00 2001 From: Sissors Date: Sat, 1 Mar 2014 16:46:48 +0100 Subject: [PATCH 3/4] Revert "Fixed writable for LPC1768" This reverts commit 19ae097c62efb66eeaa7c8ba8778a9b26d092fe3. --- .../mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c index 56c00414d9..2a06b61c31 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c @@ -368,7 +368,7 @@ int serial_writable(serial_t *obj) { if (NC != uart_data[obj->index].sw_cts.pin) isWritable = gpio_read(&uart_data[obj->index].sw_cts) == 0; if (isWritable) - isWritable = obj->uart->LSR & 0x20; + isWritable = obj->uart->LSR & 0x40; return isWritable; } From 56ce1e7290939f7acc623c581cb2f25eaf39e0c3 Mon Sep 17 00:00:00 2001 From: Sissors Date: Sat, 1 Mar 2014 16:58:01 +0100 Subject: [PATCH 4/4] Fixed LPC1768 writable Now if no flow control is used it will check if holding register is empty, instead of complete UART is empty: The TxIrq uses the same requirement. Currently BufferedSerial (and everyone else trying something similar) goes haywire because it doesn't just check if writable, but also if done writing. If flow control is enabled nothing is changed. --- .../targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c index 2a06b61c31..d6c60a852b 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c @@ -364,12 +364,10 @@ int serial_readable(serial_t *obj) { } int serial_writable(serial_t *obj) { - int isWritable = 1; if (NC != uart_data[obj->index].sw_cts.pin) - isWritable = gpio_read(&uart_data[obj->index].sw_cts) == 0; - if (isWritable) - isWritable = obj->uart->LSR & 0x40; - return isWritable; + return (gpio_read(&uart_data[obj->index].sw_cts) == 0) && (obj->uart->LSR & 0x40); //If flow control: writable if CTS low + UART done + else + return obj->uart->LSR & 0x20; //No flow control: writable if space in holding register } void serial_clear(serial_t *obj) {