Skip to content

Commit e85acac

Browse files
author
Cruz Monrreal
authored
Merge pull request #7717 from LMESTM/fix_checkfifo
STM32: check for UART ongoing transfers before entering deepsleep
2 parents 2b92b26 + e12d98e commit e85acac

File tree

11 files changed

+131
-0
lines changed

11 files changed

+131
-0
lines changed

targets/TARGET_STM/TARGET_STM32F0/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@
3636
#define DEVICE_ID_LENGTH 24
3737

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

4042
#endif

targets/TARGET_STM/TARGET_STM32F1/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@
3636
#define DEVICE_ID_LENGTH 24
3737

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

4042
#endif

targets/TARGET_STM/TARGET_STM32F2/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@
3333
#define DEVICE_ID_LENGTH 24
3434

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

3739
#endif

targets/TARGET_STM/TARGET_STM32F3/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@
3636
#define DEVICE_ID_LENGTH 24
3737

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

4042
#endif

targets/TARGET_STM/TARGET_STM32F4/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@
3636
#define DEVICE_ID_LENGTH 24
3737

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

4042
#endif

targets/TARGET_STM/TARGET_STM32F7/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@
3636
#define DEVICE_ID_LENGTH 24
3737

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

4042
#endif

targets/TARGET_STM/TARGET_STM32L0/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@
3636
#define DEVICE_ID_LENGTH 24
3737

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

4042
#endif

targets/TARGET_STM/TARGET_STM32L1/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@
3636
#define DEVICE_ID_LENGTH 24
3737

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

4042
#endif

targets/TARGET_STM/TARGET_STM32L4/device.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@
3636
#define DEVICE_ID_LENGTH 24
3737

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

4042
#endif

targets/TARGET_STM/serial_api.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,4 +660,105 @@ int8_t get_uart_index(UARTName uart_name)
660660
return -1;
661661
}
662662

663+
/* Function to protect deep sleep while a seral Tx is ongoing on not complete
664+
* yet. Returns 1 if there is at least 1 serial instance with ongoing ransfer
665+
* 0 otherwise.
666+
*/
667+
int serial_is_tx_ongoing(void) {
668+
int TxOngoing = 0;
669+
670+
#if defined(USART1_BASE)
671+
if (LL_USART_IsEnabled(USART1) && !LL_USART_IsActiveFlag_TC(USART1)) {
672+
TxOngoing |= 1;
673+
}
674+
#endif
675+
676+
#if defined(USART2_BASE)
677+
if (LL_USART_IsEnabled(USART2) && !LL_USART_IsActiveFlag_TC(USART2)) {
678+
TxOngoing |= 1;
679+
}
680+
#endif
681+
682+
#if defined(USART3_BASE)
683+
if (LL_USART_IsEnabled(USART3) && !LL_USART_IsActiveFlag_TC(USART3)) {
684+
TxOngoing |= 1;
685+
}
686+
#endif
687+
688+
#if defined(UART4_BASE)
689+
if (LL_USART_IsEnabled(UART4) && !LL_USART_IsActiveFlag_TC(UART4)) {
690+
TxOngoing |= 1;
691+
}
692+
#endif
693+
694+
#if defined(USART4_BASE)
695+
if (LL_USART_IsEnabled(USART4) && !LL_USART_IsActiveFlag_TC(USART4)) {
696+
TxOngoing |= 1;
697+
}
698+
#endif
699+
700+
#if defined(UART5_BASE)
701+
if (LL_USART_IsEnabled(UART5) && !LL_USART_IsActiveFlag_TC(UART5)) {
702+
TxOngoing |= 1;
703+
}
704+
#endif
705+
706+
#if defined(USART5_BASE)
707+
if (LL_USART_IsEnabled(USART5) && !LL_USART_IsActiveFlag_TC(USART5)) {
708+
TxOngoing |= 1;
709+
}
710+
#endif
711+
712+
#if defined(USART6_BASE)
713+
if (LL_USART_IsEnabled(USART6) && !LL_USART_IsActiveFlag_TC(USART6)) {
714+
TxOngoing |= 1;
715+
}
716+
#endif
717+
718+
#if defined(UART7_BASE)
719+
if (LL_USART_IsEnabled(UART7) && !LL_USART_IsActiveFlag_TC(UART7)) {
720+
TxOngoing |= 1;
721+
}
722+
#endif
723+
724+
#if defined(USART7_BASE)
725+
if (LL_USART_IsEnabled(USART7) && !LL_USART_IsActiveFlag_TC(USART7)) {
726+
TxOngoing |= 1;
727+
}
728+
#endif
729+
730+
#if defined(UART8_BASE)
731+
if (LL_USART_IsEnabled(UART8) && !LL_USART_IsActiveFlag_TC(UART8)) {
732+
TxOngoing |= 1;
733+
}
734+
#endif
735+
736+
#if defined(USART8_BASE)
737+
if (LL_USART_IsEnabled(USART8) && !LL_USART_IsActiveFlag_TC(USART8)) {
738+
TxOngoing |= 1;
739+
}
740+
#endif
741+
742+
#if defined(UART9_BASE)
743+
if (LL_USART_IsEnabled(UART9) && !LL_USART_IsActiveFlag_TC(UART9)) {
744+
TxOngoing |= 1;
745+
}
746+
#endif
747+
748+
#if defined(UART10_BASE)
749+
if (LL_USART_IsEnabled(UART10) && !LL_USART_IsActiveFlag_TC(UART10)) {
750+
TxOngoing |= 1;
751+
}
752+
#endif
753+
754+
#if defined(LPUART1_BASE)
755+
if (LL_USART_IsEnabled(LPUART1) && !LL_USART_IsActiveFlag_TC(LPUART1)) {
756+
TxOngoing |= 1;
757+
}
758+
#endif
759+
760+
/* If Tx is ongoing, then transfer is */
761+
return TxOngoing;
762+
}
763+
663764
#endif /* DEVICE_SERIAL */

targets/TARGET_STM/sleep.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,20 @@ void hal_sleep(void)
157157
core_util_critical_section_exit();
158158
}
159159

160+
extern int serial_is_tx_ongoing(void);
161+
160162
void hal_deepsleep(void)
161163
{
164+
/* WORKAROUND:
165+
* MBED serial driver does not handle deepsleep lock
166+
* to prevent entering deepsleep until HW serial FIFO is empty.
167+
* This is tracked in mbed issue 4408.
168+
* For now, we're checking all Serial HW FIFO. If any transfer is ongoing
169+
* we're not entering deep sleep and returning immediately. */
170+
if(serial_is_tx_ongoing()) {
171+
return;
172+
}
173+
162174
// Disable IRQs
163175
core_util_critical_section_enter();
164176

0 commit comments

Comments
 (0)