-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STM32: check for UART ongoing transfers before entering deepsleep #7717
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -690,4 +690,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_IsTxOngoing(void) { | ||
int TxOngoing = 0; | ||
|
||
#if defined(USART1_BASE) | ||
if (LL_USART_IsEnabled(USART1) && !LL_USART_IsActiveFlag_TC(USART1)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When serial is first enabled is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm ... Reset value of TC flag is 1. It is set to 0 in case there is a new TX byte or in case it is explicitly cleared by software - which could be the case in serial ASYNCH mode ... Extract from spec: Interrupt and status register (USARTx_ISR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that in case of asynch I would expect the application or driver using this mode to be in charge of locking deep sleep until Tx is complete - don't you think ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was looking at the datasheet for the Bit 6 TC: Transmission complete There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you've got an old spec. In recent one (rev17), the reset value is 0xC0 Also I've just done tests (on NUCLEO_F429ZI) using Rx only on 1 UART while printing with another one and this works fine, i.e. Deep sleep is well entered and there is no garbage character at the end of the printed line (deep sleep is actually only entered after the transmission is complete). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah good catch, I had an old version of the datasheet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also had an old one ! ... so it took me some time and tests to figure that out :-) |
||
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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall this follow the style,
serial_is_tx_ongoing
- assuming its in the HAL (I can see this is close to driver naming asLL_USART_IsEnabled()
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right ! will do the change