Skip to content

Commit

Permalink
Merge pull request #7717 from LMESTM/fix_checkfifo
Browse files Browse the repository at this point in the history
STM32: check for UART ongoing transfers before entering deepsleep
  • Loading branch information
Cruz Monrreal authored Aug 9, 2018
2 parents 2b92b26 + e12d98e commit e85acac
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 0 deletions.
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F0/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
#define DEVICE_ID_LENGTH 24

#include "objects.h"
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
#include "stm32f0xx_ll_usart.h"

#endif
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F1/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
#define DEVICE_ID_LENGTH 24

#include "objects.h"
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
#include "stm32f1xx_ll_usart.h"

#endif
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F2/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
#define DEVICE_ID_LENGTH 24

#include "objects.h"
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
#include "stm32f2xx_ll_usart.h"

#endif
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F3/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
#define DEVICE_ID_LENGTH 24

#include "objects.h"
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
#include "stm32f3xx_ll_usart.h"

#endif
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F4/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
#define DEVICE_ID_LENGTH 24

#include "objects.h"
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
#include "stm32f4xx_ll_usart.h"

#endif
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F7/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
#define DEVICE_ID_LENGTH 24

#include "objects.h"
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
#include "stm32f7xx_ll_usart.h"

#endif
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32L0/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
#define DEVICE_ID_LENGTH 24

#include "objects.h"
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
#include "stm32l0xx_ll_usart.h"

#endif
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32L1/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
#define DEVICE_ID_LENGTH 24

#include "objects.h"
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
#include "stm32l1xx_ll_usart.h"

#endif
2 changes: 2 additions & 0 deletions targets/TARGET_STM/TARGET_STM32L4/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
#define DEVICE_ID_LENGTH 24

#include "objects.h"
/* WORKAROUND waiting for mbed-os issue 4408 to be addressed */
#include "stm32l4xx_ll_usart.h"

#endif
101 changes: 101 additions & 0 deletions targets/TARGET_STM/serial_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,105 @@ int8_t get_uart_index(UARTName uart_name)
return -1;
}

/* Function to protect deep sleep while a seral Tx is ongoing on not complete
* yet. Returns 1 if there is at least 1 serial instance with ongoing ransfer
* 0 otherwise.
*/
int serial_is_tx_ongoing(void) {
int TxOngoing = 0;

#if defined(USART1_BASE)
if (LL_USART_IsEnabled(USART1) && !LL_USART_IsActiveFlag_TC(USART1)) {
TxOngoing |= 1;
}
#endif

#if defined(USART2_BASE)
if (LL_USART_IsEnabled(USART2) && !LL_USART_IsActiveFlag_TC(USART2)) {
TxOngoing |= 1;
}
#endif

#if defined(USART3_BASE)
if (LL_USART_IsEnabled(USART3) && !LL_USART_IsActiveFlag_TC(USART3)) {
TxOngoing |= 1;
}
#endif

#if defined(UART4_BASE)
if (LL_USART_IsEnabled(UART4) && !LL_USART_IsActiveFlag_TC(UART4)) {
TxOngoing |= 1;
}
#endif

#if defined(USART4_BASE)
if (LL_USART_IsEnabled(USART4) && !LL_USART_IsActiveFlag_TC(USART4)) {
TxOngoing |= 1;
}
#endif

#if defined(UART5_BASE)
if (LL_USART_IsEnabled(UART5) && !LL_USART_IsActiveFlag_TC(UART5)) {
TxOngoing |= 1;
}
#endif

#if defined(USART5_BASE)
if (LL_USART_IsEnabled(USART5) && !LL_USART_IsActiveFlag_TC(USART5)) {
TxOngoing |= 1;
}
#endif

#if defined(USART6_BASE)
if (LL_USART_IsEnabled(USART6) && !LL_USART_IsActiveFlag_TC(USART6)) {
TxOngoing |= 1;
}
#endif

#if defined(UART7_BASE)
if (LL_USART_IsEnabled(UART7) && !LL_USART_IsActiveFlag_TC(UART7)) {
TxOngoing |= 1;
}
#endif

#if defined(USART7_BASE)
if (LL_USART_IsEnabled(USART7) && !LL_USART_IsActiveFlag_TC(USART7)) {
TxOngoing |= 1;
}
#endif

#if defined(UART8_BASE)
if (LL_USART_IsEnabled(UART8) && !LL_USART_IsActiveFlag_TC(UART8)) {
TxOngoing |= 1;
}
#endif

#if defined(USART8_BASE)
if (LL_USART_IsEnabled(USART8) && !LL_USART_IsActiveFlag_TC(USART8)) {
TxOngoing |= 1;
}
#endif

#if defined(UART9_BASE)
if (LL_USART_IsEnabled(UART9) && !LL_USART_IsActiveFlag_TC(UART9)) {
TxOngoing |= 1;
}
#endif

#if defined(UART10_BASE)
if (LL_USART_IsEnabled(UART10) && !LL_USART_IsActiveFlag_TC(UART10)) {
TxOngoing |= 1;
}
#endif

#if defined(LPUART1_BASE)
if (LL_USART_IsEnabled(LPUART1) && !LL_USART_IsActiveFlag_TC(LPUART1)) {
TxOngoing |= 1;
}
#endif

/* If Tx is ongoing, then transfer is */
return TxOngoing;
}

#endif /* DEVICE_SERIAL */
12 changes: 12 additions & 0 deletions targets/TARGET_STM/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,20 @@ void hal_sleep(void)
core_util_critical_section_exit();
}

extern int serial_is_tx_ongoing(void);

void hal_deepsleep(void)
{
/* WORKAROUND:
* MBED serial driver does not handle deepsleep lock
* to prevent entering deepsleep until HW serial FIFO is empty.
* This is tracked in mbed issue 4408.
* For now, we're checking all Serial HW FIFO. If any transfer is ongoing
* we're not entering deep sleep and returning immediately. */
if(serial_is_tx_ongoing()) {
return;
}

// Disable IRQs
core_util_critical_section_enter();

Expand Down

0 comments on commit e85acac

Please sign in to comment.