├── Image ├── IMG_20211118_020216.jpg ├── IMG_20211124_214435~01.jpg ├── IMG_20211127_203054~01.jpg ├── IMG_20211128_212951~01.jpg ├── IMG_20211128_221307~01.jpg ├── IMG_20211210_230506~01.jpg ├── IMG_20211212_175627~01.jpg ├── TIM截图20211106103937.jpg ├── TIM截图20211106104007.jpg ├── TIM截图20211106104055.jpg ├── TIM截图20211106104605.jpg ├── TIM截图20211107002021.jpg ├── TIM截图20211107003349.jpg ├── TIM截图20211114205652.jpg ├── TIM截图20211114205736.jpg ├── TIM截图20211114205815.jpg ├── TIM截图20211114205849.jpg └── TIM截图20211128213619.jpg ├── README.md ├── firmware ├── OLED迷宫游戏(游戏实现逻辑,需要自己加接口) │ ├── 迷宫.c │ └── 迷宫.h └── SWD_downloader_demo │ ├── F103RC │ ├── DAPProg.uvguix.27731 │ ├── DAPProg.uvoptx │ ├── DAPProg.uvprojx │ ├── EventRecorderStub.scvd │ ├── LICENSE │ ├── README.md │ ├── doc │ │ └── FlashAlgo │ │ │ ├── STM32F10x_128.FLM │ │ │ ├── STM32F10x_128.c │ │ │ ├── STM32F4xx_1024.FLM │ │ │ ├── STM32F4xx_1024.c │ │ │ └── flash_algo.py │ ├── keilkilll.bat │ ├── out │ │ ├── DAPProg.asm │ │ ├── DAPProg.bin │ │ └── DAPProg.hex │ ├── src │ │ ├── CSL │ │ │ ├── CMSIS │ │ │ │ ├── CoreSupport │ │ │ │ │ ├── arm_common_tables.h │ │ │ │ │ ├── arm_const_structs.h │ │ │ │ │ ├── arm_math.h │ │ │ │ │ ├── core_cm0.h │ │ │ │ │ ├── core_cm0plus.h │ │ │ │ │ ├── core_cm3.h │ │ │ │ │ ├── core_cm4.h │ │ │ │ │ ├── core_cm7.h │ │ │ │ │ ├── core_cmFunc.h │ │ │ │ │ ├── core_cmInstr.h │ │ │ │ │ └── core_cmSimd.h │ │ │ │ └── DeviceSupport │ │ │ │ │ ├── startup │ │ │ │ │ ├── arm │ │ │ │ │ │ ├── startup_stm32f10x_cl.s │ │ │ │ │ │ ├── startup_stm32f10x_hd.s │ │ │ │ │ │ ├── startup_stm32f10x_hd_vl.s │ │ │ │ │ │ ├── startup_stm32f10x_ld.s │ │ │ │ │ │ ├── startup_stm32f10x_ld_vl.s │ │ │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ │ │ ├── startup_stm32f10x_md_vl.s │ │ │ │ │ │ └── startup_stm32f10x_xl.s │ │ │ │ │ ├── gcc │ │ │ │ │ │ ├── startup_stm32f10x_cl.s │ │ │ │ │ │ ├── startup_stm32f10x_hd.s │ │ │ │ │ │ ├── startup_stm32f10x_hd_vl.s │ │ │ │ │ │ ├── startup_stm32f10x_ld.s │ │ │ │ │ │ ├── startup_stm32f10x_ld_vl.s │ │ │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ │ │ ├── startup_stm32f10x_md_vl.s │ │ │ │ │ │ └── startup_stm32f10x_xl.s │ │ │ │ │ └── iar │ │ │ │ │ │ ├── startup_stm32f10x_cl.s │ │ │ │ │ │ ├── startup_stm32f10x_hd.s │ │ │ │ │ │ ├── startup_stm32f10x_hd_vl.s │ │ │ │ │ │ ├── startup_stm32f10x_ld.s │ │ │ │ │ │ ├── startup_stm32f10x_ld_vl.s │ │ │ │ │ │ ├── startup_stm32f10x_md.s │ │ │ │ │ │ ├── startup_stm32f10x_md_vl.s │ │ │ │ │ │ └── startup_stm32f10x_xl.s │ │ │ │ │ ├── stm32f10x.h │ │ │ │ │ ├── system_stm32f10x.c │ │ │ │ │ └── system_stm32f10x.h │ │ │ ├── STM32F10x_StdPeriph_Driver │ │ │ │ ├── misc.c │ │ │ │ ├── misc.h │ │ │ │ ├── stm32f10x_adc.c │ │ │ │ ├── stm32f10x_adc.h │ │ │ │ ├── stm32f10x_bkp.c │ │ │ │ ├── stm32f10x_bkp.h │ │ │ │ ├── stm32f10x_can.c │ │ │ │ ├── stm32f10x_can.h │ │ │ │ ├── stm32f10x_cec.c │ │ │ │ ├── stm32f10x_cec.h │ │ │ │ ├── stm32f10x_crc.c │ │ │ │ ├── stm32f10x_crc.h │ │ │ │ ├── stm32f10x_dac.c │ │ │ │ ├── stm32f10x_dac.h │ │ │ │ ├── stm32f10x_dbgmcu.c │ │ │ │ ├── stm32f10x_dbgmcu.h │ │ │ │ ├── stm32f10x_dma.c │ │ │ │ ├── stm32f10x_dma.h │ │ │ │ ├── stm32f10x_exti.c │ │ │ │ ├── stm32f10x_exti.h │ │ │ │ ├── stm32f10x_flash.c │ │ │ │ ├── stm32f10x_flash.h │ │ │ │ ├── stm32f10x_fsmc.c │ │ │ │ ├── stm32f10x_fsmc.h │ │ │ │ ├── stm32f10x_gpio.c │ │ │ │ ├── stm32f10x_gpio.h │ │ │ │ ├── stm32f10x_i2c.c │ │ │ │ ├── stm32f10x_i2c.h │ │ │ │ ├── stm32f10x_iwdg.c │ │ │ │ ├── stm32f10x_iwdg.h │ │ │ │ ├── stm32f10x_pwr.c │ │ │ │ ├── stm32f10x_pwr.h │ │ │ │ ├── stm32f10x_rcc.c │ │ │ │ ├── stm32f10x_rcc.h │ │ │ │ ├── stm32f10x_rtc.c │ │ │ │ ├── stm32f10x_rtc.h │ │ │ │ ├── stm32f10x_sdio.c │ │ │ │ ├── stm32f10x_sdio.h │ │ │ │ ├── stm32f10x_spi.c │ │ │ │ ├── stm32f10x_spi.h │ │ │ │ ├── stm32f10x_tim.c │ │ │ │ ├── stm32f10x_tim.h │ │ │ │ ├── stm32f10x_usart.c │ │ │ │ ├── stm32f10x_usart.h │ │ │ │ ├── stm32f10x_wwdg.c │ │ │ │ └── stm32f10x_wwdg.h │ │ │ └── stm32f10x_conf.h │ │ ├── DAP │ │ │ ├── DAP.c │ │ │ ├── DAP.h │ │ │ ├── JTAG_DP.c │ │ │ ├── SWO.c │ │ │ ├── SW_DP.c │ │ │ ├── debug_ca.h │ │ │ └── debug_cm.h │ │ ├── DAP_config.h │ │ ├── SWD_flash.c │ │ ├── SWD_flash.h │ │ ├── SWD_host.c │ │ ├── SWD_host.h │ │ ├── algo │ │ │ ├── STM32F10x_128.c │ │ │ ├── STM32F4xx_1024.c │ │ │ └── flash_blob.h │ │ ├── error.c │ │ ├── error.h │ │ └── main.c │ └── 原项目地址.txt │ ├── F405RG │ ├── 405swd.ioc │ ├── Drivers │ │ ├── CMSIS │ │ │ ├── Device │ │ │ │ └── ST │ │ │ │ │ └── STM32F4xx │ │ │ │ │ └── Include │ │ │ │ │ ├── stm32f405xx.h │ │ │ │ │ ├── stm32f4xx.h │ │ │ │ │ └── system_stm32f4xx.h │ │ │ └── Include │ │ │ │ ├── cmsis_armcc.h │ │ │ │ ├── cmsis_armclang.h │ │ │ │ ├── cmsis_compiler.h │ │ │ │ ├── cmsis_gcc.h │ │ │ │ ├── cmsis_iccarm.h │ │ │ │ ├── cmsis_version.h │ │ │ │ ├── core_armv8mbl.h │ │ │ │ ├── core_armv8mml.h │ │ │ │ ├── core_cm0.h │ │ │ │ ├── core_cm0plus.h │ │ │ │ ├── core_cm1.h │ │ │ │ ├── core_cm23.h │ │ │ │ ├── core_cm3.h │ │ │ │ ├── core_cm33.h │ │ │ │ ├── core_cm4.h │ │ │ │ ├── core_cm7.h │ │ │ │ ├── core_sc000.h │ │ │ │ ├── core_sc300.h │ │ │ │ ├── mpu_armv7.h │ │ │ │ ├── mpu_armv8.h │ │ │ │ └── tz_context.h │ │ └── STM32F4xx_HAL_Driver │ │ │ ├── Inc │ │ │ ├── Legacy │ │ │ │ └── stm32_hal_legacy.h │ │ │ ├── stm32f4xx_hal.h │ │ │ ├── stm32f4xx_hal_cortex.h │ │ │ ├── stm32f4xx_hal_def.h │ │ │ ├── stm32f4xx_hal_dma.h │ │ │ ├── stm32f4xx_hal_dma_ex.h │ │ │ ├── stm32f4xx_hal_exti.h │ │ │ ├── stm32f4xx_hal_flash.h │ │ │ ├── stm32f4xx_hal_flash_ex.h │ │ │ ├── stm32f4xx_hal_flash_ramfunc.h │ │ │ ├── stm32f4xx_hal_gpio.h │ │ │ ├── stm32f4xx_hal_gpio_ex.h │ │ │ ├── stm32f4xx_hal_pwr.h │ │ │ ├── stm32f4xx_hal_pwr_ex.h │ │ │ ├── stm32f4xx_hal_rcc.h │ │ │ ├── stm32f4xx_hal_rcc_ex.h │ │ │ ├── stm32f4xx_hal_tim.h │ │ │ └── stm32f4xx_hal_tim_ex.h │ │ │ └── Src │ │ │ ├── stm32f4xx_hal.c │ │ │ ├── stm32f4xx_hal_cortex.c │ │ │ ├── stm32f4xx_hal_dma.c │ │ │ ├── stm32f4xx_hal_dma_ex.c │ │ │ ├── stm32f4xx_hal_exti.c │ │ │ ├── stm32f4xx_hal_flash.c │ │ │ ├── stm32f4xx_hal_flash_ex.c │ │ │ ├── stm32f4xx_hal_flash_ramfunc.c │ │ │ ├── stm32f4xx_hal_gpio.c │ │ │ ├── stm32f4xx_hal_pwr.c │ │ │ ├── stm32f4xx_hal_pwr_ex.c │ │ │ ├── stm32f4xx_hal_rcc.c │ │ │ ├── stm32f4xx_hal_rcc_ex.c │ │ │ ├── stm32f4xx_hal_tim.c │ │ │ └── stm32f4xx_hal_tim_ex.c │ ├── Inc │ │ ├── gpio.h │ │ ├── main.h │ │ ├── stm32f4xx_hal_conf.h │ │ └── stm32f4xx_it.h │ ├── MDK-ARM │ │ ├── 405swd.uvguix.27731 │ │ ├── 405swd.uvoptx │ │ ├── 405swd.uvprojx │ │ ├── 405swd │ │ │ └── 405swd.hex │ │ ├── DebugConfig │ │ │ └── 405swd_STM32F405RGTx.dbgconf │ │ ├── RTE │ │ │ └── _405swd │ │ │ │ └── RTE_Components.h │ │ └── startup_stm32f405xx.s │ ├── Src │ │ ├── gpio.c │ │ ├── main.c │ │ ├── stm32f4xx_hal_msp.c │ │ ├── stm32f4xx_it.c │ │ └── system_stm32f4xx.c │ └── dap │ │ ├── DAP.c │ │ ├── DAP.h │ │ ├── DAP_config.h │ │ ├── JTAG_DP.c │ │ ├── STM32F10x_128.c │ │ ├── STM32F4xx_1024.c │ │ ├── SWD_flash.c │ │ ├── SWD_flash.h │ │ ├── SWD_host.c │ │ ├── SWD_host.h │ │ ├── SWO.c │ │ ├── SW_DP.c │ │ ├── debug_ca.h │ │ ├── debug_cm.h │ │ ├── error.c │ │ ├── error.h │ │ └── flash_blob.h │ ├── F407IG │ ├── Core │ │ ├── Inc │ │ │ ├── gpio.h │ │ │ ├── main.h │ │ │ ├── stm32f4xx_hal_conf.h │ │ │ └── stm32f4xx_it.h │ │ └── Src │ │ │ ├── gpio.c │ │ │ ├── main.c │ │ │ ├── stm32f4xx_hal_msp.c │ │ │ ├── stm32f4xx_it.c │ │ │ └── system_stm32f4xx.c │ ├── Drivers │ │ ├── CMSIS │ │ │ ├── Device │ │ │ │ └── ST │ │ │ │ │ └── STM32F4xx │ │ │ │ │ └── Include │ │ │ │ │ ├── stm32f407xx.h │ │ │ │ │ ├── stm32f4xx.h │ │ │ │ │ └── system_stm32f4xx.h │ │ │ └── Include │ │ │ │ ├── cmsis_armcc.h │ │ │ │ ├── cmsis_armclang.h │ │ │ │ ├── cmsis_compiler.h │ │ │ │ ├── cmsis_gcc.h │ │ │ │ ├── cmsis_iccarm.h │ │ │ │ ├── cmsis_version.h │ │ │ │ ├── core_armv8mbl.h │ │ │ │ ├── core_armv8mml.h │ │ │ │ ├── core_cm0.h │ │ │ │ ├── core_cm0plus.h │ │ │ │ ├── core_cm1.h │ │ │ │ ├── core_cm23.h │ │ │ │ ├── core_cm3.h │ │ │ │ ├── core_cm33.h │ │ │ │ ├── core_cm4.h │ │ │ │ ├── core_cm7.h │ │ │ │ ├── core_sc000.h │ │ │ │ ├── core_sc300.h │ │ │ │ ├── mpu_armv7.h │ │ │ │ ├── mpu_armv8.h │ │ │ │ └── tz_context.h │ │ └── STM32F4xx_HAL_Driver │ │ │ ├── Inc │ │ │ ├── Legacy │ │ │ │ └── stm32_hal_legacy.h │ │ │ ├── stm32f4xx_hal.h │ │ │ ├── stm32f4xx_hal_cortex.h │ │ │ ├── stm32f4xx_hal_def.h │ │ │ ├── stm32f4xx_hal_dma.h │ │ │ ├── stm32f4xx_hal_dma_ex.h │ │ │ ├── stm32f4xx_hal_exti.h │ │ │ ├── stm32f4xx_hal_flash.h │ │ │ ├── stm32f4xx_hal_flash_ex.h │ │ │ ├── stm32f4xx_hal_flash_ramfunc.h │ │ │ ├── stm32f4xx_hal_gpio.h │ │ │ ├── stm32f4xx_hal_gpio_ex.h │ │ │ ├── stm32f4xx_hal_pwr.h │ │ │ ├── stm32f4xx_hal_pwr_ex.h │ │ │ ├── stm32f4xx_hal_rcc.h │ │ │ ├── stm32f4xx_hal_rcc_ex.h │ │ │ ├── stm32f4xx_hal_tim.h │ │ │ └── stm32f4xx_hal_tim_ex.h │ │ │ └── Src │ │ │ ├── stm32f4xx_hal.c │ │ │ ├── stm32f4xx_hal_cortex.c │ │ │ ├── stm32f4xx_hal_dma.c │ │ │ ├── stm32f4xx_hal_dma_ex.c │ │ │ ├── stm32f4xx_hal_exti.c │ │ │ ├── stm32f4xx_hal_flash.c │ │ │ ├── stm32f4xx_hal_flash_ex.c │ │ │ ├── stm32f4xx_hal_flash_ramfunc.c │ │ │ ├── stm32f4xx_hal_gpio.c │ │ │ ├── stm32f4xx_hal_pwr.c │ │ │ ├── stm32f4xx_hal_pwr_ex.c │ │ │ ├── stm32f4xx_hal_rcc.c │ │ │ ├── stm32f4xx_hal_rcc_ex.c │ │ │ ├── stm32f4xx_hal_tim.c │ │ │ └── stm32f4xx_hal_tim_ex.c │ ├── MDK-ARM │ │ ├── DebugConfig │ │ │ └── swd_STM32F407IGTx.dbgconf │ │ ├── RTE │ │ │ └── _swd │ │ │ │ └── RTE_Components.h │ │ ├── startup_stm32f407xx.s │ │ ├── swd.uvguix.27731 │ │ ├── swd.uvoptx │ │ ├── swd.uvprojx │ │ └── swd │ │ │ └── swd.hex │ ├── dap │ │ ├── DAP.c │ │ ├── DAP.h │ │ ├── DAP_config.h │ │ ├── JTAG_DP.c │ │ ├── STM32F10x_128.c │ │ ├── STM32F4xx_1024.c │ │ ├── SWD_flash.c │ │ ├── SWD_flash.h │ │ ├── SWD_host.c │ │ ├── SWD_host.h │ │ ├── SWO.c │ │ ├── SW_DP.c │ │ ├── debug_ca.h │ │ ├── debug_cm.h │ │ ├── error.c │ │ ├── error.h │ │ └── flash_blob.h │ └── swd.ioc │ └── F730R8 │ ├── Drivers │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32F7xx │ │ │ │ └── Include │ │ │ │ ├── stm32f730xx.h │ │ │ │ ├── stm32f7xx.h │ │ │ │ └── system_stm32f7xx.h │ │ └── Include │ │ │ ├── cmsis_armcc.h │ │ │ ├── cmsis_armclang.h │ │ │ ├── cmsis_compiler.h │ │ │ ├── cmsis_gcc.h │ │ │ ├── cmsis_iccarm.h │ │ │ ├── cmsis_version.h │ │ │ ├── core_armv8mbl.h │ │ │ ├── core_armv8mml.h │ │ │ ├── core_cm0.h │ │ │ ├── core_cm0plus.h │ │ │ ├── core_cm1.h │ │ │ ├── core_cm23.h │ │ │ ├── core_cm3.h │ │ │ ├── core_cm33.h │ │ │ ├── core_cm4.h │ │ │ ├── core_cm7.h │ │ │ ├── core_sc000.h │ │ │ ├── core_sc300.h │ │ │ ├── mpu_armv7.h │ │ │ ├── mpu_armv8.h │ │ │ └── tz_context.h │ └── STM32F7xx_HAL_Driver │ │ ├── Inc │ │ ├── Legacy │ │ │ └── stm32_hal_legacy.h │ │ ├── stm32f7xx_hal.h │ │ ├── stm32f7xx_hal_adc.h │ │ ├── stm32f7xx_hal_adc_ex.h │ │ ├── stm32f7xx_hal_cortex.h │ │ ├── stm32f7xx_hal_def.h │ │ ├── stm32f7xx_hal_dma.h │ │ ├── stm32f7xx_hal_dma_ex.h │ │ ├── stm32f7xx_hal_exti.h │ │ ├── stm32f7xx_hal_flash.h │ │ ├── stm32f7xx_hal_flash_ex.h │ │ ├── stm32f7xx_hal_gpio.h │ │ ├── stm32f7xx_hal_gpio_ex.h │ │ ├── stm32f7xx_hal_i2c.h │ │ ├── stm32f7xx_hal_i2c_ex.h │ │ ├── stm32f7xx_hal_pwr.h │ │ ├── stm32f7xx_hal_pwr_ex.h │ │ ├── stm32f7xx_hal_rcc.h │ │ ├── stm32f7xx_hal_rcc_ex.h │ │ ├── stm32f7xx_hal_spi.h │ │ ├── stm32f7xx_hal_spi_ex.h │ │ ├── stm32f7xx_hal_tim.h │ │ ├── stm32f7xx_hal_tim_ex.h │ │ ├── stm32f7xx_hal_uart.h │ │ └── stm32f7xx_hal_uart_ex.h │ │ └── Src │ │ ├── stm32f7xx_hal.c │ │ ├── stm32f7xx_hal_adc.c │ │ ├── stm32f7xx_hal_adc_ex.c │ │ ├── stm32f7xx_hal_cortex.c │ │ ├── stm32f7xx_hal_dma.c │ │ ├── stm32f7xx_hal_dma_ex.c │ │ ├── stm32f7xx_hal_exti.c │ │ ├── stm32f7xx_hal_flash.c │ │ ├── stm32f7xx_hal_flash_ex.c │ │ ├── stm32f7xx_hal_gpio.c │ │ ├── stm32f7xx_hal_i2c.c │ │ ├── stm32f7xx_hal_i2c_ex.c │ │ ├── stm32f7xx_hal_pwr.c │ │ ├── stm32f7xx_hal_pwr_ex.c │ │ ├── stm32f7xx_hal_rcc.c │ │ ├── stm32f7xx_hal_rcc_ex.c │ │ ├── stm32f7xx_hal_spi.c │ │ ├── stm32f7xx_hal_spi_ex.c │ │ ├── stm32f7xx_hal_tim.c │ │ ├── stm32f7xx_hal_tim_ex.c │ │ ├── stm32f7xx_hal_uart.c │ │ └── stm32f7xx_hal_uart_ex.c │ ├── F730R8.ioc │ ├── Inc │ ├── adc.h │ ├── dma.h │ ├── gpio.h │ ├── main.h │ ├── spi.h │ ├── stm32f7xx_hal_conf.h │ ├── stm32f7xx_it.h │ └── usart.h │ ├── MDK-ARM │ ├── DebugConfig │ │ └── F730R8_STM32F730R8Tx_2.0.0.dbgconf │ ├── EventRecorderStub.scvd │ ├── F730R8.uvguix.27731 │ ├── F730R8.uvoptx │ ├── F730R8.uvprojx │ ├── F730R8 │ │ └── F730R8.hex │ ├── RTE │ │ └── _F730R8 │ │ │ └── RTE_Components.h │ └── startup_stm32f730xx.s │ ├── Src │ ├── adc.c │ ├── dma.c │ ├── gpio.c │ ├── main.c │ ├── spi.c │ ├── stm32f7xx_hal_msp.c │ ├── stm32f7xx_it.c │ ├── system_stm32f7xx.c │ └── usart.c │ └── dap │ ├── DAP.c │ ├── DAP.h │ ├── DAP_config.h │ ├── JTAG_DP.c │ ├── STM32F10x_128.c │ ├── STM32F4xx_1024.c │ ├── SWD_flash.c │ ├── SWD_flash.h │ ├── SWD_host.c │ ├── SWD_host.h │ ├── SWO.c │ ├── SW_DP.c │ ├── debug_ca.h │ ├── debug_cm.h │ ├── error.c │ ├── error.h │ └── flash_blob.h └── hardware ├── USB_Downloader.PcbDoc ├── USB_Downloader.PrjPcb ├── USB_Downloader.SchDoc ├── USB_Downloader_V1.2.PcbDoc ├── USB_Downloader_V1.2.SchDoc ├── V1.0 ├── USB_Downloader.PcbDoc ├── USB_Downloader.PrjPcb └── USB_Downloader.SchDoc ├── V1.1 ├── USB_Downloader.PcbDoc ├── USB_Downloader.PrjPcb └── USB_Downloader.SchDoc └── V1.2 ├── USB_Downloader.PcbDoc ├── USB_Downloader.PrjPcb └── USB_Downloader.SchDoc /Image/IMG_20211118_020216.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/IMG_20211118_020216.jpg -------------------------------------------------------------------------------- /Image/IMG_20211124_214435~01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/IMG_20211124_214435~01.jpg -------------------------------------------------------------------------------- /Image/IMG_20211127_203054~01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/IMG_20211127_203054~01.jpg -------------------------------------------------------------------------------- /Image/IMG_20211128_212951~01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/IMG_20211128_212951~01.jpg -------------------------------------------------------------------------------- /Image/IMG_20211128_221307~01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/IMG_20211128_221307~01.jpg -------------------------------------------------------------------------------- /Image/IMG_20211210_230506~01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/IMG_20211210_230506~01.jpg -------------------------------------------------------------------------------- /Image/IMG_20211212_175627~01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/IMG_20211212_175627~01.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211106103937.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211106103937.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211106104007.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211106104007.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211106104055.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211106104055.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211106104605.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211106104605.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211107002021.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211107002021.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211107003349.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211107003349.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211114205652.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211114205652.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211114205736.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211114205736.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211114205815.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211114205815.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211114205849.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211114205849.jpg -------------------------------------------------------------------------------- /Image/TIM截图20211128213619.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/Image/TIM截图20211128213619.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MyUSBDownloader 2 | 基于USB的离线固件更新器 3 | 4 | 滑动UI测试:https://www.bilibili.com/video/BV1m3411C7Za 5 | 6 | 离线下载功能测试:https://www.bilibili.com/video/BV1UL411M7vd 7 | 8 | ![IMG_20211128_221307](https://user-images.githubusercontent.com/23308519/146549043-1b21bc29-c150-414a-a603-37f572d35896.jpg) 9 | 10 | ![IMG_20211118_020216](https://user-images.githubusercontent.com/23308519/146549110-78322fd7-aa27-4c5f-adbd-12d014871cb9.jpg) 11 | 12 | ![IMG_20211127_203054](https://user-images.githubusercontent.com/23308519/146549170-8b4638a3-2625-433d-891f-d3341cd2b849.jpg) 13 | 14 | ![TIM截图20211106104055](https://user-images.githubusercontent.com/23308519/140595217-0ed3e551-dace-4f39-9003-48ba1a141ef5.jpg) 15 | 16 | ![TIM截图20211106104007](https://user-images.githubusercontent.com/23308519/140595224-ed43ef47-a276-4917-aba5-ec7ed828a77f.jpg) 17 | 18 | ![TIM截图20211106103937](https://user-images.githubusercontent.com/23308519/140595231-2d90a23c-c893-4010-a3fd-185477815e75.jpg) 19 | 20 | ![IMG_20211008_214713](https://user-images.githubusercontent.com/23308519/140595473-a07e1a33-9dbe-450e-93fc-e08753c3d83c.jpg) 21 | -------------------------------------------------------------------------------- /firmware/OLED迷宫游戏(游戏实现逻辑,需要自己加接口)/迷宫.h: -------------------------------------------------------------------------------- 1 | #ifndef __MG_H 2 | #define __MG_H 3 | 4 | //调用方法:mg_play(14,24,2); 5 | 6 | //最大迷宫宽高,是地图块的大小(地图复杂度),不是屏幕大小 7 | #define MG_W 32 8 | #define MG_H 64 9 | typedef struct 10 | { 11 | uint8_t msg[5]; 12 | }mg_gird; 13 | 14 | extern __IO mg_gird MapMain[MG_W][MG_H]; 15 | 16 | int randint(int p1,int p2); 17 | void Recursive_division(int left, int right, int top, int bottom); 18 | void test_mg(uint16_t x,uint16_t y,uint16_t wid,uint16_t size_x,uint16_t size_y); 19 | void play_cur(uint16_t x,uint16_t y,uint16_t w) 20 | void mg_play(uint8_t w,uint8_t h,uint8_t wi); 21 | 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/EventRecorderStub.scvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 XIVN1987 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/README.md: -------------------------------------------------------------------------------- 1 | # DAPProg 2 | Offline SWD Programmer for Cortex-M Core MCU 3 | 4 | This Project bases on some other open-source Project: 5 | 6 | 1、file under src/DAP and file SWD_host.c come form [ARMmbed/DAPLink](https://github.com/ARMmbed/DAPLink) 7 | 8 | 2、file /doc/FlashAlgo/flash_algo.py come from [mbedmicro/FlashAlgo](https://github.com/mbedmicro/FlashAlgo) 9 | 10 | flash_algo.py is used to extracting flash programming code from Keil's *.FLM algorithm file 11 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/doc/FlashAlgo/STM32F10x_128.FLM: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F103RC/doc/FlashAlgo/STM32F10x_128.FLM -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/doc/FlashAlgo/STM32F10x_128.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2015 ARM Limited 3 | */ 4 | #include "flash_blob.h" 5 | 6 | static const uint32_t flash_code[] = { 7 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 8 | 0x4603B510, 0x4C442000, 0x48446020, 0x48446060, 0x46206060, 0xF01069C0, 0xD1080F04, 0x5055F245, 9 | 0x60204C40, 0x60602006, 0x70FFF640, 0x200060A0, 0x4601BD10, 0x69004838, 0x0080F040, 0x61104A36, 10 | 0x47702000, 0x69004834, 0x0004F040, 0x61084932, 0x69004608, 0x0040F040, 0xE0036108, 0x20AAF64A, 11 | 0x60084930, 0x68C0482C, 0x0F01F010, 0x482AD1F6, 0xF0206900, 0x49280004, 0x20006108, 0x46014770, 12 | 0x69004825, 0x0002F040, 0x61104A23, 0x61414610, 0xF0406900, 0x61100040, 0xF64AE003, 0x4A2120AA, 13 | 0x481D6010, 0xF01068C0, 0xD1F60F01, 0x6900481A, 0x0002F020, 0x61104A18, 0x47702000, 0x4603B510, 14 | 0xF0201C48, 0xE0220101, 0x69004813, 0x0001F040, 0x61204C11, 0x80188810, 0x480FBF00, 0xF01068C0, 15 | 0xD1FA0F01, 0x6900480C, 0x0001F020, 0x61204C0A, 0x68C04620, 0x0F14F010, 0x4620D006, 0xF04068C0, 16 | 0x60E00014, 0xBD102001, 0x1C921C9B, 0x29001E89, 0x2000D1DA, 0x0000E7F7, 0x40022000, 0x45670123, 17 | 0xCDEF89AB, 0x40003000, 0x00000000 18 | }; 19 | 20 | const program_target_t flash_algo = { 21 | 0x20000021, // Init 22 | 0x20000053, // UnInit 23 | 0x20000065, // EraseChip 24 | 0x2000009F, // EraseSector 25 | 0x200000DD, // ProgramPage 26 | 27 | // BKPT : start of blob + 1 28 | // RSB : address to access global/static data 29 | // RSP : stack pointer 30 | { 31 | 0x20000001, 32 | 0x20000C00, 33 | 0x20001000 34 | }, 35 | 36 | 0x20000400, // mem buffer location 37 | 0x20000000, // location to write prog_blob in target RAM 38 | sizeof(flash_code), // prog_blob size 39 | flash_code, // address of prog_blob 40 | 0x00000400, // ram_to_flash_bytes_to_be_written 41 | }; 42 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/doc/FlashAlgo/STM32F4xx_1024.FLM: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F103RC/doc/FlashAlgo/STM32F4xx_1024.FLM -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/doc/FlashAlgo/STM32F4xx_1024.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2015 ARM Limited 3 | */ 4 | #include "flash_blob.h" 5 | 6 | static const uint32_t flash_code[] = { 7 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 8 | 0x0E000300, 0xD3022820, 0x1D000940, 0x28104770, 0x0900D302, 0x47701CC0, 0x47700880, 0x49414842, 9 | 0x49426041, 0x21006041, 0x68C16001, 0x431122F0, 0x694060C1, 0xD4060680, 0x493D483E, 0x21066001, 10 | 0x493D6041, 0x20006081, 0x48374770, 0x05426901, 0x61014311, 0x47702000, 0x4833B510, 0x24046901, 11 | 0x61014321, 0x03A26901, 0x61014311, 0x4A314933, 0x6011E000, 0x03DB68C3, 0x6901D4FB, 0x610143A1, 12 | 0xBD102000, 0xF7FFB530, 0x4927FFBB, 0x23F068CA, 0x60CA431A, 0x610C2402, 0x0700690A, 0x43020E40, 13 | 0x6908610A, 0x431003E2, 0x48246108, 0xE0004A21, 0x68CD6010, 0xD4FB03ED, 0x43A06908, 0x68C86108, 14 | 0x0F000600, 0x68C8D003, 0x60C84318, 0xBD302001, 0x4D15B570, 0x08891CC9, 0x008968EB, 0x433326F0, 15 | 0x230060EB, 0x4B16612B, 0x692CE017, 0x612C431C, 0x60046814, 0x03E468EC, 0x692CD4FC, 0x00640864, 16 | 0x68EC612C, 0x0F240624, 0x68E8D004, 0x60E84330, 0xBD702001, 0x1D121D00, 0x29001F09, 0x2000D1E5, 17 | 0x0000BD70, 0x45670123, 0x40023C00, 0xCDEF89AB, 0x00005555, 0x40003000, 0x00000FFF, 0x0000AAAA, 18 | 0x00000201, 0x00000000 19 | }; 20 | 21 | const program_target_t flash_algo = { 22 | 0x2000003D, // Init 23 | 0x2000006B, // UnInit 24 | 0x20000079, // EraseChip 25 | 0x200000A5, // EraseSector 26 | 0x200000F1, // ProgramPage 27 | 28 | // BKPT : start of blob + 1 29 | // RSB : address to access global/static data 30 | // RSP : stack pointer 31 | { 32 | 0x20000001, 33 | 0x20000C00, 34 | 0x20001000 35 | }, 36 | 37 | 0x20000400, // mem buffer location 38 | 0x20000000, // location to write prog_blob in target RAM 39 | sizeof(flash_code), // prog_blob size 40 | flash_code, // address of prog_blob 41 | 0x00000400, // ram_to_flash_bytes_to_be_written 42 | }; 43 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/keilkilll.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F103RC/keilkilll.bat -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/out/DAPProg.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F103RC/out/DAPProg.bin -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/CMSIS/CoreSupport/arm_const_structs.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 31. July 2014 5 | * $Revision: V1.4.4 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_const_structs.h 9 | * 10 | * Description: This file has constant structs that are initialized for 11 | * user convenience. For example, some can be given as 12 | * arguments to the arm_cfft_f32() function. 13 | * 14 | * Target Processor: Cortex-M4/Cortex-M3 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions 18 | * are met: 19 | * - Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * - Redistributions in binary form must reproduce the above copyright 22 | * notice, this list of conditions and the following disclaimer in 23 | * the documentation and/or other materials provided with the 24 | * distribution. 25 | * - Neither the name of ARM LIMITED nor the names of its contributors 26 | * may be used to endorse or promote products derived from this 27 | * software without specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 32 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 33 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 34 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 35 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 36 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 39 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 40 | * POSSIBILITY OF SUCH DAMAGE. 41 | * -------------------------------------------------------------------- */ 42 | 43 | #ifndef _ARM_CONST_STRUCTS_H 44 | #define _ARM_CONST_STRUCTS_H 45 | 46 | #include "arm_math.h" 47 | #include "arm_common_tables.h" 48 | 49 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16; 50 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32; 51 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64; 52 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128; 53 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256; 54 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512; 55 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024; 56 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048; 57 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096; 58 | 59 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16; 60 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32; 61 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64; 62 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128; 63 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256; 64 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512; 65 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024; 66 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048; 67 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096; 68 | 69 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16; 70 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32; 71 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64; 72 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128; 73 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256; 74 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512; 75 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024; 76 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048; 77 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/CMSIS/DeviceSupport/stm32f10x.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F103RC/src/CSL/CMSIS/DeviceSupport/stm32f10x.h -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/CMSIS/DeviceSupport/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /** @addtogroup CMSIS 23 | * @{ 24 | */ 25 | 26 | /** @addtogroup stm32f10x_system 27 | * @{ 28 | */ 29 | 30 | /** 31 | * @brief Define to prevent recursive inclusion 32 | */ 33 | #ifndef __SYSTEM_STM32F10X_H 34 | #define __SYSTEM_STM32F10X_H 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** @addtogroup STM32F10x_System_Includes 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @addtogroup STM32F10x_System_Exported_types 50 | * @{ 51 | */ 52 | 53 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @addtogroup STM32F10x_System_Exported_Constants 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @addtogroup STM32F10x_System_Exported_Macros 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Functions 76 | * @{ 77 | */ 78 | 79 | extern void SystemInit(void); 80 | extern void SystemCoreClockUpdate(void); 81 | /** 82 | * @} 83 | */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /*__SYSTEM_STM32F10X_H */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 99 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/STM32F10x_StdPeriph_Driver/stm32f10x_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the CRC firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_crc.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup CRC 30 | * @brief CRC driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup CRC_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup CRC_Private_Defines 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Private_Macros 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Private_FunctionPrototypes 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup CRC_Private_Functions 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @brief Resets the CRC Data register (DR). 80 | * @param None 81 | * @retval None 82 | */ 83 | void CRC_ResetDR(void) 84 | { 85 | /* Reset CRC generator */ 86 | CRC->CR = CRC_CR_RESET; 87 | } 88 | 89 | /** 90 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 91 | * @param Data: data word(32-bit) to compute its CRC 92 | * @retval 32-bit CRC 93 | */ 94 | uint32_t CRC_CalcCRC(uint32_t Data) 95 | { 96 | CRC->DR = Data; 97 | 98 | return (CRC->DR); 99 | } 100 | 101 | /** 102 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 103 | * @param pBuffer: pointer to the buffer containing the data to be computed 104 | * @param BufferLength: length of the buffer to be computed 105 | * @retval 32-bit CRC 106 | */ 107 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 108 | { 109 | uint32_t index = 0; 110 | 111 | for(index = 0; index < BufferLength; index++) 112 | { 113 | CRC->DR = pBuffer[index]; 114 | } 115 | return (CRC->DR); 116 | } 117 | 118 | /** 119 | * @brief Returns the current CRC value. 120 | * @param None 121 | * @retval 32-bit CRC 122 | */ 123 | uint32_t CRC_GetCRC(void) 124 | { 125 | return (CRC->DR); 126 | } 127 | 128 | /** 129 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 130 | * @param IDValue: 8-bit value to be stored in the ID register 131 | * @retval None 132 | */ 133 | void CRC_SetIDRegister(uint8_t IDValue) 134 | { 135 | CRC->IDR = IDValue; 136 | } 137 | 138 | /** 139 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 140 | * @param None 141 | * @retval 8-bit value of the ID register 142 | */ 143 | uint8_t CRC_GetIDRegister(void) 144 | { 145 | return (CRC->IDR); 146 | } 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 161 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/STM32F10x_StdPeriph_Driver/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_CRC_H 25 | #define __STM32F10x_CRC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup CRC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup CRC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Exported_Macros 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Exported_Functions 67 | * @{ 68 | */ 69 | 70 | void CRC_ResetDR(void); 71 | uint32_t CRC_CalcCRC(uint32_t Data); 72 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 73 | uint32_t CRC_GetCRC(void); 74 | void CRC_SetIDRegister(uint8_t IDValue); 75 | uint8_t CRC_GetIDRegister(void); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __STM32F10x_CRC_H */ 82 | /** 83 | * @} 84 | */ 85 | 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 95 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/STM32F10x_StdPeriph_Driver/stm32f10x_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the DBGMCU 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_DBGMCU_H 25 | #define __STM32F10x_DBGMCU_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup DBGMCU 39 | * @{ 40 | */ 41 | 42 | /** @defgroup DBGMCU_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup DBGMCU_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 55 | #define DBGMCU_STOP ((uint32_t)0x00000002) 56 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 57 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100) 58 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200) 59 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400) 60 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800) 61 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000) 62 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000) 63 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000) 64 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000) 65 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000) 66 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000) 67 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000) 68 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000) 69 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000) 70 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000) 71 | #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000) 72 | #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000) 73 | #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000) 74 | #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000) 75 | #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000) 76 | #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000) 77 | #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000) 78 | #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000) 79 | #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000) 80 | 81 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup DBGMCU_Exported_Macros 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup DBGMCU_Exported_Functions 95 | * @{ 96 | */ 97 | 98 | uint32_t DBGMCU_GetREVID(void); 99 | uint32_t DBGMCU_GetDEVID(void); 100 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* __STM32F10x_DBGMCU_H */ 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/STM32F10x_StdPeriph_Driver/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F103RC/src/CSL/STM32F10x_StdPeriph_Driver/stm32f10x_flash.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/STM32F10x_StdPeriph_Driver/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F103RC/src/CSL/STM32F10x_StdPeriph_Driver/stm32f10x_i2c.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/STM32F10x_StdPeriph_Driver/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F103RC/src/CSL/STM32F10x_StdPeriph_Driver/stm32f10x_usart.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/STM32F10x_StdPeriph_Driver/stm32f10x_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_WWDG_H 25 | #define __STM32F10x_WWDG_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup WWDG 39 | * @{ 40 | */ 41 | 42 | /** @defgroup WWDG_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup WWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup WWDG_Prescaler 55 | * @{ 56 | */ 57 | 58 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 59 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 60 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 61 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 62 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 63 | ((PRESCALER) == WWDG_Prescaler_2) || \ 64 | ((PRESCALER) == WWDG_Prescaler_4) || \ 65 | ((PRESCALER) == WWDG_Prescaler_8)) 66 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 67 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup WWDG_Exported_Macros 78 | * @{ 79 | */ 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup WWDG_Exported_Functions 85 | * @{ 86 | */ 87 | 88 | void WWDG_DeInit(void); 89 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 90 | void WWDG_SetWindowValue(uint8_t WindowValue); 91 | void WWDG_EnableIT(void); 92 | void WWDG_SetCounter(uint8_t Counter); 93 | void WWDG_Enable(uint8_t Counter); 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F10x_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 116 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/CSL/stm32f10x_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_conf.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_CONF_H 24 | #define __STM32F10x_CONF_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | /* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */ 28 | #include "stm32f10x_adc.h" 29 | #include "stm32f10x_bkp.h" 30 | #include "stm32f10x_can.h" 31 | #include "stm32f10x_cec.h" 32 | #include "stm32f10x_crc.h" 33 | #include "stm32f10x_dac.h" 34 | #include "stm32f10x_dbgmcu.h" 35 | #include "stm32f10x_dma.h" 36 | #include "stm32f10x_exti.h" 37 | #include "stm32f10x_flash.h" 38 | #include "stm32f10x_fsmc.h" 39 | #include "stm32f10x_gpio.h" 40 | #include "stm32f10x_i2c.h" 41 | #include "stm32f10x_iwdg.h" 42 | #include "stm32f10x_pwr.h" 43 | #include "stm32f10x_rcc.h" 44 | #include "stm32f10x_rtc.h" 45 | #include "stm32f10x_sdio.h" 46 | #include "stm32f10x_spi.h" 47 | #include "stm32f10x_tim.h" 48 | #include "stm32f10x_usart.h" 49 | #include "stm32f10x_wwdg.h" 50 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 51 | 52 | /* Exported types ------------------------------------------------------------*/ 53 | /* Exported constants --------------------------------------------------------*/ 54 | /* Uncomment the line below to expanse the "assert_param" macro in the 55 | Standard Peripheral Library drivers code */ 56 | /* #define USE_FULL_ASSERT 1 */ 57 | 58 | /* Exported macro ------------------------------------------------------------*/ 59 | #ifdef USE_FULL_ASSERT 60 | 61 | /** 62 | * @brief The assert_param macro is used for function's parameters check. 63 | * @param expr: If expr is false, it calls assert_failed function which reports 64 | * the name of the source file and the source line number of the call 65 | * that failed. If expr is true, it returns no value. 66 | * @retval None 67 | */ 68 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 69 | /* Exported functions ------------------------------------------------------- */ 70 | void assert_failed(uint8_t* file, uint32_t line); 71 | #else 72 | #define assert_param(expr) ((void)0) 73 | #endif /* USE_FULL_ASSERT */ 74 | 75 | #endif /* __STM32F10x_CONF_H */ 76 | 77 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/SWD_flash.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SWD_flash.c 3 | * @brief Program target flash through SWD 4 | */ 5 | #include "swd_host.h" 6 | #include "SWD_flash.h" 7 | 8 | 9 | extern const program_target_t flash_algo; 10 | 11 | 12 | error_t target_flash_init(uint32_t flash_start) 13 | { 14 | if (0 == swd_set_target_state_hw(RESET_PROGRAM)) { 15 | return ERROR_RESET; 16 | } 17 | 18 | // Download flash programming algorithm to target and initialise. 19 | if (0 == swd_write_memory(flash_algo.algo_start, (uint8_t *)flash_algo.algo_blob, flash_algo.algo_size)) { 20 | return ERROR_ALGO_DL; 21 | } 22 | 23 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.init, flash_start, 0, 0, 0)) { 24 | return ERROR_INIT; 25 | } 26 | 27 | return ERROR_SUCCESS; 28 | } 29 | 30 | error_t target_flash_uninit(void) 31 | { 32 | swd_set_target_state_hw(RESET_RUN); 33 | 34 | swd_off(); 35 | return ERROR_SUCCESS; 36 | } 37 | 38 | error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size) 39 | { 40 | while (size > 0) { 41 | uint32_t write_size = size > flash_algo.program_buffer_size ? flash_algo.program_buffer_size : size; 42 | 43 | // Write page to buffer 44 | if (!swd_write_memory(flash_algo.program_buffer, (uint8_t *)buf, write_size)) { 45 | return ERROR_ALGO_DATA_SEQ; 46 | } 47 | 48 | // Run flash programming 49 | if (!swd_flash_syscall_exec(&flash_algo.sys_call_s, 50 | flash_algo.program_page, 51 | addr, 52 | flash_algo.program_buffer_size, 53 | flash_algo.program_buffer, 54 | 0)) { 55 | return ERROR_WRITE; 56 | } 57 | 58 | addr += write_size; 59 | buf += write_size; 60 | size -= write_size; 61 | } 62 | 63 | return ERROR_SUCCESS; 64 | } 65 | 66 | error_t target_flash_erase_sector(uint32_t addr) 67 | { 68 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.erase_sector, addr, 0, 0, 0)) { 69 | return ERROR_ERASE_SECTOR; 70 | } 71 | 72 | return ERROR_SUCCESS; 73 | } 74 | 75 | error_t target_flash_erase_chip(void) 76 | { 77 | error_t status = ERROR_SUCCESS; 78 | 79 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.erase_chip, 0, 0, 0, 0)) { 80 | return ERROR_ERASE_ALL; 81 | } 82 | 83 | return status; 84 | } 85 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/SWD_flash.h: -------------------------------------------------------------------------------- 1 | #ifndef __SWD_FLASH_H__ 2 | #define __SWD_FLASH_H__ 3 | 4 | #include 5 | 6 | #include "error.h" 7 | 8 | error_t target_flash_init(uint32_t flash_start); 9 | error_t target_flash_uninit(void); 10 | error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size); 11 | error_t target_flash_erase_sector(uint32_t addr); 12 | error_t target_flash_erase_chip(void); 13 | 14 | 15 | #endif // __SWD_FLASH_H__ 16 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/SWD_host.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F103RC/src/SWD_host.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/SWD_host.h: -------------------------------------------------------------------------------- 1 | #ifndef SWDHOST_CM_H 2 | #define SWDHOST_CM_H 3 | 4 | #include 5 | 6 | #include "algo/flash_blob.h" 7 | 8 | 9 | typedef enum { 10 | RESET_HOLD, // Hold target in reset 11 | RESET_PROGRAM, // Reset target and setup for flash programming. 12 | RESET_RUN, // Reset target and run normally 13 | NO_DEBUG, // Disable debug on running target 14 | DEBUG, // Enable debug on running target 15 | HALT, // Halt the target without resetting it 16 | RUN // Resume the target without resetting it 17 | } TARGET_RESET_STATE; 18 | 19 | 20 | uint8_t swd_init(void); 21 | uint8_t swd_off(void); 22 | uint8_t swd_init_debug(void); 23 | uint8_t swd_read_dp(uint8_t adr, uint32_t *val); 24 | uint8_t swd_write_dp(uint8_t adr, uint32_t val); 25 | uint8_t swd_read_ap(uint32_t adr, uint32_t *val); 26 | uint8_t swd_write_ap(uint32_t adr, uint32_t val); 27 | uint8_t swd_read_memory(uint32_t address, uint8_t *data, uint32_t size); 28 | uint8_t swd_write_memory(uint32_t address, uint8_t *data, uint32_t size); 29 | uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4); 30 | void swd_set_target_reset(uint8_t asserted); 31 | uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state); 32 | uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/algo/STM32F10x_128.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2015 ARM Limited 3 | */ 4 | #include "flash_blob.h" 5 | 6 | #if 1 7 | 8 | static const uint32_t flash_code[] = { 9 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 10 | 0x4603B510, 0x4C442000, 0x48446020, 0x48446060, 0x46206060, 0xF01069C0, 0xD1080F04, 0x5055F245, 11 | 0x60204C40, 0x60602006, 0x70FFF640, 0x200060A0, 0x4601BD10, 0x69004838, 0x0080F040, 0x61104A36, 12 | 0x47702000, 0x69004834, 0x0004F040, 0x61084932, 0x69004608, 0x0040F040, 0xE0036108, 0x20AAF64A, 13 | 0x60084930, 0x68C0482C, 0x0F01F010, 0x482AD1F6, 0xF0206900, 0x49280004, 0x20006108, 0x46014770, 14 | 0x69004825, 0x0002F040, 0x61104A23, 0x61414610, 0xF0406900, 0x61100040, 0xF64AE003, 0x4A2120AA, 15 | 0x481D6010, 0xF01068C0, 0xD1F60F01, 0x6900481A, 0x0002F020, 0x61104A18, 0x47702000, 0x4603B510, 16 | 0xF0201C48, 0xE0220101, 0x69004813, 0x0001F040, 0x61204C11, 0x80188810, 0x480FBF00, 0xF01068C0, 17 | 0xD1FA0F01, 0x6900480C, 0x0001F020, 0x61204C0A, 0x68C04620, 0x0F14F010, 0x4620D006, 0xF04068C0, 18 | 0x60E00014, 0xBD102001, 0x1C921C9B, 0x29001E89, 0x2000D1DA, 0x0000E7F7, 0x40022000, 0x45670123, 19 | 0xCDEF89AB, 0x40003000, 0x00000000 20 | }; 21 | 22 | const program_target_t flash_algo = { 23 | 0x20000021, // Init 24 | 0x20000053, // UnInit 25 | 0x20000065, // EraseChip 26 | 0x2000009F, // EraseSector 27 | 0x200000DD, // ProgramPage 28 | 29 | // BKPT : start of blob + 1 30 | // RSB : address to access global/static data 31 | // RSP : stack pointer 32 | { 33 | 0x20000001, 34 | 0x20000C00, 35 | 0x20001000 36 | }, 37 | 38 | 0x20000400, // mem buffer location 39 | 0x20000000, // location to write prog_blob in target RAM 40 | sizeof(flash_code), // prog_blob size 41 | flash_code, // address of prog_blob 42 | 0x00000400, // ram_to_flash_bytes_to_be_written 43 | }; 44 | 45 | #else 46 | 47 | static const uint32_t flash_code[] = { 48 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 49 | 0x0E000300, 0xD3022820, 0x1D000940, 0x28104770, 0x0900D302, 0x47701CC0, 0x47700880, 0x49414842, 50 | 0x49426041, 0x21006041, 0x68C16001, 0x431122F0, 0x694060C1, 0xD4060680, 0x493D483E, 0x21066001, 51 | 0x493D6041, 0x20006081, 0x48374770, 0x05426901, 0x61014311, 0x47702000, 0x4833B510, 0x24046901, 52 | 0x61014321, 0x03A26901, 0x61014311, 0x4A314933, 0x6011E000, 0x03DB68C3, 0x6901D4FB, 0x610143A1, 53 | 0xBD102000, 0xF7FFB530, 0x4927FFBB, 0x23F068CA, 0x60CA431A, 0x610C2402, 0x0700690A, 0x43020E40, 54 | 0x6908610A, 0x431003E2, 0x48246108, 0xE0004A21, 0x68CD6010, 0xD4FB03ED, 0x43A06908, 0x68C86108, 55 | 0x0F000600, 0x68C8D003, 0x60C84318, 0xBD302001, 0x4D15B570, 0x08891CC9, 0x008968EB, 0x433326F0, 56 | 0x230060EB, 0x4B16612B, 0x692CE017, 0x612C431C, 0x60046814, 0x03E468EC, 0x692CD4FC, 0x00640864, 57 | 0x68EC612C, 0x0F240624, 0x68E8D004, 0x60E84330, 0xBD702001, 0x1D121D00, 0x29001F09, 0x2000D1E5, 58 | 0x0000BD70, 0x45670123, 0x40023C00, 0xCDEF89AB, 0x00005555, 0x40003000, 0x00000FFF, 0x0000AAAA, 59 | 0x00000201, 0x00000000 60 | }; 61 | 62 | const program_target_t flash_algo = { 63 | 0x2000003D, // Init 64 | 0x2000006B, // UnInit 65 | 0x20000079, // EraseChip 66 | 0x200000A5, // EraseSector 67 | 0x200000F1, // ProgramPage 68 | 69 | // BKPT : start of blob + 1 70 | // RSB : address to access global/static data 71 | // RSP : stack pointer 72 | { 73 | 0x20000001, 74 | 0x20000C00, 75 | 0x20001000 76 | }, 77 | 78 | 0x20000400, // mem buffer location 79 | 0x20000000, // location to write prog_blob in target RAM 80 | sizeof(flash_code), // prog_blob size 81 | flash_code, // address of prog_blob 82 | 0x00000400, // ram_to_flash_bytes_to_be_written 83 | }; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/algo/STM32F4xx_1024.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2015 ARM Limited 3 | */ 4 | #include "flash_blob.h" 5 | 6 | static const uint32_t flash_code[] = { 7 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 8 | 0x0E000300, 0xD3022820, 0x1D000940, 0x28104770, 0x0900D302, 0x47701CC0, 0x47700880, 0x49414842, 9 | 0x49426041, 0x21006041, 0x68C16001, 0x431122F0, 0x694060C1, 0xD4060680, 0x493D483E, 0x21066001, 10 | 0x493D6041, 0x20006081, 0x48374770, 0x05426901, 0x61014311, 0x47702000, 0x4833B510, 0x24046901, 11 | 0x61014321, 0x03A26901, 0x61014311, 0x4A314933, 0x6011E000, 0x03DB68C3, 0x6901D4FB, 0x610143A1, 12 | 0xBD102000, 0xF7FFB530, 0x4927FFBB, 0x23F068CA, 0x60CA431A, 0x610C2402, 0x0700690A, 0x43020E40, 13 | 0x6908610A, 0x431003E2, 0x48246108, 0xE0004A21, 0x68CD6010, 0xD4FB03ED, 0x43A06908, 0x68C86108, 14 | 0x0F000600, 0x68C8D003, 0x60C84318, 0xBD302001, 0x4D15B570, 0x08891CC9, 0x008968EB, 0x433326F0, 15 | 0x230060EB, 0x4B16612B, 0x692CE017, 0x612C431C, 0x60046814, 0x03E468EC, 0x692CD4FC, 0x00640864, 16 | 0x68EC612C, 0x0F240624, 0x68E8D004, 0x60E84330, 0xBD702001, 0x1D121D00, 0x29001F09, 0x2000D1E5, 17 | 0x0000BD70, 0x45670123, 0x40023C00, 0xCDEF89AB, 0x00005555, 0x40003000, 0x00000FFF, 0x0000AAAA, 18 | 0x00000201, 0x00000000 19 | }; 20 | 21 | const program_target_t flash_algo = { 22 | 0x2000003D, // Init 23 | 0x2000006B, // UnInit 24 | 0x20000079, // EraseChip 25 | 0x200000A5, // EraseSector 26 | 0x200000F1, // ProgramPage 27 | 28 | // BKPT : start of blob + 1 29 | // RSB : address to access global/static data 30 | // RSP : stack pointer 31 | { 32 | 0x20000001, 33 | 0x20000C00, 34 | 0x20001000 35 | }, 36 | 37 | 0x20000400, // mem buffer location 38 | 0x20000000, // location to write prog_blob in target RAM 39 | sizeof(flash_code), // prog_blob size 40 | flash_code, // address of prog_blob 41 | 0x00000400, // ram_to_flash_bytes_to_be_written 42 | }; 43 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/algo/flash_blob.h: -------------------------------------------------------------------------------- 1 | #ifndef FLASH_BLOB_H 2 | #define FLASH_BLOB_H 3 | 4 | #include 5 | 6 | 7 | typedef struct { 8 | uint32_t breakpoint; 9 | uint32_t static_base; 10 | uint32_t stack_pointer; 11 | } program_syscall_t; 12 | 13 | typedef struct { 14 | const uint32_t init; 15 | const uint32_t uninit; 16 | const uint32_t erase_chip; 17 | const uint32_t erase_sector; 18 | const uint32_t program_page; 19 | const program_syscall_t sys_call_s; 20 | const uint32_t program_buffer; 21 | const uint32_t algo_start; 22 | const uint32_t algo_size; 23 | const uint32_t *algo_blob; 24 | const uint32_t program_buffer_size; 25 | } program_target_t; 26 | 27 | typedef struct { 28 | const uint32_t start; 29 | const uint32_t size; 30 | } sector_info_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/error.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file error.c 3 | * @brief collection of known errors and accessor for the friendly string 4 | */ 5 | 6 | #include "error.h" 7 | 8 | static const char *const error_message[] = { 9 | 10 | /* Shared errors */ 11 | 12 | // ERROR_SUCCESS 13 | "Operation was successful", 14 | // ERROR_FAILURE 15 | "An error has occurred", 16 | // ERROR_INTERNAL 17 | "An internal error has occurred", 18 | 19 | 20 | /* Target flash errors */ 21 | 22 | // ERROR_RESET 23 | "The interface firmware FAILED to reset/halt the target MCU", 24 | // ERROR_ALGO_DL 25 | "The interface firmware FAILED to download the flash programming algorithms to the target MCU", 26 | // ERROR_ALGO_DATA_SEQ 27 | "The interface firmware FAILED to download the flash data contents to be programmed", 28 | // ERROR_INIT 29 | "The interface firmware FAILED to initialize the target MCU", 30 | // ERROR_SECURITY_BITS 31 | "The interface firmware ABORTED programming. Image is trying to set security bits", 32 | // ERROR_UNLOCK 33 | "The interface firmware FAILED to unlock the target for programming", 34 | // ERROR_ERASE_SECTOR 35 | "Flash algorithm erase sector command FAILURE", 36 | // ERROR_ERASE_ALL 37 | "Flash algorithm erase all command FAILURE", 38 | // ERROR_WRITE 39 | "Flash algorithm write command FAILURE", 40 | }; 41 | 42 | static error_type_t error_type[] = { 43 | 44 | /* These should always stay the same for each error type. */ 45 | 46 | // ERROR_SUCCESS 47 | 0, 48 | // ERROR_FAILURE 49 | ERROR_TYPE_INTERNAL, 50 | // ERROR_INTERNAL 51 | ERROR_TYPE_INTERNAL, 52 | 53 | 54 | /* Target flash errors */ 55 | 56 | // ERROR_RESET 57 | ERROR_TYPE_TARGET, 58 | // ERROR_ALGO_DL 59 | ERROR_TYPE_TARGET, 60 | // ERROR_ALGO_DATA_SEQ 61 | ERROR_TYPE_TARGET, 62 | // ERROR_INIT 63 | ERROR_TYPE_TARGET, 64 | // ERROR_SECURITY_BITS 65 | ERROR_TYPE_USER, 66 | // ERROR_UNLOCK 67 | ERROR_TYPE_TARGET, 68 | // ERROR_ERASE_SECTOR 69 | ERROR_TYPE_TARGET, 70 | // ERROR_ERASE_ALL 71 | ERROR_TYPE_TARGET, 72 | // ERROR_WRITE 73 | ERROR_TYPE_TARGET, 74 | }; 75 | 76 | const char *error_get_string(error_t error) 77 | { 78 | const char *msg = 0; 79 | 80 | if (error < ERROR_COUNT) { 81 | msg = error_message[error]; 82 | } 83 | 84 | return msg; 85 | } 86 | 87 | error_type_t error_get_type(error_t error) 88 | { 89 | error_type_t type = ERROR_TYPE_INTERNAL; 90 | 91 | if (error < ERROR_COUNT) { 92 | type = error_type[error]; 93 | } 94 | 95 | return type; 96 | } 97 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/error.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_H 2 | #define ERROR_H 3 | 4 | 5 | // Keep in sync with the lists error_message and error_type 6 | typedef enum { 7 | /* Shared errors */ 8 | ERROR_SUCCESS = 0, 9 | ERROR_FAILURE, 10 | ERROR_INTERNAL, 11 | 12 | /* Target flash errors */ 13 | ERROR_RESET, 14 | ERROR_ALGO_DL, 15 | ERROR_ALGO_DATA_SEQ, 16 | ERROR_INIT, 17 | ERROR_SECURITY_BITS, 18 | ERROR_UNLOCK, 19 | ERROR_ERASE_SECTOR, 20 | ERROR_ERASE_ALL, 21 | ERROR_WRITE, 22 | 23 | // Add new values here 24 | 25 | ERROR_COUNT 26 | } error_t; 27 | 28 | 29 | typedef unsigned char error_type_t; 30 | 31 | #define ERROR_TYPE_INTERNAL 0x1 32 | #define ERROR_TYPE_TRANSIENT 0x2 33 | #define ERROR_TYPE_USER 0x4 34 | #define ERROR_TYPE_TARGET 0x8 35 | 36 | #define ERROR_TYPE_MASK 0xF 37 | 38 | 39 | const char *error_get_string(error_t error); 40 | 41 | error_type_t error_get_type(error_t error); 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/src/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F103RC/src/main.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F103RC/原项目地址.txt: -------------------------------------------------------------------------------- 1 | 原项目地址:https://github.com/XIVN1987/DAPProg -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F405RG/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /** @addtogroup CMSIS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup stm32f4xx_system 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Define to prevent recursive inclusion 46 | */ 47 | #ifndef __SYSTEM_STM32F4XX_H 48 | #define __SYSTEM_STM32F4XX_H 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /** @addtogroup STM32F4xx_System_Includes 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @addtogroup STM32F4xx_System_Exported_types 64 | * @{ 65 | */ 66 | /* This variable is updated in three ways: 67 | 1) by calling CMSIS function SystemCoreClockUpdate() 68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 70 | Note: If you use this function to configure the system clock; then there 71 | is no need to call the 2 first functions listed above, since SystemCoreClock 72 | variable is updated automatically. 73 | */ 74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 75 | 76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup STM32F4xx_System_Exported_Constants 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F4xx_System_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @addtogroup STM32F4xx_System_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | extern void SystemInit(void); 104 | extern void SystemCoreClockUpdate(void); 105 | /** 106 | * @} 107 | */ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /*__SYSTEM_STM32F4XX_H */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 123 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_HAL_DMA_EX_H 22 | #define __STM32F4xx_HAL_DMA_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup DMAEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types 41 | * @brief DMAEx Exported types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief HAL DMA Memory definition 47 | */ 48 | typedef enum 49 | { 50 | MEMORY0 = 0x00U, /*!< Memory 0 */ 51 | MEMORY1 = 0x01U /*!< Memory 1 */ 52 | }HAL_DMA_MemoryTypeDef; 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /* Exported functions --------------------------------------------------------*/ 59 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 60 | * @brief DMAEx Exported functions 61 | * @{ 62 | */ 63 | 64 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions 65 | * @brief Extended features functions 66 | * @{ 67 | */ 68 | 69 | /* IO operation functions *******************************************************/ 70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 71 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 72 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); 73 | 74 | /** 75 | * @} 76 | */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /* Private functions ---------------------------------------------------------*/ 82 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions 83 | * @brief DMAEx Private functions 84 | * @{ 85 | */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/ 103 | 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 22 | #define __STM32F4xx_FLASH_RAMFUNC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 28 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal_def.h" 32 | 33 | /** @addtogroup STM32F4xx_HAL_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup FLASH_RAMFUNC 38 | * @{ 39 | */ 40 | 41 | /* Exported types ------------------------------------------------------------*/ 42 | /* Exported macro ------------------------------------------------------------*/ 43 | /* Exported functions --------------------------------------------------------*/ 44 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 45 | * @{ 46 | */ 47 | 48 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 49 | * @{ 50 | */ 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 53 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 54 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | 77 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file gpio.h 4 | * @brief This file contains all the function prototypes for 5 | * the gpio.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __GPIO_H__ 21 | #define __GPIO_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* USER CODE BEGIN Private defines */ 35 | 36 | /* USER CODE END Private defines */ 37 | 38 | void MX_GPIO_Init(void); 39 | 40 | /* USER CODE BEGIN Prototypes */ 41 | 42 | /* USER CODE END Prototypes */ 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /*__ GPIO_H__ */ 48 | 49 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 50 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | /* Private defines -----------------------------------------------------------*/ 61 | /* USER CODE BEGIN Private defines */ 62 | 63 | /* USER CODE END Private defines */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __MAIN_H */ 70 | 71 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 72 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F4xx_IT_H 23 | #define __STM32F4xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void MemManage_Handler(void); 53 | void BusFault_Handler(void); 54 | void UsageFault_Handler(void); 55 | void SVC_Handler(void); 56 | void DebugMon_Handler(void); 57 | void PendSV_Handler(void); 58 | void SysTick_Handler(void); 59 | /* USER CODE BEGIN EFP */ 60 | 61 | /* USER CODE END EFP */ 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* __STM32F4xx_IT_H */ 68 | 69 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 70 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/MDK-ARM/DebugConfig/405swd_STM32F405RGTx.dbgconf: -------------------------------------------------------------------------------- 1 | // <<< Use Configuration Wizard in Context Menu >>> 2 | 3 | // Debug MCU Configuration 4 | // DBG_SLEEP Debug Sleep Mode 5 | // DBG_STOP Debug Stop Mode 6 | // DBG_STANDBY Debug Standby Mode 7 | // 8 | DbgMCU_CR = 0x00000007; 9 | 10 | // Debug MCU APB1 Freeze 11 | // DBG_TIM2_STOP Timer 2 Stopped when Core is halted 12 | // DBG_TIM3_STOP Timer 3 Stopped when Core is halted 13 | // DBG_TIM4_STOP Timer 4 Stopped when Core is halted 14 | // DBG_TIM5_STOP Timer 5 Stopped when Core is halted 15 | // DBG_TIM6_STOP Timer 6 Stopped when Core is halted 16 | // DBG_TIM7_STOP Timer 7 Stopped when Core is halted 17 | // DBG_TIM12_STOP Timer 12 Stopped when Core is halted 18 | // DBG_TIM13_STOP Timer 13 Stopped when Core is halted 19 | // DBG_TIM14_STOP Timer 14 Stopped when Core is halted 20 | // DBG_RTC_STOP RTC Stopped when Core is halted 21 | // DBG_WWDG_STOP Window Watchdog Stopped when Core is halted 22 | // DBG_IWDG_STOP Independent Watchdog Stopped when Core is halted 23 | // DBG_I2C1_SMBUS_TIMEOUT I2C1 SMBUS Timeout Mode Stopped when Core is halted 24 | // DBG_I2C2_SMBUS_TIMEOUT I2C2 SMBUS Timeout Mode Stopped when Core is halted 25 | // DBG_I2C3_SMBUS_TIMEOUT I2C3 SMBUS Timeout Mode Stopped when Core is halted 26 | // DBG_CAN1_STOP CAN1 Stopped when Core is halted 27 | // DBG_CAN2_STOP CAN2 Stopped when Core is halted 28 | // 29 | DbgMCU_APB1_Fz = 0x00000000; 30 | 31 | 32 | // Debug MCU APB2 Freeze 33 | // DBG_TIM1_STOP Timer 1 Stopped when Core is halted 34 | // DBG_TIM8_STOP Timer 8 Stopped when Core is halted 35 | // DBG_TIM9_STOP Timer 9 Stopped when Core is halted 36 | // DBG_TIM10_STOP Timer 10 Stopped when Core is halted 37 | // DBG_TIM11_STOP Timer 11 Stopped when Core is halted 38 | // 39 | DbgMCU_APB2_Fz = 0x00000000; 40 | 41 | // <<< end of configuration section >>> -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/MDK-ARM/RTE/_405swd/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: '405swd' 7 | * Target: '405swd' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f4xx.h" 18 | 19 | 20 | 21 | #endif /* RTE_COMPONENTS_H */ 22 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Src/gpio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file gpio.c 4 | * @brief This file provides code for the configuration 5 | * of all used GPIO pins. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "gpio.h" 22 | 23 | /* USER CODE BEGIN 0 */ 24 | 25 | /* USER CODE END 0 */ 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /* Configure GPIO */ 29 | /*----------------------------------------------------------------------------*/ 30 | /* USER CODE BEGIN 1 */ 31 | 32 | /* USER CODE END 1 */ 33 | 34 | /** Configure pins as 35 | * Analog 36 | * Input 37 | * Output 38 | * EVENT_OUT 39 | * EXTI 40 | */ 41 | void MX_GPIO_Init(void) 42 | { 43 | 44 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 45 | 46 | /* GPIO Ports Clock Enable */ 47 | __HAL_RCC_GPIOH_CLK_ENABLE(); 48 | __HAL_RCC_GPIOA_CLK_ENABLE(); 49 | 50 | /*Configure GPIO pin Output Level */ 51 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10, GPIO_PIN_SET); 52 | 53 | /*Configure GPIO pins : PA8 PA9 PA10 */ 54 | GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10; 55 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 56 | GPIO_InitStruct.Pull = GPIO_NOPULL; 57 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 58 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 59 | 60 | } 61 | 62 | /* USER CODE BEGIN 2 */ 63 | 64 | /* USER CODE END 2 */ 65 | 66 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 67 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Src/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F405RG/Src/main.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/Src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "main.h" 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN Define */ 35 | 36 | /* USER CODE END Define */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN Macro */ 40 | 41 | /* USER CODE END Macro */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* External functions --------------------------------------------------------*/ 54 | /* USER CODE BEGIN ExternalFunctions */ 55 | 56 | /* USER CODE END ExternalFunctions */ 57 | 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | /** 62 | * Initializes the Global MSP. 63 | */ 64 | void HAL_MspInit(void) 65 | { 66 | /* USER CODE BEGIN MspInit 0 */ 67 | 68 | /* USER CODE END MspInit 0 */ 69 | 70 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 71 | __HAL_RCC_PWR_CLK_ENABLE(); 72 | 73 | /* System interrupt init*/ 74 | 75 | /* USER CODE BEGIN MspInit 1 */ 76 | 77 | /* USER CODE END MspInit 1 */ 78 | } 79 | 80 | /* USER CODE BEGIN 1 */ 81 | 82 | /* USER CODE END 1 */ 83 | 84 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 85 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/dap/DAP_config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F405RG/dap/DAP_config.h -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/dap/STM32F10x_128.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2015 ARM Limited 3 | */ 4 | #include "flash_blob.h" 5 | 6 | #if 0 7 | 8 | static const uint32_t flash_code[] = { 9 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 10 | 0x4603B510, 0x4C442000, 0x48446020, 0x48446060, 0x46206060, 0xF01069C0, 0xD1080F04, 0x5055F245, 11 | 0x60204C40, 0x60602006, 0x70FFF640, 0x200060A0, 0x4601BD10, 0x69004838, 0x0080F040, 0x61104A36, 12 | 0x47702000, 0x69004834, 0x0004F040, 0x61084932, 0x69004608, 0x0040F040, 0xE0036108, 0x20AAF64A, 13 | 0x60084930, 0x68C0482C, 0x0F01F010, 0x482AD1F6, 0xF0206900, 0x49280004, 0x20006108, 0x46014770, 14 | 0x69004825, 0x0002F040, 0x61104A23, 0x61414610, 0xF0406900, 0x61100040, 0xF64AE003, 0x4A2120AA, 15 | 0x481D6010, 0xF01068C0, 0xD1F60F01, 0x6900481A, 0x0002F020, 0x61104A18, 0x47702000, 0x4603B510, 16 | 0xF0201C48, 0xE0220101, 0x69004813, 0x0001F040, 0x61204C11, 0x80188810, 0x480FBF00, 0xF01068C0, 17 | 0xD1FA0F01, 0x6900480C, 0x0001F020, 0x61204C0A, 0x68C04620, 0x0F14F010, 0x4620D006, 0xF04068C0, 18 | 0x60E00014, 0xBD102001, 0x1C921C9B, 0x29001E89, 0x2000D1DA, 0x0000E7F7, 0x40022000, 0x45670123, 19 | 0xCDEF89AB, 0x40003000, 0x00000000 20 | }; 21 | 22 | const program_target_t flash_algo = { 23 | 0x20000021, // Init 24 | 0x20000053, // UnInit 25 | 0x20000065, // EraseChip 26 | 0x2000009F, // EraseSector 27 | 0x200000DD, // ProgramPage 28 | 29 | // BKPT : start of blob + 1 30 | // RSB : address to access global/static data 31 | // RSP : stack pointer 32 | { 33 | 0x20000001, 34 | 0x20000C00, 35 | 0x20001000 36 | }, 37 | 38 | 0x20000400, // mem buffer location 39 | 0x20000000, // location to write prog_blob in target RAM 40 | sizeof(flash_code), // prog_blob size 41 | flash_code, // address of prog_blob 42 | 0x00000400, // ram_to_flash_bytes_to_be_written 43 | }; 44 | 45 | #else 46 | 47 | static const uint32_t flash_code[] = { 48 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 49 | 0x0E000300, 0xD3022820, 0x1D000940, 0x28104770, 0x0900D302, 0x47701CC0, 0x47700880, 0x49414842, 50 | 0x49426041, 0x21006041, 0x68C16001, 0x431122F0, 0x694060C1, 0xD4060680, 0x493D483E, 0x21066001, 51 | 0x493D6041, 0x20006081, 0x48374770, 0x05426901, 0x61014311, 0x47702000, 0x4833B510, 0x24046901, 52 | 0x61014321, 0x03A26901, 0x61014311, 0x4A314933, 0x6011E000, 0x03DB68C3, 0x6901D4FB, 0x610143A1, 53 | 0xBD102000, 0xF7FFB530, 0x4927FFBB, 0x23F068CA, 0x60CA431A, 0x610C2402, 0x0700690A, 0x43020E40, 54 | 0x6908610A, 0x431003E2, 0x48246108, 0xE0004A21, 0x68CD6010, 0xD4FB03ED, 0x43A06908, 0x68C86108, 55 | 0x0F000600, 0x68C8D003, 0x60C84318, 0xBD302001, 0x4D15B570, 0x08891CC9, 0x008968EB, 0x433326F0, 56 | 0x230060EB, 0x4B16612B, 0x692CE017, 0x612C431C, 0x60046814, 0x03E468EC, 0x692CD4FC, 0x00640864, 57 | 0x68EC612C, 0x0F240624, 0x68E8D004, 0x60E84330, 0xBD702001, 0x1D121D00, 0x29001F09, 0x2000D1E5, 58 | 0x0000BD70, 0x45670123, 0x40023C00, 0xCDEF89AB, 0x00005555, 0x40003000, 0x00000FFF, 0x0000AAAA, 59 | 0x00000201, 0x00000000 60 | }; 61 | 62 | const program_target_t flash_algo = { 63 | 0x2000003D, // Init 64 | 0x2000006B, // UnInit 65 | 0x20000079, // EraseChip 66 | 0x200000A5, // EraseSector 67 | 0x200000F1, // ProgramPage 68 | 69 | // BKPT : start of blob + 1 70 | // RSB : address to access global/static data 71 | // RSP : stack pointer 72 | { 73 | 0x20000001, 74 | 0x20000C00, 75 | 0x20001000 76 | }, 77 | 78 | 0x20000400, // mem buffer location 79 | 0x20000000, // location to write prog_blob in target RAM 80 | sizeof(flash_code), // prog_blob size 81 | flash_code, // address of prog_blob 82 | 0x00000400, // ram_to_flash_bytes_to_be_written 83 | }; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/dap/STM32F4xx_1024.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2015 ARM Limited 3 | */ 4 | #include "flash_blob.h" 5 | 6 | static const uint32_t flash_code[] = { 7 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 8 | 0x0E000300, 0xD3022820, 0x1D000940, 0x28104770, 0x0900D302, 0x47701CC0, 0x47700880, 0x49414842, 9 | 0x49426041, 0x21006041, 0x68C16001, 0x431122F0, 0x694060C1, 0xD4060680, 0x493D483E, 0x21066001, 10 | 0x493D6041, 0x20006081, 0x48374770, 0x05426901, 0x61014311, 0x47702000, 0x4833B510, 0x24046901, 11 | 0x61014321, 0x03A26901, 0x61014311, 0x4A314933, 0x6011E000, 0x03DB68C3, 0x6901D4FB, 0x610143A1, 12 | 0xBD102000, 0xF7FFB530, 0x4927FFBB, 0x23F068CA, 0x60CA431A, 0x610C2402, 0x0700690A, 0x43020E40, 13 | 0x6908610A, 0x431003E2, 0x48246108, 0xE0004A21, 0x68CD6010, 0xD4FB03ED, 0x43A06908, 0x68C86108, 14 | 0x0F000600, 0x68C8D003, 0x60C84318, 0xBD302001, 0x4D15B570, 0x08891CC9, 0x008968EB, 0x433326F0, 15 | 0x230060EB, 0x4B16612B, 0x692CE017, 0x612C431C, 0x60046814, 0x03E468EC, 0x692CD4FC, 0x00640864, 16 | 0x68EC612C, 0x0F240624, 0x68E8D004, 0x60E84330, 0xBD702001, 0x1D121D00, 0x29001F09, 0x2000D1E5, 17 | 0x0000BD70, 0x45670123, 0x40023C00, 0xCDEF89AB, 0x00005555, 0x40003000, 0x00000FFF, 0x0000AAAA, 18 | 0x00000201, 0x00000000 19 | }; 20 | 21 | const program_target_t flash_algo = { 22 | 0x2000003D, // Init 23 | 0x2000006B, // UnInit 24 | 0x20000079, // EraseChip 25 | 0x200000A5, // EraseSector 26 | 0x200000F1, // ProgramPage 27 | 28 | // BKPT : start of blob + 1 29 | // RSB : address to access global/static data 30 | // RSP : stack pointer 31 | { 32 | 0x20000001, 33 | 0x20000C00, 34 | 0x20001000 35 | }, 36 | 37 | 0x20000400, // mem buffer location 38 | 0x20000000, // location to write prog_blob in target RAM 39 | sizeof(flash_code), // prog_blob size 40 | flash_code, // address of prog_blob 41 | 0x00000400, // ram_to_flash_bytes_to_be_written 42 | }; 43 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/dap/SWD_flash.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SWD_flash.c 3 | * @brief Program target flash through SWD 4 | */ 5 | #include "swd_host.h" 6 | #include "SWD_flash.h" 7 | 8 | 9 | extern const program_target_t flash_algo; 10 | 11 | 12 | error_t target_flash_init(uint32_t flash_start) 13 | { 14 | if (0 == swd_set_target_state_hw(RESET_PROGRAM)) { 15 | return ERROR_RESET; 16 | } 17 | 18 | // Download flash programming algorithm to target and initialise. 19 | if (0 == swd_write_memory(flash_algo.algo_start, (uint8_t *)flash_algo.algo_blob, flash_algo.algo_size)) { 20 | return ERROR_ALGO_DL; 21 | } 22 | 23 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.init, flash_start, 0, 0, 0)) { 24 | return ERROR_INIT; 25 | } 26 | 27 | return ERROR_SUCCESS; 28 | } 29 | 30 | error_t target_flash_uninit(void) 31 | { 32 | swd_set_target_state_hw(RESET_RUN); 33 | 34 | swd_off(); 35 | return ERROR_SUCCESS; 36 | } 37 | 38 | error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size) 39 | { 40 | while (size > 0) { 41 | uint32_t write_size = size > flash_algo.program_buffer_size ? flash_algo.program_buffer_size : size; 42 | 43 | // Write page to buffer 44 | if (!swd_write_memory(flash_algo.program_buffer, (uint8_t *)buf, write_size)) { 45 | return ERROR_ALGO_DATA_SEQ; 46 | } 47 | 48 | // Run flash programming 49 | if (!swd_flash_syscall_exec(&flash_algo.sys_call_s, 50 | flash_algo.program_page, 51 | addr, 52 | flash_algo.program_buffer_size, 53 | flash_algo.program_buffer, 54 | 0)) { 55 | return ERROR_WRITE; 56 | } 57 | 58 | addr += write_size; 59 | buf += write_size; 60 | size -= write_size; 61 | } 62 | 63 | return ERROR_SUCCESS; 64 | } 65 | 66 | error_t target_flash_erase_sector(uint32_t addr) 67 | { 68 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.erase_sector, addr, 0, 0, 0)) { 69 | return ERROR_ERASE_SECTOR; 70 | } 71 | 72 | return ERROR_SUCCESS; 73 | } 74 | 75 | error_t target_flash_erase_chip(void) 76 | { 77 | error_t status = ERROR_SUCCESS; 78 | 79 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.erase_chip, 0, 0, 0, 0)) { 80 | return ERROR_ERASE_ALL; 81 | } 82 | 83 | return status; 84 | } 85 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/dap/SWD_flash.h: -------------------------------------------------------------------------------- 1 | #ifndef __SWD_FLASH_H__ 2 | #define __SWD_FLASH_H__ 3 | 4 | #include 5 | 6 | #include "error.h" 7 | 8 | error_t target_flash_init(uint32_t flash_start); 9 | error_t target_flash_uninit(void); 10 | error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size); 11 | error_t target_flash_erase_sector(uint32_t addr); 12 | error_t target_flash_erase_chip(void); 13 | 14 | 15 | #endif // __SWD_FLASH_H__ 16 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/dap/SWD_host.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F405RG/dap/SWD_host.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/dap/SWD_host.h: -------------------------------------------------------------------------------- 1 | #ifndef SWDHOST_CM_H 2 | #define SWDHOST_CM_H 3 | 4 | #include 5 | 6 | #include "flash_blob.h" 7 | 8 | 9 | typedef enum { 10 | RESET_HOLD, // Hold target in reset 11 | RESET_PROGRAM, // Reset target and setup for flash programming. 12 | RESET_RUN, // Reset target and run normally 13 | NO_DEBUG, // Disable debug on running target 14 | DEBUG, // Enable debug on running target 15 | HALT, // Halt the target without resetting it 16 | RUN // Resume the target without resetting it 17 | } TARGET_RESET_STATE; 18 | 19 | 20 | uint8_t swd_init(void); 21 | uint8_t swd_off(void); 22 | uint8_t swd_init_debug(void); 23 | uint8_t swd_read_dp(uint8_t adr, uint32_t *val); 24 | uint8_t swd_write_dp(uint8_t adr, uint32_t val); 25 | uint8_t swd_read_ap(uint32_t adr, uint32_t *val); 26 | uint8_t swd_write_ap(uint32_t adr, uint32_t val); 27 | uint8_t swd_read_memory(uint32_t address, uint8_t *data, uint32_t size); 28 | uint8_t swd_write_memory(uint32_t address, uint8_t *data, uint32_t size); 29 | uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4); 30 | void swd_set_target_reset(uint8_t asserted); 31 | uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state); 32 | uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/dap/error.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file error.c 3 | * @brief collection of known errors and accessor for the friendly string 4 | */ 5 | 6 | #include "error.h" 7 | 8 | static const char *const error_message[] = { 9 | 10 | /* Shared errors */ 11 | 12 | // ERROR_SUCCESS 13 | "Operation was successful", 14 | // ERROR_FAILURE 15 | "An error has occurred", 16 | // ERROR_INTERNAL 17 | "An internal error has occurred", 18 | 19 | 20 | /* Target flash errors */ 21 | 22 | // ERROR_RESET 23 | "The interface firmware FAILED to reset/halt the target MCU", 24 | // ERROR_ALGO_DL 25 | "The interface firmware FAILED to download the flash programming algorithms to the target MCU", 26 | // ERROR_ALGO_DATA_SEQ 27 | "The interface firmware FAILED to download the flash data contents to be programmed", 28 | // ERROR_INIT 29 | "The interface firmware FAILED to initialize the target MCU", 30 | // ERROR_SECURITY_BITS 31 | "The interface firmware ABORTED programming. Image is trying to set security bits", 32 | // ERROR_UNLOCK 33 | "The interface firmware FAILED to unlock the target for programming", 34 | // ERROR_ERASE_SECTOR 35 | "Flash algorithm erase sector command FAILURE", 36 | // ERROR_ERASE_ALL 37 | "Flash algorithm erase all command FAILURE", 38 | // ERROR_WRITE 39 | "Flash algorithm write command FAILURE", 40 | }; 41 | 42 | static error_type_t error_type[] = { 43 | 44 | /* These should always stay the same for each error type. */ 45 | 46 | // ERROR_SUCCESS 47 | 0, 48 | // ERROR_FAILURE 49 | ERROR_TYPE_INTERNAL, 50 | // ERROR_INTERNAL 51 | ERROR_TYPE_INTERNAL, 52 | 53 | 54 | /* Target flash errors */ 55 | 56 | // ERROR_RESET 57 | ERROR_TYPE_TARGET, 58 | // ERROR_ALGO_DL 59 | ERROR_TYPE_TARGET, 60 | // ERROR_ALGO_DATA_SEQ 61 | ERROR_TYPE_TARGET, 62 | // ERROR_INIT 63 | ERROR_TYPE_TARGET, 64 | // ERROR_SECURITY_BITS 65 | ERROR_TYPE_USER, 66 | // ERROR_UNLOCK 67 | ERROR_TYPE_TARGET, 68 | // ERROR_ERASE_SECTOR 69 | ERROR_TYPE_TARGET, 70 | // ERROR_ERASE_ALL 71 | ERROR_TYPE_TARGET, 72 | // ERROR_WRITE 73 | ERROR_TYPE_TARGET, 74 | }; 75 | 76 | const char *error_get_string(error_t error) 77 | { 78 | const char *msg = 0; 79 | 80 | if (error < ERROR_COUNT) { 81 | msg = error_message[error]; 82 | } 83 | 84 | return msg; 85 | } 86 | 87 | error_type_t error_get_type(error_t error) 88 | { 89 | error_type_t type = ERROR_TYPE_INTERNAL; 90 | 91 | if (error < ERROR_COUNT) { 92 | type = error_type[error]; 93 | } 94 | 95 | return type; 96 | } 97 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/dap/error.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_H 2 | #define ERROR_H 3 | 4 | 5 | // Keep in sync with the lists error_message and error_type 6 | typedef enum { 7 | /* Shared errors */ 8 | ERROR_SUCCESS = 0, 9 | ERROR_FAILURE, 10 | ERROR_INTERNAL, 11 | 12 | /* Target flash errors */ 13 | ERROR_RESET, 14 | ERROR_ALGO_DL, 15 | ERROR_ALGO_DATA_SEQ, 16 | ERROR_INIT, 17 | ERROR_SECURITY_BITS, 18 | ERROR_UNLOCK, 19 | ERROR_ERASE_SECTOR, 20 | ERROR_ERASE_ALL, 21 | ERROR_WRITE, 22 | 23 | // Add new values here 24 | 25 | ERROR_COUNT 26 | } error_t; 27 | 28 | 29 | typedef unsigned char error_type_t; 30 | 31 | #define ERROR_TYPE_INTERNAL 0x1 32 | #define ERROR_TYPE_TRANSIENT 0x2 33 | #define ERROR_TYPE_USER 0x4 34 | #define ERROR_TYPE_TARGET 0x8 35 | 36 | #define ERROR_TYPE_MASK 0xF 37 | 38 | 39 | const char *error_get_string(error_t error); 40 | 41 | error_type_t error_get_type(error_t error); 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F405RG/dap/flash_blob.h: -------------------------------------------------------------------------------- 1 | #ifndef FLASH_BLOB_H 2 | #define FLASH_BLOB_H 3 | 4 | #include 5 | 6 | 7 | typedef struct { 8 | uint32_t breakpoint; 9 | uint32_t static_base; 10 | uint32_t stack_pointer; 11 | } program_syscall_t; 12 | 13 | typedef struct { 14 | const uint32_t init; 15 | const uint32_t uninit; 16 | const uint32_t erase_chip; 17 | const uint32_t erase_sector; 18 | const uint32_t program_page; 19 | const program_syscall_t sys_call_s; 20 | const uint32_t program_buffer; 21 | const uint32_t algo_start; 22 | const uint32_t algo_size; 23 | const uint32_t *algo_blob; 24 | const uint32_t program_buffer_size; 25 | } program_target_t; 26 | 27 | typedef struct { 28 | const uint32_t start; 29 | const uint32_t size; 30 | } sector_info_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Core/Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file gpio.h 4 | * @brief This file contains all the function prototypes for 5 | * the gpio.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __GPIO_H__ 21 | #define __GPIO_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* USER CODE BEGIN Private defines */ 35 | 36 | /* USER CODE END Private defines */ 37 | 38 | void MX_GPIO_Init(void); 39 | 40 | /* USER CODE BEGIN Prototypes */ 41 | 42 | /* USER CODE END Prototypes */ 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /*__ GPIO_H__ */ 48 | 49 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 50 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Core/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | /* Private defines -----------------------------------------------------------*/ 61 | /* USER CODE BEGIN Private defines */ 62 | 63 | /* USER CODE END Private defines */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __MAIN_H */ 70 | 71 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 72 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Core/Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F4xx_IT_H 23 | #define __STM32F4xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void MemManage_Handler(void); 53 | void BusFault_Handler(void); 54 | void UsageFault_Handler(void); 55 | void SVC_Handler(void); 56 | void DebugMon_Handler(void); 57 | void PendSV_Handler(void); 58 | void SysTick_Handler(void); 59 | /* USER CODE BEGIN EFP */ 60 | 61 | /* USER CODE END EFP */ 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* __STM32F4xx_IT_H */ 68 | 69 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 70 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Core/Src/gpio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file gpio.c 4 | * @brief This file provides code for the configuration 5 | * of all used GPIO pins. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "gpio.h" 22 | 23 | /* USER CODE BEGIN 0 */ 24 | 25 | /* USER CODE END 0 */ 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /* Configure GPIO */ 29 | /*----------------------------------------------------------------------------*/ 30 | /* USER CODE BEGIN 1 */ 31 | 32 | /* USER CODE END 1 */ 33 | 34 | /** Configure pins as 35 | * Analog 36 | * Input 37 | * Output 38 | * EVENT_OUT 39 | * EXTI 40 | */ 41 | void MX_GPIO_Init(void) 42 | { 43 | 44 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 45 | 46 | /* GPIO Ports Clock Enable */ 47 | __HAL_RCC_GPIOF_CLK_ENABLE(); 48 | __HAL_RCC_GPIOH_CLK_ENABLE(); 49 | __HAL_RCC_GPIOA_CLK_ENABLE(); 50 | 51 | /*Configure GPIO pin Output Level */ 52 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6, GPIO_PIN_SET); 53 | 54 | /*Configure GPIO pins : PF4 PF5 PF6 */ 55 | GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6; 56 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 57 | GPIO_InitStruct.Pull = GPIO_NOPULL; 58 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 59 | HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); 60 | 61 | } 62 | 63 | /* USER CODE BEGIN 2 */ 64 | 65 | /* USER CODE END 2 */ 66 | 67 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 68 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Core/Src/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F407IG/Core/Src/main.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Core/Src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "main.h" 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN Define */ 35 | 36 | /* USER CODE END Define */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN Macro */ 40 | 41 | /* USER CODE END Macro */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* External functions --------------------------------------------------------*/ 54 | /* USER CODE BEGIN ExternalFunctions */ 55 | 56 | /* USER CODE END ExternalFunctions */ 57 | 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | /** 62 | * Initializes the Global MSP. 63 | */ 64 | void HAL_MspInit(void) 65 | { 66 | /* USER CODE BEGIN MspInit 0 */ 67 | 68 | /* USER CODE END MspInit 0 */ 69 | 70 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 71 | __HAL_RCC_PWR_CLK_ENABLE(); 72 | 73 | /* System interrupt init*/ 74 | 75 | /* USER CODE BEGIN MspInit 1 */ 76 | 77 | /* USER CODE END MspInit 1 */ 78 | } 79 | 80 | /* USER CODE BEGIN 1 */ 81 | 82 | /* USER CODE END 1 */ 83 | 84 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 85 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F407IG/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /** @addtogroup CMSIS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup stm32f4xx_system 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Define to prevent recursive inclusion 46 | */ 47 | #ifndef __SYSTEM_STM32F4XX_H 48 | #define __SYSTEM_STM32F4XX_H 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /** @addtogroup STM32F4xx_System_Includes 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @addtogroup STM32F4xx_System_Exported_types 64 | * @{ 65 | */ 66 | /* This variable is updated in three ways: 67 | 1) by calling CMSIS function SystemCoreClockUpdate() 68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 70 | Note: If you use this function to configure the system clock; then there 71 | is no need to call the 2 first functions listed above, since SystemCoreClock 72 | variable is updated automatically. 73 | */ 74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 75 | 76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup STM32F4xx_System_Exported_Constants 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F4xx_System_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @addtogroup STM32F4xx_System_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | extern void SystemInit(void); 104 | extern void SystemCoreClockUpdate(void); 105 | /** 106 | * @} 107 | */ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /*__SYSTEM_STM32F4XX_H */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 123 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_HAL_DMA_EX_H 22 | #define __STM32F4xx_HAL_DMA_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup DMAEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types 41 | * @brief DMAEx Exported types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief HAL DMA Memory definition 47 | */ 48 | typedef enum 49 | { 50 | MEMORY0 = 0x00U, /*!< Memory 0 */ 51 | MEMORY1 = 0x01U /*!< Memory 1 */ 52 | }HAL_DMA_MemoryTypeDef; 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /* Exported functions --------------------------------------------------------*/ 59 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 60 | * @brief DMAEx Exported functions 61 | * @{ 62 | */ 63 | 64 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions 65 | * @brief Extended features functions 66 | * @{ 67 | */ 68 | 69 | /* IO operation functions *******************************************************/ 70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 71 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 72 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); 73 | 74 | /** 75 | * @} 76 | */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /* Private functions ---------------------------------------------------------*/ 82 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions 83 | * @brief DMAEx Private functions 84 | * @{ 85 | */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/ 103 | 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 22 | #define __STM32F4xx_FLASH_RAMFUNC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 28 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal_def.h" 32 | 33 | /** @addtogroup STM32F4xx_HAL_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup FLASH_RAMFUNC 38 | * @{ 39 | */ 40 | 41 | /* Exported types ------------------------------------------------------------*/ 42 | /* Exported macro ------------------------------------------------------------*/ 43 | /* Exported functions --------------------------------------------------------*/ 44 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 45 | * @{ 46 | */ 47 | 48 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 49 | * @{ 50 | */ 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 53 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 54 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | 77 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/MDK-ARM/DebugConfig/swd_STM32F407IGTx.dbgconf: -------------------------------------------------------------------------------- 1 | // <<< Use Configuration Wizard in Context Menu >>> 2 | 3 | // Debug MCU Configuration 4 | // DBG_SLEEP Debug Sleep Mode 5 | // DBG_STOP Debug Stop Mode 6 | // DBG_STANDBY Debug Standby Mode 7 | // 8 | DbgMCU_CR = 0x00000007; 9 | 10 | // Debug MCU APB1 Freeze 11 | // DBG_TIM2_STOP Timer 2 Stopped when Core is halted 12 | // DBG_TIM3_STOP Timer 3 Stopped when Core is halted 13 | // DBG_TIM4_STOP Timer 4 Stopped when Core is halted 14 | // DBG_TIM5_STOP Timer 5 Stopped when Core is halted 15 | // DBG_TIM6_STOP Timer 6 Stopped when Core is halted 16 | // DBG_TIM7_STOP Timer 7 Stopped when Core is halted 17 | // DBG_TIM12_STOP Timer 12 Stopped when Core is halted 18 | // DBG_TIM13_STOP Timer 13 Stopped when Core is halted 19 | // DBG_TIM14_STOP Timer 14 Stopped when Core is halted 20 | // DBG_RTC_STOP RTC Stopped when Core is halted 21 | // DBG_WWDG_STOP Window Watchdog Stopped when Core is halted 22 | // DBG_IWDG_STOP Independent Watchdog Stopped when Core is halted 23 | // DBG_I2C1_SMBUS_TIMEOUT I2C1 SMBUS Timeout Mode Stopped when Core is halted 24 | // DBG_I2C2_SMBUS_TIMEOUT I2C2 SMBUS Timeout Mode Stopped when Core is halted 25 | // DBG_I2C3_SMBUS_TIMEOUT I2C3 SMBUS Timeout Mode Stopped when Core is halted 26 | // DBG_CAN1_STOP CAN1 Stopped when Core is halted 27 | // DBG_CAN2_STOP CAN2 Stopped when Core is halted 28 | // 29 | DbgMCU_APB1_Fz = 0x00000000; 30 | 31 | 32 | // Debug MCU APB2 Freeze 33 | // DBG_TIM1_STOP Timer 1 Stopped when Core is halted 34 | // DBG_TIM8_STOP Timer 8 Stopped when Core is halted 35 | // DBG_TIM9_STOP Timer 9 Stopped when Core is halted 36 | // DBG_TIM10_STOP Timer 10 Stopped when Core is halted 37 | // DBG_TIM11_STOP Timer 11 Stopped when Core is halted 38 | // 39 | DbgMCU_APB2_Fz = 0x00000000; 40 | 41 | // <<< end of configuration section >>> -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/MDK-ARM/RTE/_swd/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'swd' 7 | * Target: 'swd' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f4xx.h" 18 | 19 | 20 | 21 | #endif /* RTE_COMPONENTS_H */ 22 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/dap/DAP_config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F407IG/dap/DAP_config.h -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/dap/STM32F10x_128.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2015 ARM Limited 3 | */ 4 | #include "flash_blob.h" 5 | 6 | #if 0 7 | 8 | static const uint32_t flash_code[] = { 9 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 10 | 0x4603B510, 0x4C442000, 0x48446020, 0x48446060, 0x46206060, 0xF01069C0, 0xD1080F04, 0x5055F245, 11 | 0x60204C40, 0x60602006, 0x70FFF640, 0x200060A0, 0x4601BD10, 0x69004838, 0x0080F040, 0x61104A36, 12 | 0x47702000, 0x69004834, 0x0004F040, 0x61084932, 0x69004608, 0x0040F040, 0xE0036108, 0x20AAF64A, 13 | 0x60084930, 0x68C0482C, 0x0F01F010, 0x482AD1F6, 0xF0206900, 0x49280004, 0x20006108, 0x46014770, 14 | 0x69004825, 0x0002F040, 0x61104A23, 0x61414610, 0xF0406900, 0x61100040, 0xF64AE003, 0x4A2120AA, 15 | 0x481D6010, 0xF01068C0, 0xD1F60F01, 0x6900481A, 0x0002F020, 0x61104A18, 0x47702000, 0x4603B510, 16 | 0xF0201C48, 0xE0220101, 0x69004813, 0x0001F040, 0x61204C11, 0x80188810, 0x480FBF00, 0xF01068C0, 17 | 0xD1FA0F01, 0x6900480C, 0x0001F020, 0x61204C0A, 0x68C04620, 0x0F14F010, 0x4620D006, 0xF04068C0, 18 | 0x60E00014, 0xBD102001, 0x1C921C9B, 0x29001E89, 0x2000D1DA, 0x0000E7F7, 0x40022000, 0x45670123, 19 | 0xCDEF89AB, 0x40003000, 0x00000000 20 | }; 21 | 22 | const program_target_t flash_algo = { 23 | 0x20000021, // Init 24 | 0x20000053, // UnInit 25 | 0x20000065, // EraseChip 26 | 0x2000009F, // EraseSector 27 | 0x200000DD, // ProgramPage 28 | 29 | // BKPT : start of blob + 1 30 | // RSB : address to access global/static data 31 | // RSP : stack pointer 32 | { 33 | 0x20000001, 34 | 0x20000C00, 35 | 0x20001000 36 | }, 37 | 38 | 0x20000400, // mem buffer location 39 | 0x20000000, // location to write prog_blob in target RAM 40 | sizeof(flash_code), // prog_blob size 41 | flash_code, // address of prog_blob 42 | 0x00000400, // ram_to_flash_bytes_to_be_written 43 | }; 44 | 45 | #else 46 | 47 | static const uint32_t flash_code[] = { 48 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 49 | 0x0E000300, 0xD3022820, 0x1D000940, 0x28104770, 0x0900D302, 0x47701CC0, 0x47700880, 0x49414842, 50 | 0x49426041, 0x21006041, 0x68C16001, 0x431122F0, 0x694060C1, 0xD4060680, 0x493D483E, 0x21066001, 51 | 0x493D6041, 0x20006081, 0x48374770, 0x05426901, 0x61014311, 0x47702000, 0x4833B510, 0x24046901, 52 | 0x61014321, 0x03A26901, 0x61014311, 0x4A314933, 0x6011E000, 0x03DB68C3, 0x6901D4FB, 0x610143A1, 53 | 0xBD102000, 0xF7FFB530, 0x4927FFBB, 0x23F068CA, 0x60CA431A, 0x610C2402, 0x0700690A, 0x43020E40, 54 | 0x6908610A, 0x431003E2, 0x48246108, 0xE0004A21, 0x68CD6010, 0xD4FB03ED, 0x43A06908, 0x68C86108, 55 | 0x0F000600, 0x68C8D003, 0x60C84318, 0xBD302001, 0x4D15B570, 0x08891CC9, 0x008968EB, 0x433326F0, 56 | 0x230060EB, 0x4B16612B, 0x692CE017, 0x612C431C, 0x60046814, 0x03E468EC, 0x692CD4FC, 0x00640864, 57 | 0x68EC612C, 0x0F240624, 0x68E8D004, 0x60E84330, 0xBD702001, 0x1D121D00, 0x29001F09, 0x2000D1E5, 58 | 0x0000BD70, 0x45670123, 0x40023C00, 0xCDEF89AB, 0x00005555, 0x40003000, 0x00000FFF, 0x0000AAAA, 59 | 0x00000201, 0x00000000 60 | }; 61 | 62 | const program_target_t flash_algo = { 63 | 0x2000003D, // Init 64 | 0x2000006B, // UnInit 65 | 0x20000079, // EraseChip 66 | 0x200000A5, // EraseSector 67 | 0x200000F1, // ProgramPage 68 | 69 | // BKPT : start of blob + 1 70 | // RSB : address to access global/static data 71 | // RSP : stack pointer 72 | { 73 | 0x20000001, 74 | 0x20000C00, 75 | 0x20001000 76 | }, 77 | 78 | 0x20000400, // mem buffer location 79 | 0x20000000, // location to write prog_blob in target RAM 80 | sizeof(flash_code), // prog_blob size 81 | flash_code, // address of prog_blob 82 | 0x00000400, // ram_to_flash_bytes_to_be_written 83 | }; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/dap/STM32F4xx_1024.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2015 ARM Limited 3 | */ 4 | #include "flash_blob.h" 5 | 6 | static const uint32_t flash_code[] = { 7 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 8 | 0x0E000300, 0xD3022820, 0x1D000940, 0x28104770, 0x0900D302, 0x47701CC0, 0x47700880, 0x49414842, 9 | 0x49426041, 0x21006041, 0x68C16001, 0x431122F0, 0x694060C1, 0xD4060680, 0x493D483E, 0x21066001, 10 | 0x493D6041, 0x20006081, 0x48374770, 0x05426901, 0x61014311, 0x47702000, 0x4833B510, 0x24046901, 11 | 0x61014321, 0x03A26901, 0x61014311, 0x4A314933, 0x6011E000, 0x03DB68C3, 0x6901D4FB, 0x610143A1, 12 | 0xBD102000, 0xF7FFB530, 0x4927FFBB, 0x23F068CA, 0x60CA431A, 0x610C2402, 0x0700690A, 0x43020E40, 13 | 0x6908610A, 0x431003E2, 0x48246108, 0xE0004A21, 0x68CD6010, 0xD4FB03ED, 0x43A06908, 0x68C86108, 14 | 0x0F000600, 0x68C8D003, 0x60C84318, 0xBD302001, 0x4D15B570, 0x08891CC9, 0x008968EB, 0x433326F0, 15 | 0x230060EB, 0x4B16612B, 0x692CE017, 0x612C431C, 0x60046814, 0x03E468EC, 0x692CD4FC, 0x00640864, 16 | 0x68EC612C, 0x0F240624, 0x68E8D004, 0x60E84330, 0xBD702001, 0x1D121D00, 0x29001F09, 0x2000D1E5, 17 | 0x0000BD70, 0x45670123, 0x40023C00, 0xCDEF89AB, 0x00005555, 0x40003000, 0x00000FFF, 0x0000AAAA, 18 | 0x00000201, 0x00000000 19 | }; 20 | 21 | const program_target_t flash_algo = { 22 | 0x2000003D, // Init 23 | 0x2000006B, // UnInit 24 | 0x20000079, // EraseChip 25 | 0x200000A5, // EraseSector 26 | 0x200000F1, // ProgramPage 27 | 28 | // BKPT : start of blob + 1 29 | // RSB : address to access global/static data 30 | // RSP : stack pointer 31 | { 32 | 0x20000001, 33 | 0x20000C00, 34 | 0x20001000 35 | }, 36 | 37 | 0x20000400, // mem buffer location 38 | 0x20000000, // location to write prog_blob in target RAM 39 | sizeof(flash_code), // prog_blob size 40 | flash_code, // address of prog_blob 41 | 0x00000400, // ram_to_flash_bytes_to_be_written 42 | }; 43 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/dap/SWD_flash.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SWD_flash.c 3 | * @brief Program target flash through SWD 4 | */ 5 | #include "swd_host.h" 6 | #include "SWD_flash.h" 7 | 8 | 9 | extern const program_target_t flash_algo; 10 | 11 | 12 | error_t target_flash_init(uint32_t flash_start) 13 | { 14 | if (0 == swd_set_target_state_hw(RESET_PROGRAM)) { 15 | return ERROR_RESET; 16 | } 17 | 18 | // Download flash programming algorithm to target and initialise. 19 | if (0 == swd_write_memory(flash_algo.algo_start, (uint8_t *)flash_algo.algo_blob, flash_algo.algo_size)) { 20 | return ERROR_ALGO_DL; 21 | } 22 | 23 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.init, flash_start, 0, 0, 0)) { 24 | return ERROR_INIT; 25 | } 26 | 27 | return ERROR_SUCCESS; 28 | } 29 | 30 | error_t target_flash_uninit(void) 31 | { 32 | swd_set_target_state_hw(RESET_RUN); 33 | 34 | swd_off(); 35 | return ERROR_SUCCESS; 36 | } 37 | 38 | error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size) 39 | { 40 | while (size > 0) { 41 | uint32_t write_size = size > flash_algo.program_buffer_size ? flash_algo.program_buffer_size : size; 42 | 43 | // Write page to buffer 44 | if (!swd_write_memory(flash_algo.program_buffer, (uint8_t *)buf, write_size)) { 45 | return ERROR_ALGO_DATA_SEQ; 46 | } 47 | 48 | // Run flash programming 49 | if (!swd_flash_syscall_exec(&flash_algo.sys_call_s, 50 | flash_algo.program_page, 51 | addr, 52 | flash_algo.program_buffer_size, 53 | flash_algo.program_buffer, 54 | 0)) { 55 | return ERROR_WRITE; 56 | } 57 | 58 | addr += write_size; 59 | buf += write_size; 60 | size -= write_size; 61 | } 62 | 63 | return ERROR_SUCCESS; 64 | } 65 | 66 | error_t target_flash_erase_sector(uint32_t addr) 67 | { 68 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.erase_sector, addr, 0, 0, 0)) { 69 | return ERROR_ERASE_SECTOR; 70 | } 71 | 72 | return ERROR_SUCCESS; 73 | } 74 | 75 | error_t target_flash_erase_chip(void) 76 | { 77 | error_t status = ERROR_SUCCESS; 78 | 79 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.erase_chip, 0, 0, 0, 0)) { 80 | return ERROR_ERASE_ALL; 81 | } 82 | 83 | return status; 84 | } 85 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/dap/SWD_flash.h: -------------------------------------------------------------------------------- 1 | #ifndef __SWD_FLASH_H__ 2 | #define __SWD_FLASH_H__ 3 | 4 | #include 5 | 6 | #include "error.h" 7 | 8 | error_t target_flash_init(uint32_t flash_start); 9 | error_t target_flash_uninit(void); 10 | error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size); 11 | error_t target_flash_erase_sector(uint32_t addr); 12 | error_t target_flash_erase_chip(void); 13 | 14 | 15 | #endif // __SWD_FLASH_H__ 16 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/dap/SWD_host.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F407IG/dap/SWD_host.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/dap/SWD_host.h: -------------------------------------------------------------------------------- 1 | #ifndef SWDHOST_CM_H 2 | #define SWDHOST_CM_H 3 | 4 | #include 5 | 6 | #include "flash_blob.h" 7 | 8 | 9 | typedef enum { 10 | RESET_HOLD, // Hold target in reset 11 | RESET_PROGRAM, // Reset target and setup for flash programming. 12 | RESET_RUN, // Reset target and run normally 13 | NO_DEBUG, // Disable debug on running target 14 | DEBUG, // Enable debug on running target 15 | HALT, // Halt the target without resetting it 16 | RUN // Resume the target without resetting it 17 | } TARGET_RESET_STATE; 18 | 19 | 20 | uint8_t swd_init(void); 21 | uint8_t swd_off(void); 22 | uint8_t swd_init_debug(void); 23 | uint8_t swd_read_dp(uint8_t adr, uint32_t *val); 24 | uint8_t swd_write_dp(uint8_t adr, uint32_t val); 25 | uint8_t swd_read_ap(uint32_t adr, uint32_t *val); 26 | uint8_t swd_write_ap(uint32_t adr, uint32_t val); 27 | uint8_t swd_read_memory(uint32_t address, uint8_t *data, uint32_t size); 28 | uint8_t swd_write_memory(uint32_t address, uint8_t *data, uint32_t size); 29 | uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4); 30 | void swd_set_target_reset(uint8_t asserted); 31 | uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state); 32 | uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/dap/error.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file error.c 3 | * @brief collection of known errors and accessor for the friendly string 4 | */ 5 | 6 | #include "error.h" 7 | 8 | static const char *const error_message[] = { 9 | 10 | /* Shared errors */ 11 | 12 | // ERROR_SUCCESS 13 | "Operation was successful", 14 | // ERROR_FAILURE 15 | "An error has occurred", 16 | // ERROR_INTERNAL 17 | "An internal error has occurred", 18 | 19 | 20 | /* Target flash errors */ 21 | 22 | // ERROR_RESET 23 | "The interface firmware FAILED to reset/halt the target MCU", 24 | // ERROR_ALGO_DL 25 | "The interface firmware FAILED to download the flash programming algorithms to the target MCU", 26 | // ERROR_ALGO_DATA_SEQ 27 | "The interface firmware FAILED to download the flash data contents to be programmed", 28 | // ERROR_INIT 29 | "The interface firmware FAILED to initialize the target MCU", 30 | // ERROR_SECURITY_BITS 31 | "The interface firmware ABORTED programming. Image is trying to set security bits", 32 | // ERROR_UNLOCK 33 | "The interface firmware FAILED to unlock the target for programming", 34 | // ERROR_ERASE_SECTOR 35 | "Flash algorithm erase sector command FAILURE", 36 | // ERROR_ERASE_ALL 37 | "Flash algorithm erase all command FAILURE", 38 | // ERROR_WRITE 39 | "Flash algorithm write command FAILURE", 40 | }; 41 | 42 | static error_type_t error_type[] = { 43 | 44 | /* These should always stay the same for each error type. */ 45 | 46 | // ERROR_SUCCESS 47 | 0, 48 | // ERROR_FAILURE 49 | ERROR_TYPE_INTERNAL, 50 | // ERROR_INTERNAL 51 | ERROR_TYPE_INTERNAL, 52 | 53 | 54 | /* Target flash errors */ 55 | 56 | // ERROR_RESET 57 | ERROR_TYPE_TARGET, 58 | // ERROR_ALGO_DL 59 | ERROR_TYPE_TARGET, 60 | // ERROR_ALGO_DATA_SEQ 61 | ERROR_TYPE_TARGET, 62 | // ERROR_INIT 63 | ERROR_TYPE_TARGET, 64 | // ERROR_SECURITY_BITS 65 | ERROR_TYPE_USER, 66 | // ERROR_UNLOCK 67 | ERROR_TYPE_TARGET, 68 | // ERROR_ERASE_SECTOR 69 | ERROR_TYPE_TARGET, 70 | // ERROR_ERASE_ALL 71 | ERROR_TYPE_TARGET, 72 | // ERROR_WRITE 73 | ERROR_TYPE_TARGET, 74 | }; 75 | 76 | const char *error_get_string(error_t error) 77 | { 78 | const char *msg = 0; 79 | 80 | if (error < ERROR_COUNT) { 81 | msg = error_message[error]; 82 | } 83 | 84 | return msg; 85 | } 86 | 87 | error_type_t error_get_type(error_t error) 88 | { 89 | error_type_t type = ERROR_TYPE_INTERNAL; 90 | 91 | if (error < ERROR_COUNT) { 92 | type = error_type[error]; 93 | } 94 | 95 | return type; 96 | } 97 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/dap/error.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_H 2 | #define ERROR_H 3 | 4 | 5 | // Keep in sync with the lists error_message and error_type 6 | typedef enum { 7 | /* Shared errors */ 8 | ERROR_SUCCESS = 0, 9 | ERROR_FAILURE, 10 | ERROR_INTERNAL, 11 | 12 | /* Target flash errors */ 13 | ERROR_RESET, 14 | ERROR_ALGO_DL, 15 | ERROR_ALGO_DATA_SEQ, 16 | ERROR_INIT, 17 | ERROR_SECURITY_BITS, 18 | ERROR_UNLOCK, 19 | ERROR_ERASE_SECTOR, 20 | ERROR_ERASE_ALL, 21 | ERROR_WRITE, 22 | 23 | // Add new values here 24 | 25 | ERROR_COUNT 26 | } error_t; 27 | 28 | 29 | typedef unsigned char error_type_t; 30 | 31 | #define ERROR_TYPE_INTERNAL 0x1 32 | #define ERROR_TYPE_TRANSIENT 0x2 33 | #define ERROR_TYPE_USER 0x4 34 | #define ERROR_TYPE_TARGET 0x8 35 | 36 | #define ERROR_TYPE_MASK 0xF 37 | 38 | 39 | const char *error_get_string(error_t error); 40 | 41 | error_type_t error_get_type(error_t error); 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F407IG/dap/flash_blob.h: -------------------------------------------------------------------------------- 1 | #ifndef FLASH_BLOB_H 2 | #define FLASH_BLOB_H 3 | 4 | #include 5 | 6 | 7 | typedef struct { 8 | uint32_t breakpoint; 9 | uint32_t static_base; 10 | uint32_t stack_pointer; 11 | } program_syscall_t; 12 | 13 | typedef struct { 14 | const uint32_t init; 15 | const uint32_t uninit; 16 | const uint32_t erase_chip; 17 | const uint32_t erase_sector; 18 | const uint32_t program_page; 19 | const program_syscall_t sys_call_s; 20 | const uint32_t program_buffer; 21 | const uint32_t algo_start; 22 | const uint32_t algo_size; 23 | const uint32_t *algo_blob; 24 | const uint32_t program_buffer_size; 25 | } program_target_t; 26 | 27 | typedef struct { 28 | const uint32_t start; 29 | const uint32_t size; 30 | } sector_info_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f730xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F730R8/Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f730xx.h -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f7xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F730R8/Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f7xx.h -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Drivers/CMSIS/Device/ST/STM32F7xx/Include/system_stm32f7xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f7xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M7 Device System Source File for STM32F7xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2016 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /** @addtogroup CMSIS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup stm32f7xx_system 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Define to prevent recursive inclusion 46 | */ 47 | #ifndef __SYSTEM_STM32F7XX_H 48 | #define __SYSTEM_STM32F7XX_H 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /** @addtogroup STM32F7xx_System_Includes 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @addtogroup STM32F7xx_System_Exported_Variables 64 | * @{ 65 | */ 66 | /* The SystemCoreClock variable is updated in three ways: 67 | 1) by calling CMSIS function SystemCoreClockUpdate() 68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 70 | Note: If you use this function to configure the system clock; then there 71 | is no need to call the 2 first functions listed above, since SystemCoreClock 72 | variable is updated automatically. 73 | */ 74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 75 | 76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 78 | 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @addtogroup STM32F7xx_System_Exported_Constants 85 | * @{ 86 | */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @addtogroup STM32F7xx_System_Exported_Macros 93 | * @{ 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** @addtogroup STM32F7xx_System_Exported_Functions 101 | * @{ 102 | */ 103 | 104 | extern void SystemInit(void); 105 | extern void SystemCoreClockUpdate(void); 106 | /** 107 | * @} 108 | */ 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /*__SYSTEM_STM32F7XX_H */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /** 121 | * @} 122 | */ 123 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 124 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Drivers/STM32F7xx_HAL_Driver/Inc/stm32f7xx_hal_spi_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f7xx_hal_spi_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of SPI HAL Extended module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F7xx_HAL_SPI_EX_H 22 | #define STM32F7xx_HAL_SPI_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f7xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F7xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup SPIEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macros -----------------------------------------------------------*/ 42 | /* Exported functions --------------------------------------------------------*/ 43 | /** @addtogroup SPIEx_Exported_Functions 44 | * @{ 45 | */ 46 | 47 | /* Initialization and de-initialization functions ****************************/ 48 | /* IO operation functions *****************************************************/ 49 | /** @addtogroup SPIEx_Exported_Functions_Group1 50 | * @{ 51 | */ 52 | HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi); 53 | /** 54 | * @} 55 | */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* STM32F7xx_HAL_SPI_EX_H */ 74 | 75 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 76 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_spi_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f7xx_hal_spi_ex.c 4 | * @author MCD Application Team 5 | * @brief Extended SPI HAL module driver. 6 | * This file provides firmware functions to manage the following 7 | * SPI peripheral extended functionalities : 8 | * + IO operation functions 9 | * 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© Copyright (c) 2017 STMicroelectronics. 14 | * All rights reserved.

