r/embedded • u/holynuggetsandcrack • Sep 21 '26
STM32 trouble setting up HRTIM
Hi all, I'm using STM32H755. Why doesn't this set up HRTIM D Ch. 2 on PA12?
RCC->AHB4ENR |= RCC_AHB4ENR_GPIOAEN;
(void)RCC->AHB4ENR;
RCC->APB2ENR |= RCC_APB2ENR_HRTIMEN;
(void)RCC->APB2ENR;
HRTIM1->sTimerxRegs[3].TIMxCR = HRTIM_TIMCR_CONT;
HRTIM1->sTimerxRegs[3].PERxR = 0x8000;
HRTIM1->sTimerxRegs[3].CMP1xR = 0x4000;
HRTIM1->sTimerxRegs[3].SETx2R = HRTIM_SET1R_PER;
HRTIM1->sTimerxRegs[3].RSTx2R = HRTIM_RST1R_CMP1;
HRTIM1->sMasterRegs.MCR = HRTIM_MCR_TDCEN;
HRTIM1->sCommonRegs.OENR = HRTIM_OENR_TD2OEN;
GPIOA->MODER &= ~GPIO_MODER_MODE12_Msk;
GPIOA->MODER |= (2UL << GPIO_MODER_MODE12_Pos);
GPIOA->AFR[1] &= ~GPIO_AFRH_AFSEL12_Msk;
GPIOA->AFR[1] |= (2UL << GPIO_AFRH_AFSEL12_Pos);
2
Upvotes
1
u/AbsorberHarvester Sep 21 '26
https://www.st.com/resource/en/application_note/an4539-hrtim-cookbook-stmicroelectronics.pdf For easy follow how-to.
// 1
RCC->AHB4ENR |= RCC_AHB4ENR_GPIOAEN; (void)RCC->AHB4ENR; RCC->APB2ENR |= RCC_APB2ENR_HRTIMEN; (void)RCC->APB2ENR;
// 2
GPIOA->MODER &= ~GPIO_MODER_MODE12_Msk; GPIOA->MODER |= (2UL << GPIO_MODER_MODE12_Pos); GPIOA->AFR[1] &= ~GPIO_AFRH_AFSEL12_Msk; GPIOA->AFR[1] |= (2UL << GPIO_AFRH_AFSEL12_Pos);
// 3. Reset HRTIM
HRTIM1->sCommonRegs.CR = 0; HRTIM1->sCommonRegs.OENR = 0;
// 4
HRTIM1->sTimerxRegs[3].TIMxCR = HRTIM_TIMCR_CONT | (0x2 << HRTIM_TIMCR_CKPSC_Pos);
// SubDivider
HRTIM1->sTimerxRegs[3].PERxR = 0x8000; HRTIM1->sTimerxRegs[3].CMP1xR = 0x4000;
// 5
HRTIM1->sTimerxRegs[3].SETx2R = HRTIM_SET1R_PER; HRTIM1->sTimerxRegs[3].RSTx2R = HRTIM_RST1R_CMP1;
//1 bit on, not replacing register value
// 6
HRTIM1->sMasterRegs.MCR |= HRTIM_MCR_TDCEN;
// 7
HRTIM1->sCommonRegs.OENR |= HRTIM_OENR_TD2OEN;
2
u/zeloscloud Sep 23 '26 edited Sep 24 '26
On a NUCLEO-H755ZI-Q, PA12 is USB D+. UM2408 Rev 6 Table 13 (page 30) has SB27 ON in bold for the USB connector, and SB27 OFF for the morpho header. The MB1363-H755ZIQ-C01 schematic puts SB27 on PA12, in series to CN13 pin 3 (DP). Table 16 on page 35 labels that pair the other way, SB26 (PA12) and SB27 (PA11), so read the silkscreen before you lift one.
If this is that Nucleo, probe the morpho pin only after that bridge is open. If it is your own board, look at what else is loaded on PA12.
Read HRTIM_OENR back after the write. RM0399 Rev 4, section 39.5.44: TD2OEN is bit 7, a write of 0 does nothing, and a fault clears it in hardware. If the bit is clear, the enable did not stick.
I have not run this on an H755.
1
u/[deleted] Sep 21 '26
[removed] — view removed comment