Skip to main content
INaka.1
Associate III
July 27, 2020
Question

I'm using the STM32L4R5 with tthe STM32CUBE and I didin't get making the USART1 work. The CR1 register always is 0.

  • July 27, 2020
  • 5 replies
  • 1599 views

..

This topic has been closed for replies.

5 replies

S.Ma
Principal
July 27, 2020

go to debug mode and look at usart, gpio and sys/rcc registers for clock enable. track down the issue

INaka.1
INaka.1Author
Associate III
July 27, 2020

The register of USART1 always zero except for the ISR=c0

TDK
Super User
July 27, 2020

Enable the usart1 clock. Generate code with stm32cubemx to do this for you. Show your code.

"If you feel a post has answered your question, please click ""Accept as Solution""."
INaka.1
INaka.1Author
Associate III
July 27, 2020

Well... The clock has been enabled at 120MHz. Please, don't repair on my code. I'm a beginner.

njedwardz
Visitor II
November 23, 2020

I am encountering the same error; all other UARTs are working, using Nucleo-L4R5ZI. USART1 CR1 remains at 0, even after the MODIFY_REG instruction is issued during initialization. I suspect that this has something to do with USART1 being on APB2 while all other USARTs are on APB1.

Tesla DeLorean
Guru
November 23, 2020

If all the USART's registers are ZERO, then the clock is likely not properly enabled. Try ENABLING it

Inspect the registers for the RCC and make a determination if it relates to APB1 vs APB2

Last time I check this was coded properly for the L4

__USART1_CLK_ENABLE();

__HAL_RCC_USART1_CLK_ENABLE

#define __HAL_RCC_USART1_CLK_ENABLE()     do { \

                         __IO uint32_t tmpreg; \

                         SET_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN); \

                         /* Delay after an RCC peripheral clock enabling */ \

                         tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_USART1EN); \

                         UNUSED(tmpreg); \

                        } while(0)

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
njedwardz
Visitor II
November 23, 2020

By manually calling __HAL_RCC_USART1_CLK_ENABLE(), I can see that USART1 CR1 is now changing to the expected value (one would not think this step necessary, as this happens in HAL_UART_MspInit as generated by CubeMx prior to any configuration being attempted).

I am still not getting transmissions through USART1. I can confirm that all registers are identical between USART1 and USART2; USART2 is working as expected. I have confirmed that the pin I am using for USART1 is functional when used as a GPIO in output mode.

The line does not idle high as expected; it is just constantly low.

I can confirm that USART1 is enabled in APB2ENR and NOT in reset state in APB2RSTR.

njedwardz
Visitor II
November 23, 2020

For all who are experiencing this issue, upgrading to the latest version of STM32CubeIDE (1.5.0) successfully resolved my issue. I was previously using 1.3.0. I presume this error was caused by some issue in the CubeMX-generated initialization code.

INaka.1
INaka.1Author
Associate III
November 25, 2020

Hello dear friend!!!

I 've tried the suggestion of ST enginneer and used the the old version of STM32 CUBEMX Version 6.0.0

and the LPUSART worked properly.

Best regards