2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ I think we're going to need your schematic - can you upload it somewhere and share a link? Someone will stop by and edit it in. \$\endgroup\$ – user17592 Apr 15 '13 at 5:12
  • \$\begingroup\$ A minor comment: I'm not sure if int is capable of handling numbers as big as 100000 (it may very well be). It wouldn't if it's only 16 bit wide. To be sure I would go with int32_t (or uint32_t) instead for the delay function declaration. \$\endgroup\$ – fm_andreas Apr 15 '13 at 8:43
  • \$\begingroup\$ @fm_andreas, you may be right. but i also tried with value 100. but nothing happens. \$\endgroup\$ – Jaydeep Dhrangdhariya Apr 15 '13 at 9:02
  • \$\begingroup\$ Have you tried using JTAG/SWD to test your hardware? \$\endgroup\$ – Leon Heller Apr 15 '13 at 9:18
  • 1
    \$\begingroup\$ I don't think that the C compiler has to honor volatile on a variable that is not accessible from any other context (is local and its address isn't passed anywhere). I'd check the machine code that the delay loop is really there. \$\endgroup\$ – Kaz Apr 15 '13 at 22:10
2
\$\begingroup\$

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++)
    ;
}
\$\endgroup\$
1
\$\begingroup\$

If you use default clock configuration, you should connect 8 MHz crystal (or 25MHz for Connectivity line chips) to your chip.

A code snippet from system_stm32f10x.c in function SetSysClockTo24().

#elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
    /*  PLL configuration:  = (HSE / 2) * 6 = 24 MHz */

Hope that helps.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.