Author Topic: STM32 GPIO problem  (Read 6894 times)

0 Members and 1 Guest are viewing this topic.

Offline cyberfishTopic starter

  • Regular Contributor
  • *
  • Posts: 240
  • Country: gb
STM32 GPIO problem
« on: July 27, 2011, 08:26:17 pm »
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: [Select]

#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(;;);
}
Can anyone see what I'm doing wrong?

Thanks!
 

Offline bruce273

  • Contributor
  • Posts: 39
  • Country: gb
Re: STM32 GPIO problem
« Reply #1 on: July 27, 2011, 08:29:55 pm »
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
 

Offline cyberfishTopic starter

  • Regular Contributor
  • *
  • Posts: 240
  • Country: gb
Re: STM32 GPIO problem
« Reply #2 on: July 27, 2011, 08:37:03 pm »
Thanks so much!! That was it!

Code: [Select]
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

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?
 

Offline TheDirty

  • Frequent Contributor
  • **
  • Posts: 440
  • Country: ca
Re: STM32 GPIO problem
« Reply #3 on: July 27, 2011, 08:42:03 pm »
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.
Mark Higgins
 

Offline bruce273

  • Contributor
  • Posts: 39
  • Country: gb
Re: STM32 GPIO problem
« Reply #4 on: July 27, 2011, 08:52:20 pm »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf