cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX timing

e d
Associate II
Posted on June 07, 2017 at 20:18

Hi guys,

I am running into some timing issue using CubeMX, probably after upgrading to the latest version. A couple of weeks ago I noticed my SysTick running roughly twice as fast as expected (half of 1ms) so I changed my 1ms systick to Timer2 which worked fine. Today I turned on my USART3 for the first time at 9600 BAUD and could not get the HyperTerm to receive correctly (all garbage). Then I took a closer look at the signal through the scope and noticed the BAUD was actually at about 23KBAUD, which was weird because I set it in the code as:

huart3.Init.BaudRate = 9600;

After mucking around I got the HyperTerm to work normally by changing the BAUD setting to:

huart3.Init.BaudRate = 4000; // This is actually 9600 BAUD (verified with scope)

I have a hunch the BAUD rate issue is related to the SysTick issue.Anyone has this issue or is familiar with CubeMX to give me a clue here?

Thanks,

ED

0690X00000607G5QAI.png

Note: this post was migrated and contained many threaded conversations, some content may be missing.
1 ACCEPTED SOLUTION

Accepted Solutions
Zt Liu
Senior III
Posted on June 14, 2017 at 06:06

I think I found why this would happen.....

using HAL library, here my Crystal is 9.8304MHz

in file stm32l4xx_hal_conf.h , you can find this macro

#if !defined (HSE_VALUE)

#define HSE_VALUE ((uint32_t)

9830400U

) /*!< Value of the External oscillator in Hz */

#endif /* HSE_VALUE */

Once you choose LL drivers, the project includesstm32l4xx_ll_rcc.h

Unfortunately, the macros in stm32l4xx_ll_rcc.his still as followed:

#if !defined (HSE_VALUE)

#define HSE_VALUE 8000000U /*!< Value of the HSE oscillator in Hz */

#endif /* HSE_VALUE */

If you manually modify this value to your crystal's frequency,

If you define the HSE_VALUE in the project setting (thanks

meyer.frank

‌ for reminding this!)

for example, in keil,

0690X00000602QRQAY.bmp

Everything would work as you expected!

🙂

Guess we need ST guys to fixed up the library.

View solution in original post

20 REPLIES 20
Posted on June 07, 2017 at 21:07

Let's start at the start, are you really running a 19.5MHz external crystal?

Andrei

Posted on June 07, 2017 at 21:54

19.2MHz to be exact. As I stated, I programmed the timer2 to run at 1ms interval with no problem so the timing for APB1 at 38.4MHz based on the 19.2MHz external crystal should be correct.

htim2.Instance = TIM2;

htim2.Init.Prescaler = 383;

htim2.Init.CounterMode = TIM_COUNTERMODE_UP;

htim2.Init.Period = 99;

Besides, SysTick should run at 1ms no matter what, am I right?

e d
Associate II
Posted on June 08, 2017 at 14:39

Anyone else want to chime in for this? I need the answer asap. Thanks!

Posted on June 08, 2017 at 16:51

Hi, Ed!

Can you please tell me which mcu you are using? at least which series?

Posted on June 08, 2017 at 16:56

Suppose your HCLK is really 38.4MHz,

Check your Systick register:

see whether SysTick->LOAD == 38400 -1 ???

e d
Associate II
Posted on June 08, 2017 at 17:09

I traced to this line and for some reason it says:

SysTick->LOAD  = (uint32_t)(ticks - 1UL); 

where ticks is 16000.... Where does this 16000 come from when I specified clearly the clock settings as seen in the CubeMX image? Is it possible that I have 2 clocks running because my timer2 is definitely derived out of the 38.4MHz HCLK. The SysTick seems to run out of the 16MHz internal clock. This would be extremely undesirable and CubeMX should resolve it somehow.

I am using the STM32L486VGT chipset. Thanks!

Posted on June 08, 2017 at 17:56

Check your FW package version, is it 1.8.0 ?!

e d
Associate II
Posted on June 08, 2017 at 18:11

How do I check this?

Posted on June 08, 2017 at 18:20

In CubeMX, Project->Settings, you will see

0690X00000602TOQAY.bmp

if it's not the latest, go to Help->Install New Libraies, and download the latest one!