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

STM32F412Cx USART3 contradiction between CMSIS and HAL #5968

Closed
sgauche opened this issue Feb 2, 2022 · 6 comments
Closed

STM32F412Cx USART3 contradiction between CMSIS and HAL #5968

sgauche opened this issue Feb 2, 2022 · 6 comments
Milestone

Comments

@sgauche
Copy link

sgauche commented Feb 2, 2022

CircuitPython version

Adafruit CircuitPython commit 9b32d549, Custom board with STM32F412CG

Code/REPL

None

Behavior

I am adding a board to CircuitPython with a STM32F412CG micro on the board. I ran into an error while building CircuitPython about USART3 functions:

common-hal/busio/UART.c: In function 'uart_clock_enable':
common-hal/busio/UART.c:484:9: error: implicit declaration of function '__HAL_RCC_USART3_FORCE_RESET' [-Werror=implicit-function-declaration]
484 | __HAL_RCC_USART3_FORCE_RESET();
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
common-hal/busio/UART.c:484:9: error: nested extern declaration of '__HAL_RCC_USART3_FORCE_RESET' [-Werror=nested-externs]
common-hal/busio/UART.c:485:9: error: implicit declaration of function '__HAL_RCC_USART3_RELEASE_RESET' [-Werror=implicit-function-declaration]
485 | __HAL_RCC_USART3_RELEASE_RESET();
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
common-hal/busio/UART.c:485:9: error: nested extern declaration of '__HAL_RCC_USART3_RELEASE_RESET' [-Werror=nested-externs]
common-hal/busio/UART.c:486:9: error: implicit declaration of function '__HAL_RCC_USART3_CLK_ENABLE' [-Werror=implicit-function-declaration]
486 | __HAL_RCC_USART3_CLK_ENABLE();
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
common-hal/busio/UART.c:486:9: error: nested extern declaration of '__HAL_RCC_USART3_CLK_ENABLE' [-Werror=nested-extern
]
common-hal/busio/UART.c: In function 'uart_clock_disable':
common-hal/busio/UART.c:559:9: error: implicit declaration of function '__HAL_RCC_USART3_CLK_DISABLE' [-Werror=implicit-function-declaration]
559 | __HAL_RCC_USART3_CLK_DISABLE();
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
common-hal/busio/UART.c:559:9: error: nested extern declaration of '__HAL_RCC_USART3_CLK_DISABLE' [-Werror=nested-externs]

Description

See STMicroelectronics/STM32CubeF4#42

In CMSIS/Device/ST/STM32F4xx/Include/stm32f412cx USART3_BASE is defined.

In STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h, USART3 functions are not defined for STM32F412Cx.

https://github.com/hathach/st_driver/blob/1900834751fd6754457874b8c971690bab33e0a7/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h#L4972-L4973

So that causes issues when common-hal/busio/UART.c sees USART3 as defined but can't find the functions for USART3.

The fix ST applied to their repo was to remove all of the #ifdef's for all USART3 define's in stm32f4xx_hal_rcc_ex.h. USART3 is available on the STM32F412CG, but only as half-duplex. See Table 2 note 2 in the STM32F412CG datasheet.

Additional information

No response

@sgauche sgauche added the bug label Feb 2, 2022
@tannewt tannewt added the stm label Feb 2, 2022
@tannewt tannewt added this to the Long term milestone Feb 2, 2022
@tannewt
Copy link
Member

tannewt commented Feb 2, 2022

Thanks for the issue! Is the best fix to switch to the STM repo for st_driver? Would you mind making a PR for it?

@sgauche
Copy link
Author

sgauche commented Feb 2, 2022

@tannewt
I was able to build successfully by only updating the stm32f4xx_hal_rcc_ex.h file to the latest from ST's repo.

I noticed that circuitpython has an archived repo as a submodule I think for the ST drivers. Are archived repo's able to be modified? This is the archived repo: https://github.com/hathach/st_driver

I'm not familiar enough with circuitpython yet to say whether it would be feasible to update to ST's latest release... There must have been a reason to point to an archived repo? Although it would be a nice update, it looks like most of the ST stuff in circuitpython is >2 years old.

I've seen @hathach 's name around here, maybe he would have some input on that?

@tannewt
Copy link
Member

tannewt commented Feb 2, 2022

It looks like TinyUSB switch to direct submodules to the ST repos: hathach/tinyusb#544

@hathach
Copy link
Member

hathach commented Feb 3, 2022

Yeah, we should switch to official st repo which is only available recently. The st_driver repo is created way before that.

@sgauche
Copy link
Author

sgauche commented Feb 3, 2022

I opened a PR to make this change #5976

@sgauche
Copy link
Author

sgauche commented Feb 4, 2022

PR #5976 was merged which fixes this issue.

@sgauche sgauche closed this as completed Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants