├── .gitignore ├── LICENSE ├── README.md ├── binary ├── usb-bootloader.bin └── usb-bootloader.map ├── bootloader-usb ├── CMakeLists.txt ├── Drivers │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32F1xx │ │ │ │ ├── Include │ │ │ │ ├── stm32f100xb.h │ │ │ │ ├── stm32f100xe.h │ │ │ │ ├── stm32f101x6.h │ │ │ │ ├── stm32f101xb.h │ │ │ │ ├── stm32f101xe.h │ │ │ │ ├── stm32f101xg.h │ │ │ │ ├── stm32f102x6.h │ │ │ │ ├── stm32f102xb.h │ │ │ │ ├── stm32f103x6.h │ │ │ │ ├── stm32f103xb.h │ │ │ │ ├── stm32f103xe.h │ │ │ │ ├── stm32f103xg.h │ │ │ │ ├── stm32f105xc.h │ │ │ │ ├── stm32f107xc.h │ │ │ │ ├── stm32f1xx.h │ │ │ │ └── system_stm32f1xx.h │ │ │ │ └── Source │ │ │ │ └── Templates │ │ │ │ ├── gcc │ │ │ │ └── startup_stm32f103xe.asm │ │ │ │ └── system_stm32f1xx.c │ │ └── Include │ │ │ ├── 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 │ │ │ ├── core_sc000.h │ │ │ └── core_sc300.h │ ├── STM32F1xx_HAL_Driver │ │ ├── Inc │ │ │ ├── Legacy │ │ │ │ └── stm32_hal_legacy.h │ │ │ ├── stm32f1xx_hal.h │ │ │ ├── stm32f1xx_hal_cortex.h │ │ │ ├── stm32f1xx_hal_def.h │ │ │ ├── stm32f1xx_hal_dma.h │ │ │ ├── stm32f1xx_hal_dma_ex.h │ │ │ ├── stm32f1xx_hal_flash.h │ │ │ ├── stm32f1xx_hal_flash_ex.h │ │ │ ├── stm32f1xx_hal_gpio.h │ │ │ ├── stm32f1xx_hal_gpio_ex.h │ │ │ ├── stm32f1xx_hal_pcd.h │ │ │ ├── stm32f1xx_hal_pcd_ex.h │ │ │ ├── stm32f1xx_hal_pwr.h │ │ │ ├── stm32f1xx_hal_rcc.h │ │ │ ├── stm32f1xx_hal_rcc_ex.h │ │ │ ├── stm32f1xx_hal_sd.h │ │ │ ├── stm32f1xx_hal_uart.h │ │ │ ├── stm32f1xx_ll_sdmmc.h │ │ │ └── stm32f1xx_ll_usb.h │ │ └── Src │ │ │ ├── stm32f1xx_hal.c │ │ │ ├── stm32f1xx_hal_cortex.c │ │ │ ├── stm32f1xx_hal_dma.c │ │ │ ├── stm32f1xx_hal_flash.c │ │ │ ├── stm32f1xx_hal_flash_ex.c │ │ │ ├── stm32f1xx_hal_gpio.c │ │ │ ├── stm32f1xx_hal_gpio_ex.c │ │ │ ├── stm32f1xx_hal_pcd.c │ │ │ ├── stm32f1xx_hal_pcd_ex.c │ │ │ ├── stm32f1xx_hal_pwr.c │ │ │ ├── stm32f1xx_hal_rcc.c │ │ │ ├── stm32f1xx_hal_rcc_ex.c │ │ │ ├── stm32f1xx_hal_sd.c │ │ │ ├── stm32f1xx_hal_uart.c │ │ │ ├── stm32f1xx_ll_sdmmc.c │ │ │ └── stm32f1xx_ll_usb.c │ └── newlib │ │ ├── _exit.c │ │ └── _sbrk.c ├── Inc │ ├── boot.h │ ├── bootloader-config.h │ ├── bsp_driver_sd.h │ ├── cardreader.h │ ├── console.h │ ├── fatfs.h │ ├── ffconf.h │ ├── filesystem.h │ ├── flash.h │ ├── mxconstants.h │ ├── sd-utils.h │ ├── state.h │ ├── stm32f1xx_hal_conf.h │ ├── stm32f1xx_it.h │ ├── usb_device.h │ ├── usbd_conf.h │ ├── usbd_desc.h │ ├── usbd_storage_if.h │ └── utils.h ├── Middlewares │ ├── ST │ │ └── STM32_USB_Device_Library │ │ │ ├── Class │ │ │ └── MSC │ │ │ │ ├── Inc │ │ │ │ ├── usbd_msc.h │ │ │ │ ├── usbd_msc_bot.h │ │ │ │ ├── usbd_msc_data.h │ │ │ │ └── usbd_msc_scsi.h │ │ │ │ └── Src │ │ │ │ ├── usbd_msc.c │ │ │ │ ├── usbd_msc_bot.c │ │ │ │ ├── usbd_msc_data.c │ │ │ │ └── usbd_msc_scsi.c │ │ │ └── Core │ │ │ ├── Inc │ │ │ ├── usbd_core.h │ │ │ ├── usbd_ctlreq.h │ │ │ ├── usbd_def.h │ │ │ └── usbd_ioreq.h │ │ │ └── Src │ │ │ ├── usbd_core.c │ │ │ ├── usbd_ctlreq.c │ │ │ └── usbd_ioreq.c │ └── Third_Party │ │ └── FatFs │ │ └── src │ │ ├── diskio.c │ │ ├── diskio.h │ │ ├── drivers │ │ ├── sd_diskio.c │ │ └── sd_diskio.h │ │ ├── ff.c │ │ ├── ff.h │ │ ├── ff_gen_drv.c │ │ ├── ff_gen_drv.h │ │ ├── ffconf_template.h │ │ ├── integer.h │ │ └── option │ │ ├── ccsbcs.c │ │ └── syscall.c ├── Src │ ├── boot.c │ ├── bsp_driver_sd.c │ ├── cardreader.c │ ├── console.c │ ├── fatfs.c │ ├── filesystem.c │ ├── flash.c │ ├── isr-vector-stub.c │ ├── main.c │ ├── sd-utils.c │ ├── state.c │ ├── stm32f1xx_hal_msp.c │ ├── stm32f1xx_it.c │ ├── usb_device.c │ ├── usbd_conf.c │ ├── usbd_desc.c │ ├── usbd_storage_if.c │ └── utils.c ├── build.sh ├── clear.sh ├── flash └── ldscripts │ └── STM32F103RETx_FLASH.ld └── generate-eclipse-project.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | 34 | # Directories 35 | bootloader-usb/build 36 | eclipse-workspace 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Aleksey Bulatov (AlexeyABulatov@yandex.ru) 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # USB bootloader for STM32F1 microcontrollers 2 | 3 | This repository contains bootloader for `STM32F1xx` microcontrollers. It was tested only for `STM32F103RET6`, but you may easily adopt it to other MCUs from `F1` series supporting STM32 HAL library. 4 | 5 | ## What do you need? 6 | 7 | To use this bootloader you should have: 8 | 9 | - SD or MicroSD card connected to your MCU via 4-wire SDIO interface (do not forget 47kOhm resistors!). MicroSD card should works properly! File system should be Fat32. 10 | 11 | - Optionally, USB 2.0 port (type B, slave device), connected to your MCU. Do not forget 1.5kOhm resistor between D+ and 3.3V, otherwise your device will not be discovered by a computer. 12 | 13 | ## How to use bootloader 14 | 15 | You can put file `flash.bin` to SD-card with your flash image. There is no restrictions to image except it's size: it should be a bit smaller then MCU flash size to leave some place for bootloader. No image modifications (such as moving IRQ table or other) needed! You have two possibilities to put this file: 16 | 17 | - Enject microSD card and put `flash.bin` directly 18 | 19 | - Connect you MCU over USB to computer and run device. No drivers needed, your chip will run in cardreader mode. Copy `flash.bin` to MicroSD over this connection. 20 | 21 | Than disconnect your device from PC (if connected), reboot it and after tens seconds your image will be flashed to MCU and run. Bootloader checks hash sum on start, so there is no reflashing every boot. 22 | 23 | Note: when your MCU starts with bootloader, it takes control for 1 second to wait connection from PC and than boot your program. In this time all pins are pulled to zero if possible. You may change this behaviour. 24 | 25 | 26 | ## Contacts 27 | 28 | You are free to communicate with me by email: `AlexeyABulatov@yandex.ru` 29 | -------------------------------------------------------------------------------- /binary/usb-bootloader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/binary/usb-bootloader.bin -------------------------------------------------------------------------------- /bootloader-usb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(usb-bootloader C ASM) 4 | 5 | set(EXE_SOURCES 6 | Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/gcc/startup_stm32f103xe.asm 7 | Src/usbd_conf.c 8 | Src/stm32f1xx_hal_msp.c 9 | Src/utils.c 10 | Src/isr-vector-stub.c 11 | Src/bsp_driver_sd.c 12 | Src/flash.c 13 | Src/boot.c 14 | Src/state.c 15 | Src/filesystem.c 16 | Src/usb_device.c 17 | Src/console.c 18 | Src/cardreader.c 19 | Src/main.c 20 | Src/stm32f1xx_it.c 21 | Src/usbd_desc.c 22 | Src/sd-utils.c 23 | Src/fatfs.c 24 | Src/usbd_storage_if.c 25 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c 26 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c 27 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd_ex.c 28 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c 29 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c 30 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c 31 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_sd.c 32 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c 33 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c 34 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c 35 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c 36 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c 37 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_sdmmc.c 38 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c 39 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c 40 | Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c 41 | Drivers/newlib/_sbrk.c 42 | Drivers/newlib/_exit.c 43 | Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c 44 | Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c 45 | Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c 46 | Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c 47 | Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c 48 | Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c 49 | Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c 50 | Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c 51 | Middlewares/Third_Party/FatFs/src/drivers/sd_diskio.c 52 | Middlewares/Third_Party/FatFs/src/option/syscall.c 53 | Middlewares/Third_Party/FatFs/src/option/ccsbcs.c 54 | Middlewares/Third_Party/FatFs/src/ff.c 55 | Middlewares/Third_Party/FatFs/src/diskio.c 56 | Middlewares/Third_Party/FatFs/src/ff_gen_drv.c 57 | ) 58 | 59 | include_directories( 60 | Drivers/STM32F1xx_HAL_Driver/Inc 61 | Drivers/CMSIS/Include 62 | Drivers/CMSIS/Device/ST/STM32F1xx/Include 63 | Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc 64 | Middlewares/ST/STM32_USB_Device_Library/Core/Inc 65 | Middlewares/Third_Party/FatFs/src 66 | Middlewares/Third_Party/FatFs/src/drivers 67 | Inc 68 | ) 69 | 70 | set(ELF_NAME ${PROJECT_NAME}.elf) 71 | set(BIN_NAME ${PROJECT_NAME}.bin) 72 | set(MAP_NAME ${PROJECT_NAME}.map) 73 | 74 | set(LDSCRIPTS "-T STM32F103RETx_FLASH.ld") 75 | set(LDSCRIPTS_DIR "${PROJECT_SOURCE_DIR}/ldscripts") 76 | 77 | set(CMAKE_C_COMPILER arm-none-eabi-gcc) 78 | set(CMAKE_CXX_COMPILER arm-none-eabi-g++) 79 | set(CMAKE_ASM_COMPILER arm-none-eabi-g++) 80 | 81 | # This two lines to avoid error 82 | # arm-none-eabi-g++: error: unrecognized command line option '-rdynamic' 83 | # during compiler check. For some reasons test use '-rdynamic' by default, but arm-none-eabi-g* compilers does not support it 84 | set(CMAKE_C_COMPILER_WORKS 1) 85 | set(CMAKE_CXX_COMPILER_WORKS 1) 86 | 87 | # To remove -rdynamic 88 | SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS) 89 | SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) 90 | 91 | set(CMAKE_C_CXX_FLAGS "-mcpu=cortex-m3 -mthumb -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -Wall -Wextra -g3") 92 | set(CMAKE_C_CXX_FLAGS_DEBUG "-fno-move-loop-invariants -g -DDEBUG -Os") 93 | set(CMAKE_C_CXX_FLAGS_RELEASE "-Os") 94 | 95 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_CXX_FLAGS} -std=gnu11") 96 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_CXX_FLAGS_DEBUG}" ) 97 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_CXX_FLAGS_RELEASE}" ) 98 | 99 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_CXX_FLAGS} -std=gnu++11") 100 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_C_CXX_FLAGS_DEBUG}" ) 101 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_C_CXX_FLAGS_RELEASE}" ) 102 | 103 | set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp") 104 | set(CMAKE_ASM_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" ) 105 | set(CMAKE_ASM_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" ) 106 | 107 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LDSCRIPTS} -Xlinker --gc-sections -L${LDSCRIPTS_DIR} -Wl,-Map,\"${MAP_NAME}\" --specs=nano.specs") 108 | #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nostartfiles") 109 | 110 | add_definitions(-DSTM32F103xE) 111 | 112 | 113 | add_executable(${ELF_NAME} ${EXE_SOURCES}) 114 | 115 | add_custom_command(TARGET ${ELF_NAME} 116 | POST_BUILD 117 | COMMAND arm-none-eabi-objcopy ARGS -O binary ${ELF_NAME} ${BIN_NAME} 118 | ) 119 | 120 | -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f100xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f100xb.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f100xe.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f100xe.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101x6.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101x6.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xb.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xe.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xe.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f101xg.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f102x6.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f102x6.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f102xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f102xb.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103x6.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103x6.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xg.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f105xc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f105xc.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f107xc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f107xc.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DAlexis/stm32-usb-bootloader/598ab833d6b29d506dea98731bafd2c7c13a2a7a/bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V4.0.1 6 | * @date 31-July-2015 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2015 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /** @addtogroup CMSIS 39 | * @{ 40 | */ 41 | 42 | /** @addtogroup stm32f10x_system 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @brief Define to prevent recursive inclusion 48 | */ 49 | #ifndef __SYSTEM_STM32F10X_H 50 | #define __SYSTEM_STM32F10X_H 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /** @addtogroup STM32F10x_System_Includes 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | /** @addtogroup STM32F10x_System_Exported_types 66 | * @{ 67 | */ 68 | 69 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Constants 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup STM32F10x_System_Exported_Macros 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F10x_System_Exported_Functions 92 | * @{ 93 | */ 94 | 95 | extern void SystemInit(void); 96 | extern void SystemCoreClockUpdate(void); 97 | /** 98 | * @} 99 | */ 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /*__SYSTEM_STM32F10X_H */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 115 | -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Include/arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 19. March 2015 5 | * $Revision: V.1.4.5 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_common_tables.h 9 | * 10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions 11 | * 12 | * Target Processor: Cortex-M4/Cortex-M3 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions 16 | * are met: 17 | * - Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * - Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in 21 | * the documentation and/or other materials provided with the 22 | * distribution. 23 | * - Neither the name of ARM LIMITED nor the names of its contributors 24 | * may be used to endorse or promote products derived from this 25 | * software without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * -------------------------------------------------------------------- */ 40 | 41 | #ifndef _ARM_COMMON_TABLES_H 42 | #define _ARM_COMMON_TABLES_H 43 | 44 | #include "arm_math.h" 45 | 46 | extern const uint16_t armBitRevTable[1024]; 47 | extern const q15_t armRecipTableQ15[64]; 48 | extern const q31_t armRecipTableQ31[64]; 49 | //extern const q31_t realCoefAQ31[1024]; 50 | //extern const q31_t realCoefBQ31[1024]; 51 | extern const float32_t twiddleCoef_16[32]; 52 | extern const float32_t twiddleCoef_32[64]; 53 | extern const float32_t twiddleCoef_64[128]; 54 | extern const float32_t twiddleCoef_128[256]; 55 | extern const float32_t twiddleCoef_256[512]; 56 | extern const float32_t twiddleCoef_512[1024]; 57 | extern const float32_t twiddleCoef_1024[2048]; 58 | extern const float32_t twiddleCoef_2048[4096]; 59 | extern const float32_t twiddleCoef_4096[8192]; 60 | #define twiddleCoef twiddleCoef_4096 61 | extern const q31_t twiddleCoef_16_q31[24]; 62 | extern const q31_t twiddleCoef_32_q31[48]; 63 | extern const q31_t twiddleCoef_64_q31[96]; 64 | extern const q31_t twiddleCoef_128_q31[192]; 65 | extern const q31_t twiddleCoef_256_q31[384]; 66 | extern const q31_t twiddleCoef_512_q31[768]; 67 | extern const q31_t twiddleCoef_1024_q31[1536]; 68 | extern const q31_t twiddleCoef_2048_q31[3072]; 69 | extern const q31_t twiddleCoef_4096_q31[6144]; 70 | extern const q15_t twiddleCoef_16_q15[24]; 71 | extern const q15_t twiddleCoef_32_q15[48]; 72 | extern const q15_t twiddleCoef_64_q15[96]; 73 | extern const q15_t twiddleCoef_128_q15[192]; 74 | extern const q15_t twiddleCoef_256_q15[384]; 75 | extern const q15_t twiddleCoef_512_q15[768]; 76 | extern const q15_t twiddleCoef_1024_q15[1536]; 77 | extern const q15_t twiddleCoef_2048_q15[3072]; 78 | extern const q15_t twiddleCoef_4096_q15[6144]; 79 | extern const float32_t twiddleCoef_rfft_32[32]; 80 | extern const float32_t twiddleCoef_rfft_64[64]; 81 | extern const float32_t twiddleCoef_rfft_128[128]; 82 | extern const float32_t twiddleCoef_rfft_256[256]; 83 | extern const float32_t twiddleCoef_rfft_512[512]; 84 | extern const float32_t twiddleCoef_rfft_1024[1024]; 85 | extern const float32_t twiddleCoef_rfft_2048[2048]; 86 | extern const float32_t twiddleCoef_rfft_4096[4096]; 87 | 88 | 89 | /* floating-point bit reversal tables */ 90 | #define ARMBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 ) 91 | #define ARMBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 ) 92 | #define ARMBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 ) 93 | #define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 ) 94 | #define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 ) 95 | #define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 ) 96 | #define ARMBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800) 97 | #define ARMBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808) 98 | #define ARMBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032) 99 | 100 | extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE__16_TABLE_LENGTH]; 101 | extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE__32_TABLE_LENGTH]; 102 | extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE__64_TABLE_LENGTH]; 103 | extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH]; 104 | extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH]; 105 | extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH]; 106 | extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE1024_TABLE_LENGTH]; 107 | extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE2048_TABLE_LENGTH]; 108 | extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE4096_TABLE_LENGTH]; 109 | 110 | /* fixed-point bit reversal tables */ 111 | #define ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 ) 112 | #define ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 ) 113 | #define ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 ) 114 | #define ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 ) 115 | #define ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 ) 116 | #define ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 ) 117 | #define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 ) 118 | #define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) 119 | #define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) 120 | 121 | extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH]; 122 | extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH]; 123 | extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH]; 124 | extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH]; 125 | extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH]; 126 | extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH]; 127 | extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; 128 | extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; 129 | extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; 130 | 131 | /* Tables for Fast Math Sine and Cosine */ 132 | extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; 133 | extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1]; 134 | extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1]; 135 | 136 | #endif /* ARM_COMMON_TABLES_H */ 137 | -------------------------------------------------------------------------------- /bootloader-usb/Drivers/CMSIS/Include/arm_const_structs.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 19. March 2015 5 | * $Revision: V.1.4.5 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 | -------------------------------------------------------------------------------- /bootloader-usb/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_def.h 4 | * @author MCD Application Team 5 | * @version V1.0.1 6 | * @date 31-July-2015 7 | * @brief This file contains HAL common defines, enumeration, macros and 8 | * structures definitions. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | *

