├── .gitignore ├── Drivers ├── CMSIS │ ├── Device │ │ └── ST │ │ │ └── STM32F4xx │ │ │ └── Include │ │ │ ├── stm32f405xx.h │ │ │ ├── stm32f4xx.h │ │ │ └── system_stm32f4xx.h │ └── Include │ │ ├── cmsis_armcc.h │ │ ├── cmsis_armclang.h │ │ ├── cmsis_compiler.h │ │ ├── cmsis_gcc.h │ │ ├── cmsis_iccarm.h │ │ ├── cmsis_version.h │ │ ├── core_armv8mbl.h │ │ ├── core_armv8mml.h │ │ ├── core_cm0.h │ │ ├── core_cm0plus.h │ │ ├── core_cm1.h │ │ ├── core_cm23.h │ │ ├── core_cm3.h │ │ ├── core_cm33.h │ │ ├── core_cm4.h │ │ ├── core_cm7.h │ │ ├── core_sc000.h │ │ ├── core_sc300.h │ │ ├── mpu_armv7.h │ │ ├── mpu_armv8.h │ │ └── tz_context.h └── STM32F4xx_HAL_Driver │ ├── Inc │ ├── Legacy │ │ └── stm32_hal_legacy.h │ ├── stm32f4xx_hal.h │ ├── stm32f4xx_hal_cortex.h │ ├── stm32f4xx_hal_def.h │ ├── stm32f4xx_hal_dma.h │ ├── stm32f4xx_hal_dma_ex.h │ ├── stm32f4xx_hal_exti.h │ ├── stm32f4xx_hal_flash.h │ ├── stm32f4xx_hal_flash_ex.h │ ├── stm32f4xx_hal_flash_ramfunc.h │ ├── stm32f4xx_hal_gpio.h │ ├── stm32f4xx_hal_gpio_ex.h │ ├── stm32f4xx_hal_pcd.h │ ├── stm32f4xx_hal_pcd_ex.h │ ├── stm32f4xx_hal_pwr.h │ ├── stm32f4xx_hal_pwr_ex.h │ ├── stm32f4xx_hal_rcc.h │ ├── stm32f4xx_hal_rcc_ex.h │ ├── stm32f4xx_hal_tim.h │ ├── stm32f4xx_hal_tim_ex.h │ ├── stm32f4xx_ll_bus.h │ ├── stm32f4xx_ll_cortex.h │ ├── stm32f4xx_ll_dma.h │ ├── stm32f4xx_ll_exti.h │ ├── stm32f4xx_ll_gpio.h │ ├── stm32f4xx_ll_pwr.h │ ├── stm32f4xx_ll_rcc.h │ ├── stm32f4xx_ll_system.h │ ├── stm32f4xx_ll_usb.h │ └── stm32f4xx_ll_utils.h │ └── Src │ ├── stm32f4xx_hal.c │ ├── stm32f4xx_hal_cortex.c │ ├── stm32f4xx_hal_dma.c │ ├── stm32f4xx_hal_dma_ex.c │ ├── stm32f4xx_hal_exti.c │ ├── stm32f4xx_hal_flash.c │ ├── stm32f4xx_hal_flash_ex.c │ ├── stm32f4xx_hal_flash_ramfunc.c │ ├── stm32f4xx_hal_gpio.c │ ├── stm32f4xx_hal_pcd.c │ ├── stm32f4xx_hal_pcd_ex.c │ ├── stm32f4xx_hal_pwr.c │ ├── stm32f4xx_hal_pwr_ex.c │ ├── stm32f4xx_hal_rcc.c │ ├── stm32f4xx_hal_rcc_ex.c │ ├── stm32f4xx_hal_tim.c │ ├── stm32f4xx_hal_tim_ex.c │ ├── stm32f4xx_ll_exti.c │ ├── stm32f4xx_ll_gpio.c │ ├── stm32f4xx_ll_rcc.c │ ├── stm32f4xx_ll_usb.c │ └── stm32f4xx_ll_utils.c ├── Inc ├── Backup │ ├── cartridge.h.bak │ ├── main.h.bak │ ├── stm32_assert.h.bak │ ├── stm32f4xx_hal_conf.h.bak │ ├── stm32f4xx_it.h.bak │ ├── usb_device.h.bak │ ├── usbd_conf.h.bak │ ├── usbd_desc.h.bak │ └── usbd_storage_if.h.bak ├── cartridge.h ├── fat.h ├── main.h ├── stm32_assert.h ├── stm32f4xx_hal_conf.h ├── stm32f4xx_it.h ├── usb_device.h ├── usbd_conf.h ├── usbd_desc.h └── usbd_storage_if.h ├── LICENSE ├── Makefile ├── 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 ├── README.md ├── STM32F405RGTx_FLASH.ld ├── Src ├── cartridge.c ├── main.c ├── stm32f4xx_hal_msp.c ├── stm32f4xx_it.c ├── system_stm32f4xx.c ├── usb_device.c ├── usbd_conf.c ├── usbd_desc.c └── usbd_storage_if.c ├── gbcart-fast.ioc └── startup_stm32f405xx.s /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | rom/ 3 | .settings/ 4 | .cproject 5 | .project 6 | .mxproject 7 | 8 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emeryth/stm32gbcart-fw/31d491ae4a700c9fd97c6a6a29b2ad72ae3f5e63/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 1. Redistributions of source code must retain the above copyright notice, 14 | * this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, 16 | * this list of conditions and the following disclaimer in the documentation 17 | * and/or other materials provided with the distribution. 18 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | ****************************************************************************** 34 | */ 35 | 36 | /** @addtogroup CMSIS 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup stm32f4xx_system 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Define to prevent recursive inclusion 46 | */ 47 | #ifndef __SYSTEM_STM32F4XX_H 48 | #define __SYSTEM_STM32F4XX_H 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /** @addtogroup STM32F4xx_System_Includes 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @addtogroup STM32F4xx_System_Exported_types 64 | * @{ 65 | */ 66 | /* This variable is updated in three ways: 67 | 1) by calling CMSIS function SystemCoreClockUpdate() 68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 70 | Note: If you use this function to configure the system clock; then there 71 | is no need to call the 2 first functions listed above, since SystemCoreClock 72 | variable is updated automatically. 73 | */ 74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 75 | 76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 78 | 79 | /** 80 | * @} 81 | */ 82 | 83 | /** @addtogroup STM32F4xx_System_Exported_Constants 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @addtogroup STM32F4xx_System_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @addtogroup STM32F4xx_System_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | extern void SystemInit(void); 104 | extern void SystemCoreClockUpdate(void); 105 | /** 106 | * @} 107 | */ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /*__SYSTEM_STM32F4XX_H */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 123 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/cmsis_compiler.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_compiler.h 3 | * @brief CMSIS compiler generic header file 4 | * @version V5.0.4 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #ifndef __CMSIS_COMPILER_H 26 | #define __CMSIS_COMPILER_H 27 | 28 | #include 29 | 30 | /* 31 | * Arm Compiler 4/5 32 | */ 33 | #if defined ( __CC_ARM ) 34 | #include "cmsis_armcc.h" 35 | 36 | 37 | /* 38 | * Arm Compiler 6 (armclang) 39 | */ 40 | #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 41 | #include "cmsis_armclang.h" 42 | 43 | 44 | /* 45 | * GNU Compiler 46 | */ 47 | #elif defined ( __GNUC__ ) 48 | #include "cmsis_gcc.h" 49 | 50 | 51 | /* 52 | * IAR Compiler 53 | */ 54 | #elif defined ( __ICCARM__ ) 55 | #include 56 | 57 | 58 | /* 59 | * TI Arm Compiler 60 | */ 61 | #elif defined ( __TI_ARM__ ) 62 | #include 63 | 64 | #ifndef __ASM 65 | #define __ASM __asm 66 | #endif 67 | #ifndef __INLINE 68 | #define __INLINE inline 69 | #endif 70 | #ifndef __STATIC_INLINE 71 | #define __STATIC_INLINE static inline 72 | #endif 73 | #ifndef __STATIC_FORCEINLINE 74 | #define __STATIC_FORCEINLINE __STATIC_INLINE 75 | #endif 76 | #ifndef __NO_RETURN 77 | #define __NO_RETURN __attribute__((noreturn)) 78 | #endif 79 | #ifndef __USED 80 | #define __USED __attribute__((used)) 81 | #endif 82 | #ifndef __WEAK 83 | #define __WEAK __attribute__((weak)) 84 | #endif 85 | #ifndef __PACKED 86 | #define __PACKED __attribute__((packed)) 87 | #endif 88 | #ifndef __PACKED_STRUCT 89 | #define __PACKED_STRUCT struct __attribute__((packed)) 90 | #endif 91 | #ifndef __PACKED_UNION 92 | #define __PACKED_UNION union __attribute__((packed)) 93 | #endif 94 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 95 | struct __attribute__((packed)) T_UINT32 { uint32_t v; }; 96 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 97 | #endif 98 | #ifndef __UNALIGNED_UINT16_WRITE 99 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 100 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) 101 | #endif 102 | #ifndef __UNALIGNED_UINT16_READ 103 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 104 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 105 | #endif 106 | #ifndef __UNALIGNED_UINT32_WRITE 107 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 108 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 109 | #endif 110 | #ifndef __UNALIGNED_UINT32_READ 111 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 112 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 113 | #endif 114 | #ifndef __ALIGNED 115 | #define __ALIGNED(x) __attribute__((aligned(x))) 116 | #endif 117 | #ifndef __RESTRICT 118 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 119 | #define __RESTRICT 120 | #endif 121 | 122 | 123 | /* 124 | * TASKING Compiler 125 | */ 126 | #elif defined ( __TASKING__ ) 127 | /* 128 | * The CMSIS functions have been implemented as intrinsics in the compiler. 129 | * Please use "carm -?i" to get an up to date list of all intrinsics, 130 | * Including the CMSIS ones. 131 | */ 132 | 133 | #ifndef __ASM 134 | #define __ASM __asm 135 | #endif 136 | #ifndef __INLINE 137 | #define __INLINE inline 138 | #endif 139 | #ifndef __STATIC_INLINE 140 | #define __STATIC_INLINE static inline 141 | #endif 142 | #ifndef __STATIC_FORCEINLINE 143 | #define __STATIC_FORCEINLINE __STATIC_INLINE 144 | #endif 145 | #ifndef __NO_RETURN 146 | #define __NO_RETURN __attribute__((noreturn)) 147 | #endif 148 | #ifndef __USED 149 | #define __USED __attribute__((used)) 150 | #endif 151 | #ifndef __WEAK 152 | #define __WEAK __attribute__((weak)) 153 | #endif 154 | #ifndef __PACKED 155 | #define __PACKED __packed__ 156 | #endif 157 | #ifndef __PACKED_STRUCT 158 | #define __PACKED_STRUCT struct __packed__ 159 | #endif 160 | #ifndef __PACKED_UNION 161 | #define __PACKED_UNION union __packed__ 162 | #endif 163 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 164 | struct __packed__ T_UINT32 { uint32_t v; }; 165 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 166 | #endif 167 | #ifndef __UNALIGNED_UINT16_WRITE 168 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 169 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 170 | #endif 171 | #ifndef __UNALIGNED_UINT16_READ 172 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 173 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 174 | #endif 175 | #ifndef __UNALIGNED_UINT32_WRITE 176 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 177 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 178 | #endif 179 | #ifndef __UNALIGNED_UINT32_READ 180 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 181 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 182 | #endif 183 | #ifndef __ALIGNED 184 | #define __ALIGNED(x) __align(x) 185 | #endif 186 | #ifndef __RESTRICT 187 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 188 | #define __RESTRICT 189 | #endif 190 | 191 | 192 | /* 193 | * COSMIC Compiler 194 | */ 195 | #elif defined ( __CSMC__ ) 196 | #include 197 | 198 | #ifndef __ASM 199 | #define __ASM _asm 200 | #endif 201 | #ifndef __INLINE 202 | #define __INLINE inline 203 | #endif 204 | #ifndef __STATIC_INLINE 205 | #define __STATIC_INLINE static inline 206 | #endif 207 | #ifndef __STATIC_FORCEINLINE 208 | #define __STATIC_FORCEINLINE __STATIC_INLINE 209 | #endif 210 | #ifndef __NO_RETURN 211 | // NO RETURN is automatically detected hence no warning here 212 | #define __NO_RETURN 213 | #endif 214 | #ifndef __USED 215 | #warning No compiler specific solution for __USED. __USED is ignored. 216 | #define __USED 217 | #endif 218 | #ifndef __WEAK 219 | #define __WEAK __weak 220 | #endif 221 | #ifndef __PACKED 222 | #define __PACKED @packed 223 | #endif 224 | #ifndef __PACKED_STRUCT 225 | #define __PACKED_STRUCT @packed struct 226 | #endif 227 | #ifndef __PACKED_UNION 228 | #define __PACKED_UNION @packed union 229 | #endif 230 | #ifndef __UNALIGNED_UINT32 /* deprecated */ 231 | @packed struct T_UINT32 { uint32_t v; }; 232 | #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) 233 | #endif 234 | #ifndef __UNALIGNED_UINT16_WRITE 235 | __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; 236 | #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) 237 | #endif 238 | #ifndef __UNALIGNED_UINT16_READ 239 | __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; 240 | #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) 241 | #endif 242 | #ifndef __UNALIGNED_UINT32_WRITE 243 | __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; 244 | #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) 245 | #endif 246 | #ifndef __UNALIGNED_UINT32_READ 247 | __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; 248 | #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) 249 | #endif 250 | #ifndef __ALIGNED 251 | #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. 252 | #define __ALIGNED(x) 253 | #endif 254 | #ifndef __RESTRICT 255 | #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. 256 | #define __RESTRICT 257 | #endif 258 | 259 | 260 | #else 261 | #error Unknown compiler. 262 | #endif 263 | 264 | 265 | #endif /* __CMSIS_COMPILER_H */ 266 | 267 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_def.h 4 | * @author MCD Application Team 5 | * @brief This file contains HAL common defines, enumeration, macros and 6 | * structures definitions. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F4xx_HAL_DEF 23 | #define __STM32F4xx_HAL_DEF 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f4xx.h" 31 | #include "Legacy/stm32_hal_legacy.h" 32 | #include 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | 36 | /** 37 | * @brief HAL Status structures definition 38 | */ 39 | typedef enum 40 | { 41 | HAL_OK = 0x00U, 42 | HAL_ERROR = 0x01U, 43 | HAL_BUSY = 0x02U, 44 | HAL_TIMEOUT = 0x03U 45 | } HAL_StatusTypeDef; 46 | 47 | /** 48 | * @brief HAL Lock structures definition 49 | */ 50 | typedef enum 51 | { 52 | HAL_UNLOCKED = 0x00U, 53 | HAL_LOCKED = 0x01U 54 | } HAL_LockTypeDef; 55 | 56 | /* Exported macro ------------------------------------------------------------*/ 57 | 58 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 59 | 60 | #define HAL_MAX_DELAY 0xFFFFFFFFU 61 | 62 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT)) 63 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) 64 | 65 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 66 | do{ \ 67 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 68 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 69 | } while(0U) 70 | 71 | /** @brief Reset the Handle's State field. 72 | * @param __HANDLE__ specifies the Peripheral Handle. 73 | * @note This macro can be used for the following purpose: 74 | * - When the Handle is declared as local variable; before passing it as parameter 75 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 76 | * to set to 0 the Handle's "State" field. 77 | * Otherwise, "State" field may have any random value and the first time the function 78 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 79 | * (i.e. HAL_PPP_MspInit() will not be executed). 80 | * - When there is a need to reconfigure the low level hardware: instead of calling 81 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 82 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 83 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 84 | * @retval None 85 | */ 86 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U) 87 | 88 | #if (USE_RTOS == 1U) 89 | /* Reserved for future use */ 90 | #error "USE_RTOS should be 0 in the current HAL release" 91 | #else 92 | #define __HAL_LOCK(__HANDLE__) \ 93 | do{ \ 94 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 95 | { \ 96 | return HAL_BUSY; \ 97 | } \ 98 | else \ 99 | { \ 100 | (__HANDLE__)->Lock = HAL_LOCKED; \ 101 | } \ 102 | }while (0U) 103 | 104 | #define __HAL_UNLOCK(__HANDLE__) \ 105 | do{ \ 106 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 107 | }while (0U) 108 | #endif /* USE_RTOS */ 109 | 110 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 111 | #ifndef __weak 112 | #define __weak __attribute__((weak)) 113 | #endif /* __weak */ 114 | #ifndef __packed 115 | #define __packed __attribute__((__packed__)) 116 | #endif /* __packed */ 117 | #endif /* __GNUC__ */ 118 | 119 | 120 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 121 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 122 | #ifndef __ALIGN_END 123 | #define __ALIGN_END __attribute__ ((aligned (4))) 124 | #endif /* __ALIGN_END */ 125 | #ifndef __ALIGN_BEGIN 126 | #define __ALIGN_BEGIN 127 | #endif /* __ALIGN_BEGIN */ 128 | #else 129 | #ifndef __ALIGN_END 130 | #define __ALIGN_END 131 | #endif /* __ALIGN_END */ 132 | #ifndef __ALIGN_BEGIN 133 | #if defined (__CC_ARM) /* ARM Compiler */ 134 | #define __ALIGN_BEGIN __align(4) 135 | #elif defined (__ICCARM__) /* IAR Compiler */ 136 | #define __ALIGN_BEGIN 137 | #endif /* __CC_ARM */ 138 | #endif /* __ALIGN_BEGIN */ 139 | #endif /* __GNUC__ */ 140 | 141 | 142 | /** 143 | * @brief __RAM_FUNC definition 144 | */ 145 | #if defined ( __CC_ARM ) 146 | /* ARM Compiler 147 | ------------ 148 | RAM functions are defined using the toolchain options. 149 | Functions that are executed in RAM should reside in a separate source module. 150 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 151 | area of a module to a memory space in physical RAM. 152 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 153 | dialog. 154 | */ 155 | #define __RAM_FUNC 156 | 157 | #elif defined ( __ICCARM__ ) 158 | /* ICCARM Compiler 159 | --------------- 160 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 161 | */ 162 | #define __RAM_FUNC __ramfunc 163 | 164 | #elif defined ( __GNUC__ ) 165 | /* GNU Compiler 166 | ------------ 167 | RAM functions are defined using a specific toolchain attribute 168 | "__attribute__((section(".RamFunc")))". 169 | */ 170 | #define __RAM_FUNC __attribute__((section(".RamFunc"))) 171 | 172 | #endif 173 | 174 | /** 175 | * @brief __NOINLINE definition 176 | */ 177 | #if defined ( __CC_ARM ) || defined ( __GNUC__ ) 178 | /* ARM & GNUCompiler 179 | ---------------- 180 | */ 181 | #define __NOINLINE __attribute__ ( (noinline) ) 182 | 183 | #elif defined ( __ICCARM__ ) 184 | /* ICCARM Compiler 185 | --------------- 186 | */ 187 | #define __NOINLINE _Pragma("optimize = no_inline") 188 | 189 | #endif 190 | 191 | #ifdef __cplusplus 192 | } 193 | #endif 194 | 195 | #endif /* ___STM32F4xx_HAL_DEF */ 196 | 197 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 198 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

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

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

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

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F4xx_HAL_PCD_EX_H 22 | #define STM32F4xx_HAL_PCD_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS) 32 | /** @addtogroup STM32F4xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup PCDEx 37 | * @{ 38 | */ 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macros -----------------------------------------------------------*/ 42 | /* Exported functions --------------------------------------------------------*/ 43 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 44 | * @{ 45 | */ 46 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 47 | * @{ 48 | */ 49 | 50 | #if defined (USB_OTG_FS) || defined (USB_OTG_HS) 51 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); 52 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); 53 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */ 54 | 55 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 56 | HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd); 57 | HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd); 58 | #endif /* defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) */ 59 | #if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) 60 | HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd); 61 | HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd); 62 | void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd); 63 | #endif /* defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) */ 64 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); 65 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** 80 | * @} 81 | */ 82 | #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | 89 | #endif /* STM32F4xx_HAL_PCD_EX_H */ 90 | 91 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 92 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.c 4 | * @author MCD Application Team 5 | * @brief DMA Extension HAL module driver 6 | * This file provides firmware functions to manage the following 7 | * functionalities of the DMA Extension peripheral: 8 | * + Extended features functions 9 | * 10 | @verbatim 11 | ============================================================================== 12 | ##### How to use this driver ##### 13 | ============================================================================== 14 | [..] 15 | The DMA Extension HAL driver can be used as follows: 16 | (#) Start a multi buffer transfer using the HAL_DMA_MultiBufferStart() function 17 | for polling mode or HAL_DMA_MultiBufferStart_IT() for interrupt mode. 18 | 19 | -@- In Memory-to-Memory transfer mode, Multi (Double) Buffer mode is not allowed. 20 | -@- When Multi (Double) Buffer mode is enabled the, transfer is circular by default. 21 | -@- In Multi (Double) buffer mode, it is possible to update the base address for 22 | the AHB memory port on the fly (DMA_SxM0AR or DMA_SxM1AR) when the stream is enabled. 23 | 24 | @endverbatim 25 | ****************************************************************************** 26 | * @attention 27 | * 28 | *

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

