Page 1 of 1
GPIO not working as expected
Posted: Wed Jun 05, 2013 3:53 pm
by mr_michael_s
I am using a STM32f407 Dicovery board here. I try to toggle a GPIO pin as fast as possible.
palClearPad(GPIOE, 15);
//mDelay(18);
palSetPad(GPIOE, 15);
//mDelay(18);
If I toggle without delay only random spikes can be seen. When I enable the delay I can see the pin changing states on the Oszi. The same works much faster in a project without ChibiOS by using CMSIS-libraries. So it has probably to do with the clock and or port init. Has anyone had similar problems and could give me a hint which setting could be wrong ?
Thanks Michael
Re: GPIO not working as expected
Posted: Wed Jun 05, 2013 8:39 pm
by Giovanni
Hi,
The STM32F4 GPIO ports have a maximum frequency setting, it depends on how fast those GPIO bits are programmed.
PAL functions are inlined inside the calling application so it is possible that the generated pulses are too fast for the GPIO to react. You may try to add few cycles in between using the halPolledDelay() (the parameter is the number of cycles).
Giovanni
Re: GPIO not working as expected
Posted: Thu Jun 06, 2013 1:55 pm
by mr_michael_s
If I insert waits between the toggles it works, but its much slower compared to doing it without the ChibiOS. It must be something with the clock setup, prescalers or GPIO-config or flash-waitstate etc...
Thank You
Michael
Re: GPIO not working as expected
Posted: Thu Jun 06, 2013 3:07 pm
by Giovanni
ChibiOS uses the optimal settings as far I know. Are your GPIOs programmed for maximum speed? if in doubt check the SPEEDR GPIO register or alternatively post your initialization code.
Giovanni
Re: GPIO not working as expected
Posted: Thu Jun 06, 2013 7:49 pm
by mr_michael_s
Ahhhhhhhhh, finally I found my mistake...
the APB1 Divider somehow was set at 16, at 4 everything is OK.
Arrrrrrrrrggghg..
Michael
Re: GPIO not working as expected
Posted: Sat Jun 08, 2013 12:04 pm
by mr_michael_s
Well the main difference was the optimization settings for te compiler -O0 is ok but -O2 doesn't work. Some I will have a look at the generated code....
Re: GPIO not working as expected
Posted: Sat Jun 08, 2013 12:10 pm
by Giovanni
-O2 is much faster than -O0 so probably it is just adding more cycles between operations.
Giovanni