© COPYRIGHT(c) 2015 STMicroelectronics

13 | * 14 | * Redistribution and use in source and binary forms, with or without modification, 15 | * are permitted provided that the following conditions are met: 16 | * 1. Redistributions of source code must retain the above copyright notice, 17 | * this list of conditions and the following disclaimer. 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, 19 | * this list of conditions and the following disclaimer in the documentation 20 | * and/or other materials provided with the distribution. 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 22 | * may be used to endorse or promote products derived from this software 23 | * without specific prior written permission. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | /* Define to prevent recursive inclusion -------------------------------------*/ 40 | #ifndef __STM32F1xx_HAL_DEF 41 | #define __STM32F1xx_HAL_DEF 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /* Includes ------------------------------------------------------------------*/ 48 | #include "stm32f1xx.h" 49 | #include "Legacy/stm32_hal_legacy.h" 50 | #include 51 | 52 | /* Exported types ------------------------------------------------------------*/ 53 | 54 | /** 55 | * @brief HAL Status structures definition 56 | */ 57 | typedef enum 58 | { 59 | HAL_OK = 0x00, 60 | HAL_ERROR = 0x01, 61 | HAL_BUSY = 0x02, 62 | HAL_TIMEOUT = 0x03 63 | } HAL_StatusTypeDef; 64 | 65 | /** 66 | * @brief HAL Lock structures definition 67 | */ 68 | typedef enum 69 | { 70 | HAL_UNLOCKED = 0x00, 71 | HAL_LOCKED = 0x01 72 | } HAL_LockTypeDef; 73 | 74 | /* Exported macro ------------------------------------------------------------*/ 75 | 76 | #define HAL_MAX_DELAY 0xFFFFFFFF 77 | 78 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != RESET) 79 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == RESET) 80 | 81 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD_, __DMA_HANDLE_) \ 82 | do{ \ 83 | (__HANDLE__)->__PPP_DMA_FIELD_ = &(__DMA_HANDLE_); \ 84 | (__DMA_HANDLE_).Parent = (__HANDLE__); \ 85 | } while(0) 86 | 87 | #define UNUSED(x) ((void)(x)) 88 | 89 | /** @brief Reset the Handle's State field. 90 | * @param __HANDLE__: specifies the Peripheral Handle. 91 | * @note This macro can be used for the following purpose: 92 | * - When the Handle is declared as local variable; before passing it as parameter 93 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 94 | * to set to 0 the Handle's "State" field. 95 | * Otherwise, "State" field may have any random value and the first time the function 96 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 97 | * (i.e. HAL_PPP_MspInit() will not be executed). 98 | * - When there is a need to reconfigure the low level hardware: instead of calling 99 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 100 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 101 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 102 | * @retval None 103 | */ 104 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0) 105 | 106 | #if (USE_RTOS == 1) 107 | #error " USE_RTOS should be 0 in the current HAL release " 108 | #else 109 | #define __HAL_LOCK(__HANDLE__) \ 110 | do{ \ 111 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 112 | { \ 113 | return HAL_BUSY; \ 114 | } \ 115 | else \ 116 | { \ 117 | (__HANDLE__)->Lock = HAL_LOCKED; \ 118 | } \ 119 | }while (0) 120 | 121 | #define __HAL_UNLOCK(__HANDLE__) \ 122 | do{ \ 123 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 124 | }while (0) 125 | #endif /* USE_RTOS */ 126 | 127 | #if defined ( __GNUC__ ) 128 | #ifndef __weak 129 | #define __weak __attribute__((weak)) 130 | #endif /* __weak */ 131 | #ifndef __packed 132 | #define __packed __attribute__((__packed__)) 133 | #endif /* __packed */ 134 | #endif /* __GNUC__ */ 135 | 136 | 137 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 138 | #if defined (__GNUC__) /* GNU Compiler */ 139 | #ifndef __ALIGN_END 140 | #define __ALIGN_END __attribute__ ((aligned (4))) 141 | #endif /* __ALIGN_END */ 142 | #ifndef __ALIGN_BEGIN 143 | #define __ALIGN_BEGIN 144 | #endif /* __ALIGN_BEGIN */ 145 | #else 146 | #ifndef __ALIGN_END 147 | #define __ALIGN_END 148 | #endif /* __ALIGN_END */ 149 | #ifndef __ALIGN_BEGIN 150 | #if defined (__CC_ARM) /* ARM Compiler */ 151 | #define __ALIGN_BEGIN __align(4) 152 | #elif defined (__ICCARM__) /* IAR Compiler */ 153 | #define __ALIGN_BEGIN 154 | #endif /* __CC_ARM */ 155 | #endif /* __ALIGN_BEGIN */ 156 | #endif /* __GNUC__ */ 157 | 158 | /** 159 | * @brief __RAM_FUNC definition 160 | */ 161 | #if defined ( __CC_ARM ) 162 | /* ARM Compiler 163 | ------------ 164 | RAM functions are defined using the toolchain options. 165 | Functions that are executed in RAM should reside in a separate source module. 166 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 167 | area of a module to a memory space in physical RAM. 168 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 169 | dialog. 170 | */ 171 | #define __RAM_FUNC HAL_StatusTypeDef 172 | 173 | #elif defined ( __ICCARM__ ) 174 | /* ICCARM Compiler 175 | --------------- 176 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 177 | */ 178 | #define __RAM_FUNC __ramfunc HAL_StatusTypeDef 179 | 180 | #elif defined ( __GNUC__ ) 181 | /* GNU Compiler 182 | ------------ 183 | RAM functions are defined using a specific toolchain attribute 184 | "__attribute__((section(".RamFunc")))". 185 | */ 186 | #define __RAM_FUNC HAL_StatusTypeDef __attribute__((section(".RamFunc"))) 187 | 188 | #endif 189 | 190 | /** 191 | * @brief __NOINLINE definition 192 | */ 193 | #if defined ( __CC_ARM ) || defined ( __GNUC__ ) 194 | /* ARM & GNUCompiler 195 | ---------------- 196 | */ 197 | #define __NOINLINE __attribute__ ( (noinline) ) 198 | 199 | #elif defined ( __ICCARM__ ) 200 | /* ICCARM Compiler 201 | --------------- 202 | */ 203 | #define __NOINLINE _Pragma("optimize = no_inline") 204 | 205 | #endif 206 | 207 | 208 | #ifdef __cplusplus 209 | } 210 | #endif 211 | 212 | #endif /* ___STM32F1xx_HAL_DEF */ 213 | 214 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 215 | -------------------------------------------------------------------------------- /bootloader-usb/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pcd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_pcd_ex.h 4 | * @author MCD Application Team 5 | * @version V1.0.1 6 | * @date 31-July-2015 7 | * @brief Header file of Extended PCD HAL module. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2015 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32F1xx_HAL_PCD_EX_H 40 | #define __STM32F1xx_HAL_PCD_EX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #if defined(STM32F102x6) || defined(STM32F102xB) || \ 47 | defined(STM32F103x6) || defined(STM32F103xB) || \ 48 | defined(STM32F103xE) || defined(STM32F103xG) || \ 49 | defined(STM32F105xC) || defined(STM32F107xC) 50 | 51 | /* Includes ------------------------------------------------------------------*/ 52 | #include "stm32f1xx_hal_def.h" 53 | 54 | /** @addtogroup STM32F1xx_HAL_Driver 55 | * @{ 56 | */ 57 | 58 | /** @addtogroup PCDEx 59 | * @{ 60 | */ 61 | 62 | /* Exported types ------------------------------------------------------------*/ 63 | /* Exported constants --------------------------------------------------------*/ 64 | /* Exported macros -----------------------------------------------------------*/ 65 | /* Exported functions --------------------------------------------------------*/ 66 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 67 | * @{ 68 | */ 69 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 70 | * @{ 71 | */ 72 | #if defined (USB_OTG_FS) 73 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); 74 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); 75 | #endif /* USB_OTG_FS */ 76 | 77 | #if defined (USB) 78 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, 79 | uint16_t ep_addr, 80 | uint16_t ep_kind, 81 | uint32_t pmaadress); 82 | #endif /* USB */ 83 | /** 84 | * @} 85 | */ 86 | 87 | /** @addtogroup PCDEx_Exported_Functions_Group2 Peripheral State functions 88 | * @{ 89 | */ 90 | void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); 91 | /** 92 | * @} 93 | */ 94 | /** 95 | * @} 96 | */ 97 | /** 98 | * @} 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | #endif /* STM32F102x6 || STM32F102xB || */ 105 | /* STM32F103x6 || STM32F103xB || */ 106 | /* STM32F103xE || STM32F103xG || */ 107 | /* STM32F105xC || STM32F107xC */ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | 114 | #endif /* __STM32F1xx_HAL_PCD_EX_H */ 115 | 116 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 117 | -------------------------------------------------------------------------------- /bootloader-usb/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_gpio_ex.c 4 | * @author MCD Application Team 5 | * @version V1.0.1 6 | * @date 31-July-2015 7 | * @brief GPIO Extension HAL module driver. 8 | * This file provides firmware functions to manage the following 9 | * functionalities of the General Purpose Input/Output (GPIO) extension peripheral. 10 | * + Extended features functions 11 | * 12 | @verbatim 13 | ============================================================================== 14 | ##### GPIO Peripheral extension features ##### 15 | ============================================================================== 16 | [..] GPIO module on STM32F1 family, manage also the AFIO register: 17 | (+) Possibility to use the EVENTOUT Cortex feature 18 | 19 | ##### How to use this driver ##### 20 | ============================================================================== 21 | [..] This driver provides functions to use EVENTOUT Cortex feature 22 | (#) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout() 23 | (#) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout() 24 | (#) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout() 25 | 26 | @endverbatim 27 | ****************************************************************************** 28 | * @attention 29 | * 30 | *

© COPYRIGHT(c) 2015 STMicroelectronics

31 | * 32 | * Redistribution and use in source and binary forms, with or without modification, 33 | * are permitted provided that the following conditions are met: 34 | * 1. Redistributions of source code must retain the above copyright notice, 35 | * this list of conditions and the following disclaimer. 36 | * 2. Redistributions in binary form must reproduce the above copyright notice, 37 | * this list of conditions and the following disclaimer in the documentation 38 | * and/or other materials provided with the distribution. 39 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 40 | * may be used to endorse or promote products derived from this software 41 | * without specific prior written permission. 42 | * 43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 44 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 45 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 46 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 47 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 48 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 49 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 50 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 51 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 52 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 53 | * 54 | ****************************************************************************** 55 | */ 56 | 57 | /* Includes ------------------------------------------------------------------*/ 58 | #include "stm32f1xx_hal.h" 59 | 60 | /** @addtogroup STM32F1xx_HAL_Driver 61 | * @{ 62 | */ 63 | 64 | /** @defgroup GPIOEx GPIOEx 65 | * @brief GPIO HAL module driver 66 | * @{ 67 | */ 68 | 69 | #ifdef HAL_GPIO_MODULE_ENABLED 70 | 71 | /** @defgroup GPIOEx_Exported_Functions GPIOEx Exported Functions 72 | * @{ 73 | */ 74 | 75 | /** @defgroup GPIOEx_Exported_Functions_Group1 Extended features functions 76 | * @brief Extended features functions 77 | * 78 | @verbatim 79 | ============================================================================== 80 | ##### Extended features functions ##### 81 | ============================================================================== 82 | [..] This section provides functions allowing to: 83 | (+) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout() 84 | (+) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout() 85 | (+) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout() 86 | 87 | @endverbatim 88 | * @{ 89 | */ 90 | 91 | /** 92 | * @brief Configures the port and pin on which the EVENTOUT Cortex signal will be connected. 93 | * @param GPIO_PortSource Select the port used to output the Cortex EVENTOUT signal. 94 | * This parameter can be a value of @ref GPIOEx_EVENTOUT_PORT. 95 | * @param GPIO_PinSource Select the pin used to output the Cortex EVENTOUT signal. 96 | * This parameter can be a value of @ref GPIOEx_EVENTOUT_PIN. 97 | * @retval None 98 | */ 99 | void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource) 100 | { 101 | /* Verify the parameters */ 102 | assert_param(IS_AFIO_EVENTOUT_PORT(GPIO_PortSource)); 103 | assert_param(IS_AFIO_EVENTOUT_PIN(GPIO_PinSource)); 104 | 105 | /* Apply the new configuration */ 106 | MODIFY_REG(AFIO->EVCR, (AFIO_EVCR_PORT)|(AFIO_EVCR_PIN), (GPIO_PortSource)|(GPIO_PinSource)); 107 | } 108 | 109 | /** 110 | * @brief Enables the Event Output. 111 | * @retval None 112 | */ 113 | void HAL_GPIOEx_EnableEventout(void) 114 | { 115 | SET_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); 116 | } 117 | 118 | /** 119 | * @brief Disables the Event Output. 120 | * @retval None 121 | */ 122 | void HAL_GPIOEx_DisableEventout(void) 123 | { 124 | CLEAR_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); 125 | } 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | #endif /* HAL_GPIO_MODULE_ENABLED */ 136 | 137 | /** 138 | * @} 139 | */ 140 | 141 | /** 142 | * @} 143 | */ 144 | 145 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 146 | -------------------------------------------------------------------------------- /bootloader-usb/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_pcd_ex.c 4 | * @author MCD Application Team 5 | * @version V1.0.1 6 | * @date 31-July-2015 7 | * @brief Extended PCD HAL module driver. 8 | * This file provides firmware functions to manage the following 9 | * functionalities of the USB Peripheral Controller: 10 | * + Extended features functions: Update FIFO configuration, 11 | * PMA configuration for EPs 12 | * 13 | ****************************************************************************** 14 | * @attention 15 | * 16 | *

© COPYRIGHT(c) 2015 STMicroelectronics