30 | * 31 | * This software component is licensed by ST under BSD 3-Clause license, 32 | * the "License"; You may not use this file except in compliance with the 33 | * License. You may obtain a copy of the License at: 34 | * opensource.org/licenses/BSD-3-Clause 35 | * 36 | ****************************************************************************** 37 | */ 38 | 39 | /* Includes ------------------------------------------------------------------*/ 40 | #include "stm32f4xx_hal.h" 41 | 42 | /** @addtogroup STM32F4xx_HAL_Driver 43 | * @{ 44 | */ 45 | 46 | /** @defgroup DMAEx DMAEx 47 | * @brief DMA Extended HAL module driver 48 | * @{ 49 | */ 50 | 51 | #ifdef HAL_DMA_MODULE_ENABLED 52 | 53 | /* Private types -------------------------------------------------------------*/ 54 | /* Private variables ---------------------------------------------------------*/ 55 | /* Private Constants ---------------------------------------------------------*/ 56 | /* Private macros ------------------------------------------------------------*/ 57 | /* Private functions ---------------------------------------------------------*/ 58 | /** @addtogroup DMAEx_Private_Functions 59 | * @{ 60 | */ 61 | static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength); 62 | /** 63 | * @} 64 | */ 65 | 66 | /* Exported functions ---------------------------------------------------------*/ 67 | 68 | /** @addtogroup DMAEx_Exported_Functions 69 | * @{ 70 | */ 71 | 72 | 73 | /** @addtogroup DMAEx_Exported_Functions_Group1 74 | * 75 | @verbatim 76 | =============================================================================== 77 | ##### Extended features functions ##### 78 | =============================================================================== 79 | [..] This section provides functions allowing to: 80 | (+) Configure the source, destination address and data length and 81 | Start MultiBuffer DMA transfer 82 | (+) Configure the source, destination address and data length and 83 | Start MultiBuffer DMA transfer with interrupt 84 | (+) Change on the fly the memory0 or memory1 address. 85 | 86 | @endverbatim 87 | * @{ 88 | */ 89 | 90 | 91 | /** 92 | * @brief Starts the multi_buffer DMA Transfer. 93 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 94 | * the configuration information for the specified DMA Stream. 95 | * @param SrcAddress The source memory Buffer address 96 | * @param DstAddress The destination memory Buffer address 97 | * @param SecondMemAddress The second memory Buffer address in case of multi buffer Transfer 98 | * @param DataLength The length of data to be transferred from source to destination 99 | * @retval HAL status 100 | */ 101 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength) 102 | { 103 | HAL_StatusTypeDef status = HAL_OK; 104 | 105 | /* Check the parameters */ 106 | assert_param(IS_DMA_BUFFER_SIZE(DataLength)); 107 | 108 | /* Memory-to-memory transfer not supported in double buffering mode */ 109 | if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY) 110 | { 111 | hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED; 112 | status = HAL_ERROR; 113 | } 114 | else 115 | { 116 | /* Process Locked */ 117 | __HAL_LOCK(hdma); 118 | 119 | if(HAL_DMA_STATE_READY == hdma->State) 120 | { 121 | /* Change DMA peripheral state */ 122 | hdma->State = HAL_DMA_STATE_BUSY; 123 | 124 | /* Enable the double buffer mode */ 125 | hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM; 126 | 127 | /* Configure DMA Stream destination address */ 128 | hdma->Instance->M1AR = SecondMemAddress; 129 | 130 | /* Configure the source, destination address and the data length */ 131 | DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength); 132 | 133 | /* Enable the peripheral */ 134 | __HAL_DMA_ENABLE(hdma); 135 | } 136 | else 137 | { 138 | /* Return error status */ 139 | status = HAL_BUSY; 140 | } 141 | } 142 | return status; 143 | } 144 | 145 | /** 146 | * @brief Starts the multi_buffer DMA Transfer with interrupt enabled. 147 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 148 | * the configuration information for the specified DMA Stream. 149 | * @param SrcAddress The source memory Buffer address 150 | * @param DstAddress The destination memory Buffer address 151 | * @param SecondMemAddress The second memory Buffer address in case of multi buffer Transfer 152 | * @param DataLength The length of data to be transferred from source to destination 153 | * @retval HAL status 154 | */ 155 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength) 156 | { 157 | HAL_StatusTypeDef status = HAL_OK; 158 | 159 | /* Check the parameters */ 160 | assert_param(IS_DMA_BUFFER_SIZE(DataLength)); 161 | 162 | /* Memory-to-memory transfer not supported in double buffering mode */ 163 | if (hdma->Init.Direction == DMA_MEMORY_TO_MEMORY) 164 | { 165 | hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED; 166 | return HAL_ERROR; 167 | } 168 | 169 | /* Check callback functions */ 170 | if ((NULL == hdma->XferCpltCallback) || (NULL == hdma->XferM1CpltCallback) || (NULL == hdma->XferErrorCallback)) 171 | { 172 | hdma->ErrorCode = HAL_DMA_ERROR_PARAM; 173 | return HAL_ERROR; 174 | } 175 | 176 | /* Process locked */ 177 | __HAL_LOCK(hdma); 178 | 179 | if(HAL_DMA_STATE_READY == hdma->State) 180 | { 181 | /* Change DMA peripheral state */ 182 | hdma->State = HAL_DMA_STATE_BUSY; 183 | 184 | /* Initialize the error code */ 185 | hdma->ErrorCode = HAL_DMA_ERROR_NONE; 186 | 187 | /* Enable the Double buffer mode */ 188 | hdma->Instance->CR |= (uint32_t)DMA_SxCR_DBM; 189 | 190 | /* Configure DMA Stream destination address */ 191 | hdma->Instance->M1AR = SecondMemAddress; 192 | 193 | /* Configure the source, destination address and the data length */ 194 | DMA_MultiBufferSetConfig(hdma, SrcAddress, DstAddress, DataLength); 195 | 196 | /* Clear all flags */ 197 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma)); 198 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma)); 199 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)); 200 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_DME_FLAG_INDEX(hdma)); 201 | __HAL_DMA_CLEAR_FLAG (hdma, __HAL_DMA_GET_FE_FLAG_INDEX(hdma)); 202 | 203 | /* Enable Common interrupts*/ 204 | hdma->Instance->CR |= DMA_IT_TC | DMA_IT_TE | DMA_IT_DME; 205 | hdma->Instance->FCR |= DMA_IT_FE; 206 | 207 | if((hdma->XferHalfCpltCallback != NULL) || (hdma->XferM1HalfCpltCallback != NULL)) 208 | { 209 | hdma->Instance->CR |= DMA_IT_HT; 210 | } 211 | 212 | /* Enable the peripheral */ 213 | __HAL_DMA_ENABLE(hdma); 214 | } 215 | else 216 | { 217 | /* Process unlocked */ 218 | __HAL_UNLOCK(hdma); 219 | 220 | /* Return error status */ 221 | status = HAL_BUSY; 222 | } 223 | return status; 224 | } 225 | 226 | /** 227 | * @brief Change the memory0 or memory1 address on the fly. 228 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 229 | * the configuration information for the specified DMA Stream. 230 | * @param Address The new address 231 | * @param memory the memory to be changed, This parameter can be one of 232 | * the following values: 233 | * MEMORY0 / 234 | * MEMORY1 235 | * @note The MEMORY0 address can be changed only when the current transfer use 236 | * MEMORY1 and the MEMORY1 address can be changed only when the current 237 | * transfer use MEMORY0. 238 | * @retval HAL status 239 | */ 240 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory) 241 | { 242 | if(memory == MEMORY0) 243 | { 244 | /* change the memory0 address */ 245 | hdma->Instance->M0AR = Address; 246 | } 247 | else 248 | { 249 | /* change the memory1 address */ 250 | hdma->Instance->M1AR = Address; 251 | } 252 | 253 | return HAL_OK; 254 | } 255 | 256 | /** 257 | * @} 258 | */ 259 | 260 | /** 261 | * @} 262 | */ 263 | 264 | /** @addtogroup DMAEx_Private_Functions 265 | * @{ 266 | */ 267 | 268 | /** 269 | * @brief Set the DMA Transfer parameter. 270 | * @param hdma pointer to a DMA_HandleTypeDef structure that contains 271 | * the configuration information for the specified DMA Stream. 272 | * @param SrcAddress The source memory Buffer address 273 | * @param DstAddress The destination memory Buffer address 274 | * @param DataLength The length of data to be transferred from source to destination 275 | * @retval HAL status 276 | */ 277 | static void DMA_MultiBufferSetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) 278 | { 279 | /* Configure DMA Stream data length */ 280 | hdma->Instance->NDTR = DataLength; 281 | 282 | /* Peripheral to Memory */ 283 | if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH) 284 | { 285 | /* Configure DMA Stream destination address */ 286 | hdma->Instance->PAR = DstAddress; 287 | 288 | /* Configure DMA Stream source address */ 289 | hdma->Instance->M0AR = SrcAddress; 290 | } 291 | /* Memory to Peripheral */ 292 | else 293 | { 294 | /* Configure DMA Stream source address */ 295 | hdma->Instance->PAR = SrcAddress; 296 | 297 | /* Configure DMA Stream destination address */ 298 | hdma->Instance->M0AR = DstAddress; 299 | } 300 | } 301 | 302 | /** 303 | * @} 304 | */ 305 | 306 | #endif /* HAL_DMA_MODULE_ENABLED */ 307 | /** 308 | * @} 309 | */ 310 | 311 | /** 312 | * @} 313 | */ 314 | 315 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 316 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.c 4 | * @author MCD Application Team 5 | * @brief FLASH RAMFUNC module driver. 6 | * This file provides a FLASH firmware functions which should be 7 | * executed from internal SRAM 8 | * + Stop/Start the flash interface while System Run 9 | * + Enable/Disable the flash sleep while System Run 10 | @verbatim 11 | ============================================================================== 12 | ##### APIs executed from Internal RAM ##### 13 | ============================================================================== 14 | [..] 15 | *** ARM Compiler *** 16 | -------------------- 17 | [..] RAM functions are defined using the toolchain options. 18 | Functions that are be executed in RAM should reside in a separate 19 | source module. Using the 'Options for File' dialog you can simply change 20 | the 'Code / Const' area of a module to a memory space in physical RAM. 21 | Available memory areas are declared in the 'Target' tab of the 22 | Options for Target' dialog. 23 | 24 | *** ICCARM Compiler *** 25 | ----------------------- 26 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc". 27 | 28 | *** GNU Compiler *** 29 | -------------------- 30 | [..] RAM functions are defined using a specific toolchain attribute 31 | "__attribute__((section(".RamFunc")))". 32 | 33 | @endverbatim 34 | ****************************************************************************** 35 | * @attention 36 | * 37 | *

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

