Page 1 of 1

Simple PWM setup question

Posted: Fri Nov 14, 2014 4:59 pm
by IgorEE
Hi,

Firstly, note that I am a newbie in RTOS world and I've been playing around with ChibiOS for a few days. I have a custom board with a STM32F103RE IC on it, and I've been trying to get some PWM action happening. Unfortunately, the compilation fails and I've been banging my head against the wall trying to figure out why, and I am sure some kind soul will figure it out in a matter of seconds.

The code is:

Code: Select all

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

static PWMConfig pwmconf = {
  10000,
  5000, 
  NULL,   /* No call back function */
  /* Channels 3 and 4 on TIM3 enabled */
  {
    {PWM_OUTPUT_DISABLED, NULL},
    {PWM_OUTPUT_DISABLED, NULL},
    {PWM_OUTPUT_ACTIVE_HIGH, NULL},
    {PWM_OUTPUT_ACTIVE_HIGH, NULL},
  },
  0,
  0,
#if STM32_PWM_USE_ADVANCED
  0
#endif
};

int main(void) {

  halInit();
  chSysInit();

  /* Enable PWM output TIM3, ch3 and ch4 (LED(PB0) and PB1) */
  palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2));
  palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATE(2));

  pwmStart(&PWMD3, &pwmconf);
  pwmEnableChannel(&PWMD3, 3, 5000);
  pwmEnableChannel(&PWMD3, 4, 5000);

  while (TRUE) {
    chThdSleepMilliseconds(5000);
  }
}


Looking at the datasheet, PB1 and PB0 should be TIM3_CH4 and TIM3_CH3. However the compilation fails with the following:

Code: Select all

main.c: In function 'main':
main.c:44:3: warning: implicit declaration of function 'PAL_MODE_ALTERNATE' [-Wimplicit-function-declaration]
   palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2));
   ^
Linking build/chARMINARM_PWM.elf
build/obj/main.o: In function `main':
/home/igor/Code/ChibiOS_2.6.6/demos/ARMCM3-STM32F103-ARMINARM_PWM/main.c:44: undefined reference to `PAL_MODE_ALTERNATE'
/home/igor/Code/ChibiOS_2.6.6/demos/ARMCM3-STM32F103-ARMINARM_PWM/main.c:45: undefined reference to `PAL_MODE_ALTERNATE'
collect2: error: ld returned 1 exit status
../../os/ports/GCC/ARMCMx/rules.mk:210: recipe for target 'build/chARMINARM_PWM.elf' failed
make: *** [build/chARMINARM_PWM.elf] Error 1



I have enabled the PWM driver in halconf.h and #define STM32_PWM_USE_TIM3 TRUE.
I also have a custom board.h for my board and I can post that if needed.

Any hints?
Thanks,
-Igor

Re: Simple PWM setup question

Posted: Fri Nov 14, 2014 8:21 pm
by Giovanni
Hi,

Probably you took the following macros:

Code: Select all

  /* Enable PWM output TIM3, ch3 and ch4 (LED(PB0) and PB1) */
  palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2));
  palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATE(2));


From a demo for the F3 or F4, the F1 has a different GPIO structure, plese see the PWM demo under ./testhal/STM32F1xx/PWM-ICU, the macros are a bit different.

Giovanni

Re: Simple PWM setup question

Posted: Sat Nov 15, 2014 1:25 pm
by IgorEE
Ciao Giovanni,

Grazie per la risposta,

I managed to compile the PWM-ICU test and upload it to the board, and then modify my program to compile as well.

Could you please point me to somewhere where I could learn more about the differences like this I need to be aware of between the F3, F4 and F1 MCUs? I have a board with the F4 and another one with a F1 and it would really help me to keep the ChibiOS APIs for the two architectures separate in my head.

Thanks,
-Igor

Re: Simple PWM setup question

Posted: Sat Nov 15, 2014 4:02 pm
by Giovanni
Hi,

It is the STM32 Reference Manual, difference in drivers are caused by differences in HW, this is why demos are duplicated for each sub-family.

In the file platform.mk you can see which driver each specific STM32 includes, for example GPIOv1 for F1, GPIOv2 all the others.

Giovanni