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

📄 bsp.c

📁 通过手动烧写flash,实现了stm32的自动更新功能,用户可以再本例程的基础上修改实现通过串口或者网络实现程序的自动更新
💻 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
*                                              with the
*                                   STM3210B-EVAL Evaluation Board
*
* Filename      : bsp.c
* Version       : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/

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

#define  BSP_GLOBALS
#include <includes.h>
#include "radio.h"


/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/
void USART_Configuration(void);
/*
*********************************************************************************************************
*                                           LOCAL CONSTANTS
*********************************************************************************************************
*/


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


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


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


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

static  void  Tmr_TickInit  (void);


void  IWDogInit(void);
/*
*********************************************************************************************************
*                                     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)
{
	//IWDogInit();


	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_2);
	RCC_PLLCmd(ENABLE);

	while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
	{
		;
	}

	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

	while (RCC_GetSYSCLKSource() != 0x08)
	{
		;
	}

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

	//射频初始化
	//RadioInit();

	//串口配置
	//USART_Configuration();

	//Backup register 配置
	/* Enable PWR and BKP clock */
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);


	//看门狗配置
//	WWDogInit();
}


/*
*********************************************************************************************************
*                                     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 and LED Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/

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


/*
******************************************************************************************************************************
******************************************************************************************************************************
**                                         uC/OS-II Timer Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/

/*
*********************************************************************************************************
*                                       TICKER INITIALIZATION
*
* Description : This function is called to initialize uC/OS-II's tick source (typically a timer generating
*               interrupts every 1 to 100 mS).
*
* Arguments   : none
*
* Note(s)     : 1) The timer is setup for output compare mode BUT 'MUST' also 'freerun' so that the timer
*                  count goes from 0x00000000 to 0xFFFFFFFF to ALSO be able to read the free running count.
*                  The reason this is needed is because we use the free-running count in uC/OS-View.
*********************************************************************************************************
*/

static  void  Tmr_TickInit (void)
{
	RCC_ClocksTypeDef  rcc_clocks;
	CPU_INT32U         cnts;


	RCC_GetClocksFreq(&rcc_clocks);

	cnts = (CPU_INT32U)rcc_clocks.HCLK_Frequency / OS_TICKS_PER_SEC;

	SysTick_SetReload(cnts);
	SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
	SysTick_CounterCmd(SysTick_Counter_Enable);
	SysTick_ITConfig(ENABLE);
}


/*
*********************************************************************************************************
*                                         TIMER IRQ HANDLER
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments   : none
*
* Note(s)     : 1) The timer is 'reloaded' with the count at compare + the time for the next interrupt.
*                  Since we are using 'unsigned' integer math, overflows are irrelevant.
*********************************************************************************************************
*/
//extern void DoMlmeTimer(void);
void  Tmr_TickISR_Handler (void)
{
	OS_CPU_SR  cpu_sr;


	OS_ENTER_CRITICAL();										/* Tell uC/OS-II that we are starting an ISR                */
	OSIntNesting++;
	OS_EXIT_CRITICAL();

	OSTimeTick();												/* Call uC/OS-II's OSTimeTick()                             */

//	DoMlmeTimer();

//	DoRangeExpire();

	OSIntExit();												/* Tell uC/OS-II that we are leaving the ISR                */
}

//独立看门狗定时器设置
void  IWDogInit(void)
{
	/* IWDG timeout equal to 280 ms (the timeout may varies due to LSI frequency
		dispersion) -------------------------------------------------------------*/
	/* Enable write access to IWDG_PR and IWDG_RLR registers */
	IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);

	/* IWDG counter clock: 40KHz(LSI) / 256 = 150 Hz */
	IWDG_SetPrescaler(IWDG_Prescaler_256);

	/* Set counter reload value to 2500 ,16秒复位*/
	IWDG_SetReload(2500);

	/* Reload IWDG counter */
	IWDG_ReloadCounter();

	/* Enable IWDG (the LSI oscillator will be enabled by hardware) */
	IWDG_Enable();


}

void WWDogInit(void)
{

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

	/* WWDG clock counter = (PCLK1/4096)/8 = 244 Hz (~4 ms)  */
	WWDG_SetPrescaler(WWDG_Prescaler_8);

	/* Set Window value to 65 */
	WWDG_SetWindowValue(65);

	/* Enable WWDG and set counter value to 127, WWDG timeout = ~4 ms * 64 = 262 ms */
	WWDG_Enable(127);

	/* Clear EWI flag */
	WWDG_ClearFlag();

	/* Enable EW interrupt */
	WWDG_EnableIT();
}

⌨️ 快捷键说明

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