# STM32F103 GPIO not working

I am programming for LPC microcontrollers (mostly LPC1769), for the past few months with success. I decided though to give STM32 series a try.

I just received a no-name board using an STM32F103C8 MCU like the pictured one.

I am using Eclipse to develop my firmware, where I have also installed the ST's plugin for ARM development. I program the chip through UART utilizing the factory bootloader. I have also extracted the CMSIS library from ST's Cube library, and I have included it in my project.

What I am trying to achieve: This board has an LED on PC13, and I am trying just to blink it. My project builds fine, and it uploads fine too.

The problem: Nothing at all happens at the board. I believe that the GPIO is does not even getting configured as output.

I have tried lots of different codes. Here is an example:

#include "stm32f10x.h"

int main(void)
{
SystemInit();
SystemCoreClockUpdate();

RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;

GPIOC->CRH=0x33333333;

while(1)
{
volatile int i = 0;

for(i=0;i<0x40000;i++){
}

GPIOC->ODR ^= (1 << 13);
}
}

• You need a lot more setup than that to use a GPIO on this chip - look for a working example, unless you want to spend hours going through the programmer's manual yourself to figure it out from first principles. Even if you can't find something for the '103 examples from the '100 discovery board will work as it is the same basic idea, just without the USB. – Chris Stratton May 21 '15 at 18:49
• Well the peripheral is clocked by the CMSIS function SystemInit(). And enabled by RCC_APB2ENR_IOPCEN. Missing a lot? I can't any example with different instructions... – Fotis Panagiotopoulos May 21 '15 at 18:57
• Also I am mostly looking for pure CMSIS examples... Any idea? – Fotis Panagiotopoulos May 21 '15 at 18:59
• Peripherals are typically handled outside of CMSIS on these. As I mentioned before, there are the examples for the '100 discovery board. Realistically, once you have one piece of working code it's not hard to see what it is doing and re-implement that in some other way. It's not clear right now that you even know your program is loaded and running. – Chris Stratton May 21 '15 at 19:02
• Did you ever get it working? I have the same problem with the same board. – Violet Giraffe Dec 7 '15 at 18:16

Here is a simple program that should help:

/* main.c
** Simple program for Olimex STM32-H103 (STM32F103RB) to flash LED on PC12
**
*/

#include <stm32f10x.h>

void delay(void);

void main(void)
{
// I/O port C clock enable
RCC->APB2ENR = RCC_APB2ENR_IOPCEN;
// Set PC_12 to output
GPIOC->CRH &= ~(GPIO_CRH_MODE12 | GPIO_CRH_CNF12);
GPIOC->CRH |= GPIO_CRH_MODE12;

while(1)
{
GPIOC->BSRR = (1<<12);
delay();
GPIOC->BRR = (1<<12);
delay();
}
}

void delay(void)
{
volatile unsigned int i;

for (i = 0; i < 20000; i++)
;
}


It was written for the Rowley CrossWorks compiler.

• Have you tested it? It still isn't working for me... – Fotis Panagiotopoulos May 21 '15 at 19:40
• It worked for me. – Leon Heller May 21 '15 at 19:51

There was nothing wrong with my code. The above provided example works as it should.

The problem was in flashing the code to the MCU. Although the LPCXpresso I was previously using was using the .axf file, the STM32flash tool had to be fed with a .bin file, and this caused my confusion.