Analysis and arrangement of Zhilin STM32 program source code 01

Publisher:TranquilOasisLatest update time:2015-08-13 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Purpose

1. A few days ago, I wrote a program for keyboard scanning, character input and simple shell on the development board. The program was modified based on the previous project. The source code was organized in a mess and there were no good comments. In the past two days, I organized the code and added more detailed comments to make it more readable and extensible.

2. Take this opportunity to study the part of the program related to STM32 hardware.

 

2. Development board configuration analysis

1. PA Exit

   PA0 corresponds to button PB3, in the lower right corner of the development board.    PA1 is used for analog potentiometer, JP1 is here.  PA2 uses the PWM of the timer to generate the backlight power of the LCD. PA4-PA7 are used to operate the SD card in SPI mode. PA9, PA10 are used for serial port 0 communication. PA11, PA12 are USB differential lines. PA13, PA14, PA15 are the three pins of JTAG.

   PA3 and PA8 are not used.

2. PB port

  PB0 is used for the speaker, PB2 and JP4 are used for Boot1 selection. PB3 and PB4 are the other two pins of JTAG. PB5 controls the green indicator light on the SD card. PB6 and PB7 are used for I2C memory. PB8 and PB9 are used for CAN transceiver. PB11-PB15 are used for joystick buttons.

   PB1 and PB10 are not used

3. PC port

  PC0 to PC7 are used for LCD data ports, PB8-PB12 are used for read, write, command data selection, reset and chip select respectively. PB13 is the PB2 button, on the left of PB3. PB14-PB15 are connected to an external 32.768KHz crystal oscillator.

4. PD port

  PD0-PD1 is connected to an external 12MHz crystal oscillator, PD2 is used for USB connection and disconnection control, low level can be detected by the host, high level disconnection, JP3 can directly control the connection. In addition, there is a BOOT 0 pin, the mode is controlled by JB5. There is also a reset pin below. The 5 pins here plus the 48 above, a total of 53 pins.

5. Power port

   There are 11 pins in total, including a battery pin.

At this point, the IO configuration of the development board is basically clear.

 

3. Writing the initialization configuration program

The program uses the ucos operating system. Before calling OS_Init(), call BSP_Config() to configure the IO of the development board. The following is the source code of the program framework.

 

 

#include "stm32f10x_lib.h"

#include "bsp_config.h"

 

 

 

 

static GPIO_InitTypeDef GPIO_InitStructure;  //Data structure for GPIO port settings

static NVIC_InitTypeDef NVIC_InitStructure;

 //Data structure for interrupt settings. The previous variables are defined in the nvic header file using typedef.

 

 

void RCC_Config(void);

void NVIC_Config(void);

void SysTick_Config(void);

void GPIO_Config(void);

void TIM_Config(void);

void USART_Config(void);

 

 

void BSP_Config(void)

{

  RCC_Config();    //Clock configuration

 

 NVIC_Config();  //Interrupt vector configuration, the main work is not done here

 

 SysTick_Config(); //System clock configuration, used for usos clock

 

 GPIO_Config();   //General IO port configuration, multiplexed port separate configuration

 

 TIM_Config();    //Timer configuration

 

 UART_Config() ;  //Asynchronous serial port configuration

 

 

The following is the source code of these specific configuration functions. I will post them as I modify them.

With such a program framework, it is easier to tailor the software to different applications.

Reference address:Analysis and arrangement of Zhilin STM32 program source code 01

Previous article:Analysis and arrangement of Zhilin STM32 program source code 02
Next article:Common ARM assembly instructions

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号