⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bsp.c

📁 STM32为ST公司最新推出的基于CORTEX内核的32位MCU,基丰富的外设,全新的设计可以充分释放你的想象.此程序为UCOS-II操做系统在上面的移植.编译软境为IAR
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
*********************************************************************************************************
*                                     MICIRUM BOARD SUPPORT PACKAGE
*
*                             (c) Copyright 2007; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*               Knowledge of the source code may NOT be used to develop a similar product.
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                        BOARD SUPPORT PACKAGE
*
*                                     ST Microelectronics STM32
*                                              with the
*                                   IAR STM32-SK Evaluation Board
*
* Filename      : bsp.c
* Version       : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                             INCLUDE FILES
*********************************************************************************************************
*/

#define  BSP_GLOBALS
#include <includes.h>


/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/
                                                                /* ---------------------- GPIOA Pins ---------------------- */
#define  GPIOA_PB_WAKEUP                DEF_BIT_00
#define  GPIOA_MIC_IN                   DEF_BIT_01
#define  GPIOA_UART2_TX                 DEF_BIT_02
#define  GPIOA_UART2_RX                 DEF_BIT_03
#define  GPIOA_LED1                     DEF_BIT_04
#define  GPIOA_LED2                     DEF_BIT_05
#define  GPIOA_LED3                     DEF_BIT_06
#define  GPIOA_LED4                     DEF_BIT_07
#define  GPIOA_PWM_OUT                  DEF_BIT_08
#define  GPIOA_LED5                     DEF_BIT_09
#define  GPIOA_LED6                     DEF_BIT_10
#define  GPIOA_LEDS        (GPIOA_LED1 | GPIOA_LED2 | GPIOA_LED3 | GPIOA_LED4 | GPIOA_LED5 | GPIOA_LED6)

                                                                /* ---------------------- GPIOB Pins ---------------------- */
#define  GPIOB_LCD_LIGHT                DEF_BIT_00
#define  GPIOB_PB2                      DEF_BIT_05
#define  GPIOB_LED7                     DEF_BIT_06
#define  GPIOB_LED8                     DEF_BIT_07
#define  GPIOB_CAN_RX                   DEF_BIT_08
#define  GPIOB_CAN_TX                   DEF_BIT_09
#define  GPIOB_LED9                     DEF_BIT_10
#define  GPIOB_LED10                    DEF_BIT_11
#define  GPIOB_LED11                    DEF_BIT_12
#define  GPIOB_LED12                    DEF_BIT_13
#define  GPIOB_LED13                    DEF_BIT_14
#define  GPIOB_LED14                    DEF_BIT_15
#define  GPIOB_LEDS        (GPIOB_LED7 | GPIOB_LED8 | GPIOB_LED9 | GPIOB_LED10 | GPIOB_LED11 | GPIOB_LED12 | GPIOB_LED13 | GPIOB_LED14)

                                                                /* ---------------------- GPIOC Pins ---------------------- */
#define  GPIOC_LCD_DB4                  DEF_BIT_00
#define  GPIOC_LCD_DB5                  DEF_BIT_01
#define  GPIOC_LCD_DB6                  DEF_BIT_02
#define  GPIOC_LCD_DB7                  DEF_BIT_03
#define  GPIOC_PB3                      DEF_BIT_04
#define  GPIOC_POT                      DEF_BIT_05
#define  GPIOC_LED15                    DEF_BIT_06
#define  GPIOC_LED16                    DEF_BIT_07
#define  GPIOC_LCD_RS                   DEF_BIT_08
#define  GPIOC_LCD_RW                   DEF_BIT_09
#define  GPIOC_USART3_TX                DEF_BIT_10
#define  GPIOC_USART3_RX                DEF_BIT_11
#define  GPIOC_LCD_E                    DEF_BIT_12
#define  GPIOC_PB1                      DEF_BIT_13
#define  GPIOC_LCD_DB      (GPIOC_LCD_DB4 | GPIOC_LCD_DB5 | GPIOC_LCD_DB6 | GPIOC_LCD_DB7)
#define  GPIOC_LEDS        (GPIOC_LED15 | GPIOC_LED16)


/*
*********************************************************************************************************
*                                           LOCAL CONSTANTS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                          LOCAL DATA TYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                            LOCAL TABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                      LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

static  void  Tmr_TickInit  (void);
static  void  LED_Init      (void);
static  void  PB_Init       (void);
static  void  LCD_LightInit (void);
static  void  ADCS_Init     (void);
#ifdef DISP_MODULE_PRESENT
static  void  DispE_High    (void);
static  void  DispE_Low     (void);
static  void  DispRW_Low    (void);

static  void  DispTmr_Init  (void);
static  void  DispTmr_Dly   (CPU_INT32U dly);

#endif

/*
*********************************************************************************************************
*                                     LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/


/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                         Global Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                         BSP INITIALIZATION
*
* Description : This function should be called by your application code before you make use of any of the
*               functions found in this module.
*
* Arguments   : none
*********************************************************************************************************
*/




