STM32F4 Disc Board PA9 PWM not working

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
chrystal
Posts: 7
Joined: Sat Jan 28, 2017 3:52 pm

STM32F4 Disc Board PA9 PWM not working

Post by chrystal »

Hello,

i'm trying to use PA9 as PWM Output. But does not work. The VBUS Led is always on. Pls help me. As you can see on the below image, the blue curve is PA9 PWM Output. The other 2 are PA8 and PA10.

Can anyone pls help me?

Code: Select all

#include "ch.h"
#include "hal.h"

static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {

  (void)arg;
  chRegSetThreadName("blinker");
  while (true) {
    palTogglePad(GPIOD, GPIOD_LED3);
    palTogglePad(GPIOD, GPIOD_LED4);
    palTogglePad(GPIOD, GPIOD_LED5);
    palTogglePad(GPIOD, GPIOD_LED6);

    chThdSleepMilliseconds(500);
  }
}


static PWMConfig pwm1cfg = {
  1000000,          /* 1MHz PWM clock frequency.   */
  US2ST(5000),      /* PWM period        */
  NULL,
  {
   {PWM_OUTPUT_ACTIVE_LOW, NULL},
   {PWM_OUTPUT_ACTIVE_LOW, NULL},
   {PWM_OUTPUT_ACTIVE_LOW, NULL},
   {PWM_OUTPUT_DISABLED, NULL}
  },
  0,
#if STM32_PWM_USE_ADVANCED
  0
#endif
};

int main(void) {

  halInit();
  chSysInit();


  pwmStart(&PWMD1, &pwm1cfg);

  palSetPadMode(GPIOA, 8, PAL_MODE_ALTERNATE(1));
  palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(1));
  palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(1));

  /*
   * Starts the PWM channel 0 using 75% duty cycle.
   */
  pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
  pwmEnableChannel(&PWMD1, 1, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));
  pwmEnableChannel(&PWMD1, 2, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 5000));

  /*
   * Activates the serial driver 2 using the driver default configuration.
   * PA2(TX) and PA3(RX) are routed to USART2.
   */

  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

  while (true) {
    chThdSleepMilliseconds(500);
  }
}
Attachments
NewFile1.png
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4 Disc Board PA9 PWM not working

Post by Giovanni »

Hi,

Is that pin free on your board? it could be connected to something and driven.

Other point US2ST cannot be used in the configuration structure, that macro is for system tick only, you need to specify the number of timer clock cycles as period in that field.

Giovanni
chrystal
Posts: 7
Joined: Sat Jan 28, 2017 3:52 pm

Re: STM32F4 Disc Board PA9 PWM not working

Post by chrystal »

Giovanni wrote:Hi,

Is that pin free on your board? it could be connected to something and driven.

Other point US2ST cannot be used in the configuration structure, that macro is for system tick only, you need to specify the number of timer clock cycles as period in that field.

Giovanni


Thanks for reply. No the Pin PA9 is connected mit GPIOA_VBUS_FS default. How can i remap PA9?
I removed US2ST und changed the line to 50. I still see same result. Only LD7 on the Discovery Board is off.


Thanks.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4 Disc Board PA9 PWM not working

Post by Giovanni »

Hi,

If PA9 is used then find on the DataSheet an alternate pin for that timer output, there is a table there.

Giovanni
Post Reply