123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- #ifndef __ST_SYS_H
- #define __ST_SYS_H
- #include <stm32f10x.h>
- #include "typedefine.h"
- #include "software_timer.h"
- #include "hardware_delay.h"
- #include "st_dma.h"
- #include "st_flash.h"
- //////////////////////////////////////////////////////////////////////////////////
- //本程序只供学习使用,未经作者许可,不得用于其它任何用途
- //ALIENTEK STM32开发板
- //系统时钟初始化(适合STM32F10x系列)
- //正点原子@ALIENTEK
- //技术论坛:www.openedv.com
- //创建日期:2010/1/1
- //版本:V1.9
- //版权所有,盗版必究。
- //Copyright(C) 广州市星翼电子科技有限公司 2009-2019
- //All rights reserved
- //********************************************************************************
- //V1.4修改说明
- //把NVIC KO了,没有使用任何库文件!
- //加入了JTAG_Set函数
- //V1.5 20120322
- //增加void INTX_DISABLE(void)和void INTX_ENABLE(void)两个函数
- //V1.6 20120412
- //1,增加MSR_MSP函数
- //2,修改VECT_TAB_RAM的默认偏移,设置为0.
- //V1.7 20120818
- //1,添加ucos支持配置宏SYSTEM_SUPPORT_UCOS
- //2,修改了注释
- //3,去掉了不常用函数BKP_Write
- //V1.8 20131120
- //1,修改头文件为stm32f10x.h,不再使用stm32f10x_lib.h及其相关头文件
- //V1.9 20150109
- //1,修改头文件为MY_NVIC_Init函数部分代码以支持向量号大于63的中断的设置
- //2,修改WFI_SET/INTX_DISABLE/INTX_ENABLE等函数的实现方式
- //V2.0 20150322
- //修改SYSTEM_SUPPORT_UCOS为SYSTEM_SUPPORT_OS
- //////////////////////////////////////////////////////////////////////////////////
- //0,不支持OS
- //1,支持OS
- #define SYSTEM_SUPPORT_OS 0 //定义系统文件夹是否支持OS
-
-
- //位带操作,实现51类似的GPIO控制功能
- //具体实现思想,参考<<CM3权威指南>>第五章(87页~92页).
- //IO口操作宏定义
- #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
- #define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
- #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
- //IO口地址映射
- #define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C
- #define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C
- #define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C
- #define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C
- #define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C
- #define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C
- #define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C
- #define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808
- #define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08
- #define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008
- #define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408
- #define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808
- #define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08
- #define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08
-
- //IO口操作,只对单一的IO口!
- //确保n的值小于16!
- #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出
- #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入
- #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出
- #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入
- #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出
- #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入
- #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出
- #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入
- #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出
- #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入
- #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出
- #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入
- #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出
- #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入
- /////////////////////////////////////////////////////////////////
- //Ex_NVIC_Config专用定义
- #define GPIO_A 0
- #define GPIO_B 1
- #define GPIO_C 2
- #define GPIO_D 3
- #define GPIO_E 4
- #define GPIO_F 5
- #define GPIO_G 6
- #define FTIR 1 //下降沿触发
- #define RTIR 2 //上升沿触发
-
- //JTAG模式设置定义
- #define JTAG_SWD_DISABLE 0X02
- #define SWD_ENABLE 0X01
- #define JTAG_SWD_ENABLE 0X00
- //GPIO设置专用宏定义
- /*
- #define GPIO_MODE_IN 0 //普通输入模式
- #define GPIO_MODE_OUT 1 //普通输出模式
- #define GPIO_MODE_AF 2 //AF功能模式
- #define GPIO_MODE_AIN 3 //模拟输入模式
- */
- #define GPIO_SPEED_2M 2 //GPIO速度2Mhz
- #define GPIO_SPEED_10M 1 //GPIO速度25Mhz
- #define GPIO_SPEED_50M 3 //GPIO速度50Mhz
- //#define GPIO_SPEED_100M 3 //GPIO速度100Mhz
- #define GPIO_PUPD_NONE 0 //不带上下拉
- #define GPIO_PUPD_PU 1 //上拉
- #define GPIO_PUPD_PD 2 //下拉
- #define GPIO_PUPD_RES 3 //保留
- #define GPIO_OTYPE_PP 0 //推挽输出
- #define GPIO_OTYPE_OD 1 //开漏输出
- #define GPIO_MODE_AIN 0
- #define GPIO_MODE_IN_FLOATING 0x04
- #define GPIO_MODE_IPD 0x28
- #define GPIO_MODE_IPU 0x48
- #define GPIO_MODE_OUT_OD 0x14
- #define GPIO_MODE_OUT_PP 0x10
- #define GPIO_MODE_AF_OD 0x1C
- #define GPIO_MODE_AF_PP 0x18
- //GPIO引脚编号定义
- #define PIN0 1<<0
- #define PIN1 1<<1
- #define PIN2 1<<2
- #define PIN3 1<<3
- #define PIN4 1<<4
- #define PIN5 1<<5
- #define PIN6 1<<6
- #define PIN7 1<<7
- #define PIN8 1<<8
- #define PIN9 1<<9
- #define PIN10 1<<10
- #define PIN11 1<<11
- #define PIN12 1<<12
- #define PIN13 1<<13
- #define PIN14 1<<14
- #define PIN15 1<<15
- #define SW_WAIT_FINISH(x) do{}while(x)
- //对管脚重新分配
- #define GPIO_Remap_SPI1 ((uint32_t)0x00000001) /*!< SPI1 Alternate Function mapping */
- #define GPIO_Remap_I2C1 ((uint32_t)0x00000002) /*!< I2C1 Alternate Function mapping */
- #define GPIO_Remap_USART1 ((uint32_t)0x00000004) /*!< USART1 Alternate Function mapping */
- #define GPIO_Remap_USART2 ((uint32_t)0x00000008) /*!< USART2 Alternate Function mapping */
- #define GPIO_PartialRemap_USART3 ((uint32_t)0x00140010) /*!< USART3 Partial Alternate Function mapping */
- #define GPIO_FullRemap_USART3 ((uint32_t)0x00140030) /*!< USART3 Full Alternate Function mapping */
- #define GPIO_PartialRemap_TIM1 ((uint32_t)0x00160040) /*!< TIM1 Partial Alternate Function mapping */
- #define GPIO_FullRemap_TIM1 ((uint32_t)0x001600C0) /*!< TIM1 Full Alternate Function mapping */
- #define GPIO_PartialRemap1_TIM2 ((uint32_t)0x00180100) /*!< TIM2 Partial1 Alternate Function mapping */
- #define GPIO_PartialRemap2_TIM2 ((uint32_t)0x00180200) /*!< TIM2 Partial2 Alternate Function mapping */
- #define GPIO_FullRemap_TIM2 ((uint32_t)0x00180300) /*!< TIM2 Full Alternate Function mapping */
- #define GPIO_PartialRemap_TIM3 ((uint32_t)0x001A0800) /*!< TIM3 Partial Alternate Function mapping */
- #define GPIO_FullRemap_TIM3 ((uint32_t)0x001A0C00) /*!< TIM3 Full Alternate Function mapping */
- #define GPIO_Remap_TIM4 ((uint32_t)0x00001000) /*!< TIM4 Alternate Function mapping */
- #define GPIO_Remap1_CAN1 ((uint32_t)0x001D4000) /*!< CAN1 Alternate Function mapping */
- #define GPIO_Remap2_CAN1 ((uint32_t)0x001D6000) /*!< CAN1 Alternate Function mapping */
- #define GPIO_Remap_PD01 ((uint32_t)0x00008000) /*!< PD01 Alternate Function mapping */
- #define GPIO_Remap_TIM5CH4_LSI ((uint32_t)0x00200001) /*!< LSI connected to TIM5 Channel4 input capture for calibration */
- #define GPIO_Remap_ADC1_ETRGINJ ((uint32_t)0x00200002) /*!< ADC1 External Trigger Injected Conversion remapping */
- #define GPIO_Remap_ADC1_ETRGREG ((uint32_t)0x00200004) /*!< ADC1 External Trigger Regular Conversion remapping */
- #define GPIO_Remap_ADC2_ETRGINJ ((uint32_t)0x00200008) /*!< ADC2 External Trigger Injected Conversion remapping */
- #define GPIO_Remap_ADC2_ETRGREG ((uint32_t)0x00200010) /*!< ADC2 External Trigger Regular Conversion remapping */
- #define GPIO_Remap_ETH ((uint32_t)0x00200020) /*!< Ethernet remapping (only for Connectivity line devices) */
- #define GPIO_Remap_CAN2 ((uint32_t)0x00200040) /*!< CAN2 remapping (only for Connectivity line devices) */
- #define GPIO_Remap_SWJ_NoJTRST ((uint32_t)0x00300100) /*!< Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST */
- #define GPIO_Remap_SWJ_JTAGDisable ((uint32_t)0x00300200) /*!< JTAG-DP Disabled and SW-DP Enabled */
- #define GPIO_Remap_SWJ_Disable ((uint32_t)0x00300400) /*!< Full SWJ Disabled (JTAG-DP + SW-DP) */
- #define GPIO_Remap_SPI3 ((uint32_t)0x00201100) /*!< SPI3/I2S3 Alternate Function mapping (only for Connectivity line devices) */
- #define GPIO_Remap_TIM2ITR1_PTP_SOF ((uint32_t)0x00202000) /*!< Ethernet PTP output or USB OTG SOF (Start of Frame) connected
- to TIM2 Internal Trigger 1 for calibration
- (only for Connectivity line devices) */
- #define GPIO_Remap_PTP_PPS ((uint32_t)0x00204000) /*!< Ethernet MAC PPS_PTS output on PB05 (only for Connectivity line devices) */
- #define GPIO_Remap_TIM15 ((uint32_t)0x80000001) /*!< TIM15 Alternate Function mapping (only for Value line devices) */
- #define GPIO_Remap_TIM16 ((uint32_t)0x80000002) /*!< TIM16 Alternate Function mapping (only for Value line devices) */
- #define GPIO_Remap_TIM17 ((uint32_t)0x80000004) /*!< TIM17 Alternate Function mapping (only for Value line devices) */
- #define GPIO_Remap_CEC ((uint32_t)0x80000008) /*!< CEC Alternate Function mapping (only for Value line devices) */
- #define GPIO_Remap_TIM1_DMA ((uint32_t)0x80000010) /*!< TIM1 DMA requests mapping (only for Value line devices) */
- #define GPIO_Remap_TIM9 ((uint32_t)0x80000020) /*!< TIM9 Alternate Function mapping (only for XL-density devices) */
- #define GPIO_Remap_TIM10 ((uint32_t)0x80000040) /*!< TIM10 Alternate Function mapping (only for XL-density devices) */
- #define GPIO_Remap_TIM11 ((uint32_t)0x80000080) /*!< TIM11 Alternate Function mapping (only for XL-density devices) */
- #define GPIO_Remap_TIM13 ((uint32_t)0x80000100) /*!< TIM13 Alternate Function mapping (only for High density Value line and XL-density devices) */
- #define GPIO_Remap_TIM14 ((uint32_t)0x80000200) /*!< TIM14 Alternate Function mapping (only for High density Value line and XL-density devices) */
- #define GPIO_Remap_FSMC_NADV ((uint32_t)0x80000400) /*!< FSMC_NADV Alternate Function mapping (only for High density Value line and XL-density devices) */
- #define GPIO_Remap_TIM67_DAC_DMA ((uint32_t)0x80000800) /*!< TIM6/TIM7 and DAC DMA requests remapping (only for High density Value line devices) */
- #define GPIO_Remap_TIM12 ((uint32_t)0x80001000) /*!< TIM12 Alternate Function mapping (only for High density Value line devices) */
- #define GPIO_Remap_MISC ((uint32_t)0x80002000) /*!< Miscellaneous Remap (DMA2 Channel5 Position and DAC Trigger remapping, */
- //////////////////////////////////////////////////////////////////////////////////
- void Stm32_Clock_Init(u8 PLL); //时钟初始化
- /////////////////////////////////////////////////////////////////
- void Sys_Clock_Set(u8 PLL); //时钟初始化
- void Sys_Soft_Reset(void); //系统软复位
- void Sys_Standby(void); //待机模式
- void Sys_NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset);//设置偏移地址
- void Sys_NVIC_PriorityGroupConfig(u8 NVIC_Group);//设置NVIC分组
- void Sys_NVIC_Init(u8 NVIC_PreemptionPriority,u8 NVIC_SubPriority,u8 NVIC_Channel,u8 NVIC_Group);//设置中断
- void Ex_NVIC_Config(u8 GPIOx,u8 BITx,u8 TRIM);//外部中断配置函数(只对GPIOA~G)
- void JTAG_Set(u8 mode);
- void GPIO_Remap_Set(uint32_t remap, u8 newstate); //GPIO复用功能设置
- void GPIO_Set(GPIO_TypeDef* GPIOx,u32 BITx,u32 MODE,u32 OSPEED,u32 PUPD);//GPIO设置函数
- //////////////////////////////////////////////////////////////////////////////
- //以下为汇编函数
- void WFI_SET(void); //执行WFI指令
- void INTX_DISABLE(void);//关闭所有中断
- void INTX_ENABLE(void); //开启所有中断
- void MSR_MSP(u32 addr); //设置堆栈地址
- #endif
|