mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
Revision 128:c31e94a47539, committed 2016-05-13
- Comitter:
- mbed_official
- Date:
- Fri May 13 16:00:11 2016 +0100
- Parent:
- 127:c0c383bd32af
- Child:
- 129:8a86d1aafce0
- Commit message:
- Synchronized with git revision 7bd986845c110b2c4e8bc58739a74757dd6ff493
Full URL: https://github.com/mbedmicro/mbed/commit/7bd986845c110b2c4e8bc58739a74757dd6ff493/
* [STM32F1 F4] Fix #1705 MBED_37
The transmit data register needs to be flushed at the initialisation of
the uart.
In case previous transmission was interrupted by a uart init, uart may
contain a char that will be transmitted at the next start.
This is the case in MBED_37 test (serial_auto_nc_rx).
The MCU is writting {{start}}\n
At the moment of the \n the main program is handling 'new serial'. The
next time the main program is handling a printf, the previous \n is
still present in the uart->DR register and is transmitted.
This cannot happen anymore with this commit
* [STM32_F1] Fix #1705 MBED_37 by resetting the uart
Changed in this revision
--- a/targets/hal/TARGET_STM/TARGET_STM32F1/serial_api.c Fri May 13 09:15:11 2016 +0100
+++ b/targets/hal/TARGET_STM/TARGET_STM32F1/serial_api.c Fri May 13 16:00:11 2016 +0100
@@ -50,6 +50,7 @@
static void init_uart(serial_t *obj)
{
+
UartHandle.Instance = (USART_TypeDef *)(obj->uart);
UartHandle.Init.BaudRate = obj->baudrate;
@@ -67,6 +68,7 @@
}
HAL_UART_Init(&UartHandle);
+
}
void serial_init(serial_t *obj, PinName tx, PinName rx)
@@ -81,14 +83,20 @@
// Enable UART clock
if (obj->uart == UART_1) {
+ __USART1_FORCE_RESET();
+ __USART1_RELEASE_RESET();
__HAL_RCC_USART1_CLK_ENABLE();
obj->index = 0;
}
if (obj->uart == UART_2) {
+ __USART2_FORCE_RESET();
+ __USART2_RELEASE_RESET();
__HAL_RCC_USART2_CLK_ENABLE();
obj->index = 1;
}
if (obj->uart == UART_3) {
+ __USART3_FORCE_RESET();
+ __USART3_RELEASE_RESET();
__HAL_RCC_USART3_CLK_ENABLE();
obj->index = 2;
}
--- a/targets/hal/TARGET_STM/TARGET_STM32F4/serial_api.c Fri May 13 09:15:11 2016 +0100
+++ b/targets/hal/TARGET_STM/TARGET_STM32F4/serial_api.c Fri May 13 16:00:11 2016 +0100
@@ -101,7 +101,6 @@
static void init_uart(serial_t *obj, UARTName instance)
{
-
UART_HandleTypeDef *handle = &UartHandle[SERIAL_OBJ(index)];
handle->Instance = (USART_TypeDef *)instance;
@@ -186,6 +185,7 @@
if (HAL_UART_Init(handle) != HAL_OK) {
error("Cannot initialize UART\n");
}
+
}
void serial_init(serial_t *obj, PinName tx, PinName rx)
@@ -202,6 +202,8 @@
// Enable USART clock
switch (instance) {
case UART_1:
+ __USART1_FORCE_RESET();
+ __USART1_RELEASE_RESET();
__HAL_RCC_USART1_CLK_ENABLE();
SERIAL_OBJ(index) = 0;
#if DEVICE_SERIAL_ASYNCH_DMA
@@ -209,6 +211,8 @@
#endif
break;
case UART_2:
+ __USART2_FORCE_RESET();
+ __USART2_RELEASE_RESET();
__HAL_RCC_USART2_CLK_ENABLE();
SERIAL_OBJ(index) = 1;
#if DEVICE_SERIAL_ASYNCH_DMA
@@ -217,6 +221,8 @@
break;
#if defined(USART3_BASE)
case UART_3:
+ __USART3_FORCE_RESET();
+ __USART3_RELEASE_RESET();
__HAL_RCC_USART3_CLK_ENABLE();
SERIAL_OBJ(index) = 2;
#if DEVICE_SERIAL_ASYNCH_DMA
@@ -226,6 +232,8 @@
#endif
#if defined(UART4_BASE)
case UART_4:
+ __USART4_FORCE_RESET();
+ __USART4_RELEASE_RESET();
__HAL_RCC_UART4_CLK_ENABLE();
SERIAL_OBJ(index) = 3;
#if DEVICE_SERIAL_ASYNCH_DMA
@@ -235,6 +243,8 @@
#endif
#if defined(UART5_BASE)
case UART_5:
+ __USART5_FORCE_RESET();
+ __USART5_RELEASE_RESET();
__HAL_RCC_UART5_CLK_ENABLE();
SERIAL_OBJ(index) = 4;
#if DEVICE_SERIAL_ASYNCH_DMA
@@ -244,6 +254,8 @@
#endif
#if defined(USART6_BASE)
case UART_6:
+ __USART6_FORCE_RESET();
+ __USART6_RELEASE_RESET();
__HAL_RCC_USART6_CLK_ENABLE();
SERIAL_OBJ(index) = 5;
#if DEVICE_SERIAL_ASYNCH_DMA
@@ -253,6 +265,8 @@
#endif
#if defined(UART7_BASE)
case UART_7:
+ __USART8_FORCE_RESET();
+ __USART8_RELEASE_RESET();
__HAL_RCC_UART7_CLK_ENABLE();
SERIAL_OBJ(index) = 6;
#if DEVICE_SERIAL_ASYNCH_DMA
@@ -262,6 +276,8 @@
#endif
#if defined(UART8_BASE)
case UART_8:
+ __USART8_FORCE_RESET();
+ __USART8_RELEASE_RESET();
__HAL_RCC_UART8_CLK_ENABLE();
SERIAL_OBJ(index) = 7;
#if DEVICE_SERIAL_ASYNCH_DMA
Helmut Tschemernjak
