Electronic – STM32 program not executing

cmicrocontrollerprogrammingstm32

I am currently trying to make my own stm32 development board. i have stm32f100c4t6 microcontroller mounted on pcb.
I am using Atollic True studio free edition. i had made small blink led program as below.

#include <stddef.h>
#include "stm32f10x.h"

void delay(int count)
{
    volatile int i;

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

GPIO_InitTypeDef GPIO_InitStructure;

int main(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 ;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    while (1)
    {
        delay(100000);
        GPIOA->BSRR = 0xF << 3;
        delay(100000);
        GPIOA->BRR = 0xF << 3;
    }
}

I have used st flash loader demonstrator under windows to load program to flash memory. however it detects the flash memory size as 32 KB whereas actually it has 16 KB. but program loaded to flash and verified successfully. (it detects device ID as 0x420 which is for medium density value line whereas this microcontroller is low-density value line.)

When i change the jumper setting of BOOT0 to ground to put it in execution mode, nothing happens. the pin PA3 to P6 remains at 0v. i have connected 24 MHz crystal as main crytal and 32.768KHz as RTC crystal. I can get voltages around 1.8v at 24 MHz crystal. the other crystal pins remains at 0v. is this wrong?

I have also tried stm32flash under linux to load program, it loads and verify the program sucessfully. but, it also detects microcontroller as mediam density value line (128 KB).

I am stuck at this situation. any help would be appreciable.

Thanks for reading.

EDIT: I have attached link of
schematic.

Best Answer

Here is the simplest possible LED flasher program that works on the STM32VL Discovery board:

/* Test.c
** Simple program for STM32F100RB to flash LED on PC_9
**
*/

#include <stm32f10x.h>

void delay(void);

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

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

void delay(void)
{
  volatile unsigned int i;

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