📄 bsp.c
字号:
/*
*********************************************************************************************************
* MICIRUM BOARD SUPPORT PACKAGE
*
* (c) Copyright 2007-2008; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may not be used to write a similar
* product. This file may only be used in accordance with a license
* and should not be redistributed in any way.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* BOARD SUPPORT PACKAGE
*
* ST Microelectronics STM32
* with the
* STM3210E-EVAL Evaluation Board
*
* Filename : bsp.c
* Version : V1.00
* Programmer(s) : BAN
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define BSP_MODULE
#include <bsp.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/* -------------------- GPIOA PINS -------------------- */
#define BSP_GPIOA_PB_WAKEUP DEF_BIT_00
#define BSP_GPIOA_USART2_CTS DEF_BIT_00 /* USART2. */
#define BSP_GPIOA_USART2_RTS DEF_BIT_01 /* USART2. */
#define BSP_GPIOA_USART2_TX DEF_BIT_02 /* USART2. */
#define BSP_GPIOA_USART2_RX DEF_BIT_03 /* USART2. */
#define BSP_GPIOA_LCD_BL DEF_BIT_08 /* LCD. */
#define BSP_GPIOA_USART1_TX DEF_BIT_09 /* USART1. */
#define BSP_GPIOA_USART1_RX DEF_BIT_10 /* USART1. */
#define BSP_GPIOA_USB_DM DEF_BIT_11 /* USB. */
#define BSP_GPIOA_USB_DP DEF_BIT_12 /* USB. */
/* -------------------- GPIOB PINS -------------------- */
#define BSP_GPIOB_SMARTCARD_PWR_SEL DEF_BIT_00 /* Smartcard. */
#define BSP_GPIOB_SMARTCARD_IOUC DEF_BIT_10 /* Smartcard. */
#define BSP_GPIOB_SMARTCARD_RSTIN DEF_BIT_11 /* Smartcard. */
#define BSP_GPIOB_SMARTCARD_XTAL1 DEF_BIT_12 /* Smartcard. */
#define BSP_GPIOB_USB_DISCONNECT DEF_BIT_14 /* USB. */
/* -------------------- GPIOC PINS -------------------- */
#define BSP_GPIOC_ANALOG_CN5 DEF_BIT_01 /* Analog Input. */
#define BSP_GPIOC_ANALOG_CN3 DEF_BIT_02 /* Analog Input. */
#define BSP_GPIOC_ANALOG_CN2 DEF_BIT_03 /* Analog Input. */
#define BSP_GPIOC_POT DEF_BIT_04 /* Potentiometer. */
#define BSP_GPIOC_SMARTCARD_CMDVCC DEF_BIT_06 /* Smartcard. */
#define BSP_GPIOC_SMARTCARD_OFF DEF_BIT_07 /* Smartcard. */
#define BSP_GPIOC_MICROSD_D0 DEF_BIT_08 /* MicroSD. */
#define BSP_GPIOC_MICROSD_D1 DEF_BIT_09 /* MicroSD. */
#define BSP_GPIOC_MICROSD_D2 DEF_BIT_10 /* MicroSD. */
#define BSP_GPIOC_MICROSD_D3 DEF_BIT_11 /* MicroSD. */
#define BSP_GPIOC_MICROSD_CLK DEF_BIT_12 /* MicroSD. */
#define BSP_GPIOC_PB_TAMPER DEF_BIT_13
/* -------------------- GPIOD PINS -------------------- */
#define BSP_GPIOD_MICROSD_CMD DEF_BIT_02 /* MicroSD. */
#define BSP_GPIOD_JOY_DOWN DEF_BIT_03 /* Joystick. */
/* -------------------- GPIOF PINS -------------------- */
#define BSP_GPIOF_LED1 DEF_BIT_06 /* LED. */
#define BSP_GPIOF_LED2 DEF_BIT_07 /* LED. */
#define BSP_GPIOF_LED3 DEF_BIT_08 /* LED. */
#define BSP_GPIOF_LED4 DEF_BIT_09 /* LED. */
#define BSP_GPIOA_LCD_CD DEF_BIT_10 /* LCD. */
#define BSP_GPIOF_MICROSD_DETECT DEF_BIT_11 /* MicroSD. */
/* -------------------- GPIOG PINS -------------------- */
#define BSP_GPIOG_FSMC_INT2 DEF_BIT_06 /* FSMC. */
#define BSP_GPIOG_JOY_SEL DEF_BIT_07 /* Joystick. */
#define BSP_GPIOG_PB_KEY DEF_BIT_08 /* Button. */
#define BSP_GPIOG_FSMC_NE2 DEF_BIT_09 /* FSMC. */
#define BSP_GPIOG_FSMC_NE3 DEF_BIT_10 /* FSMC. */
#define BSP_GPIOG_AUDIO_PDN DEF_BIT_11 /* Audio. */
#define BSP_GPIOG_FSMC_NE4 DEF_BIT_12 /* FSMC. */
#define BSP_GPIOG_JOY_RIGHT DEF_BIT_13 /* Joystick. */
#define BSP_GPIOG_JOY_LEFT DEF_BIT_14 /* Joystick. */
#define BSP_GPIOG_JOY_UP DEF_BIT_15 /* Joystick. */
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void BSP_ADC_Init (void);
static void BSP_Joystick_Init(void);
static void BSP_LED_Init (void);
static void BSP_PB_Init (void);
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSP_Init()
*
* Description : Initialize the Board Support Package (BSP).
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : (1) This function SHOULD be called before any other BSP function is called.
*********************************************************************************************************
*/
void BSP_Init (void)
{
BSP_IntInit();
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
RCC_WaitForHSEStartUp();
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {
;
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while (RCC_GetSYSCLKSource() != 0x08) {
;
}
BSP_ADC_Init(); /* Initialize the I/Os for the ADC controls. */
BSP_LED_Init(); /* Initialize the I/Os for the LED controls. */
BSP_PB_Init(); /* Initialize the I/Os for the PB control. */
BSP_Joystick_Init(); /* Initialize the I/Os for the Joystick control. */
STM3210E_LCD_Init();
LCD_Clear(0xFFFF);
}
/*
*********************************************************************************************************
* BSP_CPU_ClkFreq()
*
* Description : Read CPU registers to determine the CPU clock frequency of the chip.
*
* Argument(s) : none.
*
* Return(s) : The CPU clock frequency, in Hz.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_INT32U BSP_CPU_ClkFreq (void)
{
RCC_ClocksTypeDef rcc_clocks;
RCC_GetClocksFreq(&rcc_clocks);
return ((CPU_INT32U)rcc_clocks.HCLK_Frequency);
}
/*
*********************************************************************************************************
*********************************************************************************************************
* OS CORTEX-M3 FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* OS_CPU_SysTickClkFreq()
*
* Description : Get system tick clock frequency.
*
* Argument(s) : none.
*
* Return(s) : Clock frequency (of system tick).
*
* Caller(s) : BSP_Init().
*
* Note(s) : none.
*********************************************************************************************************
*/
INT32U OS_CPU_SysTickClkFreq (void)
{
INT32U freq;
freq = BSP_CPU_ClkFreq();
return (freq);
}
/*
*********************************************************************************************************
*********************************************************************************************************
* ADC FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSP_ADC_Init()
*
* Description : Initialize the board's ADC
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : BSP_Init().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void BSP_ADC_Init (void)
{
ADC_InitTypeDef adc_init;
GPIO_InitTypeDef gpio_init;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
gpio_init.GPIO_Pin = GPIO_Pin_4;
gpio_init.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &gpio_init);
adc_init.ADC_Mode = ADC_Mode_Independent;
adc_init.ADC_ScanConvMode = DISABLE;
adc_init.ADC_ContinuousConvMode = ENABLE;
adc_init.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
adc_init.ADC_DataAlign = ADC_DataAlign_Right;
adc_init.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &adc_init);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_13Cycles5);
ADC_Cmd(ADC1, ENABLE);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
/*
*********************************************************************************************************
* BSP_ADC_GetStatus()
*
* Description : This function initializes the board's ADC
*
* Argument(s) : adc ID of the ADC to probe. For this board, the only legitimate value is 1.
*
* Return(s) : The numerator of the binary fraction representing the result of the latest ADC conversion.
* This value will be a 12-bit value between 0x0000 and 0x0FFF, inclusive.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_INT16U BSP_ADC_GetStatus (CPU_INT08U adc)
{
CPU_INT16U result;
result = 0;
if (adc == 1) {
result = ADC_GetConversionValue(ADC1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -