[SOLVED]STM32G431CBU6 : function (timer8).setMode() does not set the pins ...

Post Reply
trimarco232
Posts: 13
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

[SOLVED]STM32G431CBU6 : function (timer8).setMode() does not set the pins ...

Post by trimarco232 »

Code: Select all


#include <Arduino.h>
HardwareTimer timer1(TIM1);
HardwareTimer timer8(TIM8);

void setup() {
  Serial.begin(115200);
  delay(3000) ; // monitor

  // this works
  timer1.setMode(1, TIMER_OUTPUT_COMPARE_PWM1, PA8); // PA8's AF6 is TIM1_CH1
  timer1.setPrescaleFactor(170 - 1); //
  TIM1->ARR = 200 ; /// timer1.setOverflow(200); //
  TIM1->CCR1 = 50 ; /// timer1.setCaptureCompare(1, 50); // TIM1_CH1
  timer1.resume();

  // this doesn't work ...
  timer8.setMode(1, TIMER_OUTPUT_COMPARE_PWM1, PB6); // PB6's AF5 is TIM8_CH1
  timer8.setPrescaleFactor(170 - 1); //
  TIM8->ARR = 200 ; /// timer8.setOverflow(200); //
  TIM8->CCR1 = 25 ; /// timer8.setCaptureCompare(1, 25); // TIM8_CH1
  timer8.resume();
  // ... unless the pin AF is set manualy
  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_6, LL_GPIO_MODE_ALTERNATE);
  LL_GPIO_SetAFPin_0_7(GPIOB, LL_GPIO_PIN_6, GPIO_AF5_TIM8);
}

void loop() {
  Serial.print("o");
  delay(50) ;
}
hi , thank you !
by fpiSTM » Fri Sep 29, 2023 6:45 pm
Try PB6_ALT1 instead of PB6.
PB6 has several possibilities:
https://github.com/stm32duino/Arduino_C ... 9C9-L149C9
Go to full post
Last edited by trimarco232 on Tue Oct 03, 2023 12:35 pm, edited 1 time in total.
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32G431CBU6 : function (timer8).setMode() does not set the pins ...

Post by fpiSTM »

Try PB6_ALT1 instead of PB6.
PB6 has several possibilities:
https://github.com/stm32duino/Arduino_C ... 9C9-L149C9
trimarco232
Posts: 13
Joined: Wed Jul 12, 2023 11:09 am
Answers: 1

Re: STM32G431CBU6 : function (timer8).setMode() does not set the pins ...

Post by trimarco232 »

aw great thanks !
I am happy to see that it even works with negative channels , as they can be used as alternative pins for positive channels
my working code (I presume the same thing applies for other series) :

Code: Select all

// "vorbiden" pins :
// PA11 , PA12 : USB
// PA13 , PA14 : SW
// PB8 : BOOT0
// PC14 , PC15 : OSC32
// PB4, PB6 , PA10, PA9 : USB C : The pull-down effect on the CC lines can be removed by using the bit UCPD1_DBDIS =1 ???


#include <Arduino.h>
HardwareTimer timer1(TIM1);
HardwareTimer timer8(TIM8);

void setup() {
  Serial.begin(115200);
  delay(4000) ; // monitor

  timer1.setMode(2, TIMER_OUTPUT_COMPARE_PWM1, PA9); //
  TIM1->CCR2 = 100 ; /// timer1.setCaptureCompare(1, 50); // TIM1_CH2
  ///timer1.setPrescaleFactor(170 - 1); //
  ///TIM1->ARR = 200 ; /// timer1.setOverflow(200); //
  ///timer1.resume();

  timer1.setMode(3, TIMER_OUTPUT_COMPARE_PWM1, PA10); // 
  TIM1->CCR3 = 50 ; /// timer1.setCaptureCompare(1, 50); // TIM1_CH3
  timer1.setPrescaleFactor(170 - 1); //
  TIM1->ARR = 200 ; /// timer1.setOverflow(200); //
  timer1.resume();

  timer8.setMode(1, TIMER_OUTPUT_COMPARE_PWM1, PB_6_ALT1); // {PB_6_ALT1,  TIM8,  STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_TIM8, 1, 0)}, // TIM8_CH1
  TIM8->CCR1 = 25 ; /// timer8.setCaptureCompare(1, 25); // TIM8_CH1
  ///timer8.setPrescaleFactor(170 - 1); //
  ///TIM8->ARR = 200 ; /// timer8.setOverflow(200); //
  ///timer8.resume();

  timer8.setMode(2, TIMER_OUTPUT_COMPARE_PWM1, PB_4_ALT1); // {PB_4_ALT1,  TIM8,  STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM8, 2, 1)}, // TIM8_CH2N
  TIM8->CCR2 = 10 ; /// timer8.setCaptureCompare(2, 10); // TIM8_CH2N
  timer8.setPrescaleFactor(170 - 1); //
  TIM8->ARR = 200 ; /// timer8.setOverflow(200); //
  timer8.resume();

}

void loop() {
  Serial.print("o");
  delay(50) ;
}
Post Reply

Return to “PR's bugs and enhancements”