39 | * 40 | * This software component is licensed by ST under BSD 3-Clause license, 41 | * the "License"; You may not use this file except in compliance with the 42 | * License. You may obtain a copy of the License at: 43 | * opensource.org/licenses/BSD-3-Clause 44 | * 45 | ****************************************************************************** 46 | */ 47 | 48 | /* Includes ------------------------------------------------------------------*/ 49 | #include "stm32f4xx_hal.h" 50 | 51 | /** @addtogroup STM32F4xx_HAL_Driver 52 | * @{ 53 | */ 54 | 55 | /** @defgroup FLASH_RAMFUNC FLASH RAMFUNC 56 | * @brief FLASH functions executed from RAM 57 | * @{ 58 | */ 59 | #ifdef HAL_FLASH_MODULE_ENABLED 60 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ 61 | defined(STM32F412Rx) || defined(STM32F412Cx) 62 | 63 | /* Private typedef -----------------------------------------------------------*/ 64 | /* Private define ------------------------------------------------------------*/ 65 | /* Private macro -------------------------------------------------------------*/ 66 | /* Private variables ---------------------------------------------------------*/ 67 | /* Private function prototypes -----------------------------------------------*/ 68 | /* Exported functions --------------------------------------------------------*/ 69 | /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH RAMFUNC Exported Functions 70 | * @{ 71 | */ 72 | 73 | /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions executed from internal RAM 74 | * @brief Peripheral Extended features functions 75 | * 76 | @verbatim 77 | 78 | =============================================================================== 79 | ##### ramfunc functions ##### 80 | =============================================================================== 81 | [..] 82 | This subsection provides a set of functions that should be executed from RAM 83 | transfers. 84 | 85 | @endverbatim 86 | * @{ 87 | */ 88 | 89 | /** 90 | * @brief Stop the flash interface while System Run 91 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 92 | * @note This mode couldn't be set while executing with the flash itself. 93 | * It should be done with specific routine executed from RAM. 94 | * @retval HAL status 95 | */ 96 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void) 97 | { 98 | /* Enable Power ctrl clock */ 99 | __HAL_RCC_PWR_CLK_ENABLE(); 100 | /* Stop the flash interface while System Run */ 101 | SET_BIT(PWR->CR, PWR_CR_FISSR); 102 | 103 | return HAL_OK; 104 | } 105 | 106 | /** 107 | * @brief Start the flash interface while System Run 108 | * @note This mode is only available for STM32F411xx/STM32F446xx devices. 109 | * @note This mode couldn't be set while executing with the flash itself. 110 | * It should be done with specific routine executed from RAM. 111 | * @retval HAL status 112 | */ 113 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void) 114 | { 115 | /* Enable Power ctrl clock */ 116 | __HAL_RCC_PWR_CLK_ENABLE(); 117 | /* Start the flash interface while System Run */ 118 | CLEAR_BIT(PWR->CR, PWR_CR_FISSR); 119 | 120 | return HAL_OK; 121 | } 122 | 123 | /** 124 | * @brief Enable the flash sleep while System Run 125 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 126 | * @note This mode could n't be set while executing with the flash itself. 127 | * It should be done with specific routine executed from RAM. 128 | * @retval HAL status 129 | */ 130 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void) 131 | { 132 | /* Enable Power ctrl clock */ 133 | __HAL_RCC_PWR_CLK_ENABLE(); 134 | /* Enable the flash sleep while System Run */ 135 | SET_BIT(PWR->CR, PWR_CR_FMSSR); 136 | 137 | return HAL_OK; 138 | } 139 | 140 | /** 141 | * @brief Disable the flash sleep while System Run 142 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 143 | * @note This mode couldn't be set while executing with the flash itself. 144 | * It should be done with specific routine executed from RAM. 145 | * @retval HAL status 146 | */ 147 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void) 148 | { 149 | /* Enable Power ctrl clock */ 150 | __HAL_RCC_PWR_CLK_ENABLE(); 151 | /* Disable the flash sleep while System Run */ 152 | CLEAR_BIT(PWR->CR, PWR_CR_FMSSR); 153 | 154 | return HAL_OK; 155 | } 156 | 157 | /** 158 | * @} 159 | */ 160 | 161 | /** 162 | * @} 163 | */ 164 | 165 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 166 | #endif /* HAL_FLASH_MODULE_ENABLED */ 167 | /** 168 | * @} 169 | */ 170 | 171 | /** 172 | * @} 173 | */ 174 | 175 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 176 | -------------------------------------------------------------------------------- /Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_exti.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_ll_exti.c 4 | * @author MCD Application Team 5 | * @brief EXTI LL module driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | #if defined(USE_FULL_LL_DRIVER) 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "stm32f4xx_ll_exti.h" 23 | #ifdef USE_FULL_ASSERT 24 | #include "stm32_assert.h" 25 | #else 26 | #define assert_param(expr) ((void)0U) 27 | #endif 28 | 29 | /** @addtogroup STM32F4xx_LL_Driver 30 | * @{ 31 | */ 32 | 33 | #if defined (EXTI) 34 | 35 | /** @defgroup EXTI_LL EXTI 36 | * @{ 37 | */ 38 | 39 | /* Private types -------------------------------------------------------------*/ 40 | /* Private variables ---------------------------------------------------------*/ 41 | /* Private constants ---------------------------------------------------------*/ 42 | /* Private macros ------------------------------------------------------------*/ 43 | /** @addtogroup EXTI_LL_Private_Macros 44 | * @{ 45 | */ 46 | 47 | #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U) 48 | 49 | #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \ 50 | || ((__VALUE__) == LL_EXTI_MODE_EVENT) \ 51 | || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT)) 52 | 53 | 54 | #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \ 55 | || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \ 56 | || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \ 57 | || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING)) 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /* Private function prototypes -----------------------------------------------*/ 64 | 65 | /* Exported functions --------------------------------------------------------*/ 66 | /** @addtogroup EXTI_LL_Exported_Functions 67 | * @{ 68 | */ 69 | 70 | /** @addtogroup EXTI_LL_EF_Init 71 | * @{ 72 | */ 73 | 74 | /** 75 | * @brief De-initialize the EXTI registers to their default reset values. 76 | * @retval An ErrorStatus enumeration value: 77 | * - SUCCESS: EXTI registers are de-initialized 78 | * - ERROR: not applicable 79 | */ 80 | uint32_t LL_EXTI_DeInit(void) 81 | { 82 | /* Interrupt mask register set to default reset values */ 83 | LL_EXTI_WriteReg(IMR, 0x00000000U); 84 | /* Event mask register set to default reset values */ 85 | LL_EXTI_WriteReg(EMR, 0x00000000U); 86 | /* Rising Trigger selection register set to default reset values */ 87 | LL_EXTI_WriteReg(RTSR, 0x00000000U); 88 | /* Falling Trigger selection register set to default reset values */ 89 | LL_EXTI_WriteReg(FTSR, 0x00000000U); 90 | /* Software interrupt event register set to default reset values */ 91 | LL_EXTI_WriteReg(SWIER, 0x00000000U); 92 | /* Pending register set to default reset values */ 93 | LL_EXTI_WriteReg(PR, 0x00FFFFFFU); 94 | 95 | return SUCCESS; 96 | } 97 | 98 | /** 99 | * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct. 100 | * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure. 101 | * @retval An ErrorStatus enumeration value: 102 | * - SUCCESS: EXTI registers are initialized 103 | * - ERROR: not applicable 104 | */ 105 | uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct) 106 | { 107 | ErrorStatus status = SUCCESS; 108 | /* Check the parameters */ 109 | assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31)); 110 | assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand)); 111 | assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode)); 112 | 113 | /* ENABLE LineCommand */ 114 | if (EXTI_InitStruct->LineCommand != DISABLE) 115 | { 116 | assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger)); 117 | 118 | /* Configure EXTI Lines in range from 0 to 31 */ 119 | if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE) 120 | { 121 | switch (EXTI_InitStruct->Mode) 122 | { 123 | case LL_EXTI_MODE_IT: 124 | /* First Disable Event on provided Lines */ 125 | LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31); 126 | /* Then Enable IT on provided Lines */ 127 | LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31); 128 | break; 129 | case LL_EXTI_MODE_EVENT: 130 | /* First Disable IT on provided Lines */ 131 | LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31); 132 | /* Then Enable Event on provided Lines */ 133 | LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31); 134 | break; 135 | case LL_EXTI_MODE_IT_EVENT: 136 | /* Directly Enable IT & Event on provided Lines */ 137 | LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31); 138 | LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31); 139 | break; 140 | default: 141 | status = ERROR; 142 | break; 143 | } 144 | if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE) 145 | { 146 | switch (EXTI_InitStruct->Trigger) 147 | { 148 | case LL_EXTI_TRIGGER_RISING: 149 | /* First Disable Falling Trigger on provided Lines */ 150 | LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31); 151 | /* Then Enable Rising Trigger on provided Lines */ 152 | LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31); 153 | break; 154 | case LL_EXTI_TRIGGER_FALLING: 155 | /* First Disable Rising Trigger on provided Lines */ 156 | LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31); 157 | /* Then Enable Falling Trigger on provided Lines */ 158 | LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31); 159 | break; 160 | case LL_EXTI_TRIGGER_RISING_FALLING: 161 | LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31); 162 | LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31); 163 | break; 164 | default: 165 | status = ERROR; 166 | break; 167 | } 168 | } 169 | } 170 | } 171 | /* DISABLE LineCommand */ 172 | else 173 | { 174 | /* De-configure EXTI Lines in range from 0 to 31 */ 175 | LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31); 176 | LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31); 177 | } 178 | return status; 179 | } 180 | 181 | /** 182 | * @brief Set each @ref LL_EXTI_InitTypeDef field to default value. 183 | * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure. 184 | * @retval None 185 | */ 186 | void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct) 187 | { 188 | EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE; 189 | EXTI_InitStruct->LineCommand = DISABLE; 190 | EXTI_InitStruct->Mode = LL_EXTI_MODE_IT; 191 | EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING; 192 | } 193 | 194 | /** 195 | * @} 196 | */ 197 | 198 | /** 199 | * @} 200 | */ 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | #endif /* defined (EXTI) */ 207 | 208 | /** 209 | * @} 210 | */ 211 | 212 | #endif /* USE_FULL_LL_DRIVER */ 213 | 214 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 215 | -------------------------------------------------------------------------------- /Inc/Backup/cartridge.h.bak: -------------------------------------------------------------------------------- 1 | /* 2 | * cartridge.h 3 | * 4 | * Created on: Jan 2, 2020 5 | * Author: andrju 6 | */ 7 | 8 | #ifndef INC_CARTRIDGE_H_ 9 | #define INC_CARTRIDGE_H_ 10 | 11 | #include 12 | 13 | #define RAM_SIZE (128*1024) 14 | #define RAM1_SIZE (96*1024) 15 | #define RAM2_SIZE (32*1024) 16 | 17 | 18 | typedef struct{ 19 | 20 | const uint8_t *rom; 21 | uint8_t *ram; 22 | int rom_bank; 23 | int ram_bank; 24 | 25 | }cartridge_t; 26 | 27 | extern cartridge_t cartridge; 28 | extern uint8_t sram[RAM1_SIZE]; 29 | extern uint8_t sram2[RAM2_SIZE]; 30 | 31 | void load_save(void); 32 | 33 | #endif /* INC_CARTRIDGE_H_ */ 34 | -------------------------------------------------------------------------------- /Inc/Backup/main.h.bak: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_ll_rcc.h" 32 | #include "stm32f4xx_ll_bus.h" 33 | #include "stm32f4xx_ll_system.h" 34 | #include "stm32f4xx_ll_exti.h" 35 | #include "stm32f4xx_ll_cortex.h" 36 | #include "stm32f4xx_ll_utils.h" 37 | #include "stm32f4xx_ll_pwr.h" 38 | #include "stm32f4xx_ll_dma.h" 39 | #include "stm32f4xx.h" 40 | #include "stm32f4xx_ll_gpio.h" 41 | 42 | #if defined(USE_FULL_ASSERT) 43 | #include "stm32_assert.h" 44 | #endif /* USE_FULL_ASSERT */ 45 | 46 | /* Private includes ----------------------------------------------------------*/ 47 | /* USER CODE BEGIN Includes */ 48 | 49 | /* USER CODE END Includes */ 50 | 51 | /* Exported types ------------------------------------------------------------*/ 52 | /* USER CODE BEGIN ET */ 53 | 54 | /* USER CODE END ET */ 55 | 56 | /* Exported constants --------------------------------------------------------*/ 57 | /* USER CODE BEGIN EC */ 58 | 59 | /* USER CODE END EC */ 60 | 61 | /* Exported macro ------------------------------------------------------------*/ 62 | /* USER CODE BEGIN EM */ 63 | 64 | /* USER CODE END EM */ 65 | 66 | /* Exported functions prototypes ---------------------------------------------*/ 67 | void Error_Handler(void); 68 | 69 | /* USER CODE BEGIN EFP */ 70 | 71 | /* USER CODE END EFP */ 72 | 73 | /* Private defines -----------------------------------------------------------*/ 74 | #define VBUS_Pin LL_GPIO_PIN_13 75 | #define VBUS_GPIO_Port GPIOC 76 | #define VGB_Pin LL_GPIO_PIN_14 77 | #define VGB_GPIO_Port GPIOC 78 | #define D0_Pin LL_GPIO_PIN_0 79 | #define D0_GPIO_Port GPIOC 80 | #define D1_Pin LL_GPIO_PIN_1 81 | #define D1_GPIO_Port GPIOC 82 | #define D2_Pin LL_GPIO_PIN_2 83 | #define D2_GPIO_Port GPIOC 84 | #define D3_Pin LL_GPIO_PIN_3 85 | #define D3_GPIO_Port GPIOC 86 | #define D4_Pin LL_GPIO_PIN_4 87 | #define D4_GPIO_Port GPIOC 88 | #define D5_Pin LL_GPIO_PIN_5 89 | #define D5_GPIO_Port GPIOC 90 | #define A0_Pin LL_GPIO_PIN_0 91 | #define A0_GPIO_Port GPIOB 92 | #define A1_Pin LL_GPIO_PIN_1 93 | #define A1_GPIO_Port GPIOB 94 | #define A2_Pin LL_GPIO_PIN_2 95 | #define A2_GPIO_Port GPIOB 96 | #define A10_Pin LL_GPIO_PIN_10 97 | #define A10_GPIO_Port GPIOB 98 | #define A11_Pin LL_GPIO_PIN_11 99 | #define A11_GPIO_Port GPIOB 100 | #define A12_Pin LL_GPIO_PIN_12 101 | #define A12_GPIO_Port GPIOB 102 | #define A13_Pin LL_GPIO_PIN_13 103 | #define A13_GPIO_Port GPIOB 104 | #define A14_Pin LL_GPIO_PIN_14 105 | #define A14_GPIO_Port GPIOB 106 | #define A15_Pin LL_GPIO_PIN_15 107 | #define A15_GPIO_Port GPIOB 108 | #define D6_Pin LL_GPIO_PIN_6 109 | #define D6_GPIO_Port GPIOC 110 | #define D7_Pin LL_GPIO_PIN_7 111 | #define D7_GPIO_Port GPIOC 112 | #define CLK_Pin LL_GPIO_PIN_8 113 | #define CLK_GPIO_Port GPIOC 114 | #define CLK_EXTI_IRQn EXTI9_5_IRQn 115 | #define WR_Pin LL_GPIO_PIN_9 116 | #define WR_GPIO_Port GPIOC 117 | #define LED3_Pin LL_GPIO_PIN_8 118 | #define LED3_GPIO_Port GPIOA 119 | #define LED2_Pin LL_GPIO_PIN_9 120 | #define LED2_GPIO_Port GPIOA 121 | #define LED1_Pin LL_GPIO_PIN_10 122 | #define LED1_GPIO_Port GPIOA 123 | #define RD_Pin LL_GPIO_PIN_10 124 | #define RD_GPIO_Port GPIOC 125 | #define CS_Pin LL_GPIO_PIN_11 126 | #define CS_GPIO_Port GPIOC 127 | #define RST_Pin LL_GPIO_PIN_12 128 | #define RST_GPIO_Port GPIOC 129 | #define A3_Pin LL_GPIO_PIN_3 130 | #define A3_GPIO_Port GPIOB 131 | #define A4_Pin LL_GPIO_PIN_4 132 | #define A4_GPIO_Port GPIOB 133 | #define A5_Pin LL_GPIO_PIN_5 134 | #define A5_GPIO_Port GPIOB 135 | #define A6_Pin LL_GPIO_PIN_6 136 | #define A6_GPIO_Port GPIOB 137 | #define A7_Pin LL_GPIO_PIN_7 138 | #define A7_GPIO_Port GPIOB 139 | #define A8_Pin LL_GPIO_PIN_8 140 | #define A8_GPIO_Port GPIOB 141 | #define A9_Pin LL_GPIO_PIN_9 142 | #define A9_GPIO_Port GPIOB 143 | #ifndef NVIC_PRIORITYGROUP_0 144 | #define NVIC_PRIORITYGROUP_0 ((uint32_t)0x00000007) /*!< 0 bit for pre-emption priority, 145 | 4 bits for subpriority */ 146 | #define NVIC_PRIORITYGROUP_1 ((uint32_t)0x00000006) /*!< 1 bit for pre-emption priority, 147 | 3 bits for subpriority */ 148 | #define NVIC_PRIORITYGROUP_2 ((uint32_t)0x00000005) /*!< 2 bits for pre-emption priority, 149 | 2 bits for subpriority */ 150 | #define NVIC_PRIORITYGROUP_3 ((uint32_t)0x00000004) /*!< 3 bits for pre-emption priority, 151 | 1 bit for subpriority */ 152 | #define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003) /*!< 4 bits for pre-emption priority, 153 | 0 bit for subpriority */ 154 | #endif 155 | /* USER CODE BEGIN Private defines */ 156 | #define NOP5 __NOP();__NOP();__NOP();__NOP();__NOP(); 157 | #define NOP10 NOP5 NOP5 158 | /* USER CODE END Private defines */ 159 | 160 | #ifdef __cplusplus 161 | } 162 | #endif 163 | 164 | #endif /* __MAIN_H */ 165 | 166 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 167 | -------------------------------------------------------------------------------- /Inc/Backup/stm32_assert.h.bak: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_assert.h 4 | * @brief STM32 assert file. 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | *

© Copyright (c) 2020 STMicroelectronics. 9 | * All rights reserved.