17 | * 18 | * Redistribution and use in source and binary forms, with or without modification, 19 | * are permitted provided that the following conditions are met: 20 | * 1. Redistributions of source code must retain the above copyright notice, 21 | * this list of conditions and the following disclaimer. 22 | * 2. Redistributions in binary form must reproduce the above copyright notice, 23 | * this list of conditions and the following disclaimer in the documentation 24 | * and/or other materials provided with the distribution. 25 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 26 | * may be used to endorse or promote products derived from this software 27 | * without specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 30 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 31 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 32 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 33 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 36 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 37 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | * 40 | ****************************************************************************** 41 | */ 42 | 43 | /* Includes ------------------------------------------------------------------*/ 44 | #include "stm32f1xx_hal.h" 45 | 46 | /** @addtogroup STM32F1xx_HAL_Driver 47 | * @{ 48 | */ 49 | 50 | #ifdef HAL_PCD_MODULE_ENABLED 51 | 52 | #if defined(STM32F102x6) || defined(STM32F102xB) || \ 53 | defined(STM32F103x6) || defined(STM32F103xB) || \ 54 | defined(STM32F103xE) || defined(STM32F103xG) || \ 55 | defined(STM32F105xC) || defined(STM32F107xC) 56 | 57 | 58 | /** @defgroup PCDEx PCDEx 59 | * @brief PCD Extended HAL module driver 60 | * @{ 61 | */ 62 | 63 | 64 | /* Private types -------------------------------------------------------------*/ 65 | /* Private variables ---------------------------------------------------------*/ 66 | /* Private constants ---------------------------------------------------------*/ 67 | /* Private macros ------------------------------------------------------------*/ 68 | /* Private functions ---------------------------------------------------------*/ 69 | /* Exported functions --------------------------------------------------------*/ 70 | /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions 71 | * @{ 72 | */ 73 | 74 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 75 | * @brief PCDEx control functions 76 | * 77 | @verbatim 78 | =============================================================================== 79 | ##### Extended Peripheral Control functions ##### 80 | =============================================================================== 81 | [..] This section provides functions allowing to: 82 | (+) Update FIFO (USB_OTG_FS) 83 | (+) Update PMA configuration (USB) 84 | 85 | @endverbatim 86 | * @{ 87 | */ 88 | 89 | #if defined (USB_OTG_FS) 90 | /** 91 | * @brief Set Tx FIFO 92 | * @param hpcd: PCD handle 93 | * @param fifo: The number of Tx fifo 94 | * @param size: Fifo size 95 | * @retval HAL status 96 | */ 97 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size) 98 | { 99 | uint8_t index = 0; 100 | uint32_t Tx_Offset = 0; 101 | 102 | /* TXn min size = 16 words. (n : Transmit FIFO index) 103 | When a TxFIFO is not used, the Configuration should be as follows: 104 | case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes) 105 | --> Txm can use the space allocated for Txn. 106 | case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes) 107 | --> Txn should be configured with the minimum space of 16 words 108 | The FIFO is used optimally when used TxFIFOs are allocated in the top 109 | of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones. 110 | When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */ 111 | 112 | Tx_Offset = hpcd->Instance->GRXFSIZ; 113 | 114 | if(fifo == 0) 115 | { 116 | hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (size << 16) | Tx_Offset; 117 | } 118 | else 119 | { 120 | Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16; 121 | for (index = 0; index < (fifo - 1); index++) 122 | { 123 | Tx_Offset += (hpcd->Instance->DIEPTXF[index] >> 16); 124 | } 125 | 126 | /* Multiply Tx_Size by 2 to get higher performance */ 127 | hpcd->Instance->DIEPTXF[fifo - 1] = (size << 16) | Tx_Offset; 128 | 129 | } 130 | 131 | return HAL_OK; 132 | } 133 | 134 | /** 135 | * @brief Set Rx FIFO 136 | * @param hpcd: PCD handle 137 | * @param size: Size of Rx fifo 138 | * @retval HAL status 139 | */ 140 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size) 141 | { 142 | hpcd->Instance->GRXFSIZ = size; 143 | return HAL_OK; 144 | } 145 | #endif /* USB_OTG_FS */ 146 | 147 | #if defined (USB) 148 | /** 149 | * @brief Configure PMA for EP 150 | * @param hpcd : Device instance 151 | * @param ep_addr: endpoint address 152 | * @param ep_kind: endpoint Kind 153 | * USB_SNG_BUF: Single Buffer used 154 | * USB_DBL_BUF: Double Buffer used 155 | * @param pmaadress: EP address in The PMA: In case of single buffer endpoint 156 | * this parameter is 16-bit value providing the address 157 | * in PMA allocated to endpoint. 158 | * In case of double buffer endpoint this parameter 159 | * is a 32-bit value providing the endpoint buffer 0 address 160 | * in the LSB part of 32-bit value and endpoint buffer 1 address 161 | * in the MSB part of 32-bit value. 162 | * @retval HAL status 163 | */ 164 | 165 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, 166 | uint16_t ep_addr, 167 | uint16_t ep_kind, 168 | uint32_t pmaadress) 169 | 170 | { 171 | PCD_EPTypeDef *ep = NULL; 172 | 173 | /* initialize ep structure*/ 174 | if ((0x80 & ep_addr) == 0x80) 175 | { 176 | ep = &hpcd->IN_ep[ep_addr & 0x7F]; 177 | } 178 | else 179 | { 180 | ep = &hpcd->OUT_ep[ep_addr]; 181 | } 182 | 183 | /* Here we check if the endpoint is single or double Buffer*/ 184 | if (ep_kind == PCD_SNG_BUF) 185 | { 186 | /*Single Buffer*/ 187 | ep->doublebuffer = 0; 188 | /*Configure te PMA*/ 189 | ep->pmaadress = (uint16_t)pmaadress; 190 | } 191 | else /*USB_DBL_BUF*/ 192 | { 193 | /*Double Buffer Endpoint*/ 194 | ep->doublebuffer = 1; 195 | /*Configure the PMA*/ 196 | ep->pmaaddr0 = pmaadress & 0xFFFF; 197 | ep->pmaaddr1 = (pmaadress & 0xFFFF0000) >> 16; 198 | } 199 | 200 | return HAL_OK; 201 | } 202 | #endif /* USB */ 203 | /** 204 | * @} 205 | */ 206 | 207 | /** @defgroup PCDEx_Exported_Functions_Group2 Peripheral State functions 208 | * @brief Manage device connection state 209 | * @{ 210 | */ 211 | /** 212 | * @brief Software Device Connection, 213 | * this function is not required by USB OTG FS peripheral, it is used 214 | * only by USB Device FS peripheral. 215 | * @param hpcd: PCD handle 216 | * @param state: connection state (0 : disconnected / 1: connected) 217 | * @retval None 218 | */ 219 | __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) 220 | { 221 | /* NOTE : This function Should not be modified, when the callback is needed, 222 | the HAL_PCDEx_SetConnectionState could be implemented in the user file 223 | */ 224 | } 225 | /** 226 | * @} 227 | */ 228 | 229 | /** 230 | * @} 231 | */ 232 | 233 | /** 234 | * @} 235 | */ 236 | 237 | #endif /* STM32F102x6 || STM32F102xB || */ 238 | /* STM32F103x6 || STM32F103xB || */ 239 | /* STM32F103xE || STM32F103xG || */ 240 | /* STM32F105xC || STM32F107xC */ 241 | 242 | #endif /* HAL_PCD_MODULE_ENABLED */ 243 | 244 | 245 | /** 246 | * @} 247 | */ 248 | 249 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 250 | -------------------------------------------------------------------------------- /bootloader-usb/Drivers/newlib/_exit.c: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | // ---------------------------------------------------------------------------- 7 | 8 | #include 9 | //#include "diag/Trace.h" 10 | 11 | // ---------------------------------------------------------------------------- 12 | 13 | extern void 14 | __attribute__((noreturn)) 15 | __reset_hardware(void); 16 | 17 | // ---------------------------------------------------------------------------- 18 | 19 | // Forward declaration 20 | 21 | void 22 | _exit(int code); 23 | 24 | // ---------------------------------------------------------------------------- 25 | 26 | // On Release, call the hardware reset procedure. 27 | // On Debug we just enter an infinite loop, to be used as landmark when halting 28 | // the debugger. 29 | // 30 | // It can be redefined in the application, if more functionality 31 | // is required. 32 | 33 | void 34 | __attribute__((weak)) 35 | _exit(int code __attribute__((unused))) 36 | { 37 | #if !defined(DEBUG) 38 | //__reset_hardware(); 39 | #endif 40 | 41 | // TODO: write on trace 42 | while (1) 43 | ; 44 | } 45 | 46 | // ---------------------------------------------------------------------------- 47 | 48 | void 49 | __attribute__((weak,noreturn)) 50 | abort(void) 51 | { 52 | //trace_puts("abort(), exiting..."); 53 | 54 | _exit(1); 55 | } 56 | 57 | // ---------------------------------------------------------------------------- 58 | -------------------------------------------------------------------------------- /bootloader-usb/Drivers/newlib/_sbrk.c: -------------------------------------------------------------------------------- 1 | // 2 | // This file is part of the µOS++ III distribution. 3 | // Copyright (c) 2014 Liviu Ionescu. 4 | // 5 | 6 | // ---------------------------------------------------------------------------- 7 | 8 | #include 9 | #include 10 | 11 | // ---------------------------------------------------------------------------- 12 | 13 | caddr_t 14 | _sbrk(int incr); 15 | 16 | // ---------------------------------------------------------------------------- 17 | 18 | // The definitions used here should be kept in sync with the 19 | // stack definitions in the linker script. 20 | 21 | caddr_t 22 | _sbrk(int incr) 23 | { 24 | // _write (1, "_sbrk\n", 6); 25 | extern char _Heap_Begin; // Defined by the linker. 26 | extern char _Heap_Limit; // Defined by the linker. 27 | //extern char isMemoryCorrupted; 28 | 29 | static char* current_heap_end; 30 | char* current_block_address; 31 | 32 | if (current_heap_end == 0) 33 | { 34 | current_heap_end = &_Heap_Begin; 35 | } 36 | 37 | current_block_address = current_heap_end; 38 | 39 | // Need to align heap to word boundary, else will get 40 | // hard faults on Cortex-M0. So we assume that heap starts on 41 | // word boundary, hence make sure we always add a multiple of 42 | // 4 to it. 43 | incr = (incr + 3) & (~3); // align value to 4 44 | if (current_heap_end + incr > &_Heap_Limit) 45 | { 46 | // Some of the libstdc++-v3 tests rely upon detecting 47 | // out of memory errors, so do not abort here. 48 | #if 0 49 | extern void abort (void); 50 | 51 | _write (1, "_sbrk: Heap and stack collision\n", 32); 52 | 53 | abort (); 54 | #else 55 | // Heap has overflowed 56 | //isMemoryCorrupted = 1; 57 | 58 | errno = ENOMEM; 59 | return (caddr_t) - 1; 60 | #endif 61 | } 62 | 63 | current_heap_end += incr; 64 | 65 | return (caddr_t) current_block_address; 66 | } 67 | 68 | // ---------------------------------------------------------------------------- 69 | 70 | 71 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/boot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * boot.h 3 | * 4 | * Created on: 5 сент. 2016 г. 5 | * Author: alexey 6 | */ 7 | 8 | #ifndef BOOTLOADER_USB_BOOTLOADER_USB_INC_BOOT_H_ 9 | #define BOOTLOADER_USB_BOOTLOADER_USB_INC_BOOT_H_ 10 | 11 | void bootMainProgram(); 12 | void reboot(); 13 | 14 | 15 | #endif /* BOOTLOADER_USB_BOOTLOADER_USB_INC_BOOT_H_ */ 16 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/bootloader-config.h: -------------------------------------------------------------------------------- 1 | #ifndef BOOTLOADER_USB_BOOTLOADER_USB_INC_BOOTLOADER_CONFIG_H_ 2 | #define BOOTLOADER_USB_BOOTLOADER_USB_INC_BOOTLOADER_CONFIG_H_ 3 | 4 | #define FIRMWARE_FILE_NAME "flash.bin" 5 | #define FIRMWARE_HASH_FILE_NAME "flash.ly" 6 | 7 | 8 | // Uncomment this if hash check for firmware is mandatory. 9 | // By default if hash file missing firmware considered as correct 10 | //#define HASH_CHECK_IS_MANDATORY 11 | 12 | 13 | // Comment out the following to totally disable UART output 14 | #define UART_ENABLED 15 | #define UART_BAUDRATE 921600 16 | 17 | 18 | 19 | #define USB_WAITING_PERIOD 1000 20 | 21 | 22 | #endif /* BOOTLOADER_USB_BOOTLOADER_USB_INC_BOOTLOADER_CONFIG_H_ */ 23 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/bsp_driver_sd.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file bsp_driver_sd.h (based on stm3210e_eval_sd.h) 4 | * @brief This file contains the common defines and functions prototypes for 5 | * the bsp_driver_sd.c driver. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2015 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Define to prevent recursive inclusion -------------------------------------*/ 36 | #ifndef __STM32F1XX_SD_H 37 | #define __STM32F1XX_SD_H 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /* Includes ------------------------------------------------------------------*/ 44 | #include "stm32f1xx_hal.h" 45 | 46 | /* Exported constants --------------------------------------------------------*/ 47 | 48 | /** 49 | * @brief SD Card information structure 50 | */ 51 | #ifndef SD_CardInfo 52 | #define SD_CardInfo HAL_SD_CardInfoTypedef 53 | #endif 54 | 55 | /** 56 | * @brief SD status structure definition 57 | */ 58 | #define MSD_OK 0x00 59 | #define MSD_ERROR 0x01 60 | 61 | /* Exported constants --------------------------------------------------------*/ 62 | 63 | /** @defgroup STM3210E_EVAL_SD_Exported_Constants Exported_Constants 64 | * @{ 65 | */ 66 | 67 | /* USER CODE BEGIN 0 */ 68 | 69 | #define __SD_DETECT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOF_CLK_ENABLE() 70 | #define SD_DETECT_IRQn EXTI15_10_IRQn 71 | #define SD_DATATIMEOUT ((uint32_t)100000000) 72 | 73 | #define SD_PRESENT ((uint8_t)0x01) 74 | #define SD_NOT_PRESENT ((uint8_t)0x00) 75 | 76 | /* DMA definitions for SD DMA transfer */ 77 | /* 78 | #define __DMAx_TxRx_CLK_ENABLE __HAL_RCC_DMA2_CLK_ENABLE 79 | #define SD_DMAx_Tx_INSTANCE DMA2_Channel4 80 | #define SD_DMAx_Rx_INSTANCE DMA2_Channel4 81 | #define SD_DMAx_Tx_IRQn DMA2_Channel4_5_IRQn 82 | #define SD_DMAx_Rx_IRQn DMA2_Channel4_5_IRQn 83 | #define SD_DMAx_Tx_IRQHandler DMA2_Channel4_5_IRQHandler 84 | #define SD_DMAx_Rx_IRQHandler DMA2_Channel4_5_IRQHandler 85 | */ 86 | 87 | /* Exported functions --------------------------------------------------------*/ 88 | /** @addtogroup STM3210E_EVAL_SD_Exported_Functions 89 | * @{ 90 | */ 91 | uint8_t BSP_SD_Init(void); 92 | uint8_t BSP_SD_ITConfig(void); 93 | void BSP_SD_DetectIT(void); 94 | void BSP_SD_DetectCallback(void); 95 | uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumOfBlocks); 96 | uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumOfBlocks); 97 | uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint64_t ReadAddr, uint32_t BlockSize, uint32_t NumOfBlocks); 98 | uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint64_t WriteAddr, uint32_t BlockSize, uint32_t NumOfBlocks); 99 | uint8_t BSP_SD_Erase(uint64_t StartAddr, uint64_t EndAddr); 100 | void BSP_SD_IRQHandler(void); 101 | void BSP_SD_DMA_Tx_IRQHandler(void); 102 | void BSP_SD_DMA_Rx_IRQHandler(void); 103 | HAL_SD_TransferStateTypedef BSP_SD_GetStatus(void); 104 | void BSP_SD_GetCardInfo(HAL_SD_CardInfoTypedef *CardInfo); 105 | uint8_t BSP_SD_IsDetected(void); 106 | /* USER CODE END 0 */ 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* __STM32F1XX_SD_H */ 113 | 114 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 115 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/cardreader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cardreader.h 3 | * 4 | * Created on: 15 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | #ifndef INC_CARDREADER_H_ 9 | #define INC_CARDREADER_H_ 10 | 11 | #include 12 | 13 | void initCardreader(); 14 | void deinitCardreader(); 15 | int isCardreaderActive(); 16 | 17 | /** 18 | * Enable cardreader for duration and stop it if no USB connection occured. 19 | * Otherwise infinite cardreader mode. 20 | */ 21 | void temporaryEnableCardreader(uint32_t duration); 22 | 23 | #endif /* INC_CARDREADER_H_ */ 24 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/console.h: -------------------------------------------------------------------------------- 1 | /* 2 | * console.h 3 | * 4 | * Created on: 9 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | #ifndef INCLUDE_CONSOLE_H_ 9 | #define INCLUDE_CONSOLE_H_ 10 | 11 | void initConsole(); 12 | 13 | void deinitConsile(); 14 | 15 | void infiniteMessage(const char* msg); 16 | 17 | #endif /* INCLUDE_CONSOLE_H_ */ 18 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/fatfs.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file fatfs.h 4 | * @brief Header for fatfs applications 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2015 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __fatfs_H 36 | #define __fatfs_H 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #include "ff.h" 42 | #include "ff_gen_drv.h" 43 | #include "sd_diskio.h" /* defines SD_Driver as external */ 44 | 45 | /* USER CODE BEGIN Includes */ 46 | 47 | /* USER CODE END Includes */ 48 | 49 | extern uint8_t retSD; /* Return value for SD */ 50 | extern char SD_Path[4]; /* SD logical drive path */ 51 | 52 | void MX_FATFS_Init(void); 53 | 54 | /* USER CODE BEGIN Prototypes */ 55 | 56 | /* USER CODE END Prototypes */ 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | #endif /*__fatfs_H */ 61 | 62 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 63 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/filesystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * filesystem.h 3 | * 4 | * Created on: 5 сент. 2016 г. 5 | * Author: alexey 6 | */ 7 | 8 | #ifndef BOOTLOADER_USB_BOOTLOADER_USB_INC_FILESYSTEM_H_ 9 | #define BOOTLOADER_USB_BOOTLOADER_USB_INC_FILESYSTEM_H_ 10 | 11 | #include 12 | 13 | #define FILESYSTEM_INIT_OK 0 14 | #define FILESYSTEM_INIT_FAIL 1 15 | 16 | uint8_t initFilesystem(); 17 | void deinitFilesystem(); 18 | 19 | 20 | 21 | 22 | #endif /* BOOTLOADER_USB_BOOTLOADER_USB_INC_FILESYSTEM_H_ */ 23 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/flash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * flash.h 3 | * 4 | * Created on: 9 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | #ifndef INCLUDE_FLASH_H_ 9 | #define INCLUDE_FLASH_H_ 10 | 11 | #include 12 | 13 | typedef enum 14 | { 15 | FLASH_FILE_OK = 0, 16 | FLASH_FILE_NOT_EXISTS, 17 | FLASH_FILE_CANNOT_OPEN, 18 | FLASH_FILE_INVALID_HASH, 19 | FLASH_FILE_TOO_BIG 20 | } HashCheckResult; 21 | 22 | typedef enum 23 | { 24 | FLASH_RESULT_OK = 0, 25 | FLASH_RESULT_FILE_ERROR, 26 | FLASH_RESULT_FLASH_ERROR 27 | } FlashResult; 28 | 29 | uint32_t getMaxFlashImageSize(); 30 | 31 | HashCheckResult checkFlashFile(uint32_t* hash, uint32_t* trueHash, uint32_t* flashFileSize); 32 | 33 | void bootIfReady(); 34 | FlashResult flash(); ///@todo add callback for progress 35 | 36 | 37 | 38 | #endif /* INCLUDE_FLASH_H_ */ 39 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/mxconstants.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : mxconstants.h 4 | * Description : This file contains the common defines of the application 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2015 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | /* Includes ------------------------------------------------------------------*/ 34 | 35 | /* USER CODE BEGIN Includes */ 36 | 37 | /* USER CODE END Includes */ 38 | 39 | /* Private define ------------------------------------------------------------*/ 40 | 41 | /* USER CODE BEGIN Private defines */ 42 | 43 | /* USER CODE END Private defines */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | /** 50 | * @} 51 | */ 52 | 53 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 54 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/sd-utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sd-utils.h 3 | * 4 | * Created on: 15 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | #ifndef INC_SD_UTILS_H_ 9 | #define INC_SD_UTILS_H_ 10 | 11 | void MX_SDIO_SD_Init(void); 12 | 13 | #endif /* INC_SD_UTILS_H_ */ 14 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * state.h 3 | * 4 | * Created on: 5 сент. 2016 г. 5 | * Author: alexey 6 | */ 7 | 8 | #ifndef BOOTLOADER_USB_BOOTLOADER_USB_INC_STATE_H_ 9 | #define BOOTLOADER_USB_BOOTLOADER_USB_INC_STATE_H_ 10 | 11 | #define LOADER_SATE_NO_FLASH 0x1234 12 | #define LOADER_SATE_HAS_FLASH 0x4321 13 | 14 | #include 15 | 16 | typedef struct { 17 | uint32_t state; 18 | uint32_t mainProgramStackPointer; 19 | uint32_t mainProgramResetHandler; 20 | uint32_t hash; 21 | } LoaderState; 22 | 23 | extern LoaderState state; 24 | 25 | void saveState(); 26 | void readState(); 27 | 28 | 29 | #endif /* BOOTLOADER_USB_BOOTLOADER_USB_INC_STATE_H_ */ 30 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/stm32f1xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_it.h 4 | * @brief This file contains the headers of the interrupt handlers. 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2015 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __STM32F1xx_IT_H 36 | #define __STM32F1xx_IT_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | /* Exported types ------------------------------------------------------------*/ 44 | /* Exported constants --------------------------------------------------------*/ 45 | /* Exported macro ------------------------------------------------------------*/ 46 | /* Exported functions ------------------------------------------------------- */ 47 | 48 | void SysTick_Handler(void); 49 | void USB_LP_CAN1_RX0_IRQHandler(void); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* __STM32F1xx_IT_H */ 56 | 57 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 58 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/usb_device.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : USB_DEVICE 4 | * @version : v1.0_Cube 5 | * @brief : Header for usb_device file. 6 | ****************************************************************************** 7 | * COPYRIGHT(c) 2015 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | /* Define to prevent recursive inclusion -------------------------------------*/ 34 | #ifndef __usb_device_H 35 | #define __usb_device_H 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /* Includes ------------------------------------------------------------------*/ 41 | #include "stm32f1xx.h" 42 | #include "stm32f1xx_hal.h" 43 | #include "usbd_def.h" 44 | 45 | extern USBD_HandleTypeDef hUsbDeviceFS; 46 | 47 | /* USB_Device init function */ 48 | void MX_USB_DEVICE_Init(void); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | #endif /*__usb_device_H */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 64 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : usbd_conf.h 4 | * @version : v1.0_Cube 5 | * @brief : Header for usbd_conf file. 6 | ****************************************************************************** 7 | * COPYRIGHT(c) 2015 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | /* Define to prevent recursive inclusion -------------------------------------*/ 34 | #ifndef __USBD_CONF__H__ 35 | #define __USBD_CONF__H__ 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | /* Includes ------------------------------------------------------------------*/ 40 | #include 41 | #include 42 | #include 43 | #include "stm32f1xx.h" 44 | #include "stm32f1xx_hal.h" 45 | #include "usbd_def.h" 46 | 47 | /** @addtogroup USBD_OTG_DRIVER 48 | * @{ 49 | */ 50 | 51 | /** @defgroup USBD_CONF 52 | * @brief usb otg low level driver configuration file 53 | * @{ 54 | */ 55 | 56 | /** @defgroup USBD_CONF_Exported_Defines 57 | * @{ 58 | */ 59 | 60 | /*---------- -----------*/ 61 | #define USBD_MAX_NUM_INTERFACES 1 62 | /*---------- -----------*/ 63 | #define USBD_MAX_NUM_CONFIGURATION 1 64 | /*---------- -----------*/ 65 | #define USBD_MAX_STR_DESC_SIZ 512 66 | /*---------- -----------*/ 67 | #define USBD_SUPPORT_USER_STRING 0 68 | /*---------- -----------*/ 69 | #define USBD_DEBUG_LEVEL 0 70 | /*---------- -----------*/ 71 | #define USBD_SELF_POWERED 1 72 | /*---------- -----------*/ 73 | #define MSC_MEDIA_PACKET 512 74 | /****************************************/ 75 | /* #define for FS and HS identification */ 76 | #define DEVICE_FS 0 77 | 78 | /** @defgroup USBD_Exported_Macros 79 | * @{ 80 | */ 81 | 82 | /* Memory management macros */ 83 | #define USBD_malloc (uint32_t *)USBD_static_malloc 84 | #define USBD_free USBD_static_free 85 | #define USBD_memset /* Not used */ 86 | #define USBD_memcpy /* Not used */ 87 | 88 | #define USBD_Delay HAL_Delay 89 | 90 | /* For footprint reasons and since only one allocation is handled in the HID class 91 | driver, the malloc/free is changed into a static allocation method */ 92 | void *USBD_static_malloc(uint32_t size); 93 | void USBD_static_free(void *p); 94 | 95 | /* DEBUG macros */ 96 | #if (USBD_DEBUG_LEVEL > 0) 97 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 98 | printf("\n"); 99 | #else 100 | #define USBD_UsrLog(...) 101 | #endif 102 | 103 | 104 | #if (USBD_DEBUG_LEVEL > 1) 105 | 106 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 107 | printf(__VA_ARGS__);\ 108 | printf("\n"); 109 | #else 110 | #define USBD_ErrLog(...) 111 | #endif 112 | 113 | 114 | #if (USBD_DEBUG_LEVEL > 2) 115 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 116 | printf(__VA_ARGS__);\ 117 | printf("\n"); 118 | #else 119 | #define USBD_DbgLog(...) 120 | #endif 121 | 122 | /** 123 | * @} 124 | */ 125 | 126 | 127 | 128 | /** 129 | * @} 130 | */ 131 | 132 | /** @defgroup USBD_CONF_Exported_Types 133 | * @{ 134 | */ 135 | /** 136 | * @} 137 | */ 138 | 139 | /** @defgroup USBD_CONF_Exported_Macros 140 | * @{ 141 | */ 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup USBD_CONF_Exported_Variables 147 | * @{ 148 | */ 149 | /** 150 | * @} 151 | */ 152 | 153 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype 154 | * @{ 155 | */ 156 | /** 157 | * @} 158 | */ 159 | #ifdef __cplusplus 160 | } 161 | #endif 162 | 163 | #endif //__USBD_CONF__H__ 164 | 165 | /** 166 | * @} 167 | */ 168 | 169 | /** 170 | * @} 171 | */ 172 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 173 | 174 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/usbd_desc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : usbd_desc.h 4 | * @version : v1.0_Cube 5 | * @brief : Header for usbd_desc file. 6 | ****************************************************************************** 7 | * COPYRIGHT(c) 2015 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __USBD_DESC__H__ 36 | #define __USBD_DESC__H__ 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | /* Includes ------------------------------------------------------------------*/ 42 | #include "usbd_def.h" 43 | 44 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USB_DESC 49 | * @brief general defines for the usb device library file 50 | * @{ 51 | */ 52 | 53 | /** @defgroup USB_DESC_Exported_Defines 54 | * @{ 55 | */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** @defgroup USBD_DESC_Exported_TypesDefinitions 62 | * @{ 63 | */ 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup USBD_DESC_Exported_Macros 69 | * @{ 70 | */ 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @defgroup USBD_DESC_Exported_Variables 76 | * @{ 77 | */ 78 | extern USBD_DescriptorsTypeDef FS_Desc; 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @defgroup USBD_DESC_Exported_FunctionsPrototype 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* __USBD_DESC_H */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/usbd_storage_if.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : usbd_storage_if.h 4 | * @brief : header file for the usbd_storage_if.c file 5 | ****************************************************************************** 6 | * COPYRIGHT(c) 2015 STMicroelectronics 7 | * 8 | * Redistribution and use in source and binary forms, with or without modification, 9 | * are permitted provided that the following conditions are met: 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | ****************************************************************************** 31 | */ 32 | 33 | /* Define to prevent recursive inclusion -------------------------------------*/ 34 | 35 | #ifndef __USBD_STORAGE_IF_H_ 36 | #define __USBD_STORAGE_IF_H_ 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* Includes ------------------------------------------------------------------*/ 42 | #include "usbd_msc.h" 43 | /* USER CODE BEGIN INCLUDE */ 44 | /* USER CODE END INCLUDE */ 45 | 46 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 47 | * @{ 48 | */ 49 | 50 | /** @defgroup USBD_STORAGE 51 | * @brief header file for the USBD_STORAGE.c file 52 | * @{ 53 | */ 54 | 55 | /** @defgroup USBD_STORAGE_Exported_Defines 56 | * @{ 57 | */ 58 | /* USER CODE BEGIN EXPORTED_DEFINES */ 59 | /* USER CODE END EXPORTED_DEFINES */ 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup USBD_STORAGE_Exported_Types 66 | * @{ 67 | */ 68 | /* USER CODE BEGIN EXPORTED_TYPES */ 69 | /* USER CODE END EXPORTED_TYPES */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @defgroup USBD_STORAGE_Exported_Macros 76 | * @{ 77 | */ 78 | /* USER CODE BEGIN EXPORTED_MACRO */ 79 | /* USER CODE END EXPORTED_MACRO */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | /** @defgroup USBD_STORAGE_Exported_Variables 86 | * @{ 87 | */ 88 | extern USBD_StorageTypeDef USBD_Storage_Interface_fops_FS; 89 | 90 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 91 | /* USER CODE END EXPORTED_VARIABLES */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | /** @defgroup USBD_STORAGE_Exported_FunctionsPrototype 98 | * @{ 99 | */ 100 | 101 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 102 | /* USER CODE END EXPORTED_FUNCTIONS */ 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* __USBD_STORAGE_IF_H */ 120 | 121 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 122 | -------------------------------------------------------------------------------- /bootloader-usb/Inc/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * utils.h 3 | * 4 | * Created on: 10 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | #ifndef INCLUDE_UTILS_H_ 9 | #define INCLUDE_UTILS_H_ 10 | 11 | #include 12 | 13 | #define assert_fatal(expr, what, code) ((expr) ? (void)0 : fatal_error(what, code, (uint8_t *)__FILE__, __LINE__)) 14 | 15 | void delay(); 16 | uint32_t HashLy(uint32_t hash, const uint8_t * buf, uint32_t size); 17 | void resetAllPins(); 18 | void deinitAllPins(); 19 | 20 | void assert_failed(uint8_t* file, uint32_t line); 21 | void fatal_error(char* what, int errCode, uint8_t* file, uint32_t line); 22 | 23 | #endif /* INCLUDE_UTILS_H_ */ 24 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc.h 4 | * @author MCD Application Team 5 | * @version V2.4.1 6 | * @date 19-June-2015 7 | * @brief Header for the usbd_msc.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_MSC_H 30 | #define __USBD_MSC_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_msc_bot.h" 38 | #include "usbd_msc_scsi.h" 39 | #include "usbd_ioreq.h" 40 | 41 | /** @addtogroup USBD_MSC_BOT 42 | * @{ 43 | */ 44 | 45 | /** @defgroup USBD_MSC 46 | * @brief This file is the Header file for usbd_msc.c 47 | * @{ 48 | */ 49 | 50 | 51 | /** @defgroup USBD_BOT_Exported_Defines 52 | * @{ 53 | */ 54 | #define MSC_MAX_FS_PACKET 0x40 55 | #define MSC_MAX_HS_PACKET 0x200 56 | 57 | #define BOT_GET_MAX_LUN 0xFE 58 | #define BOT_RESET 0xFF 59 | #define USB_MSC_CONFIG_DESC_SIZ 32 60 | 61 | 62 | #define MSC_EPIN_ADDR 0x81 63 | #define MSC_EPOUT_ADDR 0x01 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | /** @defgroup USB_CORE_Exported_Types 70 | * @{ 71 | */ 72 | typedef struct _USBD_STORAGE 73 | { 74 | int8_t (* Init) (uint8_t lun); 75 | int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint16_t *block_size); 76 | int8_t (* IsReady) (uint8_t lun); 77 | int8_t (* IsWriteProtected) (uint8_t lun); 78 | int8_t (* Read) (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); 79 | int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); 80 | int8_t (* GetMaxLun)(void); 81 | int8_t *pInquiry; 82 | 83 | }USBD_StorageTypeDef; 84 | 85 | 86 | typedef struct 87 | { 88 | uint32_t max_lun; 89 | uint32_t interface; 90 | uint8_t bot_state; 91 | uint8_t bot_status; 92 | uint16_t bot_data_length; 93 | uint8_t bot_data[MSC_MEDIA_PACKET]; 94 | USBD_MSC_BOT_CBWTypeDef cbw; 95 | USBD_MSC_BOT_CSWTypeDef csw; 96 | 97 | USBD_SCSI_SenseTypeDef scsi_sense [SENSE_LIST_DEEPTH]; 98 | uint8_t scsi_sense_head; 99 | uint8_t scsi_sense_tail; 100 | 101 | uint16_t scsi_blk_size; 102 | uint32_t scsi_blk_nbr; 103 | 104 | uint32_t scsi_blk_addr; 105 | uint32_t scsi_blk_len; 106 | } 107 | USBD_MSC_BOT_HandleTypeDef; 108 | 109 | /* Structure for MSC process */ 110 | extern USBD_ClassTypeDef USBD_MSC; 111 | #define USBD_MSC_CLASS &USBD_MSC 112 | 113 | uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev, 114 | USBD_StorageTypeDef *fops); 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* __USBD_MSC_H */ 128 | /** 129 | * @} 130 | */ 131 | 132 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 133 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_bot.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc_bot.h 4 | * @author MCD Application Team 5 | * @version V2.4.1 6 | * @date 19-June-2015 7 | * @brief Header for the usbd_msc_bot.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_MSC_BOT_H 30 | #define __USBD_MSC_BOT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_core.h" 38 | 39 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 40 | * @{ 41 | */ 42 | 43 | /** @defgroup MSC_BOT 44 | * @brief This file is the Header file for usbd_msc_bot.c 45 | * @{ 46 | */ 47 | 48 | 49 | /** @defgroup USBD_CORE_Exported_Defines 50 | * @{ 51 | */ 52 | #define USBD_BOT_IDLE 0 /* Idle state */ 53 | #define USBD_BOT_DATA_OUT 1 /* Data Out state */ 54 | #define USBD_BOT_DATA_IN 2 /* Data In state */ 55 | #define USBD_BOT_LAST_DATA_IN 3 /* Last Data In Last */ 56 | #define USBD_BOT_SEND_DATA 4 /* Send Immediate data */ 57 | #define USBD_BOT_NO_DATA 5 /* No data Stage */ 58 | 59 | #define USBD_BOT_CBW_SIGNATURE 0x43425355 60 | #define USBD_BOT_CSW_SIGNATURE 0x53425355 61 | #define USBD_BOT_CBW_LENGTH 31 62 | #define USBD_BOT_CSW_LENGTH 13 63 | #define USBD_BOT_MAX_DATA 256 64 | 65 | /* CSW Status Definitions */ 66 | #define USBD_CSW_CMD_PASSED 0x00 67 | #define USBD_CSW_CMD_FAILED 0x01 68 | #define USBD_CSW_PHASE_ERROR 0x02 69 | 70 | /* BOT Status */ 71 | #define USBD_BOT_STATUS_NORMAL 0 72 | #define USBD_BOT_STATUS_RECOVERY 1 73 | #define USBD_BOT_STATUS_ERROR 2 74 | 75 | 76 | #define USBD_DIR_IN 0 77 | #define USBD_DIR_OUT 1 78 | #define USBD_BOTH_DIR 2 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup MSC_CORE_Private_TypesDefinitions 85 | * @{ 86 | */ 87 | 88 | typedef struct 89 | { 90 | uint32_t dSignature; 91 | uint32_t dTag; 92 | uint32_t dDataLength; 93 | uint8_t bmFlags; 94 | uint8_t bLUN; 95 | uint8_t bCBLength; 96 | uint8_t CB[16]; 97 | uint8_t ReservedForAlign; 98 | } 99 | USBD_MSC_BOT_CBWTypeDef; 100 | 101 | 102 | typedef struct 103 | { 104 | uint32_t dSignature; 105 | uint32_t dTag; 106 | uint32_t dDataResidue; 107 | uint8_t bStatus; 108 | uint8_t ReservedForAlign[3]; 109 | } 110 | USBD_MSC_BOT_CSWTypeDef; 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | 117 | /** @defgroup USBD_CORE_Exported_Types 118 | * @{ 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | /** @defgroup USBD_CORE_Exported_FunctionsPrototypes 125 | * @{ 126 | */ 127 | void MSC_BOT_Init (USBD_HandleTypeDef *pdev); 128 | void MSC_BOT_Reset (USBD_HandleTypeDef *pdev); 129 | void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev); 130 | void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev, 131 | uint8_t epnum); 132 | 133 | void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev, 134 | uint8_t epnum); 135 | 136 | void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev, 137 | uint8_t CSW_Status); 138 | 139 | void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev, 140 | uint8_t epnum); 141 | /** 142 | * @} 143 | */ 144 | 145 | #ifdef __cplusplus 146 | } 147 | #endif 148 | 149 | #endif /* __USBD_MSC_BOT_H */ 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 158 | 159 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_data.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc_data.h 4 | * @author MCD Application Team 5 | * @version V2.4.1 6 | * @date 19-June-2015 7 | * @brief Header for the usbd_msc_data.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_MSC_DATA_H 30 | #define __USBD_MSC_DATA_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_conf.h" 38 | 39 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USB_INFO 44 | * @brief general defines for the usb device library file 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USB_INFO_Exported_Defines 49 | * @{ 50 | */ 51 | #define MODE_SENSE6_LEN 8 52 | #define MODE_SENSE10_LEN 8 53 | #define LENGTH_INQUIRY_PAGE00 7 54 | #define LENGTH_FORMAT_CAPACITIES 20 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | 61 | /** @defgroup USBD_INFO_Exported_TypesDefinitions 62 | * @{ 63 | */ 64 | /** 65 | * @} 66 | */ 67 | 68 | 69 | 70 | /** @defgroup USBD_INFO_Exported_Macros 71 | * @{ 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /** @defgroup USBD_INFO_Exported_Variables 79 | * @{ 80 | */ 81 | extern const uint8_t MSC_Page00_Inquiry_Data[]; 82 | extern const uint8_t MSC_Mode_Sense6_data[]; 83 | extern const uint8_t MSC_Mode_Sense10_data[] ; 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup USBD_INFO_Exported_FunctionsPrototype 90 | * @{ 91 | */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __USBD_MSC_DATA_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 112 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc_scsi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc_scsi.h 4 | * @author MCD Application Team 5 | * @version V2.4.1 6 | * @date 19-June-2015 7 | * @brief Header for the usbd_msc_scsi.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_MSC_SCSI_H 30 | #define __USBD_MSC_SCSI_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_def.h" 38 | 39 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBD_SCSI 44 | * @brief header file for the storage disk file 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USBD_SCSI_Exported_Defines 49 | * @{ 50 | */ 51 | 52 | #define SENSE_LIST_DEEPTH 4 53 | 54 | /* SCSI Commands */ 55 | #define SCSI_FORMAT_UNIT 0x04 56 | #define SCSI_INQUIRY 0x12 57 | #define SCSI_MODE_SELECT6 0x15 58 | #define SCSI_MODE_SELECT10 0x55 59 | #define SCSI_MODE_SENSE6 0x1A 60 | #define SCSI_MODE_SENSE10 0x5A 61 | #define SCSI_ALLOW_MEDIUM_REMOVAL 0x1E 62 | #define SCSI_READ6 0x08 63 | #define SCSI_READ10 0x28 64 | #define SCSI_READ12 0xA8 65 | #define SCSI_READ16 0x88 66 | 67 | #define SCSI_READ_CAPACITY10 0x25 68 | #define SCSI_READ_CAPACITY16 0x9E 69 | 70 | #define SCSI_REQUEST_SENSE 0x03 71 | #define SCSI_START_STOP_UNIT 0x1B 72 | #define SCSI_TEST_UNIT_READY 0x00 73 | #define SCSI_WRITE6 0x0A 74 | #define SCSI_WRITE10 0x2A 75 | #define SCSI_WRITE12 0xAA 76 | #define SCSI_WRITE16 0x8A 77 | 78 | #define SCSI_VERIFY10 0x2F 79 | #define SCSI_VERIFY12 0xAF 80 | #define SCSI_VERIFY16 0x8F 81 | 82 | #define SCSI_SEND_DIAGNOSTIC 0x1D 83 | #define SCSI_READ_FORMAT_CAPACITIES 0x23 84 | 85 | #define NO_SENSE 0 86 | #define RECOVERED_ERROR 1 87 | #define NOT_READY 2 88 | #define MEDIUM_ERROR 3 89 | #define HARDWARE_ERROR 4 90 | #define ILLEGAL_REQUEST 5 91 | #define UNIT_ATTENTION 6 92 | #define DATA_PROTECT 7 93 | #define BLANK_CHECK 8 94 | #define VENDOR_SPECIFIC 9 95 | #define COPY_ABORTED 10 96 | #define ABORTED_COMMAND 11 97 | #define VOLUME_OVERFLOW 13 98 | #define MISCOMPARE 14 99 | 100 | 101 | #define INVALID_CDB 0x20 102 | #define INVALID_FIELED_IN_COMMAND 0x24 103 | #define PARAMETER_LIST_LENGTH_ERROR 0x1A 104 | #define INVALID_FIELD_IN_PARAMETER_LIST 0x26 105 | #define ADDRESS_OUT_OF_RANGE 0x21 106 | #define MEDIUM_NOT_PRESENT 0x3A 107 | #define MEDIUM_HAVE_CHANGED 0x28 108 | #define WRITE_PROTECTED 0x27 109 | #define UNRECOVERED_READ_ERROR 0x11 110 | #define WRITE_FAULT 0x03 111 | 112 | #define READ_FORMAT_CAPACITY_DATA_LEN 0x0C 113 | #define READ_CAPACITY10_DATA_LEN 0x08 114 | #define MODE_SENSE10_DATA_LEN 0x08 115 | #define MODE_SENSE6_DATA_LEN 0x04 116 | #define REQUEST_SENSE_DATA_LEN 0x12 117 | #define STANDARD_INQUIRY_DATA_LEN 0x24 118 | #define BLKVFY 0x04 119 | 120 | extern uint8_t Page00_Inquiry_Data[]; 121 | extern uint8_t Standard_Inquiry_Data[]; 122 | extern uint8_t Standard_Inquiry_Data2[]; 123 | extern uint8_t Mode_Sense6_data[]; 124 | extern uint8_t Mode_Sense10_data[]; 125 | extern uint8_t Scsi_Sense_Data[]; 126 | extern uint8_t ReadCapacity10_Data[]; 127 | extern uint8_t ReadFormatCapacity_Data []; 128 | /** 129 | * @} 130 | */ 131 | 132 | 133 | /** @defgroup USBD_SCSI_Exported_TypesDefinitions 134 | * @{ 135 | */ 136 | 137 | typedef struct _SENSE_ITEM { 138 | char Skey; 139 | union { 140 | struct _ASCs { 141 | char ASC; 142 | char ASCQ; 143 | }b; 144 | unsigned int ASC; 145 | char *pData; 146 | } w; 147 | } USBD_SCSI_SenseTypeDef; 148 | /** 149 | * @} 150 | */ 151 | 152 | /** @defgroup USBD_SCSI_Exported_Macros 153 | * @{ 154 | */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** @defgroup USBD_SCSI_Exported_Variables 161 | * @{ 162 | */ 163 | 164 | /** 165 | * @} 166 | */ 167 | /** @defgroup USBD_SCSI_Exported_FunctionsPrototype 168 | * @{ 169 | */ 170 | int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, 171 | uint8_t lun, 172 | uint8_t *cmd); 173 | 174 | void SCSI_SenseCode(USBD_HandleTypeDef *pdev, 175 | uint8_t lun, 176 | uint8_t sKey, 177 | uint8_t ASC); 178 | 179 | /** 180 | * @} 181 | */ 182 | 183 | #ifdef __cplusplus 184 | } 185 | #endif 186 | 187 | #endif /* __USBD_MSC_SCSI_H */ 188 | /** 189 | * @} 190 | */ 191 | 192 | /** 193 | * @} 194 | */ 195 | 196 | /** 197 | * @} 198 | */ 199 | 200 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 201 | 202 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc_data.c 4 | * @author MCD Application Team 5 | * @version V2.4.1 6 | * @date 19-June-2015 7 | * @brief This file provides all the vital inquiry pages and sense data. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_msc_data.h" 30 | 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | 37 | /** @defgroup MSC_DATA 38 | * @brief Mass storage info/data module 39 | * @{ 40 | */ 41 | 42 | /** @defgroup MSC_DATA_Private_TypesDefinitions 43 | * @{ 44 | */ 45 | /** 46 | * @} 47 | */ 48 | 49 | 50 | /** @defgroup MSC_DATA_Private_Defines 51 | * @{ 52 | */ 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup MSC_DATA_Private_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | 66 | /** @defgroup MSC_DATA_Private_Variables 67 | * @{ 68 | */ 69 | 70 | 71 | /* USB Mass storage Page 0 Inquiry Data */ 72 | const uint8_t MSC_Page00_Inquiry_Data[] = {//7 73 | 0x00, 74 | 0x00, 75 | 0x00, 76 | (LENGTH_INQUIRY_PAGE00 - 4), 77 | 0x00, 78 | 0x80, 79 | 0x83 80 | }; 81 | /* USB Mass storage sense 6 Data */ 82 | const uint8_t MSC_Mode_Sense6_data[] = { 83 | 0x00, 84 | 0x00, 85 | 0x00, 86 | 0x00, 87 | 0x00, 88 | 0x00, 89 | 0x00, 90 | 0x00 91 | }; 92 | /* USB Mass storage sense 10 Data */ 93 | const uint8_t MSC_Mode_Sense10_data[] = { 94 | 0x00, 95 | 0x06, 96 | 0x00, 97 | 0x00, 98 | 0x00, 99 | 0x00, 100 | 0x00, 101 | 0x00 102 | }; 103 | /** 104 | * @} 105 | */ 106 | 107 | 108 | /** @defgroup MSC_DATA_Private_FunctionPrototypes 109 | * @{ 110 | */ 111 | /** 112 | * @} 113 | */ 114 | 115 | 116 | /** @defgroup MSC_DATA_Private_Functions 117 | * @{ 118 | */ 119 | 120 | /** 121 | * @} 122 | */ 123 | 124 | 125 | /** 126 | * @} 127 | */ 128 | 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 135 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @version V2.4.1 6 | * @date 19-June-2015 7 | * @brief Header file for usbd_core.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_CORE_H 30 | #define __USBD_CORE_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_conf.h" 38 | #include "usbd_def.h" 39 | #include "usbd_ioreq.h" 40 | #include "usbd_ctlreq.h" 41 | 42 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 43 | * @{ 44 | */ 45 | 46 | /** @defgroup USBD_CORE 47 | * @brief This file is the Header file for usbd_core.c file 48 | * @{ 49 | */ 50 | 51 | 52 | /** @defgroup USBD_CORE_Exported_Defines 53 | * @{ 54 | */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | 61 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 62 | * @{ 63 | */ 64 | 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | 71 | 72 | /** @defgroup USBD_CORE_Exported_Macros 73 | * @{ 74 | */ 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup USBD_CORE_Exported_Variables 81 | * @{ 82 | */ 83 | #define USBD_SOF USBD_LL_SOF 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype 89 | * @{ 90 | */ 91 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); 92 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); 93 | USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev); 94 | USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev); 95 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); 96 | 97 | USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev); 98 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 99 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 100 | 101 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); 102 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata); 103 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata); 104 | 105 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); 106 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); 107 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); 108 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); 109 | 110 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); 111 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 112 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 113 | 114 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); 115 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); 116 | 117 | /* USBD Low Level Driver */ 118 | USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev); 119 | USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev); 120 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); 121 | USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev); 122 | USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, 123 | uint8_t ep_addr, 124 | uint8_t ep_type, 125 | uint16_t ep_mps); 126 | 127 | USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 128 | USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 129 | USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 130 | USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 131 | uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 132 | USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr); 133 | USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, 134 | uint8_t ep_addr, 135 | uint8_t *pbuf, 136 | uint16_t size); 137 | 138 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, 139 | uint8_t ep_addr, 140 | uint8_t *pbuf, 141 | uint16_t size); 142 | 143 | uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 144 | void USBD_LL_Delay (uint32_t Delay); 145 | 146 | /** 147 | * @} 148 | */ 149 | 150 | #ifdef __cplusplus 151 | } 152 | #endif 153 | 154 | #endif /* __USBD_CORE_H */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** 161 | * @} 162 | */ 163 | 164 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_req.h 4 | * @author MCD Application Team 5 | * @version V2.4.1 6 | * @date 19-June-2015 7 | * @brief Header file for the usbd_req.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USB_REQUEST_H 30 | #define __USB_REQUEST_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_def.h" 38 | 39 | 40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_REQ 45 | * @brief header file for the usbd_req.c file 46 | * @{ 47 | */ 48 | 49 | /** @defgroup USBD_REQ_Exported_Defines 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | /** @defgroup USBD_REQ_Exported_Types 58 | * @{ 59 | */ 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | 66 | /** @defgroup USBD_REQ_Exported_Macros 67 | * @{ 68 | */ 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup USBD_REQ_Exported_Variables 74 | * @{ 75 | */ 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 81 | * @{ 82 | */ 83 | 84 | USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 85 | USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 86 | USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 87 | 88 | 89 | void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 90 | 91 | void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata); 92 | 93 | void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len); 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* __USB_REQUEST_H */ 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | 113 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 114 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @version V2.4.1 6 | * @date 19-June-2015 7 | * @brief Header file for the usbd_ioreq.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __USBD_IOREQ_H 30 | #define __USBD_IOREQ_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_def.h" 38 | #include "usbd_core.h" 39 | 40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_IOREQ 45 | * @brief header file for the usbd_ioreq.c file 46 | * @{ 47 | */ 48 | 49 | /** @defgroup USBD_IOREQ_Exported_Defines 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | /** @defgroup USBD_IOREQ_Exported_Types 58 | * @{ 59 | */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | 68 | /** @defgroup USBD_IOREQ_Exported_Macros 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_IOREQ_Exported_Variables 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 85 | * @{ 86 | */ 87 | 88 | USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, 89 | uint8_t *buf, 90 | uint16_t len); 91 | 92 | USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, 93 | uint8_t *pbuf, 94 | uint16_t len); 95 | 96 | USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, 97 | uint8_t *pbuf, 98 | uint16_t len); 99 | 100 | USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, 101 | uint8_t *pbuf, 102 | uint16_t len); 103 | 104 | USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev); 105 | 106 | USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev); 107 | 108 | uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , 109 | uint8_t epnum); 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* __USBD_IOREQ_H */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** 126 | * @} 127 | */ 128 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 129 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @version V2.4.1 6 | * @date 19-June-2015 7 | * @brief This file provides the IO requests APIs for control endpoints. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_ioreq.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief control I/O requests module 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Private_Defines 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | 66 | /** @defgroup USBD_IOREQ_Private_Variables 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 76 | * @{ 77 | */ 78 | /** 79 | * @} 80 | */ 81 | 82 | 83 | /** @defgroup USBD_IOREQ_Private_Functions 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @brief USBD_CtlSendData 89 | * send data on the ctl pipe 90 | * @param pdev: device instance 91 | * @param buff: pointer to data buffer 92 | * @param len: length of data to be sent 93 | * @retval status 94 | */ 95 | USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, 96 | uint8_t *pbuf, 97 | uint16_t len) 98 | { 99 | /* Set EP0 State */ 100 | pdev->ep0_state = USBD_EP0_DATA_IN; 101 | pdev->ep_in[0].total_length = len; 102 | pdev->ep_in[0].rem_length = len; 103 | /* Start the transfer */ 104 | USBD_LL_Transmit (pdev, 0x00, pbuf, len); 105 | 106 | return USBD_OK; 107 | } 108 | 109 | /** 110 | * @brief USBD_CtlContinueSendData 111 | * continue sending data on the ctl pipe 112 | * @param pdev: device instance 113 | * @param buff: pointer to data buffer 114 | * @param len: length of data to be sent 115 | * @retval status 116 | */ 117 | USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, 118 | uint8_t *pbuf, 119 | uint16_t len) 120 | { 121 | /* Start the next transfer */ 122 | USBD_LL_Transmit (pdev, 0x00, pbuf, len); 123 | 124 | return USBD_OK; 125 | } 126 | 127 | /** 128 | * @brief USBD_CtlPrepareRx 129 | * receive data on the ctl pipe 130 | * @param pdev: device instance 131 | * @param buff: pointer to data buffer 132 | * @param len: length of data to be received 133 | * @retval status 134 | */ 135 | USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, 136 | uint8_t *pbuf, 137 | uint16_t len) 138 | { 139 | /* Set EP0 State */ 140 | pdev->ep0_state = USBD_EP0_DATA_OUT; 141 | pdev->ep_out[0].total_length = len; 142 | pdev->ep_out[0].rem_length = len; 143 | /* Start the transfer */ 144 | USBD_LL_PrepareReceive (pdev, 145 | 0, 146 | pbuf, 147 | len); 148 | 149 | return USBD_OK; 150 | } 151 | 152 | /** 153 | * @brief USBD_CtlContinueRx 154 | * continue receive data on the ctl pipe 155 | * @param pdev: device instance 156 | * @param buff: pointer to data buffer 157 | * @param len: length of data to be received 158 | * @retval status 159 | */ 160 | USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, 161 | uint8_t *pbuf, 162 | uint16_t len) 163 | { 164 | 165 | USBD_LL_PrepareReceive (pdev, 166 | 0, 167 | pbuf, 168 | len); 169 | return USBD_OK; 170 | } 171 | /** 172 | * @brief USBD_CtlSendStatus 173 | * send zero lzngth packet on the ctl pipe 174 | * @param pdev: device instance 175 | * @retval status 176 | */ 177 | USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev) 178 | { 179 | 180 | /* Set EP0 State */ 181 | pdev->ep0_state = USBD_EP0_STATUS_IN; 182 | 183 | /* Start the transfer */ 184 | USBD_LL_Transmit (pdev, 0x00, NULL, 0); 185 | 186 | return USBD_OK; 187 | } 188 | 189 | /** 190 | * @brief USBD_CtlReceiveStatus 191 | * receive zero lzngth packet on the ctl pipe 192 | * @param pdev: device instance 193 | * @retval status 194 | */ 195 | USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev) 196 | { 197 | /* Set EP0 State */ 198 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 199 | 200 | /* Start the transfer */ 201 | USBD_LL_PrepareReceive ( pdev, 202 | 0, 203 | NULL, 204 | 0); 205 | 206 | return USBD_OK; 207 | } 208 | 209 | 210 | /** 211 | * @brief USBD_GetRxCount 212 | * returns the received data length 213 | * @param pdev: device instance 214 | * @param ep_addr: endpoint address 215 | * @retval Rx Data blength 216 | */ 217 | uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , uint8_t ep_addr) 218 | { 219 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 220 | } 221 | 222 | /** 223 | * @} 224 | */ 225 | 226 | 227 | /** 228 | * @} 229 | */ 230 | 231 | 232 | /** 233 | * @} 234 | */ 235 | 236 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 237 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/Third_Party/FatFs/src/diskio.c: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------*/ 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2014 */ 3 | /* */ 4 | /* Portions COPYRIGHT 2015 STMicroelectronics */ 5 | /* Portions Copyright (C) 2014, ChaN, all right reserved */ 6 | /*-----------------------------------------------------------------------*/ 7 | /* If a working storage control module is available, it should be */ 8 | /* attached to the FatFs via a glue function rather than modifying it. */ 9 | /* This is an example of glue functions to attach various exsisting */ 10 | /* storage control modules to the FatFs module with a defined API. */ 11 | /*-----------------------------------------------------------------------*/ 12 | 13 | /** 14 | ****************************************************************************** 15 | * @file diskio.c 16 | * @author MCD Application Team 17 | * @version V1.3.0 18 | * @date 08-May-2015 19 | * @brief FatFs low level disk I/O module. 20 | ****************************************************************************** 21 | * @attention 22 | * 23 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 24 | * You may not use this file except in compliance with the License. 25 | * You may obtain a copy of the License at: 26 | * 27 | * http://www.st.com/software_license_agreement_liberty_v2 28 | * 29 | * Unless required by applicable law or agreed to in writing, software 30 | * distributed under the License is distributed on an "AS IS" BASIS, 31 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 32 | * See the License for the specific language governing permissions and 33 | * limitations under the License. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Includes ------------------------------------------------------------------*/ 39 | #include "diskio.h" 40 | #include "ff_gen_drv.h" 41 | 42 | /* Private typedef -----------------------------------------------------------*/ 43 | /* Private define ------------------------------------------------------------*/ 44 | /* Private variables ---------------------------------------------------------*/ 45 | extern Disk_drvTypeDef disk; 46 | 47 | /* Private function prototypes -----------------------------------------------*/ 48 | /* Private functions ---------------------------------------------------------*/ 49 | 50 | /** 51 | * @brief Gets Disk Status 52 | * @param pdrv: Physical drive number (0..) 53 | * @retval DSTATUS: Operation status 54 | */ 55 | DSTATUS disk_status ( 56 | BYTE pdrv /* Physical drive nmuber to identify the drive */ 57 | ) 58 | { 59 | DSTATUS stat; 60 | 61 | stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]); 62 | return stat; 63 | } 64 | 65 | /** 66 | * @brief Initializes a Drive 67 | * @param pdrv: Physical drive number (0..) 68 | * @retval DSTATUS: Operation status 69 | */ 70 | DSTATUS disk_initialize ( 71 | BYTE pdrv /* Physical drive nmuber to identify the drive */ 72 | ) 73 | { 74 | DSTATUS stat = RES_OK; 75 | 76 | if(disk.is_initialized[pdrv] == 0) 77 | { 78 | disk.is_initialized[pdrv] = 1; 79 | stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]); 80 | } 81 | return stat; 82 | } 83 | 84 | /** 85 | * @brief Reads Sector(s) 86 | * @param pdrv: Physical drive number (0..) 87 | * @param *buff: Data buffer to store read data 88 | * @param sector: Sector address (LBA) 89 | * @param count: Number of sectors to read (1..128) 90 | * @retval DRESULT: Operation result 91 | */ 92 | DRESULT disk_read ( 93 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ 94 | BYTE *buff, /* Data buffer to store read data */ 95 | DWORD sector, /* Sector address in LBA */ 96 | UINT count /* Number of sectors to read */ 97 | ) 98 | { 99 | DRESULT res; 100 | 101 | res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count); 102 | return res; 103 | } 104 | 105 | /** 106 | * @brief Writes Sector(s) 107 | * @param pdrv: Physical drive number (0..) 108 | * @param *buff: Data to be written 109 | * @param sector: Sector address (LBA) 110 | * @param count: Number of sectors to write (1..128) 111 | * @retval DRESULT: Operation result 112 | */ 113 | #if _USE_WRITE == 1 114 | DRESULT disk_write ( 115 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ 116 | const BYTE *buff, /* Data to be written */ 117 | DWORD sector, /* Sector address in LBA */ 118 | UINT count /* Number of sectors to write */ 119 | ) 120 | { 121 | DRESULT res; 122 | 123 | res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count); 124 | return res; 125 | } 126 | #endif /* _USE_WRITE == 1 */ 127 | 128 | /** 129 | * @brief I/O control operation 130 | * @param pdrv: Physical drive number (0..) 131 | * @param cmd: Control code 132 | * @param *buff: Buffer to send/receive control data 133 | * @retval DRESULT: Operation result 134 | */ 135 | #if _USE_IOCTL == 1 136 | DRESULT disk_ioctl ( 137 | BYTE pdrv, /* Physical drive nmuber (0..) */ 138 | BYTE cmd, /* Control code */ 139 | void *buff /* Buffer to send/receive control data */ 140 | ) 141 | { 142 | DRESULT res; 143 | 144 | res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff); 145 | return res; 146 | } 147 | #endif /* _USE_IOCTL == 1 */ 148 | 149 | /** 150 | * @brief Gets Time from RTC 151 | * @param None 152 | * @retval Time in DWORD 153 | */ 154 | __weak DWORD get_fattime (void) 155 | { 156 | return 0; 157 | } 158 | 159 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 160 | 161 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/Third_Party/FatFs/src/diskio.h: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------/ 2 | / Low level disk interface modlue include file (C)ChaN, 2014 / 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO_DEFINED 6 | #define _DISKIO_DEFINED 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define _USE_WRITE 1 /* 1: Enable disk_write function */ 13 | #define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */ 14 | 15 | #include "integer.h" 16 | 17 | 18 | /* Status of Disk Functions */ 19 | typedef BYTE DSTATUS; 20 | 21 | /* Results of Disk Functions */ 22 | typedef enum { 23 | RES_OK = 0, /* 0: Successful */ 24 | RES_ERROR, /* 1: R/W Error */ 25 | RES_WRPRT, /* 2: Write Protected */ 26 | RES_NOTRDY, /* 3: Not Ready */ 27 | RES_PARERR /* 4: Invalid Parameter */ 28 | } DRESULT; 29 | 30 | 31 | /*---------------------------------------*/ 32 | /* Prototypes for disk control functions */ 33 | 34 | 35 | DSTATUS disk_initialize (BYTE pdrv); 36 | DSTATUS disk_status (BYTE pdrv); 37 | DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); 38 | DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); 39 | DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); 40 | DWORD get_fattime (void); 41 | 42 | /* Disk Status Bits (DSTATUS) */ 43 | 44 | #define STA_NOINIT 0x01 /* Drive not initialized */ 45 | #define STA_NODISK 0x02 /* No medium in the drive */ 46 | #define STA_PROTECT 0x04 /* Write protected */ 47 | 48 | 49 | /* Command code for disk_ioctrl fucntion */ 50 | 51 | /* Generic command (Used by FatFs) */ 52 | #define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */ 53 | #define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */ 54 | #define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */ 55 | #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */ 56 | #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */ 57 | 58 | /* Generic command (Not used by FatFs) */ 59 | #define CTRL_POWER 5 /* Get/Set power status */ 60 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 61 | #define CTRL_EJECT 7 /* Eject media */ 62 | #define CTRL_FORMAT 8 /* Create physical format on the media */ 63 | 64 | /* MMC/SDC specific ioctl command */ 65 | #define MMC_GET_TYPE 10 /* Get card type */ 66 | #define MMC_GET_CSD 11 /* Get CSD */ 67 | #define MMC_GET_CID 12 /* Get CID */ 68 | #define MMC_GET_OCR 13 /* Get OCR */ 69 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 70 | 71 | /* ATA/CF specific ioctl command */ 72 | #define ATA_GET_REV 20 /* Get F/W revision */ 73 | #define ATA_GET_MODEL 21 /* Get model name */ 74 | #define ATA_GET_SN 22 /* Get serial number */ 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/Third_Party/FatFs/src/drivers/sd_diskio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sd_diskio.c 4 | * @author MCD Application Team 5 | * @version V1.3.0 6 | * @date 08-May-2015 7 | * @brief SD Disk I/O driver 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include 30 | #include "ff_gen_drv.h" 31 | 32 | /* Private typedef -----------------------------------------------------------*/ 33 | /* Private define ------------------------------------------------------------*/ 34 | /* Block Size in Bytes */ 35 | #define BLOCK_SIZE 512 36 | 37 | /* Private variables ---------------------------------------------------------*/ 38 | /* Disk status */ 39 | static volatile DSTATUS Stat = STA_NOINIT; 40 | 41 | /* Private function prototypes -----------------------------------------------*/ 42 | DSTATUS SD_initialize (BYTE); 43 | DSTATUS SD_status (BYTE); 44 | DRESULT SD_read (BYTE, BYTE*, DWORD, UINT); 45 | #if _USE_WRITE == 1 46 | DRESULT SD_write (BYTE, const BYTE*, DWORD, UINT); 47 | #endif /* _USE_WRITE == 1 */ 48 | #if _USE_IOCTL == 1 49 | DRESULT SD_ioctl (BYTE, BYTE, void*); 50 | #endif /* _USE_IOCTL == 1 */ 51 | 52 | const Diskio_drvTypeDef SD_Driver = 53 | { 54 | SD_initialize, 55 | SD_status, 56 | SD_read, 57 | #if _USE_WRITE == 1 58 | SD_write, 59 | #endif /* _USE_WRITE == 1 */ 60 | 61 | #if _USE_IOCTL == 1 62 | SD_ioctl, 63 | #endif /* _USE_IOCTL == 1 */ 64 | }; 65 | 66 | /* Private functions ---------------------------------------------------------*/ 67 | 68 | /** 69 | * @brief Initializes a Drive 70 | * @param lun : not used 71 | * @retval DSTATUS: Operation status 72 | */ 73 | DSTATUS SD_initialize(BYTE lun) 74 | { 75 | Stat = STA_NOINIT; 76 | 77 | /* Configure the uSD device */ 78 | if(BSP_SD_Init() == MSD_OK) 79 | { 80 | Stat &= ~STA_NOINIT; 81 | } 82 | 83 | return Stat; 84 | } 85 | 86 | /** 87 | * @brief Gets Disk Status 88 | * @param lun : not used 89 | * @retval DSTATUS: Operation status 90 | */ 91 | DSTATUS SD_status(BYTE lun) 92 | { 93 | Stat = STA_NOINIT; 94 | 95 | if(BSP_SD_GetStatus() == MSD_OK) 96 | { 97 | Stat &= ~STA_NOINIT; 98 | } 99 | 100 | return Stat; 101 | } 102 | 103 | /** 104 | * @brief Reads Sector(s) 105 | * @param lun : not used 106 | * @param *buff: Data buffer to store read data 107 | * @param sector: Sector address (LBA) 108 | * @param count: Number of sectors to read (1..128) 109 | * @retval DRESULT: Operation result 110 | */ 111 | DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count) 112 | { 113 | DRESULT res = RES_OK; 114 | 115 | if(BSP_SD_ReadBlocks((uint32_t*)buff, 116 | (uint64_t) (sector * BLOCK_SIZE), 117 | BLOCK_SIZE, 118 | count) != MSD_OK) 119 | { 120 | res = RES_ERROR; 121 | } 122 | 123 | return res; 124 | } 125 | 126 | /** 127 | * @brief Writes Sector(s) 128 | * @param lun : not used 129 | * @param *buff: Data to be written 130 | * @param sector: Sector address (LBA) 131 | * @param count: Number of sectors to write (1..128) 132 | * @retval DRESULT: Operation result 133 | */ 134 | #if _USE_WRITE == 1 135 | DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count) 136 | { 137 | DRESULT res = RES_OK; 138 | 139 | if(BSP_SD_WriteBlocks((uint32_t*)buff, 140 | (uint64_t)(sector * BLOCK_SIZE), 141 | BLOCK_SIZE, count) != MSD_OK) 142 | { 143 | res = RES_ERROR; 144 | } 145 | 146 | return res; 147 | } 148 | #endif /* _USE_WRITE == 1 */ 149 | 150 | /** 151 | * @brief I/O control operation 152 | * @param lun : not used 153 | * @param cmd: Control code 154 | * @param *buff: Buffer to send/receive control data 155 | * @retval DRESULT: Operation result 156 | */ 157 | #if _USE_IOCTL == 1 158 | DRESULT SD_ioctl(BYTE lun, BYTE cmd, void *buff) 159 | { 160 | DRESULT res = RES_ERROR; 161 | SD_CardInfo CardInfo; 162 | 163 | if (Stat & STA_NOINIT) return RES_NOTRDY; 164 | 165 | switch (cmd) 166 | { 167 | /* Make sure that no pending write process */ 168 | case CTRL_SYNC : 169 | res = RES_OK; 170 | break; 171 | 172 | /* Get number of sectors on the disk (DWORD) */ 173 | case GET_SECTOR_COUNT : 174 | BSP_SD_GetCardInfo(&CardInfo); 175 | *(DWORD*)buff = CardInfo.CardCapacity / BLOCK_SIZE; 176 | res = RES_OK; 177 | break; 178 | 179 | /* Get R/W sector size (WORD) */ 180 | case GET_SECTOR_SIZE : 181 | *(WORD*)buff = BLOCK_SIZE; 182 | res = RES_OK; 183 | break; 184 | 185 | /* Get erase block size in unit of sector (DWORD) */ 186 | case GET_BLOCK_SIZE : 187 | *(DWORD*)buff = BLOCK_SIZE; 188 | break; 189 | 190 | default: 191 | res = RES_PARERR; 192 | } 193 | 194 | return res; 195 | } 196 | #endif /* _USE_IOCTL == 1 */ 197 | 198 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 199 | 200 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/Third_Party/FatFs/src/drivers/sd_diskio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sd_diskio.h 4 | * @author MCD Application Team 5 | * @version V1.3.0 6 | * @date 08-May-2015 7 | * @brief Header for sd_diskio.c module 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __SD_DISKIO_H 30 | #define __SD_DISKIO_H 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* Exported constants --------------------------------------------------------*/ 35 | /* Exported functions ------------------------------------------------------- */ 36 | extern Diskio_drvTypeDef SD_Driver; 37 | 38 | #endif /* __SD_DISKIO_H */ 39 | 40 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 41 | 42 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/Third_Party/FatFs/src/ff_gen_drv.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ff_gen_drv.c 4 | * @author MCD Application Team 5 | * @version V1.3.0 6 | * @date 08-May-2015 7 | * @brief FatFs generic low level driver. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "ff_gen_drv.h" 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | /* Private variables ---------------------------------------------------------*/ 34 | Disk_drvTypeDef disk = {{0},{0},{0},0}; 35 | 36 | /* Private function prototypes -----------------------------------------------*/ 37 | /* Private functions ---------------------------------------------------------*/ 38 | 39 | /** 40 | * @brief Links a compatible diskio driver/lun id and increments the number of active 41 | * linked drivers. 42 | * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits. 43 | * @param drv: pointer to the disk IO Driver structure 44 | * @param path: pointer to the logical drive path 45 | * @param lun : only used for USB Key Disk to add multi-lun management 46 | else the paramter must be equal to 0 47 | * @retval Returns 0 in case of success, otherwise 1. 48 | */ 49 | uint8_t FATFS_LinkDriverEx(Diskio_drvTypeDef *drv, char *path, uint8_t lun) 50 | { 51 | uint8_t ret = 1; 52 | uint8_t DiskNum = 0; 53 | 54 | if(disk.nbr <= _VOLUMES) 55 | { 56 | disk.is_initialized[disk.nbr] = 0; 57 | disk.drv[disk.nbr] = drv; 58 | disk.lun[disk.nbr] = lun; 59 | DiskNum = disk.nbr++; 60 | path[0] = DiskNum + '0'; 61 | path[1] = ':'; 62 | path[2] = '/'; 63 | path[3] = 0; 64 | ret = 0; 65 | } 66 | 67 | return ret; 68 | } 69 | 70 | /** 71 | * @brief Links a compatible diskio driver and increments the number of active 72 | * linked drivers. 73 | * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits 74 | * @param drv: pointer to the disk IO Driver structure 75 | * @param path: pointer to the logical drive path 76 | * @retval Returns 0 in case of success, otherwise 1. 77 | */ 78 | uint8_t FATFS_LinkDriver(Diskio_drvTypeDef *drv, char *path) 79 | { 80 | return FATFS_LinkDriverEx(drv, path, 0); 81 | } 82 | 83 | /** 84 | * @brief Unlinks a diskio driver and decrements the number of active linked 85 | * drivers. 86 | * @param path: pointer to the logical drive path 87 | * @param lun : not used 88 | * @retval Returns 0 in case of success, otherwise 1. 89 | */ 90 | uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun) 91 | { 92 | uint8_t DiskNum = 0; 93 | uint8_t ret = 1; 94 | 95 | if(disk.nbr >= 1) 96 | { 97 | DiskNum = path[0] - '0'; 98 | if(disk.drv[DiskNum] != 0) 99 | { 100 | disk.drv[DiskNum] = 0; 101 | disk.lun[DiskNum] = 0; 102 | disk.nbr--; 103 | ret = 0; 104 | } 105 | } 106 | 107 | return ret; 108 | } 109 | 110 | /** 111 | * @brief Unlinks a diskio driver and decrements the number of active linked 112 | * drivers. 113 | * @param path: pointer to the logical drive path 114 | * @retval Returns 0 in case of success, otherwise 1. 115 | */ 116 | uint8_t FATFS_UnLinkDriver(char *path) 117 | { 118 | return FATFS_UnLinkDriverEx(path, 0); 119 | } 120 | 121 | /** 122 | * @brief Gets number of linked drivers to the FatFs module. 123 | * @param None 124 | * @retval Number of attached drivers. 125 | */ 126 | uint8_t FATFS_GetAttachedDriversNbr(void) 127 | { 128 | return disk.nbr; 129 | } 130 | 131 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 132 | 133 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/Third_Party/FatFs/src/ff_gen_drv.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ff_gen_drv.h 4 | * @author MCD Application Team 5 | * @version V1.3.0 6 | * @date 08-May-2015 7 | * @brief Header for ff_gen_drv.c module. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 STMicroelectronics

