Enable half bridge for STM32G4 MCU

This commit is contained in:
Martin Jäger
2020-02-26 19:30:59 +01:00
parent 8307314000
commit 46630f88cb
3 changed files with 21 additions and 13 deletions
+10 -2
View File
@@ -106,7 +106,7 @@ class PWM_TIM3
}
};
#elif defined(STM32F0)
#elif defined(STM32F0) || defined(STM32G4)
class PWM_TIM1
{
@@ -115,7 +115,11 @@ class PWM_TIM1
static void _init_registers(uint32_t pwm_resolution)
{
// Enable peripheral clock of GPIOA and GPIOB
#ifdef STM32F0
RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN;
#else // STM32G4
RCC->AHB2ENR |= RCC_AHB2ENR_GPIOAEN | RCC_AHB2ENR_GPIOBEN;
#endif
// Enable TIM1 clock
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
@@ -124,9 +128,13 @@ class PWM_TIM1
GPIOB->MODER = (GPIOB->MODER & ~(GPIO_MODER_MODER13)) | GPIO_MODER_MODER13_1;
// Select AF2 on PA8 (TIM1_CH1) and PB13 (TIM1_CH1N)
#ifdef STM32F0
GPIOA->AFR[1] |= 0x2 << GPIO_AFRH_AFSEL8_Pos;
GPIOB->AFR[1] |= 0x2 << GPIO_AFRH_AFSEL13_Pos;
#else // STM32G4
GPIOA->AFR[1] |= 0x6 << GPIO_AFRH_AFSEL8_Pos;
GPIOB->AFR[1] |= 0x6 << GPIO_AFRH_AFSEL13_Pos;
#endif
// No prescaler --> timer frequency == SystemClock
TIM1->PSC = 0;