├── .gitignore ├── 001_FreeRTOS_LEDtask ├── CORE │ ├── core_cm4.h │ ├── core_cm4_simd.h │ └── startup_stm32f40_41xxx.s ├── FWLIB │ ├── inc │ │ ├── misc.h │ │ ├── stm32f4xx_adc.h │ │ ├── stm32f4xx_can.h │ │ ├── stm32f4xx_crc.h │ │ ├── stm32f4xx_cryp.h │ │ ├── stm32f4xx_dac.h │ │ ├── stm32f4xx_dbgmcu.h │ │ ├── stm32f4xx_dcmi.h │ │ ├── stm32f4xx_dma.h │ │ ├── stm32f4xx_dma2d.h │ │ ├── stm32f4xx_exti.h │ │ ├── stm32f4xx_flash.h │ │ ├── stm32f4xx_flash_ramfunc.h │ │ ├── stm32f4xx_fmc.h │ │ ├── stm32f4xx_fsmc.h │ │ ├── stm32f4xx_gpio.h │ │ ├── stm32f4xx_hash.h │ │ ├── stm32f4xx_i2c.h │ │ ├── stm32f4xx_iwdg.h │ │ ├── stm32f4xx_ltdc.h │ │ ├── stm32f4xx_pwr.h │ │ ├── stm32f4xx_rcc.h │ │ ├── stm32f4xx_rng.h │ │ ├── stm32f4xx_rtc.h │ │ ├── stm32f4xx_sai.h │ │ ├── stm32f4xx_sdio.h │ │ ├── stm32f4xx_spi.h │ │ ├── stm32f4xx_syscfg.h │ │ ├── stm32f4xx_tim.h │ │ ├── stm32f4xx_usart.h │ │ └── stm32f4xx_wwdg.h │ └── src │ │ ├── misc.c │ │ ├── stm32f4xx_adc.c │ │ ├── stm32f4xx_can.c │ │ ├── stm32f4xx_crc.c │ │ ├── stm32f4xx_cryp.c │ │ ├── stm32f4xx_cryp_aes.c │ │ ├── stm32f4xx_cryp_des.c │ │ ├── stm32f4xx_cryp_tdes.c │ │ ├── stm32f4xx_dac.c │ │ ├── stm32f4xx_dbgmcu.c │ │ ├── stm32f4xx_dcmi.c │ │ ├── stm32f4xx_dma.c │ │ ├── stm32f4xx_dma2d.c │ │ ├── stm32f4xx_exti.c │ │ ├── stm32f4xx_flash.c │ │ ├── stm32f4xx_flash_ramfunc.c │ │ ├── stm32f4xx_fmc.c │ │ ├── stm32f4xx_fsmc.c │ │ ├── stm32f4xx_gpio.c │ │ ├── stm32f4xx_hash.c │ │ ├── stm32f4xx_hash_md5.c │ │ ├── stm32f4xx_hash_sha1.c │ │ ├── stm32f4xx_i2c.c │ │ ├── stm32f4xx_iwdg.c │ │ ├── stm32f4xx_ltdc.c │ │ ├── stm32f4xx_pwr.c │ │ ├── stm32f4xx_rcc.c │ │ ├── stm32f4xx_rng.c │ │ ├── stm32f4xx_rtc.c │ │ ├── stm32f4xx_sai.c │ │ ├── stm32f4xx_sdio.c │ │ ├── stm32f4xx_spi.c │ │ ├── stm32f4xx_syscfg.c │ │ ├── stm32f4xx_tim.c │ │ ├── stm32f4xx_usart.c │ │ └── stm32f4xx_wwdg.c ├── FreeRTOS │ ├── Demo │ │ └── CORTEX_M4F_STM32F407ZG-SK │ │ │ └── FreeRTOSConfig.h │ ├── croutine.c │ ├── event_groups.c │ ├── include │ │ ├── FreeRTOS.h │ │ ├── FreeRTOSConfig.h │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── portable.h │ │ ├── projdefs.h │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ └── timers.h │ ├── list.c │ ├── portable │ │ ├── Keil │ │ │ └── See-also-the-RVDS-directory.txt │ │ ├── MemMang │ │ │ ├── ReadMe.url │ │ │ ├── heap_1.c │ │ │ ├── heap_2.c │ │ │ ├── heap_3.c │ │ │ ├── heap_4.c │ │ │ └── heap_5.c │ │ ├── RVDS │ │ │ ├── ARM7_LPC21xx │ │ │ │ ├── port.c │ │ │ │ ├── portASM.s │ │ │ │ ├── portmacro.h │ │ │ │ └── portmacro.inc │ │ │ ├── ARM_CA9 │ │ │ │ ├── port.c │ │ │ │ ├── portASM.s │ │ │ │ ├── portmacro.h │ │ │ │ └── portmacro.inc │ │ │ ├── ARM_CM0 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM3 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM4F │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM4_MPU │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ └── ARM_CM7 │ │ │ │ ├── ReadMe.txt │ │ │ │ └── r0p1 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ └── readme.txt │ ├── queue.c │ ├── readme.txt │ ├── tasks.c │ └── timers.c ├── README │ └── README.txt ├── RTE │ └── RTE_Components.h ├── SYSTEM │ ├── delay.c │ ├── delay.h │ ├── key.c │ ├── key.h │ ├── led.c │ ├── led.h │ ├── sys.c │ ├── sys.h │ ├── usart.c │ └── usart.h ├── Template_FreeRTOS.uvguix.Administrator ├── Template_FreeRTOS.uvoptx ├── Template_FreeRTOS.uvprojx ├── USER │ ├── main.c │ ├── stm32f4xx.h │ ├── stm32f4xx_conf.h │ ├── stm32f4xx_it.c │ ├── stm32f4xx_it.h │ ├── system_stm32f4xx.c │ └── system_stm32f4xx.h └── keilkilll.bat ├── README.md ├── Template_FreeRTOS ├── CORE │ ├── core_cm4.h │ ├── core_cm4_simd.h │ └── startup_stm32f40_41xxx.s ├── FWLIB │ ├── inc │ │ ├── misc.h │ │ ├── stm32f4xx_adc.h │ │ ├── stm32f4xx_can.h │ │ ├── stm32f4xx_crc.h │ │ ├── stm32f4xx_cryp.h │ │ ├── stm32f4xx_dac.h │ │ ├── stm32f4xx_dbgmcu.h │ │ ├── stm32f4xx_dcmi.h │ │ ├── stm32f4xx_dma.h │ │ ├── stm32f4xx_dma2d.h │ │ ├── stm32f4xx_exti.h │ │ ├── stm32f4xx_flash.h │ │ ├── stm32f4xx_flash_ramfunc.h │ │ ├── stm32f4xx_fmc.h │ │ ├── stm32f4xx_fsmc.h │ │ ├── stm32f4xx_gpio.h │ │ ├── stm32f4xx_hash.h │ │ ├── stm32f4xx_i2c.h │ │ ├── stm32f4xx_iwdg.h │ │ ├── stm32f4xx_ltdc.h │ │ ├── stm32f4xx_pwr.h │ │ ├── stm32f4xx_rcc.h │ │ ├── stm32f4xx_rng.h │ │ ├── stm32f4xx_rtc.h │ │ ├── stm32f4xx_sai.h │ │ ├── stm32f4xx_sdio.h │ │ ├── stm32f4xx_spi.h │ │ ├── stm32f4xx_syscfg.h │ │ ├── stm32f4xx_tim.h │ │ ├── stm32f4xx_usart.h │ │ └── stm32f4xx_wwdg.h │ └── src │ │ ├── misc.c │ │ ├── stm32f4xx_adc.c │ │ ├── stm32f4xx_can.c │ │ ├── stm32f4xx_crc.c │ │ ├── stm32f4xx_cryp.c │ │ ├── stm32f4xx_cryp_aes.c │ │ ├── stm32f4xx_cryp_des.c │ │ ├── stm32f4xx_cryp_tdes.c │ │ ├── stm32f4xx_dac.c │ │ ├── stm32f4xx_dbgmcu.c │ │ ├── stm32f4xx_dcmi.c │ │ ├── stm32f4xx_dma.c │ │ ├── stm32f4xx_dma2d.c │ │ ├── stm32f4xx_exti.c │ │ ├── stm32f4xx_flash.c │ │ ├── stm32f4xx_flash_ramfunc.c │ │ ├── stm32f4xx_fmc.c │ │ ├── stm32f4xx_fsmc.c │ │ ├── stm32f4xx_gpio.c │ │ ├── stm32f4xx_hash.c │ │ ├── stm32f4xx_hash_md5.c │ │ ├── stm32f4xx_hash_sha1.c │ │ ├── stm32f4xx_i2c.c │ │ ├── stm32f4xx_iwdg.c │ │ ├── stm32f4xx_ltdc.c │ │ ├── stm32f4xx_pwr.c │ │ ├── stm32f4xx_rcc.c │ │ ├── stm32f4xx_rng.c │ │ ├── stm32f4xx_rtc.c │ │ ├── stm32f4xx_sai.c │ │ ├── stm32f4xx_sdio.c │ │ ├── stm32f4xx_spi.c │ │ ├── stm32f4xx_syscfg.c │ │ ├── stm32f4xx_tim.c │ │ ├── stm32f4xx_usart.c │ │ └── stm32f4xx_wwdg.c ├── FreeRTOS │ ├── Demo │ │ └── CORTEX_M4F_STM32F407ZG-SK │ │ │ └── FreeRTOSConfig.h │ ├── croutine.c │ ├── event_groups.c │ ├── include │ │ ├── FreeRTOS.h │ │ ├── FreeRTOSConfig.h │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── portable.h │ │ ├── projdefs.h │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ └── timers.h │ ├── list.c │ ├── portable │ │ ├── Keil │ │ │ └── See-also-the-RVDS-directory.txt │ │ ├── MemMang │ │ │ ├── ReadMe.url │ │ │ ├── heap_1.c │ │ │ ├── heap_2.c │ │ │ ├── heap_3.c │ │ │ ├── heap_4.c │ │ │ └── heap_5.c │ │ ├── RVDS │ │ │ ├── ARM7_LPC21xx │ │ │ │ ├── port.c │ │ │ │ ├── portASM.s │ │ │ │ ├── portmacro.h │ │ │ │ └── portmacro.inc │ │ │ ├── ARM_CA9 │ │ │ │ ├── port.c │ │ │ │ ├── portASM.s │ │ │ │ ├── portmacro.h │ │ │ │ └── portmacro.inc │ │ │ ├── ARM_CM0 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM3 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM4F │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM4_MPU │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ └── ARM_CM7 │ │ │ │ ├── ReadMe.txt │ │ │ │ └── r0p1 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ └── readme.txt │ ├── queue.c │ ├── readme.txt │ ├── tasks.c │ └── timers.c ├── README │ └── README.txt ├── RTE │ └── RTE_Components.h ├── SYSTEM │ ├── delay.c │ ├── delay.h │ ├── key.c │ ├── key.h │ ├── led.c │ ├── led.h │ ├── sys.c │ ├── sys.h │ ├── usart.c │ └── usart.h ├── Template_FreeRTOS.uvguix.Administrator ├── Template_FreeRTOS.uvoptx ├── Template_FreeRTOS.uvprojx ├── USER │ ├── main.c │ ├── stm32f4xx.h │ ├── stm32f4xx_conf.h │ ├── stm32f4xx_it.c │ ├── stm32f4xx_it.h │ ├── system_stm32f4xx.c │ └── system_stm32f4xx.h └── keilkilll.bat ├── Template_lib ├── CORE │ ├── core_cm4.h │ ├── core_cm4_simd.h │ └── startup_stm32f40_41xxx.s ├── FWLIB │ ├── inc │ │ ├── misc.h │ │ ├── stm32f4xx_adc.h │ │ ├── stm32f4xx_can.h │ │ ├── stm32f4xx_crc.h │ │ ├── stm32f4xx_cryp.h │ │ ├── stm32f4xx_dac.h │ │ ├── stm32f4xx_dbgmcu.h │ │ ├── stm32f4xx_dcmi.h │ │ ├── stm32f4xx_dma.h │ │ ├── stm32f4xx_dma2d.h │ │ ├── stm32f4xx_exti.h │ │ ├── stm32f4xx_flash.h │ │ ├── stm32f4xx_flash_ramfunc.h │ │ ├── stm32f4xx_fmc.h │ │ ├── stm32f4xx_fsmc.h │ │ ├── stm32f4xx_gpio.h │ │ ├── stm32f4xx_hash.h │ │ ├── stm32f4xx_i2c.h │ │ ├── stm32f4xx_iwdg.h │ │ ├── stm32f4xx_ltdc.h │ │ ├── stm32f4xx_pwr.h │ │ ├── stm32f4xx_rcc.h │ │ ├── stm32f4xx_rng.h │ │ ├── stm32f4xx_rtc.h │ │ ├── stm32f4xx_sai.h │ │ ├── stm32f4xx_sdio.h │ │ ├── stm32f4xx_spi.h │ │ ├── stm32f4xx_syscfg.h │ │ ├── stm32f4xx_tim.h │ │ ├── stm32f4xx_usart.h │ │ └── stm32f4xx_wwdg.h │ └── src │ │ ├── misc.c │ │ ├── stm32f4xx_adc.c │ │ ├── stm32f4xx_can.c │ │ ├── stm32f4xx_crc.c │ │ ├── stm32f4xx_cryp.c │ │ ├── stm32f4xx_cryp_aes.c │ │ ├── stm32f4xx_cryp_des.c │ │ ├── stm32f4xx_cryp_tdes.c │ │ ├── stm32f4xx_dac.c │ │ ├── stm32f4xx_dbgmcu.c │ │ ├── stm32f4xx_dcmi.c │ │ ├── stm32f4xx_dma.c │ │ ├── stm32f4xx_dma2d.c │ │ ├── stm32f4xx_exti.c │ │ ├── stm32f4xx_flash.c │ │ ├── stm32f4xx_flash_ramfunc.c │ │ ├── stm32f4xx_fmc.c │ │ ├── stm32f4xx_fsmc.c │ │ ├── stm32f4xx_gpio.c │ │ ├── stm32f4xx_hash.c │ │ ├── stm32f4xx_hash_md5.c │ │ ├── stm32f4xx_hash_sha1.c │ │ ├── stm32f4xx_i2c.c │ │ ├── stm32f4xx_iwdg.c │ │ ├── stm32f4xx_ltdc.c │ │ ├── stm32f4xx_pwr.c │ │ ├── stm32f4xx_rcc.c │ │ ├── stm32f4xx_rng.c │ │ ├── stm32f4xx_rtc.c │ │ ├── stm32f4xx_sai.c │ │ ├── stm32f4xx_sdio.c │ │ ├── stm32f4xx_spi.c │ │ ├── stm32f4xx_syscfg.c │ │ ├── stm32f4xx_tim.c │ │ ├── stm32f4xx_usart.c │ │ └── stm32f4xx_wwdg.c ├── FreeRTOS │ ├── Demo │ │ └── CORTEX_M4F_STM32F407ZG-SK │ │ │ └── FreeRTOSConfig.h │ ├── croutine.c │ ├── event_groups.c │ ├── include │ │ ├── FreeRTOS.h │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── portable.h │ │ ├── projdefs.h │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ └── timers.h │ ├── list.c │ ├── portable │ │ ├── Keil │ │ │ └── See-also-the-RVDS-directory.txt │ │ ├── MemMang │ │ │ ├── ReadMe.url │ │ │ ├── heap_1.c │ │ │ ├── heap_2.c │ │ │ ├── heap_3.c │ │ │ ├── heap_4.c │ │ │ └── heap_5.c │ │ ├── RVDS │ │ │ ├── ARM7_LPC21xx │ │ │ │ ├── port.c │ │ │ │ ├── portASM.s │ │ │ │ ├── portmacro.h │ │ │ │ └── portmacro.inc │ │ │ ├── ARM_CA9 │ │ │ │ ├── port.c │ │ │ │ ├── portASM.s │ │ │ │ ├── portmacro.h │ │ │ │ └── portmacro.inc │ │ │ ├── ARM_CM0 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM3 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM4F │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM4_MPU │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ └── ARM_CM7 │ │ │ │ ├── ReadMe.txt │ │ │ │ └── r0p1 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ └── readme.txt │ ├── queue.c │ ├── readme.txt │ ├── tasks.c │ └── timers.c ├── README │ └── README.txt ├── SYSTEM │ ├── delay.c │ ├── delay.h │ ├── key.c │ ├── key.h │ ├── led.c │ ├── led.h │ ├── sys.c │ ├── sys.h │ ├── usart.c │ └── usart.h └── USER │ ├── main.c │ ├── stm32f4xx.h │ ├── stm32f4xx_conf.h │ ├── stm32f4xx_it.c │ ├── stm32f4xx_it.h │ ├── system_stm32f4xx.c │ └── system_stm32f4xx.h ├── Template_noOS ├── CORE │ ├── core_cm4.h │ ├── core_cm4_simd.h │ └── startup_stm32f40_41xxx.s ├── FWLIB │ ├── inc │ │ ├── misc.h │ │ ├── stm32f4xx_adc.h │ │ ├── stm32f4xx_can.h │ │ ├── stm32f4xx_crc.h │ │ ├── stm32f4xx_cryp.h │ │ ├── stm32f4xx_dac.h │ │ ├── stm32f4xx_dbgmcu.h │ │ ├── stm32f4xx_dcmi.h │ │ ├── stm32f4xx_dma.h │ │ ├── stm32f4xx_dma2d.h │ │ ├── stm32f4xx_exti.h │ │ ├── stm32f4xx_flash.h │ │ ├── stm32f4xx_flash_ramfunc.h │ │ ├── stm32f4xx_fmc.h │ │ ├── stm32f4xx_fsmc.h │ │ ├── stm32f4xx_gpio.h │ │ ├── stm32f4xx_hash.h │ │ ├── stm32f4xx_i2c.h │ │ ├── stm32f4xx_iwdg.h │ │ ├── stm32f4xx_ltdc.h │ │ ├── stm32f4xx_pwr.h │ │ ├── stm32f4xx_rcc.h │ │ ├── stm32f4xx_rng.h │ │ ├── stm32f4xx_rtc.h │ │ ├── stm32f4xx_sai.h │ │ ├── stm32f4xx_sdio.h │ │ ├── stm32f4xx_spi.h │ │ ├── stm32f4xx_syscfg.h │ │ ├── stm32f4xx_tim.h │ │ ├── stm32f4xx_usart.h │ │ └── stm32f4xx_wwdg.h │ └── src │ │ ├── misc.c │ │ ├── stm32f4xx_adc.c │ │ ├── stm32f4xx_can.c │ │ ├── stm32f4xx_crc.c │ │ ├── stm32f4xx_cryp.c │ │ ├── stm32f4xx_cryp_aes.c │ │ ├── stm32f4xx_cryp_des.c │ │ ├── stm32f4xx_cryp_tdes.c │ │ ├── stm32f4xx_dac.c │ │ ├── stm32f4xx_dbgmcu.c │ │ ├── stm32f4xx_dcmi.c │ │ ├── stm32f4xx_dma.c │ │ ├── stm32f4xx_dma2d.c │ │ ├── stm32f4xx_exti.c │ │ ├── stm32f4xx_flash.c │ │ ├── stm32f4xx_flash_ramfunc.c │ │ ├── stm32f4xx_fmc.c │ │ ├── stm32f4xx_fsmc.c │ │ ├── stm32f4xx_gpio.c │ │ ├── stm32f4xx_hash.c │ │ ├── stm32f4xx_hash_md5.c │ │ ├── stm32f4xx_hash_sha1.c │ │ ├── stm32f4xx_i2c.c │ │ ├── stm32f4xx_iwdg.c │ │ ├── stm32f4xx_ltdc.c │ │ ├── stm32f4xx_pwr.c │ │ ├── stm32f4xx_rcc.c │ │ ├── stm32f4xx_rng.c │ │ ├── stm32f4xx_rtc.c │ │ ├── stm32f4xx_sai.c │ │ ├── stm32f4xx_sdio.c │ │ ├── stm32f4xx_spi.c │ │ ├── stm32f4xx_syscfg.c │ │ ├── stm32f4xx_tim.c │ │ ├── stm32f4xx_usart.c │ │ └── stm32f4xx_wwdg.c ├── README │ └── README.txt ├── RTE │ └── RTE_Components.h ├── SYSTEM │ ├── delay.c │ ├── delay.h │ ├── key.c │ ├── key.h │ ├── led.c │ ├── led.h │ ├── sys.c │ ├── sys.h │ ├── usart.c │ └── usart.h ├── Template_noOS.uvguix.Administrator ├── Template_noOS.uvoptx ├── Template_noOS.uvprojx ├── USER │ ├── main.c │ ├── stm32f4xx.h │ ├── stm32f4xx_conf.h │ ├── stm32f4xx_it.c │ ├── stm32f4xx_it.h │ ├── system_stm32f4xx.c │ └── system_stm32f4xx.h └── keilkilll.bat ├── examples ├── 001_FreeRTOS_LEDtask │ ├── CORE │ │ ├── core_cm4.h │ │ ├── core_cm4_simd.h │ │ └── startup_stm32f40_41xxx.s │ ├── README │ │ └── README.txt │ ├── RTE │ │ └── RTE_Components.h │ ├── SYSTEM │ │ ├── delay.c │ │ ├── delay.h │ │ ├── key.c │ │ ├── key.h │ │ ├── led.c │ │ ├── led.h │ │ ├── sys.c │ │ ├── sys.h │ │ ├── usart.c │ │ └── usart.h │ ├── Template_FreeRTOS.uvprojx │ ├── USER │ │ ├── main.c │ │ ├── stm32f4xx_it.c │ │ └── stm32f4xx_it.h │ └── keilkilll.bat ├── 002_FreeRTOS_LEDtask_Suspend_Resume │ ├── CORE │ │ ├── core_cm4.h │ │ ├── core_cm4_simd.h │ │ └── startup_stm32f40_41xxx.s │ ├── README │ │ └── README.txt │ ├── RTE │ │ └── RTE_Components.h │ ├── SYSTEM │ │ ├── delay.c │ │ ├── delay.h │ │ ├── key.c │ │ ├── key.h │ │ ├── led.c │ │ ├── led.h │ │ ├── sys.c │ │ ├── sys.h │ │ ├── usart.c │ │ └── usart.h │ ├── Template_FreeRTOS.uvprojx │ ├── USER │ │ ├── main.c │ │ ├── stm32f4xx_it.c │ │ └── stm32f4xx_it.h │ └── keilkilll.bat ├── 003_FreeRTOS_uart_idle_recv_and_semaphore │ ├── CORE │ │ ├── core_cm4.h │ │ ├── core_cm4_simd.h │ │ └── startup_stm32f40_41xxx.s │ ├── README │ │ └── README.txt │ ├── RTE │ │ └── RTE_Components.h │ ├── SYSTEM │ │ ├── delay.c │ │ ├── delay.h │ │ ├── key.c │ │ ├── key.h │ │ ├── led.c │ │ ├── led.h │ │ ├── sys.c │ │ ├── sys.h │ │ ├── usart.c │ │ └── usart.h │ ├── Template_FreeRTOS.uvprojx │ ├── USER │ │ ├── main.c │ │ ├── stm32f4xx_it.c │ │ └── stm32f4xx_it.h │ └── keilkilll.bat ├── 004_FreeRTOS_uart_dma_recv_send │ ├── CORE │ │ ├── core_cm4.h │ │ ├── core_cm4_simd.h │ │ └── startup_stm32f40_41xxx.s │ ├── README │ │ └── README.txt │ ├── RTE │ │ └── RTE_Components.h │ ├── SYSTEM │ │ ├── delay.c │ │ ├── delay.h │ │ ├── key.c │ │ ├── key.h │ │ ├── led.c │ │ ├── led.h │ │ ├── sys.c │ │ ├── sys.h │ │ ├── usart.c │ │ └── usart.h │ ├── Template_FreeRTOS.uvprojx │ ├── USER │ │ ├── main.c │ │ ├── stm32f4xx_it.c │ │ └── stm32f4xx_it.h │ └── keilkilll.bat └── commonlib │ ├── FWLIB │ ├── inc │ │ ├── misc.h │ │ ├── stm32f4xx_adc.h │ │ ├── stm32f4xx_can.h │ │ ├── stm32f4xx_crc.h │ │ ├── stm32f4xx_cryp.h │ │ ├── stm32f4xx_dac.h │ │ ├── stm32f4xx_dbgmcu.h │ │ ├── stm32f4xx_dcmi.h │ │ ├── stm32f4xx_dma.h │ │ ├── stm32f4xx_dma2d.h │ │ ├── stm32f4xx_exti.h │ │ ├── stm32f4xx_flash.h │ │ ├── stm32f4xx_flash_ramfunc.h │ │ ├── stm32f4xx_fmc.h │ │ ├── stm32f4xx_fsmc.h │ │ ├── stm32f4xx_gpio.h │ │ ├── stm32f4xx_hash.h │ │ ├── stm32f4xx_i2c.h │ │ ├── stm32f4xx_iwdg.h │ │ ├── stm32f4xx_ltdc.h │ │ ├── stm32f4xx_pwr.h │ │ ├── stm32f4xx_rcc.h │ │ ├── stm32f4xx_rng.h │ │ ├── stm32f4xx_rtc.h │ │ ├── stm32f4xx_sai.h │ │ ├── stm32f4xx_sdio.h │ │ ├── stm32f4xx_spi.h │ │ ├── stm32f4xx_syscfg.h │ │ ├── stm32f4xx_tim.h │ │ ├── stm32f4xx_usart.h │ │ └── stm32f4xx_wwdg.h │ └── src │ │ ├── misc.c │ │ ├── stm32f4xx_adc.c │ │ ├── stm32f4xx_can.c │ │ ├── stm32f4xx_crc.c │ │ ├── stm32f4xx_cryp.c │ │ ├── stm32f4xx_cryp_aes.c │ │ ├── stm32f4xx_cryp_des.c │ │ ├── stm32f4xx_cryp_tdes.c │ │ ├── stm32f4xx_dac.c │ │ ├── stm32f4xx_dbgmcu.c │ │ ├── stm32f4xx_dcmi.c │ │ ├── stm32f4xx_dma.c │ │ ├── stm32f4xx_dma2d.c │ │ ├── stm32f4xx_exti.c │ │ ├── stm32f4xx_flash.c │ │ ├── stm32f4xx_flash_ramfunc.c │ │ ├── stm32f4xx_fmc.c │ │ ├── stm32f4xx_fsmc.c │ │ ├── stm32f4xx_gpio.c │ │ ├── stm32f4xx_hash.c │ │ ├── stm32f4xx_hash_md5.c │ │ ├── stm32f4xx_hash_sha1.c │ │ ├── stm32f4xx_i2c.c │ │ ├── stm32f4xx_iwdg.c │ │ ├── stm32f4xx_ltdc.c │ │ ├── stm32f4xx_pwr.c │ │ ├── stm32f4xx_rcc.c │ │ ├── stm32f4xx_rng.c │ │ ├── stm32f4xx_rtc.c │ │ ├── stm32f4xx_sai.c │ │ ├── stm32f4xx_sdio.c │ │ ├── stm32f4xx_spi.c │ │ ├── stm32f4xx_syscfg.c │ │ ├── stm32f4xx_tim.c │ │ ├── stm32f4xx_usart.c │ │ └── stm32f4xx_wwdg.c │ ├── FreeRTOS │ ├── Demo │ │ └── CORTEX_M4F_STM32F407ZG-SK │ │ │ └── FreeRTOSConfig.h │ ├── croutine.c │ ├── event_groups.c │ ├── include │ │ ├── FreeRTOS.h │ │ ├── FreeRTOSConfig.h │ │ ├── StackMacros.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── list.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── portable.h │ │ ├── projdefs.h │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stdint.readme │ │ ├── task.h │ │ └── timers.h │ ├── list.c │ ├── portable │ │ ├── Keil │ │ │ └── See-also-the-RVDS-directory.txt │ │ ├── MemMang │ │ │ ├── ReadMe.url │ │ │ ├── heap_1.c │ │ │ ├── heap_2.c │ │ │ ├── heap_3.c │ │ │ ├── heap_4.c │ │ │ └── heap_5.c │ │ ├── RVDS │ │ │ ├── ARM7_LPC21xx │ │ │ │ ├── port.c │ │ │ │ ├── portASM.s │ │ │ │ ├── portmacro.h │ │ │ │ └── portmacro.inc │ │ │ ├── ARM_CA9 │ │ │ │ ├── port.c │ │ │ │ ├── portASM.s │ │ │ │ ├── portmacro.h │ │ │ │ └── portmacro.inc │ │ │ ├── ARM_CM0 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM3 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM4F │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ ├── ARM_CM4_MPU │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ │ └── ARM_CM7 │ │ │ │ ├── ReadMe.txt │ │ │ │ └── r0p1 │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ └── readme.txt │ ├── queue.c │ ├── readme.txt │ ├── tasks.c │ └── timers.c │ ├── USER2 │ ├── stm32f4xx.h │ ├── stm32f4xx_conf.h │ ├── system_stm32f4xx.c │ └── system_stm32f4xx.h │ └── readme.txt ├── keilkilll.bat └── pic └── FreeRTOSv9.png /.gitignore: -------------------------------------------------------------------------------- 1 | */Listings/* 2 | */Objects/* 3 | 4 | *.uvguix.Administrator 5 | *.uvoptx 6 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/FWLIB/inc/stm32f4xx_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_crc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_CRC_H 31 | #define __STM32F4xx_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup CRC_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | 62 | void CRC_ResetDR(void); 63 | uint32_t CRC_CalcCRC(uint32_t Data); 64 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 65 | uint32_t CRC_GetCRC(void); 66 | void CRC_SetIDRegister(uint8_t IDValue); 67 | uint8_t CRC_GetIDRegister(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __STM32F4xx_CRC_H */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/FWLIB/inc/stm32f4xx_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief Header file of FLASH RAMFUNC driver. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 31 | #define __STM32F4xx_FLASH_RAMFUNC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup FLASH RAMFUNC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Private define ------------------------------------------------------------*/ 50 | /** 51 | * @brief __RAM_FUNC definition 52 | */ 53 | #if defined ( __CC_ARM ) 54 | /* ARM Compiler 55 | ------------ 56 | RAM functions are defined using the toolchain options. 57 | Functions that are executed in RAM should reside in a separate source module. 58 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 59 | area of a module to a memory space in physical RAM. 60 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 61 | dialog. 62 | */ 63 | #define __RAM_FUNC void 64 | 65 | #elif defined ( __ICCARM__ ) 66 | /* ICCARM Compiler 67 | --------------- 68 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 69 | */ 70 | #define __RAM_FUNC __ramfunc void 71 | 72 | #elif defined ( __GNUC__ ) 73 | /* GNU Compiler 74 | ------------ 75 | RAM functions are defined using a specific toolchain attribute 76 | "__attribute__((section(".RamFunc")))". 77 | */ 78 | #define __RAM_FUNC void __attribute__((section(".RamFunc"))) 79 | 80 | #endif 81 | /* Exported constants --------------------------------------------------------*/ 82 | /* Exported macro ------------------------------------------------------------*/ 83 | /* Exported functions --------------------------------------------------------*/ 84 | __RAM_FUNC FLASH_FlashInterfaceCmd(FunctionalState NewState); 85 | __RAM_FUNC FLASH_FlashSleepModeCmd(FunctionalState NewState); 86 | 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 103 | 104 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/FreeRTOS/include/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/FreeRTOS/portable/Keil/See-also-the-RVDS-directory.txt: -------------------------------------------------------------------------------- 1 | Nothing to see here. -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/FreeRTOS/portable/MemMang/ReadMe.url: -------------------------------------------------------------------------------- 1 | [{000214A0-0000-0000-C000-000000000046}] 2 | Prop3=19,2 3 | [InternetShortcut] 4 | URL=http://www.freertos.org/a00111.html 5 | IDList= 6 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/FreeRTOS/portable/RVDS/ARM_CM7/ReadMe.txt: -------------------------------------------------------------------------------- 1 | There are two options for running FreeRTOS on ARM Cortex-M7 microcontrollers. 2 | The best option depends on the revision of the ARM Cortex-M7 core in use. The 3 | revision is specified by an 'r' number, and a 'p' number, so will look something 4 | like 'r0p1'. Check the documentation for the microcontroller in use to find the 5 | revision of the Cortex-M7 core used in that microcontroller. If in doubt, use 6 | the FreeRTOS port provided specifically for r0p1 revisions, as that can be used 7 | with all core revisions. 8 | 9 | The first option is to use the ARM Cortex-M4F port, and the second option is to 10 | use the Cortex-M7 r0p1 port - the latter containing a minor errata workaround. 11 | 12 | If the revision of the ARM Cortex-M7 core is not r0p1 then either option can be 13 | used, but it is recommended to use the FreeRTOS ARM Cortex-M4F port located in 14 | the /FreeRTOS/Source/portable/RVDS/ARM_CM4F directory. 15 | 16 | If the revision of the ARM Cortex-M7 core is r0p1 then use the FreeRTOS ARM 17 | Cortex-M7 r0p1 port located in the /FreeRTOS/Source/portable/RVDS/ARM_CM7/r0p1 18 | directory. -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/FreeRTOS/portable/readme.txt: -------------------------------------------------------------------------------- 1 | Each real time kernel port consists of three files that contain the core kernel 2 | components and are common to every port, and one or more files that are 3 | specific to a particular microcontroller and/or compiler. 4 | 5 | 6 | + The FreeRTOS/Source/Portable/MemMang directory contains the five sample 7 | memory allocators as described on the http://www.FreeRTOS.org WEB site. 8 | 9 | + The other directories each contain files specific to a particular 10 | microcontroller or compiler, where the directory name denotes the compiler 11 | specific files the directory contains. 12 | 13 | 14 | 15 | For example, if you are interested in the [compiler] port for the [architecture] 16 | microcontroller, then the port specific files are contained in 17 | FreeRTOS/Source/Portable/[compiler]/[architecture] directory. If this is the 18 | only port you are interested in then all the other directories can be 19 | ignored. 20 | 21 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/FreeRTOS/readme.txt: -------------------------------------------------------------------------------- 1 | Each real time kernel port consists of three files that contain the core kernel 2 | components and are common to every port, and one or more files that are 3 | specific to a particular microcontroller and or compiler. 4 | 5 | + The FreeRTOS/Source directory contains the three files that are common to 6 | every port - list.c, queue.c and tasks.c. The kernel is contained within these 7 | three files. croutine.c implements the optional co-routine functionality - which 8 | is normally only used on very memory limited systems. 9 | 10 | + The FreeRTOS/Source/Portable directory contains the files that are specific to 11 | a particular microcontroller and or compiler. 12 | 13 | + The FreeRTOS/Source/include directory contains the real time kernel header 14 | files. 15 | 16 | See the readme file in the FreeRTOS/Source/Portable directory for more 17 | information. -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/README/README.txt: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407工程模板 3 | //File: README.txt 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | 基于STM32F4 固件库V1.4.0的工程模板 10 | 11 | 新建工程的时候,请确保Option for target->C/C++选项卡的全部宏定义Define输入框字符串为:STM32F40_41xxx,USE_STDPERIPH_DRIVER 12 | 13 | Keil Version:5.15 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'Template_FreeRTOS' 7 | * Target: 'Template_FreeRTOS' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | #endif /* RTE_COMPONENTS_H */ 15 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/SYSTEM/delay.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "delay.h" 10 | #include "sys.h" 11 | 12 | static u8 fac_us=0;//us延时倍乘数 13 | static u16 fac_ms=0;//ms延时倍乘数,在ucos下,代表每个节拍的ms数 14 | 15 | //========================================= 16 | //初始化延迟函数 17 | //SYSTICK的时钟固定为HCLK时钟的1/8 18 | //SYSCLK:系统时钟 19 | //========================================= 20 | void delay_init(u8 SYSCLK) 21 | { 22 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); 23 | fac_us=SYSCLK/8; 24 | fac_ms=(u16)fac_us*1000;//代表每个ms需要的systick时钟数 25 | } 26 | 27 | //========================================= 28 | //延时nus 29 | //nus为要延时的us数. 30 | //注意:nus的值,不要大于798915us 31 | //========================================= 32 | void delay_us(u32 nus) 33 | { 34 | u32 temp; 35 | SysTick->LOAD=nus*fac_us; //时间加载 36 | SysTick->VAL=0x00; //清空计数器 37 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;//开始倒数 38 | do 39 | { 40 | temp=SysTick->CTRL; 41 | } 42 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 43 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 44 | SysTick->VAL =0X00; //清空计数器 45 | } 46 | 47 | //========================================= 48 | //延时nms 49 | //注意nms的范围 50 | //SysTick->LOAD为24位寄存器,所以,最大延时为: 51 | //nms<=0xffffff*8*1000/SYSCLK 52 | //SYSCLK单位为Hz,nms单位为ms 53 | //对168M条件下,nms<=798ms 54 | //========================================= 55 | void delay_xms(u16 nms) 56 | { 57 | u32 temp; 58 | SysTick->LOAD=(u32)nms*fac_ms;//时间加载(SysTick->LOAD为24bit) 59 | SysTick->VAL =0x00; //清空计数器 60 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 61 | do 62 | { 63 | temp=SysTick->CTRL; 64 | } 65 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 66 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 67 | SysTick->VAL =0X00; //清空计数器 68 | } 69 | 70 | //========================================= 71 | //延时nms 72 | //nms:0~65535 73 | //========================================= 74 | void delay_ms(u16 nms) 75 | { 76 | u8 repeat=nms/540; //这里用540,是考虑到某些客户可能超频使用, 77 | //比如超频到248M的时候,delay_xms最大只能延时541ms左右了 78 | u16 remain=nms%540; 79 | while(repeat) 80 | { 81 | delay_xms(540); 82 | repeat--; 83 | } 84 | if(remain)delay_xms(remain); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/SYSTEM/delay.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __DELAY_H 10 | #define __DELAY_H 11 | #include 12 | 13 | void delay_init(u8 SYSCLK); 14 | void delay_ms(u16 nms); 15 | void delay_us(u32 nus); 16 | 17 | #endif 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/SYSTEM/key.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "key.h" 10 | #include "delay.h" 11 | 12 | //========================== 13 | //按键初始化函数 14 | //========================== 15 | void KEY_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_KEY0|RCC_AHB1Periph_KEY1|RCC_AHB1Periph_K_UP, ENABLE);//使能GPIOA,GPIOE时钟 20 | 21 | //KEY0 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY0; //KEY0对应引脚 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 24 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 25 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 26 | GPIO_Init(GPIO_KEY0, &GPIO_InitStructure);//初始化GPIOE4,3 27 | 28 | //KEY1 29 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY1; //KEY1对应引脚 30 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 31 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 32 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 33 | GPIO_Init(GPIO_KEY1, &GPIO_InitStructure);//初始化GPIOE4,3 34 | 35 | //K_UP 36 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_K_UP;//K_UP对应引脚PA0 37 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;//下拉 38 | GPIO_Init(GPIO_K_UP, &GPIO_InitStructure);//初始化GPIOA0 39 | } 40 | 41 | //========================================= 42 | //按键处理函数 43 | //返回按键值 44 | //mode:0,不支持连续按;1,支持连续按; 45 | //0,没有任何按键按下 46 | //1,KEY0按下 47 | //2,KEY1按下 48 | //3,K_UP按下 WK_UP 49 | //注意此函数有响应优先级,KEY0>KEY1>WK_UP!! 50 | //========================================= 51 | u8 KEY_Scan(u8 mode) 52 | { 53 | static u8 key_up=1;//按键按松开标志 54 | if(mode)key_up=1; //支持连按 55 | 56 | if(key_up&&(KEY0==0||KEY1==0||K_UP==1)) 57 | { 58 | delay_ms(10);//去抖动 59 | key_up=0; 60 | 61 | if(KEY0==0)return 1; 62 | else if(KEY1==0)return 2; 63 | else if(K_UP==1)return 3; 64 | } 65 | else if(KEY0==1&&KEY1==1&&K_UP==0) 66 | { 67 | key_up=1; 68 | } 69 | 70 | return 0;// 无按键按下 71 | } 72 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/SYSTEM/key.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __KEY_H 10 | #define __KEY_H 11 | #include "sys.h" 12 | 13 | //======================= 14 | //3个板载按键 15 | //E4:(KEY0)按下为低电平 16 | //E3:(KEY1)按下为低电平 17 | //A0:(K_UP)按下为高电平 18 | //======================= 19 | 20 | #define RCC_AHB1Periph_KEY0 RCC_AHB1Periph_GPIOE 21 | #define RCC_AHB1Periph_KEY1 RCC_AHB1Periph_GPIOE 22 | #define RCC_AHB1Periph_K_UP RCC_AHB1Periph_GPIOA 23 | 24 | #define GPIO_KEY0 GPIOE 25 | #define GPIO_KEY1 GPIOE 26 | #define GPIO_K_UP GPIOA 27 | 28 | #define GPIO_Pin_KEY0 GPIO_Pin_4 29 | #define GPIO_Pin_KEY1 GPIO_Pin_3 30 | #define GPIO_Pin_K_UP GPIO_Pin_0 31 | 32 | //通过直接操作库函数方式读取IO 33 | #define KEY0 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY0) //PE4 34 | #define KEY1 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY1) //PE3 35 | #define K_UP GPIO_ReadInputDataBit(GPIO_K_UP,GPIO_Pin_K_UP) //PA0 36 | 37 | #define KEY0_PRES 1 38 | #define KEY1_PRES 2 39 | #define K_UP_PRES 3 40 | 41 | void KEY_Init(void); //IO初始化 42 | u8 KEY_Scan(u8); //按键扫描函数 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/SYSTEM/led.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "led.h" 10 | 11 | //=========================================== 12 | //LED IO初始化 13 | //初始化PA6和PA7为输出口.并使能这两个口的时钟 14 | //=========================================== 15 | void LED_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_LED, ENABLE);//使能GPIOA时钟 20 | 21 | //GPIOA6,A7初始化设置 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_LEDa | GPIO_Pin_LEDb;//LEDa和LEDb对应IO口 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式 24 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 25 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz 26 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 27 | GPIO_Init(GPIO_LED, &GPIO_InitStructure);//初始化GPIO 28 | 29 | GPIO_SetBits(GPIO_LED,GPIO_Pin_LEDa | GPIO_Pin_LEDb);//设置高,灯灭 30 | } 31 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/SYSTEM/led.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Vesion: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __LED_H 10 | #define __LED_H 11 | #include "sys.h" 12 | 13 | //========================= 14 | //板载两个LED,低电平点亮 15 | //A6:D2(重命名为LEDa) 16 | //A7:D3(重命名为LEDb) 17 | //========================= 18 | 19 | //LED端口定义 20 | #define RCC_AHB1Periph_LED RCC_AHB1Periph_GPIOA 21 | #define GPIO_LED GPIOA 22 | 23 | #define GPIO_Pin_LEDa GPIO_Pin_6 24 | #define GPIO_Pin_LEDb GPIO_Pin_7 25 | 26 | #define digitalHigh(p,i) {p->BSRRH=i;} //引脚输出高电平 27 | #define digitalLow(p,i) {p->BSRRL=i;} //引脚输出低电平 28 | #define digitalToggle(p,i) {p->ODR ^=i;} //反转 29 | 30 | #define LEDa_ON digitalLow(GPIO_LED,GPIO_Pin_LEDa) 31 | #define LEDb_ON digitalLow(GPIO_LED,GPIO_Pin_LEDb) 32 | 33 | #define LEDa_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDa) 34 | #define LEDb_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDb) 35 | 36 | #define LEDa_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDa) 37 | #define LEDb_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDb) 38 | 39 | void LED_Init(void);//初始化 40 | #endif 41 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/SYSTEM/sys.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "sys.h" 10 | 11 | //================================== 12 | //系统时钟初始化 13 | //包括时钟设置/中断管理/GPIO设置等 14 | //================================== 15 | 16 | 17 | //THUMB指令不支持汇编内联 18 | //采用如下方法实现执行汇编指令WFI 19 | __asm void WFI_SET(void) 20 | { 21 | WFI; 22 | } 23 | //关闭所有中断(但是不包括fault和NMI中断) 24 | __asm void INTX_DISABLE(void) 25 | { 26 | CPSID I 27 | BX LR 28 | } 29 | //开启所有中断 30 | __asm void INTX_ENABLE(void) 31 | { 32 | CPSIE I 33 | BX LR 34 | } 35 | //设置栈顶地址 36 | //addr:栈顶地址 37 | __asm void MSR_MSP(u32 addr) 38 | { 39 | MSR MSP, r0 //set Main Stack value 40 | BX r14 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/SYSTEM/sys.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __SYS_H 10 | #define __SYS_H 11 | #include "stm32f4xx.h" 12 | 13 | //IO口操作宏定义 14 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 15 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 16 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 17 | 18 | //IO口地址映射 19 | #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014 20 | #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414 21 | #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814 22 | #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14 23 | #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014 24 | #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414 25 | #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814 26 | #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14 27 | #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014 28 | 29 | #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010 30 | #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410 31 | #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810 32 | #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10 33 | #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010 34 | #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410 35 | #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810 36 | #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10 37 | #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010 38 | 39 | //IO口操作,只对单一的IO口! 40 | //确保n的值小于16! 41 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出 42 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 43 | 44 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出 45 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 46 | 47 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出 48 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 49 | 50 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出 51 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 52 | 53 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出 54 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入 55 | 56 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出 57 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入 58 | 59 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出 60 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入 61 | 62 | #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出 63 | #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入 64 | 65 | #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出 66 | #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入 67 | 68 | //汇编函数 69 | void WFI_SET(void); //执行WFI指令 70 | void INTX_DISABLE(void);//关闭所有中断 71 | void INTX_ENABLE(void); //开启所有中断 72 | void MSR_MSP(u32 addr); //设置堆栈地址 73 | #endif 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/SYSTEM/usart.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载串口1配置 3 | //File: usart.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __USART_H 10 | #define __USART_H 11 | #include "stdio.h" 12 | #include "stm32f4xx_conf.h" 13 | #include "sys.h" 14 | 15 | //************************* 16 | //STM32F407 17 | //串口1初始化 18 | //************************* 19 | 20 | #define USART_REC_LEN 200 //定义最大接收字节数 200 21 | #define EN_USART1_RX 1 //使能(1)/禁止(0)串口1接收 22 | 23 | extern u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 24 | extern u16 USART_RX_STA; //接收状态标记 25 | 26 | void uart_init(u32 bound); 27 | #endif 28 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/USER/main.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407+FreeRTOS 创建LED任务 3 | //File: main.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "stm32f4xx.h" 10 | #include "led.h" 11 | 12 | #include "FreeRTOS.h" 13 | #include "task.h" 14 | 15 | //任务参数-------------------------- 16 | //优先级 堆栈大小 任务句柄 任务函数 17 | #define START_TASK_PRIO 1 18 | #define START_STK_SIZE 128 19 | TaskHandle_t StartTask_Handler; 20 | void start_task(void *pvParameters); 21 | 22 | #define TASK1_TASK_PRIO 2 23 | #define TASK1_STK_SIZE 128 24 | TaskHandle_t Task1Task_Handler; 25 | void task1_task(void *pvParameters); 26 | 27 | #define TASK2_TASK_PRIO 3 28 | #define TASK2_STK_SIZE 128 29 | TaskHandle_t Task2Task_Handler; 30 | void task2_task(void *pvParameters); 31 | 32 | 33 | int main(void) 34 | { 35 | //设置系统中断优先级分组4(FreeRTOS中的默认方式!) 36 | NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); 37 | 38 | //初始化LED端口 39 | LED_Init(); 40 | 41 | //创建开始任务 42 | xTaskCreate((TaskFunction_t )start_task, //任务函数 43 | (const char* )"start_task", //任务名称 44 | (uint16_t )START_STK_SIZE, //任务堆栈大小 45 | (void* )NULL, //传递给任务函数的参数 46 | (UBaseType_t )START_TASK_PRIO, //任务优先级 47 | (TaskHandle_t* )&StartTask_Handler); //任务句柄 48 | //开启任务调度 49 | vTaskStartScheduler(); 50 | } 51 | 52 | //开始任务任务函数 53 | void start_task(void *pvParameters) 54 | { 55 | taskENTER_CRITICAL(); //进入临界区 56 | 57 | //创建TASK1任务 58 | xTaskCreate((TaskFunction_t )task1_task, 59 | (const char* )"task1_task", 60 | (uint16_t )TASK1_STK_SIZE, 61 | (void* )NULL, 62 | (UBaseType_t )TASK1_TASK_PRIO, 63 | (TaskHandle_t* )&Task1Task_Handler); 64 | //创建TASK2任务 65 | xTaskCreate((TaskFunction_t )task2_task, 66 | (const char* )"task2_task", 67 | (uint16_t )TASK2_STK_SIZE, 68 | (void* )NULL, 69 | (UBaseType_t )TASK2_TASK_PRIO, 70 | (TaskHandle_t* )&Task2Task_Handler); 71 | 72 | vTaskDelete(StartTask_Handler); //删除开始任务 73 | 74 | taskEXIT_CRITICAL(); //退出临界区 75 | } 76 | 77 | //task1任务函数 78 | void task1_task(void *pvParameters) 79 | { 80 | while(1) 81 | { 82 | LEDa_Toggle; 83 | vTaskDelay(500); //延时500ms 84 | } 85 | } 86 | 87 | //task2任务函数 88 | void task2_task(void *pvParameters) 89 | { 90 | while(1) 91 | { 92 | LEDb_ON; 93 | vTaskDelay(200); //延时200ms 94 | LEDb_OFF; 95 | vTaskDelay(800); //延时800ms 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/USER/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/001_FreeRTOS_LEDtask/USER/stm32f4xx.h -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/USER/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_IT_H 30 | #define __STM32F4xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macro ------------------------------------------------------------*/ 42 | /* Exported functions ------------------------------------------------------- */ 43 | 44 | void NMI_Handler(void); 45 | void HardFault_Handler(void); 46 | void MemManage_Handler(void); 47 | void BusFault_Handler(void); 48 | void UsageFault_Handler(void); 49 | void SVC_Handler(void); 50 | void DebugMon_Handler(void); 51 | void PendSV_Handler(void); 52 | void SysTick_Handler(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __STM32F4xx_IT_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/USER/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /** @addtogroup CMSIS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup stm32f4xx_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32F4XX_H 40 | #define __SYSTEM_STM32F4XX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32F4xx_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32F4xx_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F4xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F4xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F4xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F4XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /001_FreeRTOS_LEDtask/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/001_FreeRTOS_LEDtask/keilkilll.bat -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 项目结构 2 | 3 | ## 库与工程模板 4 | 5 | - **Template_lib** : STM32F407的库文件(v1.4.0)+FreeRTOS库文件(v9.0.0) 6 | - **Template_noOS** : 基于Keil5.15的STM32F407模板工程(不包含操作系统) 7 | - **Template_TreeRTOS** : 基于Keil5.15的STM32F407+FreeRTOS的模板工程 8 | 9 | ## 测试例程 10 | 11 | - **001_FreeRTOS_LEDtask** : 任务创建实验,创建两个LED闪烁任务(**独立的工程**) 12 | - **examples** : 所有的例程,为减少存储空间,此文件的所有例程**共用相同的库文件** 13 | - **commonlib** : 共用的库文件 14 | - **001_FreeRTOS_LEDtask** : 任务创建实验,创建两个LED闪烁任务 15 | 16 | # FreeRTOS文件结构 17 | 18 | ![](https://github.com/xxpcb/FreeRTOS-STM32F407-examples/blob/master/pic/FreeRTOSv9.png) 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Template_FreeRTOS/FWLIB/inc/stm32f4xx_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_crc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_CRC_H 31 | #define __STM32F4xx_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup CRC_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | 62 | void CRC_ResetDR(void); 63 | uint32_t CRC_CalcCRC(uint32_t Data); 64 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 65 | uint32_t CRC_GetCRC(void); 66 | void CRC_SetIDRegister(uint8_t IDValue); 67 | uint8_t CRC_GetIDRegister(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __STM32F4xx_CRC_H */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /Template_FreeRTOS/FWLIB/inc/stm32f4xx_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief Header file of FLASH RAMFUNC driver. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 31 | #define __STM32F4xx_FLASH_RAMFUNC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup FLASH RAMFUNC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Private define ------------------------------------------------------------*/ 50 | /** 51 | * @brief __RAM_FUNC definition 52 | */ 53 | #if defined ( __CC_ARM ) 54 | /* ARM Compiler 55 | ------------ 56 | RAM functions are defined using the toolchain options. 57 | Functions that are executed in RAM should reside in a separate source module. 58 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 59 | area of a module to a memory space in physical RAM. 60 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 61 | dialog. 62 | */ 63 | #define __RAM_FUNC void 64 | 65 | #elif defined ( __ICCARM__ ) 66 | /* ICCARM Compiler 67 | --------------- 68 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 69 | */ 70 | #define __RAM_FUNC __ramfunc void 71 | 72 | #elif defined ( __GNUC__ ) 73 | /* GNU Compiler 74 | ------------ 75 | RAM functions are defined using a specific toolchain attribute 76 | "__attribute__((section(".RamFunc")))". 77 | */ 78 | #define __RAM_FUNC void __attribute__((section(".RamFunc"))) 79 | 80 | #endif 81 | /* Exported constants --------------------------------------------------------*/ 82 | /* Exported macro ------------------------------------------------------------*/ 83 | /* Exported functions --------------------------------------------------------*/ 84 | __RAM_FUNC FLASH_FlashInterfaceCmd(FunctionalState NewState); 85 | __RAM_FUNC FLASH_FlashSleepModeCmd(FunctionalState NewState); 86 | 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 103 | 104 | -------------------------------------------------------------------------------- /Template_FreeRTOS/FWLIB/inc/stm32f4xx_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_wwdg.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_WWDG_H 31 | #define __STM32F4xx_WWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup WWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup WWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup WWDG_Prescaler 56 | * @{ 57 | */ 58 | 59 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 60 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 61 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 62 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 63 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 64 | ((PRESCALER) == WWDG_Prescaler_2) || \ 65 | ((PRESCALER) == WWDG_Prescaler_4) || \ 66 | ((PRESCALER) == WWDG_Prescaler_8)) 67 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 68 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /* Exported macro ------------------------------------------------------------*/ 79 | /* Exported functions --------------------------------------------------------*/ 80 | 81 | /* Function used to set the WWDG configuration to the default reset state ****/ 82 | void WWDG_DeInit(void); 83 | 84 | /* Prescaler, Refresh window and Counter configuration functions **************/ 85 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 86 | void WWDG_SetWindowValue(uint8_t WindowValue); 87 | void WWDG_EnableIT(void); 88 | void WWDG_SetCounter(uint8_t Counter); 89 | 90 | /* WWDG activation function ***************************************************/ 91 | void WWDG_Enable(uint8_t Counter); 92 | 93 | /* Interrupts and flags management functions **********************************/ 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F4xx_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 112 | -------------------------------------------------------------------------------- /Template_FreeRTOS/FreeRTOS/include/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /Template_FreeRTOS/FreeRTOS/portable/Keil/See-also-the-RVDS-directory.txt: -------------------------------------------------------------------------------- 1 | Nothing to see here. -------------------------------------------------------------------------------- /Template_FreeRTOS/FreeRTOS/portable/MemMang/ReadMe.url: -------------------------------------------------------------------------------- 1 | [{000214A0-0000-0000-C000-000000000046}] 2 | Prop3=19,2 3 | [InternetShortcut] 4 | URL=http://www.freertos.org/a00111.html 5 | IDList= 6 | -------------------------------------------------------------------------------- /Template_FreeRTOS/FreeRTOS/portable/RVDS/ARM_CM7/ReadMe.txt: -------------------------------------------------------------------------------- 1 | There are two options for running FreeRTOS on ARM Cortex-M7 microcontrollers. 2 | The best option depends on the revision of the ARM Cortex-M7 core in use. The 3 | revision is specified by an 'r' number, and a 'p' number, so will look something 4 | like 'r0p1'. Check the documentation for the microcontroller in use to find the 5 | revision of the Cortex-M7 core used in that microcontroller. If in doubt, use 6 | the FreeRTOS port provided specifically for r0p1 revisions, as that can be used 7 | with all core revisions. 8 | 9 | The first option is to use the ARM Cortex-M4F port, and the second option is to 10 | use the Cortex-M7 r0p1 port - the latter containing a minor errata workaround. 11 | 12 | If the revision of the ARM Cortex-M7 core is not r0p1 then either option can be 13 | used, but it is recommended to use the FreeRTOS ARM Cortex-M4F port located in 14 | the /FreeRTOS/Source/portable/RVDS/ARM_CM4F directory. 15 | 16 | If the revision of the ARM Cortex-M7 core is r0p1 then use the FreeRTOS ARM 17 | Cortex-M7 r0p1 port located in the /FreeRTOS/Source/portable/RVDS/ARM_CM7/r0p1 18 | directory. -------------------------------------------------------------------------------- /Template_FreeRTOS/FreeRTOS/portable/readme.txt: -------------------------------------------------------------------------------- 1 | Each real time kernel port consists of three files that contain the core kernel 2 | components and are common to every port, and one or more files that are 3 | specific to a particular microcontroller and/or compiler. 4 | 5 | 6 | + The FreeRTOS/Source/Portable/MemMang directory contains the five sample 7 | memory allocators as described on the http://www.FreeRTOS.org WEB site. 8 | 9 | + The other directories each contain files specific to a particular 10 | microcontroller or compiler, where the directory name denotes the compiler 11 | specific files the directory contains. 12 | 13 | 14 | 15 | For example, if you are interested in the [compiler] port for the [architecture] 16 | microcontroller, then the port specific files are contained in 17 | FreeRTOS/Source/Portable/[compiler]/[architecture] directory. If this is the 18 | only port you are interested in then all the other directories can be 19 | ignored. 20 | 21 | -------------------------------------------------------------------------------- /Template_FreeRTOS/FreeRTOS/readme.txt: -------------------------------------------------------------------------------- 1 | Each real time kernel port consists of three files that contain the core kernel 2 | components and are common to every port, and one or more files that are 3 | specific to a particular microcontroller and or compiler. 4 | 5 | + The FreeRTOS/Source directory contains the three files that are common to 6 | every port - list.c, queue.c and tasks.c. The kernel is contained within these 7 | three files. croutine.c implements the optional co-routine functionality - which 8 | is normally only used on very memory limited systems. 9 | 10 | + The FreeRTOS/Source/Portable directory contains the files that are specific to 11 | a particular microcontroller and or compiler. 12 | 13 | + The FreeRTOS/Source/include directory contains the real time kernel header 14 | files. 15 | 16 | See the readme file in the FreeRTOS/Source/Portable directory for more 17 | information. -------------------------------------------------------------------------------- /Template_FreeRTOS/README/README.txt: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407工程模板 3 | //File: README.txt 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | 基于STM32F4 固件库V1.4.0的工程模板 10 | 11 | 新建工程的时候,请确保Option for target->C/C++选项卡的全部宏定义Define输入框字符串为:STM32F40_41xxx,USE_STDPERIPH_DRIVER 12 | 13 | Keil Version:5.15 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Template_FreeRTOS/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'Template_FreeRTOS' 7 | * Target: 'Template_FreeRTOS' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | #endif /* RTE_COMPONENTS_H */ 15 | -------------------------------------------------------------------------------- /Template_FreeRTOS/SYSTEM/delay.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "delay.h" 10 | #include "sys.h" 11 | 12 | static u8 fac_us=0;//us延时倍乘数 13 | static u16 fac_ms=0;//ms延时倍乘数,在ucos下,代表每个节拍的ms数 14 | 15 | //========================================= 16 | //初始化延迟函数 17 | //SYSTICK的时钟固定为HCLK时钟的1/8 18 | //SYSCLK:系统时钟 19 | //========================================= 20 | void delay_init(u8 SYSCLK) 21 | { 22 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); 23 | fac_us=SYSCLK/8; 24 | fac_ms=(u16)fac_us*1000;//代表每个ms需要的systick时钟数 25 | } 26 | 27 | //========================================= 28 | //延时nus 29 | //nus为要延时的us数. 30 | //注意:nus的值,不要大于798915us 31 | //========================================= 32 | void delay_us(u32 nus) 33 | { 34 | u32 temp; 35 | SysTick->LOAD=nus*fac_us; //时间加载 36 | SysTick->VAL=0x00; //清空计数器 37 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;//开始倒数 38 | do 39 | { 40 | temp=SysTick->CTRL; 41 | } 42 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 43 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 44 | SysTick->VAL =0X00; //清空计数器 45 | } 46 | 47 | //========================================= 48 | //延时nms 49 | //注意nms的范围 50 | //SysTick->LOAD为24位寄存器,所以,最大延时为: 51 | //nms<=0xffffff*8*1000/SYSCLK 52 | //SYSCLK单位为Hz,nms单位为ms 53 | //对168M条件下,nms<=798ms 54 | //========================================= 55 | void delay_xms(u16 nms) 56 | { 57 | u32 temp; 58 | SysTick->LOAD=(u32)nms*fac_ms;//时间加载(SysTick->LOAD为24bit) 59 | SysTick->VAL =0x00; //清空计数器 60 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 61 | do 62 | { 63 | temp=SysTick->CTRL; 64 | } 65 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 66 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 67 | SysTick->VAL =0X00; //清空计数器 68 | } 69 | 70 | //========================================= 71 | //延时nms 72 | //nms:0~65535 73 | //========================================= 74 | void delay_ms(u16 nms) 75 | { 76 | u8 repeat=nms/540; //这里用540,是考虑到某些客户可能超频使用, 77 | //比如超频到248M的时候,delay_xms最大只能延时541ms左右了 78 | u16 remain=nms%540; 79 | while(repeat) 80 | { 81 | delay_xms(540); 82 | repeat--; 83 | } 84 | if(remain)delay_xms(remain); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /Template_FreeRTOS/SYSTEM/delay.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __DELAY_H 10 | #define __DELAY_H 11 | #include 12 | 13 | void delay_init(u8 SYSCLK); 14 | void delay_ms(u16 nms); 15 | void delay_us(u32 nus); 16 | 17 | #endif 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Template_FreeRTOS/SYSTEM/key.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "key.h" 10 | #include "delay.h" 11 | 12 | //========================== 13 | //按键初始化函数 14 | //========================== 15 | void KEY_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_KEY0|RCC_AHB1Periph_KEY1|RCC_AHB1Periph_K_UP, ENABLE);//使能GPIOA,GPIOE时钟 20 | 21 | //KEY0 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY0; //KEY0对应引脚 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 24 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 25 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 26 | GPIO_Init(GPIO_KEY0, &GPIO_InitStructure);//初始化GPIOE4,3 27 | 28 | //KEY1 29 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY1; //KEY1对应引脚 30 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 31 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 32 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 33 | GPIO_Init(GPIO_KEY1, &GPIO_InitStructure);//初始化GPIOE4,3 34 | 35 | //K_UP 36 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_K_UP;//K_UP对应引脚PA0 37 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;//下拉 38 | GPIO_Init(GPIO_K_UP, &GPIO_InitStructure);//初始化GPIOA0 39 | } 40 | 41 | //========================================= 42 | //按键处理函数 43 | //返回按键值 44 | //mode:0,不支持连续按;1,支持连续按; 45 | //0,没有任何按键按下 46 | //1,KEY0按下 47 | //2,KEY1按下 48 | //3,K_UP按下 WK_UP 49 | //注意此函数有响应优先级,KEY0>KEY1>WK_UP!! 50 | //========================================= 51 | u8 KEY_Scan(u8 mode) 52 | { 53 | static u8 key_up=1;//按键按松开标志 54 | if(mode)key_up=1; //支持连按 55 | 56 | if(key_up&&(KEY0==0||KEY1==0||K_UP==1)) 57 | { 58 | delay_ms(10);//去抖动 59 | key_up=0; 60 | 61 | if(KEY0==0)return 1; 62 | else if(KEY1==0)return 2; 63 | else if(K_UP==1)return 3; 64 | } 65 | else if(KEY0==1&&KEY1==1&&K_UP==0) 66 | { 67 | key_up=1; 68 | } 69 | 70 | return 0;// 无按键按下 71 | } 72 | -------------------------------------------------------------------------------- /Template_FreeRTOS/SYSTEM/key.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __KEY_H 10 | #define __KEY_H 11 | #include "sys.h" 12 | 13 | //======================= 14 | //3个板载按键 15 | //E4:(KEY0)按下为低电平 16 | //E3:(KEY1)按下为低电平 17 | //A0:(K_UP)按下为高电平 18 | //======================= 19 | 20 | #define RCC_AHB1Periph_KEY0 RCC_AHB1Periph_GPIOE 21 | #define RCC_AHB1Periph_KEY1 RCC_AHB1Periph_GPIOE 22 | #define RCC_AHB1Periph_K_UP RCC_AHB1Periph_GPIOA 23 | 24 | #define GPIO_KEY0 GPIOE 25 | #define GPIO_KEY1 GPIOE 26 | #define GPIO_K_UP GPIOA 27 | 28 | #define GPIO_Pin_KEY0 GPIO_Pin_4 29 | #define GPIO_Pin_KEY1 GPIO_Pin_3 30 | #define GPIO_Pin_K_UP GPIO_Pin_0 31 | 32 | //通过直接操作库函数方式读取IO 33 | #define KEY0 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY0) //PE4 34 | #define KEY1 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY1) //PE3 35 | #define K_UP GPIO_ReadInputDataBit(GPIO_K_UP,GPIO_Pin_K_UP) //PA0 36 | 37 | #define KEY0_PRES 1 38 | #define KEY1_PRES 2 39 | #define K_UP_PRES 3 40 | 41 | void KEY_Init(void); //IO初始化 42 | u8 KEY_Scan(u8); //按键扫描函数 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Template_FreeRTOS/SYSTEM/led.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "led.h" 10 | 11 | //=========================================== 12 | //LED IO初始化 13 | //初始化PA6和PA7为输出口.并使能这两个口的时钟 14 | //=========================================== 15 | void LED_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_LED, ENABLE);//使能GPIOA时钟 20 | 21 | //GPIOA6,A7初始化设置 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_LEDa | GPIO_Pin_LEDb;//LEDa和LEDb对应IO口 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式 24 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 25 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz 26 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 27 | GPIO_Init(GPIO_LED, &GPIO_InitStructure);//初始化GPIO 28 | 29 | GPIO_SetBits(GPIO_LED,GPIO_Pin_LEDa | GPIO_Pin_LEDb);//设置高,灯灭 30 | } 31 | -------------------------------------------------------------------------------- /Template_FreeRTOS/SYSTEM/led.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Vesion: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __LED_H 10 | #define __LED_H 11 | #include "sys.h" 12 | 13 | //========================= 14 | //板载两个LED,低电平点亮 15 | //A6:D2(重命名为LEDa) 16 | //A7:D3(重命名为LEDb) 17 | //========================= 18 | 19 | //LED端口定义 20 | #define RCC_AHB1Periph_LED RCC_AHB1Periph_GPIOA 21 | #define GPIO_LED GPIOA 22 | 23 | #define GPIO_Pin_LEDa GPIO_Pin_6 24 | #define GPIO_Pin_LEDb GPIO_Pin_7 25 | 26 | #define digitalHigh(p,i) {p->BSRRH=i;} //引脚输出高电平 27 | #define digitalLow(p,i) {p->BSRRL=i;} //引脚输出低电平 28 | #define digitalToggle(p,i) {p->ODR ^=i;} //反转 29 | 30 | #define LEDa_ON digitalLow(GPIO_LED,GPIO_Pin_LEDa) 31 | #define LEDb_ON digitalLow(GPIO_LED,GPIO_Pin_LEDb) 32 | 33 | #define LEDa_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDa) 34 | #define LEDb_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDb) 35 | 36 | #define LEDa_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDa) 37 | #define LEDb_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDb) 38 | 39 | void LED_Init(void);//初始化 40 | #endif 41 | -------------------------------------------------------------------------------- /Template_FreeRTOS/SYSTEM/sys.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "sys.h" 10 | 11 | //================================== 12 | //系统时钟初始化 13 | //包括时钟设置/中断管理/GPIO设置等 14 | //================================== 15 | 16 | 17 | //THUMB指令不支持汇编内联 18 | //采用如下方法实现执行汇编指令WFI 19 | __asm void WFI_SET(void) 20 | { 21 | WFI; 22 | } 23 | //关闭所有中断(但是不包括fault和NMI中断) 24 | __asm void INTX_DISABLE(void) 25 | { 26 | CPSID I 27 | BX LR 28 | } 29 | //开启所有中断 30 | __asm void INTX_ENABLE(void) 31 | { 32 | CPSIE I 33 | BX LR 34 | } 35 | //设置栈顶地址 36 | //addr:栈顶地址 37 | __asm void MSR_MSP(u32 addr) 38 | { 39 | MSR MSP, r0 //set Main Stack value 40 | BX r14 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /Template_FreeRTOS/SYSTEM/sys.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __SYS_H 10 | #define __SYS_H 11 | #include "stm32f4xx.h" 12 | 13 | //IO口操作宏定义 14 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 15 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 16 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 17 | 18 | //IO口地址映射 19 | #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014 20 | #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414 21 | #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814 22 | #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14 23 | #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014 24 | #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414 25 | #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814 26 | #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14 27 | #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014 28 | 29 | #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010 30 | #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410 31 | #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810 32 | #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10 33 | #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010 34 | #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410 35 | #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810 36 | #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10 37 | #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010 38 | 39 | //IO口操作,只对单一的IO口! 40 | //确保n的值小于16! 41 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出 42 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 43 | 44 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出 45 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 46 | 47 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出 48 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 49 | 50 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出 51 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 52 | 53 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出 54 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入 55 | 56 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出 57 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入 58 | 59 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出 60 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入 61 | 62 | #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出 63 | #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入 64 | 65 | #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出 66 | #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入 67 | 68 | //汇编函数 69 | void WFI_SET(void); //执行WFI指令 70 | void INTX_DISABLE(void);//关闭所有中断 71 | void INTX_ENABLE(void); //开启所有中断 72 | void MSR_MSP(u32 addr); //设置堆栈地址 73 | #endif 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /Template_FreeRTOS/SYSTEM/usart.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载串口1配置 3 | //File: usart.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __USART_H 10 | #define __USART_H 11 | #include "stdio.h" 12 | #include "stm32f4xx_conf.h" 13 | #include "sys.h" 14 | 15 | //************************* 16 | //STM32F407 17 | //串口1初始化 18 | //************************* 19 | 20 | #define USART_REC_LEN 200 //定义最大接收字节数 200 21 | #define EN_USART1_RX 1 //使能(1)/禁止(0)串口1接收 22 | 23 | extern u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 24 | extern u16 USART_RX_STA; //接收状态标记 25 | 26 | void uart_init(u32 bound); 27 | #endif 28 | -------------------------------------------------------------------------------- /Template_FreeRTOS/USER/main.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407+FreeRTOS工程模板 3 | //File: main.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "stm32f4xx.h" 10 | #include "led.h" 11 | #include "delay.h" 12 | 13 | int main(void) 14 | { 15 | LED_Init(); 16 | delay_init(84); 17 | 18 | while(1) 19 | { 20 | //LEDa亮500ms,灭500ms 21 | LEDa_ON; 22 | delay_ms(500); 23 | LEDa_OFF; 24 | delay_ms(500); 25 | 26 | //LEDb每隔1000ms翻转一次 27 | LEDb_Toggle; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Template_FreeRTOS/USER/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/Template_FreeRTOS/USER/stm32f4xx.h -------------------------------------------------------------------------------- /Template_FreeRTOS/USER/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_IT_H 30 | #define __STM32F4xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macro ------------------------------------------------------------*/ 42 | /* Exported functions ------------------------------------------------------- */ 43 | 44 | void NMI_Handler(void); 45 | void HardFault_Handler(void); 46 | void MemManage_Handler(void); 47 | void BusFault_Handler(void); 48 | void UsageFault_Handler(void); 49 | void SVC_Handler(void); 50 | void DebugMon_Handler(void); 51 | void PendSV_Handler(void); 52 | void SysTick_Handler(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __STM32F4xx_IT_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /Template_FreeRTOS/USER/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /** @addtogroup CMSIS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup stm32f4xx_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32F4XX_H 40 | #define __SYSTEM_STM32F4XX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32F4xx_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32F4xx_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F4xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F4xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F4xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F4XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /Template_FreeRTOS/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/Template_FreeRTOS/keilkilll.bat -------------------------------------------------------------------------------- /Template_lib/FWLIB/inc/stm32f4xx_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_crc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_CRC_H 31 | #define __STM32F4xx_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup CRC_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | 62 | void CRC_ResetDR(void); 63 | uint32_t CRC_CalcCRC(uint32_t Data); 64 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 65 | uint32_t CRC_GetCRC(void); 66 | void CRC_SetIDRegister(uint8_t IDValue); 67 | uint8_t CRC_GetIDRegister(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __STM32F4xx_CRC_H */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /Template_lib/FWLIB/inc/stm32f4xx_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief Header file of FLASH RAMFUNC driver. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 31 | #define __STM32F4xx_FLASH_RAMFUNC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup FLASH RAMFUNC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Private define ------------------------------------------------------------*/ 50 | /** 51 | * @brief __RAM_FUNC definition 52 | */ 53 | #if defined ( __CC_ARM ) 54 | /* ARM Compiler 55 | ------------ 56 | RAM functions are defined using the toolchain options. 57 | Functions that are executed in RAM should reside in a separate source module. 58 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 59 | area of a module to a memory space in physical RAM. 60 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 61 | dialog. 62 | */ 63 | #define __RAM_FUNC void 64 | 65 | #elif defined ( __ICCARM__ ) 66 | /* ICCARM Compiler 67 | --------------- 68 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 69 | */ 70 | #define __RAM_FUNC __ramfunc void 71 | 72 | #elif defined ( __GNUC__ ) 73 | /* GNU Compiler 74 | ------------ 75 | RAM functions are defined using a specific toolchain attribute 76 | "__attribute__((section(".RamFunc")))". 77 | */ 78 | #define __RAM_FUNC void __attribute__((section(".RamFunc"))) 79 | 80 | #endif 81 | /* Exported constants --------------------------------------------------------*/ 82 | /* Exported macro ------------------------------------------------------------*/ 83 | /* Exported functions --------------------------------------------------------*/ 84 | __RAM_FUNC FLASH_FlashInterfaceCmd(FunctionalState NewState); 85 | __RAM_FUNC FLASH_FlashSleepModeCmd(FunctionalState NewState); 86 | 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 103 | 104 | -------------------------------------------------------------------------------- /Template_lib/FWLIB/inc/stm32f4xx_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_wwdg.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_WWDG_H 31 | #define __STM32F4xx_WWDG_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup WWDG 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup WWDG_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** @defgroup WWDG_Prescaler 56 | * @{ 57 | */ 58 | 59 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 60 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 61 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 62 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 63 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 64 | ((PRESCALER) == WWDG_Prescaler_2) || \ 65 | ((PRESCALER) == WWDG_Prescaler_4) || \ 66 | ((PRESCALER) == WWDG_Prescaler_8)) 67 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 68 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /* Exported macro ------------------------------------------------------------*/ 79 | /* Exported functions --------------------------------------------------------*/ 80 | 81 | /* Function used to set the WWDG configuration to the default reset state ****/ 82 | void WWDG_DeInit(void); 83 | 84 | /* Prescaler, Refresh window and Counter configuration functions **************/ 85 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 86 | void WWDG_SetWindowValue(uint8_t WindowValue); 87 | void WWDG_EnableIT(void); 88 | void WWDG_SetCounter(uint8_t Counter); 89 | 90 | /* WWDG activation function ***************************************************/ 91 | void WWDG_Enable(uint8_t Counter); 92 | 93 | /* Interrupts and flags management functions **********************************/ 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F4xx_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 112 | -------------------------------------------------------------------------------- /Template_lib/FreeRTOS/include/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /Template_lib/FreeRTOS/portable/Keil/See-also-the-RVDS-directory.txt: -------------------------------------------------------------------------------- 1 | Nothing to see here. -------------------------------------------------------------------------------- /Template_lib/FreeRTOS/portable/MemMang/ReadMe.url: -------------------------------------------------------------------------------- 1 | [{000214A0-0000-0000-C000-000000000046}] 2 | Prop3=19,2 3 | [InternetShortcut] 4 | URL=http://www.freertos.org/a00111.html 5 | IDList= 6 | -------------------------------------------------------------------------------- /Template_lib/FreeRTOS/portable/RVDS/ARM_CM7/ReadMe.txt: -------------------------------------------------------------------------------- 1 | There are two options for running FreeRTOS on ARM Cortex-M7 microcontrollers. 2 | The best option depends on the revision of the ARM Cortex-M7 core in use. The 3 | revision is specified by an 'r' number, and a 'p' number, so will look something 4 | like 'r0p1'. Check the documentation for the microcontroller in use to find the 5 | revision of the Cortex-M7 core used in that microcontroller. If in doubt, use 6 | the FreeRTOS port provided specifically for r0p1 revisions, as that can be used 7 | with all core revisions. 8 | 9 | The first option is to use the ARM Cortex-M4F port, and the second option is to 10 | use the Cortex-M7 r0p1 port - the latter containing a minor errata workaround. 11 | 12 | If the revision of the ARM Cortex-M7 core is not r0p1 then either option can be 13 | used, but it is recommended to use the FreeRTOS ARM Cortex-M4F port located in 14 | the /FreeRTOS/Source/portable/RVDS/ARM_CM4F directory. 15 | 16 | If the revision of the ARM Cortex-M7 core is r0p1 then use the FreeRTOS ARM 17 | Cortex-M7 r0p1 port located in the /FreeRTOS/Source/portable/RVDS/ARM_CM7/r0p1 18 | directory. -------------------------------------------------------------------------------- /Template_lib/FreeRTOS/portable/readme.txt: -------------------------------------------------------------------------------- 1 | Each real time kernel port consists of three files that contain the core kernel 2 | components and are common to every port, and one or more files that are 3 | specific to a particular microcontroller and/or compiler. 4 | 5 | 6 | + The FreeRTOS/Source/Portable/MemMang directory contains the five sample 7 | memory allocators as described on the http://www.FreeRTOS.org WEB site. 8 | 9 | + The other directories each contain files specific to a particular 10 | microcontroller or compiler, where the directory name denotes the compiler 11 | specific files the directory contains. 12 | 13 | 14 | 15 | For example, if you are interested in the [compiler] port for the [architecture] 16 | microcontroller, then the port specific files are contained in 17 | FreeRTOS/Source/Portable/[compiler]/[architecture] directory. If this is the 18 | only port you are interested in then all the other directories can be 19 | ignored. 20 | 21 | -------------------------------------------------------------------------------- /Template_lib/FreeRTOS/readme.txt: -------------------------------------------------------------------------------- 1 | Each real time kernel port consists of three files that contain the core kernel 2 | components and are common to every port, and one or more files that are 3 | specific to a particular microcontroller and or compiler. 4 | 5 | + The FreeRTOS/Source directory contains the three files that are common to 6 | every port - list.c, queue.c and tasks.c. The kernel is contained within these 7 | three files. croutine.c implements the optional co-routine functionality - which 8 | is normally only used on very memory limited systems. 9 | 10 | + The FreeRTOS/Source/Portable directory contains the files that are specific to 11 | a particular microcontroller and or compiler. 12 | 13 | + The FreeRTOS/Source/include directory contains the real time kernel header 14 | files. 15 | 16 | See the readme file in the FreeRTOS/Source/Portable directory for more 17 | information. -------------------------------------------------------------------------------- /Template_lib/README/README.txt: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407工程模板 3 | //File: README.txt 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | 基于STM32F4 固件库V1.4.0的工程模板 10 | 11 | 新建工程的时候,请确保Option for target->C/C++选项卡的全部宏定义Define输入框字符串为:STM32F40_41xxx,USE_STDPERIPH_DRIVER 12 | 13 | Keil Version:5.15 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Template_lib/SYSTEM/delay.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "delay.h" 10 | #include "sys.h" 11 | 12 | static u8 fac_us=0;//us延时倍乘数 13 | static u16 fac_ms=0;//ms延时倍乘数,在ucos下,代表每个节拍的ms数 14 | 15 | //========================================= 16 | //初始化延迟函数 17 | //SYSTICK的时钟固定为HCLK时钟的1/8 18 | //SYSCLK:系统时钟 19 | //========================================= 20 | void delay_init(u8 SYSCLK) 21 | { 22 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); 23 | fac_us=SYSCLK/8; 24 | fac_ms=(u16)fac_us*1000;//代表每个ms需要的systick时钟数 25 | } 26 | 27 | //========================================= 28 | //延时nus 29 | //nus为要延时的us数. 30 | //注意:nus的值,不要大于798915us 31 | //========================================= 32 | void delay_us(u32 nus) 33 | { 34 | u32 temp; 35 | SysTick->LOAD=nus*fac_us; //时间加载 36 | SysTick->VAL=0x00; //清空计数器 37 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;//开始倒数 38 | do 39 | { 40 | temp=SysTick->CTRL; 41 | } 42 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 43 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 44 | SysTick->VAL =0X00; //清空计数器 45 | } 46 | 47 | //========================================= 48 | //延时nms 49 | //注意nms的范围 50 | //SysTick->LOAD为24位寄存器,所以,最大延时为: 51 | //nms<=0xffffff*8*1000/SYSCLK 52 | //SYSCLK单位为Hz,nms单位为ms 53 | //对168M条件下,nms<=798ms 54 | //========================================= 55 | void delay_xms(u16 nms) 56 | { 57 | u32 temp; 58 | SysTick->LOAD=(u32)nms*fac_ms;//时间加载(SysTick->LOAD为24bit) 59 | SysTick->VAL =0x00; //清空计数器 60 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 61 | do 62 | { 63 | temp=SysTick->CTRL; 64 | } 65 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 66 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 67 | SysTick->VAL =0X00; //清空计数器 68 | } 69 | 70 | //========================================= 71 | //延时nms 72 | //nms:0~65535 73 | //========================================= 74 | void delay_ms(u16 nms) 75 | { 76 | u8 repeat=nms/540; //这里用540,是考虑到某些客户可能超频使用, 77 | //比如超频到248M的时候,delay_xms最大只能延时541ms左右了 78 | u16 remain=nms%540; 79 | while(repeat) 80 | { 81 | delay_xms(540); 82 | repeat--; 83 | } 84 | if(remain)delay_xms(remain); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /Template_lib/SYSTEM/delay.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __DELAY_H 10 | #define __DELAY_H 11 | #include 12 | 13 | void delay_init(u8 SYSCLK); 14 | void delay_ms(u16 nms); 15 | void delay_us(u32 nus); 16 | 17 | #endif 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Template_lib/SYSTEM/key.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "key.h" 10 | #include "delay.h" 11 | 12 | //========================== 13 | //按键初始化函数 14 | //========================== 15 | void KEY_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_KEY0|RCC_AHB1Periph_KEY1|RCC_AHB1Periph_K_UP, ENABLE);//使能GPIOA,GPIOE时钟 20 | 21 | //KEY0 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY0; //KEY0对应引脚 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 24 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 25 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 26 | GPIO_Init(GPIO_KEY0, &GPIO_InitStructure);//初始化GPIOE4,3 27 | 28 | //KEY1 29 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY1; //KEY1对应引脚 30 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 31 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 32 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 33 | GPIO_Init(GPIO_KEY1, &GPIO_InitStructure);//初始化GPIOE4,3 34 | 35 | //K_UP 36 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_K_UP;//K_UP对应引脚PA0 37 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;//下拉 38 | GPIO_Init(GPIO_K_UP, &GPIO_InitStructure);//初始化GPIOA0 39 | } 40 | 41 | //========================================= 42 | //按键处理函数 43 | //返回按键值 44 | //mode:0,不支持连续按;1,支持连续按; 45 | //0,没有任何按键按下 46 | //1,KEY0按下 47 | //2,KEY1按下 48 | //3,K_UP按下 WK_UP 49 | //注意此函数有响应优先级,KEY0>KEY1>WK_UP!! 50 | //========================================= 51 | u8 KEY_Scan(u8 mode) 52 | { 53 | static u8 key_up=1;//按键按松开标志 54 | if(mode)key_up=1; //支持连按 55 | 56 | if(key_up&&(KEY0==0||KEY1==0||K_UP==1)) 57 | { 58 | delay_ms(10);//去抖动 59 | key_up=0; 60 | 61 | if(KEY0==0)return 1; 62 | else if(KEY1==0)return 2; 63 | else if(K_UP==1)return 3; 64 | } 65 | else if(KEY0==1&&KEY1==1&&K_UP==0) 66 | { 67 | key_up=1; 68 | } 69 | 70 | return 0;// 无按键按下 71 | } 72 | -------------------------------------------------------------------------------- /Template_lib/SYSTEM/key.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __KEY_H 10 | #define __KEY_H 11 | #include "sys.h" 12 | 13 | //======================= 14 | //3个板载按键 15 | //E4:(KEY0)按下为低电平 16 | //E3:(KEY1)按下为低电平 17 | //A0:(K_UP)按下为高电平 18 | //======================= 19 | 20 | #define RCC_AHB1Periph_KEY0 RCC_AHB1Periph_GPIOE 21 | #define RCC_AHB1Periph_KEY1 RCC_AHB1Periph_GPIOE 22 | #define RCC_AHB1Periph_K_UP RCC_AHB1Periph_GPIOA 23 | 24 | #define GPIO_KEY0 GPIOE 25 | #define GPIO_KEY1 GPIOE 26 | #define GPIO_K_UP GPIOA 27 | 28 | #define GPIO_Pin_KEY0 GPIO_Pin_4 29 | #define GPIO_Pin_KEY1 GPIO_Pin_3 30 | #define GPIO_Pin_K_UP GPIO_Pin_0 31 | 32 | //通过直接操作库函数方式读取IO 33 | #define KEY0 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY0) //PE4 34 | #define KEY1 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY1) //PE3 35 | #define K_UP GPIO_ReadInputDataBit(GPIO_K_UP,GPIO_Pin_K_UP) //PA0 36 | 37 | #define KEY0_PRES 1 38 | #define KEY1_PRES 2 39 | #define K_UP_PRES 3 40 | 41 | void KEY_Init(void); //IO初始化 42 | u8 KEY_Scan(u8); //按键扫描函数 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Template_lib/SYSTEM/led.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "led.h" 10 | 11 | //=========================================== 12 | //LED IO初始化 13 | //初始化PA6和PA7为输出口.并使能这两个口的时钟 14 | //=========================================== 15 | void LED_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_LED, ENABLE);//使能GPIOA时钟 20 | 21 | //GPIOA6,A7初始化设置 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_LEDa | GPIO_Pin_LEDb;//LEDa和LEDb对应IO口 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式 24 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 25 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz 26 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 27 | GPIO_Init(GPIO_LED, &GPIO_InitStructure);//初始化GPIO 28 | 29 | GPIO_SetBits(GPIO_LED,GPIO_Pin_LEDa | GPIO_Pin_LEDb);//设置高,灯灭 30 | } 31 | -------------------------------------------------------------------------------- /Template_lib/SYSTEM/led.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Vesion: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __LED_H 10 | #define __LED_H 11 | #include "sys.h" 12 | 13 | //========================= 14 | //板载两个LED,低电平点亮 15 | //A6:D2(重命名为LEDa) 16 | //A7:D3(重命名为LEDb) 17 | //========================= 18 | 19 | //LED端口定义 20 | #define RCC_AHB1Periph_LED RCC_AHB1Periph_GPIOA 21 | #define GPIO_LED GPIOA 22 | 23 | #define GPIO_Pin_LEDa GPIO_Pin_6 24 | #define GPIO_Pin_LEDb GPIO_Pin_7 25 | 26 | #define digitalHigh(p,i) {p->BSRRH=i;} //引脚输出高电平 27 | #define digitalLow(p,i) {p->BSRRL=i;} //引脚输出低电平 28 | #define digitalToggle(p,i) {p->ODR ^=i;} //反转 29 | 30 | #define LEDa_ON digitalLow(GPIO_LED,GPIO_Pin_LEDa) 31 | #define LEDb_ON digitalLow(GPIO_LED,GPIO_Pin_LEDb) 32 | 33 | #define LEDa_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDa) 34 | #define LEDb_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDb) 35 | 36 | #define LEDa_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDa) 37 | #define LEDb_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDb) 38 | 39 | void LED_Init(void);//初始化 40 | #endif 41 | -------------------------------------------------------------------------------- /Template_lib/SYSTEM/sys.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "sys.h" 10 | 11 | //================================== 12 | //系统时钟初始化 13 | //包括时钟设置/中断管理/GPIO设置等 14 | //================================== 15 | 16 | 17 | //THUMB指令不支持汇编内联 18 | //采用如下方法实现执行汇编指令WFI 19 | __asm void WFI_SET(void) 20 | { 21 | WFI; 22 | } 23 | //关闭所有中断(但是不包括fault和NMI中断) 24 | __asm void INTX_DISABLE(void) 25 | { 26 | CPSID I 27 | BX LR 28 | } 29 | //开启所有中断 30 | __asm void INTX_ENABLE(void) 31 | { 32 | CPSIE I 33 | BX LR 34 | } 35 | //设置栈顶地址 36 | //addr:栈顶地址 37 | __asm void MSR_MSP(u32 addr) 38 | { 39 | MSR MSP, r0 //set Main Stack value 40 | BX r14 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /Template_lib/SYSTEM/sys.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __SYS_H 10 | #define __SYS_H 11 | #include "stm32f4xx.h" 12 | 13 | //IO口操作宏定义 14 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 15 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 16 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 17 | 18 | //IO口地址映射 19 | #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014 20 | #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414 21 | #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814 22 | #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14 23 | #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014 24 | #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414 25 | #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814 26 | #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14 27 | #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014 28 | 29 | #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010 30 | #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410 31 | #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810 32 | #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10 33 | #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010 34 | #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410 35 | #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810 36 | #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10 37 | #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010 38 | 39 | //IO口操作,只对单一的IO口! 40 | //确保n的值小于16! 41 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出 42 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 43 | 44 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出 45 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 46 | 47 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出 48 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 49 | 50 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出 51 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 52 | 53 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出 54 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入 55 | 56 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出 57 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入 58 | 59 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出 60 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入 61 | 62 | #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出 63 | #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入 64 | 65 | #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出 66 | #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入 67 | 68 | //汇编函数 69 | void WFI_SET(void); //执行WFI指令 70 | void INTX_DISABLE(void);//关闭所有中断 71 | void INTX_ENABLE(void); //开启所有中断 72 | void MSR_MSP(u32 addr); //设置堆栈地址 73 | #endif 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /Template_lib/SYSTEM/usart.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载串口1配置 3 | //File: usart.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __USART_H 10 | #define __USART_H 11 | #include "stdio.h" 12 | #include "stm32f4xx_conf.h" 13 | #include "sys.h" 14 | 15 | //************************* 16 | //STM32F407 17 | //串口1初始化 18 | //************************* 19 | 20 | #define USART_REC_LEN 200 //定义最大接收字节数 200 21 | #define EN_USART1_RX 1 //使能(1)/禁止(0)串口1接收 22 | 23 | extern u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 24 | extern u16 USART_RX_STA; //接收状态标记 25 | 26 | void uart_init(u32 bound); 27 | #endif 28 | -------------------------------------------------------------------------------- /Template_lib/USER/main.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407工程模板 3 | //File: main.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Vesion: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "stm32f4xx.h" 10 | #include "led.h" 11 | #include "delay.h" 12 | 13 | int main(void) 14 | { 15 | LED_Init(); 16 | delay_init(84); 17 | 18 | while(1) 19 | { 20 | //LEDa亮500ms,灭500ms 21 | LEDa_ON; 22 | delay_ms(500); 23 | LEDa_OFF; 24 | delay_ms(500); 25 | 26 | //LEDb每隔1000ms翻转一次 27 | LEDb_Toggle; 28 | } 29 | } 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Template_lib/USER/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/Template_lib/USER/stm32f4xx.h -------------------------------------------------------------------------------- /Template_lib/USER/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_IT_H 30 | #define __STM32F4xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macro ------------------------------------------------------------*/ 42 | /* Exported functions ------------------------------------------------------- */ 43 | 44 | void NMI_Handler(void); 45 | void HardFault_Handler(void); 46 | void MemManage_Handler(void); 47 | void BusFault_Handler(void); 48 | void UsageFault_Handler(void); 49 | void SVC_Handler(void); 50 | void DebugMon_Handler(void); 51 | void PendSV_Handler(void); 52 | void SysTick_Handler(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __STM32F4xx_IT_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /Template_lib/USER/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /** @addtogroup CMSIS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup stm32f4xx_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32F4XX_H 40 | #define __SYSTEM_STM32F4XX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32F4xx_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32F4xx_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F4xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F4xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F4xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F4XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /Template_noOS/FWLIB/inc/stm32f4xx_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_crc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_CRC_H 31 | #define __STM32F4xx_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup CRC_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | 62 | void CRC_ResetDR(void); 63 | uint32_t CRC_CalcCRC(uint32_t Data); 64 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 65 | uint32_t CRC_GetCRC(void); 66 | void CRC_SetIDRegister(uint8_t IDValue); 67 | uint8_t CRC_GetIDRegister(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __STM32F4xx_CRC_H */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /Template_noOS/FWLIB/inc/stm32f4xx_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief Header file of FLASH RAMFUNC driver. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 31 | #define __STM32F4xx_FLASH_RAMFUNC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup FLASH RAMFUNC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Private define ------------------------------------------------------------*/ 50 | /** 51 | * @brief __RAM_FUNC definition 52 | */ 53 | #if defined ( __CC_ARM ) 54 | /* ARM Compiler 55 | ------------ 56 | RAM functions are defined using the toolchain options. 57 | Functions that are executed in RAM should reside in a separate source module. 58 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 59 | area of a module to a memory space in physical RAM. 60 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 61 | dialog. 62 | */ 63 | #define __RAM_FUNC void 64 | 65 | #elif defined ( __ICCARM__ ) 66 | /* ICCARM Compiler 67 | --------------- 68 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 69 | */ 70 | #define __RAM_FUNC __ramfunc void 71 | 72 | #elif defined ( __GNUC__ ) 73 | /* GNU Compiler 74 | ------------ 75 | RAM functions are defined using a specific toolchain attribute 76 | "__attribute__((section(".RamFunc")))". 77 | */ 78 | #define __RAM_FUNC void __attribute__((section(".RamFunc"))) 79 | 80 | #endif 81 | /* Exported constants --------------------------------------------------------*/ 82 | /* Exported macro ------------------------------------------------------------*/ 83 | /* Exported functions --------------------------------------------------------*/ 84 | __RAM_FUNC FLASH_FlashInterfaceCmd(FunctionalState NewState); 85 | __RAM_FUNC FLASH_FlashSleepModeCmd(FunctionalState NewState); 86 | 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 103 | 104 | -------------------------------------------------------------------------------- /Template_noOS/README/README.txt: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407工程模板 3 | //File: README.txt 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | 基于STM32F4 固件库V1.4.0的工程模板 10 | 11 | 新建工程的时候,请确保Option for target->C/C++选项卡的全部宏定义Define输入框字符串为:STM32F40_41xxx,USE_STDPERIPH_DRIVER 12 | 13 | Keil Version:5.15 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Template_noOS/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'Template_noOS' 7 | * Target: 'Template_noOS' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | #endif /* RTE_COMPONENTS_H */ 15 | -------------------------------------------------------------------------------- /Template_noOS/SYSTEM/delay.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "delay.h" 10 | #include "sys.h" 11 | 12 | static u8 fac_us=0;//us延时倍乘数 13 | static u16 fac_ms=0;//ms延时倍乘数,在ucos下,代表每个节拍的ms数 14 | 15 | //========================================= 16 | //初始化延迟函数 17 | //SYSTICK的时钟固定为HCLK时钟的1/8 18 | //SYSCLK:系统时钟 19 | //========================================= 20 | void delay_init(u8 SYSCLK) 21 | { 22 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); 23 | fac_us=SYSCLK/8; 24 | fac_ms=(u16)fac_us*1000;//代表每个ms需要的systick时钟数 25 | } 26 | 27 | //========================================= 28 | //延时nus 29 | //nus为要延时的us数. 30 | //注意:nus的值,不要大于798915us 31 | //========================================= 32 | void delay_us(u32 nus) 33 | { 34 | u32 temp; 35 | SysTick->LOAD=nus*fac_us; //时间加载 36 | SysTick->VAL=0x00; //清空计数器 37 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;//开始倒数 38 | do 39 | { 40 | temp=SysTick->CTRL; 41 | } 42 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 43 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 44 | SysTick->VAL =0X00; //清空计数器 45 | } 46 | 47 | //========================================= 48 | //延时nms 49 | //注意nms的范围 50 | //SysTick->LOAD为24位寄存器,所以,最大延时为: 51 | //nms<=0xffffff*8*1000/SYSCLK 52 | //SYSCLK单位为Hz,nms单位为ms 53 | //对168M条件下,nms<=798ms 54 | //========================================= 55 | void delay_xms(u16 nms) 56 | { 57 | u32 temp; 58 | SysTick->LOAD=(u32)nms*fac_ms;//时间加载(SysTick->LOAD为24bit) 59 | SysTick->VAL =0x00; //清空计数器 60 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 61 | do 62 | { 63 | temp=SysTick->CTRL; 64 | } 65 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 66 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 67 | SysTick->VAL =0X00; //清空计数器 68 | } 69 | 70 | //========================================= 71 | //延时nms 72 | //nms:0~65535 73 | //========================================= 74 | void delay_ms(u16 nms) 75 | { 76 | u8 repeat=nms/540; //这里用540,是考虑到某些客户可能超频使用, 77 | //比如超频到248M的时候,delay_xms最大只能延时541ms左右了 78 | u16 remain=nms%540; 79 | while(repeat) 80 | { 81 | delay_xms(540); 82 | repeat--; 83 | } 84 | if(remain)delay_xms(remain); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /Template_noOS/SYSTEM/delay.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __DELAY_H 10 | #define __DELAY_H 11 | #include 12 | 13 | void delay_init(u8 SYSCLK); 14 | void delay_ms(u16 nms); 15 | void delay_us(u32 nus); 16 | 17 | #endif 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Template_noOS/SYSTEM/key.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "key.h" 10 | #include "delay.h" 11 | 12 | //========================== 13 | //按键初始化函数 14 | //========================== 15 | void KEY_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_KEY0|RCC_AHB1Periph_KEY1|RCC_AHB1Periph_K_UP, ENABLE);//使能GPIOA,GPIOE时钟 20 | 21 | //KEY0 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY0; //KEY0对应引脚 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 24 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 25 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 26 | GPIO_Init(GPIO_KEY0, &GPIO_InitStructure);//初始化GPIOE4,3 27 | 28 | //KEY1 29 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY1; //KEY1对应引脚 30 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 31 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 32 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 33 | GPIO_Init(GPIO_KEY1, &GPIO_InitStructure);//初始化GPIOE4,3 34 | 35 | //K_UP 36 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_K_UP;//K_UP对应引脚PA0 37 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;//下拉 38 | GPIO_Init(GPIO_K_UP, &GPIO_InitStructure);//初始化GPIOA0 39 | } 40 | 41 | //========================================= 42 | //按键处理函数 43 | //返回按键值 44 | //mode:0,不支持连续按;1,支持连续按; 45 | //0,没有任何按键按下 46 | //1,KEY0按下 47 | //2,KEY1按下 48 | //3,K_UP按下 WK_UP 49 | //注意此函数有响应优先级,KEY0>KEY1>WK_UP!! 50 | //========================================= 51 | u8 KEY_Scan(u8 mode) 52 | { 53 | static u8 key_up=1;//按键按松开标志 54 | if(mode)key_up=1; //支持连按 55 | 56 | if(key_up&&(KEY0==0||KEY1==0||K_UP==1)) 57 | { 58 | delay_ms(10);//去抖动 59 | key_up=0; 60 | 61 | if(KEY0==0)return 1; 62 | else if(KEY1==0)return 2; 63 | else if(K_UP==1)return 3; 64 | } 65 | else if(KEY0==1&&KEY1==1&&K_UP==0) 66 | { 67 | key_up=1; 68 | } 69 | 70 | return 0;// 无按键按下 71 | } 72 | -------------------------------------------------------------------------------- /Template_noOS/SYSTEM/key.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __KEY_H 10 | #define __KEY_H 11 | #include "sys.h" 12 | 13 | //======================= 14 | //3个板载按键 15 | //E4:(KEY0)按下为低电平 16 | //E3:(KEY1)按下为低电平 17 | //A0:(K_UP)按下为高电平 18 | //======================= 19 | 20 | #define RCC_AHB1Periph_KEY0 RCC_AHB1Periph_GPIOE 21 | #define RCC_AHB1Periph_KEY1 RCC_AHB1Periph_GPIOE 22 | #define RCC_AHB1Periph_K_UP RCC_AHB1Periph_GPIOA 23 | 24 | #define GPIO_KEY0 GPIOE 25 | #define GPIO_KEY1 GPIOE 26 | #define GPIO_K_UP GPIOA 27 | 28 | #define GPIO_Pin_KEY0 GPIO_Pin_4 29 | #define GPIO_Pin_KEY1 GPIO_Pin_3 30 | #define GPIO_Pin_K_UP GPIO_Pin_0 31 | 32 | //通过直接操作库函数方式读取IO 33 | #define KEY0 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY0) //PE4 34 | #define KEY1 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY1) //PE3 35 | #define K_UP GPIO_ReadInputDataBit(GPIO_K_UP,GPIO_Pin_K_UP) //PA0 36 | 37 | #define KEY0_PRES 1 38 | #define KEY1_PRES 2 39 | #define K_UP_PRES 3 40 | 41 | void KEY_Init(void); //IO初始化 42 | u8 KEY_Scan(u8); //按键扫描函数 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Template_noOS/SYSTEM/led.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "led.h" 10 | 11 | //=========================================== 12 | //LED IO初始化 13 | //初始化PA6和PA7为输出口.并使能这两个口的时钟 14 | //=========================================== 15 | void LED_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_LED, ENABLE);//使能GPIOA时钟 20 | 21 | //GPIOA6,A7初始化设置 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_LEDa | GPIO_Pin_LEDb;//LEDa和LEDb对应IO口 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式 24 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 25 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz 26 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 27 | GPIO_Init(GPIO_LED, &GPIO_InitStructure);//初始化GPIO 28 | 29 | GPIO_SetBits(GPIO_LED,GPIO_Pin_LEDa | GPIO_Pin_LEDb);//设置高,灯灭 30 | } 31 | -------------------------------------------------------------------------------- /Template_noOS/SYSTEM/led.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Vesion: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __LED_H 10 | #define __LED_H 11 | #include "sys.h" 12 | 13 | //========================= 14 | //板载两个LED,低电平点亮 15 | //A6:D2(重命名为LEDa) 16 | //A7:D3(重命名为LEDb) 17 | //========================= 18 | 19 | //LED端口定义 20 | #define RCC_AHB1Periph_LED RCC_AHB1Periph_GPIOA 21 | #define GPIO_LED GPIOA 22 | 23 | #define GPIO_Pin_LEDa GPIO_Pin_6 24 | #define GPIO_Pin_LEDb GPIO_Pin_7 25 | 26 | #define digitalHigh(p,i) {p->BSRRH=i;} //引脚输出高电平 27 | #define digitalLow(p,i) {p->BSRRL=i;} //引脚输出低电平 28 | #define digitalToggle(p,i) {p->ODR ^=i;} //反转 29 | 30 | #define LEDa_ON digitalLow(GPIO_LED,GPIO_Pin_LEDa) 31 | #define LEDb_ON digitalLow(GPIO_LED,GPIO_Pin_LEDb) 32 | 33 | #define LEDa_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDa) 34 | #define LEDb_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDb) 35 | 36 | #define LEDa_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDa) 37 | #define LEDb_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDb) 38 | 39 | void LED_Init(void);//初始化 40 | #endif 41 | -------------------------------------------------------------------------------- /Template_noOS/SYSTEM/sys.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "sys.h" 10 | 11 | //================================== 12 | //系统时钟初始化 13 | //包括时钟设置/中断管理/GPIO设置等 14 | //================================== 15 | 16 | 17 | //THUMB指令不支持汇编内联 18 | //采用如下方法实现执行汇编指令WFI 19 | __asm void WFI_SET(void) 20 | { 21 | WFI; 22 | } 23 | //关闭所有中断(但是不包括fault和NMI中断) 24 | __asm void INTX_DISABLE(void) 25 | { 26 | CPSID I 27 | BX LR 28 | } 29 | //开启所有中断 30 | __asm void INTX_ENABLE(void) 31 | { 32 | CPSIE I 33 | BX LR 34 | } 35 | //设置栈顶地址 36 | //addr:栈顶地址 37 | __asm void MSR_MSP(u32 addr) 38 | { 39 | MSR MSP, r0 //set Main Stack value 40 | BX r14 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /Template_noOS/SYSTEM/sys.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __SYS_H 10 | #define __SYS_H 11 | #include "stm32f4xx.h" 12 | 13 | //IO口操作宏定义 14 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 15 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 16 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 17 | 18 | //IO口地址映射 19 | #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014 20 | #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414 21 | #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814 22 | #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14 23 | #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014 24 | #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414 25 | #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814 26 | #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14 27 | #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014 28 | 29 | #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010 30 | #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410 31 | #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810 32 | #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10 33 | #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010 34 | #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410 35 | #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810 36 | #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10 37 | #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010 38 | 39 | //IO口操作,只对单一的IO口! 40 | //确保n的值小于16! 41 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出 42 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 43 | 44 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出 45 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 46 | 47 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出 48 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 49 | 50 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出 51 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 52 | 53 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出 54 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入 55 | 56 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出 57 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入 58 | 59 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出 60 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入 61 | 62 | #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出 63 | #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入 64 | 65 | #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出 66 | #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入 67 | 68 | //汇编函数 69 | void WFI_SET(void); //执行WFI指令 70 | void INTX_DISABLE(void);//关闭所有中断 71 | void INTX_ENABLE(void); //开启所有中断 72 | void MSR_MSP(u32 addr); //设置堆栈地址 73 | #endif 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /Template_noOS/SYSTEM/usart.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载串口1配置 3 | //File: usart.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __USART_H 10 | #define __USART_H 11 | #include "stdio.h" 12 | #include "stm32f4xx_conf.h" 13 | #include "sys.h" 14 | 15 | //************************* 16 | //STM32F407 17 | //串口1初始化 18 | //************************* 19 | 20 | #define USART_REC_LEN 200 //定义最大接收字节数 200 21 | #define EN_USART1_RX 1 //使能(1)/禁止(0)串口1接收 22 | 23 | extern u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 24 | extern u16 USART_RX_STA; //接收状态标记 25 | 26 | void uart_init(u32 bound); 27 | #endif 28 | -------------------------------------------------------------------------------- /Template_noOS/USER/main.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407工程模板 3 | //File: main.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "stm32f4xx.h" 10 | #include "led.h" 11 | #include "delay.h" 12 | 13 | int main(void) 14 | { 15 | LED_Init(); 16 | delay_init(84); 17 | 18 | while(1) 19 | { 20 | //LEDa亮500ms,灭500ms 21 | LEDa_ON; 22 | delay_ms(500); 23 | LEDa_OFF; 24 | delay_ms(500); 25 | 26 | //LEDb每隔1000ms翻转一次 27 | LEDb_Toggle; 28 | } 29 | } 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Template_noOS/USER/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/Template_noOS/USER/stm32f4xx.h -------------------------------------------------------------------------------- /Template_noOS/USER/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_IT_H 30 | #define __STM32F4xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macro ------------------------------------------------------------*/ 42 | /* Exported functions ------------------------------------------------------- */ 43 | 44 | void NMI_Handler(void); 45 | void HardFault_Handler(void); 46 | void MemManage_Handler(void); 47 | void BusFault_Handler(void); 48 | void UsageFault_Handler(void); 49 | void SVC_Handler(void); 50 | void DebugMon_Handler(void); 51 | void PendSV_Handler(void); 52 | void SysTick_Handler(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __STM32F4xx_IT_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /Template_noOS/USER/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /** @addtogroup CMSIS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup stm32f4xx_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32F4XX_H 40 | #define __SYSTEM_STM32F4XX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32F4xx_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32F4xx_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F4xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F4xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F4xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F4XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /Template_noOS/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/Template_noOS/keilkilll.bat -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/README/README.txt: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407工程模板 3 | //File: README.txt 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | 基于STM32F4 固件库V1.4.0的工程模板 10 | 11 | 新建工程的时候,请确保Option for target->C/C++选项卡的全部宏定义Define输入框字符串为:STM32F40_41xxx,USE_STDPERIPH_DRIVER 12 | 13 | Keil Version:5.15 14 | 15 | 注:此工程将需要用到的库文件(STM32 FreeRTOS)放置在了工程文件外的commonlib文件夹 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'Template_FreeRTOS' 7 | * Target: 'Template_FreeRTOS' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | #endif /* RTE_COMPONENTS_H */ 15 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/SYSTEM/delay.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "delay.h" 10 | #include "sys.h" 11 | 12 | static u8 fac_us=0;//us延时倍乘数 13 | static u16 fac_ms=0;//ms延时倍乘数,在ucos下,代表每个节拍的ms数 14 | 15 | //========================================= 16 | //初始化延迟函数 17 | //SYSTICK的时钟固定为HCLK时钟的1/8 18 | //SYSCLK:系统时钟 19 | //========================================= 20 | void delay_init(u8 SYSCLK) 21 | { 22 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); 23 | fac_us=SYSCLK/8; 24 | fac_ms=(u16)fac_us*1000;//代表每个ms需要的systick时钟数 25 | } 26 | 27 | //========================================= 28 | //延时nus 29 | //nus为要延时的us数. 30 | //注意:nus的值,不要大于798915us 31 | //========================================= 32 | void delay_us(u32 nus) 33 | { 34 | u32 temp; 35 | SysTick->LOAD=nus*fac_us; //时间加载 36 | SysTick->VAL=0x00; //清空计数器 37 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;//开始倒数 38 | do 39 | { 40 | temp=SysTick->CTRL; 41 | } 42 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 43 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 44 | SysTick->VAL =0X00; //清空计数器 45 | } 46 | 47 | //========================================= 48 | //延时nms 49 | //注意nms的范围 50 | //SysTick->LOAD为24位寄存器,所以,最大延时为: 51 | //nms<=0xffffff*8*1000/SYSCLK 52 | //SYSCLK单位为Hz,nms单位为ms 53 | //对168M条件下,nms<=798ms 54 | //========================================= 55 | void delay_xms(u16 nms) 56 | { 57 | u32 temp; 58 | SysTick->LOAD=(u32)nms*fac_ms;//时间加载(SysTick->LOAD为24bit) 59 | SysTick->VAL =0x00; //清空计数器 60 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 61 | do 62 | { 63 | temp=SysTick->CTRL; 64 | } 65 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 66 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 67 | SysTick->VAL =0X00; //清空计数器 68 | } 69 | 70 | //========================================= 71 | //延时nms 72 | //nms:0~65535 73 | //========================================= 74 | void delay_ms(u16 nms) 75 | { 76 | u8 repeat=nms/540; //这里用540,是考虑到某些客户可能超频使用, 77 | //比如超频到248M的时候,delay_xms最大只能延时541ms左右了 78 | u16 remain=nms%540; 79 | while(repeat) 80 | { 81 | delay_xms(540); 82 | repeat--; 83 | } 84 | if(remain)delay_xms(remain); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/SYSTEM/delay.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __DELAY_H 10 | #define __DELAY_H 11 | #include 12 | 13 | void delay_init(u8 SYSCLK); 14 | void delay_ms(u16 nms); 15 | void delay_us(u32 nus); 16 | 17 | #endif 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/SYSTEM/key.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "key.h" 10 | #include "delay.h" 11 | 12 | //========================== 13 | //按键初始化函数 14 | //========================== 15 | void KEY_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_KEY0|RCC_AHB1Periph_KEY1|RCC_AHB1Periph_K_UP, ENABLE);//使能GPIOA,GPIOE时钟 20 | 21 | //KEY0 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY0; //KEY0对应引脚 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 24 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 25 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 26 | GPIO_Init(GPIO_KEY0, &GPIO_InitStructure);//初始化GPIOE4,3 27 | 28 | //KEY1 29 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY1; //KEY1对应引脚 30 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 31 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 32 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 33 | GPIO_Init(GPIO_KEY1, &GPIO_InitStructure);//初始化GPIOE4,3 34 | 35 | //K_UP 36 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_K_UP;//K_UP对应引脚PA0 37 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;//下拉 38 | GPIO_Init(GPIO_K_UP, &GPIO_InitStructure);//初始化GPIOA0 39 | } 40 | 41 | //========================================= 42 | //按键处理函数 43 | //返回按键值 44 | //mode:0,不支持连续按;1,支持连续按; 45 | //0,没有任何按键按下 46 | //1,KEY0按下 47 | //2,KEY1按下 48 | //3,K_UP按下 WK_UP 49 | //注意此函数有响应优先级,KEY0>KEY1>WK_UP!! 50 | //========================================= 51 | u8 KEY_Scan(u8 mode) 52 | { 53 | static u8 key_up=1;//按键按松开标志 54 | if(mode)key_up=1; //支持连按 55 | 56 | if(key_up&&(KEY0==0||KEY1==0||K_UP==1)) 57 | { 58 | delay_ms(10);//去抖动 59 | key_up=0; 60 | 61 | if(KEY0==0)return 1; 62 | else if(KEY1==0)return 2; 63 | else if(K_UP==1)return 3; 64 | } 65 | else if(KEY0==1&&KEY1==1&&K_UP==0) 66 | { 67 | key_up=1; 68 | } 69 | 70 | return 0;// 无按键按下 71 | } 72 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/SYSTEM/key.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __KEY_H 10 | #define __KEY_H 11 | #include "sys.h" 12 | 13 | //======================= 14 | //3个板载按键 15 | //E4:(KEY0)按下为低电平 16 | //E3:(KEY1)按下为低电平 17 | //A0:(K_UP)按下为高电平 18 | //======================= 19 | 20 | #define RCC_AHB1Periph_KEY0 RCC_AHB1Periph_GPIOE 21 | #define RCC_AHB1Periph_KEY1 RCC_AHB1Periph_GPIOE 22 | #define RCC_AHB1Periph_K_UP RCC_AHB1Periph_GPIOA 23 | 24 | #define GPIO_KEY0 GPIOE 25 | #define GPIO_KEY1 GPIOE 26 | #define GPIO_K_UP GPIOA 27 | 28 | #define GPIO_Pin_KEY0 GPIO_Pin_4 29 | #define GPIO_Pin_KEY1 GPIO_Pin_3 30 | #define GPIO_Pin_K_UP GPIO_Pin_0 31 | 32 | //通过直接操作库函数方式读取IO 33 | #define KEY0 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY0) //PE4 34 | #define KEY1 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY1) //PE3 35 | #define K_UP GPIO_ReadInputDataBit(GPIO_K_UP,GPIO_Pin_K_UP) //PA0 36 | 37 | #define KEY0_PRES 1 38 | #define KEY1_PRES 2 39 | #define K_UP_PRES 3 40 | 41 | void KEY_Init(void); //IO初始化 42 | u8 KEY_Scan(u8); //按键扫描函数 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/SYSTEM/led.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "led.h" 10 | 11 | //=========================================== 12 | //LED IO初始化 13 | //初始化PA6和PA7为输出口.并使能这两个口的时钟 14 | //=========================================== 15 | void LED_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_LED, ENABLE);//使能GPIOA时钟 20 | 21 | //GPIOA6,A7初始化设置 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_LEDa | GPIO_Pin_LEDb;//LEDa和LEDb对应IO口 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式 24 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 25 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz 26 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 27 | GPIO_Init(GPIO_LED, &GPIO_InitStructure);//初始化GPIO 28 | 29 | GPIO_SetBits(GPIO_LED,GPIO_Pin_LEDa | GPIO_Pin_LEDb);//设置高,灯灭 30 | } 31 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/SYSTEM/led.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Vesion: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __LED_H 10 | #define __LED_H 11 | #include "sys.h" 12 | 13 | //========================= 14 | //板载两个LED,低电平点亮 15 | //A6:D2(重命名为LEDa) 16 | //A7:D3(重命名为LEDb) 17 | //========================= 18 | 19 | //LED端口定义 20 | #define RCC_AHB1Periph_LED RCC_AHB1Periph_GPIOA 21 | #define GPIO_LED GPIOA 22 | 23 | #define GPIO_Pin_LEDa GPIO_Pin_6 24 | #define GPIO_Pin_LEDb GPIO_Pin_7 25 | 26 | #define digitalHigh(p,i) {p->BSRRH=i;} //引脚输出高电平 27 | #define digitalLow(p,i) {p->BSRRL=i;} //引脚输出低电平 28 | #define digitalToggle(p,i) {p->ODR ^=i;} //反转 29 | 30 | #define LEDa_ON digitalLow(GPIO_LED,GPIO_Pin_LEDa) 31 | #define LEDb_ON digitalLow(GPIO_LED,GPIO_Pin_LEDb) 32 | 33 | #define LEDa_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDa) 34 | #define LEDb_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDb) 35 | 36 | #define LEDa_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDa) 37 | #define LEDb_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDb) 38 | 39 | void LED_Init(void);//初始化 40 | #endif 41 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/SYSTEM/sys.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "sys.h" 10 | 11 | //================================== 12 | //系统时钟初始化 13 | //包括时钟设置/中断管理/GPIO设置等 14 | //================================== 15 | 16 | 17 | //THUMB指令不支持汇编内联 18 | //采用如下方法实现执行汇编指令WFI 19 | __asm void WFI_SET(void) 20 | { 21 | WFI; 22 | } 23 | //关闭所有中断(但是不包括fault和NMI中断) 24 | __asm void INTX_DISABLE(void) 25 | { 26 | CPSID I 27 | BX LR 28 | } 29 | //开启所有中断 30 | __asm void INTX_ENABLE(void) 31 | { 32 | CPSIE I 33 | BX LR 34 | } 35 | //设置栈顶地址 36 | //addr:栈顶地址 37 | __asm void MSR_MSP(u32 addr) 38 | { 39 | MSR MSP, r0 //set Main Stack value 40 | BX r14 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/SYSTEM/sys.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __SYS_H 10 | #define __SYS_H 11 | #include "stm32f4xx.h" 12 | 13 | //IO口操作宏定义 14 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 15 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 16 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 17 | 18 | //IO口地址映射 19 | #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014 20 | #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414 21 | #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814 22 | #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14 23 | #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014 24 | #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414 25 | #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814 26 | #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14 27 | #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014 28 | 29 | #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010 30 | #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410 31 | #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810 32 | #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10 33 | #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010 34 | #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410 35 | #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810 36 | #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10 37 | #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010 38 | 39 | //IO口操作,只对单一的IO口! 40 | //确保n的值小于16! 41 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出 42 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 43 | 44 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出 45 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 46 | 47 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出 48 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 49 | 50 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出 51 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 52 | 53 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出 54 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入 55 | 56 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出 57 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入 58 | 59 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出 60 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入 61 | 62 | #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出 63 | #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入 64 | 65 | #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出 66 | #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入 67 | 68 | //汇编函数 69 | void WFI_SET(void); //执行WFI指令 70 | void INTX_DISABLE(void);//关闭所有中断 71 | void INTX_ENABLE(void); //开启所有中断 72 | void MSR_MSP(u32 addr); //设置堆栈地址 73 | #endif 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/SYSTEM/usart.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载串口1配置 3 | //File: usart.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __USART_H 10 | #define __USART_H 11 | #include "stdio.h" 12 | #include "stm32f4xx_conf.h" 13 | #include "sys.h" 14 | 15 | //************************* 16 | //STM32F407 17 | //串口1初始化 18 | //************************* 19 | 20 | #define USART_REC_LEN 200 //定义最大接收字节数 200 21 | #define EN_USART1_RX 1 //使能(1)/禁止(0)串口1接收 22 | 23 | extern u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 24 | extern u16 USART_RX_STA; //接收状态标记 25 | 26 | void uart_init(u32 bound); 27 | #endif 28 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/USER/main.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407+FreeRTOS 创建LED任务 3 | //File: main.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "stm32f4xx.h" 10 | #include "led.h" 11 | 12 | #include "FreeRTOS.h" 13 | #include "task.h" 14 | 15 | //任务参数-------------------------- 16 | //优先级 堆栈大小 任务句柄 任务函数 17 | #define START_TASK_PRIO 1 18 | #define START_STK_SIZE 128 19 | TaskHandle_t StartTask_Handler; 20 | void start_task(void *pvParameters); 21 | 22 | #define TASK1_TASK_PRIO 2 23 | #define TASK1_STK_SIZE 128 24 | TaskHandle_t Task1Task_Handler; 25 | void task1_task(void *pvParameters); 26 | 27 | #define TASK2_TASK_PRIO 3 28 | #define TASK2_STK_SIZE 128 29 | TaskHandle_t Task2Task_Handler; 30 | void task2_task(void *pvParameters); 31 | 32 | 33 | int main(void) 34 | { 35 | //设置系统中断优先级分组4(FreeRTOS中的默认方式!) 36 | NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4); 37 | 38 | //初始化LED端口 39 | LED_Init(); 40 | 41 | //创建开始任务 42 | xTaskCreate((TaskFunction_t )start_task, //任务函数 43 | (const char* )"start_task", //任务名称 44 | (uint16_t )START_STK_SIZE, //任务堆栈大小 45 | (void* )NULL, //传递给任务函数的参数 46 | (UBaseType_t )START_TASK_PRIO, //任务优先级 47 | (TaskHandle_t* )&StartTask_Handler); //任务句柄 48 | //开启任务调度 49 | vTaskStartScheduler(); 50 | } 51 | 52 | //开始任务任务函数 53 | void start_task(void *pvParameters) 54 | { 55 | taskENTER_CRITICAL(); //进入临界区 56 | 57 | //创建TASK1任务 58 | xTaskCreate((TaskFunction_t )task1_task, 59 | (const char* )"task1_task", 60 | (uint16_t )TASK1_STK_SIZE, 61 | (void* )NULL, 62 | (UBaseType_t )TASK1_TASK_PRIO, 63 | (TaskHandle_t* )&Task1Task_Handler); 64 | //创建TASK2任务 65 | xTaskCreate((TaskFunction_t )task2_task, 66 | (const char* )"task2_task", 67 | (uint16_t )TASK2_STK_SIZE, 68 | (void* )NULL, 69 | (UBaseType_t )TASK2_TASK_PRIO, 70 | (TaskHandle_t* )&Task2Task_Handler); 71 | 72 | vTaskDelete(StartTask_Handler); //删除开始任务 73 | 74 | taskEXIT_CRITICAL(); //退出临界区 75 | } 76 | 77 | //task1任务函数 78 | void task1_task(void *pvParameters) 79 | { 80 | while(1) 81 | { 82 | LEDa_Toggle; 83 | vTaskDelay(500); //延时500ms 84 | } 85 | } 86 | 87 | //task2任务函数 88 | void task2_task(void *pvParameters) 89 | { 90 | while(1) 91 | { 92 | LEDb_ON; 93 | vTaskDelay(200); //延时200ms 94 | LEDb_OFF; 95 | vTaskDelay(800); //延时800ms 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/USER/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_IT_H 30 | #define __STM32F4xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macro ------------------------------------------------------------*/ 42 | /* Exported functions ------------------------------------------------------- */ 43 | 44 | void NMI_Handler(void); 45 | void HardFault_Handler(void); 46 | void MemManage_Handler(void); 47 | void BusFault_Handler(void); 48 | void UsageFault_Handler(void); 49 | void SVC_Handler(void); 50 | void DebugMon_Handler(void); 51 | void PendSV_Handler(void); 52 | void SysTick_Handler(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __STM32F4xx_IT_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /examples/001_FreeRTOS_LEDtask/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/examples/001_FreeRTOS_LEDtask/keilkilll.bat -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/README/README.txt: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407工程模板 3 | //File: README.txt 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | 基于STM32F4 固件库V1.4.0的工程模板 10 | 11 | 新建工程的时候,请确保Option for target->C/C++选项卡的全部宏定义Define输入框字符串为:STM32F40_41xxx,USE_STDPERIPH_DRIVER 12 | 13 | Keil Version:5.15 14 | 15 | 注:此工程将需要用到的库文件(STM32 FreeRTOS)放置在了工程文件外的commonlib文件夹 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'Template_FreeRTOS' 7 | * Target: 'Template_FreeRTOS' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | #endif /* RTE_COMPONENTS_H */ 15 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/SYSTEM/delay.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "delay.h" 10 | #include "sys.h" 11 | 12 | static u8 fac_us=0;//us延时倍乘数 13 | static u16 fac_ms=0;//ms延时倍乘数,在ucos下,代表每个节拍的ms数 14 | 15 | //========================================= 16 | //初始化延迟函数 17 | //SYSTICK的时钟固定为HCLK时钟的1/8 18 | //SYSCLK:系统时钟 19 | //========================================= 20 | void delay_init(u8 SYSCLK) 21 | { 22 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); 23 | fac_us=SYSCLK/8; 24 | fac_ms=(u16)fac_us*1000;//代表每个ms需要的systick时钟数 25 | } 26 | 27 | //========================================= 28 | //延时nus 29 | //nus为要延时的us数. 30 | //注意:nus的值,不要大于798915us 31 | //========================================= 32 | void delay_us(u32 nus) 33 | { 34 | u32 temp; 35 | SysTick->LOAD=nus*fac_us; //时间加载 36 | SysTick->VAL=0x00; //清空计数器 37 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;//开始倒数 38 | do 39 | { 40 | temp=SysTick->CTRL; 41 | } 42 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 43 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 44 | SysTick->VAL =0X00; //清空计数器 45 | } 46 | 47 | //========================================= 48 | //延时nms 49 | //注意nms的范围 50 | //SysTick->LOAD为24位寄存器,所以,最大延时为: 51 | //nms<=0xffffff*8*1000/SYSCLK 52 | //SYSCLK单位为Hz,nms单位为ms 53 | //对168M条件下,nms<=798ms 54 | //========================================= 55 | void delay_xms(u16 nms) 56 | { 57 | u32 temp; 58 | SysTick->LOAD=(u32)nms*fac_ms;//时间加载(SysTick->LOAD为24bit) 59 | SysTick->VAL =0x00; //清空计数器 60 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 61 | do 62 | { 63 | temp=SysTick->CTRL; 64 | } 65 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 66 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 67 | SysTick->VAL =0X00; //清空计数器 68 | } 69 | 70 | //========================================= 71 | //延时nms 72 | //nms:0~65535 73 | //========================================= 74 | void delay_ms(u16 nms) 75 | { 76 | u8 repeat=nms/540; //这里用540,是考虑到某些客户可能超频使用, 77 | //比如超频到248M的时候,delay_xms最大只能延时541ms左右了 78 | u16 remain=nms%540; 79 | while(repeat) 80 | { 81 | delay_xms(540); 82 | repeat--; 83 | } 84 | if(remain)delay_xms(remain); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/SYSTEM/delay.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __DELAY_H 10 | #define __DELAY_H 11 | #include 12 | 13 | void delay_init(u8 SYSCLK); 14 | void delay_ms(u16 nms); 15 | void delay_us(u32 nus); 16 | 17 | #endif 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/SYSTEM/key.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "key.h" 10 | #include "delay.h" 11 | 12 | #include "FreeRTOS.h" 13 | #include "task.h" 14 | 15 | //========================== 16 | //按键初始化函数 17 | //========================== 18 | void KEY_Init(void) 19 | { 20 | GPIO_InitTypeDef GPIO_InitStructure; 21 | 22 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_KEY0|RCC_AHB1Periph_KEY1|RCC_AHB1Periph_K_UP, ENABLE);//使能GPIOA,GPIOE时钟 23 | 24 | //KEY0 25 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY0; //KEY0对应引脚 26 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 27 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 28 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 29 | GPIO_Init(GPIO_KEY0, &GPIO_InitStructure);//初始化GPIOE4,3 30 | 31 | //KEY1 32 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY1; //KEY1对应引脚 33 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 34 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 35 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 36 | GPIO_Init(GPIO_KEY1, &GPIO_InitStructure);//初始化GPIOE4,3 37 | 38 | //K_UP 39 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_K_UP;//K_UP对应引脚PA0 40 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;//下拉 41 | GPIO_Init(GPIO_K_UP, &GPIO_InitStructure);//初始化GPIOA0 42 | } 43 | 44 | //========================================= 45 | //按键处理函数 46 | //返回按键值 47 | //mode:0,不支持连续按;1,支持连续按; 48 | //0,没有任何按键按下 49 | //1,KEY0按下 50 | //2,KEY1按下 51 | //3,K_UP按下 WK_UP 52 | //注意此函数有响应优先级,KEY0>KEY1>WK_UP!! 53 | //========================================= 54 | u8 KEY_Scan(u8 mode) 55 | { 56 | static u8 key_up=1;//按键按松开标志 57 | if(mode)key_up=1; //支持连按 58 | 59 | if(key_up&&(KEY0==0||KEY1==0||K_UP==1)) 60 | { 61 | vTaskDelay(10);//去抖动 62 | key_up=0; 63 | 64 | if(KEY0==0)return 1; 65 | else if(KEY1==0)return 2; 66 | else if(K_UP==1)return 3; 67 | } 68 | else if(KEY0==1&&KEY1==1&&K_UP==0) 69 | { 70 | key_up=1; 71 | } 72 | 73 | return 0;// 无按键按下 74 | } 75 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/SYSTEM/key.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __KEY_H 10 | #define __KEY_H 11 | #include "sys.h" 12 | 13 | //======================= 14 | //3个板载按键 15 | //E4:(KEY0)按下为低电平 16 | //E3:(KEY1)按下为低电平 17 | //A0:(K_UP)按下为高电平 18 | //======================= 19 | 20 | #define RCC_AHB1Periph_KEY0 RCC_AHB1Periph_GPIOE 21 | #define RCC_AHB1Periph_KEY1 RCC_AHB1Periph_GPIOE 22 | #define RCC_AHB1Periph_K_UP RCC_AHB1Periph_GPIOA 23 | 24 | #define GPIO_KEY0 GPIOE 25 | #define GPIO_KEY1 GPIOE 26 | #define GPIO_K_UP GPIOA 27 | 28 | #define GPIO_Pin_KEY0 GPIO_Pin_4 29 | #define GPIO_Pin_KEY1 GPIO_Pin_3 30 | #define GPIO_Pin_K_UP GPIO_Pin_0 31 | 32 | //通过直接操作库函数方式读取IO 33 | #define KEY0 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY0) //PE4 34 | #define KEY1 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY1) //PE3 35 | #define K_UP GPIO_ReadInputDataBit(GPIO_K_UP,GPIO_Pin_K_UP) //PA0 36 | 37 | #define KEY0_PRES 1 38 | #define KEY1_PRES 2 39 | #define K_UP_PRES 3 40 | 41 | void KEY_Init(void); //IO初始化 42 | u8 KEY_Scan(u8); //按键扫描函数 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/SYSTEM/led.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "led.h" 10 | 11 | //=========================================== 12 | //LED IO初始化 13 | //初始化PA6和PA7为输出口.并使能这两个口的时钟 14 | //=========================================== 15 | void LED_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_LED, ENABLE);//使能GPIOA时钟 20 | 21 | //GPIOA6,A7初始化设置 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_LEDa | GPIO_Pin_LEDb;//LEDa和LEDb对应IO口 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式 24 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 25 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz 26 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 27 | GPIO_Init(GPIO_LED, &GPIO_InitStructure);//初始化GPIO 28 | 29 | GPIO_SetBits(GPIO_LED,GPIO_Pin_LEDa | GPIO_Pin_LEDb);//设置高,灯灭 30 | } 31 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/SYSTEM/led.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Vesion: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __LED_H 10 | #define __LED_H 11 | #include "sys.h" 12 | 13 | //========================= 14 | //板载两个LED,低电平点亮 15 | //A6:D2(重命名为LEDa) 16 | //A7:D3(重命名为LEDb) 17 | //========================= 18 | 19 | //LED端口定义 20 | #define RCC_AHB1Periph_LED RCC_AHB1Periph_GPIOA 21 | #define GPIO_LED GPIOA 22 | 23 | #define GPIO_Pin_LEDa GPIO_Pin_6 24 | #define GPIO_Pin_LEDb GPIO_Pin_7 25 | 26 | #define digitalHigh(p,i) {p->BSRRH=i;} //引脚输出高电平 27 | #define digitalLow(p,i) {p->BSRRL=i;} //引脚输出低电平 28 | #define digitalToggle(p,i) {p->ODR ^=i;} //反转 29 | 30 | #define LEDa_ON digitalLow(GPIO_LED,GPIO_Pin_LEDa) 31 | #define LEDb_ON digitalLow(GPIO_LED,GPIO_Pin_LEDb) 32 | 33 | #define LEDa_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDa) 34 | #define LEDb_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDb) 35 | 36 | #define LEDa_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDa) 37 | #define LEDb_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDb) 38 | 39 | void LED_Init(void);//初始化 40 | #endif 41 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/SYSTEM/sys.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "sys.h" 10 | 11 | //================================== 12 | //系统时钟初始化 13 | //包括时钟设置/中断管理/GPIO设置等 14 | //================================== 15 | 16 | 17 | //THUMB指令不支持汇编内联 18 | //采用如下方法实现执行汇编指令WFI 19 | __asm void WFI_SET(void) 20 | { 21 | WFI; 22 | } 23 | //关闭所有中断(但是不包括fault和NMI中断) 24 | __asm void INTX_DISABLE(void) 25 | { 26 | CPSID I 27 | BX LR 28 | } 29 | //开启所有中断 30 | __asm void INTX_ENABLE(void) 31 | { 32 | CPSIE I 33 | BX LR 34 | } 35 | //设置栈顶地址 36 | //addr:栈顶地址 37 | __asm void MSR_MSP(u32 addr) 38 | { 39 | MSR MSP, r0 //set Main Stack value 40 | BX r14 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/SYSTEM/sys.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __SYS_H 10 | #define __SYS_H 11 | #include "stm32f4xx.h" 12 | 13 | //IO口操作宏定义 14 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 15 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 16 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 17 | 18 | //IO口地址映射 19 | #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014 20 | #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414 21 | #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814 22 | #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14 23 | #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014 24 | #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414 25 | #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814 26 | #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14 27 | #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014 28 | 29 | #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010 30 | #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410 31 | #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810 32 | #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10 33 | #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010 34 | #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410 35 | #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810 36 | #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10 37 | #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010 38 | 39 | //IO口操作,只对单一的IO口! 40 | //确保n的值小于16! 41 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出 42 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 43 | 44 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出 45 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 46 | 47 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出 48 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 49 | 50 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出 51 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 52 | 53 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出 54 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入 55 | 56 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出 57 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入 58 | 59 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出 60 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入 61 | 62 | #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出 63 | #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入 64 | 65 | #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出 66 | #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入 67 | 68 | //汇编函数 69 | void WFI_SET(void); //执行WFI指令 70 | void INTX_DISABLE(void);//关闭所有中断 71 | void INTX_ENABLE(void); //开启所有中断 72 | void MSR_MSP(u32 addr); //设置堆栈地址 73 | #endif 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/SYSTEM/usart.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载串口1配置 3 | //File: usart.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __USART_H 10 | #define __USART_H 11 | #include "stdio.h" 12 | #include "stm32f4xx_conf.h" 13 | #include "sys.h" 14 | 15 | //************************* 16 | //STM32F407 17 | //串口1初始化 18 | //************************* 19 | 20 | #define USART_REC_LEN 200 //定义最大接收字节数 200 21 | #define EN_USART1_RX 1 //使能(1)/禁止(0)串口1接收 22 | 23 | extern u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 24 | extern u16 USART_RX_STA; //接收状态标记 25 | 26 | void uart_init(u32 bound); 27 | #endif 28 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/USER/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_IT_H 30 | #define __STM32F4xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macro ------------------------------------------------------------*/ 42 | /* Exported functions ------------------------------------------------------- */ 43 | 44 | void NMI_Handler(void); 45 | void HardFault_Handler(void); 46 | void MemManage_Handler(void); 47 | void BusFault_Handler(void); 48 | void UsageFault_Handler(void); 49 | void SVC_Handler(void); 50 | void DebugMon_Handler(void); 51 | void PendSV_Handler(void); 52 | void SysTick_Handler(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __STM32F4xx_IT_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /examples/002_FreeRTOS_LEDtask_Suspend_Resume/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/examples/002_FreeRTOS_LEDtask_Suspend_Resume/keilkilll.bat -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/README/README.txt: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407工程模板 3 | //File: README.txt 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | 基于STM32F4 固件库V1.4.0的工程模板 10 | 11 | 新建工程的时候,请确保Option for target->C/C++选项卡的全部宏定义Define输入框字符串为:STM32F40_41xxx,USE_STDPERIPH_DRIVER 12 | 13 | Keil Version:5.15 14 | 15 | 注:此工程将需要用到的库文件(STM32 FreeRTOS)放置在了工程文件外的commonlib文件夹 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'Template_FreeRTOS' 7 | * Target: 'Template_FreeRTOS' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | #endif /* RTE_COMPONENTS_H */ 15 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/SYSTEM/delay.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "delay.h" 10 | #include "sys.h" 11 | 12 | static u8 fac_us=0;//us延时倍乘数 13 | static u16 fac_ms=0;//ms延时倍乘数,在ucos下,代表每个节拍的ms数 14 | 15 | //========================================= 16 | //初始化延迟函数 17 | //SYSTICK的时钟固定为HCLK时钟的1/8 18 | //SYSCLK:系统时钟 19 | //========================================= 20 | void delay_init(u8 SYSCLK) 21 | { 22 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); 23 | fac_us=SYSCLK/8; 24 | fac_ms=(u16)fac_us*1000;//代表每个ms需要的systick时钟数 25 | } 26 | 27 | //========================================= 28 | //延时nus 29 | //nus为要延时的us数. 30 | //注意:nus的值,不要大于798915us 31 | //========================================= 32 | void delay_us(u32 nus) 33 | { 34 | u32 temp; 35 | SysTick->LOAD=nus*fac_us; //时间加载 36 | SysTick->VAL=0x00; //清空计数器 37 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;//开始倒数 38 | do 39 | { 40 | temp=SysTick->CTRL; 41 | } 42 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 43 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 44 | SysTick->VAL =0X00; //清空计数器 45 | } 46 | 47 | //========================================= 48 | //延时nms 49 | //注意nms的范围 50 | //SysTick->LOAD为24位寄存器,所以,最大延时为: 51 | //nms<=0xffffff*8*1000/SYSCLK 52 | //SYSCLK单位为Hz,nms单位为ms 53 | //对168M条件下,nms<=798ms 54 | //========================================= 55 | void delay_xms(u16 nms) 56 | { 57 | u32 temp; 58 | SysTick->LOAD=(u32)nms*fac_ms;//时间加载(SysTick->LOAD为24bit) 59 | SysTick->VAL =0x00; //清空计数器 60 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 61 | do 62 | { 63 | temp=SysTick->CTRL; 64 | } 65 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 66 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 67 | SysTick->VAL =0X00; //清空计数器 68 | } 69 | 70 | //========================================= 71 | //延时nms 72 | //nms:0~65535 73 | //========================================= 74 | void delay_ms(u16 nms) 75 | { 76 | u8 repeat=nms/540; //这里用540,是考虑到某些客户可能超频使用, 77 | //比如超频到248M的时候,delay_xms最大只能延时541ms左右了 78 | u16 remain=nms%540; 79 | while(repeat) 80 | { 81 | delay_xms(540); 82 | repeat--; 83 | } 84 | if(remain)delay_xms(remain); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/SYSTEM/delay.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __DELAY_H 10 | #define __DELAY_H 11 | #include 12 | 13 | void delay_init(u8 SYSCLK); 14 | void delay_ms(u16 nms); 15 | void delay_us(u32 nus); 16 | 17 | #endif 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/SYSTEM/key.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "key.h" 10 | #include "delay.h" 11 | 12 | #include "FreeRTOS.h" 13 | #include "task.h" 14 | 15 | //========================== 16 | //按键初始化函数 17 | //========================== 18 | void KEY_Init(void) 19 | { 20 | GPIO_InitTypeDef GPIO_InitStructure; 21 | 22 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_KEY0|RCC_AHB1Periph_KEY1|RCC_AHB1Periph_K_UP, ENABLE);//使能GPIOA,GPIOE时钟 23 | 24 | //KEY0 25 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY0; //KEY0对应引脚 26 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 27 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 28 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 29 | GPIO_Init(GPIO_KEY0, &GPIO_InitStructure);//初始化GPIOE4,3 30 | 31 | //KEY1 32 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY1; //KEY1对应引脚 33 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 34 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 35 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 36 | GPIO_Init(GPIO_KEY1, &GPIO_InitStructure);//初始化GPIOE4,3 37 | 38 | //K_UP 39 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_K_UP;//K_UP对应引脚PA0 40 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;//下拉 41 | GPIO_Init(GPIO_K_UP, &GPIO_InitStructure);//初始化GPIOA0 42 | } 43 | 44 | //========================================= 45 | //按键处理函数 46 | //返回按键值 47 | //mode:0,不支持连续按;1,支持连续按; 48 | //0,没有任何按键按下 49 | //1,KEY0按下 50 | //2,KEY1按下 51 | //3,K_UP按下 WK_UP 52 | //注意此函数有响应优先级,KEY0>KEY1>WK_UP!! 53 | //========================================= 54 | u8 KEY_Scan(u8 mode) 55 | { 56 | static u8 key_up=1;//按键按松开标志 57 | if(mode)key_up=1; //支持连按 58 | 59 | if(key_up&&(KEY0==0||KEY1==0||K_UP==1)) 60 | { 61 | vTaskDelay(10);//去抖动 62 | key_up=0; 63 | 64 | if(KEY0==0)return 1; 65 | else if(KEY1==0)return 2; 66 | else if(K_UP==1)return 3; 67 | } 68 | else if(KEY0==1&&KEY1==1&&K_UP==0) 69 | { 70 | key_up=1; 71 | } 72 | 73 | return 0;// 无按键按下 74 | } 75 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/SYSTEM/key.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __KEY_H 10 | #define __KEY_H 11 | #include "sys.h" 12 | 13 | //======================= 14 | //3个板载按键 15 | //E4:(KEY0)按下为低电平 16 | //E3:(KEY1)按下为低电平 17 | //A0:(K_UP)按下为高电平 18 | //======================= 19 | 20 | #define RCC_AHB1Periph_KEY0 RCC_AHB1Periph_GPIOE 21 | #define RCC_AHB1Periph_KEY1 RCC_AHB1Periph_GPIOE 22 | #define RCC_AHB1Periph_K_UP RCC_AHB1Periph_GPIOA 23 | 24 | #define GPIO_KEY0 GPIOE 25 | #define GPIO_KEY1 GPIOE 26 | #define GPIO_K_UP GPIOA 27 | 28 | #define GPIO_Pin_KEY0 GPIO_Pin_4 29 | #define GPIO_Pin_KEY1 GPIO_Pin_3 30 | #define GPIO_Pin_K_UP GPIO_Pin_0 31 | 32 | //通过直接操作库函数方式读取IO 33 | #define KEY0 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY0) //PE4 34 | #define KEY1 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY1) //PE3 35 | #define K_UP GPIO_ReadInputDataBit(GPIO_K_UP,GPIO_Pin_K_UP) //PA0 36 | 37 | #define KEY0_PRES 1 38 | #define KEY1_PRES 2 39 | #define K_UP_PRES 3 40 | 41 | void KEY_Init(void); //IO初始化 42 | u8 KEY_Scan(u8); //按键扫描函数 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/SYSTEM/led.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "led.h" 10 | 11 | //=========================================== 12 | //LED IO初始化 13 | //初始化PA6和PA7为输出口.并使能这两个口的时钟 14 | //=========================================== 15 | void LED_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_LED, ENABLE);//使能GPIOA时钟 20 | 21 | //GPIOA6,A7初始化设置 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_LEDa | GPIO_Pin_LEDb;//LEDa和LEDb对应IO口 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式 24 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 25 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz 26 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 27 | GPIO_Init(GPIO_LED, &GPIO_InitStructure);//初始化GPIO 28 | 29 | GPIO_SetBits(GPIO_LED,GPIO_Pin_LEDa | GPIO_Pin_LEDb);//设置高,灯灭 30 | } 31 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/SYSTEM/led.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Vesion: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __LED_H 10 | #define __LED_H 11 | #include "sys.h" 12 | 13 | //========================= 14 | //板载两个LED,低电平点亮 15 | //A6:D2(重命名为LEDa) 16 | //A7:D3(重命名为LEDb) 17 | //========================= 18 | 19 | //LED端口定义 20 | #define RCC_AHB1Periph_LED RCC_AHB1Periph_GPIOA 21 | #define GPIO_LED GPIOA 22 | 23 | #define GPIO_Pin_LEDa GPIO_Pin_6 24 | #define GPIO_Pin_LEDb GPIO_Pin_7 25 | 26 | #define digitalHigh(p,i) {p->BSRRH=i;} //引脚输出高电平 27 | #define digitalLow(p,i) {p->BSRRL=i;} //引脚输出低电平 28 | #define digitalToggle(p,i) {p->ODR ^=i;} //反转 29 | 30 | #define LEDa_ON digitalLow(GPIO_LED,GPIO_Pin_LEDa) 31 | #define LEDb_ON digitalLow(GPIO_LED,GPIO_Pin_LEDb) 32 | 33 | #define LEDa_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDa) 34 | #define LEDb_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDb) 35 | 36 | #define LEDa_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDa) 37 | #define LEDb_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDb) 38 | 39 | void LED_Init(void);//初始化 40 | #endif 41 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/SYSTEM/sys.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "sys.h" 10 | 11 | //================================== 12 | //系统时钟初始化 13 | //包括时钟设置/中断管理/GPIO设置等 14 | //================================== 15 | 16 | 17 | //THUMB指令不支持汇编内联 18 | //采用如下方法实现执行汇编指令WFI 19 | __asm void WFI_SET(void) 20 | { 21 | WFI; 22 | } 23 | //关闭所有中断(但是不包括fault和NMI中断) 24 | __asm void INTX_DISABLE(void) 25 | { 26 | CPSID I 27 | BX LR 28 | } 29 | //开启所有中断 30 | __asm void INTX_ENABLE(void) 31 | { 32 | CPSIE I 33 | BX LR 34 | } 35 | //设置栈顶地址 36 | //addr:栈顶地址 37 | __asm void MSR_MSP(u32 addr) 38 | { 39 | MSR MSP, r0 //set Main Stack value 40 | BX r14 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/SYSTEM/sys.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __SYS_H 10 | #define __SYS_H 11 | #include "stm32f4xx.h" 12 | 13 | //IO口操作宏定义 14 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 15 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 16 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 17 | 18 | //IO口地址映射 19 | #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014 20 | #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414 21 | #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814 22 | #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14 23 | #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014 24 | #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414 25 | #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814 26 | #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14 27 | #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014 28 | 29 | #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010 30 | #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410 31 | #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810 32 | #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10 33 | #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010 34 | #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410 35 | #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810 36 | #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10 37 | #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010 38 | 39 | //IO口操作,只对单一的IO口! 40 | //确保n的值小于16! 41 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出 42 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 43 | 44 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出 45 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 46 | 47 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出 48 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 49 | 50 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出 51 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 52 | 53 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出 54 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入 55 | 56 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出 57 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入 58 | 59 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出 60 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入 61 | 62 | #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出 63 | #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入 64 | 65 | #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出 66 | #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入 67 | 68 | //汇编函数 69 | void WFI_SET(void); //执行WFI指令 70 | void INTX_DISABLE(void);//关闭所有中断 71 | void INTX_ENABLE(void); //开启所有中断 72 | void MSR_MSP(u32 addr); //设置堆栈地址 73 | #endif 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/SYSTEM/usart.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载串口1配置 3 | //File: usart.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __USART_H 10 | #define __USART_H 11 | #include "stdio.h" 12 | #include "stm32f4xx_conf.h" 13 | #include "sys.h" 14 | 15 | //************************* 16 | //STM32F407 17 | //串口1初始化 18 | //************************* 19 | 20 | #define USART_REC_LEN 200 //定义最大接收字节数 200 21 | #define EN_USART1_RX 1 //使能(1)/禁止(0)串口1接收 22 | 23 | extern u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 24 | extern u16 USART_RX_STA; //接收状态标记 25 | 26 | void uart_init(u32 bound); 27 | #endif 28 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/USER/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_IT_H 30 | #define __STM32F4xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macro ------------------------------------------------------------*/ 42 | /* Exported functions ------------------------------------------------------- */ 43 | 44 | void NMI_Handler(void); 45 | void HardFault_Handler(void); 46 | void MemManage_Handler(void); 47 | void BusFault_Handler(void); 48 | void UsageFault_Handler(void); 49 | void SVC_Handler(void); 50 | void DebugMon_Handler(void); 51 | void PendSV_Handler(void); 52 | void SysTick_Handler(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __STM32F4xx_IT_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /examples/003_FreeRTOS_uart_idle_recv_and_semaphore/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/examples/003_FreeRTOS_uart_idle_recv_and_semaphore/keilkilll.bat -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/README/README.txt: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407工程模板 3 | //File: README.txt 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | 基于STM32F4 固件库V1.4.0的工程模板 10 | 11 | 新建工程的时候,请确保Option for target->C/C++选项卡的全部宏定义Define输入框字符串为:STM32F40_41xxx,USE_STDPERIPH_DRIVER 12 | 13 | Keil Version:5.15 14 | 15 | 注:此工程将需要用到的库文件(STM32 FreeRTOS)放置在了工程文件外的commonlib文件夹 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/RTE/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'Template_FreeRTOS' 7 | * Target: 'Template_FreeRTOS' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | #endif /* RTE_COMPONENTS_H */ 15 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/SYSTEM/delay.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "delay.h" 10 | #include "sys.h" 11 | 12 | static u8 fac_us=0;//us延时倍乘数 13 | static u16 fac_ms=0;//ms延时倍乘数,在ucos下,代表每个节拍的ms数 14 | 15 | //========================================= 16 | //初始化延迟函数 17 | //SYSTICK的时钟固定为HCLK时钟的1/8 18 | //SYSCLK:系统时钟 19 | //========================================= 20 | void delay_init(u8 SYSCLK) 21 | { 22 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); 23 | fac_us=SYSCLK/8; 24 | fac_ms=(u16)fac_us*1000;//代表每个ms需要的systick时钟数 25 | } 26 | 27 | //========================================= 28 | //延时nus 29 | //nus为要延时的us数. 30 | //注意:nus的值,不要大于798915us 31 | //========================================= 32 | void delay_us(u32 nus) 33 | { 34 | u32 temp; 35 | SysTick->LOAD=nus*fac_us; //时间加载 36 | SysTick->VAL=0x00; //清空计数器 37 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ;//开始倒数 38 | do 39 | { 40 | temp=SysTick->CTRL; 41 | } 42 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 43 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 44 | SysTick->VAL =0X00; //清空计数器 45 | } 46 | 47 | //========================================= 48 | //延时nms 49 | //注意nms的范围 50 | //SysTick->LOAD为24位寄存器,所以,最大延时为: 51 | //nms<=0xffffff*8*1000/SYSCLK 52 | //SYSCLK单位为Hz,nms单位为ms 53 | //对168M条件下,nms<=798ms 54 | //========================================= 55 | void delay_xms(u16 nms) 56 | { 57 | u32 temp; 58 | SysTick->LOAD=(u32)nms*fac_ms;//时间加载(SysTick->LOAD为24bit) 59 | SysTick->VAL =0x00; //清空计数器 60 | SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //开始倒数 61 | do 62 | { 63 | temp=SysTick->CTRL; 64 | } 65 | while((temp&0x01)&&!(temp&(1<<16)));//等待时间到达 66 | SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;//关闭计数器 67 | SysTick->VAL =0X00; //清空计数器 68 | } 69 | 70 | //========================================= 71 | //延时nms 72 | //nms:0~65535 73 | //========================================= 74 | void delay_ms(u16 nms) 75 | { 76 | u8 repeat=nms/540; //这里用540,是考虑到某些客户可能超频使用, 77 | //比如超频到248M的时候,delay_xms最大只能延时541ms左右了 78 | u16 remain=nms%540; 79 | while(repeat) 80 | { 81 | delay_xms(540); 82 | repeat--; 83 | } 84 | if(remain)delay_xms(remain); 85 | 86 | } 87 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/SYSTEM/delay.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 延时函数配置 3 | //File: delay.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __DELAY_H 10 | #define __DELAY_H 11 | #include 12 | 13 | void delay_init(u8 SYSCLK); 14 | void delay_ms(u16 nms); 15 | void delay_us(u32 nus); 16 | 17 | #endif 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/SYSTEM/key.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "key.h" 10 | #include "delay.h" 11 | 12 | #include "FreeRTOS.h" 13 | #include "task.h" 14 | 15 | //========================== 16 | //按键初始化函数 17 | //========================== 18 | void KEY_Init(void) 19 | { 20 | GPIO_InitTypeDef GPIO_InitStructure; 21 | 22 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_KEY0|RCC_AHB1Periph_KEY1|RCC_AHB1Periph_K_UP, ENABLE);//使能GPIOA,GPIOE时钟 23 | 24 | //KEY0 25 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY0; //KEY0对应引脚 26 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 27 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 28 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 29 | GPIO_Init(GPIO_KEY0, &GPIO_InitStructure);//初始化GPIOE4,3 30 | 31 | //KEY1 32 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_KEY1; //KEY1对应引脚 33 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式 34 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100M 35 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 36 | GPIO_Init(GPIO_KEY1, &GPIO_InitStructure);//初始化GPIOE4,3 37 | 38 | //K_UP 39 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_K_UP;//K_UP对应引脚PA0 40 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ;//下拉 41 | GPIO_Init(GPIO_K_UP, &GPIO_InitStructure);//初始化GPIOA0 42 | } 43 | 44 | //========================================= 45 | //按键处理函数 46 | //返回按键值 47 | //mode:0,不支持连续按;1,支持连续按; 48 | //0,没有任何按键按下 49 | //1,KEY0按下 50 | //2,KEY1按下 51 | //3,K_UP按下 WK_UP 52 | //注意此函数有响应优先级,KEY0>KEY1>WK_UP!! 53 | //========================================= 54 | u8 KEY_Scan(u8 mode) 55 | { 56 | static u8 key_up=1;//按键按松开标志 57 | if(mode)key_up=1; //支持连按 58 | 59 | if(key_up&&(KEY0==0||KEY1==0||K_UP==1)) 60 | { 61 | vTaskDelay(10);//去抖动 62 | key_up=0; 63 | 64 | if(KEY0==0)return 1; 65 | else if(KEY1==0)return 2; 66 | else if(K_UP==1)return 3; 67 | } 68 | else if(KEY0==1&&KEY1==1&&K_UP==0) 69 | { 70 | key_up=1; 71 | } 72 | 73 | return 0;// 无按键按下 74 | } 75 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/SYSTEM/key.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载按键配置 3 | //File: key.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __KEY_H 10 | #define __KEY_H 11 | #include "sys.h" 12 | 13 | //======================= 14 | //3个板载按键 15 | //E4:(KEY0)按下为低电平 16 | //E3:(KEY1)按下为低电平 17 | //A0:(K_UP)按下为高电平 18 | //======================= 19 | 20 | #define RCC_AHB1Periph_KEY0 RCC_AHB1Periph_GPIOE 21 | #define RCC_AHB1Periph_KEY1 RCC_AHB1Periph_GPIOE 22 | #define RCC_AHB1Periph_K_UP RCC_AHB1Periph_GPIOA 23 | 24 | #define GPIO_KEY0 GPIOE 25 | #define GPIO_KEY1 GPIOE 26 | #define GPIO_K_UP GPIOA 27 | 28 | #define GPIO_Pin_KEY0 GPIO_Pin_4 29 | #define GPIO_Pin_KEY1 GPIO_Pin_3 30 | #define GPIO_Pin_K_UP GPIO_Pin_0 31 | 32 | //通过直接操作库函数方式读取IO 33 | #define KEY0 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY0) //PE4 34 | #define KEY1 GPIO_ReadInputDataBit(GPIO_KEY0,GPIO_Pin_KEY1) //PE3 35 | #define K_UP GPIO_ReadInputDataBit(GPIO_K_UP,GPIO_Pin_K_UP) //PA0 36 | 37 | #define KEY0_PRES 1 38 | #define KEY1_PRES 2 39 | #define K_UP_PRES 3 40 | 41 | void KEY_Init(void); //IO初始化 42 | u8 KEY_Scan(u8); //按键扫描函数 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/SYSTEM/led.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "led.h" 10 | 11 | //=========================================== 12 | //LED IO初始化 13 | //初始化PA6和PA7为输出口.并使能这两个口的时钟 14 | //=========================================== 15 | void LED_Init(void) 16 | { 17 | GPIO_InitTypeDef GPIO_InitStructure; 18 | 19 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_LED, ENABLE);//使能GPIOA时钟 20 | 21 | //GPIOA6,A7初始化设置 22 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_LEDa | GPIO_Pin_LEDb;//LEDa和LEDb对应IO口 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式 24 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出 25 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz 26 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉 27 | GPIO_Init(GPIO_LED, &GPIO_InitStructure);//初始化GPIO 28 | 29 | GPIO_SetBits(GPIO_LED,GPIO_Pin_LEDa | GPIO_Pin_LEDb);//设置高,灯灭 30 | } 31 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/SYSTEM/led.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载LED配置 3 | //File: led.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Vesion: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __LED_H 10 | #define __LED_H 11 | #include "sys.h" 12 | 13 | //========================= 14 | //板载两个LED,低电平点亮 15 | //A6:D2(重命名为LEDa) 16 | //A7:D3(重命名为LEDb) 17 | //========================= 18 | 19 | //LED端口定义 20 | #define RCC_AHB1Periph_LED RCC_AHB1Periph_GPIOA 21 | #define GPIO_LED GPIOA 22 | 23 | #define GPIO_Pin_LEDa GPIO_Pin_6 24 | #define GPIO_Pin_LEDb GPIO_Pin_7 25 | 26 | #define digitalHigh(p,i) {p->BSRRH=i;} //引脚输出高电平 27 | #define digitalLow(p,i) {p->BSRRL=i;} //引脚输出低电平 28 | #define digitalToggle(p,i) {p->ODR ^=i;} //反转 29 | 30 | #define LEDa_ON digitalLow(GPIO_LED,GPIO_Pin_LEDa) 31 | #define LEDb_ON digitalLow(GPIO_LED,GPIO_Pin_LEDb) 32 | 33 | #define LEDa_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDa) 34 | #define LEDb_OFF digitalHigh(GPIO_LED,GPIO_Pin_LEDb) 35 | 36 | #define LEDa_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDa) 37 | #define LEDb_Toggle digitalToggle(GPIO_LED,GPIO_Pin_LEDb) 38 | 39 | void LED_Init(void);//初始化 40 | #endif 41 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/SYSTEM/sys.c: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.c 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #include "sys.h" 10 | 11 | //================================== 12 | //系统时钟初始化 13 | //包括时钟设置/中断管理/GPIO设置等 14 | //================================== 15 | 16 | 17 | //THUMB指令不支持汇编内联 18 | //采用如下方法实现执行汇编指令WFI 19 | __asm void WFI_SET(void) 20 | { 21 | WFI; 22 | } 23 | //关闭所有中断(但是不包括fault和NMI中断) 24 | __asm void INTX_DISABLE(void) 25 | { 26 | CPSID I 27 | BX LR 28 | } 29 | //开启所有中断 30 | __asm void INTX_ENABLE(void) 31 | { 32 | CPSIE I 33 | BX LR 34 | } 35 | //设置栈顶地址 36 | //addr:栈顶地址 37 | __asm void MSR_MSP(u32 addr) 38 | { 39 | MSR MSP, r0 //set Main Stack value 40 | BX r14 41 | } 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/SYSTEM/sys.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 系统配置 3 | //File: sys.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __SYS_H 10 | #define __SYS_H 11 | #include "stm32f4xx.h" 12 | 13 | //IO口操作宏定义 14 | #define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 15 | #define MEM_ADDR(addr) *((volatile unsigned long *)(addr)) 16 | #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) 17 | 18 | //IO口地址映射 19 | #define GPIOA_ODR_Addr (GPIOA_BASE+20) //0x40020014 20 | #define GPIOB_ODR_Addr (GPIOB_BASE+20) //0x40020414 21 | #define GPIOC_ODR_Addr (GPIOC_BASE+20) //0x40020814 22 | #define GPIOD_ODR_Addr (GPIOD_BASE+20) //0x40020C14 23 | #define GPIOE_ODR_Addr (GPIOE_BASE+20) //0x40021014 24 | #define GPIOF_ODR_Addr (GPIOF_BASE+20) //0x40021414 25 | #define GPIOG_ODR_Addr (GPIOG_BASE+20) //0x40021814 26 | #define GPIOH_ODR_Addr (GPIOH_BASE+20) //0x40021C14 27 | #define GPIOI_ODR_Addr (GPIOI_BASE+20) //0x40022014 28 | 29 | #define GPIOA_IDR_Addr (GPIOA_BASE+16) //0x40020010 30 | #define GPIOB_IDR_Addr (GPIOB_BASE+16) //0x40020410 31 | #define GPIOC_IDR_Addr (GPIOC_BASE+16) //0x40020810 32 | #define GPIOD_IDR_Addr (GPIOD_BASE+16) //0x40020C10 33 | #define GPIOE_IDR_Addr (GPIOE_BASE+16) //0x40021010 34 | #define GPIOF_IDR_Addr (GPIOF_BASE+16) //0x40021410 35 | #define GPIOG_IDR_Addr (GPIOG_BASE+16) //0x40021810 36 | #define GPIOH_IDR_Addr (GPIOH_BASE+16) //0x40021C10 37 | #define GPIOI_IDR_Addr (GPIOI_BASE+16) //0x40022010 38 | 39 | //IO口操作,只对单一的IO口! 40 | //确保n的值小于16! 41 | #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出 42 | #define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 43 | 44 | #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出 45 | #define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 46 | 47 | #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出 48 | #define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 49 | 50 | #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出 51 | #define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 52 | 53 | #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出 54 | #define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入 55 | 56 | #define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出 57 | #define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入 58 | 59 | #define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出 60 | #define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入 61 | 62 | #define PHout(n) BIT_ADDR(GPIOH_ODR_Addr,n) //输出 63 | #define PHin(n) BIT_ADDR(GPIOH_IDR_Addr,n) //输入 64 | 65 | #define PIout(n) BIT_ADDR(GPIOI_ODR_Addr,n) //输出 66 | #define PIin(n) BIT_ADDR(GPIOI_IDR_Addr,n) //输入 67 | 68 | //汇编函数 69 | void WFI_SET(void); //执行WFI指令 70 | void INTX_DISABLE(void);//关闭所有中断 71 | void INTX_ENABLE(void); //开启所有中断 72 | void MSR_MSP(u32 addr); //设置堆栈地址 73 | #endif 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/SYSTEM/usart.h: -------------------------------------------------------------------------------- 1 | //******************************* 2 | //STM32F407 板载串口1配置 3 | //File: usart.h 4 | //Author: xxpcb(wxgzh:码农爱学习) 5 | //Version: V1.0 6 | //Date: 2020/05/30 7 | //******************************* 8 | 9 | #ifndef __USART_H 10 | #define __USART_H 11 | #include "stdio.h" 12 | #include "stm32f4xx_conf.h" 13 | #include "sys.h" 14 | 15 | #define Uart_Tx_DMAStream DMA2_Stream7 16 | #define Uart_Rx_DMAStream DMA2_Stream5 17 | 18 | #define BUF_SIZE 200 //定义最大接收字节数 200 19 | extern u8 USART_RX_BUF[BUF_SIZE]; //接收缓冲 20 | extern u8 ReceiveBuff[BUF_SIZE]; 21 | extern u16 USART_RX_STA; //接收状态标记 22 | 23 | void uart_init(u32 bound); 24 | void MYDMA_Enable(DMA_Stream_TypeDef *DMA_Streamx,u16 ndtr); 25 | void uart_DMA_send(u8 *str,u16 ndtr); 26 | #endif 27 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/USER/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_it.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __STM32F4xx_IT_H 30 | #define __STM32F4xx_IT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "stm32f4xx.h" 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macro ------------------------------------------------------------*/ 42 | /* Exported functions ------------------------------------------------------- */ 43 | 44 | void NMI_Handler(void); 45 | void HardFault_Handler(void); 46 | void MemManage_Handler(void); 47 | void BusFault_Handler(void); 48 | void UsageFault_Handler(void); 49 | void SVC_Handler(void); 50 | void DebugMon_Handler(void); 51 | void PendSV_Handler(void); 52 | void SysTick_Handler(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __STM32F4xx_IT_H */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /examples/004_FreeRTOS_uart_dma_recv_send/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/examples/004_FreeRTOS_uart_dma_recv_send/keilkilll.bat -------------------------------------------------------------------------------- /examples/commonlib/FWLIB/inc/stm32f4xx_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_crc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT 2014 STMicroelectronics

