P100脱机下载器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.5 KiB

4 years ago
  1. #ifndef __SYS_H
  2. #define __SYS_H
  3. #include "stm32f4xx.h"
  4. //////////////////////////////////////////////////////////////////////////////////
  5. //������ֻ��ѧϰʹ�ã�δ���������ɣ��������������κ���;
  6. //ALIENTEK STM32F407������
  7. //ϵͳʱ�ӳ�ʼ��
  8. //����ʱ������/�жϹ���/GPIO���õ�
  9. //����ԭ��@ALIENTEK
  10. //������̳:www.openedv.com
  11. //��������:2014/5/2
  12. //�汾��V1.1
  13. //��Ȩ���У������ؾ���
  14. //Copyright(C) �������������ӿƼ����޹�˾ 2014-2024
  15. //All rights reserved
  16. //********************************************************************************
  17. //�޸�˵��
  18. //V1.1 20150411
  19. //1,�޸�WFI_SET/INTX_DISABLE/INTX_ENABLE�Ⱥ�����ʵ�ַ�ʽ
  20. //2,�޸�SYSTEM_SUPPORT_UCOSΪSYSTEM_SUPPORT_OS
  21. //////////////////////////////////////////////////////////////////////////////////
  22. //0,��֧��OS
  23. //1,֧��OS
  24. #define SYSTEM_SUPPORT_OS 0 //����ϵͳ�ļ����Ƿ�֧��OS
  25. //λ������,ʵ��51���Ƶ�GPIO���ƹ���
  26. //����ʵ��˼��,�ο�<<CM3Ȩ��ָ��>>������(87ҳ~92ҳ).M4ͬM3����,ֻ�ǼĴ�����ַ����.
  27. //IO�ڲ����궨��
  28. #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
  29. #define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
  30. #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
  31. //IO�ڵ�ַӳ��
  32. #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014
  33. #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414
  34. #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814
  35. #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14
  36. #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014
  37. #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414
  38. #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814
  39. #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14
  40. #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014
  41. #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010
  42. #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410
  43. #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810
  44. #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10
  45. #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010
  46. #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410
  47. #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810
  48. #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10
  49. #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010
  50. //IO�ڲ���,ֻ�Ե�һ��IO��!
  51. //ȷ��n��ֵС��16!
  52. #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //����
  53. #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //����
  54. #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //����
  55. #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //����
  56. #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //����
  57. #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //����
  58. #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //����
  59. #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //����
  60. #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //����
  61. #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //����
  62. #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //����
  63. #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //����
  64. #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //����
  65. #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //����
  66. #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //����
  67. #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //����
  68. #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //����
  69. #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //����
  70. //////////////////////////////////////////////////////////////////////////////////
  71. //Ex_NVIC_Configר�ö���
  72. #define GPIO_A 0
  73. #define GPIO_B 1
  74. #define GPIO_C 2
  75. #define GPIO_D 3
  76. #define GPIO_E 4
  77. #define GPIO_F 5
  78. #define GPIO_G 6
  79. #define GPIO_H 7
  80. #define GPIO_I 8
  81. #define FTIR 1 //�½��ش���
  82. #define RTIR 2 //�����ش���
  83. //GPIO����ר�ú궨��
  84. #define GPIO_MODE_IN 0 //��ͨ����ģʽ
  85. #define GPIO_MODE_OUT 1 //��ͨ����ģʽ
  86. #define GPIO_MODE_AF 2 //AF����ģʽ
  87. #define GPIO_MODE_AIN 3 //ģ������ģʽ
  88. #define GPIO_SPEED_2M 0 //GPIO�ٶ�2Mhz
  89. #define GPIO_SPEED_25M 1 //GPIO�ٶ�25Mhz
  90. #define GPIO_SPEED_50M 2 //GPIO�ٶ�50Mhz
  91. #define GPIO_SPEED_100M 3 //GPIO�ٶ�100Mhz
  92. #define GPIO_PUPD_NONE 0 //����������
  93. #define GPIO_PUPD_PU 1 //����
  94. #define GPIO_PUPD_PD 2 //����
  95. #define GPIO_PUPD_RES 3 //����
  96. #define GPIO_OTYPE_PP 0 //��������
  97. #define GPIO_OTYPE_OD 1 //��©����
  98. //GPIO���ű��Ŷ���
  99. #define PIN0 1<<0
  100. #define PIN1 1<<1
  101. #define PIN2 1<<2
  102. #define PIN3 1<<3
  103. #define PIN4 1<<4
  104. #define PIN5 1<<5
  105. #define PIN6 1<<6
  106. #define PIN7 1<<7
  107. #define PIN8 1<<8
  108. #define PIN9 1<<9
  109. #define PIN10 1<<10
  110. #define PIN11 1<<11
  111. #define PIN12 1<<12
  112. #define PIN13 1<<13
  113. #define PIN14 1<<14
  114. #define PIN15 1<<15
  115. //////////////////////////////////////////////////////////////////////////////////
  116. u8 Sys_Clock_Set(u32 plln,u32 pllm,u32 pllp,u32 pllq); //ϵͳʱ������
  117. void Stm32_Clock_Init(u32 plln,u32 pllm,u32 pllp,u32 pllq); //ʱ�ӳ�ʼ��
  118. void Sys_Soft_Reset(void); //ϵͳ����λ
  119. void Sys_Standby(void); //����ģʽ
  120. void MY_NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset); //����ƫ�Ƶ�ַ
  121. void MY_NVIC_PriorityGroupConfig(u8 NVIC_Group); //����NVIC����
  122. void MY_NVIC_Init(u8 NVIC_PreemptionPriority,u8 NVIC_SubPriority,u8 NVIC_Channel,u8 NVIC_Group);//�����ж�
  123. void Ex_NVIC_Config(u8 GPIOx,u8 BITx,u8 TRIM); //�ⲿ�ж����ú���(ֻ��GPIOA~I)
  124. void GPIO_AF_Set(GPIO_TypeDef* GPIOx,u8 BITx,u8 AFx); //GPIO���ù�������
  125. void GPIO_Set(GPIO_TypeDef* GPIOx,u32 BITx,u32 MODE,u32 OTYPE,u32 OSPEED,u32 PUPD);//GPIO���ú���
  126. //����Ϊ���ຯ��
  127. void WFI_SET(void); //ִ��WFIָ��
  128. void INTX_DISABLE(void);//�ر������ж�
  129. void INTX_ENABLE(void); //���������ж�
  130. void MSR_MSP(u32 addr); //���ö�ջ��ַ
  131. #endif