10 | * 11 | * This software component is licensed by ST under BSD 3-Clause license, 12 | * the "License"; You may not use this file except in compliance with the 13 | * License. You may obtain a copy of the License at: 14 | * opensource.org/licenses/BSD-3-Clause 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __STM32_ASSERT_H 21 | #define __STM32_ASSERT_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Exported types ------------------------------------------------------------*/ 28 | /* Exported constants --------------------------------------------------------*/ 29 | /* Includes ------------------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | #ifdef USE_FULL_ASSERT 32 | /** 33 | * @brief The assert_param macro is used for function's parameters check. 34 | * @param expr: If expr is false, it calls assert_failed function 35 | * which reports the name of the source file and the source 36 | * line number of the call that failed. 37 | * If expr is true, it returns no value. 38 | * @retval None 39 | */ 40 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 41 | /* Exported functions ------------------------------------------------------- */ 42 | void assert_failed(uint8_t* file, uint32_t line); 43 | #else 44 | #define assert_param(expr) ((void)0U) 45 | #endif /* USE_FULL_ASSERT */ 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* __STM32_ASSERT_H */ 52 | 53 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 54 | -------------------------------------------------------------------------------- /Inc/Backup/stm32f4xx_it.h.bak: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

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

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

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __USB_DEVICE__H__ 24 | #define __USB_DEVICE__H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx.h" 32 | #include "stm32f4xx_hal.h" 33 | #include "usbd_def.h" 34 | 35 | /* USER CODE BEGIN INCLUDE */ 36 | 37 | /* USER CODE END INCLUDE */ 38 | 39 | /** @addtogroup USBD_OTG_DRIVER 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBD_DEVICE USBD_DEVICE 44 | * @brief Device file for Usb otg low level driver. 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables 49 | * @brief Public variables. 50 | * @{ 51 | */ 52 | 53 | /* Private variables ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN PV */ 55 | 56 | /* USER CODE END PV */ 57 | 58 | /* Private function prototypes -----------------------------------------------*/ 59 | /* USER CODE BEGIN PFP */ 60 | 61 | /* USER CODE END PFP */ 62 | 63 | /* 64 | * -- Insert your variables declaration here -- 65 | */ 66 | /* USER CODE BEGIN VARIABLES */ 67 | 68 | /* USER CODE END VARIABLES */ 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype 74 | * @brief Declaration of public functions for Usb device. 75 | * @{ 76 | */ 77 | 78 | /** USB Device initialization function. */ 79 | void MX_USB_DEVICE_Init(void); 80 | 81 | /* 82 | * -- Insert functions declaration here -- 83 | */ 84 | /* USER CODE BEGIN FD */ 85 | 86 | /* USER CODE END FD */ 87 | /** 88 | * @} 89 | */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* __USB_DEVICE__H__ */ 104 | 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /Inc/Backup/usbd_conf.h.bak: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_conf.h 5 | * @version : v1.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __USBD_CONF__H__ 24 | #define __USBD_CONF__H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include 32 | #include 33 | #include 34 | #include "main.h" 35 | #include "stm32f4xx.h" 36 | #include "stm32f4xx_hal.h" 37 | 38 | /* USER CODE BEGIN INCLUDE */ 39 | 40 | /* USER CODE END INCLUDE */ 41 | 42 | /** @addtogroup USBD_OTG_DRIVER 43 | * @brief Driver for Usb device. 44 | * @{ 45 | */ 46 | 47 | /** @defgroup USBD_CONF USBD_CONF 48 | * @brief Configuration file for Usb otg low level driver. 49 | * @{ 50 | */ 51 | 52 | /** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables 53 | * @brief Public variables. 54 | * @{ 55 | */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines 62 | * @brief Defines for configuration of the Usb device. 63 | * @{ 64 | */ 65 | 66 | /*---------- -----------*/ 67 | #define USBD_MAX_NUM_INTERFACES 1U 68 | /*---------- -----------*/ 69 | #define USBD_MAX_NUM_CONFIGURATION 1U 70 | /*---------- -----------*/ 71 | #define USBD_MAX_STR_DESC_SIZ 512U 72 | /*---------- -----------*/ 73 | #define USBD_SUPPORT_USER_STRING 0U 74 | /*---------- -----------*/ 75 | #define USBD_DEBUG_LEVEL 0U 76 | /*---------- -----------*/ 77 | #define USBD_LPM_ENABLED 0U 78 | /*---------- -----------*/ 79 | #define USBD_SELF_POWERED 1U 80 | /*---------- -----------*/ 81 | #define MSC_MEDIA_PACKET 512U 82 | 83 | /****************************************/ 84 | /* #define for FS and HS identification */ 85 | #define DEVICE_FS 0 86 | #define DEVICE_HS 1 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros 93 | * @brief Aliases. 94 | * @{ 95 | */ 96 | 97 | /* Memory management macros */ 98 | 99 | /** Alias for memory allocation. */ 100 | #define USBD_malloc malloc 101 | 102 | /** Alias for memory release. */ 103 | #define USBD_free free 104 | 105 | /** Alias for memory set. */ 106 | #define USBD_memset memset 107 | 108 | /** Alias for memory copy. */ 109 | #define USBD_memcpy memcpy 110 | 111 | /** Alias for delay. */ 112 | #define USBD_Delay HAL_Delay 113 | 114 | /* DEBUG macros */ 115 | 116 | #if (USBD_DEBUG_LEVEL > 0) 117 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 118 | printf("\n"); 119 | #else 120 | #define USBD_UsrLog(...) 121 | #endif 122 | 123 | #if (USBD_DEBUG_LEVEL > 1) 124 | 125 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 126 | printf(__VA_ARGS__);\ 127 | printf("\n"); 128 | #else 129 | #define USBD_ErrLog(...) 130 | #endif 131 | 132 | #if (USBD_DEBUG_LEVEL > 2) 133 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 134 | printf(__VA_ARGS__);\ 135 | printf("\n"); 136 | #else 137 | #define USBD_DbgLog(...) 138 | #endif 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types 145 | * @brief Types. 146 | * @{ 147 | */ 148 | 149 | /** 150 | * @} 151 | */ 152 | 153 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype 154 | * @brief Declaration of public functions for Usb device. 155 | * @{ 156 | */ 157 | 158 | /* Exported functions -------------------------------------------------------*/ 159 | 160 | /** 161 | * @} 162 | */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | /** 169 | * @} 170 | */ 171 | 172 | #ifdef __cplusplus 173 | } 174 | #endif 175 | 176 | #endif /* __USBD_CONF__H__ */ 177 | 178 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 179 | -------------------------------------------------------------------------------- /Inc/Backup/usbd_desc.h.bak: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_desc.c 5 | * @version : v1.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __USBD_DESC__C__ 23 | #define __USBD_DESC__C__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usbd_def.h" 31 | 32 | /* USER CODE BEGIN INCLUDE */ 33 | 34 | /* USER CODE END INCLUDE */ 35 | 36 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USBD_DESC USBD_DESC 41 | * @brief Usb device descriptors module. 42 | * @{ 43 | */ 44 | 45 | /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants 46 | * @brief Constants. 47 | * @{ 48 | */ 49 | #define DEVICE_ID1 (UID_BASE) 50 | #define DEVICE_ID2 (UID_BASE + 0x4) 51 | #define DEVICE_ID3 (UID_BASE + 0x8) 52 | 53 | #define USB_SIZ_STRING_SERIAL 0x1A 54 | 55 | /* USER CODE BEGIN EXPORTED_CONSTANTS */ 56 | 57 | /* USER CODE END EXPORTED_CONSTANTS */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines 64 | * @brief Defines. 65 | * @{ 66 | */ 67 | 68 | /* USER CODE BEGIN EXPORTED_DEFINES */ 69 | 70 | /* USER CODE END EXPORTED_DEFINES */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions 77 | * @brief Types. 78 | * @{ 79 | */ 80 | 81 | /* USER CODE BEGIN EXPORTED_TYPES */ 82 | 83 | /* USER CODE END EXPORTED_TYPES */ 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros 90 | * @brief Aliases. 91 | * @{ 92 | */ 93 | 94 | /* USER CODE BEGIN EXPORTED_MACRO */ 95 | 96 | /* USER CODE END EXPORTED_MACRO */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables 103 | * @brief Public variables. 104 | * @{ 105 | */ 106 | 107 | /** Descriptor for the Usb device. */ 108 | extern USBD_DescriptorsTypeDef FS_Desc; 109 | 110 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 111 | 112 | /* USER CODE END EXPORTED_VARIABLES */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype 119 | * @brief Public functions declaration. 120 | * @{ 121 | */ 122 | 123 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 124 | 125 | /* USER CODE END EXPORTED_FUNCTIONS */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __USBD_DESC__C__ */ 144 | 145 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 146 | -------------------------------------------------------------------------------- /Inc/Backup/usbd_storage_if.h.bak: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_storage_if.h 5 | * @version : v1.0_Cube 6 | * @brief : Header for usbd_storage_if.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __USBD_STORAGE_IF_H__ 24 | #define __USBD_STORAGE_IF_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usbd_msc.h" 32 | 33 | /* USER CODE BEGIN INCLUDE */ 34 | 35 | /* USER CODE END INCLUDE */ 36 | 37 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 38 | * @brief For Usb device. 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBD_STORAGE USBD_STORAGE 43 | * @brief Header file for the usb_storage_if.c file 44 | * @{ 45 | */ 46 | 47 | /** @defgroup USBD_STORAGE_Exported_Defines USBD_STORAGE_Exported_Defines 48 | * @brief Defines. 49 | * @{ 50 | */ 51 | 52 | /* USER CODE BEGIN EXPORTED_DEFINES */ 53 | 54 | /* USER CODE END EXPORTED_DEFINES */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup USBD_STORAGE_Exported_Types USBD_STORAGE_Exported_Types 61 | * @brief Types. 62 | * @{ 63 | */ 64 | 65 | /* USER CODE BEGIN EXPORTED_TYPES */ 66 | 67 | /* USER CODE END EXPORTED_TYPES */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup USBD_STORAGE_Exported_Macros USBD_STORAGE_Exported_Macros 74 | * @brief Aliases. 75 | * @{ 76 | */ 77 | 78 | /* USER CODE BEGIN EXPORTED_MACRO */ 79 | 80 | /* USER CODE END EXPORTED_MACRO */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup USBD_STORAGE_Exported_Variables USBD_STORAGE_Exported_Variables 87 | * @brief Public variables. 88 | * @{ 89 | */ 90 | 91 | /** STORAGE Interface callback. */ 92 | extern USBD_StorageTypeDef USBD_Storage_Interface_fops_FS; 93 | 94 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 95 | 96 | /* USER CODE END EXPORTED_VARIABLES */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** @defgroup USBD_STORAGE_Exported_FunctionsPrototype USBD_STORAGE_Exported_FunctionsPrototype 103 | * @brief Public functions declaration. 104 | * @{ 105 | */ 106 | 107 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 108 | 109 | /* USER CODE END EXPORTED_FUNCTIONS */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* __USBD_STORAGE_IF_H__ */ 128 | 129 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 130 | -------------------------------------------------------------------------------- /Inc/cartridge.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cartridge.h 3 | * 4 | * Created on: Jan 2, 2020 5 | * Author: andrju 6 | */ 7 | 8 | #ifndef INC_CARTRIDGE_H_ 9 | #define INC_CARTRIDGE_H_ 10 | 11 | #include 12 | 13 | #define RAM_SIZE (128*1024) 14 | #define RAM1_SIZE (96*1024) 15 | #define RAM2_SIZE (32*1024) 16 | 17 | #define ROM_SAVE_ADDR 0x08020000 18 | #define SRAM_SAVE_ADDR 0x080E0000 19 | 20 | #define ROM_MAX_SIZE (SRAM_SAVE_ADDR-ROM_SAVE_ADDR) 21 | #define ROM_MAX_BANK (ROM_MAX_SIZE/(16*1024)-1) 22 | 23 | typedef struct{ 24 | 25 | const uint8_t *rom; 26 | uint8_t *ram; 27 | int rom_bank; 28 | int ram_bank; 29 | 30 | }cartridge_t; 31 | 32 | extern cartridge_t cartridge; 33 | extern uint8_t sram[RAM1_SIZE]; 34 | extern uint8_t sram2[RAM2_SIZE]; 35 | 36 | void load_ram(void); 37 | void save_ram(void); 38 | void erase_ram(void); 39 | void erase_rom(void); 40 | 41 | #endif /* INC_CARTRIDGE_H_ */ 42 | -------------------------------------------------------------------------------- /Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal.h" 32 | #include "stm32f4xx_ll_rcc.h" 33 | #include "stm32f4xx_ll_bus.h" 34 | #include "stm32f4xx_ll_system.h" 35 | #include "stm32f4xx_ll_exti.h" 36 | #include "stm32f4xx_ll_cortex.h" 37 | #include "stm32f4xx_ll_utils.h" 38 | #include "stm32f4xx_ll_pwr.h" 39 | #include "stm32f4xx_ll_dma.h" 40 | #include "stm32f4xx.h" 41 | #include "stm32f4xx_ll_gpio.h" 42 | 43 | /* Private includes ----------------------------------------------------------*/ 44 | /* USER CODE BEGIN Includes */ 45 | 46 | /* USER CODE END Includes */ 47 | 48 | /* Exported types ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN ET */ 50 | 51 | /* USER CODE END ET */ 52 | 53 | /* Exported constants --------------------------------------------------------*/ 54 | /* USER CODE BEGIN EC */ 55 | 56 | /* USER CODE END EC */ 57 | 58 | /* Exported macro ------------------------------------------------------------*/ 59 | /* USER CODE BEGIN EM */ 60 | 61 | /* USER CODE END EM */ 62 | 63 | /* Exported functions prototypes ---------------------------------------------*/ 64 | void Error_Handler(void); 65 | 66 | /* USER CODE BEGIN EFP */ 67 | 68 | /* USER CODE END EFP */ 69 | 70 | /* Private defines -----------------------------------------------------------*/ 71 | #define VBUS_Pin LL_GPIO_PIN_13 72 | #define VBUS_GPIO_Port GPIOC 73 | #define VGB_Pin LL_GPIO_PIN_14 74 | #define VGB_GPIO_Port GPIOC 75 | #define D0_Pin LL_GPIO_PIN_0 76 | #define D0_GPIO_Port GPIOC 77 | #define D1_Pin LL_GPIO_PIN_1 78 | #define D1_GPIO_Port GPIOC 79 | #define D2_Pin LL_GPIO_PIN_2 80 | #define D2_GPIO_Port GPIOC 81 | #define D3_Pin LL_GPIO_PIN_3 82 | #define D3_GPIO_Port GPIOC 83 | #define D4_Pin LL_GPIO_PIN_4 84 | #define D4_GPIO_Port GPIOC 85 | #define D5_Pin LL_GPIO_PIN_5 86 | #define D5_GPIO_Port GPIOC 87 | #define A0_Pin LL_GPIO_PIN_0 88 | #define A0_GPIO_Port GPIOB 89 | #define A1_Pin LL_GPIO_PIN_1 90 | #define A1_GPIO_Port GPIOB 91 | #define A2_Pin LL_GPIO_PIN_2 92 | #define A2_GPIO_Port GPIOB 93 | #define A10_Pin LL_GPIO_PIN_10 94 | #define A10_GPIO_Port GPIOB 95 | #define A11_Pin LL_GPIO_PIN_11 96 | #define A11_GPIO_Port GPIOB 97 | #define A12_Pin LL_GPIO_PIN_12 98 | #define A12_GPIO_Port GPIOB 99 | #define A13_Pin LL_GPIO_PIN_13 100 | #define A13_GPIO_Port GPIOB 101 | #define A14_Pin LL_GPIO_PIN_14 102 | #define A14_GPIO_Port GPIOB 103 | #define A15_Pin LL_GPIO_PIN_15 104 | #define A15_GPIO_Port GPIOB 105 | #define D6_Pin LL_GPIO_PIN_6 106 | #define D6_GPIO_Port GPIOC 107 | #define D7_Pin LL_GPIO_PIN_7 108 | #define D7_GPIO_Port GPIOC 109 | #define CLK_Pin LL_GPIO_PIN_8 110 | #define CLK_GPIO_Port GPIOC 111 | #define WR_Pin LL_GPIO_PIN_9 112 | #define WR_GPIO_Port GPIOC 113 | #define LED3_Pin LL_GPIO_PIN_8 114 | #define LED3_GPIO_Port GPIOA 115 | #define LED2_Pin LL_GPIO_PIN_9 116 | #define LED2_GPIO_Port GPIOA 117 | #define LED1_Pin LL_GPIO_PIN_10 118 | #define LED1_GPIO_Port GPIOA 119 | #define RD_Pin LL_GPIO_PIN_10 120 | #define RD_GPIO_Port GPIOC 121 | #define CS_Pin LL_GPIO_PIN_11 122 | #define CS_GPIO_Port GPIOC 123 | #define RST_Pin LL_GPIO_PIN_12 124 | #define RST_GPIO_Port GPIOC 125 | #define BUTTON_Pin LL_GPIO_PIN_2 126 | #define BUTTON_GPIO_Port GPIOD 127 | #define BUTTON_EXTI_IRQn EXTI2_IRQn 128 | #define A3_Pin LL_GPIO_PIN_3 129 | #define A3_GPIO_Port GPIOB 130 | #define A4_Pin LL_GPIO_PIN_4 131 | #define A4_GPIO_Port GPIOB 132 | #define A5_Pin LL_GPIO_PIN_5 133 | #define A5_GPIO_Port GPIOB 134 | #define A6_Pin LL_GPIO_PIN_6 135 | #define A6_GPIO_Port GPIOB 136 | #define A7_Pin LL_GPIO_PIN_7 137 | #define A7_GPIO_Port GPIOB 138 | #define A8_Pin LL_GPIO_PIN_8 139 | #define A8_GPIO_Port GPIOB 140 | #define A9_Pin LL_GPIO_PIN_9 141 | #define A9_GPIO_Port GPIOB 142 | /* USER CODE BEGIN Private defines */ 143 | #define NOP5 __NOP();__NOP();__NOP();__NOP();__NOP(); 144 | #define NOP10 NOP5 NOP5 145 | /* USER CODE END Private defines */ 146 | 147 | #ifdef __cplusplus 148 | } 149 | #endif 150 | 151 | #endif /* __MAIN_H */ 152 | 153 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 154 | -------------------------------------------------------------------------------- /Inc/stm32_assert.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_assert.h 4 | * @brief STM32 assert file. 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | *

© Copyright (c) 2020 STMicroelectronics. 9 | * All rights reserved.