12 | * 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 14 | * You may not use this file except in compliance with the License. 15 | * You may obtain a copy of the License at: 16 | * 17 | * http://www.st.com/software_license_agreement_liberty_v2 18 | * 19 | * Unless required by applicable law or agreed to in writing, software 20 | * distributed under the License is distributed on an "AS IS" BASIS, 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | * See the License for the specific language governing permissions and 23 | * limitations under the License. 24 | * 25 | ****************************************************************************** 26 | */ 27 | 28 | /* Define to prevent recursive inclusion -------------------------------------*/ 29 | #ifndef __FF_GEN_DRV_H 30 | #define __FF_GEN_DRV_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "diskio.h" 38 | #include "ff.h" 39 | 40 | /* Exported types ------------------------------------------------------------*/ 41 | 42 | /** 43 | * @brief Disk IO Driver structure definition 44 | */ 45 | typedef struct 46 | { 47 | DSTATUS (*disk_initialize) (BYTE); /*!< Initialize Disk Drive */ 48 | DSTATUS (*disk_status) (BYTE); /*!< Get Disk Status */ 49 | DRESULT (*disk_read) (BYTE, BYTE*, DWORD, UINT); /*!< Read Sector(s) */ 50 | #if _USE_WRITE == 1 51 | DRESULT (*disk_write) (BYTE, const BYTE*, DWORD, UINT); /*!< Write Sector(s) when _USE_WRITE = 0 */ 52 | #endif /* _USE_WRITE == 1 */ 53 | #if _USE_IOCTL == 1 54 | DRESULT (*disk_ioctl) (BYTE, BYTE, void*); /*!< I/O control operation when _USE_IOCTL = 1 */ 55 | #endif /* _USE_IOCTL == 1 */ 56 | 57 | }Diskio_drvTypeDef; 58 | 59 | /** 60 | * @brief Global Disk IO Drivers structure definition 61 | */ 62 | typedef struct 63 | { 64 | uint8_t is_initialized[_VOLUMES]; 65 | Diskio_drvTypeDef *drv[_VOLUMES]; 66 | uint8_t lun[_VOLUMES]; 67 | __IO uint8_t nbr; 68 | 69 | }Disk_drvTypeDef; 70 | 71 | /* Exported constants --------------------------------------------------------*/ 72 | /* Exported macro ------------------------------------------------------------*/ 73 | /* Exported functions ------------------------------------------------------- */ 74 | uint8_t FATFS_LinkDriverEx(Diskio_drvTypeDef *drv, char *path, uint8_t lun); 75 | uint8_t FATFS_LinkDriver(Diskio_drvTypeDef *drv, char *path); 76 | uint8_t FATFS_UnLinkDriver(char *path); 77 | uint8_t FATFS_LinkDriverEx(Diskio_drvTypeDef *drv, char *path, BYTE lun); 78 | uint8_t FATFS_UnLinkDriverEx(char *path, BYTE lun); 79 | uint8_t FATFS_GetAttachedDriversNbr(void); 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* __FF_GEN_DRV_H */ 86 | 87 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 88 | 89 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/Third_Party/FatFs/src/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _FF_INTEGER 6 | #define _FF_INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* This type MUST be 8 bit */ 16 | typedef unsigned char BYTE; 17 | 18 | /* These types MUST be 16 bit */ 19 | typedef short SHORT; 20 | typedef unsigned short WORD; 21 | typedef unsigned short WCHAR; 22 | 23 | /* These types MUST be 16 bit or 32 bit */ 24 | typedef int INT; 25 | typedef unsigned int UINT; 26 | 27 | /* These types MUST be 32 bit */ 28 | typedef long LONG; 29 | typedef unsigned long DWORD; 30 | 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /bootloader-usb/Middlewares/Third_Party/FatFs/src/option/syscall.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* Sample code of OS dependent controls for FatFs */ 3 | /* (C)ChaN, 2014 */ 4 | /*------------------------------------------------------------------------*/ 5 | 6 | #include /* ANSI memory controls */ 7 | #include "../ff.h" 8 | 9 | #if _FS_REENTRANT 10 | /*----------------------------------------------------------------------- 11 | Create a Synchronization Object 12 | ------------------------------------------------------------------------ 13 | This function is called in f_mount function to create a new 14 | synchronization object, such as semaphore and mutex. When a zero is 15 | returned, the f_mount function fails with FR_INT_ERR. 16 | */ 17 | 18 | int ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */ 19 | BYTE vol, /* Corresponding logical drive being processed */ 20 | _SYNC_t *sobj /* Pointer to return the created sync object */ 21 | ) 22 | { 23 | int ret; 24 | 25 | osSemaphoreDef(SEM); 26 | *sobj = osSemaphoreCreate(osSemaphore(SEM), 1); 27 | ret = (*sobj != NULL); 28 | 29 | return ret; 30 | } 31 | 32 | 33 | 34 | /*------------------------------------------------------------------------*/ 35 | /* Delete a Synchronization Object */ 36 | /*------------------------------------------------------------------------*/ 37 | /* This function is called in f_mount function to delete a synchronization 38 | / object that created with ff_cre_syncobj function. When a zero is 39 | / returned, the f_mount function fails with FR_INT_ERR. 40 | */ 41 | 42 | int ff_del_syncobj ( /* TRUE:Function succeeded, FALSE:Could not delete due to any error */ 43 | _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ 44 | ) 45 | { 46 | osSemaphoreDelete (sobj); 47 | return 1; 48 | } 49 | 50 | 51 | 52 | /*------------------------------------------------------------------------*/ 53 | /* Request Grant to Access the Volume */ 54 | /*------------------------------------------------------------------------*/ 55 | /* This function is called on entering file functions to lock the volume. 56 | / When a zero is returned, the file function fails with FR_TIMEOUT. 57 | */ 58 | 59 | int ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */ 60 | _SYNC_t sobj /* Sync object to wait */ 61 | ) 62 | { 63 | int ret = 0; 64 | 65 | if(osSemaphoreWait(sobj, _FS_TIMEOUT) == osOK) 66 | { 67 | ret = 1; 68 | } 69 | 70 | return ret; 71 | } 72 | 73 | 74 | 75 | /*------------------------------------------------------------------------*/ 76 | /* Release Grant to Access the Volume */ 77 | /*------------------------------------------------------------------------*/ 78 | /* This function is called on leaving file functions to unlock the volume. 79 | */ 80 | 81 | void ff_rel_grant ( 82 | _SYNC_t sobj /* Sync object to be signaled */ 83 | ) 84 | { 85 | osSemaphoreRelease(sobj); 86 | } 87 | 88 | #endif 89 | 90 | 91 | 92 | 93 | #if _USE_LFN == 3 /* LFN with a working buffer on the heap */ 94 | /*------------------------------------------------------------------------*/ 95 | /* Allocate a memory block */ 96 | /*------------------------------------------------------------------------*/ 97 | /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE. 98 | */ 99 | 100 | void* ff_memalloc ( /* Returns pointer to the allocated memory block */ 101 | UINT msize /* Number of bytes to allocate */ 102 | ) 103 | { 104 | return malloc(msize); /* Allocate a new memory block with POSIX API */ 105 | } 106 | 107 | 108 | /*------------------------------------------------------------------------*/ 109 | /* Free a memory block */ 110 | /*------------------------------------------------------------------------*/ 111 | 112 | void ff_memfree ( 113 | void* mblock /* Pointer to the memory block to free */ 114 | ) 115 | { 116 | free(mblock); /* Discard the memory block with POSIX API */ 117 | } 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /bootloader-usb/Src/boot.c: -------------------------------------------------------------------------------- 1 | #include "boot.h" 2 | #include "state.h" 3 | #include "filesystem.h" 4 | 5 | #include "console.h" 6 | #include "stm32f1xx_hal.h" 7 | 8 | typedef void (*Callable)(); 9 | 10 | void bootMainProgram() 11 | { 12 | deinitFilesystem(); 13 | Callable pReset_Handler = (Callable) state.mainProgramResetHandler; 14 | printf("Booting at %lX\n", (uint32_t)pReset_Handler); 15 | //__disable_irq(); 16 | deinitConsile(); 17 | HAL_DeInit(); 18 | // Disabling SysTick interrupt 19 | SysTick->CTRL = 0; 20 | moveVectorTable(0x00); 21 | // Setting initial value to stack pointer 22 | __set_MSP(state.mainProgramStackPointer); 23 | // booting really 24 | pReset_Handler(); 25 | } 26 | 27 | void reboot() 28 | { 29 | deinitFilesystem(); 30 | deinitConsile(); 31 | NVIC_SystemReset(); 32 | } 33 | -------------------------------------------------------------------------------- /bootloader-usb/Src/cardreader.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cardreader.c 3 | * 4 | * Created on: 15 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | #include "cardreader.h" 9 | #include "console.h" 10 | #include "sd-utils.h" 11 | #include "bsp_driver_sd.h" 12 | #include "usb_device.h" 13 | #include "usbd_core.h" 14 | 15 | extern HAL_SD_CardInfoTypedef SDCardInfo; 16 | extern SD_HandleTypeDef hsd; 17 | extern USBD_HandleTypeDef hUsbDeviceFS; 18 | 19 | int USBDeviceActivated = 0; 20 | 21 | void initCardreader() 22 | { 23 | MX_SDIO_SD_Init(); 24 | BSP_SD_Init(); 25 | MX_USB_DEVICE_Init(); 26 | /* 27 | HAL_SD_Get_CardInfo(&hsd, &SDCardInfo); 28 | printf("SDCardInfo.CardCapacity = %d\n", (int) SDCardInfo.CardCapacity); 29 | printf("SDCardInfo.CardBlockSize = %d\n", (int) SDCardInfo.CardBlockSize); 30 | printf("SDCardInfo.CardType = %d\n", (int) SDCardInfo.CardType);*/ 31 | } 32 | 33 | void deinitCardreader() 34 | { 35 | /* Stop the low level driver */ 36 | USBD_LL_Stop(&hUsbDeviceFS); 37 | 38 | /* Initialize low level driver */ 39 | USBD_LL_DeInit(&hUsbDeviceFS); 40 | } 41 | 42 | int isCardreaderActive() 43 | { 44 | return USBDeviceActivated; 45 | } 46 | 47 | void temporaryEnableCardreader(uint32_t duration) 48 | { 49 | initCardreader(); 50 | printf("Cardreader temporary enabled...\n"); 51 | HAL_Delay(duration); 52 | if (isCardreaderActive()) 53 | { 54 | infiniteMessage("System in USB device mode\n"); 55 | } else { 56 | printf("Cardreader stopped\n"); 57 | deinitCardreader(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /bootloader-usb/Src/console.c: -------------------------------------------------------------------------------- 1 | /* 2 | * console.c 3 | * 4 | * Created on: 9 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | #include "console.h" 9 | #include "bootloader-config.h" 10 | #include "stm32f1xx_hal.h" 11 | #include 12 | 13 | UART_HandleTypeDef huart1; 14 | 15 | void initConsole() 16 | { 17 | #ifdef UART_ENABLED 18 | huart1.Instance = USART1; 19 | huart1.Init.BaudRate = UART_BAUDRATE; 20 | huart1.Init.WordLength = UART_WORDLENGTH_8B; 21 | huart1.Init.StopBits = UART_STOPBITS_1; 22 | huart1.Init.Parity = UART_PARITY_NONE; 23 | huart1.Init.Mode = UART_MODE_TX_RX; 24 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 25 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; 26 | HAL_UART_Init(&huart1); 27 | #endif 28 | } 29 | 30 | void deinitConsile() 31 | { 32 | #ifdef UART_ENABLED 33 | HAL_UART_DeInit(&huart1); 34 | #endif 35 | } 36 | 37 | void infiniteMessage(const char* msg) 38 | { 39 | for (;;) 40 | { 41 | printf(msg); 42 | HAL_Delay(1000); 43 | } 44 | } 45 | 46 | ssize_t 47 | _write (int fd __attribute__((unused)), const char* buf __attribute__((unused)), 48 | size_t nbyte __attribute__((unused))) 49 | { 50 | #ifdef UART_ENABLED 51 | HAL_UART_Transmit(&huart1, buf, nbyte, 1000); 52 | #endif 53 | return nbyte; 54 | } 55 | 56 | int __attribute__((weak)) 57 | _fstat(int fildes __attribute__((unused)), 58 | struct stat* st __attribute__((unused))) 59 | { 60 | //errno = ENOSYS; 61 | return -1; 62 | } 63 | 64 | int __attribute__((weak)) 65 | _lseek(int file __attribute__((unused)), int ptr __attribute__((unused)), 66 | int dir __attribute__((unused))) 67 | { 68 | //errno = ENOSYS; 69 | return -1; 70 | } 71 | 72 | int __attribute__((weak)) 73 | _close(int fildes __attribute__((unused))) 74 | { 75 | //errno = ENOSYS; 76 | return -1; 77 | } 78 | 79 | int __attribute__((weak)) 80 | _read(int file __attribute__((unused)), char* ptr __attribute__((unused)), 81 | int len __attribute__((unused))) 82 | { 83 | //errno = ENOSYS; 84 | return -1; 85 | } 86 | 87 | int __attribute__((weak)) 88 | _isatty(int file __attribute__((unused))) 89 | { 90 | //errno = ENOSYS; 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /bootloader-usb/Src/fatfs.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file fatfs.c 4 | * @brief Code for fatfs applications 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2015 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | 34 | #include "fatfs.h" 35 | 36 | uint8_t retSD; /* Return value for SD */ 37 | char SD_Path[4]; /* SD logical drive path */ 38 | 39 | /* USER CODE BEGIN Variables */ 40 | 41 | /* USER CODE END Variables */ 42 | 43 | void MX_FATFS_Init(void) 44 | { 45 | /*## FatFS: Link the SD driver ###########################*/ 46 | retSD = FATFS_LinkDriver(&SD_Driver, SD_Path); 47 | 48 | /* USER CODE BEGIN Init */ 49 | /* additional user code for init */ 50 | /* USER CODE END Init */ 51 | } 52 | 53 | /** 54 | * @brief Gets Time from RTC 55 | * @param None 56 | * @retval Time in DWORD 57 | */ 58 | DWORD get_fattime(void) 59 | { 60 | /* USER CODE BEGIN get_fattime */ 61 | return 0; 62 | /* USER CODE END get_fattime */ 63 | } 64 | 65 | /* USER CODE BEGIN Application */ 66 | 67 | /* USER CODE END Application */ 68 | 69 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 70 | -------------------------------------------------------------------------------- /bootloader-usb/Src/filesystem.c: -------------------------------------------------------------------------------- 1 | #include "filesystem.h" 2 | #include "fatfs.h" 3 | 4 | static FATFS fatfs; 5 | 6 | extern SD_HandleTypeDef hsd; 7 | 8 | uint8_t initFilesystem() 9 | { 10 | MX_SDIO_SD_Init(); 11 | MX_FATFS_Init(); 12 | FRESULT res = f_mount(&fatfs, "", 1); 13 | if (res != FR_OK) 14 | { 15 | printf("Cannot mount FS!\n"); 16 | return FILESYSTEM_INIT_FAIL; 17 | } 18 | return FILESYSTEM_INIT_OK; 19 | } 20 | 21 | void deinitFilesystem() 22 | { 23 | f_mount(&fatfs, "", 0); 24 | HAL_SD_DeInit(&hsd); 25 | } 26 | -------------------------------------------------------------------------------- /bootloader-usb/Src/flash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * flash.c 3 | * 4 | * Created on: 9 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | #include "state.h" 9 | #include "flash.h" 10 | #include "fatfs.h" 11 | #include "console.h" 12 | #include "utils.h" 13 | #include "sd-utils.h" 14 | #include "bootloader-config.h" 15 | #include "stm32f1xx_hal.h" 16 | 17 | #include 18 | #include 19 | 20 | #define FLASH_BEGIN 0x8000000 21 | 22 | void Reset_Handler(); 23 | 24 | extern unsigned int _isr_real; 25 | extern unsigned int _estack; 26 | 27 | uint32_t firstPageAddr = 0x8000000; 28 | uint32_t secondPageAddr = 0x8000000 + FLASH_PAGE_SIZE; 29 | 30 | uint32_t lastPageAddr = ((uint32_t) &_isr_real) - FLASH_PAGE_SIZE; 31 | 32 | uint8_t firstPage[FLASH_PAGE_SIZE]; 33 | uint32_t fistPageLen = 0; 34 | 35 | uint8_t buffer[FLASH_PAGE_SIZE]; 36 | uint32_t bufferLen = 0; 37 | 38 | static FATFS fatfs; 39 | static FIL fil; 40 | static FILINFO info; 41 | 42 | extern SD_HandleTypeDef hsd; 43 | 44 | const char flashFileName[] = FIRMWARE_FILE_NAME; 45 | const char hashFileName[] = FIRMWARE_HASH_FILE_NAME; 46 | 47 | uint32_t getMaxFlashImageSize() 48 | { 49 | return (uint32_t) &_isr_real - firstPageAddr; 50 | } 51 | 52 | void moveVectorTable(uint32_t Offset) 53 | { 54 | SCB->VTOR = FLASH_BASE | Offset; 55 | } 56 | 57 | HAL_StatusTypeDef erase(uint32_t from, uint32_t to) 58 | { 59 | HAL_StatusTypeDef res = HAL_OK; 60 | for (uint32_t i = from; i <= to; i += FLASH_PAGE_SIZE) 61 | { 62 | FLASH_EraseInitTypeDef erase; 63 | erase.TypeErase = FLASH_TYPEERASE_PAGES; 64 | erase.Banks = FLASH_BANK_1; 65 | erase.PageAddress = i; 66 | erase.NbPages = 1; 67 | uint32_t error = 0; 68 | res = HAL_FLASHEx_Erase(&erase, &error); 69 | if (res != HAL_OK) { 70 | printf("Error while erasing page at %lX\n", i); 71 | return res; 72 | } 73 | } 74 | printf("Pages from %lX to %lX erased\n", from, to); 75 | return res; 76 | } 77 | 78 | FRESULT readNextPage(uint8_t *target, uint32_t *readed) 79 | { 80 | uint16_t blocksCount = 16; 81 | uint16_t fileBlock = FLASH_PAGE_SIZE / blocksCount; 82 | *readed = 0; 83 | UINT readedNow = 0; 84 | FRESULT res = FR_OK; 85 | for (uint16_t i = 0; i getMaxFlashImageSize()) 167 | return FLASH_FILE_TOO_BIG; 168 | 169 | // Reading file with hash 170 | *trueHash = 0; // keep 0 if we have no hash value 171 | res = f_open(&fil, hashFileName, FA_OPEN_EXISTING | FA_READ); 172 | if (res == FR_OK) { 173 | UINT readed = 0; 174 | f_read(&fil, (void*) trueHash, sizeof(*trueHash), &readed); 175 | f_close(&fil); 176 | if (readed != sizeof(*trueHash)) 177 | *trueHash = 0; 178 | } 179 | 180 | res = f_open(&fil, flashFileName, FA_OPEN_EXISTING | FA_READ); 181 | if (res != FR_OK) 182 | return FLASH_FILE_CANNOT_OPEN; 183 | 184 | *hash = calculateFileHash(&fil); 185 | f_close(&fil); 186 | if (*hash == 0) 187 | return FLASH_FILE_CANNOT_OPEN; 188 | 189 | if (*hash == *trueHash 190 | #ifndef HASH_CHECK_IS_MANDATORY 191 | || *trueHash == 0 192 | #endif 193 | ) 194 | return FLASH_FILE_OK; 195 | else 196 | return FLASH_FILE_INVALID_HASH; 197 | } 198 | 199 | FlashResult flash() 200 | { 201 | FRESULT res = f_open(&fil, flashFileName, FA_OPEN_EXISTING | FA_READ); 202 | 203 | if (res != FR_OK) 204 | return FLASH_RESULT_FILE_ERROR; 205 | 206 | uint32_t position = FLASH_BEGIN + FLASH_PAGE_SIZE; 207 | printf("Erasing MCU pages except first...\n"); 208 | HAL_StatusTypeDef hal_res = HAL_FLASH_Unlock(); 209 | if (hal_res != HAL_OK) 210 | { 211 | printf("Unlock error: %d\n", res); 212 | return FLASH_RESULT_FLASH_ERROR; 213 | } 214 | 215 | if (HAL_OK != erase(secondPageAddr, info.fsize + firstPageAddr)) 216 | { 217 | printf("Error during erasing MCU, rebooting system.\n"); 218 | return FLASH_RESULT_FLASH_ERROR; 219 | } 220 | 221 | if (FR_OK == readNextPage(firstPage, &fistPageLen)) 222 | { 223 | printf("First page of flash readed successfuly\n"); 224 | // Reading original SP and Reset_Handler 225 | state.mainProgramStackPointer = *(uint32_t*)&firstPage[0]; 226 | state.mainProgramResetHandler = *(uint32_t*)&firstPage[4]; 227 | // Changing it to bootloader ones 228 | *(uint32_t*)&firstPage[0] = (uint32_t) &_estack; 229 | *(uint32_t*)&firstPage[4] = (uint32_t) Reset_Handler; 230 | } else { 231 | f_close(&fil); 232 | return FLASH_RESULT_FILE_ERROR; 233 | } 234 | 235 | do { 236 | readNextPage(buffer, &bufferLen); 237 | if (HAL_OK != flashWrite(position, buffer, bufferLen)) 238 | { 239 | printf("Cannot write flash page at %lX, rebooting system.\n", position); 240 | return FLASH_RESULT_FLASH_ERROR; 241 | } 242 | position += bufferLen; 243 | printf("Page at %lX written\n", position); 244 | } while (bufferLen != 0); 245 | f_close(&fil); 246 | 247 | printf("Erasing first page...\n"); 248 | if (HAL_OK != erase(FLASH_BEGIN, FLASH_BEGIN)) 249 | { 250 | printf("Error during erasing first page, rebooting system.\n"); 251 | return FLASH_RESULT_FLASH_ERROR; 252 | } 253 | printf("Writing first page...\n"); 254 | if (HAL_OK != flashWrite(FLASH_BEGIN, firstPage, fistPageLen)) 255 | { 256 | infiniteMessage("Cannot write first flash page. Your MCU bricked, reflash bootloader with SWD/JTAG!\n"); 257 | } 258 | 259 | printf("First page written\n"); 260 | HAL_FLASH_Lock(); 261 | printf("Flash locked\n"); 262 | } 263 | -------------------------------------------------------------------------------- /bootloader-usb/Src/isr-vector-stub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * isr-vector-stub.c 3 | * 4 | * Created on: 8 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | typedef void 9 | (* const pHandler)(void); 10 | 11 | extern unsigned int _estack; 12 | 13 | void Reset_Handler(); 14 | 15 | __attribute__ ((section(".isr_vector_stub"),used)) 16 | pHandler isr_vectors_stub[2] = 17 | { 18 | // Core Level - CM3 19 | (pHandler) &_estack, // The initial stack pointer 20 | Reset_Handler // The reset handler 21 | // Other vectors are unnecessary 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /bootloader-usb/Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : main.c 4 | * Description : Main program body 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2015 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "console.h" 35 | #include "cardreader.h" 36 | #include "filesystem.h" 37 | #include "boot.h" 38 | #include "state.h" 39 | #include "flash.h" 40 | #include "utils.h" 41 | #include "fatfs.h" 42 | #include "bootloader-config.h" 43 | #include "usb_device.h" 44 | 45 | #include "stm32f1xx_hal.h" 46 | 47 | HAL_SD_CardInfoTypedef SDCardInfo; 48 | extern USBD_HandleTypeDef hUsbDeviceFS; 49 | 50 | void SystemClock_Config(void); 51 | static void MX_GPIO_Init(void); 52 | 53 | 54 | int main(void) 55 | { 56 | // Reset of all peripherals, Initializes the Flash interface and the Systick. 57 | HAL_Init(); 58 | SystemClock_Config(); 59 | MX_GPIO_Init(); 60 | // Resetting all pins in case of open gates of mosfets 61 | resetAllPins(); 62 | 63 | initConsole(); 64 | printf("Starting bootloader\n"); 65 | 66 | // Reading state from MCU flash's last page 67 | readState(); 68 | 69 | // Ok, something was programmed 70 | // Enabling FAT FS 71 | if (initFilesystem() != FILESYSTEM_INIT_OK) 72 | { 73 | // Cannot mount SD-card and pick FAT fs for some reason 74 | // If nothing was programmed yet 75 | printf("Cannot mount file system or find file with flash\n"); 76 | if (state.state == LOADER_SATE_NO_FLASH) 77 | { 78 | // Infinite cardreader 79 | initCardreader(); 80 | infiniteMessage("System in USB device mode\n"); 81 | } else { 82 | temporaryEnableCardreader(USB_WAITING_PERIOD); 83 | printf("Booting...\n"); 84 | bootMainProgram(); 85 | } 86 | } 87 | 88 | temporaryEnableCardreader(USB_WAITING_PERIOD); 89 | 90 | // We have properly mounted FAT fs and now we should check hash sum of flash.bin 91 | uint32_t fileHash, trueHash, size; 92 | HashCheckResult hcr = checkFlashFile(&fileHash, &trueHash, &size); 93 | switch (hcr) 94 | { 95 | case FLASH_FILE_OK: 96 | // Check if no upgrade was provided 97 | if (state.hash == fileHash) 98 | { 99 | printf("Firmware is up-to-date, nothing to update\n"); 100 | break; 101 | } 102 | // Here we should flash our MCU 103 | FlashResult fr = flash(); 104 | switch (fr) 105 | { 106 | case FLASH_RESULT_OK: 107 | printf("MCU successfuly programmed\n"); 108 | break; 109 | case FLASH_RESULT_FILE_ERROR: 110 | infiniteMessage("Flash error: cannot read file\n"); 111 | break; 112 | case FLASH_RESULT_FLASH_ERROR: 113 | infiniteMessage("Flash error: cannot write or erase flash memory. Maybe you MCU is totally broken\n"); 114 | break; 115 | } 116 | 117 | state.hash = fileHash; 118 | state.state = LOADER_SATE_HAS_FLASH; 119 | saveState(); 120 | break; 121 | case FLASH_FILE_NOT_EXISTS: 122 | printf("Flash file not exists on sd-card\n"); 123 | break; 124 | case FLASH_FILE_CANNOT_OPEN: 125 | printf("Cannot read from flash file\n"); 126 | break; 127 | case FLASH_FILE_INVALID_HASH: 128 | printf("Flash file hash is invalid: %lu against %lu specified in .ly file\n", fileHash, trueHash); 129 | break; 130 | case FLASH_FILE_TOO_BIG: 131 | printf("Flash file is too big: %lu against %lu available in MCU\n", size, getMaxFlashImageSize()); 132 | break; 133 | } 134 | printf("Booting...\n"); 135 | bootMainProgram(); 136 | 137 | infiniteMessage("Unexpected fail\n"); 138 | return 0; 139 | } 140 | 141 | /** System Clock Configuration 142 | */ 143 | void SystemClock_Config(void) 144 | { 145 | 146 | RCC_OscInitTypeDef RCC_OscInitStruct; 147 | RCC_ClkInitTypeDef RCC_ClkInitStruct; 148 | RCC_PeriphCLKInitTypeDef PeriphClkInit; 149 | 150 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 151 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 152 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; 153 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 154 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 155 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; 156 | HAL_RCC_OscConfig(&RCC_OscInitStruct); 157 | 158 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1; 159 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 160 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 161 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 162 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 163 | HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); 164 | 165 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; 166 | PeriphClkInit.UsbClockSelection = RCC_USBPLLCLK_DIV1_5; 167 | HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); 168 | 169 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); 170 | 171 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 172 | 173 | /* SysTick_IRQn interrupt configuration */ 174 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 175 | } 176 | 177 | 178 | 179 | /** Configure pins as 180 | * Analog 181 | * Input 182 | * Output 183 | * EVENT_OUT 184 | * EXTI 185 | */ 186 | void MX_GPIO_Init(void) 187 | { 188 | 189 | /* GPIO Ports Clock Enable */ 190 | __GPIOA_CLK_ENABLE(); 191 | __GPIOB_CLK_ENABLE(); 192 | __GPIOC_CLK_ENABLE(); 193 | __GPIOD_CLK_ENABLE(); 194 | } 195 | 196 | /* USER CODE BEGIN 4 */ 197 | 198 | /* USER CODE END 4 */ 199 | 200 | 201 | /** 202 | * @} 203 | */ 204 | 205 | /** 206 | * @} 207 | */ 208 | 209 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 210 | -------------------------------------------------------------------------------- /bootloader-usb/Src/sd-utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sd-utils.c 3 | * 4 | * Created on: 15 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | #include "sd-utils.h" 9 | 10 | #include "stm32f1xx_hal.h" 11 | 12 | SD_HandleTypeDef hsd; 13 | 14 | void MX_SDIO_SD_Init(void) 15 | { 16 | hsd.Instance = SDIO; 17 | hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING; 18 | hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE; 19 | hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE; 20 | hsd.Init.BusWide = SDIO_BUS_WIDE_1B; 21 | hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE; 22 | hsd.Init.ClockDiv = 3; 23 | } 24 | -------------------------------------------------------------------------------- /bootloader-usb/Src/state.c: -------------------------------------------------------------------------------- 1 | /* 2 | * state.c 3 | * 4 | * Created on: 5 сент. 2016 г. 5 | * Author: alexey 6 | */ 7 | 8 | #include "state.h" 9 | #include "boot.h" 10 | #include "stm32f1xx_hal.h" 11 | 12 | LoaderState state; 13 | 14 | extern unsigned int _loader_state_addr; 15 | 16 | // Initial loader state when no real program is flashed yet 17 | __attribute__ ((section(".loader_state"),used)) 18 | uint32_t loaderStateStub[] = 19 | { 20 | LOADER_SATE_NO_FLASH, 21 | 0x0, 22 | 0x0, 23 | 0x0 24 | }; 25 | 26 | void saveState() 27 | { 28 | HAL_FLASH_Unlock(); 29 | if (HAL_OK != erase((uint32_t) &_loader_state_addr, (uint32_t) &_loader_state_addr)) 30 | { 31 | printf("Error while loader state saving: cannot erase state page. Rebooting...\n"); 32 | reboot(); 33 | } 34 | //FLASH_PageErase((uint32_t) &_loader_state_addr); 35 | for (uint32_t i=0; i < sizeof(LoaderState) / 4; i++) 36 | { 37 | uint32_t targetAddress = (uint32_t) &_loader_state_addr + 4*i; 38 | uint32_t* pWord = ((uint32_t*) &state) + i; 39 | if (HAL_OK != HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, targetAddress, *pWord)) 40 | { 41 | printf("Error while loader state saving: cannot program state page. Rebooting...\n"); 42 | reboot(); 43 | } 44 | } 45 | HAL_FLASH_Lock(); 46 | } 47 | 48 | void readState() 49 | { 50 | memcpy(&state, &_loader_state_addr, sizeof(LoaderState)); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /bootloader-usb/Src/stm32f1xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : stm32f1xx_hal_msp.c 4 | * Description : This file provides code for the MSP Initialization 5 | * and de-Initialization codes. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2015 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* Includes ------------------------------------------------------------------*/ 35 | #include "stm32f1xx_hal.h" 36 | 37 | /* USER CODE BEGIN 0 */ 38 | 39 | /* USER CODE END 0 */ 40 | 41 | /** 42 | * Initializes the Global MSP. 43 | */ 44 | void HAL_MspInit(void) 45 | { 46 | /* USER CODE BEGIN MspInit 0 */ 47 | 48 | /* USER CODE END MspInit 0 */ 49 | 50 | __HAL_RCC_AFIO_CLK_ENABLE(); 51 | 52 | HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); 53 | 54 | /* System interrupt init*/ 55 | /* SysTick_IRQn interrupt configuration */ 56 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 57 | 58 | /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled 59 | */ 60 | __HAL_AFIO_REMAP_SWJ_NOJTAG(); 61 | 62 | /* USER CODE BEGIN MspInit 1 */ 63 | 64 | /* USER CODE END MspInit 1 */ 65 | } 66 | 67 | void HAL_SD_MspInit(SD_HandleTypeDef* hsd) 68 | { 69 | 70 | GPIO_InitTypeDef GPIO_InitStruct; 71 | if(hsd->Instance==SDIO) 72 | { 73 | /* USER CODE BEGIN SDIO_MspInit 0 */ 74 | 75 | /* USER CODE END SDIO_MspInit 0 */ 76 | /* Peripheral clock enable */ 77 | __SDIO_CLK_ENABLE(); 78 | 79 | /**SDIO GPIO Configuration 80 | PC8 ------> SDIO_D0 81 | PC9 ------> SDIO_D1 82 | PC10 ------> SDIO_D2 83 | PC11 ------> SDIO_D3 84 | PC12 ------> SDIO_CK 85 | PD2 ------> SDIO_CMD 86 | */ 87 | GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 88 | |GPIO_PIN_12; 89 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 90 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 91 | GPIO_InitStruct.Pull = GPIO_NOPULL; 92 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 93 | 94 | GPIO_InitStruct.Pin = GPIO_PIN_2; 95 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 96 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 97 | GPIO_InitStruct.Pull = GPIO_NOPULL; 98 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); 99 | 100 | /* USER CODE BEGIN SDIO_MspInit 1 */ 101 | 102 | /* USER CODE END SDIO_MspInit 1 */ 103 | } 104 | 105 | } 106 | 107 | void HAL_SD_MspDeInit(SD_HandleTypeDef* hsd) 108 | { 109 | 110 | if(hsd->Instance==SDIO) 111 | { 112 | /* USER CODE BEGIN SDIO_MspDeInit 0 */ 113 | 114 | /* USER CODE END SDIO_MspDeInit 0 */ 115 | /* Peripheral clock disable */ 116 | __SDIO_CLK_DISABLE(); 117 | 118 | /**SDIO GPIO Configuration 119 | PC8 ------> SDIO_D0 120 | PC9 ------> SDIO_D1 121 | PC10 ------> SDIO_D2 122 | PC11 ------> SDIO_D3 123 | PC12 ------> SDIO_CK 124 | PD2 ------> SDIO_CMD 125 | */ 126 | HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 127 | |GPIO_PIN_12); 128 | 129 | HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2); 130 | 131 | } 132 | /* USER CODE BEGIN SDIO_MspDeInit 1 */ 133 | 134 | /* USER CODE END SDIO_MspDeInit 1 */ 135 | 136 | } 137 | 138 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) 139 | { 140 | 141 | GPIO_InitTypeDef GPIO_InitStruct; 142 | if(huart->Instance==USART1) 143 | { 144 | /* USER CODE BEGIN USART1_MspInit 0 */ 145 | 146 | /* USER CODE END USART1_MspInit 0 */ 147 | /* Peripheral clock enable */ 148 | __USART1_CLK_ENABLE(); 149 | 150 | /**USART1 GPIO Configuration 151 | PA9 ------> USART1_TX 152 | PA10 ------> USART1_RX 153 | */ 154 | GPIO_InitStruct.Pin = GPIO_PIN_9; 155 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 156 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 157 | GPIO_InitStruct.Pull = GPIO_NOPULL; 158 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 159 | 160 | GPIO_InitStruct.Pin = GPIO_PIN_10; 161 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 162 | GPIO_InitStruct.Pull = GPIO_NOPULL; 163 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 164 | 165 | /* USER CODE BEGIN USART1_MspInit 1 */ 166 | 167 | /* USER CODE END USART1_MspInit 1 */ 168 | } 169 | 170 | } 171 | 172 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) 173 | { 174 | 175 | if(huart->Instance==USART1) 176 | { 177 | /* USER CODE BEGIN USART1_MspDeInit 0 */ 178 | 179 | /* USER CODE END USART1_MspDeInit 0 */ 180 | /* Peripheral clock disable */ 181 | __USART1_CLK_DISABLE(); 182 | 183 | /**USART1 GPIO Configuration 184 | PA9 ------> USART1_TX 185 | PA10 ------> USART1_RX 186 | */ 187 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); 188 | 189 | } 190 | /* USER CODE BEGIN USART1_MspDeInit 1 */ 191 | 192 | /* USER CODE END USART1_MspDeInit 1 */ 193 | 194 | } 195 | 196 | /* USER CODE BEGIN 1 */ 197 | 198 | /* USER CODE END 1 */ 199 | 200 | /** 201 | * @} 202 | */ 203 | 204 | /** 205 | * @} 206 | */ 207 | 208 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 209 | -------------------------------------------------------------------------------- /bootloader-usb/Src/stm32f1xx_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_it.c 4 | * @brief Interrupt Service Routines. 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2015 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm32f1xx_hal.h" 35 | #include "stm32f1xx.h" 36 | #include "stm32f1xx_it.h" 37 | 38 | /* USER CODE BEGIN 0 */ 39 | 40 | /* USER CODE END 0 */ 41 | 42 | /* External variables --------------------------------------------------------*/ 43 | extern PCD_HandleTypeDef hpcd_USB_FS; 44 | 45 | /******************************************************************************/ 46 | /* Cortex-M3 Processor Interruption and Exception Handlers */ 47 | /******************************************************************************/ 48 | 49 | /** 50 | * @brief This function handles System tick timer. 51 | */ 52 | void SysTick_Handler(void) 53 | { 54 | /* USER CODE BEGIN SysTick_IRQn 0 */ 55 | 56 | /* USER CODE END SysTick_IRQn 0 */ 57 | HAL_IncTick(); 58 | HAL_SYSTICK_IRQHandler(); 59 | /* USER CODE BEGIN SysTick_IRQn 1 */ 60 | 61 | /* USER CODE END SysTick_IRQn 1 */ 62 | } 63 | 64 | /******************************************************************************/ 65 | /* STM32F1xx Peripheral Interrupt Handlers */ 66 | /* Add here the Interrupt Handlers for the used peripherals. */ 67 | /* For the available peripheral interrupt handler names, */ 68 | /* please refer to the startup file (startup_stm32f1xx.s). */ 69 | /******************************************************************************/ 70 | 71 | /** 72 | * @brief This function handles USB low priority or CAN RX0 interrupts. 73 | */ 74 | void USB_LP_CAN1_RX0_IRQHandler(void) 75 | { 76 | /* USER CODE BEGIN USB_LP_CAN1_RX0_IRQn 0 */ 77 | 78 | /* USER CODE END USB_LP_CAN1_RX0_IRQn 0 */ 79 | HAL_PCD_IRQHandler(&hpcd_USB_FS); 80 | /* USER CODE BEGIN USB_LP_CAN1_RX0_IRQn 1 */ 81 | 82 | /* USER CODE END USB_LP_CAN1_RX0_IRQn 1 */ 83 | } 84 | 85 | /* USER CODE BEGIN 1 */ 86 | 87 | /* USER CODE END 1 */ 88 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 89 | -------------------------------------------------------------------------------- /bootloader-usb/Src/usb_device.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : USB_DEVICE 4 | * @version : v1.0_Cube 5 | * @brief : This file implements the USB Device 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2015 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | 37 | #include "usb_device.h" 38 | #include "usbd_core.h" 39 | #include "usbd_desc.h" 40 | #include "usbd_msc.h" 41 | #include "usbd_storage_if.h" 42 | 43 | /* USB Device Core handle declaration */ 44 | USBD_HandleTypeDef hUsbDeviceFS; 45 | 46 | /* init function */ 47 | void MX_USB_DEVICE_Init(void) 48 | { 49 | /* Init Device Library,Add Supported Class and Start the library*/ 50 | USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS); 51 | 52 | USBD_RegisterClass(&hUsbDeviceFS, &USBD_MSC); 53 | 54 | USBD_MSC_RegisterStorage(&hUsbDeviceFS, &USBD_Storage_Interface_fops_FS); 55 | 56 | USBD_Start(&hUsbDeviceFS); 57 | 58 | } 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 68 | -------------------------------------------------------------------------------- /bootloader-usb/Src/utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * utils.c 3 | * 4 | * Created on: 10 дек. 2015 г. 5 | * Author: alexey 6 | */ 7 | 8 | #include "utils.h" 9 | 10 | #include "stm32f1xx_hal.h" 11 | 12 | #include 13 | #include 14 | 15 | 16 | void delay() 17 | { 18 | for (volatile uint32_t i=0; i<10000000; i++) {} 19 | } 20 | 21 | uint32_t HashLy(uint32_t hash, const uint8_t * buf, uint32_t size) 22 | { 23 | for(uint32_t i=0; i. Debug is default" 6 | 7 | cfg="Debug" 8 | build_dir_prefix="./build" 9 | build_dir=$build_dir_prefix"/debug" 10 | source_dir_from_build_dir="../../" 11 | 12 | if [ "$1" == "release" ]; 13 | then 14 | cfg="Release" 15 | build_dir=$build_dir_prefix"/release" 16 | fi 17 | 18 | mkdir -p $build_dir 19 | ( 20 | cd $build_dir && cmake -DCMAKE_BUILD_TYPE=$cfg $source_dir_from_build_dir && make -j `nproc` 21 | ) 22 | -------------------------------------------------------------------------------- /bootloader-usb/clear.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | rm -rf build 6 | -------------------------------------------------------------------------------- /bootloader-usb/flash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | dir="debug" 4 | 5 | if [ "$1" == "release" ]; 6 | then 7 | dir="release" 8 | fi 9 | 10 | st-flash write build/$dir/usb-bootloader.bin 0x8000000 11 | -------------------------------------------------------------------------------- /bootloader-usb/ldscripts/STM32F103RETx_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ***************************************************************************** 3 | ** 4 | 5 | ** File : LinkerScript.ld 6 | ** 7 | ** Abstract : Linker script for STM32F103RETx Device with 8 | ** 512KByte FLASH, 64KByte RAM 9 | ** 10 | ** Set heap size, stack size and stack location according 11 | ** to application requirements. 12 | ** 13 | ** Set memory bank area and size if external memory is used. 14 | ** 15 | ** Target : STMicroelectronics STM32 16 | ** 17 | ** 18 | ** Distribution: The file is distributed as is, without any warranty 19 | ** of any kind. 20 | ** 21 | ***************************************************************************** 22 | ** @attention 23 | ** 24 | **