13 | * 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 15 | * You may not use this file except in compliance with the License. 16 | * You may obtain a copy of the License at: 17 | * 18 | * http://www.st.com/software_license_agreement_liberty_v2 19 | * 20 | * Unless required by applicable law or agreed to in writing, software 21 | * distributed under the License is distributed on an "AS IS" BASIS, 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | * See the License for the specific language governing permissions and 24 | * limitations under the License. 25 | * 26 | ****************************************************************************** 27 | */ 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_CRC_H 31 | #define __STM32F4xx_CRC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup CRC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Exported constants --------------------------------------------------------*/ 50 | 51 | /** @defgroup CRC_Exported_Constants 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | 62 | void CRC_ResetDR(void); 63 | uint32_t CRC_CalcCRC(uint32_t Data); 64 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 65 | uint32_t CRC_GetCRC(void); 66 | void CRC_SetIDRegister(uint8_t IDValue); 67 | uint8_t CRC_GetIDRegister(void); 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* __STM32F4xx_CRC_H */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 84 | -------------------------------------------------------------------------------- /examples/commonlib/FWLIB/inc/stm32f4xx_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief Header file of FLASH RAMFUNC driver. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | 29 | /* Define to prevent recursive inclusion -------------------------------------*/ 30 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 31 | #define __STM32F4xx_FLASH_RAMFUNC_H 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Includes ------------------------------------------------------------------*/ 38 | #include "stm32f4xx.h" 39 | 40 | /** @addtogroup STM32F4xx_StdPeriph_Driver 41 | * @{ 42 | */ 43 | 44 | /** @addtogroup FLASH RAMFUNC 45 | * @{ 46 | */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* Private define ------------------------------------------------------------*/ 50 | /** 51 | * @brief __RAM_FUNC definition 52 | */ 53 | #if defined ( __CC_ARM ) 54 | /* ARM Compiler 55 | ------------ 56 | RAM functions are defined using the toolchain options. 57 | Functions that are executed in RAM should reside in a separate source module. 58 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 59 | area of a module to a memory space in physical RAM. 60 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 61 | dialog. 62 | */ 63 | #define __RAM_FUNC void 64 | 65 | #elif defined ( __ICCARM__ ) 66 | /* ICCARM Compiler 67 | --------------- 68 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 69 | */ 70 | #define __RAM_FUNC __ramfunc void 71 | 72 | #elif defined ( __GNUC__ ) 73 | /* GNU Compiler 74 | ------------ 75 | RAM functions are defined using a specific toolchain attribute 76 | "__attribute__((section(".RamFunc")))". 77 | */ 78 | #define __RAM_FUNC void __attribute__((section(".RamFunc"))) 79 | 80 | #endif 81 | /* Exported constants --------------------------------------------------------*/ 82 | /* Exported macro ------------------------------------------------------------*/ 83 | /* Exported functions --------------------------------------------------------*/ 84 | __RAM_FUNC FLASH_FlashInterfaceCmd(FunctionalState NewState); 85 | __RAM_FUNC FLASH_FlashSleepModeCmd(FunctionalState NewState); 86 | 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 103 | 104 | -------------------------------------------------------------------------------- /examples/commonlib/FreeRTOS/include/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /examples/commonlib/FreeRTOS/portable/Keil/See-also-the-RVDS-directory.txt: -------------------------------------------------------------------------------- 1 | Nothing to see here. -------------------------------------------------------------------------------- /examples/commonlib/FreeRTOS/portable/MemMang/ReadMe.url: -------------------------------------------------------------------------------- 1 | [{000214A0-0000-0000-C000-000000000046}] 2 | Prop3=19,2 3 | [InternetShortcut] 4 | URL=http://www.freertos.org/a00111.html 5 | IDList= 6 | -------------------------------------------------------------------------------- /examples/commonlib/FreeRTOS/portable/RVDS/ARM_CM7/ReadMe.txt: -------------------------------------------------------------------------------- 1 | There are two options for running FreeRTOS on ARM Cortex-M7 microcontrollers. 2 | The best option depends on the revision of the ARM Cortex-M7 core in use. The 3 | revision is specified by an 'r' number, and a 'p' number, so will look something 4 | like 'r0p1'. Check the documentation for the microcontroller in use to find the 5 | revision of the Cortex-M7 core used in that microcontroller. If in doubt, use 6 | the FreeRTOS port provided specifically for r0p1 revisions, as that can be used 7 | with all core revisions. 8 | 9 | The first option is to use the ARM Cortex-M4F port, and the second option is to 10 | use the Cortex-M7 r0p1 port - the latter containing a minor errata workaround. 11 | 12 | If the revision of the ARM Cortex-M7 core is not r0p1 then either option can be 13 | used, but it is recommended to use the FreeRTOS ARM Cortex-M4F port located in 14 | the /FreeRTOS/Source/portable/RVDS/ARM_CM4F directory. 15 | 16 | If the revision of the ARM Cortex-M7 core is r0p1 then use the FreeRTOS ARM 17 | Cortex-M7 r0p1 port located in the /FreeRTOS/Source/portable/RVDS/ARM_CM7/r0p1 18 | directory. -------------------------------------------------------------------------------- /examples/commonlib/FreeRTOS/portable/readme.txt: -------------------------------------------------------------------------------- 1 | Each real time kernel port consists of three files that contain the core kernel 2 | components and are common to every port, and one or more files that are 3 | specific to a particular microcontroller and/or compiler. 4 | 5 | 6 | + The FreeRTOS/Source/Portable/MemMang directory contains the five sample 7 | memory allocators as described on the http://www.FreeRTOS.org WEB site. 8 | 9 | + The other directories each contain files specific to a particular 10 | microcontroller or compiler, where the directory name denotes the compiler 11 | specific files the directory contains. 12 | 13 | 14 | 15 | For example, if you are interested in the [compiler] port for the [architecture] 16 | microcontroller, then the port specific files are contained in 17 | FreeRTOS/Source/Portable/[compiler]/[architecture] directory. If this is the 18 | only port you are interested in then all the other directories can be 19 | ignored. 20 | 21 | -------------------------------------------------------------------------------- /examples/commonlib/FreeRTOS/readme.txt: -------------------------------------------------------------------------------- 1 | Each real time kernel port consists of three files that contain the core kernel 2 | components and are common to every port, and one or more files that are 3 | specific to a particular microcontroller and or compiler. 4 | 5 | + The FreeRTOS/Source directory contains the three files that are common to 6 | every port - list.c, queue.c and tasks.c. The kernel is contained within these 7 | three files. croutine.c implements the optional co-routine functionality - which 8 | is normally only used on very memory limited systems. 9 | 10 | + The FreeRTOS/Source/Portable directory contains the files that are specific to 11 | a particular microcontroller and or compiler. 12 | 13 | + The FreeRTOS/Source/include directory contains the real time kernel header 14 | files. 15 | 16 | See the readme file in the FreeRTOS/Source/Portable directory for more 17 | information. -------------------------------------------------------------------------------- /examples/commonlib/USER2/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/examples/commonlib/USER2/stm32f4xx.h -------------------------------------------------------------------------------- /examples/commonlib/USER2/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @version V1.4.0 6 | * @date 04-August-2014 7 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2014 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /** @addtogroup CMSIS 29 | * @{ 30 | */ 31 | 32 | /** @addtogroup stm32f4xx_system 33 | * @{ 34 | */ 35 | 36 | /** 37 | * @brief Define to prevent recursive inclusion 38 | */ 39 | #ifndef __SYSTEM_STM32F4XX_H 40 | #define __SYSTEM_STM32F4XX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** @addtogroup STM32F4xx_System_Includes 47 | * @{ 48 | */ 49 | 50 | /** 51 | * @} 52 | */ 53 | 54 | 55 | /** @addtogroup STM32F4xx_System_Exported_types 56 | * @{ 57 | */ 58 | 59 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @addtogroup STM32F4xx_System_Exported_Constants 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @addtogroup STM32F4xx_System_Exported_Macros 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** @addtogroup STM32F4xx_System_Exported_Functions 83 | * @{ 84 | */ 85 | 86 | extern void SystemInit(void); 87 | extern void SystemCoreClockUpdate(void); 88 | /** 89 | * @} 90 | */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /*__SYSTEM_STM32F4XX_H */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** 103 | * @} 104 | */ 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /examples/commonlib/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/examples/commonlib/readme.txt -------------------------------------------------------------------------------- /keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/keilkilll.bat -------------------------------------------------------------------------------- /pic/FreeRTOSv9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xxpcb/FreeRTOS-STM32F407-examples/cc67808c491312446a0653db329b2b69fa4f633f/pic/FreeRTOSv9.png --------------------------------------------------------------------------------