10 | * 11 | * This software component is licensed by ST under Ultimate Liberty license 12 | * SLA0044, the "License"; You may not use this file except in compliance with 13 | * the License. You may obtain a copy of the License at: 14 | * www.st.com/SLA0044 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __STM32_ASSERT_H 21 | #define __STM32_ASSERT_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Exported types ------------------------------------------------------------*/ 28 | /* Exported constants --------------------------------------------------------*/ 29 | /* Includes ------------------------------------------------------------------*/ 30 | /* Exported macro ------------------------------------------------------------*/ 31 | #ifdef USE_FULL_ASSERT 32 | /** 33 | * @brief The assert_param macro is used for function's parameters check. 34 | * @param expr: If expr is false, it calls assert_failed function 35 | * which reports the name of the source file and the source 36 | * line number of the call that failed. 37 | * If expr is true, it returns no value. 38 | * @retval None 39 | */ 40 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 41 | /* Exported functions ------------------------------------------------------- */ 42 | void assert_failed(uint8_t* file, uint32_t line); 43 | #else 44 | #define assert_param(expr) ((void)0U) 45 | #endif /* USE_FULL_ASSERT */ 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* __STM32_ASSERT_H */ 52 | 53 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 54 | -------------------------------------------------------------------------------- /Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

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

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

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __USB_DEVICE__H__ 24 | #define __USB_DEVICE__H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx.h" 32 | #include "stm32f4xx_hal.h" 33 | #include "usbd_def.h" 34 | 35 | /* USER CODE BEGIN INCLUDE */ 36 | 37 | /* USER CODE END INCLUDE */ 38 | 39 | /** @addtogroup USBD_OTG_DRIVER 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBD_DEVICE USBD_DEVICE 44 | * @brief Device file for Usb otg low level driver. 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables 49 | * @brief Public variables. 50 | * @{ 51 | */ 52 | 53 | /* Private variables ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN PV */ 55 | 56 | /* USER CODE END PV */ 57 | 58 | /* Private function prototypes -----------------------------------------------*/ 59 | /* USER CODE BEGIN PFP */ 60 | 61 | /* USER CODE END PFP */ 62 | 63 | /* 64 | * -- Insert your variables declaration here -- 65 | */ 66 | /* USER CODE BEGIN VARIABLES */ 67 | 68 | /* USER CODE END VARIABLES */ 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype 74 | * @brief Declaration of public functions for Usb device. 75 | * @{ 76 | */ 77 | 78 | /** USB Device initialization function. */ 79 | void MX_USB_DEVICE_Init(void); 80 | 81 | /* 82 | * -- Insert functions declaration here -- 83 | */ 84 | /* USER CODE BEGIN FD */ 85 | 86 | /* USER CODE END FD */ 87 | /** 88 | * @} 89 | */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | #ifdef __cplusplus 100 | } 101 | #endif 102 | 103 | #endif /* __USB_DEVICE__H__ */ 104 | 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /Inc/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_conf.h 5 | * @version : v1.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __USBD_CONF__H__ 24 | #define __USBD_CONF__H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include 32 | #include 33 | #include 34 | #include "main.h" 35 | #include "stm32f4xx.h" 36 | #include "stm32f4xx_hal.h" 37 | 38 | /* USER CODE BEGIN INCLUDE */ 39 | 40 | /* USER CODE END INCLUDE */ 41 | 42 | /** @addtogroup USBD_OTG_DRIVER 43 | * @brief Driver for Usb device. 44 | * @{ 45 | */ 46 | 47 | /** @defgroup USBD_CONF USBD_CONF 48 | * @brief Configuration file for Usb otg low level driver. 49 | * @{ 50 | */ 51 | 52 | /** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables 53 | * @brief Public variables. 54 | * @{ 55 | */ 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | /** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines 62 | * @brief Defines for configuration of the Usb device. 63 | * @{ 64 | */ 65 | 66 | /*---------- -----------*/ 67 | #define USBD_MAX_NUM_INTERFACES 1U 68 | /*---------- -----------*/ 69 | #define USBD_MAX_NUM_CONFIGURATION 1U 70 | /*---------- -----------*/ 71 | #define USBD_MAX_STR_DESC_SIZ 512U 72 | /*---------- -----------*/ 73 | #define USBD_SUPPORT_USER_STRING 0U 74 | /*---------- -----------*/ 75 | #define USBD_DEBUG_LEVEL 0U 76 | /*---------- -----------*/ 77 | #define USBD_LPM_ENABLED 0U 78 | /*---------- -----------*/ 79 | #define USBD_SELF_POWERED 1U 80 | /*---------- -----------*/ 81 | #define MSC_MEDIA_PACKET 512U 82 | 83 | /****************************************/ 84 | /* #define for FS and HS identification */ 85 | #define DEVICE_FS 0 86 | #define DEVICE_HS 1 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros 93 | * @brief Aliases. 94 | * @{ 95 | */ 96 | 97 | /* Memory management macros */ 98 | 99 | /** Alias for memory allocation. */ 100 | #define USBD_malloc malloc 101 | 102 | /** Alias for memory release. */ 103 | #define USBD_free free 104 | 105 | /** Alias for memory set. */ 106 | #define USBD_memset memset 107 | 108 | /** Alias for memory copy. */ 109 | #define USBD_memcpy memcpy 110 | 111 | /** Alias for delay. */ 112 | #define USBD_Delay HAL_Delay 113 | 114 | /* DEBUG macros */ 115 | 116 | #if (USBD_DEBUG_LEVEL > 0) 117 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 118 | printf("\n"); 119 | #else 120 | #define USBD_UsrLog(...) 121 | #endif 122 | 123 | #if (USBD_DEBUG_LEVEL > 1) 124 | 125 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 126 | printf(__VA_ARGS__);\ 127 | printf("\n"); 128 | #else 129 | #define USBD_ErrLog(...) 130 | #endif 131 | 132 | #if (USBD_DEBUG_LEVEL > 2) 133 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 134 | printf(__VA_ARGS__);\ 135 | printf("\n"); 136 | #else 137 | #define USBD_DbgLog(...) 138 | #endif 139 | 140 | /** 141 | * @} 142 | */ 143 | 144 | /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types 145 | * @brief Types. 146 | * @{ 147 | */ 148 | 149 | /** 150 | * @} 151 | */ 152 | 153 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype 154 | * @brief Declaration of public functions for Usb device. 155 | * @{ 156 | */ 157 | 158 | /* Exported functions -------------------------------------------------------*/ 159 | 160 | /** 161 | * @} 162 | */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | /** 169 | * @} 170 | */ 171 | 172 | #ifdef __cplusplus 173 | } 174 | #endif 175 | 176 | #endif /* __USBD_CONF__H__ */ 177 | 178 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 179 | -------------------------------------------------------------------------------- /Inc/usbd_desc.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_desc.c 5 | * @version : v1.0_Cube 6 | * @brief : Header for usbd_conf.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __USBD_DESC__C__ 23 | #define __USBD_DESC__C__ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "usbd_def.h" 31 | 32 | /* USER CODE BEGIN INCLUDE */ 33 | 34 | /* USER CODE END INCLUDE */ 35 | 36 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USBD_DESC USBD_DESC 41 | * @brief Usb device descriptors module. 42 | * @{ 43 | */ 44 | 45 | /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants 46 | * @brief Constants. 47 | * @{ 48 | */ 49 | #define DEVICE_ID1 (UID_BASE) 50 | #define DEVICE_ID2 (UID_BASE + 0x4) 51 | #define DEVICE_ID3 (UID_BASE + 0x8) 52 | 53 | #define USB_SIZ_STRING_SERIAL 0x1A 54 | 55 | /* USER CODE BEGIN EXPORTED_CONSTANTS */ 56 | 57 | /* USER CODE END EXPORTED_CONSTANTS */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines 64 | * @brief Defines. 65 | * @{ 66 | */ 67 | 68 | /* USER CODE BEGIN EXPORTED_DEFINES */ 69 | 70 | /* USER CODE END EXPORTED_DEFINES */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions 77 | * @brief Types. 78 | * @{ 79 | */ 80 | 81 | /* USER CODE BEGIN EXPORTED_TYPES */ 82 | 83 | /* USER CODE END EXPORTED_TYPES */ 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros 90 | * @brief Aliases. 91 | * @{ 92 | */ 93 | 94 | /* USER CODE BEGIN EXPORTED_MACRO */ 95 | 96 | /* USER CODE END EXPORTED_MACRO */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables 103 | * @brief Public variables. 104 | * @{ 105 | */ 106 | 107 | /** Descriptor for the Usb device. */ 108 | extern USBD_DescriptorsTypeDef FS_Desc; 109 | 110 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 111 | 112 | /* USER CODE END EXPORTED_VARIABLES */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype 119 | * @brief Public functions declaration. 120 | * @{ 121 | */ 122 | 123 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 124 | 125 | /* USER CODE END EXPORTED_FUNCTIONS */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __USBD_DESC__C__ */ 144 | 145 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 146 | -------------------------------------------------------------------------------- /Inc/usbd_storage_if.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_storage_if.h 5 | * @version : v1.0_Cube 6 | * @brief : Header for usbd_storage_if.c file. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __USBD_STORAGE_IF_H__ 24 | #define __USBD_STORAGE_IF_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usbd_msc.h" 32 | 33 | /* USER CODE BEGIN INCLUDE */ 34 | 35 | /* USER CODE END INCLUDE */ 36 | 37 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 38 | * @brief For Usb device. 39 | * @{ 40 | */ 41 | 42 | /** @defgroup USBD_STORAGE USBD_STORAGE 43 | * @brief Header file for the usb_storage_if.c file 44 | * @{ 45 | */ 46 | 47 | /** @defgroup USBD_STORAGE_Exported_Defines USBD_STORAGE_Exported_Defines 48 | * @brief Defines. 49 | * @{ 50 | */ 51 | 52 | /* USER CODE BEGIN EXPORTED_DEFINES */ 53 | 54 | /* USER CODE END EXPORTED_DEFINES */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | /** @defgroup USBD_STORAGE_Exported_Types USBD_STORAGE_Exported_Types 61 | * @brief Types. 62 | * @{ 63 | */ 64 | 65 | /* USER CODE BEGIN EXPORTED_TYPES */ 66 | 67 | /* USER CODE END EXPORTED_TYPES */ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup USBD_STORAGE_Exported_Macros USBD_STORAGE_Exported_Macros 74 | * @brief Aliases. 75 | * @{ 76 | */ 77 | 78 | /* USER CODE BEGIN EXPORTED_MACRO */ 79 | 80 | /* USER CODE END EXPORTED_MACRO */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup USBD_STORAGE_Exported_Variables USBD_STORAGE_Exported_Variables 87 | * @brief Public variables. 88 | * @{ 89 | */ 90 | 91 | /** STORAGE Interface callback. */ 92 | extern USBD_StorageTypeDef USBD_Storage_Interface_fops_FS; 93 | 94 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 95 | 96 | /* USER CODE END EXPORTED_VARIABLES */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /** @defgroup USBD_STORAGE_Exported_FunctionsPrototype USBD_STORAGE_Exported_FunctionsPrototype 103 | * @brief Public functions declaration. 104 | * @{ 105 | */ 106 | 107 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 108 | 109 | /* USER CODE END EXPORTED_FUNCTIONS */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /** 120 | * @} 121 | */ 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* __USBD_STORAGE_IF_H__ */ 128 | 129 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Andrzej Surowiec 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ########################################################################################################################## 2 | # File automatically-generated by tool: [projectgenerator] version: [3.4.0] date: [Thu Jan 02 23:25:25 CET 2020] 3 | ########################################################################################################################## 4 | 5 | # ------------------------------------------------ 6 | # Generic Makefile (based on gcc) 7 | # 8 | # ChangeLog : 9 | # 2017-02-10 - Several enhancements + project update mode 10 | # 2015-07-22 - first version 11 | # ------------------------------------------------ 12 | 13 | ###################################### 14 | # target 15 | ###################################### 16 | TARGET = gbcart-fast 17 | 18 | 19 | ###################################### 20 | # building variables 21 | ###################################### 22 | # debug build? 23 | DEBUG = 1 24 | # optimization 25 | OPT = -O3 26 | 27 | 28 | ####################################### 29 | # paths 30 | ####################################### 31 | # Build path 32 | BUILD_DIR = build 33 | 34 | ###################################### 35 | # source 36 | ###################################### 37 | # C sources 38 | C_SOURCES = \ 39 | Src/main.c \ 40 | Src/stm32f4xx_it.c \ 41 | Src/cartridge.c \ 42 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_gpio.c \ 43 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_rcc.c \ 44 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_utils.c \ 45 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_exti.c \ 46 | Src/system_stm32f4xx.c \ 47 | Src/usb_device.c \ 48 | Src/usbd_conf.c \ 49 | Src/usbd_desc.c \ 50 | Src/usbd_storage_if.c \ 51 | Src/stm32f4xx_hal_msp.c \ 52 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c \ 53 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c \ 54 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c \ 55 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c \ 56 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c \ 57 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c \ 58 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c \ 59 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c \ 60 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c \ 61 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c \ 62 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c \ 63 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c \ 64 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c \ 65 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c \ 66 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c \ 67 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c \ 68 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c \ 69 | Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c \ 70 | Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c \ 71 | Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c \ 72 | Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c \ 73 | Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c \ 74 | Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c \ 75 | Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_data.c \ 76 | Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c 77 | 78 | # ASM sources 79 | ASM_SOURCES = \ 80 | startup_stm32f405xx.s 81 | 82 | 83 | ####################################### 84 | # binaries 85 | ####################################### 86 | PREFIX = arm-none-eabi- 87 | # The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) 88 | # either it can be added to the PATH environment variable. 89 | ifdef GCC_PATH 90 | CC = $(GCC_PATH)/$(PREFIX)gcc 91 | AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp 92 | CP = $(GCC_PATH)/$(PREFIX)objcopy 93 | SZ = $(GCC_PATH)/$(PREFIX)size 94 | else 95 | CC = $(PREFIX)gcc 96 | AS = $(PREFIX)gcc -x assembler-with-cpp 97 | CP = $(PREFIX)objcopy 98 | SZ = $(PREFIX)size 99 | endif 100 | HEX = $(CP) -O ihex 101 | BIN = $(CP) -O binary -S 102 | 103 | ####################################### 104 | # CFLAGS 105 | ####################################### 106 | # cpu 107 | CPU = -mcpu=cortex-m4 108 | 109 | # fpu 110 | FPU = -mfpu=fpv4-sp-d16 111 | 112 | # float-abi 113 | FLOAT-ABI = -mfloat-abi=hard 114 | 115 | # mcu 116 | MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) 117 | 118 | # macros for gcc 119 | # AS defines 120 | AS_DEFS = 121 | 122 | # C defines 123 | C_DEFS = \ 124 | -DUSE_FULL_LL_DRIVER \ 125 | -DSTM32F405xx \ 126 | -DUSE_FULL_LL_DRIVER \ 127 | -DHSE_VALUE=8000000 \ 128 | -DHSE_STARTUP_TIMEOUT=100 \ 129 | -DLSE_STARTUP_TIMEOUT=5000 \ 130 | -DLSE_VALUE=32768 \ 131 | -DEXTERNAL_CLOCK_VALUE=12288000 \ 132 | -DHSI_VALUE=16000000 \ 133 | -DLSI_VALUE=32000 \ 134 | -DVDD_VALUE=3300 \ 135 | -DPREFETCH_ENABLE=1 \ 136 | -DINSTRUCTION_CACHE_ENABLE=1 \ 137 | -DDATA_CACHE_ENABLE=1 \ 138 | -DSTM32F405xx \ 139 | -DUSE_HAL_DRIVER 140 | 141 | 142 | # AS includes 143 | AS_INCLUDES = 144 | 145 | # C includes 146 | C_INCLUDES = \ 147 | -IInc \ 148 | -Irom \ 149 | -IDrivers/STM32F4xx_HAL_Driver/Inc \ 150 | -IDrivers/CMSIS/Device/ST/STM32F4xx/Include \ 151 | -IDrivers/CMSIS/Include \ 152 | -IDrivers/CMSIS/Include \ 153 | -IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \ 154 | -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc \ 155 | -IMiddlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc 156 | 157 | 158 | # compile gcc flags 159 | ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections 160 | 161 | CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections 162 | 163 | ifeq ($(DEBUG), 1) 164 | CFLAGS += -g -gdwarf-2 165 | endif 166 | 167 | 168 | # Generate dependency information 169 | CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" 170 | 171 | 172 | ####################################### 173 | # LDFLAGS 174 | ####################################### 175 | # link script 176 | LDSCRIPT = STM32F405RGTx_FLASH.ld 177 | 178 | # libraries 179 | LIBS = -lc -lm -lnosys 180 | LIBDIR = 181 | LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections 182 | 183 | # default action: build all 184 | all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin 185 | 186 | 187 | ####################################### 188 | # build the application 189 | ####################################### 190 | # list of objects 191 | OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) 192 | vpath %.c $(sort $(dir $(C_SOURCES))) 193 | # list of ASM program objects 194 | OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) 195 | vpath %.s $(sort $(dir $(ASM_SOURCES))) 196 | 197 | $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) 198 | $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ 199 | 200 | $(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) 201 | $(AS) -c $(CFLAGS) $< -o $@ 202 | 203 | $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile 204 | $(CC) $(OBJECTS) $(LDFLAGS) -o $@ 205 | $(SZ) $@ 206 | 207 | $(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) 208 | $(HEX) $< $@ 209 | 210 | $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) 211 | $(BIN) $< $@ 212 | 213 | $(BUILD_DIR): 214 | mkdir $@ 215 | 216 | ####################################### 217 | # clean up 218 | ####################################### 219 | clean: 220 | -rm -fR $(BUILD_DIR) 221 | 222 | ####################################### 223 | # dependencies 224 | ####################################### 225 | -include $(wildcard $(BUILD_DIR)/*.d) 226 | 227 | # *** EOF *** 228 | -------------------------------------------------------------------------------- /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 | * @brief Header for the usbd_msc.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_MSC_H 22 | #define __USBD_MSC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_msc_bot.h" 30 | #include "usbd_msc_scsi.h" 31 | #include "usbd_ioreq.h" 32 | 33 | /** @addtogroup USBD_MSC_BOT 34 | * @{ 35 | */ 36 | 37 | /** @defgroup USBD_MSC 38 | * @brief This file is the Header file for usbd_msc.c 39 | * @{ 40 | */ 41 | 42 | 43 | /** @defgroup USBD_BOT_Exported_Defines 44 | * @{ 45 | */ 46 | /* MSC Class Config */ 47 | #ifndef MSC_MEDIA_PACKET 48 | #define MSC_MEDIA_PACKET 512U 49 | #endif /* MSC_MEDIA_PACKET */ 50 | 51 | #define MSC_MAX_FS_PACKET 0x40U 52 | #define MSC_MAX_HS_PACKET 0x200U 53 | 54 | #define BOT_GET_MAX_LUN 0xFE 55 | #define BOT_RESET 0xFF 56 | #define USB_MSC_CONFIG_DESC_SIZ 32 57 | 58 | 59 | #define MSC_EPIN_ADDR 0x81U 60 | #define MSC_EPOUT_ADDR 0x01U 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup USB_CORE_Exported_Types 67 | * @{ 68 | */ 69 | typedef struct _USBD_STORAGE 70 | { 71 | int8_t (* Init) (uint8_t lun); 72 | int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint16_t *block_size); 73 | int8_t (* IsReady) (uint8_t lun); 74 | int8_t (* IsWriteProtected) (uint8_t lun); 75 | int8_t (* Read) (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); 76 | int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); 77 | int8_t (* GetMaxLun)(void); 78 | int8_t *pInquiry; 79 | 80 | }USBD_StorageTypeDef; 81 | 82 | 83 | typedef struct 84 | { 85 | uint32_t max_lun; 86 | uint32_t interface; 87 | uint8_t bot_state; 88 | uint8_t bot_status; 89 | uint16_t bot_data_length; 90 | uint8_t bot_data[MSC_MEDIA_PACKET]; 91 | USBD_MSC_BOT_CBWTypeDef cbw; 92 | USBD_MSC_BOT_CSWTypeDef csw; 93 | 94 | USBD_SCSI_SenseTypeDef scsi_sense [SENSE_LIST_DEEPTH]; 95 | uint8_t scsi_sense_head; 96 | uint8_t scsi_sense_tail; 97 | 98 | uint16_t scsi_blk_size; 99 | uint32_t scsi_blk_nbr; 100 | 101 | uint32_t scsi_blk_addr; 102 | uint32_t scsi_blk_len; 103 | } 104 | USBD_MSC_BOT_HandleTypeDef; 105 | 106 | /* Structure for MSC process */ 107 | extern USBD_ClassTypeDef USBD_MSC; 108 | #define USBD_MSC_CLASS &USBD_MSC 109 | 110 | uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev, 111 | USBD_StorageTypeDef *fops); 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | 124 | #endif /* __USBD_MSC_H */ 125 | /** 126 | * @} 127 | */ 128 | 129 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 130 | -------------------------------------------------------------------------------- /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 | * @brief Header for the usbd_msc_bot.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_MSC_BOT_H 22 | #define __USBD_MSC_BOT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_core.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | /** @defgroup MSC_BOT 36 | * @brief This file is the Header file for usbd_msc_bot.c 37 | * @{ 38 | */ 39 | 40 | 41 | /** @defgroup USBD_CORE_Exported_Defines 42 | * @{ 43 | */ 44 | #define USBD_BOT_IDLE 0U /* Idle state */ 45 | #define USBD_BOT_DATA_OUT 1U /* Data Out state */ 46 | #define USBD_BOT_DATA_IN 2U /* Data In state */ 47 | #define USBD_BOT_LAST_DATA_IN 3U /* Last Data In Last */ 48 | #define USBD_BOT_SEND_DATA 4U /* Send Immediate data */ 49 | #define USBD_BOT_NO_DATA 5U /* No data Stage */ 50 | 51 | #define USBD_BOT_CBW_SIGNATURE 0x43425355U 52 | #define USBD_BOT_CSW_SIGNATURE 0x53425355U 53 | #define USBD_BOT_CBW_LENGTH 31U 54 | #define USBD_BOT_CSW_LENGTH 13U 55 | #define USBD_BOT_MAX_DATA 256U 56 | 57 | /* CSW Status Definitions */ 58 | #define USBD_CSW_CMD_PASSED 0x00U 59 | #define USBD_CSW_CMD_FAILED 0x01U 60 | #define USBD_CSW_PHASE_ERROR 0x02U 61 | 62 | /* BOT Status */ 63 | #define USBD_BOT_STATUS_NORMAL 0U 64 | #define USBD_BOT_STATUS_RECOVERY 1U 65 | #define USBD_BOT_STATUS_ERROR 2U 66 | 67 | 68 | #define USBD_DIR_IN 0U 69 | #define USBD_DIR_OUT 1U 70 | #define USBD_BOTH_DIR 2U 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup MSC_CORE_Private_TypesDefinitions 77 | * @{ 78 | */ 79 | 80 | typedef struct 81 | { 82 | uint32_t dSignature; 83 | uint32_t dTag; 84 | uint32_t dDataLength; 85 | uint8_t bmFlags; 86 | uint8_t bLUN; 87 | uint8_t bCBLength; 88 | uint8_t CB[16]; 89 | uint8_t ReservedForAlign; 90 | } 91 | USBD_MSC_BOT_CBWTypeDef; 92 | 93 | 94 | typedef struct 95 | { 96 | uint32_t dSignature; 97 | uint32_t dTag; 98 | uint32_t dDataResidue; 99 | uint8_t bStatus; 100 | uint8_t ReservedForAlign[3]; 101 | } 102 | USBD_MSC_BOT_CSWTypeDef; 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | 109 | /** @defgroup USBD_CORE_Exported_Types 110 | * @{ 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | /** @defgroup USBD_CORE_Exported_FunctionsPrototypes 117 | * @{ 118 | */ 119 | void MSC_BOT_Init (USBD_HandleTypeDef *pdev); 120 | void MSC_BOT_Reset (USBD_HandleTypeDef *pdev); 121 | void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev); 122 | void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev, 123 | uint8_t epnum); 124 | 125 | void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev, 126 | uint8_t epnum); 127 | 128 | void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev, 129 | uint8_t CSW_Status); 130 | 131 | void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev, 132 | uint8_t epnum); 133 | /** 134 | * @} 135 | */ 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif /* __USBD_MSC_BOT_H */ 142 | /** 143 | * @} 144 | */ 145 | 146 | /** 147 | * @} 148 | */ 149 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 150 | 151 | -------------------------------------------------------------------------------- /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 | * @brief Header for the usbd_msc_data.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_MSC_DATA_H 22 | #define __USBD_MSC_DATA_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_conf.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | /** @defgroup USB_INFO 36 | * @brief general defines for the usb device library file 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USB_INFO_Exported_Defines 41 | * @{ 42 | */ 43 | #define MODE_SENSE6_LEN 8U 44 | #define MODE_SENSE10_LEN 8U 45 | #define LENGTH_INQUIRY_PAGE00 7U 46 | #define LENGTH_FORMAT_CAPACITIES 20U 47 | 48 | /** 49 | * @} 50 | */ 51 | 52 | 53 | /** @defgroup USBD_INFO_Exported_TypesDefinitions 54 | * @{ 55 | */ 56 | /** 57 | * @} 58 | */ 59 | 60 | 61 | 62 | /** @defgroup USBD_INFO_Exported_Macros 63 | * @{ 64 | */ 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /** @defgroup USBD_INFO_Exported_Variables 71 | * @{ 72 | */ 73 | extern const uint8_t MSC_Page00_Inquiry_Data[]; 74 | extern const uint8_t MSC_Mode_Sense6_data[]; 75 | extern const uint8_t MSC_Mode_Sense10_data[] ; 76 | 77 | /** 78 | * @} 79 | */ 80 | 81 | /** @defgroup USBD_INFO_Exported_FunctionsPrototype 82 | * @{ 83 | */ 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | #endif /* __USBD_MSC_DATA_H */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** 100 | * @} 101 | */ 102 | 103 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 104 | -------------------------------------------------------------------------------- /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 | * @brief Header for the usbd_msc_scsi.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_MSC_SCSI_H 22 | #define __USBD_MSC_SCSI_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | /** @defgroup USBD_SCSI 36 | * @brief header file for the storage disk file 37 | * @{ 38 | */ 39 | 40 | /** @defgroup USBD_SCSI_Exported_Defines 41 | * @{ 42 | */ 43 | 44 | #define SENSE_LIST_DEEPTH 4U 45 | 46 | /* SCSI Commands */ 47 | #define SCSI_FORMAT_UNIT 0x04U 48 | #define SCSI_INQUIRY 0x12U 49 | #define SCSI_MODE_SELECT6 0x15U 50 | #define SCSI_MODE_SELECT10 0x55U 51 | #define SCSI_MODE_SENSE6 0x1AU 52 | #define SCSI_MODE_SENSE10 0x5AU 53 | #define SCSI_ALLOW_MEDIUM_REMOVAL 0x1EU 54 | #define SCSI_READ6 0x08U 55 | #define SCSI_READ10 0x28U 56 | #define SCSI_READ12 0xA8U 57 | #define SCSI_READ16 0x88U 58 | 59 | #define SCSI_READ_CAPACITY10 0x25U 60 | #define SCSI_READ_CAPACITY16 0x9EU 61 | 62 | #define SCSI_REQUEST_SENSE 0x03U 63 | #define SCSI_START_STOP_UNIT 0x1BU 64 | #define SCSI_TEST_UNIT_READY 0x00U 65 | #define SCSI_WRITE6 0x0AU 66 | #define SCSI_WRITE10 0x2AU 67 | #define SCSI_WRITE12 0xAAU 68 | #define SCSI_WRITE16 0x8AU 69 | 70 | #define SCSI_VERIFY10 0x2FU 71 | #define SCSI_VERIFY12 0xAFU 72 | #define SCSI_VERIFY16 0x8FU 73 | 74 | #define SCSI_SEND_DIAGNOSTIC 0x1DU 75 | #define SCSI_READ_FORMAT_CAPACITIES 0x23U 76 | 77 | #define NO_SENSE 0U 78 | #define RECOVERED_ERROR 1U 79 | #define NOT_READY 2U 80 | #define MEDIUM_ERROR 3U 81 | #define HARDWARE_ERROR 4U 82 | #define ILLEGAL_REQUEST 5U 83 | #define UNIT_ATTENTION 6U 84 | #define DATA_PROTECT 7U 85 | #define BLANK_CHECK 8U 86 | #define VENDOR_SPECIFIC 9U 87 | #define COPY_ABORTED 10U 88 | #define ABORTED_COMMAND 11U 89 | #define VOLUME_OVERFLOW 13U 90 | #define MISCOMPARE 14U 91 | 92 | 93 | #define INVALID_CDB 0x20U 94 | #define INVALID_FIELED_IN_COMMAND 0x24U 95 | #define PARAMETER_LIST_LENGTH_ERROR 0x1AU 96 | #define INVALID_FIELD_IN_PARAMETER_LIST 0x26U 97 | #define ADDRESS_OUT_OF_RANGE 0x21U 98 | #define MEDIUM_NOT_PRESENT 0x3AU 99 | #define MEDIUM_HAVE_CHANGED 0x28U 100 | #define WRITE_PROTECTED 0x27U 101 | #define UNRECOVERED_READ_ERROR 0x11U 102 | #define WRITE_FAULT 0x03U 103 | 104 | #define READ_FORMAT_CAPACITY_DATA_LEN 0x0CU 105 | #define READ_CAPACITY10_DATA_LEN 0x08U 106 | #define MODE_SENSE10_DATA_LEN 0x08U 107 | #define MODE_SENSE6_DATA_LEN 0x04U 108 | #define REQUEST_SENSE_DATA_LEN 0x12U 109 | #define STANDARD_INQUIRY_DATA_LEN 0x24U 110 | #define BLKVFY 0x04U 111 | 112 | extern uint8_t Page00_Inquiry_Data[]; 113 | extern uint8_t Standard_Inquiry_Data[]; 114 | extern uint8_t Standard_Inquiry_Data2[]; 115 | extern uint8_t Mode_Sense6_data[]; 116 | extern uint8_t Mode_Sense10_data[]; 117 | extern uint8_t Scsi_Sense_Data[]; 118 | extern uint8_t ReadCapacity10_Data[]; 119 | extern uint8_t ReadFormatCapacity_Data []; 120 | /** 121 | * @} 122 | */ 123 | 124 | 125 | /** @defgroup USBD_SCSI_Exported_TypesDefinitions 126 | * @{ 127 | */ 128 | 129 | typedef struct _SENSE_ITEM { 130 | char Skey; 131 | union { 132 | struct _ASCs { 133 | char ASC; 134 | char ASCQ; 135 | }b; 136 | uint8_t ASC; 137 | char *pData; 138 | } w; 139 | } USBD_SCSI_SenseTypeDef; 140 | /** 141 | * @} 142 | */ 143 | 144 | /** @defgroup USBD_SCSI_Exported_Macros 145 | * @{ 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** @defgroup USBD_SCSI_Exported_Variables 153 | * @{ 154 | */ 155 | 156 | /** 157 | * @} 158 | */ 159 | /** @defgroup USBD_SCSI_Exported_FunctionsPrototype 160 | * @{ 161 | */ 162 | int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd); 163 | 164 | void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, 165 | uint8_t ASC); 166 | 167 | /** 168 | * @} 169 | */ 170 | 171 | #ifdef __cplusplus 172 | } 173 | #endif 174 | 175 | #endif /* __USBD_MSC_SCSI_H */ 176 | /** 177 | * @} 178 | */ 179 | 180 | /** 181 | * @} 182 | */ 183 | 184 | /** 185 | * @} 186 | */ 187 | 188 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 189 | 190 | -------------------------------------------------------------------------------- /Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc_bot.c 4 | * @author MCD Application Team 5 | * @brief This file provides all the BOT protocol core functions. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* BSPDependencies 21 | - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" 22 | - "stm32xxxxx_{eval}{discovery}_io.c" 23 | - "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" 24 | EndBSPDependencies */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "usbd_msc_bot.h" 28 | #include "usbd_msc.h" 29 | #include "usbd_msc_scsi.h" 30 | #include "usbd_ioreq.h" 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | 37 | /** @defgroup MSC_BOT 38 | * @brief BOT protocol module 39 | * @{ 40 | */ 41 | 42 | /** @defgroup MSC_BOT_Private_TypesDefinitions 43 | * @{ 44 | */ 45 | /** 46 | * @} 47 | */ 48 | 49 | 50 | /** @defgroup MSC_BOT_Private_Defines 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | 59 | /** @defgroup MSC_BOT_Private_Macros 60 | * @{ 61 | */ 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | /** @defgroup MSC_BOT_Private_Variables 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | 76 | /** @defgroup MSC_BOT_Private_FunctionPrototypes 77 | * @{ 78 | */ 79 | static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev); 80 | 81 | static void MSC_BOT_SendData (USBD_HandleTypeDef *pdev, uint8_t* pbuf, 82 | uint16_t len); 83 | 84 | static void MSC_BOT_Abort(USBD_HandleTypeDef *pdev); 85 | /** 86 | * @} 87 | */ 88 | 89 | 90 | /** @defgroup MSC_BOT_Private_Functions 91 | * @{ 92 | */ 93 | 94 | 95 | 96 | /** 97 | * @brief MSC_BOT_Init 98 | * Initialize the BOT Process 99 | * @param pdev: device instance 100 | * @retval None 101 | */ 102 | void MSC_BOT_Init (USBD_HandleTypeDef *pdev) 103 | { 104 | USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; 105 | 106 | hmsc->bot_state = USBD_BOT_IDLE; 107 | hmsc->bot_status = USBD_BOT_STATUS_NORMAL; 108 | 109 | hmsc->scsi_sense_tail = 0U; 110 | hmsc->scsi_sense_head = 0U; 111 | 112 | ((USBD_StorageTypeDef *)pdev->pUserData)->Init(0U); 113 | 114 | USBD_LL_FlushEP(pdev, MSC_EPOUT_ADDR); 115 | USBD_LL_FlushEP(pdev, MSC_EPIN_ADDR); 116 | 117 | /* Prapare EP to Receive First BOT Cmd */ 118 | USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, 119 | USBD_BOT_CBW_LENGTH); 120 | } 121 | 122 | /** 123 | * @brief MSC_BOT_Reset 124 | * Reset the BOT Machine 125 | * @param pdev: device instance 126 | * @retval None 127 | */ 128 | void MSC_BOT_Reset (USBD_HandleTypeDef *pdev) 129 | { 130 | USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; 131 | 132 | hmsc->bot_state = USBD_BOT_IDLE; 133 | hmsc->bot_status = USBD_BOT_STATUS_RECOVERY; 134 | 135 | /* Prapare EP to Receive First BOT Cmd */ 136 | USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, 137 | USBD_BOT_CBW_LENGTH); 138 | } 139 | 140 | /** 141 | * @brief MSC_BOT_DeInit 142 | * Deinitialize the BOT Machine 143 | * @param pdev: device instance 144 | * @retval None 145 | */ 146 | void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev) 147 | { 148 | USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; 149 | hmsc->bot_state = USBD_BOT_IDLE; 150 | } 151 | 152 | /** 153 | * @brief MSC_BOT_DataIn 154 | * Handle BOT IN data stage 155 | * @param pdev: device instance 156 | * @param epnum: endpoint index 157 | * @retval None 158 | */ 159 | void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev, 160 | uint8_t epnum) 161 | { 162 | USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; 163 | 164 | switch (hmsc->bot_state) 165 | { 166 | case USBD_BOT_DATA_IN: 167 | if(SCSI_ProcessCmd(pdev, 168 | hmsc->cbw.bLUN, 169 | &hmsc->cbw.CB[0]) < 0) 170 | { 171 | MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED); 172 | } 173 | break; 174 | 175 | case USBD_BOT_SEND_DATA: 176 | case USBD_BOT_LAST_DATA_IN: 177 | MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED); 178 | 179 | break; 180 | 181 | default: 182 | break; 183 | } 184 | } 185 | /** 186 | * @brief MSC_BOT_DataOut 187 | * Process MSC OUT data 188 | * @param pdev: device instance 189 | * @param epnum: endpoint index 190 | * @retval None 191 | */ 192 | void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev, 193 | uint8_t epnum) 194 | { 195 | USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; 196 | 197 | switch (hmsc->bot_state) 198 | { 199 | case USBD_BOT_IDLE: 200 | MSC_BOT_CBW_Decode(pdev); 201 | break; 202 | 203 | case USBD_BOT_DATA_OUT: 204 | 205 | if(SCSI_ProcessCmd(pdev, 206 | hmsc->cbw.bLUN, 207 | &hmsc->cbw.CB[0]) < 0) 208 | { 209 | MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED); 210 | } 211 | 212 | break; 213 | 214 | default: 215 | break; 216 | } 217 | } 218 | 219 | /** 220 | * @brief MSC_BOT_CBW_Decode 221 | * Decode the CBW command and set the BOT state machine accordingly 222 | * @param pdev: device instance 223 | * @retval None 224 | */ 225 | static void MSC_BOT_CBW_Decode (USBD_HandleTypeDef *pdev) 226 | { 227 | USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; 228 | 229 | hmsc->csw.dTag = hmsc->cbw.dTag; 230 | hmsc->csw.dDataResidue = hmsc->cbw.dDataLength; 231 | 232 | if ((USBD_LL_GetRxDataSize (pdev ,MSC_EPOUT_ADDR) != USBD_BOT_CBW_LENGTH) || 233 | (hmsc->cbw.dSignature != USBD_BOT_CBW_SIGNATURE) || 234 | (hmsc->cbw.bLUN > 1U) || 235 | (hmsc->cbw.bCBLength < 1U) || (hmsc->cbw.bCBLength > 16U)) 236 | { 237 | 238 | SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); 239 | 240 | hmsc->bot_status = USBD_BOT_STATUS_ERROR; 241 | MSC_BOT_Abort(pdev); 242 | } 243 | else 244 | { 245 | if(SCSI_ProcessCmd(pdev, hmsc->cbw.bLUN, &hmsc->cbw.CB[0]) < 0) 246 | { 247 | if(hmsc->bot_state == USBD_BOT_NO_DATA) 248 | { 249 | MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED); 250 | } 251 | else 252 | { 253 | MSC_BOT_Abort(pdev); 254 | } 255 | } 256 | /*Burst xfer handled internally*/ 257 | else if ((hmsc->bot_state != USBD_BOT_DATA_IN) && 258 | (hmsc->bot_state != USBD_BOT_DATA_OUT) && 259 | (hmsc->bot_state != USBD_BOT_LAST_DATA_IN)) 260 | { 261 | if (hmsc->bot_data_length > 0U) 262 | { 263 | MSC_BOT_SendData(pdev, hmsc->bot_data, hmsc->bot_data_length); 264 | } 265 | else if (hmsc->bot_data_length == 0U) 266 | { 267 | MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED); 268 | } 269 | else 270 | { 271 | MSC_BOT_Abort(pdev); 272 | } 273 | } 274 | else 275 | { 276 | return; 277 | } 278 | } 279 | } 280 | 281 | /** 282 | * @brief MSC_BOT_SendData 283 | * Send the requested data 284 | * @param pdev: device instance 285 | * @param buf: pointer to data buffer 286 | * @param len: Data Length 287 | * @retval None 288 | */ 289 | static void MSC_BOT_SendData(USBD_HandleTypeDef *pdev, uint8_t* pbuf, 290 | uint16_t len) 291 | { 292 | USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; 293 | 294 | uint16_t length = (uint16_t)MIN(hmsc->cbw.dDataLength, len); 295 | 296 | hmsc->csw.dDataResidue -= len; 297 | hmsc->csw.bStatus = USBD_CSW_CMD_PASSED; 298 | hmsc->bot_state = USBD_BOT_SEND_DATA; 299 | 300 | USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, pbuf, length); 301 | } 302 | 303 | /** 304 | * @brief MSC_BOT_SendCSW 305 | * Send the Command Status Wrapper 306 | * @param pdev: device instance 307 | * @param status : CSW status 308 | * @retval None 309 | */ 310 | void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev, 311 | uint8_t CSW_Status) 312 | { 313 | USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; 314 | 315 | hmsc->csw.dSignature = USBD_BOT_CSW_SIGNATURE; 316 | hmsc->csw.bStatus = CSW_Status; 317 | hmsc->bot_state = USBD_BOT_IDLE; 318 | 319 | USBD_LL_Transmit (pdev, MSC_EPIN_ADDR, (uint8_t *)(void *)&hmsc->csw, 320 | USBD_BOT_CSW_LENGTH); 321 | 322 | /* Prepare EP to Receive next Cmd */ 323 | USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, 324 | USBD_BOT_CBW_LENGTH); 325 | } 326 | 327 | /** 328 | * @brief MSC_BOT_Abort 329 | * Abort the current transfer 330 | * @param pdev: device instance 331 | * @retval status 332 | */ 333 | 334 | static void MSC_BOT_Abort (USBD_HandleTypeDef *pdev) 335 | { 336 | USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; 337 | 338 | if ((hmsc->cbw.bmFlags == 0U) && 339 | (hmsc->cbw.dDataLength != 0U) && 340 | (hmsc->bot_status == USBD_BOT_STATUS_NORMAL)) 341 | { 342 | USBD_LL_StallEP(pdev, MSC_EPOUT_ADDR ); 343 | } 344 | 345 | USBD_LL_StallEP(pdev, MSC_EPIN_ADDR); 346 | 347 | if(hmsc->bot_status == USBD_BOT_STATUS_ERROR) 348 | { 349 | USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, (uint8_t *)(void *)&hmsc->cbw, 350 | USBD_BOT_CBW_LENGTH); 351 | } 352 | } 353 | 354 | /** 355 | * @brief MSC_BOT_CplClrFeature 356 | * Complete the clear feature request 357 | * @param pdev: device instance 358 | * @param epnum: endpoint index 359 | * @retval None 360 | */ 361 | 362 | void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev, uint8_t epnum) 363 | { 364 | USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData; 365 | 366 | if(hmsc->bot_status == USBD_BOT_STATUS_ERROR)/* Bad CBW Signature */ 367 | { 368 | USBD_LL_StallEP(pdev, MSC_EPIN_ADDR); 369 | hmsc->bot_status = USBD_BOT_STATUS_NORMAL; 370 | } 371 | else if(((epnum & 0x80U) == 0x80U) && (hmsc->bot_status != USBD_BOT_STATUS_RECOVERY)) 372 | { 373 | MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_FAILED); 374 | } 375 | else 376 | { 377 | return; 378 | } 379 | } 380 | /** 381 | * @} 382 | */ 383 | 384 | 385 | /** 386 | * @} 387 | */ 388 | 389 | 390 | /** 391 | * @} 392 | */ 393 | 394 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 395 | -------------------------------------------------------------------------------- /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 | * @brief This file provides all the vital inquiry pages and sense data. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* BSPDependencies 21 | - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" 22 | - "stm32xxxxx_{eval}{discovery}_io.c" 23 | - "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" 24 | EndBSPDependencies */ 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | #include "usbd_msc_data.h" 28 | 29 | 30 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 31 | * @{ 32 | */ 33 | 34 | 35 | /** @defgroup MSC_DATA 36 | * @brief Mass storage info/data module 37 | * @{ 38 | */ 39 | 40 | /** @defgroup MSC_DATA_Private_TypesDefinitions 41 | * @{ 42 | */ 43 | /** 44 | * @} 45 | */ 46 | 47 | 48 | /** @defgroup MSC_DATA_Private_Defines 49 | * @{ 50 | */ 51 | /** 52 | * @} 53 | */ 54 | 55 | 56 | /** @defgroup MSC_DATA_Private_Macros 57 | * @{ 58 | */ 59 | /** 60 | * @} 61 | */ 62 | 63 | 64 | /** @defgroup MSC_DATA_Private_Variables 65 | * @{ 66 | */ 67 | 68 | 69 | /* USB Mass storage Page 0 Inquiry Data */ 70 | const uint8_t MSC_Page00_Inquiry_Data[] = { 71 | 0x00, 72 | 0x00, 73 | 0x00, 74 | (LENGTH_INQUIRY_PAGE00 - 4U), 75 | 0x00, 76 | 0x80, 77 | 0x83 78 | }; 79 | /* USB Mass storage sense 6 Data */ 80 | const uint8_t MSC_Mode_Sense6_data[] = { 81 | 0x00, 82 | 0x00, 83 | 0x00, 84 | 0x00, 85 | 0x00, 86 | 0x00, 87 | 0x00, 88 | 0x00 89 | }; 90 | /* USB Mass storage sense 10 Data */ 91 | const uint8_t MSC_Mode_Sense10_data[] = { 92 | 0x00, 93 | 0x06, 94 | 0x00, 95 | 0x00, 96 | 0x00, 97 | 0x00, 98 | 0x00, 99 | 0x00 100 | }; 101 | /** 102 | * @} 103 | */ 104 | 105 | 106 | /** @defgroup MSC_DATA_Private_FunctionPrototypes 107 | * @{ 108 | */ 109 | /** 110 | * @} 111 | */ 112 | 113 | 114 | /** @defgroup MSC_DATA_Private_Functions 115 | * @{ 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | 123 | /** 124 | * @} 125 | */ 126 | 127 | 128 | /** 129 | * @} 130 | */ 131 | 132 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 133 | -------------------------------------------------------------------------------- /Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @brief Header file for usbd_core.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

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

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USB_REQUEST_H 22 | #define __USB_REQUEST_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_REQ 37 | * @brief header file for the usbd_req.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_REQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_REQ_Exported_Types 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | 58 | /** @defgroup USBD_REQ_Exported_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | /** @defgroup USBD_REQ_Exported_Variables 66 | * @{ 67 | */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 73 | * @{ 74 | */ 75 | 76 | USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 77 | USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 78 | USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 79 | 80 | 81 | void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 82 | 83 | void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata); 84 | 85 | void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len); 86 | /** 87 | * @} 88 | */ 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* __USB_REQUEST_H */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | 105 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 106 | -------------------------------------------------------------------------------- /Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @brief Header file for the usbd_ioreq.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __USBD_IOREQ_H 22 | #define __USBD_IOREQ_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_def.h" 30 | #include "usbd_core.h" 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief header file for the usbd_ioreq.c file 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Exported_Defines 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Exported_Types 50 | * @{ 51 | */ 52 | 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | 59 | 60 | /** @defgroup USBD_IOREQ_Exported_Macros 61 | * @{ 62 | */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup USBD_IOREQ_Exported_Variables 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 77 | * @{ 78 | */ 79 | 80 | USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, 81 | uint8_t *pbuf, 82 | uint16_t len); 83 | 84 | USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, 85 | uint8_t *pbuf, 86 | uint16_t len); 87 | 88 | USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, 89 | uint8_t *pbuf, 90 | uint16_t len); 91 | 92 | USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, 93 | uint8_t *pbuf, 94 | uint16_t len); 95 | 96 | USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev); 97 | 98 | USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev); 99 | 100 | uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 101 | 102 | /** 103 | * @} 104 | */ 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /* __USBD_IOREQ_H */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @brief This file provides the IO requests APIs for control endpoints. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * http://www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "usbd_ioreq.h" 22 | 23 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 24 | * @{ 25 | */ 26 | 27 | 28 | /** @defgroup USBD_IOREQ 29 | * @brief control I/O requests module 30 | * @{ 31 | */ 32 | 33 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 34 | * @{ 35 | */ 36 | /** 37 | * @} 38 | */ 39 | 40 | 41 | /** @defgroup USBD_IOREQ_Private_Defines 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @} 47 | */ 48 | 49 | 50 | /** @defgroup USBD_IOREQ_Private_Macros 51 | * @{ 52 | */ 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 68 | * @{ 69 | */ 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_Functions 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @brief USBD_CtlSendData 81 | * send data on the ctl pipe 82 | * @param pdev: device instance 83 | * @param buff: pointer to data buffer 84 | * @param len: length of data to be sent 85 | * @retval status 86 | */ 87 | USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf, 88 | uint16_t len) 89 | { 90 | /* Set EP0 State */ 91 | pdev->ep0_state = USBD_EP0_DATA_IN; 92 | pdev->ep_in[0].total_length = len; 93 | pdev->ep_in[0].rem_length = len; 94 | 95 | /* Start the transfer */ 96 | USBD_LL_Transmit (pdev, 0x00U, pbuf, len); 97 | 98 | return USBD_OK; 99 | } 100 | 101 | /** 102 | * @brief USBD_CtlContinueSendData 103 | * continue sending data on the ctl pipe 104 | * @param pdev: device instance 105 | * @param buff: pointer to data buffer 106 | * @param len: length of data to be sent 107 | * @retval status 108 | */ 109 | USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, 110 | uint8_t *pbuf, uint16_t len) 111 | { 112 | /* Start the next transfer */ 113 | USBD_LL_Transmit (pdev, 0x00U, pbuf, len); 114 | 115 | return USBD_OK; 116 | } 117 | 118 | /** 119 | * @brief USBD_CtlPrepareRx 120 | * receive data on the ctl pipe 121 | * @param pdev: device instance 122 | * @param buff: pointer to data buffer 123 | * @param len: length of data to be received 124 | * @retval status 125 | */ 126 | USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, 127 | uint16_t len) 128 | { 129 | /* Set EP0 State */ 130 | pdev->ep0_state = USBD_EP0_DATA_OUT; 131 | pdev->ep_out[0].total_length = len; 132 | pdev->ep_out[0].rem_length = len; 133 | 134 | /* Start the transfer */ 135 | USBD_LL_PrepareReceive (pdev, 0U, pbuf, len); 136 | 137 | return USBD_OK; 138 | } 139 | 140 | /** 141 | * @brief USBD_CtlContinueRx 142 | * continue receive data on the ctl pipe 143 | * @param pdev: device instance 144 | * @param buff: pointer to data buffer 145 | * @param len: length of data to be received 146 | * @retval status 147 | */ 148 | USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, 149 | uint16_t len) 150 | { 151 | USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); 152 | 153 | return USBD_OK; 154 | } 155 | 156 | /** 157 | * @brief USBD_CtlSendStatus 158 | * send zero lzngth packet on the ctl pipe 159 | * @param pdev: device instance 160 | * @retval status 161 | */ 162 | USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev) 163 | { 164 | /* Set EP0 State */ 165 | pdev->ep0_state = USBD_EP0_STATUS_IN; 166 | 167 | /* Start the transfer */ 168 | USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); 169 | 170 | return USBD_OK; 171 | } 172 | 173 | /** 174 | * @brief USBD_CtlReceiveStatus 175 | * receive zero lzngth packet on the ctl pipe 176 | * @param pdev: device instance 177 | * @retval status 178 | */ 179 | USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev) 180 | { 181 | /* Set EP0 State */ 182 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 183 | 184 | /* Start the transfer */ 185 | USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U); 186 | 187 | return USBD_OK; 188 | } 189 | 190 | /** 191 | * @brief USBD_GetRxCount 192 | * returns the received data length 193 | * @param pdev: device instance 194 | * @param ep_addr: endpoint address 195 | * @retval Rx Data blength 196 | */ 197 | uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr) 198 | { 199 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 200 | } 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | 207 | /** 208 | * @} 209 | */ 210 | 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 217 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STM32 Game Boy cart firmware 2 | 3 | Firmware for the [STM32 Game Boy flash cart](https://github.com/Emeryth/stm32gbcart) 4 | 5 | Its goal is to run LSDJ, but it should be able to run any GB rom with up to 768KiB of ROM and 128KiB RAM. 6 | 7 | Features upload and download of ROM and RAM contents over USB mass storage. 8 | 9 | ## License and Copyright 10 | 11 | Copyright (c) 2020 Andrzej Surowiec, 12 | released under MIT License 13 | -------------------------------------------------------------------------------- /STM32F405RGTx_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | 5 | ** File : LinkerScript.ld 6 | ** 7 | ** Author : Auto-generated by Ac6 System Workbench 8 | ** 9 | ** Abstract : Linker script for STM32F405RGTx series 10 | ** 1024Kbytes FLASH and 128Kbytes RAM 11 | ** 12 | ** Set heap size, stack size and stack location according 13 | ** to application requirements. 14 | ** 15 | ** Set memory bank area and size if external memory is used. 16 | ** 17 | ** Target : STMicroelectronics STM32 18 | ** 19 | ** Distribution: The file is distributed “as is,” without any warranty 20 | ** of any kind. 21 | ** 22 | ***************************************************************************** 23 | ** @attention 24 | ** 25 | **