15 | * 16 | * This software component is licensed by ST under BSD 3-Clause license, 17 | * the "License"; You may not use this file except in compliance with the 18 | * License. You may obtain a copy of the License at: 19 | * opensource.org/licenses/BSD-3-Clause 20 | * 21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes ------------------------------------------------------------------*/ 25 | #include "stm32f7xx_hal.h" 26 | 27 | /** @addtogroup STM32F7xx_HAL_Driver 28 | * @{ 29 | */ 30 | 31 | /** @defgroup SPIEx SPIEx 32 | * @brief SPI Extended HAL module driver 33 | * @{ 34 | */ 35 | #ifdef HAL_SPI_MODULE_ENABLED 36 | 37 | /* Private typedef -----------------------------------------------------------*/ 38 | /* Private defines -----------------------------------------------------------*/ 39 | /** @defgroup SPIEx_Private_Constants SPIEx Private Constants 40 | * @{ 41 | */ 42 | #define SPI_FIFO_SIZE 4UL 43 | /** 44 | * @} 45 | */ 46 | 47 | /* Private macros ------------------------------------------------------------*/ 48 | /* Private variables ---------------------------------------------------------*/ 49 | /* Private function prototypes -----------------------------------------------*/ 50 | /* Exported functions --------------------------------------------------------*/ 51 | 52 | /** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions 53 | * @{ 54 | */ 55 | 56 | /** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions 57 | * @brief Data transfers functions 58 | * 59 | @verbatim 60 | ============================================================================== 61 | ##### IO operation functions ##### 62 | =============================================================================== 63 | [..] 64 | This subsection provides a set of extended functions to manage the SPI 65 | data transfers. 66 | 67 | (#) Rx data flush function: 68 | (++) HAL_SPIEx_FlushRxFifo() 69 | 70 | @endverbatim 71 | * @{ 72 | */ 73 | 74 | /** 75 | * @brief Flush the RX fifo. 76 | * @param hspi pointer to a SPI_HandleTypeDef structure that contains 77 | * the configuration information for the specified SPI module. 78 | * @retval HAL status 79 | */ 80 | HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(SPI_HandleTypeDef *hspi) 81 | { 82 | __IO uint32_t tmpreg; 83 | uint8_t count = 0U; 84 | while ((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_FRLVL_EMPTY) 85 | { 86 | count++; 87 | tmpreg = hspi->Instance->DR; 88 | UNUSED(tmpreg); /* To avoid GCC warning */ 89 | if (count == SPI_FIFO_SIZE) 90 | { 91 | return HAL_TIMEOUT; 92 | } 93 | } 94 | return HAL_OK; 95 | } 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | 105 | #endif /* HAL_SPI_MODULE_ENABLED */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 116 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Inc/adc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file adc.h 4 | * @brief This file contains all the function prototypes for 5 | * the adc.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __ADC_H__ 21 | #define __ADC_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern ADC_HandleTypeDef hadc1; 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | /* USER CODE END Private defines */ 39 | 40 | void MX_ADC1_Init(void); 41 | 42 | /* USER CODE BEGIN Prototypes */ 43 | 44 | /* USER CODE END Prototypes */ 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* __ADC_H__ */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Inc/dma.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file dma.h 4 | * @brief This file contains all the function prototypes for 5 | * the dma.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __DMA_H__ 21 | #define __DMA_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* DMA memory to memory transfer handles -------------------------------------*/ 31 | 32 | /* USER CODE BEGIN Includes */ 33 | 34 | /* USER CODE END Includes */ 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | /* USER CODE END Private defines */ 39 | 40 | void MX_DMA_Init(void); 41 | 42 | /* USER CODE BEGIN Prototypes */ 43 | 44 | /* USER CODE END Prototypes */ 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* __DMA_H__ */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file gpio.h 4 | * @brief This file contains all the function prototypes for 5 | * the gpio.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __GPIO_H__ 21 | #define __GPIO_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* USER CODE BEGIN Private defines */ 35 | 36 | /* USER CODE END Private defines */ 37 | 38 | void MX_GPIO_Init(void); 39 | 40 | /* USER CODE BEGIN Prototypes */ 41 | 42 | /* USER CODE END Prototypes */ 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /*__ GPIO_H__ */ 48 | 49 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 50 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f7xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | /* Private defines -----------------------------------------------------------*/ 61 | #define DIDIR_Pin GPIO_PIN_0 62 | #define DIDIR_GPIO_Port GPIOC 63 | #define SWDIR_Pin GPIO_PIN_1 64 | #define SWDIR_GPIO_Port GPIOC 65 | #define JTDI_Pin GPIO_PIN_2 66 | #define JTDI_GPIO_Port GPIOC 67 | #define SWDIO_Pin GPIO_PIN_3 68 | #define SWDIO_GPIO_Port GPIOC 69 | #define ETX_V_Pin GPIO_PIN_0 70 | #define ETX_V_GPIO_Port GPIOA 71 | #define USB_V_Pin GPIO_PIN_1 72 | #define USB_V_GPIO_Port GPIOA 73 | #define T_TX_Pin GPIO_PIN_5 74 | #define T_TX_GPIO_Port GPIOA 75 | #define T_RX_Pin GPIO_PIN_6 76 | #define T_RX_GPIO_Port GPIOA 77 | #define DCDCEN_Pin GPIO_PIN_4 78 | #define DCDCEN_GPIO_Port GPIOC 79 | #define CON5V_Pin GPIO_PIN_0 80 | #define CON5V_GPIO_Port GPIOB 81 | #define CON1833V_Pin GPIO_PIN_1 82 | #define CON1833V_GPIO_Port GPIOB 83 | #define LED1_Pin GPIO_PIN_10 84 | #define LED1_GPIO_Port GPIOB 85 | #define LED2_Pin GPIO_PIN_11 86 | #define LED2_GPIO_Port GPIOB 87 | #define SDA_Pin GPIO_PIN_7 88 | #define SDA_GPIO_Port GPIOC 89 | #define SCL_Pin GPIO_PIN_8 90 | #define SCL_GPIO_Port GPIOC 91 | #define T_CS_Pin GPIO_PIN_9 92 | #define T_CS_GPIO_Port GPIOC 93 | #define SWCLK_Pin GPIO_PIN_12 94 | #define SWCLK_GPIO_Port GPIOC 95 | #define JTDO_Pin GPIO_PIN_2 96 | #define JTDO_GPIO_Port GPIOD 97 | #define T_O2_Pin GPIO_PIN_7 98 | #define T_O2_GPIO_Port GPIOB 99 | /* USER CODE BEGIN Private defines */ 100 | 101 | /* USER CODE END Private defines */ 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /* __MAIN_H */ 108 | 109 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 110 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Inc/spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi.h 4 | * @brief This file contains all the function prototypes for 5 | * the spi.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __SPI_H__ 21 | #define __SPI_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern SPI_HandleTypeDef hspi2; 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | /* USER CODE END Private defines */ 39 | 40 | void MX_SPI2_Init(void); 41 | 42 | /* USER CODE BEGIN Prototypes */ 43 | 44 | /* USER CODE END Prototypes */ 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* __SPI_H__ */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Inc/stm32f7xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f7xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F7xx_IT_H 23 | #define __STM32F7xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void MemManage_Handler(void); 53 | void BusFault_Handler(void); 54 | void UsageFault_Handler(void); 55 | void SVC_Handler(void); 56 | void DebugMon_Handler(void); 57 | void PendSV_Handler(void); 58 | void SysTick_Handler(void); 59 | void DMA1_Stream1_IRQHandler(void); 60 | void DMA1_Stream5_IRQHandler(void); 61 | void USART2_IRQHandler(void); 62 | void USART3_IRQHandler(void); 63 | /* USER CODE BEGIN EFP */ 64 | 65 | /* USER CODE END EFP */ 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __STM32F7xx_IT_H */ 72 | 73 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 74 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Inc/usart.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usart.h 4 | * @brief This file contains all the function prototypes for 5 | * the usart.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __USART_H__ 21 | #define __USART_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern UART_HandleTypeDef huart2; 35 | extern UART_HandleTypeDef huart3; 36 | 37 | /* USER CODE BEGIN Private defines */ 38 | 39 | /* USER CODE END Private defines */ 40 | 41 | void MX_USART2_UART_Init(void); 42 | void MX_USART3_UART_Init(void); 43 | 44 | /* USER CODE BEGIN Prototypes */ 45 | 46 | /* USER CODE END Prototypes */ 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* __USART_H__ */ 53 | 54 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 55 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/MDK-ARM/DebugConfig/F730R8_STM32F730R8Tx_2.0.0.dbgconf: -------------------------------------------------------------------------------- 1 | // File: STM32F72x_73x.dbgconf 2 | // Version: 1.0.0 3 | // Note: refer to STM32F72xxx STM32F73xxx reference manual (RM0431) 4 | // refer to STM32F72xxx STM32F73xxx datasheets 5 | 6 | // <<< Use Configuration Wizard in Context Menu >>> 7 | 8 | // Debug MCU configuration register (DBGMCU_CR) 9 | // DBG_STANDBY Debug standby mode 10 | // DBG_STOP Debug stop mode 11 | // DBG_SLEEP Debug sleep mode 12 | // 13 | DbgMCU_CR = 0x00000007; 14 | 15 | // Debug MCU APB1 freeze register (DBGMCU_APB1_FZ) 16 | // Reserved bits must be kept at reset value 17 | // DBG_CAN1_STOP Debug CAN1 stopped when core is halted 18 | // DBG_I2C3_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted 19 | // DBG_I2C2_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted 20 | // DBG_I2C1_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted 21 | // DBG_IWDG_STOP Debug independent watchdog stopped when core is halted 22 | // DBG_WWDG_STOP Debug window watchdog stopped when core is halted 23 | // DBG_RTC_STOP RTC stopped when core is halted 24 | // DBG_LPTIM1_STOP LPTMI1 counter stopped when core is halted 25 | // DBG_TIM14_STOP TIM14 counter stopped when core is halted 26 | // DBG_TIM13_STOP TIM13 counter stopped when core is halted 27 | // DBG_TIM12_STOP TIM12 counter stopped when core is halted 28 | // DBG_TIM7_STOP TIM7 counter stopped when core is halted 29 | // DBG_TIM6_STOP TIM6 counter stopped when core is halted 30 | // DBG_TIM5_STOP TIM5 counter stopped when core is halted 31 | // DBG_TIM4_STOP TIM4 counter stopped when core is halted 32 | // DBG_TIM3_STOP TIM3 counter stopped when core is halted 33 | // DBG_TIM2_STOP TIM2 counter stopped when core is halted 34 | // 35 | DbgMCU_APB1_Fz = 0x00000000; 36 | 37 | // Debug MCU APB2 freeze register (DBGMCU_APB2_FZ) 38 | // Reserved bits must be kept at reset value 39 | // DBG_TIM11_STOP TIM11 counter stopped when core is halted 40 | // DBG_TIM10_STOP TIM10 counter stopped when core is halted 41 | // DBG_TIM9_STOP TIM9 counter stopped when core is halted 42 | // DBG_TIM8_STOP TIM8 counter stopped when core is halted 43 | // DBG_TIM1_STOP TIM1 counter stopped when core is halted 44 | // 45 | DbgMCU_APB2_Fz = 0x00000000; 46 | 47 | // TPIU Pin Routing (TRACECLK fixed on Pin PE2) 48 | // TRACECLK: Pin PE2 49 | // TRACED0 50 | // ETM Trace Data 0 51 | // <0x00040003=> Pin PE3 52 | // <0x00020001=> Pin PC1 53 | // <0x0006000D=> Pin PG13 54 | // TRACED1 55 | // ETM Trace Data 1 56 | // <0x00040004=> Pin PE4 57 | // <0x00020008=> Pin PC8 58 | // <0x0006000E=> Pin PG14 59 | // TRACED2 60 | // ETM Trace Data 2 61 | // <0x00040005=> Pin PE5 62 | // <0x00030002=> Pin PD2 63 | // TRACED3 64 | // ETM Trace Data 3 65 | // <0x00040006=> Pin PE6 66 | // <0x0002000C=> Pin PC12 67 | // 68 | TraceClk_Pin = 0x00040002; 69 | TraceD0_Pin = 0x00040003; 70 | TraceD1_Pin = 0x00040004; 71 | TraceD2_Pin = 0x00040005; 72 | TraceD3_Pin = 0x00040006; 73 | 74 | // <<< end of configuration section >>> 75 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/MDK-ARM/EventRecorderStub.scvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/MDK-ARM/RTE/_F730R8/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'F730R8' 7 | * Target: 'F730R8' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f7xx.h" 18 | 19 | 20 | 21 | #endif /* RTE_COMPONENTS_H */ 22 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Src/adc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file adc.c 4 | * @brief This file provides code for the configuration 5 | * of the ADC instances. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "adc.h" 22 | 23 | /* USER CODE BEGIN 0 */ 24 | 25 | /* USER CODE END 0 */ 26 | 27 | ADC_HandleTypeDef hadc1; 28 | 29 | /* ADC1 init function */ 30 | void MX_ADC1_Init(void) 31 | { 32 | ADC_ChannelConfTypeDef sConfig = {0}; 33 | 34 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 35 | */ 36 | hadc1.Instance = ADC1; 37 | hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; 38 | hadc1.Init.Resolution = ADC_RESOLUTION_12B; 39 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; 40 | hadc1.Init.ContinuousConvMode = DISABLE; 41 | hadc1.Init.DiscontinuousConvMode = DISABLE; 42 | hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; 43 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; 44 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; 45 | hadc1.Init.NbrOfConversion = 1; 46 | hadc1.Init.DMAContinuousRequests = DISABLE; 47 | hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; 48 | if (HAL_ADC_Init(&hadc1) != HAL_OK) 49 | { 50 | Error_Handler(); 51 | } 52 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 53 | */ 54 | sConfig.Channel = ADC_CHANNEL_0; 55 | sConfig.Rank = ADC_REGULAR_RANK_1; 56 | sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; 57 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) 58 | { 59 | Error_Handler(); 60 | } 61 | 62 | } 63 | 64 | void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle) 65 | { 66 | 67 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 68 | if(adcHandle->Instance==ADC1) 69 | { 70 | /* USER CODE BEGIN ADC1_MspInit 0 */ 71 | 72 | /* USER CODE END ADC1_MspInit 0 */ 73 | /* ADC1 clock enable */ 74 | __HAL_RCC_ADC1_CLK_ENABLE(); 75 | 76 | __HAL_RCC_GPIOA_CLK_ENABLE(); 77 | /**ADC1 GPIO Configuration 78 | PA0-WKUP ------> ADC1_IN0 79 | PA1 ------> ADC1_IN1 80 | */ 81 | GPIO_InitStruct.Pin = ETX_V_Pin|USB_V_Pin; 82 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; 83 | GPIO_InitStruct.Pull = GPIO_NOPULL; 84 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 85 | 86 | /* USER CODE BEGIN ADC1_MspInit 1 */ 87 | 88 | /* USER CODE END ADC1_MspInit 1 */ 89 | } 90 | } 91 | 92 | void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) 93 | { 94 | 95 | if(adcHandle->Instance==ADC1) 96 | { 97 | /* USER CODE BEGIN ADC1_MspDeInit 0 */ 98 | 99 | /* USER CODE END ADC1_MspDeInit 0 */ 100 | /* Peripheral clock disable */ 101 | __HAL_RCC_ADC1_CLK_DISABLE(); 102 | 103 | /**ADC1 GPIO Configuration 104 | PA0-WKUP ------> ADC1_IN0 105 | PA1 ------> ADC1_IN1 106 | */ 107 | HAL_GPIO_DeInit(GPIOA, ETX_V_Pin|USB_V_Pin); 108 | 109 | /* USER CODE BEGIN ADC1_MspDeInit 1 */ 110 | 111 | /* USER CODE END ADC1_MspDeInit 1 */ 112 | } 113 | } 114 | 115 | /* USER CODE BEGIN 1 */ 116 | 117 | /* USER CODE END 1 */ 118 | 119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Src/dma.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file dma.c 4 | * @brief This file provides code for the configuration 5 | * of all the requested memory to memory DMA transfers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "dma.h" 22 | 23 | /* USER CODE BEGIN 0 */ 24 | 25 | /* USER CODE END 0 */ 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /* Configure DMA */ 29 | /*----------------------------------------------------------------------------*/ 30 | 31 | /* USER CODE BEGIN 1 */ 32 | 33 | /* USER CODE END 1 */ 34 | 35 | /** 36 | * Enable DMA controller clock 37 | */ 38 | void MX_DMA_Init(void) 39 | { 40 | 41 | /* DMA controller clock enable */ 42 | __HAL_RCC_DMA1_CLK_ENABLE(); 43 | 44 | /* DMA interrupt init */ 45 | /* DMA1_Stream1_IRQn interrupt configuration */ 46 | HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 0, 0); 47 | HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn); 48 | /* DMA1_Stream5_IRQn interrupt configuration */ 49 | HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 0, 0); 50 | HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn); 51 | 52 | } 53 | 54 | /* USER CODE BEGIN 2 */ 55 | 56 | /* USER CODE END 2 */ 57 | 58 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 59 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Src/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F730R8/Src/main.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Src/spi.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi.c 4 | * @brief This file provides code for the configuration 5 | * of the SPI instances. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "spi.h" 22 | 23 | /* USER CODE BEGIN 0 */ 24 | 25 | /* USER CODE END 0 */ 26 | 27 | SPI_HandleTypeDef hspi2; 28 | 29 | /* SPI2 init function */ 30 | void MX_SPI2_Init(void) 31 | { 32 | 33 | hspi2.Instance = SPI2; 34 | hspi2.Init.Mode = SPI_MODE_MASTER; 35 | hspi2.Init.Direction = SPI_DIRECTION_2LINES; 36 | hspi2.Init.DataSize = SPI_DATASIZE_4BIT; 37 | hspi2.Init.CLKPolarity = SPI_POLARITY_LOW; 38 | hspi2.Init.CLKPhase = SPI_PHASE_1EDGE; 39 | hspi2.Init.NSS = SPI_NSS_SOFT; 40 | hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; 41 | hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; 42 | hspi2.Init.TIMode = SPI_TIMODE_DISABLE; 43 | hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; 44 | hspi2.Init.CRCPolynomial = 7; 45 | hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; 46 | hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; 47 | if (HAL_SPI_Init(&hspi2) != HAL_OK) 48 | { 49 | Error_Handler(); 50 | } 51 | 52 | } 53 | 54 | void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) 55 | { 56 | 57 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 58 | if(spiHandle->Instance==SPI2) 59 | { 60 | /* USER CODE BEGIN SPI2_MspInit 0 */ 61 | 62 | /* USER CODE END SPI2_MspInit 0 */ 63 | /* SPI2 clock enable */ 64 | __HAL_RCC_SPI2_CLK_ENABLE(); 65 | 66 | __HAL_RCC_GPIOB_CLK_ENABLE(); 67 | __HAL_RCC_GPIOA_CLK_ENABLE(); 68 | /**SPI2 GPIO Configuration 69 | PB14 ------> SPI2_MISO 70 | PB15 ------> SPI2_MOSI 71 | PA9 ------> SPI2_SCK 72 | */ 73 | GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15; 74 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 75 | GPIO_InitStruct.Pull = GPIO_NOPULL; 76 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 77 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; 78 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 79 | 80 | GPIO_InitStruct.Pin = GPIO_PIN_9; 81 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 82 | GPIO_InitStruct.Pull = GPIO_NOPULL; 83 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 84 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; 85 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 86 | 87 | /* USER CODE BEGIN SPI2_MspInit 1 */ 88 | 89 | /* USER CODE END SPI2_MspInit 1 */ 90 | } 91 | } 92 | 93 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) 94 | { 95 | 96 | if(spiHandle->Instance==SPI2) 97 | { 98 | /* USER CODE BEGIN SPI2_MspDeInit 0 */ 99 | 100 | /* USER CODE END SPI2_MspDeInit 0 */ 101 | /* Peripheral clock disable */ 102 | __HAL_RCC_SPI2_CLK_DISABLE(); 103 | 104 | /**SPI2 GPIO Configuration 105 | PB14 ------> SPI2_MISO 106 | PB15 ------> SPI2_MOSI 107 | PA9 ------> SPI2_SCK 108 | */ 109 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14|GPIO_PIN_15); 110 | 111 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9); 112 | 113 | /* USER CODE BEGIN SPI2_MspDeInit 1 */ 114 | 115 | /* USER CODE END SPI2_MspDeInit 1 */ 116 | } 117 | } 118 | 119 | /* USER CODE BEGIN 1 */ 120 | 121 | /* USER CODE END 1 */ 122 | 123 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 124 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/Src/stm32f7xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f7xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "main.h" 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN Define */ 35 | 36 | /* USER CODE END Define */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN Macro */ 40 | 41 | /* USER CODE END Macro */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* External functions --------------------------------------------------------*/ 54 | /* USER CODE BEGIN ExternalFunctions */ 55 | 56 | /* USER CODE END ExternalFunctions */ 57 | 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | /** 62 | * Initializes the Global MSP. 63 | */ 64 | void HAL_MspInit(void) 65 | { 66 | /* USER CODE BEGIN MspInit 0 */ 67 | 68 | /* USER CODE END MspInit 0 */ 69 | 70 | __HAL_RCC_PWR_CLK_ENABLE(); 71 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 72 | 73 | /* System interrupt init*/ 74 | 75 | /* USER CODE BEGIN MspInit 1 */ 76 | 77 | /* USER CODE END MspInit 1 */ 78 | } 79 | 80 | /* USER CODE BEGIN 1 */ 81 | 82 | /* USER CODE END 1 */ 83 | 84 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 85 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/dap/DAP_config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F730R8/dap/DAP_config.h -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/dap/STM32F10x_128.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2015 ARM Limited 3 | */ 4 | #include "flash_blob.h" 5 | 6 | #if 0 7 | 8 | static const uint32_t flash_code[] = { 9 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 10 | 0x4603B510, 0x4C442000, 0x48446020, 0x48446060, 0x46206060, 0xF01069C0, 0xD1080F04, 0x5055F245, 11 | 0x60204C40, 0x60602006, 0x70FFF640, 0x200060A0, 0x4601BD10, 0x69004838, 0x0080F040, 0x61104A36, 12 | 0x47702000, 0x69004834, 0x0004F040, 0x61084932, 0x69004608, 0x0040F040, 0xE0036108, 0x20AAF64A, 13 | 0x60084930, 0x68C0482C, 0x0F01F010, 0x482AD1F6, 0xF0206900, 0x49280004, 0x20006108, 0x46014770, 14 | 0x69004825, 0x0002F040, 0x61104A23, 0x61414610, 0xF0406900, 0x61100040, 0xF64AE003, 0x4A2120AA, 15 | 0x481D6010, 0xF01068C0, 0xD1F60F01, 0x6900481A, 0x0002F020, 0x61104A18, 0x47702000, 0x4603B510, 16 | 0xF0201C48, 0xE0220101, 0x69004813, 0x0001F040, 0x61204C11, 0x80188810, 0x480FBF00, 0xF01068C0, 17 | 0xD1FA0F01, 0x6900480C, 0x0001F020, 0x61204C0A, 0x68C04620, 0x0F14F010, 0x4620D006, 0xF04068C0, 18 | 0x60E00014, 0xBD102001, 0x1C921C9B, 0x29001E89, 0x2000D1DA, 0x0000E7F7, 0x40022000, 0x45670123, 19 | 0xCDEF89AB, 0x40003000, 0x00000000 20 | }; 21 | 22 | const program_target_t flash_algo = { 23 | 0x20000021, // Init 24 | 0x20000053, // UnInit 25 | 0x20000065, // EraseChip 26 | 0x2000009F, // EraseSector 27 | 0x200000DD, // ProgramPage 28 | 29 | // BKPT : start of blob + 1 30 | // RSB : address to access global/static data 31 | // RSP : stack pointer 32 | { 33 | 0x20000001, 34 | 0x20000C00, 35 | 0x20001000 36 | }, 37 | 38 | 0x20000400, // mem buffer location 39 | 0x20000000, // location to write prog_blob in target RAM 40 | sizeof(flash_code), // prog_blob size 41 | flash_code, // address of prog_blob 42 | 0x00000400, // ram_to_flash_bytes_to_be_written 43 | }; 44 | 45 | #else 46 | 47 | static const uint32_t flash_code[] = { 48 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 49 | 0x0E000300, 0xD3022820, 0x1D000940, 0x28104770, 0x0900D302, 0x47701CC0, 0x47700880, 0x49414842, 50 | 0x49426041, 0x21006041, 0x68C16001, 0x431122F0, 0x694060C1, 0xD4060680, 0x493D483E, 0x21066001, 51 | 0x493D6041, 0x20006081, 0x48374770, 0x05426901, 0x61014311, 0x47702000, 0x4833B510, 0x24046901, 52 | 0x61014321, 0x03A26901, 0x61014311, 0x4A314933, 0x6011E000, 0x03DB68C3, 0x6901D4FB, 0x610143A1, 53 | 0xBD102000, 0xF7FFB530, 0x4927FFBB, 0x23F068CA, 0x60CA431A, 0x610C2402, 0x0700690A, 0x43020E40, 54 | 0x6908610A, 0x431003E2, 0x48246108, 0xE0004A21, 0x68CD6010, 0xD4FB03ED, 0x43A06908, 0x68C86108, 55 | 0x0F000600, 0x68C8D003, 0x60C84318, 0xBD302001, 0x4D15B570, 0x08891CC9, 0x008968EB, 0x433326F0, 56 | 0x230060EB, 0x4B16612B, 0x692CE017, 0x612C431C, 0x60046814, 0x03E468EC, 0x692CD4FC, 0x00640864, 57 | 0x68EC612C, 0x0F240624, 0x68E8D004, 0x60E84330, 0xBD702001, 0x1D121D00, 0x29001F09, 0x2000D1E5, 58 | 0x0000BD70, 0x45670123, 0x40023C00, 0xCDEF89AB, 0x00005555, 0x40003000, 0x00000FFF, 0x0000AAAA, 59 | 0x00000201, 0x00000000 60 | }; 61 | 62 | const program_target_t flash_algo = { 63 | 0x2000003D, // Init 64 | 0x2000006B, // UnInit 65 | 0x20000079, // EraseChip 66 | 0x200000A5, // EraseSector 67 | 0x200000F1, // ProgramPage 68 | 69 | // BKPT : start of blob + 1 70 | // RSB : address to access global/static data 71 | // RSP : stack pointer 72 | { 73 | 0x20000001, 74 | 0x20000C00, 75 | 0x20001000 76 | }, 77 | 78 | 0x20000400, // mem buffer location 79 | 0x20000000, // location to write prog_blob in target RAM 80 | sizeof(flash_code), // prog_blob size 81 | flash_code, // address of prog_blob 82 | 0x00000400, // ram_to_flash_bytes_to_be_written 83 | }; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/dap/STM32F4xx_1024.c: -------------------------------------------------------------------------------- 1 | /* Flash OS Routines (Automagically Generated) 2 | * Copyright (c) 2009-2015 ARM Limited 3 | */ 4 | #include "flash_blob.h" 5 | 6 | static const uint32_t flash_code[] = { 7 | 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, 8 | 0x0E000300, 0xD3022820, 0x1D000940, 0x28104770, 0x0900D302, 0x47701CC0, 0x47700880, 0x49414842, 9 | 0x49426041, 0x21006041, 0x68C16001, 0x431122F0, 0x694060C1, 0xD4060680, 0x493D483E, 0x21066001, 10 | 0x493D6041, 0x20006081, 0x48374770, 0x05426901, 0x61014311, 0x47702000, 0x4833B510, 0x24046901, 11 | 0x61014321, 0x03A26901, 0x61014311, 0x4A314933, 0x6011E000, 0x03DB68C3, 0x6901D4FB, 0x610143A1, 12 | 0xBD102000, 0xF7FFB530, 0x4927FFBB, 0x23F068CA, 0x60CA431A, 0x610C2402, 0x0700690A, 0x43020E40, 13 | 0x6908610A, 0x431003E2, 0x48246108, 0xE0004A21, 0x68CD6010, 0xD4FB03ED, 0x43A06908, 0x68C86108, 14 | 0x0F000600, 0x68C8D003, 0x60C84318, 0xBD302001, 0x4D15B570, 0x08891CC9, 0x008968EB, 0x433326F0, 15 | 0x230060EB, 0x4B16612B, 0x692CE017, 0x612C431C, 0x60046814, 0x03E468EC, 0x692CD4FC, 0x00640864, 16 | 0x68EC612C, 0x0F240624, 0x68E8D004, 0x60E84330, 0xBD702001, 0x1D121D00, 0x29001F09, 0x2000D1E5, 17 | 0x0000BD70, 0x45670123, 0x40023C00, 0xCDEF89AB, 0x00005555, 0x40003000, 0x00000FFF, 0x0000AAAA, 18 | 0x00000201, 0x00000000 19 | }; 20 | 21 | const program_target_t flash_algo = { 22 | 0x2000003D, // Init 23 | 0x2000006B, // UnInit 24 | 0x20000079, // EraseChip 25 | 0x200000A5, // EraseSector 26 | 0x200000F1, // ProgramPage 27 | 28 | // BKPT : start of blob + 1 29 | // RSB : address to access global/static data 30 | // RSP : stack pointer 31 | { 32 | 0x20000001, 33 | 0x20000C00, 34 | 0x20001000 35 | }, 36 | 37 | 0x20000400, // mem buffer location 38 | 0x20000000, // location to write prog_blob in target RAM 39 | sizeof(flash_code), // prog_blob size 40 | flash_code, // address of prog_blob 41 | 0x00000400, // ram_to_flash_bytes_to_be_written 42 | }; 43 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/dap/SWD_flash.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SWD_flash.c 3 | * @brief Program target flash through SWD 4 | */ 5 | #include "swd_host.h" 6 | #include "SWD_flash.h" 7 | 8 | 9 | extern const program_target_t flash_algo; 10 | 11 | 12 | error_t target_flash_init(uint32_t flash_start) 13 | { 14 | if (0 == swd_set_target_state_hw(RESET_PROGRAM)) { 15 | return ERROR_RESET; 16 | } 17 | 18 | // Download flash programming algorithm to target and initialise. 19 | if (0 == swd_write_memory(flash_algo.algo_start, (uint8_t *)flash_algo.algo_blob, flash_algo.algo_size)) { 20 | return ERROR_ALGO_DL; 21 | } 22 | 23 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.init, flash_start, 0, 0, 0)) { 24 | return ERROR_INIT; 25 | } 26 | 27 | return ERROR_SUCCESS; 28 | } 29 | 30 | error_t target_flash_uninit(void) 31 | { 32 | swd_set_target_state_hw(RESET_RUN); 33 | 34 | swd_off(); 35 | return ERROR_SUCCESS; 36 | } 37 | 38 | error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size) 39 | { 40 | while (size > 0) { 41 | uint32_t write_size = size > flash_algo.program_buffer_size ? flash_algo.program_buffer_size : size; 42 | 43 | // Write page to buffer 44 | if (!swd_write_memory(flash_algo.program_buffer, (uint8_t *)buf, write_size)) { 45 | return ERROR_ALGO_DATA_SEQ; 46 | } 47 | 48 | // Run flash programming 49 | if (!swd_flash_syscall_exec(&flash_algo.sys_call_s, 50 | flash_algo.program_page, 51 | addr, 52 | flash_algo.program_buffer_size, 53 | flash_algo.program_buffer, 54 | 0)) { 55 | return ERROR_WRITE; 56 | } 57 | 58 | addr += write_size; 59 | buf += write_size; 60 | size -= write_size; 61 | } 62 | 63 | return ERROR_SUCCESS; 64 | } 65 | 66 | error_t target_flash_erase_sector(uint32_t addr) 67 | { 68 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.erase_sector, addr, 0, 0, 0)) { 69 | return ERROR_ERASE_SECTOR; 70 | } 71 | 72 | return ERROR_SUCCESS; 73 | } 74 | 75 | error_t target_flash_erase_chip(void) 76 | { 77 | error_t status = ERROR_SUCCESS; 78 | 79 | if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.erase_chip, 0, 0, 0, 0)) { 80 | return ERROR_ERASE_ALL; 81 | } 82 | 83 | return status; 84 | } 85 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/dap/SWD_flash.h: -------------------------------------------------------------------------------- 1 | #ifndef __SWD_FLASH_H__ 2 | #define __SWD_FLASH_H__ 3 | 4 | #include 5 | 6 | #include "error.h" 7 | 8 | error_t target_flash_init(uint32_t flash_start); 9 | error_t target_flash_uninit(void); 10 | error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size); 11 | error_t target_flash_erase_sector(uint32_t addr); 12 | error_t target_flash_erase_chip(void); 13 | 14 | 15 | #endif // __SWD_FLASH_H__ 16 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/dap/SWD_host.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/firmware/SWD_downloader_demo/F730R8/dap/SWD_host.c -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/dap/SWD_host.h: -------------------------------------------------------------------------------- 1 | #ifndef SWDHOST_CM_H 2 | #define SWDHOST_CM_H 3 | 4 | #include 5 | 6 | #include "flash_blob.h" 7 | 8 | 9 | typedef enum { 10 | RESET_HOLD, // Hold target in reset 11 | RESET_PROGRAM, // Reset target and setup for flash programming. 12 | RESET_RUN, // Reset target and run normally 13 | NO_DEBUG, // Disable debug on running target 14 | DEBUG, // Enable debug on running target 15 | HALT, // Halt the target without resetting it 16 | RUN // Resume the target without resetting it 17 | } TARGET_RESET_STATE; 18 | 19 | 20 | uint8_t swd_init(void); 21 | uint8_t swd_off(void); 22 | uint8_t swd_init_debug(void); 23 | uint8_t swd_read_dp(uint8_t adr, uint32_t *val); 24 | uint8_t swd_write_dp(uint8_t adr, uint32_t val); 25 | uint8_t swd_read_ap(uint32_t adr, uint32_t *val); 26 | uint8_t swd_write_ap(uint32_t adr, uint32_t val); 27 | uint8_t swd_read_memory(uint32_t address, uint8_t *data, uint32_t size); 28 | uint8_t swd_write_memory(uint32_t address, uint8_t *data, uint32_t size); 29 | uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4); 30 | void swd_set_target_reset(uint8_t asserted); 31 | uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state); 32 | uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/dap/error.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file error.c 3 | * @brief collection of known errors and accessor for the friendly string 4 | */ 5 | 6 | #include "error.h" 7 | 8 | static const char *const error_message[] = { 9 | 10 | /* Shared errors */ 11 | 12 | // ERROR_SUCCESS 13 | "Operation was successful", 14 | // ERROR_FAILURE 15 | "An error has occurred", 16 | // ERROR_INTERNAL 17 | "An internal error has occurred", 18 | 19 | 20 | /* Target flash errors */ 21 | 22 | // ERROR_RESET 23 | "The interface firmware FAILED to reset/halt the target MCU", 24 | // ERROR_ALGO_DL 25 | "The interface firmware FAILED to download the flash programming algorithms to the target MCU", 26 | // ERROR_ALGO_DATA_SEQ 27 | "The interface firmware FAILED to download the flash data contents to be programmed", 28 | // ERROR_INIT 29 | "The interface firmware FAILED to initialize the target MCU", 30 | // ERROR_SECURITY_BITS 31 | "The interface firmware ABORTED programming. Image is trying to set security bits", 32 | // ERROR_UNLOCK 33 | "The interface firmware FAILED to unlock the target for programming", 34 | // ERROR_ERASE_SECTOR 35 | "Flash algorithm erase sector command FAILURE", 36 | // ERROR_ERASE_ALL 37 | "Flash algorithm erase all command FAILURE", 38 | // ERROR_WRITE 39 | "Flash algorithm write command FAILURE", 40 | }; 41 | 42 | static error_type_t error_type[] = { 43 | 44 | /* These should always stay the same for each error type. */ 45 | 46 | // ERROR_SUCCESS 47 | 0, 48 | // ERROR_FAILURE 49 | ERROR_TYPE_INTERNAL, 50 | // ERROR_INTERNAL 51 | ERROR_TYPE_INTERNAL, 52 | 53 | 54 | /* Target flash errors */ 55 | 56 | // ERROR_RESET 57 | ERROR_TYPE_TARGET, 58 | // ERROR_ALGO_DL 59 | ERROR_TYPE_TARGET, 60 | // ERROR_ALGO_DATA_SEQ 61 | ERROR_TYPE_TARGET, 62 | // ERROR_INIT 63 | ERROR_TYPE_TARGET, 64 | // ERROR_SECURITY_BITS 65 | ERROR_TYPE_USER, 66 | // ERROR_UNLOCK 67 | ERROR_TYPE_TARGET, 68 | // ERROR_ERASE_SECTOR 69 | ERROR_TYPE_TARGET, 70 | // ERROR_ERASE_ALL 71 | ERROR_TYPE_TARGET, 72 | // ERROR_WRITE 73 | ERROR_TYPE_TARGET, 74 | }; 75 | 76 | const char *error_get_string(error_t error) 77 | { 78 | const char *msg = 0; 79 | 80 | if (error < ERROR_COUNT) { 81 | msg = error_message[error]; 82 | } 83 | 84 | return msg; 85 | } 86 | 87 | error_type_t error_get_type(error_t error) 88 | { 89 | error_type_t type = ERROR_TYPE_INTERNAL; 90 | 91 | if (error < ERROR_COUNT) { 92 | type = error_type[error]; 93 | } 94 | 95 | return type; 96 | } 97 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/dap/error.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_H 2 | #define ERROR_H 3 | 4 | 5 | // Keep in sync with the lists error_message and error_type 6 | typedef enum { 7 | /* Shared errors */ 8 | ERROR_SUCCESS = 0, 9 | ERROR_FAILURE, 10 | ERROR_INTERNAL, 11 | 12 | /* Target flash errors */ 13 | ERROR_RESET, 14 | ERROR_ALGO_DL, 15 | ERROR_ALGO_DATA_SEQ, 16 | ERROR_INIT, 17 | ERROR_SECURITY_BITS, 18 | ERROR_UNLOCK, 19 | ERROR_ERASE_SECTOR, 20 | ERROR_ERASE_ALL, 21 | ERROR_WRITE, 22 | 23 | // Add new values here 24 | 25 | ERROR_COUNT 26 | } error_t; 27 | 28 | 29 | typedef unsigned char error_type_t; 30 | 31 | #define ERROR_TYPE_INTERNAL 0x1 32 | #define ERROR_TYPE_TRANSIENT 0x2 33 | #define ERROR_TYPE_USER 0x4 34 | #define ERROR_TYPE_TARGET 0x8 35 | 36 | #define ERROR_TYPE_MASK 0xF 37 | 38 | 39 | const char *error_get_string(error_t error); 40 | 41 | error_type_t error_get_type(error_t error); 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /firmware/SWD_downloader_demo/F730R8/dap/flash_blob.h: -------------------------------------------------------------------------------- 1 | #ifndef FLASH_BLOB_H 2 | #define FLASH_BLOB_H 3 | 4 | #include 5 | 6 | 7 | typedef struct { 8 | uint32_t breakpoint; 9 | uint32_t static_base; 10 | uint32_t stack_pointer; 11 | } program_syscall_t; 12 | 13 | typedef struct { 14 | const uint32_t init; 15 | const uint32_t uninit; 16 | const uint32_t erase_chip; 17 | const uint32_t erase_sector; 18 | const uint32_t program_page; 19 | const program_syscall_t sys_call_s; 20 | const uint32_t program_buffer; 21 | const uint32_t algo_start; 22 | const uint32_t algo_size; 23 | const uint32_t *algo_blob; 24 | const uint32_t program_buffer_size; 25 | } program_target_t; 26 | 27 | typedef struct { 28 | const uint32_t start; 29 | const uint32_t size; 30 | } sector_info_t; 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /hardware/USB_Downloader.PcbDoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/hardware/USB_Downloader.PcbDoc -------------------------------------------------------------------------------- /hardware/USB_Downloader.SchDoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/hardware/USB_Downloader.SchDoc -------------------------------------------------------------------------------- /hardware/USB_Downloader_V1.2.PcbDoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/hardware/USB_Downloader_V1.2.PcbDoc -------------------------------------------------------------------------------- /hardware/USB_Downloader_V1.2.SchDoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/hardware/USB_Downloader_V1.2.SchDoc -------------------------------------------------------------------------------- /hardware/V1.0/USB_Downloader.PcbDoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/hardware/V1.0/USB_Downloader.PcbDoc -------------------------------------------------------------------------------- /hardware/V1.0/USB_Downloader.SchDoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/hardware/V1.0/USB_Downloader.SchDoc -------------------------------------------------------------------------------- /hardware/V1.1/USB_Downloader.PcbDoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/hardware/V1.1/USB_Downloader.PcbDoc -------------------------------------------------------------------------------- /hardware/V1.1/USB_Downloader.SchDoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/hardware/V1.1/USB_Downloader.SchDoc -------------------------------------------------------------------------------- /hardware/V1.2/USB_Downloader.PcbDoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/hardware/V1.2/USB_Downloader.PcbDoc -------------------------------------------------------------------------------- /hardware/V1.2/USB_Downloader.SchDoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cuixudong/MyUSBDownloader/ac38354adb2598d0d91938e4348b21d79acb1a37/hardware/V1.2/USB_Downloader.SchDoc --------------------------------------------------------------------------------