November 23, 2024, 10:50:10 PM

Olimex STM32-H407 PWM support

Started by mgulin, June 23, 2014, 03:55:00 PM

Previous topic - Next topic

mgulin

Hello everyone!
I'm having a little troubles working with an Olimex STM32-H407 development board (with STM32F407ZG inside). I've found example projects for IAR on Olimex pages, but we're rather using gcc (i.e. WinARM toolchain with OpenOCD) since we don't have a license for IAR.
My question is: can you please provide me with some basic .s (startup) and .ld (linker definitions) files that I can use to compile some basic C program for this particular Olimex board, e.g.:

int a=1,b=2,c;
int main() {
  while(1){
    c=a+b;
  }
}


I'm complete beginner in this matter. Can you recommend me some literature/tutorials on how to compose .s and .ld files for a generic microcontroller?

Best regards,
Marko.

JohnS

There are samples & tutorials if you google things like
STM32F4 gcc

John

LubOlimex

Hello mgulin,

You can check our OpenOCD package which has a simple blink example for the H407. Download link and information might be found here: https://www.olimex.com/Products/ARM/JTAG/_resources/OpenOCD/.

Unfortunately, it is hard to provide full support for the ever changing open source tools. Something more the initial attempts to configure an IDE properly might be very tough for a beginner. Make sure to find and follow a good guide on how to do it.

Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex

mgulin

Thank you for your help!
I managed to start up the board using a blinking LED example for gcc. For those who are interested, here you can find detailed tutorial how to do it: http://www.angstromsandalgorithms.com/free-eclipse-arm-gcc-openocd-toolchain-for-windows-part-1-introduction/

I have another question - I'm trying to find a PWM GPIO pin on the Olimex board. I saw in the STM32F407ZG processor datasheet that it has two timers, TIM1 and TIM8, that can be used for PWM. However, I'm having troubles finding this GPIO on the Olimex board. I couldn't find it on schematics provided in Olimex STM32-H407 datasheet either. Am I missing something, or this board doesn't have PWM GPIO pins?

Best,
Marko.

JohnS

Please use google with something like
STM32 PWM

Also refer to the device datasheet.

ST provide many samples, too.

John

mgulin

#5
Hi all,

I'm trying to use a PWM on the Olimex board to drive the green LED, but without any success. I managed to use timers for generating output signal to turn on/off the LED, but inside the infinite loop in main program. Now I want to generate this output signal in "background", i.e. as a PWM. Here is an example of a code that I've used:

int main(void)
{

GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;

/* Enable GPIOC */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

/* Enable TIM4 */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

/* Configure GPIOC to access LED */
GPIO_StructInit(&GPIO_InitStructure); // initalization

GPIO_PinAFConfig(GPIOC, GPIO_PinSource13, GPIO_AF_TIM4);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; // LED @ Olimex-STM32-H407
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);

TIM_TimeBaseStructInit(&TIM_TimeBaseInitStructure); // initialization

TIM_TimeBaseInitStructure.TIM_Prescaler = 40000; // 40 MHz -> 1 kHz (1 ms)
TIM_TimeBaseInitStructure.TIM_Period = 1000; // 1000 ms = 1 s
TIM_TimeBaseInitStructure.TIM_ClockDivision = 0;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseInitStructure);

TIM_OCStructInit(&TIM_OCInitStructure); // initialization

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_Pulse = 500;
TIM_OC1Init(TIM4, &TIM_OCInitStructure);

/* Enable TIM4 */
TIM_Cmd(TIM4, ENABLE);

while(1);

}


As a result of this program, LED is always ON (this is by default, since LED is ON for reset state), but it should be blinking with 50% duty-cycle, and with 1 sec time period.

I also tried to "send" a PWM signal on GPIO output and to monitor that port/pin with oscilloscope - in this case the output pin used is always at low level, i.e. in reset state.

Can you please tell me what am I doing wrong?

Thanks!

Best,
Marko.

mgulin

I found an error in the code above - I tried to use a TIM4 CH1 to drive GPIOC Pin0. However, this connection does not exist. Instead, TIM4 CH1 is connected on GPIOD Pin12. Now PWM works just fine.

Marko.