© COPYRIGHT(c) 2014 Ac6

26 | ** 27 | ** Redistribution and use in source and binary forms, with or without modification, 28 | ** are permitted provided that the following conditions are met: 29 | ** 1. Redistributions of source code must retain the above copyright notice, 30 | ** this list of conditions and the following disclaimer. 31 | ** 2. Redistributions in binary form must reproduce the above copyright notice, 32 | ** this list of conditions and the following disclaimer in the documentation 33 | ** and/or other materials provided with the distribution. 34 | ** 3. Neither the name of Ac6 nor the names of its contributors 35 | ** may be used to endorse or promote products derived from this software 36 | ** without specific prior written permission. 37 | ** 38 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 39 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 40 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 42 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 43 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 44 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 45 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 47 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 48 | ** 49 | ***************************************************************************** 50 | */ 51 | 52 | /* Entry Point */ 53 | ENTRY(Reset_Handler) 54 | 55 | /* Highest address of the user mode stack */ 56 | _estack = 0x20020000; /* end of RAM */ 57 | /* Generate a link error if heap and stack don't fit into RAM */ 58 | _Min_Heap_Size = 0x200; /* required amount of heap */ 59 | _Min_Stack_Size = 0x400; /* required amount of stack */ 60 | 61 | /* Specify the memory areas */ 62 | MEMORY 63 | { 64 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 65 | CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K 66 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K 67 | } 68 | 69 | /* Define output sections */ 70 | SECTIONS 71 | { 72 | /* The startup code goes first into FLASH */ 73 | .isr_vector : 74 | { 75 | . = ALIGN(4); 76 | KEEP(*(.isr_vector)) /* Startup code */ 77 | . = ALIGN(4); 78 | } >FLASH 79 | 80 | /* The program code and other data goes into FLASH */ 81 | .text : 82 | { 83 | . = ALIGN(4); 84 | *(.text) /* .text sections (code) */ 85 | *(.text*) /* .text* sections (code) */ 86 | *(.glue_7) /* glue arm to thumb code */ 87 | *(.glue_7t) /* glue thumb to arm code */ 88 | *(.eh_frame) 89 | 90 | KEEP (*(.init)) 91 | KEEP (*(.fini)) 92 | 93 | . = ALIGN(4); 94 | _etext = .; /* define a global symbols at end of code */ 95 | } >FLASH 96 | 97 | /* Constant data goes into FLASH */ 98 | .rodata : 99 | { 100 | . = ALIGN(4); 101 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 102 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 103 | . = ALIGN(4); 104 | } >FLASH 105 | 106 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH 107 | .ARM : { 108 | __exidx_start = .; 109 | *(.ARM.exidx*) 110 | __exidx_end = .; 111 | } >FLASH 112 | 113 | .preinit_array : 114 | { 115 | PROVIDE_HIDDEN (__preinit_array_start = .); 116 | KEEP (*(.preinit_array*)) 117 | PROVIDE_HIDDEN (__preinit_array_end = .); 118 | } >FLASH 119 | .init_array : 120 | { 121 | PROVIDE_HIDDEN (__init_array_start = .); 122 | KEEP (*(SORT(.init_array.*))) 123 | KEEP (*(.init_array*)) 124 | PROVIDE_HIDDEN (__init_array_end = .); 125 | } >FLASH 126 | .fini_array : 127 | { 128 | PROVIDE_HIDDEN (__fini_array_start = .); 129 | KEEP (*(SORT(.fini_array.*))) 130 | KEEP (*(.fini_array*)) 131 | PROVIDE_HIDDEN (__fini_array_end = .); 132 | } >FLASH 133 | 134 | /* used by the startup to initialize data */ 135 | _sidata = LOADADDR(.data); 136 | 137 | /* Initialized data sections goes into RAM, load LMA copy after code */ 138 | .data : 139 | { 140 | . = ALIGN(4); 141 | _sdata = .; /* create a global symbol at data start */ 142 | *(.data) /* .data sections */ 143 | *(.data*) /* .data* sections */ 144 | 145 | . = ALIGN(4); 146 | _edata = .; /* define a global symbol at data end */ 147 | } >RAM AT> FLASH 148 | 149 | _siccmram = LOADADDR(.ccmram); 150 | 151 | /* CCM-RAM section 152 | * 153 | * IMPORTANT NOTE! 154 | * If initialized variables will be placed in this section, 155 | * the startup code needs to be modified to copy the init-values. 156 | */ 157 | .ccmram : 158 | { 159 | . = ALIGN(4); 160 | _sccmram = .; /* create a global symbol at ccmram start */ 161 | *(.ccmram) 162 | *(.ccmram*) 163 | 164 | . = ALIGN(4); 165 | _eccmram = .; /* create a global symbol at ccmram end */ 166 | } >CCMRAM AT> FLASH 167 | 168 | 169 | /* Uninitialized data section */ 170 | . = ALIGN(4); 171 | .bss : 172 | { 173 | /* This is used by the startup in order to initialize the .bss secion */ 174 | _sbss = .; /* define a global symbol at bss start */ 175 | __bss_start__ = _sbss; 176 | *(.bss) 177 | *(.bss*) 178 | *(COMMON) 179 | 180 | . = ALIGN(4); 181 | _ebss = .; /* define a global symbol at bss end */ 182 | __bss_end__ = _ebss; 183 | } >RAM 184 | 185 | /* User_heap_stack section, used to check that there is enough RAM left */ 186 | ._user_heap_stack : 187 | { 188 | . = ALIGN(8); 189 | PROVIDE ( end = . ); 190 | PROVIDE ( _end = . ); 191 | . = . + _Min_Heap_Size; 192 | . = . + _Min_Stack_Size; 193 | . = ALIGN(8); 194 | } >RAM 195 | 196 | 197 | 198 | /* Remove information from the standard libraries */ 199 | /DISCARD/ : 200 | { 201 | libc.a ( * ) 202 | libm.a ( * ) 203 | libgcc.a ( * ) 204 | } 205 | 206 | .ARM.attributes 0 : { *(.ARM.attributes) } 207 | } 208 | 209 | 210 | -------------------------------------------------------------------------------- /Src/cartridge.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cartridge.c 3 | * 4 | * Created on: Jan 2, 2020 5 | * Author: andrju 6 | */ 7 | 8 | #include "cartridge.h" 9 | #include 10 | #include "main.h" 11 | 12 | //#include "gejmboj.h" 13 | //#include "lsdj.h" 14 | //#include "save.h" 15 | //#include "roccow.h" 16 | 17 | uint8_t sram[RAM1_SIZE]; 18 | uint8_t sram2[RAM2_SIZE]__attribute__((section(".ccmram"))); 19 | 20 | cartridge_t cartridge = { .rom = (uint8_t *)ROM_SAVE_ADDR 21 | , .ram = sram, .rom_bank = 1, 22 | .ram_bank = 0, }; 23 | 24 | void load_ram(void) { 25 | 26 | // memcpy(sram, roccow_sav, RAM1_SIZE); 27 | // memcpy(sram2, roccow_sav + RAM1_SIZE, RAM2_SIZE); 28 | 29 | uint32_t Address = SRAM_SAVE_ADDR; 30 | 31 | for(int i=0;i < RAM1_SIZE/4;i++){ 32 | ((uint32_t*)sram)[i]=*((uint32_t*)Address); 33 | Address+=4; 34 | } 35 | for(int i=0;i < RAM2_SIZE/4;i++){ 36 | ((uint32_t*)sram2)[i]=*((uint32_t*)Address); 37 | Address+=4; 38 | } 39 | 40 | } 41 | 42 | static FLASH_EraseInitTypeDef EraseInitStruct; 43 | uint32_t SectorError = 0; 44 | 45 | void erase_ram(void){ 46 | 47 | EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; 48 | EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; 49 | EraseInitStruct.Sector = FLASH_SECTOR_11; 50 | EraseInitStruct.NbSectors = 1; 51 | if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) { 52 | 53 | Error_Handler(); 54 | } 55 | } 56 | 57 | void erase_rom(void){ 58 | 59 | EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS; 60 | EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3; 61 | EraseInitStruct.Sector = FLASH_SECTOR_5; 62 | EraseInitStruct.NbSectors = 6; 63 | if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) { 64 | 65 | Error_Handler(); 66 | } 67 | 68 | } 69 | 70 | void save_ram(void) { 71 | LL_GPIO_SetOutputPin(LED2_GPIO_Port, LED2_Pin); 72 | HAL_FLASH_Unlock(); 73 | 74 | erase_ram(); 75 | 76 | uint32_t Address = SRAM_SAVE_ADDR; 77 | int i=0; 78 | 79 | for(i=0;i < RAM1_SIZE/4;i++) 80 | { 81 | if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, ((uint32_t*)sram)[i]) == HAL_OK) 82 | { 83 | Address = Address + 4; 84 | } 85 | else 86 | { 87 | Error_Handler(); 88 | } 89 | } 90 | i=0; 91 | for(i=0;i < RAM2_SIZE/4;i++) 92 | { 93 | if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, ((uint32_t*)sram2)[i]) == HAL_OK) 94 | { 95 | Address = Address + 4; 96 | } 97 | else 98 | { 99 | Error_Handler(); 100 | } 101 | } 102 | 103 | HAL_FLASH_Lock(); 104 | 105 | LL_GPIO_ResetOutputPin(LED2_GPIO_Port, LED2_Pin); 106 | 107 | HAL_PWR_EnterSTANDBYMode(); 108 | } 109 | -------------------------------------------------------------------------------- /Src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * File Name : stm32f4xx_hal_msp.c 5 | * Description : This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

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

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | #include "stm32f4xx_it.h" 24 | /* Private includes ----------------------------------------------------------*/ 25 | /* USER CODE BEGIN Includes */ 26 | #include "cartridge.h" 27 | /* USER CODE END Includes */ 28 | 29 | /* Private typedef -----------------------------------------------------------*/ 30 | /* USER CODE BEGIN TD */ 31 | 32 | /* USER CODE END TD */ 33 | 34 | /* Private define ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN PD */ 36 | 37 | /* USER CODE END PD */ 38 | 39 | /* Private macro -------------------------------------------------------------*/ 40 | /* USER CODE BEGIN PM */ 41 | 42 | /* USER CODE END PM */ 43 | 44 | /* Private variables ---------------------------------------------------------*/ 45 | /* USER CODE BEGIN PV */ 46 | 47 | /* USER CODE END PV */ 48 | 49 | /* Private function prototypes -----------------------------------------------*/ 50 | /* USER CODE BEGIN PFP */ 51 | 52 | /* USER CODE END PFP */ 53 | 54 | /* Private user code ---------------------------------------------------------*/ 55 | /* USER CODE BEGIN 0 */ 56 | 57 | /* USER CODE END 0 */ 58 | 59 | /* External variables --------------------------------------------------------*/ 60 | extern PCD_HandleTypeDef hpcd_USB_OTG_FS; 61 | /* USER CODE BEGIN EV */ 62 | 63 | /* USER CODE END EV */ 64 | 65 | /******************************************************************************/ 66 | /* Cortex-M4 Processor Interruption and Exception Handlers */ 67 | /******************************************************************************/ 68 | /** 69 | * @brief This function handles Non maskable interrupt. 70 | */ 71 | void NMI_Handler(void) 72 | { 73 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 74 | 75 | /* USER CODE END NonMaskableInt_IRQn 0 */ 76 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 77 | 78 | /* USER CODE END NonMaskableInt_IRQn 1 */ 79 | } 80 | 81 | /** 82 | * @brief This function handles Hard fault interrupt. 83 | */ 84 | void HardFault_Handler(void) 85 | { 86 | /* USER CODE BEGIN HardFault_IRQn 0 */ 87 | 88 | /* USER CODE END HardFault_IRQn 0 */ 89 | while (1) 90 | { 91 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 92 | /* USER CODE END W1_HardFault_IRQn 0 */ 93 | } 94 | } 95 | 96 | /** 97 | * @brief This function handles Memory management fault. 98 | */ 99 | void MemManage_Handler(void) 100 | { 101 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 102 | 103 | /* USER CODE END MemoryManagement_IRQn 0 */ 104 | while (1) 105 | { 106 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 107 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 108 | } 109 | } 110 | 111 | /** 112 | * @brief This function handles Pre-fetch fault, memory access fault. 113 | */ 114 | void BusFault_Handler(void) 115 | { 116 | /* USER CODE BEGIN BusFault_IRQn 0 */ 117 | 118 | /* USER CODE END BusFault_IRQn 0 */ 119 | while (1) 120 | { 121 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 122 | /* USER CODE END W1_BusFault_IRQn 0 */ 123 | } 124 | } 125 | 126 | /** 127 | * @brief This function handles Undefined instruction or illegal state. 128 | */ 129 | void UsageFault_Handler(void) 130 | { 131 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 132 | 133 | /* USER CODE END UsageFault_IRQn 0 */ 134 | while (1) 135 | { 136 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 137 | /* USER CODE END W1_UsageFault_IRQn 0 */ 138 | } 139 | } 140 | 141 | /** 142 | * @brief This function handles System service call via SWI instruction. 143 | */ 144 | void SVC_Handler(void) 145 | { 146 | /* USER CODE BEGIN SVCall_IRQn 0 */ 147 | 148 | /* USER CODE END SVCall_IRQn 0 */ 149 | /* USER CODE BEGIN SVCall_IRQn 1 */ 150 | 151 | /* USER CODE END SVCall_IRQn 1 */ 152 | } 153 | 154 | /** 155 | * @brief This function handles Debug monitor. 156 | */ 157 | void DebugMon_Handler(void) 158 | { 159 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 160 | 161 | /* USER CODE END DebugMonitor_IRQn 0 */ 162 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 163 | 164 | /* USER CODE END DebugMonitor_IRQn 1 */ 165 | } 166 | 167 | /** 168 | * @brief This function handles Pendable request for system service. 169 | */ 170 | void PendSV_Handler(void) 171 | { 172 | /* USER CODE BEGIN PendSV_IRQn 0 */ 173 | 174 | /* USER CODE END PendSV_IRQn 0 */ 175 | /* USER CODE BEGIN PendSV_IRQn 1 */ 176 | 177 | /* USER CODE END PendSV_IRQn 1 */ 178 | } 179 | 180 | /** 181 | * @brief This function handles System tick timer. 182 | */ 183 | void SysTick_Handler(void) 184 | { 185 | /* USER CODE BEGIN SysTick_IRQn 0 */ 186 | 187 | /* USER CODE END SysTick_IRQn 0 */ 188 | HAL_IncTick(); 189 | /* USER CODE BEGIN SysTick_IRQn 1 */ 190 | 191 | /* USER CODE END SysTick_IRQn 1 */ 192 | } 193 | 194 | /******************************************************************************/ 195 | /* STM32F4xx Peripheral Interrupt Handlers */ 196 | /* Add here the Interrupt Handlers for the used peripherals. */ 197 | /* For the available peripheral interrupt handler names, */ 198 | /* please refer to the startup file (startup_stm32f4xx.s). */ 199 | /******************************************************************************/ 200 | 201 | /** 202 | * @brief This function handles EXTI line2 interrupt. 203 | */ 204 | void EXTI2_IRQHandler(void) 205 | { 206 | /* USER CODE BEGIN EXTI2_IRQn 0 */ 207 | 208 | /* USER CODE END EXTI2_IRQn 0 */ 209 | if (LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_2) != RESET) 210 | { 211 | LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_2); 212 | /* USER CODE BEGIN LL_EXTI_LINE_2 */ 213 | // HAL_InitTick(TICK_INT_PRIORITY); 214 | save_ram(); 215 | /* USER CODE END LL_EXTI_LINE_2 */ 216 | } 217 | /* USER CODE BEGIN EXTI2_IRQn 1 */ 218 | 219 | /* USER CODE END EXTI2_IRQn 1 */ 220 | } 221 | 222 | /** 223 | * @brief This function handles USB On The Go FS global interrupt. 224 | */ 225 | void OTG_FS_IRQHandler(void) 226 | { 227 | /* USER CODE BEGIN OTG_FS_IRQn 0 */ 228 | 229 | /* USER CODE END OTG_FS_IRQn 0 */ 230 | HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS); 231 | /* USER CODE BEGIN OTG_FS_IRQn 1 */ 232 | 233 | /* USER CODE END OTG_FS_IRQn 1 */ 234 | } 235 | 236 | /* USER CODE BEGIN 1 */ 237 | 238 | /* USER CODE END 1 */ 239 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 240 | -------------------------------------------------------------------------------- /Src/usb_device.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usb_device.c 5 | * @version : v1.0_Cube 6 | * @brief : This file implements the USB Device 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | 24 | #include "usb_device.h" 25 | #include "usbd_core.h" 26 | #include "usbd_desc.h" 27 | #include "usbd_msc.h" 28 | #include "usbd_storage_if.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* USER CODE BEGIN PV */ 35 | /* Private variables ---------------------------------------------------------*/ 36 | 37 | /* USER CODE END PV */ 38 | 39 | /* USER CODE BEGIN PFP */ 40 | /* Private function prototypes -----------------------------------------------*/ 41 | 42 | /* USER CODE END PFP */ 43 | 44 | /* USB Device Core handle declaration. */ 45 | USBD_HandleTypeDef hUsbDeviceFS; 46 | 47 | /* 48 | * -- Insert your variables declaration here -- 49 | */ 50 | /* USER CODE BEGIN 0 */ 51 | 52 | /* USER CODE END 0 */ 53 | 54 | /* 55 | * -- Insert your external function declaration here -- 56 | */ 57 | /* USER CODE BEGIN 1 */ 58 | 59 | /* USER CODE END 1 */ 60 | 61 | /** 62 | * Init USB device Library, add supported class and start the library 63 | * @retval None 64 | */ 65 | void MX_USB_DEVICE_Init(void) 66 | { 67 | /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ 68 | 69 | /* USER CODE END USB_DEVICE_Init_PreTreatment */ 70 | 71 | /* Init Device Library, add supported class and start the library. */ 72 | if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) 73 | { 74 | Error_Handler(); 75 | } 76 | if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_MSC) != USBD_OK) 77 | { 78 | Error_Handler(); 79 | } 80 | if (USBD_MSC_RegisterStorage(&hUsbDeviceFS, &USBD_Storage_Interface_fops_FS) != USBD_OK) 81 | { 82 | Error_Handler(); 83 | } 84 | if (USBD_Start(&hUsbDeviceFS) != USBD_OK) 85 | { 86 | Error_Handler(); 87 | } 88 | 89 | /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ 90 | 91 | /* USER CODE END USB_DEVICE_Init_PostTreatment */ 92 | } 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** 99 | * @} 100 | */ 101 | 102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 103 | -------------------------------------------------------------------------------- /Src/usbd_storage_if.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_storage_if.c 5 | * @version : v1.0_Cube 6 | * @brief : Memory management layer. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

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

