/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Did I do anything wrong on my first Primer1 project?

Username:     
Password:     
             

Forum

# 1   2009-10-18 14:09:11 Did I do anything wrong on my first Primer1 project?

erna
New member
Registered: 2009-10-17
Posts: 3

Did I do anything wrong on my first Primer1 project?

Hello,

having developed applications for Atmel's 8bit microcontrollers for some time now I wanted to try ARM MCUs. The Primer1 seemed like an ideal tool to get started with it but I now realize that programming ARM MCUs is not as easy as I expected it to be. This is why I wanted to show You my first “Hello World” application before flashing it onto the Primer and probably damaging something.

So what I did was downloading the newest version of the ST Standard Peripheral Library (3.1.2) and creating a new Ride project inspired by the GPIO example supplied with the library. I reused their stm32f10x_it.c/h and stm32f10x_conf.h, defined STM32F10X_MD and USE_STDPERIPH_DRIVER and used the startup code supplied with the library.
Since the ST library assumes an external 8 MHz crystal being connected to the MCU but the Primer is equipped with a 12 MHz crystal I changed HSE_Value in “stm32f10x.h” accordingly and replaced “RCC_CFGR_PLLMULL9” with “RCC_CFGR_PLLMULL6” in the following line of the SetSysClockTo72() function in system_stm32f10x.h:

Code:

RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9);

And now at last this is my main.c (which is also mostly a copy of the GPIO example):

Code:

#include "stm32f10x.h"
#include "stm32f10x_conf.h"

GPIO_InitTypeDef GPIO_InitStructure;

void Delay(__IO uint32_t nCount);

int main()
{
    SystemInit();

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC, DISABLE);
  
    /* Enable the GPIO_LED Clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

    /* Configure the GPIO_LED pin */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOB, &GPIO_InitStructure);

    while(1)
    {
        // LED0 on
        GPIOB->BSRR = GPIO_Pin_8;
        // delay
        Delay(0xAFFFF);
        // LED0 off
        GPIOB->BRR = GPIO_Pin_8;
        // delay
        Delay(0xAFFFF);
    }
}

void Delay(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}

Compiling it all works well. Have I done anything wrong or forgot something (and thereby putting the Primer hardware at risk)?

In addition to that question I was wondering whether there is any documentation on the peripherals of the STM32F10x family available. If You take a look at the datasheets of Atmel's AVRs every bit of every register controlling the peripherals is described very detailed. Is there anything similar for the STM32F10x?


Best regards

Offline

 

# 2   2009-10-18 19:54:00 Did I do anything wrong on my first Primer1 project?

erna
New member
Registered: 2009-10-17
Posts: 3

Re: Did I do anything wrong on my first Primer1 project?

Well, my second question has just been answered by finding the documents “STM32F10xxx Cortex-M3 programming manual” and the reference manual for the STM32 family (RM0008) I overlooked earlier.

Offline

 

# 3   2009-10-19 06:41:57 Did I do anything wrong on my first Primer1 project?

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Did I do anything wrong on my first Primer1 project?

Effectively the entire description of the STM32 peripehals are in the RM0008 manual.

Concerning the clock configuration, if you want to run at 72 MHz systemclock with a 12 MHz external quartz, you are right to change the line
     RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL9);

but, you have to declare the macro :
    #define SYSCLK_FREQ_72MHz  72000000

In this case the value of HSE_Value is not taken into account.

Anyway, your code seems to be correct, and there is no risk for your Primer hardware.

Yves

Offline

 

# 4   2009-10-19 13:07:30 Did I do anything wrong on my first Primer1 project?

erna
New member
Registered: 2009-10-17
Posts: 3

Re: Did I do anything wrong on my first Primer1 project?

Thank You very much!

Offline

 

Board footer