2017-06-07 11:18 AM
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
Note: this post was migrated and contained many threaded conversations, some content may be missing.Solved! Go to Solution.
2017-06-13 09:06 PM
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,
Everything would work as you expected!
:)
Guess we need ST guys to fixed up the library.
2017-06-07 12:07 PM
Let's start at the start, are you really running a 19.5MHz external crystal?
Andrei
2017-06-07 02:54 PM
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?
2017-06-08 05:39 AM
Anyone else want to chime in for this? I need the answer asap. Thanks!
2017-06-08 09:51 AM
Hi, Ed!
Can you please tell me which mcu you are using? at least which series?
2017-06-08 09:56 AM
Suppose your HCLK is really 38.4MHz,
Check your Systick register:
see whether SysTick->LOAD == 38400 -1 ???
2017-06-08 10:09 AM
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!
2017-06-08 10:56 AM
Check your FW package version, is it 1.8.0 ?!
2017-06-08 11:11 AM
How do I check this?
2017-06-08 11:20 AM
In CubeMX, Project->Settings, you will see
if it's not the latest, go to Help->Install New Libraies, and download the latest one!