cancel
Showing results for 
Search instead for 
Did you mean: 

PWM pins on STM32F072CB

akshat
Associate II
Posted on October 12, 2016 at 08:37

Hello,

I am working on STM32F072CB micro controller on a custom board. I am using mbed compiler and IDE for the development. I am having an issue related to the PWM pins on mcu.

I have configure PB_4(pin 40) and PB_5(pin 41) pins as PwmOut pins, but I am not able to generate PWM signals on PB_5.

Can you please help me to figure out issue for the same?

Thank you.

#mbed
11 REPLIES 11
Walid FTITI_O
Senior II
Posted on October 12, 2016 at 13:15

Hi saraf.akshat, 

To let other community users helping you, try to provide more details about the hardware that you are using, if any external setup is established , and your code or part of it (Timer configuration for example).

I recommend that you run the ready-to-use example ''TIM_PWMOutput'' in the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef0.html

library package at this path : STM32Cube_FW_F0_V1.6.0\Projects\STM32F072RB-Nucleo\Examples\TIM\TIM_PWMOutput

Try to figure out what you have missed comparing with your own code (TIM2 is used in the example, replace it with TIM3)

-Hannibal-

akshat
Associate II
Posted on October 12, 2016 at 14:06

Hi Hannibal,

Thanks for you response.

Actually I am using mbed IDE and compiler for the development purpose.

I have attached a sample PWM sample code, reference board is selected as NUCLEO-F072RB. Please check that and help me.

________________

Attachments :

pwm_sample.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0rn&d=%2Fa%2F0X0000000bhQ%2FSRUeTagP_C2oMEBJ3TvhvZYYwDqc2zkbsyMSwpecfDE&asPdf=false
Posted on October 12, 2016 at 14:44

And can you toggle that pin manually, if you set it as a plain output?

JW
akshat
Associate II
Posted on October 12, 2016 at 15:28

Hi Jan,

Yes, when i am configuring these pins as DigitalOut, these are working properly.

Walid FTITI_O
Senior II
Posted on October 12, 2016 at 19:18

Hi saraf.akshat,

I see that you have already posted in the mbed communicty for this subject. I notify our mbed developper to investigate, and I will come back to you. 

-Hannibal-

Posted on October 12, 2016 at 19:20

According to the manual they are using PC7 (D9) for TIM3_CH2 and PB4 (D5) for TIM3_CH1

Now while I might expect getting the PWM out of PB5 (D4) TIM3_CH2 is possible, you'd likely have to dig back into the mbed pin definition stuff related to the board itself for that to happen.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
akshat
Associate II
Posted on October 13, 2016 at 07:07

Hi Hannibal,

Thank you so much for your support.

Walid FTITI_O
Senior II
Posted on October 13, 2016 at 11:22

Hi saraf.akshat,

We confirme the bug. A pull request is greated in the Github for fixing it at this

https://github.com/ARMmbed/mbed-os/pull/3008

Meanwhile, you can use the mbed-dev source in the mbed IDE and correct it in PeripheralPins.c as follow :

replace:

{PB_5, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3, 1, 0)},TIM3_CH2 
by: 
{PB_5, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3, 2, 0)}, TIM3_CH2

I gave you the same response on your mbed thread.

-Hannibal-
akshat
Associate II
Posted on October 13, 2016 at 12:14

Hi Hannibal,

Thank for the support.

I have gone through the mbed library source. I found the PeripheralPins.c file, but the PWM pin definition looks like this:

const PinMap PinMap_PWM[] = {

//  {PA_1,  PWM_2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2)},  // TIM2_CH2

    {PA_1,  PWM_15, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_TIM15)}, // TIM15_CH1N

    {PA_2,  PWM_15, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_TIM15)}, // TIM15_CH1

//  {PA_2,  PWM_2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2)},  // TIM2_CH3

    {PA_3,  PWM_15, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_TIM15)}, // TIM15_CH2

//  {PA_3,  PWM_2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2)},  // TIM2_CH4

    {PA_4,  PWM_14, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM14)}, // TIM14_CH1

//  {PA_6,  PWM_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3)},  // TIM3_CH1

    {PA_6,  PWM_16, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_TIM16)}, // TIM16_CH1

//  {PA_7,  PWM_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3)},  // TIM3_CH2

//  {PA_7,  PWM_1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1)},  // TIM1_CH1N

//  {PA_7,  PWM_14, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM14)}, // TIM14_CH1

    {PA_7,  PWM_17, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_TIM17)}, // TIM17_CH1

    {PA_8,  PWM_1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1)},  // TIM1_CH1

    {PA_9,  PWM_1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1)},  // TIM1_CH2

    {PA_10, PWM_1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1)},  // TIM1_CH3

    {PA_11, PWM_1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1)},  // TIM1_CH4

    {PB_0,  PWM_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3)},  // TIM3_CH3

//  {PB_0,  PWM_1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1)},  // TIM1_CH2N

//  {PB_1,  PWM_14, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_TIM14)}, // TIM14_CH1

    {PB_1,  PWM_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3)},  // TIM3_CH4

//  {PB_1,  PWM_1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1)},  // TIM1_CH3N

//  {PB_3,  PWM_2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2)},  // TIM2_CH2

    {PB_4,  PWM_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3)},  // TIM3_CH1

    {PB_5,  PWM_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM3)},  // TIM3_CH2

    {PB_6,  PWM_16, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM16)}, // TIM16_CH1N

    {PB_7,  PWM_17, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM17)}, // TIM17_CH1N

    {PB_8,  PWM_16, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM16)}, // TIM16_CH1

    {PB_9,  PWM_17, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM17)}, // TIM17_CH1

//  {PB_10, PWM_2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2)},  // TIM2_CH3

//  {PB_11, PWM_2,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM2)},  // TIM2_CH4

    {PB_13, PWM_1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1)},  // TIM1_CH1N

    {PB_14, PWM_15, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM15)}, // TIM15_CH1

//  {PB_14, PWM_1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1)},  // TIM1_CH2N

    {PB_15, PWM_15, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM15)}, // TIM15_CH2

//  {PB_15, PWM_1,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM1)},  // TIM1_CH3N

//  {PB_15, PWM_15, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM15)}, // TIM15_CH1N

    {PC_6,  PWM_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_TIM3)},  // TIM3_CH1

    {PC_7,  PWM_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_TIM3)},  // TIM3_CH2

    {PC_8,  PWM_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_TIM3)},  // TIM3_CH3

    {PC_9,  PWM_3,  STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_TIM3)},  // TIM3_CH4

    {NC,    NC,    0}

};

I think there is no need or provision to change the Timer3 channels in definition.

Should i need to look in the other source.