Home > Back-end >  STM32 programming
STM32 programming

Time:03-16



Stm32f10x. H file
/used to store the STM32 register mapping code

//peripherals perirhral

# define PERIPH_BASE ((unsigned int) 0 x40000000)
# define APB1PERIPH_BASE PERIPH_BASE
# define APB2PERIPH_BASE (PERIPH_BASE + 0 x10000)
# define AHBPERIPH_BASE (PERIPH_BASE + 0 x20000)


# define RCC_BASE (AHBPERIPH_BASE + 0 x1000)
# define GPIOB_BASE (APB2PERIPH_BASE + 0 x0c00)


# define RCC_APB2ENR * (unsigned int *) (RCC_BASE + 0 x18)

# define GPIOB_CRL * (unsigned int *) (GPIOB_BASE + 0 x00)
# define GPIOB_CRH * (unsigned int *) (GPIOB_BASE + 0 x04)
# define GPIOB_IDR * (unsigned int *) (GPIOB_BASE + 0 x08)
# define GPIOB_ODR * (unsigned int *) (GPIOB_BASE + 0 x0c)
# define GPIOB_BSRR * (unsigned int *) (GPIOB_BASE + 0 x10)
# define GPIOB_BRR * (unsigned int *) (GPIOB_BASE + 0 x14)
# define GPIOB_LCKR * (unsigned int *) (GPIOB_BASE + 0 x18)

Typedef unsigned int uint32_t;
Typedef unsigned short uint16_t;

Typedef struct
{
Uint32_t CRL.
Uint32_t CRH.
Uint32_t IDR;
Uint32_t ODR;
Uint32_t BSRR;
Uint32_t BRR.
Uint32_t LCKR;
} GPIO_TypeDef;


Typedef struct
{
Uint32_t CR;
Uint32_t CFGR;
Uint32_t CIR.
Uint32_t APB2RSTR;
Uint32_t APB1RSTR;
Uint32_t AHBENR;
Uint32_t APB2ENR;
Uint32_t APB1ENR;
Uint32_t BDCR;
Uint32_t CSR;
} RCC_TypeDef


# define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
# define RCC ((RCC_TypeDef *) RCC_BASE)

. The main c files

//# if 0

//# include

//sbit LED=P0 ^ 0

//void main (void)
//{
//P0=0 xfe;//bus operation strP0 0 x80
//
//the LED=0;//a
//}

//# endif



# include "stm32f10x. H"

Int main (void)

{
# if 0
//open GPIOB port clock
* * (unsigned int) 0 x40021018 |=((1) & lt; <3);
//configuration IO mouth for the output
* * (unsigned int) 0 x40010c00 |=((1) & lt; <(4 * 0));
//control the ODR register
* * (unsigned int) 0 x40010c0c & amp;=~ (1 & lt; <0);




# elif 0

//open GPIOB port clock
RCC_APB2ENR |=((1) & lt; <3);

//configuration IO mouth for the output
GPIOB_CRL & amp;=((0 x0f) & lt; <(4 * 0));
GPIOB_CRL |=((1) & lt; <(4 * 0));

//control the ODR register
GPIOB_ODR & amp;=~ (1 & lt; <0);
//GPIOB_ODR |=(1 & lt; <0);

Elif # 1

//open GPIOB port clock
RCC - & gt; APB2ENR |=((1) & lt; <3);

//configuration IO mouth for the output
GPIOB - & gt; The CRL & amp;=((0 x0f) & lt; <(4 * 0));
GPIOB - & gt; The CRL |=((1) & lt; <(4 * 0));

//control the ODR register
GPIOB - & gt; The ODR & amp;=~ (1 & lt; <0);
//GPIOB - & gt; The ODR |=(1 & lt; <0);
# endif
}


Void SystemInit (void)
{
//function body is empty, the purpose is to fool the compiler is not an error
}

Results the following
* * * Using the Compiler 'V5.05 update 2 (build 169)', folder: 'D: \ stm32 \ ARM \ ARMCC \ Bin'
Rebuild the target 'Template - REG'
Assembling startup_stm32f10x_hd. S...
The compiling. The main c...
The main c (21) : error: # 65: expected a ";"
Int main (void)
The main. C (51) : warning: # 12 - D: parsing restarts here after previous syntax error

CC - & gt; APB2ENR |=((1) & lt; <3);
The main c (54) : error: # 18: expected a ") "

PIOB - & gt; The CRL & amp;=((0 x0f) & lt; <(4 * 0));
The main c (54) : error: # 79: expected a type specifiers

PIOB - & gt; The CRL & amp;=((0 x0f) & lt; <(4 * 0));
Main. C (54) : error: # 101: "GPIO_TypeDef" has already had been declared in the current scope

PIOB - & gt; The CRL & amp;=((0 x0f) & lt; <(4 * 0));
The main c (54) : error: # 141 - D: unnamed prototyped parameters not allowed when the body is the present

PIOB - & gt; The CRL & amp;=((0 x0f) & lt; <(4 * 0));
The main c (54) : error: # 130: expected a "{"

PIOB - & gt; The CRL & amp;=((0 x0f) & lt; <(4 * 0));
The main c (61) : warning: # 12 - D: parsing restarts here after previous syntax error
}
The main. C: 2 warnings, 6 errors
"./Objects/Template - REG. Axf "- 6 Error (s), 2 Warning (s).
Target not created.
The Build Time Elapsed: 00:00:01
Does anyone know where is the problem?
  • Related