Quantcast

Use PWM on STM32F4-NUCLEO

classic Classic list List threaded Threaded
5 messages Options
Synaps3 Synaps3
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Use PWM on STM32F4-NUCLEO

Hi everyone !
I am new in the eLua community and i want to test the potential of eLua on a small robotic project.
My problem is that i don't understand at all how i can use PWM signal on my STM32F4-NUCLEO.

I have done this :

pwm.setup(0, 100, 75)
pwm.start(0)

But there is no pwm signal on any pin. That's why i gess i have to connect this PWM signal on a pin, maybe with a cpu.w32() on the right register but... I am not sure.

If anyone could give me a hand i would be very grateful !
jbsnyder jbsnyder
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use PWM on STM32F4-NUCLEO

Hi,

The PWM module has not been tested on the the nucleo boards but has on other STM32F4 parts. It should be simple to fix by referring to the reference manual and updating the platform.c for stm32f4.

I don't have a scope handy right now to test with but I can try to look at this soon. Otherwise  the configuration is done here if you'd like to look:

Looking at that and the nucleo datasheet it looks like that's using Port D 12-15 which aren't brought out on the nucleo. It could be that clocking or other things might need to be fixed as well but picking an appropriate timer and adjusting the pin config near the top of that section, lines 1281-1285, will probably get PWM outputs at least working.

Best.

-jsnyder




James Snyder
ph: (847) 448-0386


On Mon, Jun 8, 2015 at 12:47 PM, Synaps3 [via eLua Development] <[hidden email]> wrote:

Hi everyone !
I am new in the eLua community and i want to test the potential of eLua on a small robotic project.
My problem is that i don't understand at all how i can use PWM signal on my STM32F4-NUCLEO.

I have done this :

pwm.setup(0, 100, 75)
pwm.start(0)

But there is no pwm signal on any pin. That's why i gess i have to connect this PWM signal on a pin, maybe with a cpu.w32() on the right register but... I am not sure.

If anyone could give me a hand i would be very grateful !


If you reply to this email, your message will be added to the discussion below:
http://elua-development.2368040.n2.nabble.com/Use-PWM-on-STM32F4-NUCLEO-tp7578505.html
To start a new topic under eLua Development, email [hidden email]
To unsubscribe from eLua Development, click here.
NAML

Synaps3 Synaps3
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use PWM on STM32F4-NUCLEO

First of all thanks for your quick and complete answer !

I understand a little bit more what the problem is.
I read the NUCLEO board's documentation and i think i found something interresting on page 40/63.

If i understand well :

* The pin 7 of the port A is connected to the timer 1 channel 1
* The pin 6 of the port B is connected to the timer 4 channel 1
* The pin 7 of the port C is connected to the timer 3 channel 2
* The pin 10 of the port B is connected to the timer 2 channel 3
* The pin 4 of the port B is connected to the timer 3 channel 1
* The pin 3 of the port B is connected to the timer 2 channel 2

So in order to have two PWM signals i have to choose timer 2, GPIOB with pin 3 and 10.

jbsnyder jbsnyder
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use PWM on STM32F4-NUCLEO

Hi,

Sorry for the delay. Those ones should work, and I see those in the reference manual for the STM32F401:
(should be the same for the F411).

Looks like the ones you selected are Alternate Function 01 (on page 46) or GPIO_AF_TIM2.

Alternately, I haven't fully checked it out yet relative to other pins we're currently using, but TIM4 has channels all on Port B (6-9).

For that, I think you'd have:
#if defined( ELUA_BOARD_STM32F4ALT )
// Using Timer 8 (5 in eLua)
#define PWM_TIMER_ID    5
#define PWM_TIMER_NAME  TIM8
#define PWM_TIMER_AF    GPIO_AF_TIM8
#define PWM_GPIO_PORT   GPIOC
static const u8 pwm_gpio_pins_source[] = { GPIO_PinSource6, GPIO_PinSource7, GPIO_PinSource8, GPIO_PinSource9 };
#elif defined( FORSTM32F411RE ) || defined( FORSTM32F401RE )
#define PWM_TIMER_ID    3
#define PWM_TIMER_NAME  TIM4
#define PWM_TIMER_AF    GPIO_AF_TIM4
#define PWM_GPIO_PORT   GPIOB
static const u8 pwm_gpio_pins_source[] = { GPIO_PinSource6, GPIO_PinSource7, GPIO_PinSource8, GPIO_PinSource9 };
#else
// Using Timer 4 (3 in eLua)
#define PWM_TIMER_ID    3
#define PWM_TIMER_NAME  TIM4
#define PWM_TIMER_AF    GPIO_AF_TIM4
#define PWM_GPIO_PORT   GPIOD
static const u8 pwm_gpio_pins_source[] = { GPIO_PinSource12, GPIO_PinSource13, GPIO_PinSource14, GPIO_PinSource15 };
#endif

I just added an #elif block in the middle of the other two pin config options.

Are you building from sources yourself and have tried something or would you need a version committed to give a try?

Alternately, with some mild modifications I think we could make the 2 channels you suggested work too.

Best.

-jsnyder

On Wed, Jun 10, 2015 at 12:31 PM, Synaps3 [via eLua Development] <[hidden email]> wrote:
First of all thanks for your quick and complete answer !

I understand a little bit more what the problem is.
I read the NUCLEO board's documentation and i think i found something interresting on page 40/63.

If i understand well :

* The pin 7 of the port A is connected to the timer 1 channel 1
* The pin 6 of the port B is connected to the timer 4 channel 1
* The pin 7 of the port C is connected to the timer 3 channel 2
* The pin 10 of the port B is connected to the timer 2 channel 3
* The pin 4 of the port B is connected to the timer 3 channel 1
* The pin 3 of the port B is connected to the timer 2 channel 2

So in order to have two PWM signals i have to choose timer 2, GPIOB with pin 3 and 10.




If you reply to this email, your message will be added to the discussion below:
http://elua-development.2368040.n2.nabble.com/Use-PWM-on-STM32F4-NUCLEO-tp7578505p7578507.html
To start a new topic under eLua Development, email [hidden email]
To unsubscribe from eLua Development, click here.
NAML



--
James Snyder
ph: (847) 448-0386
Synaps3 Synaps3
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Use PWM on STM32F4-NUCLEO

Hi !

No problem for the delay, i was very busy too.

Thanks you very much for your help : the modifications that you suggest work perfectly !
I had some incomprehensible issues when i tried to compile elua on my laptop yesterday and today but i just succeed. I have tested all the four channels to command the intensity of a led : it works without problem.

Loading...