12 | * 13 | * This software component is licensed by ST under Ultimate Liberty license 14 | * SLA0044, the "License"; You may not use this file except in compliance with 15 | * the License. You may obtain a copy of the License at: 16 | * www.st.com/SLA0044 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "usbd_storage_if.h" 24 | 25 | /* USER CODE BEGIN INCLUDE */ 26 | #include 27 | #include "fat.h" 28 | #include "cartridge.h" 29 | /* USER CODE END INCLUDE */ 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* Private define ------------------------------------------------------------*/ 33 | /* Private macro -------------------------------------------------------------*/ 34 | 35 | /* USER CODE BEGIN PV */ 36 | /* Private variables ---------------------------------------------------------*/ 37 | 38 | /* USER CODE END PV */ 39 | 40 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY 41 | * @brief Usb device. 42 | * @{ 43 | */ 44 | 45 | /** @defgroup USBD_STORAGE 46 | * @brief Usb mass storage device module 47 | * @{ 48 | */ 49 | 50 | /** @defgroup USBD_STORAGE_Private_TypesDefinitions 51 | * @brief Private types. 52 | * @{ 53 | */ 54 | 55 | /* USER CODE BEGIN PRIVATE_TYPES */ 56 | 57 | /* USER CODE END PRIVATE_TYPES */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** @defgroup USBD_STORAGE_Private_Defines 64 | * @brief Private defines. 65 | * @{ 66 | */ 67 | 68 | #define STORAGE_LUN_NBR 1 69 | #define STORAGE_BLK_NBR 0x930 70 | #define STORAGE_BLK_SIZ 0x200 71 | 72 | /* USER CODE BEGIN PRIVATE_DEFINES */ 73 | #define FAT_END_BLK 8 74 | #define ROM_START_BLK 41 75 | #define ROM_END_BLK (ROM_START_BLK+(ROM_MAX_SIZE/STORAGE_BLK_SIZ)) 76 | #define RAM_START_BLK 2089 77 | #define RAM_END_BLK (RAM_START_BLK+(RAM_SIZE/STORAGE_BLK_SIZ)) 78 | /* USER CODE END PRIVATE_DEFINES */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup USBD_STORAGE_Private_Macros 85 | * @brief Private macros. 86 | * @{ 87 | */ 88 | 89 | /* USER CODE BEGIN PRIVATE_MACRO */ 90 | 91 | /* USER CODE END PRIVATE_MACRO */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | /** @defgroup USBD_STORAGE_Private_Variables 98 | * @brief Private variables. 99 | * @{ 100 | */ 101 | 102 | /* USER CODE BEGIN INQUIRY_DATA_FS */ 103 | /** USB Mass storage Standard Inquiry Data. */ 104 | const int8_t STORAGE_Inquirydata_FS[] = {/* 36 */ 105 | 106 | /* LUN 0 */ 107 | 0x00, 108 | 0x80, 109 | 0x02, 110 | 0x02, 111 | (STANDARD_INQUIRY_DATA_LEN - 5), 112 | 0x00, 113 | 0x00, 114 | 0x00, 115 | 'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */ 116 | 'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */ 117 | ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 118 | '0', '.', '0' ,'1' /* Version : 4 Bytes */ 119 | }; 120 | /* USER CODE END INQUIRY_DATA_FS */ 121 | 122 | /* USER CODE BEGIN PRIVATE_VARIABLES */ 123 | int flash_unlocked=0; 124 | int rom_erased=0; 125 | int ram_erased=0; 126 | /* USER CODE END PRIVATE_VARIABLES */ 127 | 128 | /** 129 | * @} 130 | */ 131 | 132 | /** @defgroup USBD_STORAGE_Exported_Variables 133 | * @brief Public variables. 134 | * @{ 135 | */ 136 | 137 | extern USBD_HandleTypeDef hUsbDeviceFS; 138 | 139 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 140 | 141 | /* USER CODE END EXPORTED_VARIABLES */ 142 | 143 | /** 144 | * @} 145 | */ 146 | 147 | /** @defgroup USBD_STORAGE_Private_FunctionPrototypes 148 | * @brief Private functions declaration. 149 | * @{ 150 | */ 151 | 152 | static int8_t STORAGE_Init_FS(uint8_t lun); 153 | static int8_t STORAGE_GetCapacity_FS(uint8_t lun, uint32_t *block_num, uint16_t *block_size); 154 | static int8_t STORAGE_IsReady_FS(uint8_t lun); 155 | static int8_t STORAGE_IsWriteProtected_FS(uint8_t lun); 156 | static int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); 157 | static int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); 158 | static int8_t STORAGE_GetMaxLun_FS(void); 159 | 160 | /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ 161 | 162 | /* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | USBD_StorageTypeDef USBD_Storage_Interface_fops_FS = 169 | { 170 | STORAGE_Init_FS, 171 | STORAGE_GetCapacity_FS, 172 | STORAGE_IsReady_FS, 173 | STORAGE_IsWriteProtected_FS, 174 | STORAGE_Read_FS, 175 | STORAGE_Write_FS, 176 | STORAGE_GetMaxLun_FS, 177 | (int8_t *)STORAGE_Inquirydata_FS 178 | }; 179 | 180 | /* Private functions ---------------------------------------------------------*/ 181 | /** 182 | * @brief Initializes over USB FS IP 183 | * @param lun: 184 | * @retval USBD_OK if all operations are OK else USBD_FAIL 185 | */ 186 | int8_t STORAGE_Init_FS(uint8_t lun) 187 | { 188 | /* USER CODE BEGIN 2 */ 189 | return (USBD_OK); 190 | /* USER CODE END 2 */ 191 | } 192 | 193 | /** 194 | * @brief . 195 | * @param lun: . 196 | * @param block_num: . 197 | * @param block_size: . 198 | * @retval USBD_OK if all operations are OK else USBD_FAIL 199 | */ 200 | int8_t STORAGE_GetCapacity_FS(uint8_t lun, uint32_t *block_num, uint16_t *block_size) 201 | { 202 | /* USER CODE BEGIN 3 */ 203 | *block_num = STORAGE_BLK_NBR; 204 | *block_size = STORAGE_BLK_SIZ; 205 | return (USBD_OK); 206 | /* USER CODE END 3 */ 207 | } 208 | 209 | /** 210 | * @brief . 211 | * @param lun: . 212 | * @retval USBD_OK if all operations are OK else USBD_FAIL 213 | */ 214 | int8_t STORAGE_IsReady_FS(uint8_t lun) 215 | { 216 | /* USER CODE BEGIN 4 */ 217 | return (USBD_OK); 218 | /* USER CODE END 4 */ 219 | } 220 | 221 | /** 222 | * @brief . 223 | * @param lun: . 224 | * @retval USBD_OK if all operations are OK else USBD_FAIL 225 | */ 226 | int8_t STORAGE_IsWriteProtected_FS(uint8_t lun) 227 | { 228 | /* USER CODE BEGIN 5 */ 229 | return (USBD_OK); 230 | /* USER CODE END 5 */ 231 | } 232 | 233 | /** 234 | * @brief . 235 | * @param lun: . 236 | * @retval USBD_OK if all operations are OK else USBD_FAIL 237 | */ 238 | int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) 239 | { 240 | /* USER CODE BEGIN 6 */ 241 | 242 | int addr; 243 | 244 | if (blk_addr=ROM_START_BLK&&blk_addr=RAM_START_BLK&&blk_addr=ROM_START_BLK&&blk_addr=RAM_START_BLK&&blk_addr