mbed SDK library sources

Fork of mbed-src by mbed official

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Mon Dec 09 11:15:04 2013 +0000
Parent:
54:24d77221bceb
Child:
56:99eb381a3269
Commit message:
Synchronized with git revision faee2bf073820222f14e0baf95ec002e8cfec21e

Full URL: https://github.com/mbedmicro/mbed/commit/faee2bf073820222f14e0baf95ec002e8cfec21e/

- use TC flag instead of TXE for TX interrupt
- clear interrupt flags to prevent possible interrupt storm

Changed in this revision

targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c Show annotated file Show diff for this revision Revisions of this file
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c	Sat Dec 07 12:45:04 2013 +0000
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/serial_api.c	Mon Dec 09 11:15:04 2013 +0000
@@ -182,30 +182,21 @@
  ******************************************************************************/
 
 // not api
-void uart1_irq(void) {
-    USART_TypeDef *usart = (USART_TypeDef *)UART_1;  
-    if (serial_irq_ids[0] != 0) {
-        if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) {
-            irq_handler(serial_irq_ids[0], TxIrq);
+static void uart_irq(USART_TypeDef* usart, int id) {
+    if (serial_irq_ids[id] != 0) {
+        if (USART_GetITStatus(usart, USART_IT_TC) != RESET) {
+            irq_handler(serial_irq_ids[id], TxIrq);
+            USART_ClearITPendingBit(usart, USART_IT_TC);
         }
         if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) {
-            irq_handler(serial_irq_ids[0], RxIrq);
+            irq_handler(serial_irq_ids[id], RxIrq);
+            USART_ClearITPendingBit(usart, USART_IT_RXNE);
         }
     }
 }
 
-// not api
-void uart2_irq(void) {
-    USART_TypeDef *usart = (USART_TypeDef *)UART_2;  
-    if (serial_irq_ids[1] != 0) {
-        if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) {
-            irq_handler(serial_irq_ids[1], TxIrq);
-        }
-        if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) {
-            irq_handler(serial_irq_ids[1], RxIrq);
-        }
-    }
-}
+static void uart1_irq(void) {uart_irq((USART_TypeDef*)UART_1, 0);}
+static void uart2_irq(void) {uart_irq((USART_TypeDef*)UART_2, 1);}
 
 void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) {
     irq_handler = handler;
@@ -233,7 +224,7 @@
             USART_ITConfig(usart, USART_IT_RXNE, ENABLE);
         }
         else { // TxIrq
-            USART_ITConfig(usart, USART_IT_TXE, ENABLE);
+            USART_ITConfig(usart, USART_IT_TC, ENABLE);
         }        
         
         NVIC_SetVector(irq_n, vector);