GPIO not working as expected

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
mr_michael_s
Posts: 13
Joined: Sat Jul 07, 2012 1:08 pm

GPIO not working as expected

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: GPIO not working as expected

Post 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
mr_michael_s
Posts: 13
Joined: Sat Jul 07, 2012 1:08 pm

Re: GPIO not working as expected

Post 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
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: GPIO not working as expected

Post 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
mr_michael_s
Posts: 13
Joined: Sat Jul 07, 2012 1:08 pm

Re: GPIO not working as expected

Post 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
mr_michael_s
Posts: 13
Joined: Sat Jul 07, 2012 1:08 pm

Re: GPIO not working as expected

Post 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....
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: GPIO not working as expected

Post by Giovanni »

-O2 is much faster than -O0 so probably it is just adding more cycles between operations.

Giovanni
Post Reply