Electronic – STM32F103 GPIO not working

blinkcortex-m3eclipsegpiostm32f10x

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.

STM32F103C6 Board

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);
    }
}

Best Answer

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.