© COPYRIGHT(c) 2014 Ac6

25 | ** 26 | ** Redistribution and use in source and binary forms, with or without modification, 27 | ** are permitted provided that the following conditions are met: 28 | ** 1. Redistributions of source code must retain the above copyright notice, 29 | ** this list of conditions and the following disclaimer. 30 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 31 | ** this list of conditions and the following disclaimer in the documentation 32 | ** and/or other materials provided with the distribution. 33 | ** 3. Neither the name of Ac6 nor the names of its contributors 34 | ** may be used to endorse or promote products derived from this software 35 | ** without specific prior written permission. 36 | ** 37 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 38 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 39 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 41 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 42 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 43 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 44 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 45 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 | ** 48 | ***************************************************************************** 49 | */ 50 | 51 | /* Entry Point */ 52 | ENTRY(Reset_Handler) 53 | 54 | /* Highest address of the user mode stack */ 55 | _estack = 0x2000FFFF; /* end of RAM */ 56 | /* Generate a link error if heap and stack don't fit into RAM */ 57 | _Min_Heap_Size = 0x200; /* required amount of heap */ 58 | _Min_Stack_Size = 0x400; /* required amount of stack */ 59 | 60 | __Main_Stack_Size = 1024 ; 61 | PROVIDE ( _Heap_Begin = _end ) ; 62 | PROVIDE ( _Heap_Limit = _estack - __Main_Stack_Size ) ; 63 | 64 | /* Specify the memory areas */ 65 | MEMORY 66 | { 67 | /*FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K*/ 68 | INTERRUPTS_STUB (rx) : ORIGIN = 0x8000000, LENGTH = 4K 69 | FREE_SPACE (rx) : ORIGIN = 0x8001000, LENGTH = 462K 70 | FLASH (rx) : ORIGIN = 0x8074800, LENGTH = 44K 71 | STATE (rx) : ORIGIN = 0x807F800, LENGTH = 2K 72 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K 73 | } 74 | 75 | /* Define output sections */ 76 | SECTIONS 77 | { 78 | 79 | .isr_vector_stub : 80 | { 81 | . = ALIGN(4); 82 | _isr_stub = .; 83 | KEEP(*(.isr_vector_stub)) 84 | . = ALIGN(4); 85 | } >INTERRUPTS_STUB 86 | 87 | .loader_state : 88 | { 89 | . = ALIGN(4); 90 | _loader_state_addr = .; 91 | KEEP(*(.loader_state)) 92 | . = ALIGN(4); 93 | } >STATE 94 | 95 | /* The startup code goes first into FLASH */ 96 | .isr_vector : 97 | { 98 | . = ALIGN(4); 99 | _isr_real = .; 100 | KEEP(*(.isr_vector)) 101 | . = ALIGN(4); 102 | } >FLASH 103 | 104 | /* The program code and other data goes into FLASH */ 105 | .text : 106 | { 107 | . = ALIGN(4); 108 | *(.text) /* .text sections (code) */ 109 | *(.text*) /* .text* sections (code) */ 110 | *(.glue_7) /* glue arm to thumb code */ 111 | *(.glue_7t) /* glue thumb to arm code */ 112 | *(.eh_frame) 113 | 114 | KEEP (*(.init)) 115 | KEEP (*(.fini)) 116 | 117 | . = ALIGN(4); 118 | _etext = .; /* define a global symbols at end of code */ 119 | } >FLASH 120 | 121 | /* Constant data goes into FLASH */ 122 | .rodata : 123 | { 124 | . = ALIGN(4); 125 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 126 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 127 | . = ALIGN(4); 128 | } >FLASH 129 | 130 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH 131 | .ARM : { 132 | __exidx_start = .; 133 | *(.ARM.exidx*) 134 | __exidx_end = .; 135 | } >FLASH 136 | 137 | .preinit_array : 138 | { 139 | PROVIDE_HIDDEN (__preinit_array_start = .); 140 | KEEP (*(.preinit_array*)) 141 | PROVIDE_HIDDEN (__preinit_array_end = .); 142 | } >FLASH 143 | .init_array : 144 | { 145 | PROVIDE_HIDDEN (__init_array_start = .); 146 | KEEP (*(SORT(.init_array.*))) 147 | KEEP (*(.init_array*)) 148 | PROVIDE_HIDDEN (__init_array_end = .); 149 | } >FLASH 150 | .fini_array : 151 | { 152 | PROVIDE_HIDDEN (__fini_array_start = .); 153 | KEEP (*(SORT(.fini_array.*))) 154 | KEEP (*(.fini_array*)) 155 | PROVIDE_HIDDEN (__fini_array_end = .); 156 | } >FLASH 157 | 158 | /* used by the startup to initialize data */ 159 | _sidata = LOADADDR(.data); 160 | 161 | /* Initialized data sections goes into RAM, load LMA copy after code */ 162 | .data : 163 | { 164 | . = ALIGN(4); 165 | _sdata = .; /* create a global symbol at data start */ 166 | *(.data) /* .data sections */ 167 | *(.data*) /* .data* sections */ 168 | 169 | . = ALIGN(4); 170 | _edata = .; /* define a global symbol at data end */ 171 | } >RAM AT> FLASH 172 | 173 | 174 | /* Uninitialized data section */ 175 | . = ALIGN(4); 176 | .bss : 177 | { 178 | /* This is used by the startup in order to initialize the .bss secion */ 179 | _sbss = .; /* define a global symbol at bss start */ 180 | __bss_start__ = _sbss; 181 | *(.bss) 182 | *(.bss*) 183 | *(COMMON) 184 | 185 | . = ALIGN(4); 186 | _ebss = .; /* define a global symbol at bss end */ 187 | __bss_end__ = _ebss; 188 | } >RAM 189 | 190 | /* User_heap_stack section, used to check that there is enough RAM left */ 191 | ._user_heap_stack : 192 | { 193 | . = ALIGN(8); 194 | PROVIDE ( end = . ); 195 | PROVIDE ( _end = . ); 196 | . = . + _Min_Heap_Size; 197 | . = . + _Min_Stack_Size; 198 | . = ALIGN(8); 199 | } >RAM 200 | 201 | 202 | 203 | /* Remove information from the standard libraries */ 204 | /DISCARD/ : 205 | { 206 | libc.a ( * ) 207 | libm.a ( * ) 208 | libgcc.a ( * ) 209 | } 210 | 211 | .ARM.attributes 0 : { *(.ARM.attributes) } 212 | } 213 | 214 | 215 | -------------------------------------------------------------------------------- /generate-eclipse-project.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | echo "Usage: ./generate-eclipse-project.sh . Debug is default" 6 | 7 | workspace="eclipse-workspace" 8 | project="usb-bootloader" 9 | dir=$workspace/$project 10 | 11 | mkdir -p $dir 12 | 13 | cfg="Debug" 14 | if [ "$1" == "release" ]; 15 | then 16 | cfg="Release" 17 | build_dir=$build_dir_prefix"/release" 18 | fi 19 | 20 | ( 21 | cd $dir 22 | cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=$cfg ../../bootloader-usb 23 | 24 | # Patching definitions for C++11 support 25 | sed -i s/199711L/201103L/ .cproject 26 | ) 27 | 28 | echo "Unpacking archive with metadata.tar.gz with .metadata directory if presented" 29 | echo "Error here is normal if you have not metadata.tar.gz with eclipse settings" 30 | 31 | tar -xvf metadata.tar.gz 32 | mv .metadata $workspace 33 | echo "done." 34 | 35 | --------------------------------------------------------------------------------