2
\$\begingroup\$

I am making a sound card with STM32H750 and USB3300. I am using standard Stm32CubeMX USB driver.

To do that, I need to track the number of I2S sample rate clocks per SOF. The idea is to use TIM5 as a counter, by supplying it an external clock via TIM5_ETR pin and resetting it using the internal ITR signal from USB.

I've successfully configured USB and it's SOF (the SOF handler is working), but for some reason the timer does not reset.

Here is the configuration code:

RCC->AHB4ENR |= RCC_AHB4ENR_GPIOAEN;
MODIFY_REG(GPIOA->MODER, GPIO_MODER_MODE4_Msk, 0b10 << GPIO_MODER_MODE4_Pos);
GPIOA->AFR[0] |= 2 << GPIO_AFRL_AFSEL4_Pos;

NVIC_SetPriority(TIM5_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 3, 2));
NVIC_EnableIRQ(TIM5_IRQn);

RCC->APB1LENR |= RCC_APB1LENR_TIM5EN;
TIM5->PSC = 256 - 1;
TIM5->ARR = 0xFFFFFFFF;
TIM5->CR1 |= TIM_CR1_ARPE;
TIM5->DIER |= TIM_DIER_UIE | TIM_DIER_TIE;

TIM5->SMCR |= TIM_SMCR_ECE;

TIM5->SMCR |= 0b01011 << TIM_SMCR_TS_Pos;
TIM5->SMCR |= 0b0100 << TIM_SMCR_SMS_Pos;

__DMB();
TIM5->CR1 |= TIM_CR1_CEN;

Timer internal triggers

Also, for some reason, the USB HS description in the reference manual contradicts the timer internal trigger connections (it says that USB HS SOF is ITR1, not ITR7):

SOF ITR1

I've tried ITR1 as well - still does not work. Neither does the counter reset or the trigger interrupt being called.

What am I missing? Is there some USB HS configuration that needs to be done?

RM0433 Reference Manual

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I reported the incorrect ITR number here. \$\endgroup\$
    – wek
    Commented Aug 13 at 13:06

1 Answer 1

4
\$\begingroup\$
TIM5->SMCR |= 0b01011 << TIM_SMCR_TS_Pos;
TIM5->SMCR |= 0b0100 << TIM_SMCR_SMS_Pos;

TIMx_SMCR.TS (and TIMx_SMCR.SMS) are not continuous bitfields, for historical reasons:

enter image description here

Source: RM0433 Reference Manual

\$\endgroup\$
5
  • \$\begingroup\$ wek - Thanks for writing this answer. Re site rules: (a) The original answer didn't include the required reference for the copied image. There is no exemption for datasheets etc. so please remember to include the name & source link for copied material (even if you slightly adapt it e.g. by putting those coloured boxes, the original source must be referenced). Another site member kindly added the required reference this time. (b) Are you associated with the other link you gave? If so, that affiliation must be disclosed. Are there any questions on that? TY \$\endgroup\$
    – SamGibson
    Commented Aug 13 at 15:20
  • \$\begingroup\$ @SamGibson, Your welcome. Re re site rules: my intention is to help, don't have time to discuss policies, however noble. a) I always do screenshots from RM so that it includes the RM number which is on every page; STM32 users know what RM are and presumably can google for it so putting extra links is superfluous and waste of time/resources/etc. I prefer ignoring SO/SE if SO/SE does not see this as sufficient. b) yes; have some template to do that with no hassle? \$\endgroup\$
    – wek
    Commented Aug 13 at 15:45
  • \$\begingroup\$ wek - Thanks for your reply. (a) "I prefer ignoring SO/SE if SO/SE does not see this as sufficient." I hope you will reconsider. The requirement to include the name & link of the source exists in 3 places: The "referencing rule"; Code of Conduct; and SE Terms of Service: "all Public Content you contribute {...} must have appropriate attribution.". Just the source name & link is needed, as another site member added for you this time. (b) Just add "(my site)" next to the link \$\endgroup\$
    – SamGibson
    Commented Aug 13 at 16:57
  • \$\begingroup\$ @SamGibson, "all Public Content you contribute {...} must have appropriate attribution." as I've explained, the RM number is always there and given context (STM32), I consider that to be reasonably appropriate attribution. Finding the RM's link - which btw. is volatile - copypaste it etc. takes time which is unreasonable burden on my side. The OP already has given RM at hand from principle, others can find easily. Given you (as SO/SE representative/moderator) don't find this sufficient not even willing to discuss, the rest is moot. \$\endgroup\$
    – wek
    Commented Aug 13 at 17:06
  • \$\begingroup\$ wek - I'm genuinely sorry you see things that way :( :( As one example, I could explain the unreasonable burden which not supplying the link adds to other people (i.e. all the readers who want to see the source and learn more / have questions / need to check details etc. - they all have to search, when just one person, you, could have searched once) but I sense you would not be open to that counter-argument. || I'll report your refusal to follow the referencing rule (with your stated reasons) to Stack Exchange and, as I have to do, I'll follow their guidance when they reply. \$\endgroup\$
    – SamGibson
    Commented Aug 13 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.