?? bsp.c
字號:
/*
*********************************************************************************************************
* 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
* on the
*
* Micrium uC-Eval-STM32F107
* Evaluation Board
*
* Filename : bsp.c
* Version : V1.00
* Programmer(s) : EHS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define BSP_MODULE
#include <bsp.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
#define BSP_LED_START_BIT (13 - 1) /* LEDs[3:1] are sequentially connected to PTD[15:13]. */
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL TABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
CPU_INT32U BSP_CPU_ClkFreq_MHz;
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void BSP_LED_Init (void);
static void BSP_StatusInit (void);
/*
*********************************************************************************************************
* REGISTERS
*********************************************************************************************************
*/
#define DWT_CR *(CPU_REG32 *)0xE0001000
#define DWT_CYCCNT *(CPU_REG32 *)0xE0001004
#define DEM_CR *(CPU_REG32 *)0xE000EDFC
#define DBGMCU_CR *(CPU_REG32 *)0xE0042004
/*
*********************************************************************************************************
* REGISTER BITS
*********************************************************************************************************
*/
#define DBGMCU_CR_TRACE_IOEN_MASK 0x10
#define DBGMCU_CR_TRACE_MODE_ASYNC 0x00
#define DBGMCU_CR_TRACE_MODE_SYNC_01 0x40
#define DBGMCU_CR_TRACE_MODE_SYNC_02 0x80
#define DBGMCU_CR_TRACE_MODE_SYNC_04 0xC0
#define DBGMCU_CR_TRACE_MODE_MASK 0xC0
#define DEM_CR_TRCENA (1 << 24)
#define DWT_CR_CYCCNTENA (1 << 0)
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
#if ((CPU_CFG_TS_TMR_EN != DEF_ENABLED) && \
(APP_CFG_PROBE_OS_PLUGIN_EN == DEF_ENABLED) && \
(OS_PROBE_HOOKS_EN > 0u))
#error "CPU_CFG_TS_EN illegally #define'd in 'cpu.h'"
#error " [MUST be DEF_ENABLED] when "
#error " using uC/Probe COM modules "
#endif
/*
*********************************************************************************************************
* 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.
*
* (2) CPU instruction / data tracing requires the use of the following pins :
* (a) (1) Aysynchronous : PB[3]
* (2) Synchronous 1-bit : PE[3:2]
* (3) Synchronous 2-bit : PE[4:2]
* (4) Synchronous 4-bit : PE[6:2]
*
* (b) The uC-Eval board MAY utilize the following pins depending on the application :
* (1) PE[5], MII_INT
* (1) PE[6], SDCard_Detection
*
* (c) The application may wish to adjust the trace bus width depending on I/O
* requirements.
*********************************************************************************************************
*/
void BSP_Init (void)
{
BSP_IntInit();
SystemInit();
BSP_CPU_ClkFreq_MHz = BSP_CPU_ClkFreq() / (CPU_INT32U)1000000;
BSP_CPU_ClkFreq_MHz = BSP_CPU_ClkFreq_MHz; /* Surpress compiler warning BSP_CPU_ClkFreq_MHz ... */
/* ... set and not used. */
BSP_LED_Init(); /* Initialize the I/Os for the LED controls. */
BSP_StatusInit(); /* Initialize the status input(s) */
#ifdef TRACE_EN /* See project / compiler preprocessor options. */
DBGMCU_CR |= DBGMCU_CR_TRACE_IOEN_MASK; /* Enable tracing (see Note #2). */
DBGMCU_CR &= ~DBGMCU_CR_TRACE_MODE_MASK; /* Clr trace mode sel bits. */
DBGMCU_CR |= DBGMCU_CR_TRACE_MODE_SYNC_04; /* Cfg trace mode to synch 4-bit. */
#endif
}
/*
*********************************************************************************************************
* 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);
}
/*
*********************************************************************************************************
*********************************************************************************************************
* LED FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSP_LED_Init()
*
* Description : Initialize the I/O for the LEDs
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : BSP_Init().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void BSP_LED_Init (void)
{
GPIO_InitTypeDef gpio_init;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
gpio_init.GPIO_Pin = BSP_GPIOD_LEDS;
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
gpio_init.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &gpio_init);
}
/*
*********************************************************************************************************
* BSP_LED_On()
*
* Description : Turn ON any or all the LEDs on the board.
*
* Argument(s) : led The ID of the LED to control:
*
* 0 turns ON ALL the LEDs
* 1 turns ON user LED1 on the board
* 2 turns ON user LED2 on the board
* 3 turns ON user LED3 on the board
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_LED_On (CPU_INT08U led)
{
switch (led) {
case 0:
GPIO_SetBits(GPIOD, BSP_GPIOD_LEDS);
break;
case 1:
GPIO_SetBits(GPIOD, BSP_GPIOD_LED1);
break;
case 2:
GPIO_SetBits(GPIOD, BSP_GPIOD_LED2);
break;
case 3:
GPIO_SetBits(GPIOD, BSP_GPIOD_LED3);
break;
default:
break;
}
}
/*
*********************************************************************************************************
* BSP_LED_Off()
*
* Description : Turn OFF any or all the LEDs on the board.
*
* Argument(s) : led The ID of the LED to control:
*
* 0 turns OFF ALL the LEDs
* 1 turns OFF user LED1 on the board
* 2 turns OFF user LED2 on the board
* 3 turns OFF user LED3 on the board
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_LED_Off (CPU_INT08U led)
{
switch (led) {
case 0:
GPIO_ResetBits(GPIOD, BSP_GPIOD_LEDS);
break;
case 1:
GPIO_ResetBits(GPIOD, BSP_GPIOD_LED1);
break;
case 2:
GPIO_ResetBits(GPIOD, BSP_GPIOD_LED2);
break;
case 3:
GPIO_ResetBits(GPIOD, BSP_GPIOD_LED3);
break;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -