这里使用到的是**stm32f4**的板子

stm32f407vet6详情

在一个空项目中编辑一个MakeFile文件

  1. ########
  2. #target 项目名称
  3. ########
  4. TARGET = one
  5. ########
  6. # building build配置
  7. ########
  8. # debug build?
  9. DEBUG = 1
  10. # optimization
  11. OPT = -Og
  12. #######################################
  13. # paths 路径配置
  14. #######################################
  15. # Build path
  16. BUILD_DIR = build
  17. ######################################
  18. # source 主文件的配置文件信息,需要配置的往这添加
  19. ######################################
  20. # C sources
  21. C_SOURCES = \
  22. Core/Src/main.c \
  23. # ASM sources 不清楚,反正stm32的一系列配置信息
  24. ASM_SOURCES = \
  25. startup_stm32f407xx.s
  26. #######################################
  27. # binaries
  28. #######################################
  29. PREFIX = arm-none-eabi-
  30. # The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
  31. # either it can be added to the PATH environment variable.
  32. ifdef GCC_PATH
  33. CC = $(GCC_PATH)/$(PREFIX)gcc
  34. AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
  35. CP = $(GCC_PATH)/$(PREFIX)objcopy
  36. SZ = $(GCC_PATH)/$(PREFIX)size
  37. else
  38. CC = $(PREFIX)gcc
  39. AS = $(PREFIX)gcc -x assembler-with-cpp
  40. CP = $(PREFIX)objcopy
  41. SZ = $(PREFIX)size
  42. endif
  43. HEX = $(CP) -O ihex
  44. BIN = $(CP) -O binary -S
  45. #######################################
  46. # CFLAGS
  47. #######################################
  48. # cpu
  49. CPU = -mcpu=cortex-m4
  50. # fpu
  51. FPU = -mfpu=fpv4-sp-d16
  52. # float-abi
  53. FLOAT-ABI = -mfloat-abi=hard
  54. # mcu
  55. MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI)
  56. # macros for gcc
  57. # AS defines
  58. AS_DEFS =
  59. # C defines C的定义信息Shift+Ctrl+p进行配置
  60. C_DEFS = \
  61. -DUSE_HAL_DRIVER \
  62. -DSTM32F407xx
  63. # AS includes
  64. AS_INCLUDES =
  65. # C includes
  66. C_INCLUDES = \
  67. -ICore/Inc \
  68. -IDrivers/STM32F4xx_HAL_Driver/Inc \
  69. -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \
  70. -IDrivers/CMSIS/Device/ST/STM32F4xx/Include \
  71. -IDrivers/CMSIS/Include
  72. # compile gcc flags
  73. ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  74. CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
  75. ifeq ($(DEBUG), 1)
  76. CFLAGS += -g -gdwarf-2
  77. endif
  78. # Generate dependency information
  79. CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
  80. #######################################
  81. # LDFLAGS
  82. #######################################
  83. # link script
  84. LDSCRIPT = STM32F407VETx_FLASH.ld
  85. # libraries
  86. LIBS = -lc -lm -lnosys
  87. LIBDIR =
  88. LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
  89. # default action: build all
  90. all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
  91. #######################################
  92. # build the application
  93. #######################################
  94. # list of objects
  95. OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
  96. vpath %.c $(sort $(dir $(C_SOURCES)))
  97. # list of ASM program objects
  98. OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
  99. vpath %.s $(sort $(dir $(ASM_SOURCES)))
  100. $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
  101. $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
  102. $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
  103. $(AS) -c $(CFLAGS) $< -o $@
  104. $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
  105. $(CC) $(OBJECTS) $(LDFLAGS) -o $@
  106. $(SZ) $@
  107. $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  108. $(HEX) $< $@
  109. $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
  110. $(BIN) $< $@
  111. $(BUILD_DIR):
  112. mkdir $@
  113. #######################################
  114. # clean up
  115. #######################################
  116. clean:
  117. -rm -fR $(BUILD_DIR)
  118. #######################################
  119. # dependencies
  120. #######################################
  121. -include $(wildcard $(BUILD_DIR)/*.d)
  122. # *** EOF ***
  1. /**
  2. ******************************************************************************
  3. * @file startup_stm32f407xx.s
  4. * @author MCD Application Team
  5. * @brief STM32F407xx Devices vector table for GCC based toolchains.
  6. * This module performs:
  7. * - Set the initial SP
  8. * - Set the initial PC == Reset_Handler,
  9. * - Set the vector table entries with the exceptions ISR address
  10. * - Branches to main in the C library (which eventually
  11. * calls main()).
  12. * After Reset the Cortex-M4 processor is in Thread mode,
  13. * priority is Privileged, and the Stack is set to Main.
  14. ******************************************************************************
  15. * @attention
  16. *
  17. * Copyright (c) 2017 STMicroelectronics.
  18. * All rights reserved.
  19. *
  20. * This software is licensed under terms that can be found in the LICENSE file
  21. * in the root directory of this software component.
  22. * If no LICENSE file comes with this software, it is provided AS-IS.
  23. *
  24. ******************************************************************************
  25. */
  26. .syntax unified
  27. .cpu cortex-m4
  28. .fpu softvfp
  29. .thumb
  30. .global g_pfnVectors
  31. .global Default_Handler
  32. /* start address for the initialization values of the .data section.
  33. defined in linker script */
  34. .word _sidata
  35. /* start address for the .data section. defined in linker script */
  36. .word _sdata
  37. /* end address for the .data section. defined in linker script */
  38. .word _edata
  39. /* start address for the .bss section. defined in linker script */
  40. .word _sbss
  41. /* end address for the .bss section. defined in linker script */
  42. .word _ebss
  43. /* stack used for SystemInit_ExtMemCtl; always internal RAM used */
  44. /**
  45. * @brief This is the code that gets called when the processor first
  46. * starts execution following a reset event. Only the absolutely
  47. * necessary set is performed, after which the application
  48. * supplied main() routine is called.
  49. * @param None
  50. * @retval : None
  51. */
  52. .section .text.Reset_Handler
  53. .weak Reset_Handler
  54. .type Reset_Handler, %function
  55. Reset_Handler:
  56. ldr sp, =_estack /* set stack pointer */
  57. /* Copy the data segment initializers from flash to SRAM */
  58. ldr r0, =_sdata
  59. ldr r1, =_edata
  60. ldr r2, =_sidata
  61. movs r3, #0
  62. b LoopCopyDataInit
  63. CopyDataInit:
  64. ldr r4, [r2, r3]
  65. str r4, [r0, r3]
  66. adds r3, r3, #4
  67. LoopCopyDataInit:
  68. adds r4, r0, r3
  69. cmp r4, r1
  70. bcc CopyDataInit
  71. /* Zero fill the bss segment. */
  72. ldr r2, =_sbss
  73. ldr r4, =_ebss
  74. movs r3, #0
  75. b LoopFillZerobss
  76. FillZerobss:
  77. str r3, [r2]
  78. adds r2, r2, #4
  79. LoopFillZerobss:
  80. cmp r2, r4
  81. bcc FillZerobss
  82. /* Call the clock system initialization function.*/
  83. bl SystemInit
  84. /* Call static constructors */
  85. bl __libc_init_array
  86. /* Call the application's entry point.*/
  87. bl main
  88. bx lr
  89. .size Reset_Handler, .-Reset_Handler
  90. /**
  91. * @brief This is the code that gets called when the processor receives an
  92. * unexpected interrupt. This simply enters an infinite loop, preserving
  93. * the system state for examination by a debugger.
  94. * @param None
  95. * @retval None
  96. */
  97. .section .text.Default_Handler,"ax",%progbits
  98. Default_Handler:
  99. Infinite_Loop:
  100. b Infinite_Loop
  101. .size Default_Handler, .-Default_Handler
  102. /******************************************************************************
  103. *
  104. * The minimal vector table for a Cortex M3. Note that the proper constructs
  105. * must be placed on this to ensure that it ends up at physical address
  106. * 0x0000.0000.
  107. *
  108. *******************************************************************************/
  109. .section .isr_vector,"a",%progbits
  110. .type g_pfnVectors, %object
  111. .size g_pfnVectors, .-g_pfnVectors
  112. g_pfnVectors:
  113. .word _estack
  114. .word Reset_Handler
  115. .word NMI_Handler
  116. .word HardFault_Handler
  117. .word MemManage_Handler
  118. .word BusFault_Handler
  119. .word UsageFault_Handler
  120. .word 0
  121. .word 0
  122. .word 0
  123. .word 0
  124. .word SVC_Handler
  125. .word DebugMon_Handler
  126. .word 0
  127. .word PendSV_Handler
  128. .word SysTick_Handler
  129. /* External Interrupts */
  130. .word WWDG_IRQHandler /* Window WatchDog */
  131. .word PVD_IRQHandler /* PVD through EXTI Line detection */
  132. .word TAMP_STAMP_IRQHandler /* Tamper and TimeStamps through the EXTI line */
  133. .word RTC_WKUP_IRQHandler /* RTC Wakeup through the EXTI line */
  134. .word FLASH_IRQHandler /* FLASH */
  135. .word RCC_IRQHandler /* RCC */
  136. .word EXTI0_IRQHandler /* EXTI Line0 */
  137. .word EXTI1_IRQHandler /* EXTI Line1 */
  138. .word EXTI2_IRQHandler /* EXTI Line2 */
  139. .word EXTI3_IRQHandler /* EXTI Line3 */
  140. .word EXTI4_IRQHandler /* EXTI Line4 */
  141. .word DMA1_Stream0_IRQHandler /* DMA1 Stream 0 */
  142. .word DMA1_Stream1_IRQHandler /* DMA1 Stream 1 */
  143. .word DMA1_Stream2_IRQHandler /* DMA1 Stream 2 */
  144. .word DMA1_Stream3_IRQHandler /* DMA1 Stream 3 */
  145. .word DMA1_Stream4_IRQHandler /* DMA1 Stream 4 */
  146. .word DMA1_Stream5_IRQHandler /* DMA1 Stream 5 */
  147. .word DMA1_Stream6_IRQHandler /* DMA1 Stream 6 */
  148. .word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */
  149. .word CAN1_TX_IRQHandler /* CAN1 TX */
  150. .word CAN1_RX0_IRQHandler /* CAN1 RX0 */
  151. .word CAN1_RX1_IRQHandler /* CAN1 RX1 */
  152. .word CAN1_SCE_IRQHandler /* CAN1 SCE */
  153. .word EXTI9_5_IRQHandler /* External Line[9:5]s */
  154. .word TIM1_BRK_TIM9_IRQHandler /* TIM1 Break and TIM9 */
  155. .word TIM1_UP_TIM10_IRQHandler /* TIM1 Update and TIM10 */
  156. .word TIM1_TRG_COM_TIM11_IRQHandler /* TIM1 Trigger and Commutation and TIM11 */
  157. .word TIM1_CC_IRQHandler /* TIM1 Capture Compare */
  158. .word TIM2_IRQHandler /* TIM2 */
  159. .word TIM3_IRQHandler /* TIM3 */
  160. .word TIM4_IRQHandler /* TIM4 */
  161. .word I2C1_EV_IRQHandler /* I2C1 Event */
  162. .word I2C1_ER_IRQHandler /* I2C1 Error */
  163. .word I2C2_EV_IRQHandler /* I2C2 Event */
  164. .word I2C2_ER_IRQHandler /* I2C2 Error */
  165. .word SPI1_IRQHandler /* SPI1 */
  166. .word SPI2_IRQHandler /* SPI2 */
  167. .word USART1_IRQHandler /* USART1 */
  168. .word USART2_IRQHandler /* USART2 */
  169. .word USART3_IRQHandler /* USART3 */
  170. .word EXTI15_10_IRQHandler /* External Line[15:10]s */
  171. .word RTC_Alarm_IRQHandler /* RTC Alarm (A and B) through EXTI Line */
  172. .word OTG_FS_WKUP_IRQHandler /* USB OTG FS Wakeup through EXTI line */
  173. .word TIM8_BRK_TIM12_IRQHandler /* TIM8 Break and TIM12 */
  174. .word TIM8_UP_TIM13_IRQHandler /* TIM8 Update and TIM13 */
  175. .word TIM8_TRG_COM_TIM14_IRQHandler /* TIM8 Trigger and Commutation and TIM14 */
  176. .word TIM8_CC_IRQHandler /* TIM8 Capture Compare */
  177. .word DMA1_Stream7_IRQHandler /* DMA1 Stream7 */
  178. .word FSMC_IRQHandler /* FSMC */
  179. .word SDIO_IRQHandler /* SDIO */
  180. .word TIM5_IRQHandler /* TIM5 */
  181. .word SPI3_IRQHandler /* SPI3 */
  182. .word UART4_IRQHandler /* UART4 */
  183. .word UART5_IRQHandler /* UART5 */
  184. .word TIM6_DAC_IRQHandler /* TIM6 and DAC1&2 underrun errors */
  185. .word TIM7_IRQHandler /* TIM7 */
  186. .word DMA2_Stream0_IRQHandler /* DMA2 Stream 0 */
  187. .word DMA2_Stream1_IRQHandler /* DMA2 Stream 1 */
  188. .word DMA2_Stream2_IRQHandler /* DMA2 Stream 2 */
  189. .word DMA2_Stream3_IRQHandler /* DMA2 Stream 3 */
  190. .word DMA2_Stream4_IRQHandler /* DMA2 Stream 4 */
  191. .word ETH_IRQHandler /* Ethernet */
  192. .word ETH_WKUP_IRQHandler /* Ethernet Wakeup through EXTI line */
  193. .word CAN2_TX_IRQHandler /* CAN2 TX */
  194. .word CAN2_RX0_IRQHandler /* CAN2 RX0 */
  195. .word CAN2_RX1_IRQHandler /* CAN2 RX1 */
  196. .word CAN2_SCE_IRQHandler /* CAN2 SCE */
  197. .word OTG_FS_IRQHandler /* USB OTG FS */
  198. .word DMA2_Stream5_IRQHandler /* DMA2 Stream 5 */
  199. .word DMA2_Stream6_IRQHandler /* DMA2 Stream 6 */
  200. .word DMA2_Stream7_IRQHandler /* DMA2 Stream 7 */
  201. .word USART6_IRQHandler /* USART6 */
  202. .word I2C3_EV_IRQHandler /* I2C3 event */
  203. .word I2C3_ER_IRQHandler /* I2C3 error */
  204. .word OTG_HS_EP1_OUT_IRQHandler /* USB OTG HS End Point 1 Out */
  205. .word OTG_HS_EP1_IN_IRQHandler /* USB OTG HS End Point 1 In */
  206. .word OTG_HS_WKUP_IRQHandler /* USB OTG HS Wakeup through EXTI */
  207. .word OTG_HS_IRQHandler /* USB OTG HS */
  208. .word DCMI_IRQHandler /* DCMI */
  209. .word 0 /* CRYP crypto */
  210. .word HASH_RNG_IRQHandler /* Hash and Rng */
  211. .word FPU_IRQHandler /* FPU */
  212. /*******************************************************************************
  213. *
  214. * Provide weak aliases for each Exception handler to the Default_Handler.
  215. * As they are weak aliases, any function with the same name will override
  216. * this definition.
  217. *
  218. *******************************************************************************/
  219. .weak NMI_Handler
  220. .thumb_set NMI_Handler,Default_Handler
  221. .weak HardFault_Handler
  222. .thumb_set HardFault_Handler,Default_Handler
  223. .weak MemManage_Handler
  224. .thumb_set MemManage_Handler,Default_Handler
  225. .weak BusFault_Handler
  226. .thumb_set BusFault_Handler,Default_Handler
  227. .weak UsageFault_Handler
  228. .thumb_set UsageFault_Handler,Default_Handler
  229. .weak SVC_Handler
  230. .thumb_set SVC_Handler,Default_Handler
  231. .weak DebugMon_Handler
  232. .thumb_set DebugMon_Handler,Default_Handler
  233. .weak PendSV_Handler
  234. .thumb_set PendSV_Handler,Default_Handler
  235. .weak SysTick_Handler
  236. .thumb_set SysTick_Handler,Default_Handler
  237. .weak WWDG_IRQHandler
  238. .thumb_set WWDG_IRQHandler,Default_Handler
  239. .weak PVD_IRQHandler
  240. .thumb_set PVD_IRQHandler,Default_Handler
  241. .weak TAMP_STAMP_IRQHandler
  242. .thumb_set TAMP_STAMP_IRQHandler,Default_Handler
  243. .weak RTC_WKUP_IRQHandler
  244. .thumb_set RTC_WKUP_IRQHandler,Default_Handler
  245. .weak FLASH_IRQHandler
  246. .thumb_set FLASH_IRQHandler,Default_Handler
  247. .weak RCC_IRQHandler
  248. .thumb_set RCC_IRQHandler,Default_Handler
  249. .weak EXTI0_IRQHandler
  250. .thumb_set EXTI0_IRQHandler,Default_Handler
  251. .weak EXTI1_IRQHandler
  252. .thumb_set EXTI1_IRQHandler,Default_Handler
  253. .weak EXTI2_IRQHandler
  254. .thumb_set EXTI2_IRQHandler,Default_Handler
  255. .weak EXTI3_IRQHandler
  256. .thumb_set EXTI3_IRQHandler,Default_Handler
  257. .weak EXTI4_IRQHandler
  258. .thumb_set EXTI4_IRQHandler,Default_Handler
  259. .weak DMA1_Stream0_IRQHandler
  260. .thumb_set DMA1_Stream0_IRQHandler,Default_Handler
  261. .weak DMA1_Stream1_IRQHandler
  262. .thumb_set DMA1_Stream1_IRQHandler,Default_Handler
  263. .weak DMA1_Stream2_IRQHandler
  264. .thumb_set DMA1_Stream2_IRQHandler,Default_Handler
  265. .weak DMA1_Stream3_IRQHandler
  266. .thumb_set DMA1_Stream3_IRQHandler,Default_Handler
  267. .weak DMA1_Stream4_IRQHandler
  268. .thumb_set DMA1_Stream4_IRQHandler,Default_Handler
  269. .weak DMA1_Stream5_IRQHandler
  270. .thumb_set DMA1_Stream5_IRQHandler,Default_Handler
  271. .weak DMA1_Stream6_IRQHandler
  272. .thumb_set DMA1_Stream6_IRQHandler,Default_Handler
  273. .weak ADC_IRQHandler
  274. .thumb_set ADC_IRQHandler,Default_Handler
  275. .weak CAN1_TX_IRQHandler
  276. .thumb_set CAN1_TX_IRQHandler,Default_Handler
  277. .weak CAN1_RX0_IRQHandler
  278. .thumb_set CAN1_RX0_IRQHandler,Default_Handler
  279. .weak CAN1_RX1_IRQHandler
  280. .thumb_set CAN1_RX1_IRQHandler,Default_Handler
  281. .weak CAN1_SCE_IRQHandler
  282. .thumb_set CAN1_SCE_IRQHandler,Default_Handler
  283. .weak EXTI9_5_IRQHandler
  284. .thumb_set EXTI9_5_IRQHandler,Default_Handler
  285. .weak TIM1_BRK_TIM9_IRQHandler
  286. .thumb_set TIM1_BRK_TIM9_IRQHandler,Default_Handler
  287. .weak TIM1_UP_TIM10_IRQHandler
  288. .thumb_set TIM1_UP_TIM10_IRQHandler,Default_Handler
  289. .weak TIM1_TRG_COM_TIM11_IRQHandler
  290. .thumb_set TIM1_TRG_COM_TIM11_IRQHandler,Default_Handler
  291. .weak TIM1_CC_IRQHandler
  292. .thumb_set TIM1_CC_IRQHandler,Default_Handler
  293. .weak TIM2_IRQHandler
  294. .thumb_set TIM2_IRQHandler,Default_Handler
  295. .weak TIM3_IRQHandler
  296. .thumb_set TIM3_IRQHandler,Default_Handler
  297. .weak TIM4_IRQHandler
  298. .thumb_set TIM4_IRQHandler,Default_Handler
  299. .weak I2C1_EV_IRQHandler
  300. .thumb_set I2C1_EV_IRQHandler,Default_Handler
  301. .weak I2C1_ER_IRQHandler
  302. .thumb_set I2C1_ER_IRQHandler,Default_Handler
  303. .weak I2C2_EV_IRQHandler
  304. .thumb_set I2C2_EV_IRQHandler,Default_Handler
  305. .weak I2C2_ER_IRQHandler
  306. .thumb_set I2C2_ER_IRQHandler,Default_Handler
  307. .weak SPI1_IRQHandler
  308. .thumb_set SPI1_IRQHandler,Default_Handler
  309. .weak SPI2_IRQHandler
  310. .thumb_set SPI2_IRQHandler,Default_Handler
  311. .weak USART1_IRQHandler
  312. .thumb_set USART1_IRQHandler,Default_Handler
  313. .weak USART2_IRQHandler
  314. .thumb_set USART2_IRQHandler,Default_Handler
  315. .weak USART3_IRQHandler
  316. .thumb_set USART3_IRQHandler,Default_Handler
  317. .weak EXTI15_10_IRQHandler
  318. .thumb_set EXTI15_10_IRQHandler,Default_Handler
  319. .weak RTC_Alarm_IRQHandler
  320. .thumb_set RTC_Alarm_IRQHandler,Default_Handler
  321. .weak OTG_FS_WKUP_IRQHandler
  322. .thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler
  323. .weak TIM8_BRK_TIM12_IRQHandler
  324. .thumb_set TIM8_BRK_TIM12_IRQHandler,Default_Handler
  325. .weak TIM8_UP_TIM13_IRQHandler
  326. .thumb_set TIM8_UP_TIM13_IRQHandler,Default_Handler
  327. .weak TIM8_TRG_COM_TIM14_IRQHandler
  328. .thumb_set TIM8_TRG_COM_TIM14_IRQHandler,Default_Handler
  329. .weak TIM8_CC_IRQHandler
  330. .thumb_set TIM8_CC_IRQHandler,Default_Handler
  331. .weak DMA1_Stream7_IRQHandler
  332. .thumb_set DMA1_Stream7_IRQHandler,Default_Handler
  333. .weak FSMC_IRQHandler
  334. .thumb_set FSMC_IRQHandler,Default_Handler
  335. .weak SDIO_IRQHandler
  336. .thumb_set SDIO_IRQHandler,Default_Handler
  337. .weak TIM5_IRQHandler
  338. .thumb_set TIM5_IRQHandler,Default_Handler
  339. .weak SPI3_IRQHandler
  340. .thumb_set SPI3_IRQHandler,Default_Handler
  341. .weak UART4_IRQHandler
  342. .thumb_set UART4_IRQHandler,Default_Handler
  343. .weak UART5_IRQHandler
  344. .thumb_set UART5_IRQHandler,Default_Handler
  345. .weak TIM6_DAC_IRQHandler
  346. .thumb_set TIM6_DAC_IRQHandler,Default_Handler
  347. .weak TIM7_IRQHandler
  348. .thumb_set TIM7_IRQHandler,Default_Handler
  349. .weak DMA2_Stream0_IRQHandler
  350. .thumb_set DMA2_Stream0_IRQHandler,Default_Handler
  351. .weak DMA2_Stream1_IRQHandler
  352. .thumb_set DMA2_Stream1_IRQHandler,Default_Handler
  353. .weak DMA2_Stream2_IRQHandler
  354. .thumb_set DMA2_Stream2_IRQHandler,Default_Handler
  355. .weak DMA2_Stream3_IRQHandler
  356. .thumb_set DMA2_Stream3_IRQHandler,Default_Handler
  357. .weak DMA2_Stream4_IRQHandler
  358. .thumb_set DMA2_Stream4_IRQHandler,Default_Handler
  359. .weak ETH_IRQHandler
  360. .thumb_set ETH_IRQHandler,Default_Handler
  361. .weak ETH_WKUP_IRQHandler
  362. .thumb_set ETH_WKUP_IRQHandler,Default_Handler
  363. .weak CAN2_TX_IRQHandler
  364. .thumb_set CAN2_TX_IRQHandler,Default_Handler
  365. .weak CAN2_RX0_IRQHandler
  366. .thumb_set CAN2_RX0_IRQHandler,Default_Handler
  367. .weak CAN2_RX1_IRQHandler
  368. .thumb_set CAN2_RX1_IRQHandler,Default_Handler
  369. .weak CAN2_SCE_IRQHandler
  370. .thumb_set CAN2_SCE_IRQHandler,Default_Handler
  371. .weak OTG_FS_IRQHandler
  372. .thumb_set OTG_FS_IRQHandler,Default_Handler
  373. .weak DMA2_Stream5_IRQHandler
  374. .thumb_set DMA2_Stream5_IRQHandler,Default_Handler
  375. .weak DMA2_Stream6_IRQHandler
  376. .thumb_set DMA2_Stream6_IRQHandler,Default_Handler
  377. .weak DMA2_Stream7_IRQHandler
  378. .thumb_set DMA2_Stream7_IRQHandler,Default_Handler
  379. .weak USART6_IRQHandler
  380. .thumb_set USART6_IRQHandler,Default_Handler
  381. .weak I2C3_EV_IRQHandler
  382. .thumb_set I2C3_EV_IRQHandler,Default_Handler
  383. .weak I2C3_ER_IRQHandler
  384. .thumb_set I2C3_ER_IRQHandler,Default_Handler
  385. .weak OTG_HS_EP1_OUT_IRQHandler
  386. .thumb_set OTG_HS_EP1_OUT_IRQHandler,Default_Handler
  387. .weak OTG_HS_EP1_IN_IRQHandler
  388. .thumb_set OTG_HS_EP1_IN_IRQHandler,Default_Handler
  389. .weak OTG_HS_WKUP_IRQHandler
  390. .thumb_set OTG_HS_WKUP_IRQHandler,Default_Handler
  391. .weak OTG_HS_IRQHandler
  392. .thumb_set OTG_HS_IRQHandler,Default_Handler
  393. .weak DCMI_IRQHandler
  394. .thumb_set DCMI_IRQHandler,Default_Handler
  395. .weak HASH_RNG_IRQHandler
  396. .thumb_set HASH_RNG_IRQHandler,Default_Handler
  397. .weak FPU_IRQHandler
  398. .thumb_set FPU_IRQHandler,Default_Handler
  1. /*
  2. ******************************************************************************
  3. **
  4. ** File : LinkerScript.ld
  5. **
  6. ** Author : STM32CubeMX
  7. **
  8. ** Abstract : Linker script for STM32F407VETx series
  9. ** 512Kbytes FLASH and 192Kbytes RAM
  10. **
  11. ** Set heap size, stack size and stack location according
  12. ** to application requirements.
  13. **
  14. ** Set memory bank area and size if external memory is used.
  15. **
  16. ** Target : STMicroelectronics STM32
  17. **
  18. ** Distribution: The file is distributed “as is,” without any warranty
  19. ** of any kind.
  20. **
  21. *****************************************************************************
  22. ** @attention
  23. **
  24. ** <h2><center>&copy; COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
  25. **
  26. ** Redistribution and use in source and binary forms, with or without modification,
  27. ** are permitted provided that the following conditions are met:
  28. ** 1. Redistributions of source code must retain the above copyright notice,
  29. ** this list of conditions and the following disclaimer.
  30. ** 2. Redistributions in binary form must reproduce the above copyright notice,
  31. ** this list of conditions and the following disclaimer in the documentation
  32. ** and/or other materials provided with the distribution.
  33. ** 3. Neither the name of STMicroelectronics nor the names of its contributors
  34. ** may be used to endorse or promote products derived from this software
  35. ** without specific prior written permission.
  36. **
  37. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  38. ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  39. ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  40. ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  41. ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  42. ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  43. ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  44. ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  46. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. **
  48. *****************************************************************************
  49. */
  50. /* Entry Point */
  51. ENTRY(Reset_Handler)
  52. /* Highest address of the user mode stack */
  53. _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of RAM */
  54. /* Generate a link error if heap and stack don't fit into RAM */
  55. _Min_Heap_Size = 0x200; /* required amount of heap */
  56. _Min_Stack_Size = 0x400; /* required amount of stack */
  57. /* Specify the memory areas */
  58. MEMORY
  59. {
  60. RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
  61. CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
  62. FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
  63. }
  64. /* Define output sections */
  65. SECTIONS
  66. {
  67. /* The startup code goes first into FLASH */
  68. .isr_vector :
  69. {
  70. . = ALIGN(4);
  71. KEEP(*(.isr_vector)) /* Startup code */
  72. . = ALIGN(4);
  73. } >FLASH
  74. /* The program code and other data goes into FLASH */
  75. .text :
  76. {
  77. . = ALIGN(4);
  78. *(.text) /* .text sections (code) */
  79. *(.text*) /* .text* sections (code) */
  80. *(.glue_7) /* glue arm to thumb code */
  81. *(.glue_7t) /* glue thumb to arm code */
  82. *(.eh_frame)
  83. KEEP (*(.init))
  84. KEEP (*(.fini))
  85. . = ALIGN(4);
  86. _etext = .; /* define a global symbols at end of code */
  87. } >FLASH
  88. /* Constant data goes into FLASH */
  89. .rodata :
  90. {
  91. . = ALIGN(4);
  92. *(.rodata) /* .rodata sections (constants, strings, etc.) */
  93. *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
  94. . = ALIGN(4);
  95. } >FLASH
  96. .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
  97. .ARM : {
  98. __exidx_start = .;
  99. *(.ARM.exidx*)
  100. __exidx_end = .;
  101. } >FLASH
  102. .preinit_array :
  103. {
  104. PROVIDE_HIDDEN (__preinit_array_start = .);
  105. KEEP (*(.preinit_array*))
  106. PROVIDE_HIDDEN (__preinit_array_end = .);
  107. } >FLASH
  108. .init_array :
  109. {
  110. PROVIDE_HIDDEN (__init_array_start = .);
  111. KEEP (*(SORT(.init_array.*)))
  112. KEEP (*(.init_array*))
  113. PROVIDE_HIDDEN (__init_array_end = .);
  114. } >FLASH
  115. .fini_array :
  116. {
  117. PROVIDE_HIDDEN (__fini_array_start = .);
  118. KEEP (*(SORT(.fini_array.*)))
  119. KEEP (*(.fini_array*))
  120. PROVIDE_HIDDEN (__fini_array_end = .);
  121. } >FLASH
  122. /* used by the startup to initialize data */
  123. _sidata = LOADADDR(.data);
  124. /* Initialized data sections goes into RAM, load LMA copy after code */
  125. .data :
  126. {
  127. . = ALIGN(4);
  128. _sdata = .; /* create a global symbol at data start */
  129. *(.data) /* .data sections */
  130. *(.data*) /* .data* sections */
  131. . = ALIGN(4);
  132. _edata = .; /* define a global symbol at data end */
  133. } >RAM AT> FLASH
  134. _siccmram = LOADADDR(.ccmram);
  135. /* CCM-RAM section
  136. *
  137. * IMPORTANT NOTE!
  138. * If initialized variables will be placed in this section,
  139. * the startup code needs to be modified to copy the init-values.
  140. */
  141. .ccmram :
  142. {
  143. . = ALIGN(4);
  144. _sccmram = .; /* create a global symbol at ccmram start */
  145. *(.ccmram)
  146. *(.ccmram*)
  147. . = ALIGN(4);
  148. _eccmram = .; /* create a global symbol at ccmram end */
  149. } >CCMRAM AT> FLASH
  150. /* Uninitialized data section */
  151. . = ALIGN(4);
  152. .bss :
  153. {
  154. /* This is used by the startup in order to initialize the .bss secion */
  155. _sbss = .; /* define a global symbol at bss start */
  156. __bss_start__ = _sbss;
  157. *(.bss)
  158. *(.bss*)
  159. *(COMMON)
  160. . = ALIGN(4);
  161. _ebss = .; /* define a global symbol at bss end */
  162. __bss_end__ = _ebss;
  163. } >RAM
  164. /* User_heap_stack section, used to check that there is enough RAM left */
  165. ._user_heap_stack :
  166. {
  167. . = ALIGN(8);
  168. PROVIDE ( end = . );
  169. PROVIDE ( _end = . );
  170. . = . + _Min_Heap_Size;
  171. . = . + _Min_Stack_Size;
  172. . = ALIGN(8);
  173. } >RAM
  174. /* Remove information from the standard libraries */
  175. /DISCARD/ :
  176. {
  177. libc.a ( * )
  178. libm.a ( * )
  179. libgcc.a ( * )
  180. }
  181. .ARM.attributes 0 : { *(.ARM.attributes) }
  182. }
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx.h
  4. * @author MCD Application Team
  5. * @brief CMSIS STM32F4xx Device Peripheral Access Layer Header File.
  6. *
  7. * The file is the unique include file that the application programmer
  8. * is using in the C source code, usually in main.c. This file contains:
  9. * - Configuration section that allows to select:
  10. * - The STM32F4xx device used in the target application
  11. * - To use or not the peripheral's drivers in application code(i.e.
  12. * code will be based on direct access to peripheral's registers
  13. * rather than drivers API), this option is controlled by
  14. * "#define USE_HAL_DRIVER"
  15. *
  16. ******************************************************************************
  17. * @attention
  18. *
  19. * Copyright (c) 2017 STMicroelectronics.
  20. * All rights reserved.
  21. *
  22. * This software is licensed under terms that can be found in the LICENSE file
  23. * in the root directory of this software component.
  24. * If no LICENSE file comes with this software, it is provided AS-IS.
  25. *
  26. ******************************************************************************
  27. */
  28. /** @addtogroup CMSIS
  29. * @{
  30. */
  31. /** @addtogroup stm32f4xx
  32. * @{
  33. */
  34. #ifndef __STM32F4xx_H
  35. #define __STM32F4xx_H
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif /* __cplusplus */
  39. /** @addtogroup Library_configuration_section
  40. * @{
  41. */
  42. /**
  43. * @brief STM32 Family
  44. */
  45. #if !defined (STM32F4)
  46. #define STM32F4
  47. #endif /* STM32F4 */
  48. /* Uncomment the line below according to the target STM32 device used in your
  49. application
  50. */
  51. #if !defined (STM32F405xx) && !defined (STM32F415xx) && !defined (STM32F407xx) && !defined (STM32F417xx) && \
  52. !defined (STM32F427xx) && !defined (STM32F437xx) && !defined (STM32F429xx) && !defined (STM32F439xx) && \
  53. !defined (STM32F401xC) && !defined (STM32F401xE) && !defined (STM32F410Tx) && !defined (STM32F410Cx) && \
  54. !defined (STM32F410Rx) && !defined (STM32F411xE) && !defined (STM32F446xx) && !defined (STM32F469xx) && \
  55. !defined (STM32F479xx) && !defined (STM32F412Cx) && !defined (STM32F412Rx) && !defined (STM32F412Vx) && \
  56. !defined (STM32F412Zx) && !defined (STM32F413xx) && !defined (STM32F423xx)
  57. /* #define STM32F405xx */ /*!< STM32F405RG, STM32F405VG and STM32F405ZG Devices */
  58. /* #define STM32F415xx */ /*!< STM32F415RG, STM32F415VG and STM32F415ZG Devices */
  59. /* #define STM32F407xx */ /*!< STM32F407VG, STM32F407VE, STM32F407ZG, STM32F407ZE, STM32F407IG and STM32F407IE Devices */
  60. /* #define STM32F417xx */ /*!< STM32F417VG, STM32F417VE, STM32F417ZG, STM32F417ZE, STM32F417IG and STM32F417IE Devices */
  61. /* #define STM32F427xx */ /*!< STM32F427VG, STM32F427VI, STM32F427ZG, STM32F427ZI, STM32F427IG and STM32F427II Devices */
  62. /* #define STM32F437xx */ /*!< STM32F437VG, STM32F437VI, STM32F437ZG, STM32F437ZI, STM32F437IG and STM32F437II Devices */
  63. /* #define STM32F429xx */ /*!< STM32F429VG, STM32F429VI, STM32F429ZG, STM32F429ZI, STM32F429BG, STM32F429BI, STM32F429NG,
  64. STM32F439NI, STM32F429IG and STM32F429II Devices */
  65. /* #define STM32F439xx */ /*!< STM32F439VG, STM32F439VI, STM32F439ZG, STM32F439ZI, STM32F439BG, STM32F439BI, STM32F439NG,
  66. STM32F439NI, STM32F439IG and STM32F439II Devices */
  67. /* #define STM32F401xC */ /*!< STM32F401CB, STM32F401CC, STM32F401RB, STM32F401RC, STM32F401VB and STM32F401VC Devices */
  68. /* #define STM32F401xE */ /*!< STM32F401CD, STM32F401RD, STM32F401VD, STM32F401CE, STM32F401RE and STM32F401VE Devices */
  69. /* #define STM32F410Tx */ /*!< STM32F410T8 and STM32F410TB Devices */
  70. /* #define STM32F410Cx */ /*!< STM32F410C8 and STM32F410CB Devices */
  71. /* #define STM32F410Rx */ /*!< STM32F410R8 and STM32F410RB Devices */
  72. /* #define STM32F411xE */ /*!< STM32F411CC, STM32F411RC, STM32F411VC, STM32F411CE, STM32F411RE and STM32F411VE Devices */
  73. /* #define STM32F446xx */ /*!< STM32F446MC, STM32F446ME, STM32F446RC, STM32F446RE, STM32F446VC, STM32F446VE, STM32F446ZC,
  74. and STM32F446ZE Devices */
  75. /* #define STM32F469xx */ /*!< STM32F469AI, STM32F469II, STM32F469BI, STM32F469NI, STM32F469AG, STM32F469IG, STM32F469BG,
  76. STM32F469NG, STM32F469AE, STM32F469IE, STM32F469BE and STM32F469NE Devices */
  77. /* #define STM32F479xx */ /*!< STM32F479AI, STM32F479II, STM32F479BI, STM32F479NI, STM32F479AG, STM32F479IG, STM32F479BG
  78. and STM32F479NG Devices */
  79. /* #define STM32F412Cx */ /*!< STM32F412CEU and STM32F412CGU Devices */
  80. /* #define STM32F412Zx */ /*!< STM32F412ZET, STM32F412ZGT, STM32F412ZEJ and STM32F412ZGJ Devices */
  81. /* #define STM32F412Vx */ /*!< STM32F412VET, STM32F412VGT, STM32F412VEH and STM32F412VGH Devices */
  82. /* #define STM32F412Rx */ /*!< STM32F412RET, STM32F412RGT, STM32F412REY and STM32F412RGY Devices */
  83. /* #define STM32F413xx */ /*!< STM32F413CH, STM32F413MH, STM32F413RH, STM32F413VH, STM32F413ZH, STM32F413CG, STM32F413MG,
  84. STM32F413RG, STM32F413VG and STM32F413ZG Devices */
  85. /* #define STM32F423xx */ /*!< STM32F423CH, STM32F423RH, STM32F423VH and STM32F423ZH Devices */
  86. #endif
  87. /* Tip: To avoid modifying this file each time you need to switch between these
  88. devices, you can define the device in your toolchain compiler preprocessor.
  89. */
  90. #if !defined (USE_HAL_DRIVER)
  91. /**
  92. * @brief Comment the line below if you will not use the peripherals drivers.
  93. In this case, these drivers will not be included and the application code will
  94. be based on direct access to peripherals registers
  95. */
  96. /*#define USE_HAL_DRIVER */
  97. #endif /* USE_HAL_DRIVER */
  98. /**
  99. * @brief CMSIS version number V2.6.8
  100. */
  101. #define __STM32F4xx_CMSIS_VERSION_MAIN (0x02U) /*!< [31:24] main version */
  102. #define __STM32F4xx_CMSIS_VERSION_SUB1 (0x06U) /*!< [23:16] sub1 version */
  103. #define __STM32F4xx_CMSIS_VERSION_SUB2 (0x08U) /*!< [15:8] sub2 version */
  104. #define __STM32F4xx_CMSIS_VERSION_RC (0x00U) /*!< [7:0] release candidate */
  105. #define __STM32F4xx_CMSIS_VERSION ((__STM32F4xx_CMSIS_VERSION_MAIN << 24)\
  106. |(__STM32F4xx_CMSIS_VERSION_SUB1 << 16)\
  107. |(__STM32F4xx_CMSIS_VERSION_SUB2 << 8 )\
  108. |(__STM32F4xx_CMSIS_VERSION_RC))
  109. /**
  110. * @}
  111. */
  112. /** @addtogroup Device_Included
  113. * @{
  114. */
  115. #if defined(STM32F405xx)
  116. #include "stm32f405xx.h"
  117. #elif defined(STM32F415xx)
  118. #include "stm32f415xx.h"
  119. #elif defined(STM32F407xx)
  120. #include "stm32f407xx.h"
  121. #elif defined(STM32F417xx)
  122. #include "stm32f417xx.h"
  123. #elif defined(STM32F427xx)
  124. #include "stm32f427xx.h"
  125. #elif defined(STM32F437xx)
  126. #include "stm32f437xx.h"
  127. #elif defined(STM32F429xx)
  128. #include "stm32f429xx.h"
  129. #elif defined(STM32F439xx)
  130. #include "stm32f439xx.h"
  131. #elif defined(STM32F401xC)
  132. #include "stm32f401xc.h"
  133. #elif defined(STM32F401xE)
  134. #include "stm32f401xe.h"
  135. #elif defined(STM32F410Tx)
  136. #include "stm32f410tx.h"
  137. #elif defined(STM32F410Cx)
  138. #include "stm32f410cx.h"
  139. #elif defined(STM32F410Rx)
  140. #include "stm32f410rx.h"
  141. #elif defined(STM32F411xE)
  142. #include "stm32f411xe.h"
  143. #elif defined(STM32F446xx)
  144. #include "stm32f446xx.h"
  145. #elif defined(STM32F469xx)
  146. #include "stm32f469xx.h"
  147. #elif defined(STM32F479xx)
  148. #include "stm32f479xx.h"
  149. #elif defined(STM32F412Cx)
  150. #include "stm32f412cx.h"
  151. #elif defined(STM32F412Zx)
  152. #include "stm32f412zx.h"
  153. #elif defined(STM32F412Rx)
  154. #include "stm32f412rx.h"
  155. #elif defined(STM32F412Vx)
  156. #include "stm32f412vx.h"
  157. #elif defined(STM32F413xx)
  158. #include "stm32f413xx.h"
  159. #elif defined(STM32F423xx)
  160. #include "stm32f423xx.h"
  161. #else
  162. #error "Please select first the target STM32F4xx device used in your application (in stm32f4xx.h file)"
  163. #endif
  164. /**
  165. * @}
  166. */
  167. /** @addtogroup Exported_types
  168. * @{
  169. */
  170. typedef enum
  171. {
  172. RESET = 0U,
  173. SET = !RESET
  174. } FlagStatus, ITStatus;
  175. typedef enum
  176. {
  177. DISABLE = 0U,
  178. ENABLE = !DISABLE
  179. } FunctionalState;
  180. #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
  181. typedef enum
  182. {
  183. SUCCESS = 0U,
  184. ERROR = !SUCCESS
  185. } ErrorStatus;
  186. /**
  187. * @}
  188. */
  189. /** @addtogroup Exported_macro
  190. * @{
  191. */
  192. #define SET_BIT(REG, BIT) ((REG) |= (BIT))
  193. #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
  194. #define READ_BIT(REG, BIT) ((REG) & (BIT))
  195. #define CLEAR_REG(REG) ((REG) = (0x0))
  196. #define WRITE_REG(REG, VAL) ((REG) = (VAL))
  197. #define READ_REG(REG) ((REG))
  198. #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
  199. #define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL)))
  200. /* Use of CMSIS compiler intrinsics for register exclusive access */
  201. /* Atomic 32-bit register access macro to set one or several bits */
  202. #define ATOMIC_SET_BIT(REG, BIT) \
  203. do { \
  204. uint32_t val; \
  205. do { \
  206. val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT); \
  207. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  208. } while(0)
  209. /* Atomic 32-bit register access macro to clear one or several bits */
  210. #define ATOMIC_CLEAR_BIT(REG, BIT) \
  211. do { \
  212. uint32_t val; \
  213. do { \
  214. val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT); \
  215. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  216. } while(0)
  217. /* Atomic 32-bit register access macro to clear and set one or several bits */
  218. #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \
  219. do { \
  220. uint32_t val; \
  221. do { \
  222. val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
  223. } while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
  224. } while(0)
  225. /* Atomic 16-bit register access macro to set one or several bits */
  226. #define ATOMIC_SETH_BIT(REG, BIT) \
  227. do { \
  228. uint16_t val; \
  229. do { \
  230. val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT); \
  231. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  232. } while(0)
  233. /* Atomic 16-bit register access macro to clear one or several bits */
  234. #define ATOMIC_CLEARH_BIT(REG, BIT) \
  235. do { \
  236. uint16_t val; \
  237. do { \
  238. val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT); \
  239. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  240. } while(0)
  241. /* Atomic 16-bit register access macro to clear and set one or several bits */
  242. #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) \
  243. do { \
  244. uint16_t val; \
  245. do { \
  246. val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
  247. } while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
  248. } while(0)
  249. /**
  250. * @}
  251. */
  252. #if defined (USE_HAL_DRIVER)
  253. #include "stm32f4xx_hal.h"
  254. #endif /* USE_HAL_DRIVER */
  255. #ifdef __cplusplus
  256. }
  257. #endif /* __cplusplus */
  258. #endif /* __STM32F4xx_H */
  259. /**
  260. * @}
  261. */
  262. /**
  263. * @}
  264. */

Shift+Ctrl+p(C/C++配置)后生成的c_cpp_properties.json文件

  1. {
  2. "configurations": [
  3. {
  4. "name": "Win32",
  5. "includePath": [
  6. "${workspaceFolder}/**"
  7. ],
  8. "defines": [
  9. "_DEBUG",
  10. "UNICODE",
  11. "_UNICODE",
  12. "USE_HAL_DRIVER",//可以修改(makefile c defines中的)
  13. "STM32F407xx"//可以修改(makefile c defines中的)
  14. ],
  15. "windowsSdkVersion": "10.0.19041.0",
  16. "compilerPath": "D:/vs studio/SDK/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe",
  17. "cStandard": "c17",
  18. "cppStandard": "c++17",
  19. "intelliSenseMode": "gcc-arm"//可以修改
  20. }
  21. ],
  22. "version": 4
  23. }

添加settings.json

  1. {
  2. "makefile.extensionOutputFolder": "./.vscode"
  3. }
  1. {
  2. "tasks": [
  3. {
  4. "type": "cppbuild",
  5. "label": "C/C++: gcc.exe 生成活动文件",
  6. "command": "D:/LearnApp/SDK/C/Feil/mingw64/bin/gcc.exe",
  7. "args": [
  8. "-fdiagnostics-color=always",
  9. "-g",
  10. "${file}",
  11. "-o",
  12. "${fileDirname}\\${fileBasenameNoExtension}.exe"
  13. ],
  14. "options": {
  15. "cwd": "D:/LearnApp/SDK/C/Feil/mingw64/bin"
  16. },
  17. "problemMatcher": [
  18. "$gcc"
  19. ],
  20. "group": {
  21. "kind": "build",
  22. "isDefault": true
  23. },
  24. "detail": "调试器生成的任务。"
  25. },
  26. //按照以上格式添加这段
  27. {
  28. "type": "shell",//类型
  29. "label": "Update", //运行任务中的名称
  30. "command": "D:/IOT/STM32/File/openocd-0.10.0/bin/openocd.exe", //执行的命令
  31. "args": [
  32. "-f", //文件
  33. "D:/IOT/STM32/File/openocd-0.10.0/scripts/interface/jlink-swd.cfg",
  34. "-f",
  35. "D:/IOT/STM32/File/openocd-0.10.0/scripts/target/stm32f4x.cfg",
  36. "-c",
  37. "program build/401CEU6fist.elf verify reset exit" //build/401CEU6fist.elf: 是你build里面的.elf文件名称和build路径
  38. ],
  39. "problemMatcher": [
  40. "$gcc"
  41. ],
  42. "group": {
  43. "kind": "build",
  44. "isDefault": true
  45. },
  46. "detail": "调试器生成的任务。"
  47. },
  48. //按照最上面的格式添加这段
  49. {
  50. "type": "shell",//类型
  51. "label": "Build",//运行任务中的名称
  52. "command": "make",//执行的命令(需要在环境依赖中有配置)
  53. "args": [
  54. ],
  55. "problemMatcher": [
  56. "$gcc"
  57. ],
  58. "group": {
  59. "kind": "build",
  60. "isDefault": true
  61. },
  62. "detail": "调试器生成的任务。"
  63. }
  64. ],
  65. "version": "2.0.0"
  66. }

之后再写代码:

  1. #include "main.h"
  2. int main(){
  3. volatile unsigned int* pointer;//指针
  4. return 0;
  5. }
  • volatile: 关键字;防止编译器对程序进行优化 ```c

    include “main.h”

int main(){ unsigned int pointer;//指针 pointer += 1; pointer += 2; pointer += 3; //优化后直接+3,可能会与先+1,再+2的产生效果不一致
return 0; }

  1. ```c
  2. #ifndef __MAIN_H
  3. #define __MAIN_H
  4. #ifdef __cplusplus
  5. extern "C"{
  6. #endif
  7. //什么都没有
  8. #ifdef __cplusplus
  9. }
  10. #endif
  11. #endif
  1. #include "main.h"
  2. int main(){
  3. volatile unsigned int* pointer1 = (unsigned int *)0x40022000;
  4. return 0;
  5. }

这样子就指向了我们寄存器中的地址