2023-03-15 10:35 AM
I have designed an audio device based on a STM32H743 MCU. For synchronization purposes I need to be able to count incoming USB frames.
To achieve this, I use TIM5 in slave mode, with ITR8 as its trigger.
The results are puzzling. I am getting either 1000 SOFs per second (as expected) - or 2000.
The behavior is specific to a particular MCU. I have 12 boards, all running the same code. Five count SOFs correctly and seven at twice the expected rate. Reflashing a MCU, even after a full chip erase, makes no difference.
The markings on all the processors are identical.
What might be going on? Any ideas?
2023-03-15 11:46 PM
> To achieve this, I use TIM5 in slave mode, with ITR8 as its trigger.
Read out and post TIM5 registers content.
How are you determining the count per second?
JW
2023-03-16 09:41 AM
2023-03-16 11:29 AM
If you stop execution and look at TIM5_CNT in debugger, refreshing it roughly once per second, do you see the same difference in increments on two different boards?
(In other words, I doubt your ThreadX task does what you describe or that executes once every 50ms in both cases. By using debugger and your own eyes, a whole bunch of software layers is excluded
An even better test would be to set up TIM5 to perform PWM one some of the TIM5_CHx and observe using oscilloscope/LA, if you have such pin available).
JW
2023-03-16 12:42 PM
I made the task blink a LED every second (10 periods on, 10 periods off) and there is no difference between the boards. I also made the boards output (over a USB serial port) the TIM5->CNT register every period, and sure enough, one increments 1000 per second and the other - 2000.
Identical boards, built by the same assembly house in the same batch, running the same code.
2023-03-16 01:10 PM
This is a mystery.
Both (all) devices are connected to the same port of the same host (PC)? Can you try if when connected to a different host (e.g. Linux PC) devices behave the same?
Can you please read out and check in perhaps similar manner (i.e. sending it through USB) content of OTG_DSTS.FNSOF of given USB module?
JW
2023-03-16 02:58 PM
Same port of the same host. I don't have a Linux host handy right now, but can probably find one later if I have to.
I tried reading the FNSOF field. Well, this is interesting. FNSOF is incrementing at the expected rate on all boards. The timers are still incrementing at either exactly that rate or double the rate.
Well, at least this gives me an elegant way to program around the problem. I will just use FNSOF instead of the timer. I will have to read it often enough to handle the counter wrapping, but that's not a big problem.
Thank you for looking at this!
2023-03-16 03:28 PM
In that case this sounds much like a hardware error.
@Amel NASRI , can this please be checked.
Thanks,
JW
2023-03-16 04:40 PM
Straight from a crystal ball - are you using HSE, what is connected to it and is a bypass enabled?
2023-03-16 04:43 PM
I am using HSE, 8 MHz crystal (ABM2-8.000MHZ-D4Y-T), bypass disabled.