Skip to content
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

STM32G0: failed assertion trying to set USART4 baud rate #1529

Open
scgtrp opened this issue Mar 1, 2024 · 1 comment
Open

STM32G0: failed assertion trying to set USART4 baud rate #1529

scgtrp opened this issue Mar 1, 2024 · 1 comment

Comments

@scgtrp
Copy link

scgtrp commented Mar 1, 2024

I'm using revision 9545471 and targeting a STM32G070RBT6, which has a USART4.

When I call usart_set_baudrate(USART4, 100000) the device crashes due to an assertion failure at:

(gdb) bt
#0  cm3_assert_failed () at ../../cm3/assert.c:24
#1  0x08001964 in rcc_get_usart_clk_freq (usart=usart@entry=1073761280) at rcc.c:583
#2  0x08001be6 in usart_set_baudrate (usart=1073761280, baud=100000) at ../common/usart_common_all.c:55

That function doesn't know about USART4, because it's also missing from RCC_CCIPR (RM0454 p163):
image

I think what's going on there, based on this bit of the clock tree (RM0454 p124):
image
image
and this table in the USART docs (RM0454 p777):
image
is that this only works on "full" USARTs and not "basic" ones. It's unclear to me where the basic USARTs get their clock from.

(This also suggests it shouldn't even work on USART3 on the G070, but the previous revision of the board I'm working on used USART3 and it seemed to work fine, possibly by accident.)

@scgtrp
Copy link
Author

scgtrp commented Mar 5, 2024

For anyone who shows up here searching: I'm now successfully working around this by setting USART4_BRR directly, calculated using the APB clock, e.g.

USART4_BRR = rcc_clock_config[RCC_CLOCK_CONFIG_HSI_PLL_64MHZ].apb_frequency / 100000;

I think this means that adding "else just return the APB frequency" as a fallback case to rcc_get_usart_clk_freq() in place of the cm3_assert_not_reached() call that's there now would fix this, but I'm not certain enough that that's always correct to submit it as a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant