Electronics > Microcontrollers

STM32 GPIO problem

(1/1)

cyberfish:
Hello!

I have recently assembled my custom STM32 board, and after a day of work, was finally able to program and debug it through JTAG.

However, my first program, that turns on 2 LEDs, isn't working.

I can trace the code running on the chip through gdb, so compiling/flashing/JTAG seem to not be the problem. The only problem is, the GPIO pin voltages aren't actually changing. The LEDs (on PB8 and PB9) don't light up, and I also verified with a scope (both are at DC 0V).

This is what I have -

--- Code: ---
#include "stm32/stm32f2xx.h"

void assert_failed(uint8_t* file, uint32_t line)
{
}

int main()
{
GPIO_InitTypeDef gpio_init;

GPIO_StructInit(&gpio_init);

gpio_init.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
gpio_init.GPIO_Mode = GPIO_Mode_OUT;
gpio_init.GPIO_OType = GPIO_OType_PP;

GPIO_Init(GPIOB, &gpio_init);

GPIO_SetBits(GPIOB, GPIO_Pin_8 | GPIO_Pin_9);

for(;;);
}

--- End code ---
Can anyone see what I'm doing wrong?

Thanks!

bruce273:
I had the same problem can't remember the code for it but you have to initialise the GPIO clock aswell for GPIO to work

cyberfish:
Thanks so much!! That was it!


--- Code: ---RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

--- End code ---

I have never been so excited to see 2 LEDs light up. It has taken me about 5 hours of head scratching already.

Never seen this kind of regional clock stuff coming from 8-bit micros.

Is it to save power by not clocking unused peripherals?

TheDirty:
Yes, ARM's generally have peripheral clocks, at least ARM7 and Cortex-M3/M0 do which are the only ones I'm familiar with.  You only enable what you are using.

bruce273:
I'm not sure I'd assume so too. It's also possible that it is there to reduce effects of the internal impedance and interference on the clock signal when the peripheral is not in use. Odd thing in both cases is the GPIO clock is still required when an alternative function like UART is used on a pin.

Navigation

[0] Message Index

There was an error while thanking
Thanking...
Go to full version