void  BSP_Init (void)
{
    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) {
        ;
    }

    LED_Init();                                                 /* Initialize the I/Os for the LED      controls            */
    PB_Init();                                                  /* Initialize the I/Os for the PB       controls            */
    LCD_LightInit();                                            /* Initialize the I/Os for the LCD backlight                */
    ADCS_Init();                                                /* Initialize the ADC  for the potentiometer                */

    Tmr_TickInit();                                             /* Initialize the uC/OS-II tick interrupt                   */
}


/*
*********************************************************************************************************
*                                     DISABLE ALL INTERRUPTS
*
* Description : This function disables all interrupts from the interrupt controller.
*
* Arguments   : None.
*
* Returns     : None.
*********************************************************************************************************
*/

void  BSP_IntDisAll (void)
{
    CPU_IntDis();
}


/*
*********************************************************************************************************
*                                      GET THE CPU CLOCK FREQUENCY
*
* Description: This function reads CPU registers to determine the CPU clock frequency of the chip in KHz.
*
* Argument(s): None.
*
* Returns    : The CPU clock frequency, in Hz.
*********************************************************************************************************
*/

CPU_INT32U  BSP_CPU_ClkFreq (void)
{
    static  RCC_ClocksTypeDef  rcc_clocks;


    RCC_GetClocksFreq(&rcc_clocks);

    return ((CPU_INT32U)rcc_clocks.HCLK_Frequency);
}


/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                   PB, LED, LCD Backlight, and ADC Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                         PB INITIALIZATION
*
* Description : This function initializes the board's PB
*
* Arguments   : none
*
* Returns     ; none
*********************************************************************************************************
*/

static  void  PB_Init (void)
{
    GPIO_InitTypeDef  gpio_init;


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

    gpio_init.GPIO_Pin  = GPIOA_PB_WAKEUP;
    gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &gpio_init);

    gpio_init.GPIO_Pin  = GPIOB_PB2;
    gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOB, &gpio_init);

    gpio_init.GPIO_Pin  = GPIOC_PB1 | GPIOC_PB3;
    gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOC, &gpio_init);

}


/*
*********************************************************************************************************
*                                         GET 'PUSH BUTTON' STATUS
*
* Description : This function is used to get the status of any push button on the board.
*
* Arguments   : push_button    is the number of the push button to probe
*                              1    probe the PB1    push button
*                              2    probe the PB2    push button
*                              3    probe the PB3    push button
*                              4    probe the wakeup push button
*
* Returns     : DEF_TRUE  if the push button is pressed
*               DEF_FALSE if the push button is not pressed
*********************************************************************************************************
*/

CPU_BOOLEAN  PB_GetStatus (CPU_INT08U pb)
{
    CPU_BOOLEAN  status;
    CPU_INT32U   pin;


    status = DEF_FALSE;

    switch (pb) {
        case 1:
             pin = GPIO_ReadInputDataBit(GPIOC, GPIOC_PB1);
             if (pin > 0) {
                 status = DEF_TRUE;
             }
             break;

        case 2:
             pin = GPIO_ReadInputDataBit(GPIOB, GPIOB_PB2);
             if (pin > 0) {
                 status = DEF_TRUE;
             }
             break;

        case 3:
             pin = GPIO_ReadInputDataBit(GPIOC, GPIOC_PB3);
             if (pin > 0) {
                 status = DEF_TRUE;
             }
             break;

        case 4:
             pin = GPIO_ReadInputDataBit(GPIOA, GPIOA_PB_WAKEUP);
             if (pin > 0) {
                 status = DEF_TRUE;
             }
             break;

        default:
             break;
    }

    return (status);
}


/*
*********************************************************************************************************
*                                         LED INITIALIZATION
*
* Description : This function initializes the board's LEDs
*
* Arguments   : none
*
* Returns     : none
*********************************************************************************************************
*/

static  void  LED_Init (void)
{
    GPIO_InitTypeDef  gpio_init;


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

    gpio_init.GPIO_Pin   = GPIOA_LEDS;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &gpio_init);

    gpio_init.GPIO_Pin   = GPIOB_LEDS;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOB, &gpio_init);

    gpio_init.GPIO_Pin   = GPIOC_LEDS;
    gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
    gpio_init.GPIO_Mode  = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOC, &gpio_init);
}


/*
*********************************************************************************************************
*                                             LED ON
*
* Description : This function is used to control any or all the LEDs on the board.
*
* Arguments   : led    is the number of the LED to control
*                      0    indicates that you want ALL the LEDs to be ON
*                      1    turns ON user LED1  on the board
*                      2    turns ON user LED2  on the board
*                            .
*                            .
*                            .
*                      16   turns ON user LED16 on the board
*
* Returns     : none
*********************************************************************************************************
*/

void  LED_On (CPU_INT08U led)
{
    switch (led) {
        case 0:
             GPIO_ResetBits(GPIOA, GPIOA_LEDS);
             GPIO_ResetBits(GPIOB, GPIOB_LEDS);
             GPIO_ResetBits(GPIOC, GPIOC_LEDS);
             break;

        case 1:
             GPIO_ResetBits(GPIOA, GPIOA_LED1);
             break;

        case 2:
             GPIO_ResetBits(GPIOA, GPIOA_LED2);
             break;

        case 3:
             GPIO_ResetBits(GPIOA, GPIOA_LED3);
             break;

        case 4:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -