├── LICENSE ├── README.md ├── STM32 ├── Drivers │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32F4xx │ │ │ │ └── Include │ │ │ │ ├── stm32f407xx.h │ │ │ │ ├── stm32f4xx.h │ │ │ │ └── system_stm32f4xx.h │ │ └── Include │ │ │ ├── cmsis_armcc.h │ │ │ ├── cmsis_armclang.h │ │ │ ├── cmsis_compiler.h │ │ │ ├── cmsis_gcc.h │ │ │ ├── cmsis_iccarm.h │ │ │ ├── cmsis_version.h │ │ │ ├── core_armv8mbl.h │ │ │ ├── core_armv8mml.h │ │ │ ├── core_cm0.h │ │ │ ├── core_cm0plus.h │ │ │ ├── core_cm1.h │ │ │ ├── core_cm23.h │ │ │ ├── core_cm3.h │ │ │ ├── core_cm33.h │ │ │ ├── core_cm4.h │ │ │ ├── core_cm7.h │ │ │ ├── core_sc000.h │ │ │ ├── core_sc300.h │ │ │ ├── mpu_armv7.h │ │ │ ├── mpu_armv8.h │ │ │ └── tz_context.h │ └── STM32F4xx_HAL_Driver │ │ ├── Inc │ │ ├── Legacy │ │ │ └── stm32_hal_legacy.h │ │ ├── stm32f4xx_hal.h │ │ ├── stm32f4xx_hal_cortex.h │ │ ├── stm32f4xx_hal_dcmi.h │ │ ├── stm32f4xx_hal_dcmi_ex.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_spi.h │ │ ├── stm32f4xx_hal_tim.h │ │ ├── stm32f4xx_hal_tim_ex.h │ │ └── stm32f4xx_ll_usb.h │ │ └── Src │ │ ├── stm32f4xx_hal.c │ │ ├── stm32f4xx_hal_cortex.c │ │ ├── stm32f4xx_hal_dcmi.c │ │ ├── stm32f4xx_hal_dcmi_ex.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_spi.c │ │ ├── stm32f4xx_hal_tim.c │ │ ├── stm32f4xx_hal_tim_ex.c │ │ └── stm32f4xx_ll_usb.c ├── EWARM │ ├── F407HS.ewp │ ├── Project.eww │ ├── startup_stm32f407xx.s │ ├── stm32f407xx_flash.icf │ └── stm32f407xx_sram.icf ├── F407HS.ioc ├── Inc │ ├── main.h │ ├── pl.h │ ├── pl_flash.h │ ├── stm32f4xx_hal_conf.h │ ├── stm32f4xx_it.h │ ├── str_util.h │ ├── usb_device.h │ ├── usb_tmc.h │ ├── usb_tmc_commands.h │ ├── usb_tmc_proto.h │ ├── usbd_cdc.h │ ├── usbd_cdc_if.h │ ├── usbd_conf.h │ ├── usbd_desc.h │ ├── uuid.h │ └── version.h ├── Middlewares │ └── ST │ │ └── STM32_USB_Device_Library │ │ └── Core │ │ ├── Inc │ │ ├── usbd_core.h │ │ ├── usbd_ctlreq.h │ │ ├── usbd_def.h │ │ └── usbd_ioreq.h │ │ └── Src │ │ ├── usbd_core.c │ │ ├── usbd_ctlreq.c │ │ └── usbd_ioreq.c └── Src │ ├── main.c │ ├── pl.c │ ├── pl_flash.c │ ├── stm32f4xx_hal_msp.c │ ├── stm32f4xx_it.c │ ├── system_stm32f4xx.c │ ├── usb_device.c │ ├── usb_tmc_handler.c │ ├── usbd_cdc.c │ ├── usbd_cdc_if.c │ ├── usbd_conf.c │ └── usbd_desc.c ├── doc ├── Spartan6Configuration.pdf ├── USBTMC_1_00.pdf ├── XCore407I-Schematic.pdf ├── XME0601SCH.pdf ├── prototype.jpg ├── schematic.png ├── schematic.vsdx ├── scpi-99.pdf ├── stm32f407ig.pdf ├── usbtmc_usb488_subclass_1_00.pdf └── w25q16jv.pdf ├── hdl ├── lib │ ├── dcmi_util.v │ └── spi_gate.v └── test │ ├── XME0601blink │ ├── XME0601blink.xise │ ├── blink.ucf │ └── blink.v │ └── XME0601echo │ ├── XME0601echo.xise │ ├── echo.ucf │ ├── echo.v │ └── test │ ├── blink.py │ ├── capture.py │ ├── echo16.py │ ├── echo8.py │ ├── echo_cnt.py │ └── echo_dcmi.py ├── python ├── chipscope.py ├── pl.py └── pl_flash.py └── test ├── echo.py └── imtest.vi /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /STM32/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/STM32/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dcmi_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dcmi_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DCMI Extension HAL 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_DCMI_EX_H 22 | #define __STM32F4xx_HAL_DCMI_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) ||\ 29 | defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) ||\ 30 | defined(STM32F479xx) 31 | 32 | /* Includes ------------------------------------------------------------------*/ 33 | #include "stm32f4xx_hal_def.h" 34 | 35 | 36 | /** @addtogroup STM32F4xx_HAL_Driver 37 | * @{ 38 | */ 39 | 40 | /** @addtogroup DCMIEx 41 | * @brief DCMI HAL module driver 42 | * @{ 43 | */ 44 | 45 | /* Exported types ------------------------------------------------------------*/ 46 | /** @defgroup DCMIEx_Exported_Types DCMI Extended Exported Types 47 | * @{ 48 | */ 49 | /** 50 | * @brief DCMIEx Embedded Synchronisation CODE Init structure definition 51 | */ 52 | typedef struct 53 | { 54 | uint8_t FrameStartCode; /*!< Specifies the code of the frame start delimiter. */ 55 | uint8_t LineStartCode; /*!< Specifies the code of the line start delimiter. */ 56 | uint8_t LineEndCode; /*!< Specifies the code of the line end delimiter. */ 57 | uint8_t FrameEndCode; /*!< Specifies the code of the frame end delimiter. */ 58 | }DCMI_CodesInitTypeDef; 59 | 60 | /** 61 | * @brief DCMI Init structure definition 62 | */ 63 | typedef struct 64 | { 65 | uint32_t SynchroMode; /*!< Specifies the Synchronization Mode: Hardware or Embedded. 66 | This parameter can be a value of @ref DCMI_Synchronization_Mode */ 67 | 68 | uint32_t PCKPolarity; /*!< Specifies the Pixel clock polarity: Falling or Rising. 69 | This parameter can be a value of @ref DCMI_PIXCK_Polarity */ 70 | 71 | uint32_t VSPolarity; /*!< Specifies the Vertical synchronization polarity: High or Low. 72 | This parameter can be a value of @ref DCMI_VSYNC_Polarity */ 73 | 74 | uint32_t HSPolarity; /*!< Specifies the Horizontal synchronization polarity: High or Low. 75 | This parameter can be a value of @ref DCMI_HSYNC_Polarity */ 76 | 77 | uint32_t CaptureRate; /*!< Specifies the frequency of frame capture: All, 1/2 or 1/4. 78 | This parameter can be a value of @ref DCMI_Capture_Rate */ 79 | 80 | uint32_t ExtendedDataMode; /*!< Specifies the data width: 8-bit, 10-bit, 12-bit or 14-bit. 81 | This parameter can be a value of @ref DCMI_Extended_Data_Mode */ 82 | 83 | DCMI_CodesInitTypeDef SyncroCode; /*!< Specifies the code of the frame start delimiter. */ 84 | 85 | uint32_t JPEGMode; /*!< Enable or Disable the JPEG mode 86 | This parameter can be a value of @ref DCMI_MODE_JPEG */ 87 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) 88 | uint32_t ByteSelectMode; /*!< Specifies the data to be captured by the interface 89 | This parameter can be a value of @ref DCMIEx_Byte_Select_Mode */ 90 | 91 | uint32_t ByteSelectStart; /*!< Specifies if the data to be captured by the interface is even or odd 92 | This parameter can be a value of @ref DCMIEx_Byte_Select_Start */ 93 | 94 | uint32_t LineSelectMode; /*!< Specifies the line of data to be captured by the interface 95 | This parameter can be a value of @ref DCMIEx_Line_Select_Mode */ 96 | 97 | uint32_t LineSelectStart; /*!< Specifies if the line of data to be captured by the interface is even or odd 98 | This parameter can be a value of @ref DCMIEx_Line_Select_Start */ 99 | 100 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */ 101 | }DCMI_InitTypeDef; 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /* Exported constants --------------------------------------------------------*/ 108 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) 109 | /** @defgroup DCMIEx_Exported_Constants DCMI Exported Constants 110 | * @{ 111 | */ 112 | 113 | /** @defgroup DCMIEx_Byte_Select_Mode DCMI Byte Select Mode 114 | * @{ 115 | */ 116 | #define DCMI_BSM_ALL 0x00000000U /*!< Interface captures all received data */ 117 | #define DCMI_BSM_OTHER ((uint32_t)DCMI_CR_BSM_0) /*!< Interface captures every other byte from the received data */ 118 | #define DCMI_BSM_ALTERNATE_4 ((uint32_t)DCMI_CR_BSM_1) /*!< Interface captures one byte out of four */ 119 | #define DCMI_BSM_ALTERNATE_2 ((uint32_t)(DCMI_CR_BSM_0 | DCMI_CR_BSM_1)) /*!< Interface captures two bytes out of four */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** @defgroup DCMIEx_Byte_Select_Start DCMI Byte Select Start 126 | * @{ 127 | */ 128 | #define DCMI_OEBS_ODD 0x00000000U /*!< Interface captures first data from the frame/line start, second one being dropped */ 129 | #define DCMI_OEBS_EVEN ((uint32_t)DCMI_CR_OEBS) /*!< Interface captures second data from the frame/line start, first one being dropped */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | /** @defgroup DCMIEx_Line_Select_Mode DCMI Line Select Mode 136 | * @{ 137 | */ 138 | #define DCMI_LSM_ALL 0x00000000U /*!< Interface captures all received lines */ 139 | #define DCMI_LSM_ALTERNATE_2 ((uint32_t)DCMI_CR_LSM) /*!< Interface captures one line out of two */ 140 | 141 | /** 142 | * @} 143 | */ 144 | 145 | /** @defgroup DCMIEx_Line_Select_Start DCMI Line Select Start 146 | * @{ 147 | */ 148 | #define DCMI_OELS_ODD 0x00000000U /*!< Interface captures first line from the frame start, second one being dropped */ 149 | #define DCMI_OELS_EVEN ((uint32_t)DCMI_CR_OELS) /*!< Interface captures second line from the frame start, first one being dropped */ 150 | 151 | /** 152 | * @} 153 | */ 154 | 155 | /** 156 | * @} 157 | */ 158 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */ 159 | 160 | /* Exported macro ------------------------------------------------------------*/ 161 | /* Exported functions --------------------------------------------------------*/ 162 | /* Private types -------------------------------------------------------------*/ 163 | /* Private variables ---------------------------------------------------------*/ 164 | /* Private constants ---------------------------------------------------------*/ 165 | #define DCMI_POSITION_ESCR_LSC (uint32_t)DCMI_ESCR_LSC_Pos /*!< Required left shift to set line start delimiter */ 166 | #define DCMI_POSITION_ESCR_LEC (uint32_t)DCMI_ESCR_LEC_Pos /*!< Required left shift to set line end delimiter */ 167 | #define DCMI_POSITION_ESCR_FEC (uint32_t)DCMI_ESCR_FEC_Pos /*!< Required left shift to set frame end delimiter */ 168 | 169 | /* Private macro -------------------------------------------------------------*/ 170 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) 171 | /** @defgroup DCMIEx_Private_Macros DCMI Extended Private Macros 172 | * @{ 173 | */ 174 | #define IS_DCMI_BYTE_SELECT_MODE(MODE)(((MODE) == DCMI_BSM_ALL) || \ 175 | ((MODE) == DCMI_BSM_OTHER) || \ 176 | ((MODE) == DCMI_BSM_ALTERNATE_4) || \ 177 | ((MODE) == DCMI_BSM_ALTERNATE_2)) 178 | 179 | #define IS_DCMI_BYTE_SELECT_START(POLARITY)(((POLARITY) == DCMI_OEBS_ODD) || \ 180 | ((POLARITY) == DCMI_OEBS_EVEN)) 181 | 182 | #define IS_DCMI_LINE_SELECT_MODE(MODE)(((MODE) == DCMI_LSM_ALL) || \ 183 | ((MODE) == DCMI_LSM_ALTERNATE_2)) 184 | 185 | #define IS_DCMI_LINE_SELECT_START(POLARITY)(((POLARITY) == DCMI_OELS_ODD) || \ 186 | ((POLARITY) == DCMI_OELS_EVEN)) 187 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */ 188 | /** 189 | * @} 190 | */ 191 | 192 | /* Private functions ---------------------------------------------------------*/ 193 | #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\ 194 | STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx ||\ 195 | STM32F479xx */ 196 | 197 | 198 | /** 199 | * @} 200 | */ 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | #ifdef __cplusplus 207 | } 208 | #endif 209 | 210 | #endif /* __STM32F4xx_HAL_DCMI_H */ 211 | 212 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 213 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dcmi_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dcmi_ex.c 4 | * @author MCD Application Team 5 | * @brief DCMI Extension HAL module driver 6 | * This file provides firmware functions to manage the following 7 | * functionalities of DCMI extension peripheral: 8 | * + Extension features functions 9 | * 10 | @verbatim 11 | ============================================================================== 12 | ##### DCMI peripheral extension features ##### 13 | ============================================================================== 14 | 15 | [..] Comparing to other previous devices, the DCMI interface for STM32F446xx 16 | devices contains the following additional features : 17 | 18 | (+) Support of Black and White cameras 19 | 20 | ##### How to use this driver ##### 21 | ============================================================================== 22 | [..] This driver provides functions to manage the Black and White feature 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 | /** @defgroup DCMIEx DCMIEx 46 | * @brief DCMI Extended HAL module driver 47 | * @{ 48 | */ 49 | 50 | #ifdef HAL_DCMI_MODULE_ENABLED 51 | 52 | #if defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) ||\ 53 | defined(STM32F439xx) || defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) 54 | /* Private typedef -----------------------------------------------------------*/ 55 | /* Private define ------------------------------------------------------------*/ 56 | /* Private macro -------------------------------------------------------------*/ 57 | /* Private variables ---------------------------------------------------------*/ 58 | /* Private function prototypes -----------------------------------------------*/ 59 | /* Exported functions --------------------------------------------------------*/ 60 | 61 | /** @defgroup DCMIEx_Exported_Functions DCMI Extended Exported Functions 62 | * @{ 63 | */ 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | /** @addtogroup DCMI_Exported_Functions_Group1 Initialization and Configuration functions 70 | * @{ 71 | */ 72 | 73 | /** 74 | * @brief Initializes the DCMI according to the specified 75 | * parameters in the DCMI_InitTypeDef and create the associated handle. 76 | * @param hdcmi pointer to a DCMI_HandleTypeDef structure that contains 77 | * the configuration information for DCMI. 78 | * @retval HAL status 79 | */ 80 | HAL_StatusTypeDef HAL_DCMI_Init(DCMI_HandleTypeDef *hdcmi) 81 | { 82 | /* Check the DCMI peripheral state */ 83 | if(hdcmi == NULL) 84 | { 85 | return HAL_ERROR; 86 | } 87 | 88 | /* Check function parameters */ 89 | assert_param(IS_DCMI_ALL_INSTANCE(hdcmi->Instance)); 90 | assert_param(IS_DCMI_PCKPOLARITY(hdcmi->Init.PCKPolarity)); 91 | assert_param(IS_DCMI_VSPOLARITY(hdcmi->Init.VSPolarity)); 92 | assert_param(IS_DCMI_HSPOLARITY(hdcmi->Init.HSPolarity)); 93 | assert_param(IS_DCMI_SYNCHRO(hdcmi->Init.SynchroMode)); 94 | assert_param(IS_DCMI_CAPTURE_RATE(hdcmi->Init.CaptureRate)); 95 | assert_param(IS_DCMI_EXTENDED_DATA(hdcmi->Init.ExtendedDataMode)); 96 | assert_param(IS_DCMI_MODE_JPEG(hdcmi->Init.JPEGMode)); 97 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) 98 | assert_param(IS_DCMI_BYTE_SELECT_MODE(hdcmi->Init.ByteSelectMode)); 99 | assert_param(IS_DCMI_BYTE_SELECT_START(hdcmi->Init.ByteSelectStart)); 100 | assert_param(IS_DCMI_LINE_SELECT_MODE(hdcmi->Init.LineSelectMode)); 101 | assert_param(IS_DCMI_LINE_SELECT_START(hdcmi->Init.LineSelectStart)); 102 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */ 103 | if(hdcmi->State == HAL_DCMI_STATE_RESET) 104 | { 105 | /* Init the low level hardware */ 106 | HAL_DCMI_MspInit(hdcmi); 107 | } 108 | 109 | /* Change the DCMI state */ 110 | hdcmi->State = HAL_DCMI_STATE_BUSY; 111 | /* Configures the HS, VS, DE and PC polarity */ 112 | hdcmi->Instance->CR &= ~(DCMI_CR_PCKPOL | DCMI_CR_HSPOL | DCMI_CR_VSPOL | DCMI_CR_EDM_0 |\ 113 | DCMI_CR_EDM_1 | DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1 | DCMI_CR_JPEG |\ 114 | DCMI_CR_ESS 115 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) 116 | | DCMI_CR_BSM_0 | DCMI_CR_BSM_1 | DCMI_CR_OEBS |\ 117 | DCMI_CR_LSM | DCMI_CR_OELS 118 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */ 119 | ); 120 | hdcmi->Instance->CR |= (uint32_t)(hdcmi->Init.SynchroMode | hdcmi->Init.CaptureRate |\ 121 | hdcmi->Init.VSPolarity | hdcmi->Init.HSPolarity |\ 122 | hdcmi->Init.PCKPolarity | hdcmi->Init.ExtendedDataMode |\ 123 | hdcmi->Init.JPEGMode 124 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) 125 | | hdcmi->Init.ByteSelectMode |\ 126 | hdcmi->Init.ByteSelectStart | hdcmi->Init.LineSelectMode |\ 127 | hdcmi->Init.LineSelectStart 128 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */ 129 | ); 130 | if(hdcmi->Init.SynchroMode == DCMI_SYNCHRO_EMBEDDED) 131 | { 132 | hdcmi->Instance->ESCR = (((uint32_t)hdcmi->Init.SyncroCode.FrameStartCode) | 133 | ((uint32_t)hdcmi->Init.SyncroCode.LineStartCode << DCMI_POSITION_ESCR_LSC)| 134 | ((uint32_t)hdcmi->Init.SyncroCode.LineEndCode << DCMI_POSITION_ESCR_LEC) | 135 | ((uint32_t)hdcmi->Init.SyncroCode.FrameEndCode << DCMI_POSITION_ESCR_FEC)); 136 | 137 | } 138 | 139 | /* Enable the Line, Vsync, Error and Overrun interrupts */ 140 | __HAL_DCMI_ENABLE_IT(hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC | DCMI_IT_ERR | DCMI_IT_OVR); 141 | 142 | /* Update error code */ 143 | hdcmi->ErrorCode = HAL_DCMI_ERROR_NONE; 144 | 145 | /* Initialize the DCMI state*/ 146 | hdcmi->State = HAL_DCMI_STATE_READY; 147 | 148 | return HAL_OK; 149 | } 150 | 151 | /** 152 | * @} 153 | */ 154 | #endif /* STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx ||\ 155 | STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */ 156 | #endif /* HAL_DCMI_MODULE_ENABLED */ 157 | /** 158 | * @} 159 | */ 160 | 161 | /** 162 | * @} 163 | */ 164 | 165 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 166 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/EWARM/Project.eww: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $WS_DIR$\F407HS.ewp 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /STM32/EWARM/stm32f407xx_flash.icf: -------------------------------------------------------------------------------- 1 | /*###ICF### Section handled by ICF editor, don't touch! ****/ 2 | /*-Editor annotation file-*/ 3 | /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ 4 | /*-Specials-*/ 5 | define symbol __ICFEDIT_intvec_start__ = 0x08000000; 6 | /*-Memory Regions-*/ 7 | define symbol __ICFEDIT_region_ROM_start__ = 0x08000000; 8 | define symbol __ICFEDIT_region_ROM_end__ = 0x080FFFFF; 9 | define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; 10 | define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF; 11 | define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000; 12 | define symbol __ICFEDIT_region_CCMRAM_end__ = 0x1000FFFF; 13 | /*-Sizes-*/ 14 | define symbol __ICFEDIT_size_cstack__ = 0x400; 15 | define symbol __ICFEDIT_size_heap__ = 0x2000; 16 | /**** End of ICF editor section. ###ICF###*/ 17 | 18 | 19 | define memory mem with size = 4G; 20 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; 21 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; 22 | define region CCMRAM_region = mem:[from __ICFEDIT_region_CCMRAM_start__ to __ICFEDIT_region_CCMRAM_end__]; 23 | 24 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; 25 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; 26 | 27 | initialize by copy { readwrite }; 28 | do not initialize { section .noinit }; 29 | 30 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; 31 | 32 | place in ROM_region { readonly }; 33 | place in RAM_region { readwrite, 34 | block CSTACK, block HEAP }; 35 | -------------------------------------------------------------------------------- /STM32/EWARM/stm32f407xx_sram.icf: -------------------------------------------------------------------------------- 1 | /*###ICF### Section handled by ICF editor, don't touch! ****/ 2 | /*-Editor annotation file-*/ 3 | /* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ 4 | /*-Specials-*/ 5 | define symbol __ICFEDIT_intvec_start__ = 0x20000000; 6 | /*-Memory Regions-*/ 7 | define symbol __ICFEDIT_region_ROM_start__ = 0x20000000; 8 | define symbol __ICFEDIT_region_ROM_end__ = 0x2000FFFF; 9 | define symbol __ICFEDIT_region_RAM_start__ = 0x20010000; 10 | define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF; 11 | define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000; 12 | define symbol __ICFEDIT_region_CCMRAM_end__ = 0x1000FFFF; 13 | /*-Sizes-*/ 14 | define symbol __ICFEDIT_size_cstack__ = 0x400; 15 | define symbol __ICFEDIT_size_heap__ = 0x2000; 16 | /**** End of ICF editor section. ###ICF###*/ 17 | 18 | 19 | define memory mem with size = 4G; 20 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; 21 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; 22 | define region CCMRAM_region = mem:[from __ICFEDIT_region_CCMRAM_start__ to __ICFEDIT_region_CCMRAM_end__]; 23 | 24 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; 25 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; 26 | 27 | initialize by copy { readwrite }; 28 | do not initialize { section .noinit }; 29 | 30 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; 31 | 32 | place in ROM_region { readonly }; 33 | place in RAM_region { readwrite, 34 | block CSTACK, block HEAP }; 35 | -------------------------------------------------------------------------------- /STM32/F407HS.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | DCMI.HSPolarity=DCMI_HSPOLARITY_HIGH 3 | DCMI.IPParameters=JPEGMode,VSPolarity,HSPolarity,PCKPolarity 4 | DCMI.JPEGMode=DCMI_JPEG_ENABLE 5 | DCMI.PCKPolarity=DCMI_PCKPOLARITY_RISING 6 | DCMI.VSPolarity=DCMI_VSPOLARITY_LOW 7 | Dma.DCMI.0.Direction=DMA_PERIPH_TO_MEMORY 8 | Dma.DCMI.0.FIFOMode=DMA_FIFOMODE_DISABLE 9 | Dma.DCMI.0.Instance=DMA2_Stream1 10 | Dma.DCMI.0.MemDataAlignment=DMA_MDATAALIGN_WORD 11 | Dma.DCMI.0.MemInc=DMA_MINC_ENABLE 12 | Dma.DCMI.0.Mode=DMA_NORMAL 13 | Dma.DCMI.0.PeriphDataAlignment=DMA_PDATAALIGN_WORD 14 | Dma.DCMI.0.PeriphInc=DMA_PINC_DISABLE 15 | Dma.DCMI.0.Priority=DMA_PRIORITY_LOW 16 | Dma.DCMI.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode 17 | Dma.Request0=DCMI 18 | Dma.RequestsNb=1 19 | File.Version=6 20 | KeepUserPlacement=false 21 | Mcu.Family=STM32F4 22 | Mcu.IP0=DCMI 23 | Mcu.IP1=DMA 24 | Mcu.IP2=NVIC 25 | Mcu.IP3=RCC 26 | Mcu.IP4=SPI3 27 | Mcu.IP5=SYS 28 | Mcu.IP6=USB_DEVICE 29 | Mcu.IP7=USB_OTG_HS 30 | Mcu.IPNb=8 31 | Mcu.Name=STM32F407I(E-G)Tx 32 | Mcu.Package=LQFP176 33 | Mcu.Pin0=PE4 34 | Mcu.Pin1=PE5 35 | Mcu.Pin10=PA5 36 | Mcu.Pin11=PA6 37 | Mcu.Pin12=PB0 38 | Mcu.Pin13=PB1 39 | Mcu.Pin14=PB10 40 | Mcu.Pin15=PB11 41 | Mcu.Pin16=PH9 42 | Mcu.Pin17=PH10 43 | Mcu.Pin18=PH11 44 | Mcu.Pin19=PH12 45 | Mcu.Pin2=PE6 46 | Mcu.Pin20=PB12 47 | Mcu.Pin21=PB13 48 | Mcu.Pin22=PA13 49 | Mcu.Pin23=PA14 50 | Mcu.Pin24=PA15 51 | Mcu.Pin25=PC10 52 | Mcu.Pin26=PC11 53 | Mcu.Pin27=PC12 54 | Mcu.Pin28=PD0 55 | Mcu.Pin29=PD1 56 | Mcu.Pin3=PI11 57 | Mcu.Pin30=PD2 58 | Mcu.Pin31=PD3 59 | Mcu.Pin32=PB5 60 | Mcu.Pin33=PB6 61 | Mcu.Pin34=PB7 62 | Mcu.Pin35=VP_SYS_VS_Systick 63 | Mcu.Pin36=VP_USB_DEVICE_VS_USB_DEVICE_CDC_HS 64 | Mcu.Pin4=PH0-OSC_IN 65 | Mcu.Pin5=PH1-OSC_OUT 66 | Mcu.Pin6=PC0 67 | Mcu.Pin7=PC3 68 | Mcu.Pin8=PA3 69 | Mcu.Pin9=PA4 70 | Mcu.PinsNb=37 71 | Mcu.ThirdPartyNb=0 72 | Mcu.UserConstants= 73 | Mcu.UserName=STM32F407IGTx 74 | MxCube.Version=5.4.0 75 | MxDb.Version=DB.5.0.40 76 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 77 | NVIC.DMA2_Stream1_IRQn=true\:0\:0\:false\:false\:true\:false\:true 78 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false 79 | NVIC.ForceEnableDMAVector=true 80 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 81 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false 82 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 83 | NVIC.OTG_HS_EP1_IN_IRQn=true\:0\:0\:false\:false\:true\:true\:true 84 | NVIC.OTG_HS_EP1_OUT_IRQn=true\:0\:0\:false\:false\:true\:true\:true 85 | NVIC.OTG_HS_IRQn=true\:0\:0\:false\:false\:true\:true\:true 86 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false 87 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 88 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false 89 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true 90 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 91 | PA13.Mode=Serial_Wire 92 | PA13.Signal=SYS_JTMS-SWDIO 93 | PA14.Mode=Serial_Wire 94 | PA14.Signal=SYS_JTCK-SWCLK 95 | PA15.GPIOParameters=GPIO_Speed,PinState,GPIO_Label 96 | PA15.GPIO_Label=FFLASH_CS 97 | PA15.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 98 | PA15.Locked=true 99 | PA15.PinState=GPIO_PIN_SET 100 | PA15.Signal=GPIO_Output 101 | PA3.Mode=Device_HS 102 | PA3.Signal=USB_OTG_HS_ULPI_D0 103 | PA4.GPIOParameters=GPIO_Speed,GPIO_PuPd 104 | PA4.GPIO_PuPd=GPIO_PULLUP 105 | PA4.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 106 | PA4.Mode=Slave_8_bits_External_Synchro 107 | PA4.Signal=DCMI_HSYNC 108 | PA5.Mode=Device_HS 109 | PA5.Signal=USB_OTG_HS_ULPI_CK 110 | PA6.GPIOParameters=GPIO_Speed,GPIO_PuPd 111 | PA6.GPIO_PuPd=GPIO_PULLUP 112 | PA6.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 113 | PA6.Mode=Slave_8_bits_External_Synchro 114 | PA6.Signal=DCMI_PIXCLK 115 | PB0.Mode=Device_HS 116 | PB0.Signal=USB_OTG_HS_ULPI_D1 117 | PB1.Mode=Device_HS 118 | PB1.Signal=USB_OTG_HS_ULPI_D2 119 | PB10.Mode=Device_HS 120 | PB10.Signal=USB_OTG_HS_ULPI_D3 121 | PB11.Mode=Device_HS 122 | PB11.Signal=USB_OTG_HS_ULPI_D4 123 | PB12.Mode=Device_HS 124 | PB12.Signal=USB_OTG_HS_ULPI_D5 125 | PB13.Mode=Device_HS 126 | PB13.Signal=USB_OTG_HS_ULPI_D6 127 | PB5.Mode=Device_HS 128 | PB5.Signal=USB_OTG_HS_ULPI_D7 129 | PB6.GPIOParameters=GPIO_Speed 130 | PB6.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 131 | PB6.Mode=Slave_8_bits_External_Synchro 132 | PB6.Signal=DCMI_D5 133 | PB7.GPIOParameters=GPIO_Speed,GPIO_PuPd 134 | PB7.GPIO_PuPd=GPIO_PULLUP 135 | PB7.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 136 | PB7.Mode=Slave_8_bits_External_Synchro 137 | PB7.Signal=DCMI_VSYNC 138 | PC0.Mode=Device_HS 139 | PC0.Signal=USB_OTG_HS_ULPI_STP 140 | PC10.Mode=Full_Duplex_Master 141 | PC10.Signal=SPI3_SCK 142 | PC11.Mode=Full_Duplex_Master 143 | PC11.Signal=SPI3_MISO 144 | PC12.Mode=Full_Duplex_Master 145 | PC12.Signal=SPI3_MOSI 146 | PC3.Mode=Device_HS 147 | PC3.Signal=USB_OTG_HS_ULPI_NXT 148 | PCC.Checker=false 149 | PCC.Line=STM32F407/417 150 | PCC.MCU=STM32F407I(E-G)Tx 151 | PCC.PartNumber=STM32F407IGTx 152 | PCC.Seq0=0 153 | PCC.Series=STM32F4 154 | PCC.Temperature=25 155 | PCC.Vdd=3.3 156 | PD0.GPIOParameters=PinState,GPIO_Label 157 | PD0.GPIO_Label=PROGRAM_B 158 | PD0.Locked=true 159 | PD0.PinState=GPIO_PIN_RESET 160 | PD0.Signal=GPIO_Output 161 | PD1.GPIOParameters=GPIO_PuPd,GPIO_Label 162 | PD1.GPIO_Label=DONE 163 | PD1.GPIO_PuPd=GPIO_PULLDOWN 164 | PD1.Locked=true 165 | PD1.Signal=GPIO_Input 166 | PD2.GPIOParameters=GPIO_Speed,PinState,GPIO_Label 167 | PD2.GPIO_Label=PL_CS 168 | PD2.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 169 | PD2.Locked=true 170 | PD2.PinState=GPIO_PIN_SET 171 | PD2.Signal=GPIO_Output 172 | PD3.GPIOParameters=GPIO_PuPd,GPIO_Label 173 | PD3.GPIO_Label=PL_SRQ 174 | PD3.GPIO_PuPd=GPIO_PULLUP 175 | PD3.Locked=true 176 | PD3.Signal=GPIO_Input 177 | PE4.GPIOParameters=GPIO_Speed 178 | PE4.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 179 | PE4.Mode=Slave_8_bits_External_Synchro 180 | PE4.Signal=DCMI_D4 181 | PE5.GPIOParameters=GPIO_Speed 182 | PE5.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 183 | PE5.Mode=Slave_8_bits_External_Synchro 184 | PE5.Signal=DCMI_D6 185 | PE6.GPIOParameters=GPIO_Speed 186 | PE6.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 187 | PE6.Mode=Slave_8_bits_External_Synchro 188 | PE6.Signal=DCMI_D7 189 | PH0-OSC_IN.Mode=HSE-External-Oscillator 190 | PH0-OSC_IN.Signal=RCC_OSC_IN 191 | PH1-OSC_OUT.Mode=HSE-External-Oscillator 192 | PH1-OSC_OUT.Signal=RCC_OSC_OUT 193 | PH10.GPIOParameters=GPIO_Speed 194 | PH10.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 195 | PH10.Mode=Slave_8_bits_External_Synchro 196 | PH10.Signal=DCMI_D1 197 | PH11.GPIOParameters=GPIO_Speed 198 | PH11.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 199 | PH11.Mode=Slave_8_bits_External_Synchro 200 | PH11.Signal=DCMI_D2 201 | PH12.GPIOParameters=GPIO_Speed 202 | PH12.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 203 | PH12.Mode=Slave_8_bits_External_Synchro 204 | PH12.Signal=DCMI_D3 205 | PH9.GPIOParameters=GPIO_Speed 206 | PH9.GPIO_Speed=GPIO_SPEED_FREQ_HIGH 207 | PH9.Mode=Slave_8_bits_External_Synchro 208 | PH9.Signal=DCMI_D0 209 | PI11.Mode=Device_HS 210 | PI11.Signal=USB_OTG_HS_ULPI_DIR 211 | PinOutPanel.RotationAngle=0 212 | ProjectManager.AskForMigrate=true 213 | ProjectManager.BackupPrevious=false 214 | ProjectManager.CompilerOptimize=6 215 | ProjectManager.ComputerToolchain=false 216 | ProjectManager.CoupleFile=false 217 | ProjectManager.CustomerFirmwarePackage= 218 | ProjectManager.DefaultFWLocation=true 219 | ProjectManager.DeletePrevious=true 220 | ProjectManager.DeviceId=STM32F407IGTx 221 | ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.24.2 222 | ProjectManager.FreePins=false 223 | ProjectManager.HalAssertFull=false 224 | ProjectManager.HeapSize=0x2000 225 | ProjectManager.KeepUserCode=true 226 | ProjectManager.LastFirmware=false 227 | ProjectManager.LibraryCopy=1 228 | ProjectManager.MainLocation=Src 229 | ProjectManager.NoMain=false 230 | ProjectManager.PreviousToolchain= 231 | ProjectManager.ProjectBuild=false 232 | ProjectManager.ProjectFileName=F407HS.ioc 233 | ProjectManager.ProjectName=F407HS 234 | ProjectManager.StackSize=0x400 235 | ProjectManager.TargetToolchain=EWARM V8.32 236 | ProjectManager.ToolChainLocation= 237 | ProjectManager.UnderRoot=false 238 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,4-MX_SPI3_Init-SPI3-false-HAL-true,5-MX_DMA_Init-DMA-false-HAL-true,6-MX_DCMI_Init-DCMI-false-HAL-true 239 | RCC.48MHZClocksFreq_Value=48000000 240 | RCC.AHBFreq_Value=72000000 241 | RCC.APB1CLKDivider=RCC_HCLK_DIV2 242 | RCC.APB1Freq_Value=36000000 243 | RCC.APB1TimFreq_Value=72000000 244 | RCC.APB2Freq_Value=72000000 245 | RCC.APB2TimFreq_Value=72000000 246 | RCC.CortexFreq_Value=72000000 247 | RCC.EthernetFreq_Value=72000000 248 | RCC.FCLKCortexFreq_Value=72000000 249 | RCC.FamilyName=M 250 | RCC.HCLKFreq_Value=72000000 251 | RCC.HSE_VALUE=8000000 252 | RCC.HSI_VALUE=16000000 253 | RCC.I2SClocksFreq_Value=192000000 254 | RCC.IPParameters=48MHZClocksFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2SClocksFreq_Value,LSE_VALUE,LSI_VALUE,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLM,PLLN,PLLQ,PLLQCLKFreq_Value,PLLSourceVirtual,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VcooutputI2S 255 | RCC.LSE_VALUE=32768 256 | RCC.LSI_VALUE=32000 257 | RCC.MCO2PinFreq_Value=72000000 258 | RCC.PLLCLKFreq_Value=72000000 259 | RCC.PLLM=4 260 | RCC.PLLN=72 261 | RCC.PLLQ=3 262 | RCC.PLLQCLKFreq_Value=48000000 263 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 264 | RCC.RTCFreq_Value=32000 265 | RCC.RTCHSEDivFreq_Value=4000000 266 | RCC.SYSCLKFreq_VALUE=72000000 267 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 268 | RCC.VCOI2SOutputFreq_Value=384000000 269 | RCC.VCOInputFreq_Value=2000000 270 | RCC.VCOOutputFreq_Value=144000000 271 | RCC.VcooutputI2S=192000000 272 | SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4 273 | SPI3.CalculateBaudRate=9.0 MBits/s 274 | SPI3.Direction=SPI_DIRECTION_2LINES 275 | SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler 276 | SPI3.Mode=SPI_MODE_MASTER 277 | SPI3.VirtualType=VM_MASTER 278 | USB_DEVICE.CLASS_NAME_HS=CDC 279 | USB_DEVICE.IPParameters=VirtualMode-CDC_HS,VirtualModeHS,CLASS_NAME_HS 280 | USB_DEVICE.VirtualMode-CDC_HS=Cdc 281 | USB_DEVICE.VirtualModeHS=Cdc_HS 282 | USB_OTG_HS.IPParameters=VirtualMode-Device_HS 283 | USB_OTG_HS.VirtualMode-Device_HS=Device_HS 284 | VP_SYS_VS_Systick.Mode=SysTick 285 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 286 | VP_USB_DEVICE_VS_USB_DEVICE_CDC_HS.Mode=CDC_HS 287 | VP_USB_DEVICE_VS_USB_DEVICE_CDC_HS.Signal=USB_DEVICE_VS_USB_DEVICE_CDC_HS 288 | board=custom 289 | -------------------------------------------------------------------------------- /STM32/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 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 __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | 58 | /* USER CODE END EFP */ 59 | 60 | /* Private defines -----------------------------------------------------------*/ 61 | #define FFLASH_CS_Pin GPIO_PIN_15 62 | #define FFLASH_CS_GPIO_Port GPIOA 63 | #define PROGRAM_B_Pin GPIO_PIN_0 64 | #define PROGRAM_B_GPIO_Port GPIOD 65 | #define DONE_Pin GPIO_PIN_1 66 | #define DONE_GPIO_Port GPIOD 67 | #define PL_CS_Pin GPIO_PIN_2 68 | #define PL_CS_GPIO_Port GPIOD 69 | #define PL_SRQ_Pin GPIO_PIN_3 70 | #define PL_SRQ_GPIO_Port GPIOD 71 | /* USER CODE BEGIN Private defines */ 72 | extern SPI_HandleTypeDef hspi3; 73 | extern DCMI_HandleTypeDef hdcmi; 74 | /* USER CODE END Private defines */ 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* __MAIN_H */ 81 | 82 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 83 | -------------------------------------------------------------------------------- /STM32/Inc/pl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | // 7 | // Programmable logic management and data exchange API 8 | // 9 | 10 | typedef enum { 11 | pl_inactive, 12 | pl_active, 13 | pl_configured 14 | } pl_status_t; 15 | 16 | extern pl_status_t pl_status; 17 | 18 | // Start programmable logic configuration 19 | void pl_start(void); 20 | 21 | // Enable / disable PL. May be called from ISR context. 22 | // The actual status switch will be performed within pl_process() call. 23 | void pl_enable(bool en); 24 | 25 | // Check PL status. Called periodically in the main() loop. 26 | void pl_process(void); 27 | 28 | // Perform transaction on SPI channel 29 | bool pl_tx(uint8_t* buff, unsigned len); 30 | 31 | // 32 | // Fast DCMI bus data exchange API 33 | // 34 | 35 | typedef enum { 36 | pl_pull_ready, 37 | pl_pull_busy, 38 | pl_pull_failed 39 | } pl_pull_status_t; 40 | 41 | // Start waiting for the DCMI data frame 42 | bool pl_start_pull(uint8_t* buff, unsigned len); 43 | 44 | // Get DCMI data frame reception status 45 | pl_pull_status_t pl_get_pull_status(void); 46 | 47 | // Stop waiting for the DCMI data frame 48 | void pl_stop_pull(void); 49 | -------------------------------------------------------------------------------- /STM32/Inc/pl_flash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | // 6 | // Programmable logic flash access functions 7 | // 8 | 9 | // Write buffer to flash SPI port and put response back to the buffer 10 | void pl_flash_tx(uint8_t *buff, unsigned len); 11 | 12 | #define FLASH_STATUS_BUSY 1 13 | 14 | // Wait non-busy status. Returns the last status received from the flash. 15 | // So the FLASH_STATUS_BUSY will be set on result if operation is timed out. 16 | uint8_t pl_flash_wait(uint32_t tout); 17 | -------------------------------------------------------------------------------- /STM32/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 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 | * www.st.com/SLA0044 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 DMA2_Stream1_IRQHandler(void); 60 | void OTG_HS_EP1_OUT_IRQHandler(void); 61 | void OTG_HS_EP1_IN_IRQHandler(void); 62 | void OTG_HS_IRQHandler(void); 63 | /* USER CODE BEGIN EFP */ 64 | 65 | /* USER CODE END EFP */ 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __STM32F4xx_IT_H */ 72 | 73 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 74 | -------------------------------------------------------------------------------- /STM32/Inc/str_util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 4 | // String manipulation helpers 5 | // 6 | 7 | #define STRZ_LEN(s) (sizeof(s)-1) 8 | #define PREFIX_MATCHED(pref, buf, len) (len >= STRZ_LEN(pref) && !strncmp(pref, (const char*)buf, STRZ_LEN(pref))) 9 | 10 | // Convert value to single hexadecimal digit 11 | static inline char to_hex(uint8_t v) 12 | { 13 | return v >= 0xA ? 'A' + v - 0xA : '0' + v; 14 | } 15 | 16 | // Convert 8 bit value to hexadecimal representation 17 | static inline void byte_to_hex(uint8_t v, char buf[2]) 18 | { 19 | buf[0] = to_hex(v >> 4); 20 | buf[1] = to_hex(v & 0xf); 21 | } 22 | 23 | // Convert 16 bit value to hexadecimal representation 24 | static inline void u16_to_hex(uint16_t v, char buf[4]) 25 | { 26 | byte_to_hex(v >> 8, buf); 27 | byte_to_hex(v, buf + 2); 28 | } 29 | 30 | // Convert 32 bit value to hexadecimal representation 31 | static inline void u32_to_hex(uint32_t v, char buf[8]) 32 | { 33 | u16_to_hex(v >> 16, buf); 34 | u16_to_hex(v, buf + 4); 35 | } 36 | 37 | // Scan buffer bytes until the specified character is found and skip it. 38 | // Returns the number of bytes skipped or 0 if the character is not found. 39 | // Use this function to find token prefixed by the given character. 40 | static inline unsigned skip_through(char c, uint8_t const* buf, unsigned len) 41 | { 42 | unsigned cnt; 43 | for (cnt = 0; len; --len, ++buf, ++cnt) { 44 | if (*buf == c) 45 | return cnt + 1; 46 | if (*buf == ':') 47 | break; 48 | } 49 | return 0; 50 | } 51 | 52 | // Read unsigned value from the buffer. The value may start from the radix prefix. 53 | // Returns the number of bytes consumed or 0 if buffer does not start with the number. 54 | static inline unsigned scan_u(uint8_t const* buf, unsigned len, unsigned* val) 55 | { 56 | unsigned v = 0, radix = 10, cnt; 57 | for (cnt = 0; len; --len, ++buf, ++cnt) 58 | { 59 | unsigned char d; 60 | char c = *buf; 61 | if (!cnt) { 62 | switch (c) { 63 | case 'X': 64 | case 'x': 65 | case 'H': 66 | case 'h': 67 | radix = 16; 68 | continue; 69 | case 'Q': 70 | radix = 8; 71 | continue; 72 | case 'B': 73 | radix = 2; 74 | continue; 75 | default: 76 | ; 77 | } 78 | } 79 | if (c < '0') 80 | break; 81 | if (radix <= 10 && c >= '0' + radix) 82 | break; 83 | if (c <= '9') 84 | d = c - '0'; 85 | else if ('a' <= c && c <= 'f') 86 | d = c - 'a' + 0xa; 87 | else if ('A' <= c && c <= 'F') 88 | d = c - 'A' + 0xA; 89 | else 90 | break; 91 | v *= radix; 92 | v += d; 93 | } 94 | *val = v; 95 | return cnt; 96 | } 97 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/Inc/usb_tmc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "usbd_def.h" 6 | #include "usb_tmc_proto.h" 7 | 8 | // Add safety margin to possible payload size and align to USB packet size 9 | #define USB_TMC_RX_MAX_DATA_SZ (1024 + USB_HS_MAX_PACKET_SIZE - USB_TMC_HDR_SZ) 10 | #define USB_TMC_TX_MAX_DATA_SZ (4096 + USB_HS_MAX_PACKET_SIZE - USB_TMC_HDR_SZ) 11 | 12 | // Initialize device data 13 | void USB_TMC_init(void); 14 | 15 | // Transmit data buffer 16 | uint8_t* USB_TMC_TxDataBuffer(void); 17 | 18 | // Message received 19 | void USB_TMC_Receive(uint8_t const* pbuf, unsigned len); 20 | 21 | // Input response requested 22 | void USB_TMC_RequestResponse(uint8_t tag, unsigned max_len); 23 | 24 | // Reply to host. 25 | uint8_t USB_TMC_Reply(unsigned len, uint8_t tag); 26 | 27 | // Asynchronous processing routine. 28 | // Called periodically in main() loop. 29 | void USB_TMC_Process(void); 30 | -------------------------------------------------------------------------------- /STM32/Inc/usb_tmc_commands.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 4 | // Generic commands 5 | // 6 | #define CMD_IDN "IDN?" 7 | 8 | // Test commands 9 | #define CMD_TEST "TEST" 10 | #define CMD_ECHO "ECHO" 11 | 12 | // Programmable Logic access commands 13 | #define CMD_PL "PL" 14 | 15 | // PL state control 16 | #define CMD_ACTIVE "ACTIVE" 17 | 18 | // PL data exchange transactions 19 | #define CMD_TX "TX" 20 | #define CMD_PULL "PULL" 21 | 22 | // PL flash access commands 23 | #define CMD_FLASH "FLASH" 24 | #define CMD_RD "RD" // Read transaction 25 | #define CMD_WR "WR" // Write transaction 26 | #define CMD_WAIT "WA" // Wait BUSY status clear, returns status byte 27 | #define CMD_PROG "PR" // Program is the combination of wait, write enable and write, returns status byte 28 | 29 | -------------------------------------------------------------------------------- /STM32/Inc/usb_tmc_proto.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 4 | // Control requests specific to TMC class 5 | // 6 | #define USB_TMC_INITIATE_ABORT_BULK_OUT 1 // Required Aborts a Bulk-OUT transfer. 7 | #define USB_TMC_CHECK_ABORT_BULK_OUT_STATUS 2 // Required Returns the status of the previously sent 8 | // INITIATE_ABORT_BULK_OUT request. 9 | #define USB_TMC_INITIATE_ABORT_BULK_IN 3 // Required Aborts a Bulk-IN transfer. 10 | #define USB_TMC_CHECK_ABORT_BULK_IN_STATUS 4 // Required Returns the status of the previously sent 11 | // INITIATE_ABORT_BULK_IN request. 12 | #define USB_TMC_INITIATE_CLEAR 5 // Required Clears all previously sent pending and unprocessed Bulk-OUT USBTMC message 13 | // content and clears all pending Bulk-IN transfers from the USBTMC interface. 14 | #define USB_TMC_CHECK_CLEAR_STATUS 6 // Required Returns the status of the previously sent INITIATE_CLEAR request. 15 | #define USB_TMC_GET_CAPABILITIES 7 16 | 17 | 18 | // 19 | // Status codes 20 | // 21 | #define USB_TMC_STATUS_SUCCESS 0x01 22 | 23 | // This status is valid if a device has received a USBTMC split transaction CHECK_STATUS 24 | // request and the request is still being processed. 25 | #define USB_TMC_STATUS_PENDING 0x02 26 | 27 | // Failure, unspecified reason, and a more specific USBTMC_status is not defined. 28 | #define USB_TMC_STATUS_FAILED 0x80 29 | 30 | // This status is only valid if a device has received an INITIATE_ABORT_BULK_OUT or 31 | // INITIATE_ABORT_BULK_IN request and the specified transfer to abort is not in progress. 32 | #define USB_TMC_STATUS_TRANSFER_NOT_IN_PROGRESS 0x81 33 | 34 | // Failure This status is valid if the device received a CHECK_STATUS request and the device is not 35 | // processing an INITIATE request. 36 | #define USB_TMC_STATUS_SPLIT_NOT_IN_PROGRESS 0x82 37 | 38 | // This status is valid if the device received a new class-specific request and the device is still processing an INITIATE. 39 | #define USB_TMC_STATUS_SPLIT_IN_PROGRESS 0x83 40 | 41 | 42 | // 43 | // BULK message types (MsgID) 44 | // 45 | #define USB_TMC_DEV_DEP_MSG_OUT 1 // The USBTMC message is a USBTMC device dependent command message. 46 | #define USB_TMC_REQUEST_DEV_DEP_MSG_IN 2 // The USBTMC message is a USBTMC command message that requests 47 | // the device to send a USBTMC response message on the Bulk-IN endpoint 48 | 49 | // The USBTMC message is a USBTMC response message to the REQUEST_DEV_DEP_MSG_IN 50 | #define USB_TMC_DEV_DEP_MSG_IN USB_TMC_REQUEST_DEV_DEP_MSG_IN 51 | 52 | // The bulk endpoint message header size in bytes 53 | #define USB_TMC_HDR_SZ 12 54 | 55 | -------------------------------------------------------------------------------- /STM32/Inc/usbd_cdc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_cdc.h 4 | * @author MCD Application Team 5 | * @brief header file for the usbd_cdc.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_CDC_H 22 | #define __USB_CDC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "usbd_ioreq.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | /** @defgroup usbd_cdc 36 | * @brief This file is the Header file for usbd_cdc.c 37 | * @{ 38 | */ 39 | 40 | 41 | /** @defgroup usbd_cdc_Exported_Defines 42 | * @{ 43 | */ 44 | #define CDC_IN_EP 0x81U /* EP1 for data IN */ 45 | #define CDC_OUT_EP 0x01U /* EP1 for data OUT */ 46 | #define CDC_CMD_EP 0x82U /* EP2 for CDC commands */ 47 | 48 | #ifndef CDC_HS_BINTERVAL 49 | #define CDC_HS_BINTERVAL 0x10U 50 | #endif /* CDC_HS_BINTERVAL */ 51 | 52 | #ifndef CDC_FS_BINTERVAL 53 | #define CDC_FS_BINTERVAL 0x10U 54 | #endif /* CDC_FS_BINTERVAL */ 55 | 56 | /* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */ 57 | #define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */ 58 | #define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */ 59 | #define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */ 60 | 61 | #define USB_CDC_CONFIG_DESC_SIZ 32U 62 | #define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE 63 | #define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE 64 | 65 | #define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE 66 | #define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE 67 | 68 | /*---------------------------------------------------------------------*/ 69 | /* CDC definitions */ 70 | /*---------------------------------------------------------------------*/ 71 | #define CDC_SEND_ENCAPSULATED_COMMAND 0x00U 72 | #define CDC_GET_ENCAPSULATED_RESPONSE 0x01U 73 | #define CDC_SET_COMM_FEATURE 0x02U 74 | #define CDC_GET_COMM_FEATURE 0x03U 75 | #define CDC_CLEAR_COMM_FEATURE 0x04U 76 | #define CDC_SET_LINE_CODING 0x20U 77 | #define CDC_GET_LINE_CODING 0x21U 78 | #define CDC_SET_CONTROL_LINE_STATE 0x22U 79 | #define CDC_SEND_BREAK 0x23U 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | 86 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | typedef struct 94 | { 95 | uint32_t bitrate; 96 | uint8_t format; 97 | uint8_t paritytype; 98 | uint8_t datatype; 99 | }USBD_CDC_LineCodingTypeDef; 100 | 101 | typedef struct _USBD_CDC_Itf 102 | { 103 | int8_t (* Init) (void); 104 | int8_t (* DeInit) (void); 105 | int8_t (* Control) (uint8_t cmd, uint8_t* pbuf, uint16_t length); 106 | int8_t (* Receive) (uint8_t* Buf, uint32_t *Len); 107 | 108 | }USBD_CDC_ItfTypeDef; 109 | 110 | 111 | typedef struct 112 | { 113 | uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */ 114 | uint8_t CmdOpCode; 115 | uint8_t CmdLength; 116 | uint8_t *RxBuffer; 117 | uint8_t *TxBuffer; 118 | uint32_t RxLength; 119 | uint32_t TxLength; 120 | 121 | __IO uint32_t TxState; 122 | __IO uint32_t RxState; 123 | } 124 | USBD_CDC_HandleTypeDef; 125 | 126 | 127 | 128 | /** @defgroup USBD_CORE_Exported_Macros 129 | * @{ 130 | */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | /** @defgroup USBD_CORE_Exported_Variables 137 | * @{ 138 | */ 139 | 140 | extern USBD_ClassTypeDef USBD_CDC; 141 | #define USBD_CDC_CLASS &USBD_CDC 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup USB_CORE_Exported_Functions 147 | * @{ 148 | */ 149 | uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev, 150 | USBD_CDC_ItfTypeDef *fops); 151 | 152 | uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev, 153 | uint8_t *pbuff, 154 | uint16_t length); 155 | 156 | uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev, 157 | uint8_t *pbuff); 158 | 159 | uint8_t USBD_CDC_ReceivePacket (USBD_HandleTypeDef *pdev); 160 | 161 | uint8_t USBD_CDC_TransmitPacket (USBD_HandleTypeDef *pdev); 162 | /** 163 | * @} 164 | */ 165 | 166 | #ifdef __cplusplus 167 | } 168 | #endif 169 | 170 | #endif /* __USB_CDC_H */ 171 | /** 172 | * @} 173 | */ 174 | 175 | /** 176 | * @} 177 | */ 178 | 179 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 180 | -------------------------------------------------------------------------------- /STM32/Inc/usbd_cdc_if.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_cdc_if.h 5 | * @version : v1.0_Cube 6 | * @brief : Header for usbd_cdc_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_CDC_IF_H__ 24 | #define __USBD_CDC_IF_H__ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "usbd_cdc.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_CDC_IF USBD_CDC_IF 43 | * @brief Usb VCP device module 44 | * @{ 45 | */ 46 | 47 | /** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines 48 | * @brief Defines. 49 | * @{ 50 | */ 51 | /* USER CODE BEGIN EXPORTED_DEFINES */ 52 | 53 | /* USER CODE END EXPORTED_DEFINES */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types 60 | * @brief Types. 61 | * @{ 62 | */ 63 | 64 | /* USER CODE BEGIN EXPORTED_TYPES */ 65 | 66 | /* USER CODE END EXPORTED_TYPES */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros 73 | * @brief Aliases. 74 | * @{ 75 | */ 76 | 77 | /* USER CODE BEGIN EXPORTED_MACRO */ 78 | 79 | /* USER CODE END EXPORTED_MACRO */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables 86 | * @brief Public variables. 87 | * @{ 88 | */ 89 | 90 | /** CDC Interface callback. */ 91 | extern USBD_CDC_ItfTypeDef USBD_Interface_fops_HS; 92 | 93 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 94 | 95 | /* USER CODE END EXPORTED_VARIABLES */ 96 | 97 | /** 98 | * @} 99 | */ 100 | 101 | /** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype 102 | * @brief Public functions declaration. 103 | * @{ 104 | */ 105 | 106 | uint8_t CDC_Transmit_HS(uint8_t* Buf, uint16_t Len); 107 | 108 | /* USER CODE BEGIN EXPORTED_FUNCTIONS */ 109 | 110 | /* USER CODE END EXPORTED_FUNCTIONS */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /** 121 | * @} 122 | */ 123 | 124 | #ifdef __cplusplus 125 | } 126 | #endif 127 | 128 | #endif /* __USBD_CDC_IF_H__ */ 129 | 130 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 131 | -------------------------------------------------------------------------------- /STM32/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_DEBUG_LEVEL 0U 74 | /*---------- -----------*/ 75 | #define USBD_LPM_ENABLED 0U 76 | /*---------- -----------*/ 77 | #define USBD_SELF_POWERED 1U 78 | 79 | /****************************************/ 80 | /* #define for FS and HS identification */ 81 | #define DEVICE_FS 0 82 | #define DEVICE_HS 1 83 | 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros 89 | * @brief Aliases. 90 | * @{ 91 | */ 92 | 93 | /* Memory management macros */ 94 | 95 | /** Alias for memory allocation. */ 96 | #define USBD_malloc malloc 97 | 98 | /** Alias for memory release. */ 99 | #define USBD_free free 100 | 101 | /** Alias for memory set. */ 102 | #define USBD_memset memset 103 | 104 | /** Alias for memory copy. */ 105 | #define USBD_memcpy memcpy 106 | 107 | /** Alias for delay. */ 108 | #define USBD_Delay HAL_Delay 109 | 110 | /* DEBUG macros */ 111 | 112 | #if (USBD_DEBUG_LEVEL > 0) 113 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 114 | printf("\n"); 115 | #else 116 | #define USBD_UsrLog(...) 117 | #endif 118 | 119 | #if (USBD_DEBUG_LEVEL > 1) 120 | 121 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 122 | printf(__VA_ARGS__);\ 123 | printf("\n"); 124 | #else 125 | #define USBD_ErrLog(...) 126 | #endif 127 | 128 | #if (USBD_DEBUG_LEVEL > 2) 129 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 130 | printf(__VA_ARGS__);\ 131 | printf("\n"); 132 | #else 133 | #define USBD_DbgLog(...) 134 | #endif 135 | 136 | /** 137 | * @} 138 | */ 139 | 140 | /** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types 141 | * @brief Types. 142 | * @{ 143 | */ 144 | 145 | /** 146 | * @} 147 | */ 148 | 149 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype 150 | * @brief Declaration of public functions for Usb device. 151 | * @{ 152 | */ 153 | 154 | /* Exported functions -------------------------------------------------------*/ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** 161 | * @} 162 | */ 163 | 164 | /** 165 | * @} 166 | */ 167 | 168 | #ifdef __cplusplus 169 | } 170 | #endif 171 | 172 | #endif /* __USBD_CONF__H__ */ 173 | 174 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 175 | -------------------------------------------------------------------------------- /STM32/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 HS_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 | -------------------------------------------------------------------------------- /STM32/Inc/uuid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // STM32 factory-programmed UUID 4 | // Three 32 bit values: 5 | // UUID[0], UUID[1], UUID[2] 6 | 7 | #define UUID ((uint32_t const*)0x1FFF7A10) 8 | -------------------------------------------------------------------------------- /STM32/Inc/version.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 4 | // Product version information 5 | // 6 | 7 | #define VENDOR "OlegV" 8 | #define PRODUCT "All-Programmable System" 9 | #define VERSION "0.1" 10 | 11 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/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 | -------------------------------------------------------------------------------- /STM32/Src/main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2020 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 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | #include "usb_device.h" 24 | 25 | /* Private includes ----------------------------------------------------------*/ 26 | /* USER CODE BEGIN Includes */ 27 | #include "usb_tmc.h" 28 | #include "pl.h" 29 | /* USER CODE END Includes */ 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* USER CODE BEGIN PTD */ 33 | 34 | /* USER CODE END PTD */ 35 | 36 | /* Private define ------------------------------------------------------------*/ 37 | /* USER CODE BEGIN PD */ 38 | /* USER CODE END PD */ 39 | 40 | /* Private macro -------------------------------------------------------------*/ 41 | /* USER CODE BEGIN PM */ 42 | 43 | /* USER CODE END PM */ 44 | 45 | /* Private variables ---------------------------------------------------------*/ 46 | DCMI_HandleTypeDef hdcmi; 47 | DMA_HandleTypeDef hdma_dcmi; 48 | 49 | SPI_HandleTypeDef hspi3; 50 | 51 | /* USER CODE BEGIN PV */ 52 | 53 | /* USER CODE END PV */ 54 | 55 | /* Private function prototypes -----------------------------------------------*/ 56 | void SystemClock_Config(void); 57 | static void MX_GPIO_Init(void); 58 | static void MX_SPI3_Init(void); 59 | static void MX_DMA_Init(void); 60 | static void MX_DCMI_Init(void); 61 | /* USER CODE BEGIN PFP */ 62 | 63 | /* USER CODE END PFP */ 64 | 65 | /* Private user code ---------------------------------------------------------*/ 66 | /* USER CODE BEGIN 0 */ 67 | 68 | /* USER CODE END 0 */ 69 | 70 | /** 71 | * @brief The application entry point. 72 | * @retval int 73 | */ 74 | int main(void) 75 | { 76 | /* USER CODE BEGIN 1 */ 77 | 78 | /* USER CODE END 1 */ 79 | 80 | 81 | /* MCU Configuration--------------------------------------------------------*/ 82 | 83 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 84 | HAL_Init(); 85 | 86 | /* USER CODE BEGIN Init */ 87 | 88 | /* USER CODE END Init */ 89 | 90 | /* Configure the system clock */ 91 | SystemClock_Config(); 92 | 93 | /* USER CODE BEGIN SysInit */ 94 | USB_TMC_init(); 95 | /* USER CODE END SysInit */ 96 | 97 | /* Initialize all configured peripherals */ 98 | MX_GPIO_Init(); 99 | MX_USB_DEVICE_Init(); 100 | MX_SPI3_Init(); 101 | MX_DMA_Init(); 102 | MX_DCMI_Init(); 103 | /* USER CODE BEGIN 2 */ 104 | pl_start(); 105 | /* USER CODE END 2 */ 106 | 107 | /* Infinite loop */ 108 | /* USER CODE BEGIN WHILE */ 109 | while (1) 110 | { 111 | /* USER CODE END WHILE */ 112 | 113 | /* USER CODE BEGIN 3 */ 114 | USB_TMC_Process(); 115 | 116 | pl_process(); 117 | } 118 | /* USER CODE END 3 */ 119 | } 120 | 121 | /** 122 | * @brief System Clock Configuration 123 | * @retval None 124 | */ 125 | void SystemClock_Config(void) 126 | { 127 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 128 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 129 | 130 | /** Configure the main internal regulator output voltage 131 | */ 132 | __HAL_RCC_PWR_CLK_ENABLE(); 133 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); 134 | /** Initializes the CPU, AHB and APB busses clocks 135 | */ 136 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 137 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 138 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 139 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 140 | RCC_OscInitStruct.PLL.PLLM = 4; 141 | RCC_OscInitStruct.PLL.PLLN = 72; 142 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 143 | RCC_OscInitStruct.PLL.PLLQ = 3; 144 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 145 | { 146 | Error_Handler(); 147 | } 148 | /** Initializes the CPU, AHB and APB busses clocks 149 | */ 150 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 151 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 152 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 153 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 154 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 155 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 156 | 157 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) 158 | { 159 | Error_Handler(); 160 | } 161 | } 162 | 163 | /** 164 | * @brief DCMI Initialization Function 165 | * @param None 166 | * @retval None 167 | */ 168 | static void MX_DCMI_Init(void) 169 | { 170 | 171 | /* USER CODE BEGIN DCMI_Init 0 */ 172 | 173 | /* USER CODE END DCMI_Init 0 */ 174 | 175 | /* USER CODE BEGIN DCMI_Init 1 */ 176 | 177 | /* USER CODE END DCMI_Init 1 */ 178 | hdcmi.Instance = DCMI; 179 | hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE; 180 | hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_RISING; 181 | hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW; 182 | hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_HIGH; 183 | hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME; 184 | hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B; 185 | hdcmi.Init.JPEGMode = DCMI_JPEG_ENABLE; 186 | if (HAL_DCMI_Init(&hdcmi) != HAL_OK) 187 | { 188 | Error_Handler(); 189 | } 190 | /* USER CODE BEGIN DCMI_Init 2 */ 191 | 192 | /* USER CODE END DCMI_Init 2 */ 193 | 194 | } 195 | 196 | /** 197 | * @brief SPI3 Initialization Function 198 | * @param None 199 | * @retval None 200 | */ 201 | static void MX_SPI3_Init(void) 202 | { 203 | 204 | /* USER CODE BEGIN SPI3_Init 0 */ 205 | 206 | /* USER CODE END SPI3_Init 0 */ 207 | 208 | /* USER CODE BEGIN SPI3_Init 1 */ 209 | 210 | /* USER CODE END SPI3_Init 1 */ 211 | /* SPI3 parameter configuration*/ 212 | hspi3.Instance = SPI3; 213 | hspi3.Init.Mode = SPI_MODE_MASTER; 214 | hspi3.Init.Direction = SPI_DIRECTION_2LINES; 215 | hspi3.Init.DataSize = SPI_DATASIZE_8BIT; 216 | hspi3.Init.CLKPolarity = SPI_POLARITY_LOW; 217 | hspi3.Init.CLKPhase = SPI_PHASE_1EDGE; 218 | hspi3.Init.NSS = SPI_NSS_SOFT; 219 | hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; 220 | hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; 221 | hspi3.Init.TIMode = SPI_TIMODE_DISABLE; 222 | hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; 223 | hspi3.Init.CRCPolynomial = 10; 224 | if (HAL_SPI_Init(&hspi3) != HAL_OK) 225 | { 226 | Error_Handler(); 227 | } 228 | /* USER CODE BEGIN SPI3_Init 2 */ 229 | 230 | /* USER CODE END SPI3_Init 2 */ 231 | 232 | } 233 | 234 | /** 235 | * Enable DMA controller clock 236 | */ 237 | static void MX_DMA_Init(void) 238 | { 239 | 240 | /* DMA controller clock enable */ 241 | __HAL_RCC_DMA2_CLK_ENABLE(); 242 | 243 | /* DMA interrupt init */ 244 | /* DMA2_Stream1_IRQn interrupt configuration */ 245 | HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0); 246 | HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn); 247 | 248 | } 249 | 250 | /** 251 | * @brief GPIO Initialization Function 252 | * @param None 253 | * @retval None 254 | */ 255 | static void MX_GPIO_Init(void) 256 | { 257 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 258 | 259 | /* GPIO Ports Clock Enable */ 260 | __HAL_RCC_GPIOE_CLK_ENABLE(); 261 | __HAL_RCC_GPIOI_CLK_ENABLE(); 262 | __HAL_RCC_GPIOH_CLK_ENABLE(); 263 | __HAL_RCC_GPIOC_CLK_ENABLE(); 264 | __HAL_RCC_GPIOA_CLK_ENABLE(); 265 | __HAL_RCC_GPIOB_CLK_ENABLE(); 266 | __HAL_RCC_GPIOD_CLK_ENABLE(); 267 | 268 | /*Configure GPIO pin Output Level */ 269 | HAL_GPIO_WritePin(FFLASH_CS_GPIO_Port, FFLASH_CS_Pin, GPIO_PIN_SET); 270 | 271 | /*Configure GPIO pin Output Level */ 272 | HAL_GPIO_WritePin(PROGRAM_B_GPIO_Port, PROGRAM_B_Pin, GPIO_PIN_RESET); 273 | 274 | /*Configure GPIO pin Output Level */ 275 | HAL_GPIO_WritePin(PL_CS_GPIO_Port, PL_CS_Pin, GPIO_PIN_SET); 276 | 277 | /*Configure GPIO pin : FFLASH_CS_Pin */ 278 | GPIO_InitStruct.Pin = FFLASH_CS_Pin; 279 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 280 | GPIO_InitStruct.Pull = GPIO_NOPULL; 281 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 282 | HAL_GPIO_Init(FFLASH_CS_GPIO_Port, &GPIO_InitStruct); 283 | 284 | /*Configure GPIO pin : PROGRAM_B_Pin */ 285 | GPIO_InitStruct.Pin = PROGRAM_B_Pin; 286 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 287 | GPIO_InitStruct.Pull = GPIO_NOPULL; 288 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 289 | HAL_GPIO_Init(PROGRAM_B_GPIO_Port, &GPIO_InitStruct); 290 | 291 | /*Configure GPIO pin : DONE_Pin */ 292 | GPIO_InitStruct.Pin = DONE_Pin; 293 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 294 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; 295 | HAL_GPIO_Init(DONE_GPIO_Port, &GPIO_InitStruct); 296 | 297 | /*Configure GPIO pin : PL_CS_Pin */ 298 | GPIO_InitStruct.Pin = PL_CS_Pin; 299 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 300 | GPIO_InitStruct.Pull = GPIO_NOPULL; 301 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 302 | HAL_GPIO_Init(PL_CS_GPIO_Port, &GPIO_InitStruct); 303 | 304 | /*Configure GPIO pin : PL_SRQ_Pin */ 305 | GPIO_InitStruct.Pin = PL_SRQ_Pin; 306 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 307 | GPIO_InitStruct.Pull = GPIO_PULLUP; 308 | HAL_GPIO_Init(PL_SRQ_GPIO_Port, &GPIO_InitStruct); 309 | 310 | } 311 | 312 | /* USER CODE BEGIN 4 */ 313 | 314 | /* USER CODE END 4 */ 315 | 316 | /** 317 | * @brief This function is executed in case of error occurrence. 318 | * @retval None 319 | */ 320 | void Error_Handler(void) 321 | { 322 | /* USER CODE BEGIN Error_Handler_Debug */ 323 | /* User can add his own implementation to report the HAL error return state */ 324 | 325 | /* USER CODE END Error_Handler_Debug */ 326 | } 327 | 328 | #ifdef USE_FULL_ASSERT 329 | /** 330 | * @brief Reports the name of the source file and the source line number 331 | * where the assert_param error has occurred. 332 | * @param file: pointer to the source file name 333 | * @param line: assert_param error line source number 334 | * @retval None 335 | */ 336 | void assert_failed(uint8_t *file, uint32_t line) 337 | { 338 | /* USER CODE BEGIN 6 */ 339 | /* User can add his own implementation to report the file name and line number, 340 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 341 | /* USER CODE END 6 */ 342 | } 343 | #endif /* USE_FULL_ASSERT */ 344 | 345 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 346 | -------------------------------------------------------------------------------- /STM32/Src/pl.c: -------------------------------------------------------------------------------- 1 | #include "pl.h" 2 | #include "main.h" 3 | 4 | // The current PL status 5 | pl_status_t pl_status = pl_inactive; 6 | 7 | // Target PL status. May be set from ISR context and processed later. 8 | bool volatile pl_enable_ = false; 9 | 10 | // Initialize SPI interface to PL 11 | static inline void pl_iface_init(void) 12 | { 13 | HAL_SPI_MspInit(&hspi3); 14 | HAL_GPIO_WritePin(FFLASH_CS_GPIO_Port, FFLASH_CS_Pin, GPIO_PIN_SET); 15 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 16 | GPIO_InitStruct.Pin = FFLASH_CS_Pin; 17 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 18 | GPIO_InitStruct.Pull = GPIO_NOPULL; 19 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 20 | HAL_GPIO_Init(FFLASH_CS_GPIO_Port, &GPIO_InitStruct); 21 | } 22 | 23 | // De-initialize SPI interface to PL 24 | static inline void pl_iface_deinit(void) 25 | { 26 | HAL_GPIO_DeInit(FFLASH_CS_GPIO_Port, FFLASH_CS_Pin); 27 | HAL_SPI_MspDeInit(&hspi3); 28 | } 29 | 30 | // Reset PL by turning PROGRAM_B low 31 | static void pl_stop(void) 32 | { 33 | HAL_GPIO_WritePin(PROGRAM_B_GPIO_Port, PROGRAM_B_Pin, GPIO_PIN_RESET); 34 | if (pl_status != pl_configured) 35 | pl_iface_init(); 36 | pl_status = pl_inactive; 37 | } 38 | 39 | // Resume PL by turning PROGRAM_B high 40 | static void pl_resume(void) 41 | { 42 | pl_iface_deinit(); 43 | HAL_GPIO_WritePin(PROGRAM_B_GPIO_Port, PROGRAM_B_Pin, GPIO_PIN_SET); 44 | pl_status = pl_active; 45 | } 46 | 47 | // Start programmable logic configuration 48 | void pl_start(void) 49 | { 50 | pl_enable_ = true; 51 | pl_resume(); 52 | } 53 | 54 | // Enable / disable PL. May be called from ISR context. 55 | // The actual status switch will be performed within pl_process() call. 56 | void pl_enable(bool en) 57 | { 58 | pl_enable_ = en; 59 | } 60 | 61 | // Check PL status. Called periodically in the main() loop. 62 | void pl_process(void) 63 | { 64 | bool is_active = (pl_status != pl_inactive); 65 | bool enable = pl_enable_; 66 | if (is_active != enable) { 67 | if (enable) 68 | pl_resume(); 69 | else 70 | pl_stop(); 71 | } 72 | else if (pl_status == pl_active) { 73 | if (HAL_GPIO_ReadPin(DONE_GPIO_Port, DONE_Pin) == GPIO_PIN_RESET) 74 | return; 75 | pl_iface_init(); 76 | pl_status = pl_configured; 77 | } 78 | else if (pl_status == pl_configured) { 79 | if (HAL_GPIO_ReadPin(DONE_GPIO_Port, DONE_Pin) == GPIO_PIN_SET) 80 | return; 81 | // FPGA reset itself unexpectedly 82 | pl_stop(); 83 | } 84 | } 85 | 86 | // Error counter for debugging 87 | unsigned pl_tx_errors; 88 | 89 | // Perform transaction on SPI channel 90 | bool pl_tx(uint8_t* buff, unsigned len) 91 | { 92 | if (pl_status != pl_configured) { 93 | ++pl_tx_errors; 94 | return false; 95 | } 96 | HAL_GPIO_WritePin(PL_CS_GPIO_Port, PL_CS_Pin, GPIO_PIN_RESET); 97 | HAL_StatusTypeDef sta = HAL_SPI_TransmitReceive( 98 | &hspi3, buff, buff, len, HAL_MAX_DELAY 99 | ); 100 | HAL_GPIO_WritePin(PL_CS_GPIO_Port, PL_CS_Pin, GPIO_PIN_SET); 101 | if (sta != HAL_OK) { 102 | ++pl_tx_errors; 103 | return false; 104 | } 105 | return true; 106 | } 107 | 108 | // Start waiting for the DCMI data frame 109 | bool pl_start_pull(uint8_t* buff, unsigned len) 110 | { 111 | if (HAL_DCMI_GetState(&hdcmi) != HAL_DCMI_STATE_READY) { 112 | HAL_DCMI_Stop(&hdcmi); 113 | ++pl_tx_errors; 114 | } 115 | // The length must be the integral number of 32 bit words 116 | // In theory it should work with any frame length but in practice it does not 117 | if (len % 4 || HAL_OK != HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)buff, len / 4)) { 118 | ++pl_tx_errors; 119 | return false; 120 | } 121 | return true; 122 | } 123 | 124 | // Get DCMI data frame reception status 125 | pl_pull_status_t pl_get_pull_status(void) 126 | { 127 | switch (HAL_DCMI_GetState(&hdcmi)) { 128 | case HAL_DCMI_STATE_READY: 129 | return pl_pull_ready; 130 | case HAL_DCMI_STATE_BUSY: 131 | return pl_pull_busy; 132 | default: 133 | return pl_pull_failed; 134 | } 135 | } 136 | 137 | // Stop waiting for the DCMI data frame 138 | void pl_stop_pull(void) 139 | { 140 | HAL_DCMI_Stop(&hdcmi); 141 | } 142 | 143 | -------------------------------------------------------------------------------- /STM32/Src/pl_flash.c: -------------------------------------------------------------------------------- 1 | #include "pl_flash.h" 2 | #include "main.h" 3 | 4 | #include 5 | 6 | // Error counter for debugging 7 | unsigned pl_flash_errors; 8 | 9 | // Select / deselect flash 10 | static inline void pl_flash_cs(bool active) 11 | { 12 | HAL_GPIO_WritePin(FFLASH_CS_GPIO_Port, FFLASH_CS_Pin, active ? GPIO_PIN_RESET : GPIO_PIN_SET); 13 | } 14 | 15 | // Transmit data via SPI receiving response to the same buffer 16 | void pl_flash_tx(uint8_t *buff, unsigned len) 17 | { 18 | HAL_StatusTypeDef sta; 19 | pl_flash_cs(true); 20 | sta = HAL_SPI_TransmitReceive( 21 | &hspi3, buff, buff, len, HAL_MAX_DELAY 22 | ); 23 | pl_flash_cs(false); 24 | if (sta != HAL_OK) 25 | ++pl_flash_errors; 26 | } 27 | 28 | // Wait non-busy status. Returns the last status received from the flash. 29 | // So the FLASH_STATUS_BUSY will be set on result if operation is timed out. 30 | uint8_t pl_flash_wait(uint32_t tout) 31 | { 32 | HAL_StatusTypeDef sta; 33 | uint8_t cmd = 0x5, status = FLASH_STATUS_BUSY; 34 | uint32_t start = HAL_GetTick(); 35 | pl_flash_cs(true); 36 | sta = HAL_SPI_Transmit(&hspi3, &cmd, 1, HAL_MAX_DELAY); 37 | if (sta != HAL_OK) { 38 | ++pl_flash_errors; 39 | goto done; 40 | } 41 | for (;;) { 42 | sta = HAL_SPI_Receive(&hspi3, &status, 1, HAL_MAX_DELAY); 43 | if (sta != HAL_OK) { 44 | ++pl_flash_errors; 45 | goto done; 46 | } 47 | if (!(status & FLASH_STATUS_BUSY)) 48 | break; 49 | if (HAL_GetTick() - start > tout) 50 | break; 51 | } 52 | done: 53 | pl_flash_cs(false); 54 | return status; 55 | } 56 | -------------------------------------------------------------------------------- /STM32/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 | extern DMA_HandleTypeDef hdma_dcmi; 28 | 29 | /* Private typedef -----------------------------------------------------------*/ 30 | /* USER CODE BEGIN TD */ 31 | 32 | /* USER CODE END TD */ 33 | 34 | /* Private define ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN Define */ 36 | 37 | /* USER CODE END Define */ 38 | 39 | /* Private macro -------------------------------------------------------------*/ 40 | /* USER CODE BEGIN Macro */ 41 | 42 | /* USER CODE END Macro */ 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 | /* External functions --------------------------------------------------------*/ 55 | /* USER CODE BEGIN ExternalFunctions */ 56 | 57 | /* USER CODE END ExternalFunctions */ 58 | 59 | /* USER CODE BEGIN 0 */ 60 | 61 | /* USER CODE END 0 */ 62 | /** 63 | * Initializes the Global MSP. 64 | */ 65 | void HAL_MspInit(void) 66 | { 67 | /* USER CODE BEGIN MspInit 0 */ 68 | 69 | /* USER CODE END MspInit 0 */ 70 | 71 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 72 | __HAL_RCC_PWR_CLK_ENABLE(); 73 | 74 | /* System interrupt init*/ 75 | 76 | /* USER CODE BEGIN MspInit 1 */ 77 | 78 | /* USER CODE END MspInit 1 */ 79 | } 80 | 81 | /** 82 | * @brief DCMI MSP Initialization 83 | * This function configures the hardware resources used in this example 84 | * @param hdcmi: DCMI handle pointer 85 | * @retval None 86 | */ 87 | void HAL_DCMI_MspInit(DCMI_HandleTypeDef* hdcmi) 88 | { 89 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 90 | if(hdcmi->Instance==DCMI) 91 | { 92 | /* USER CODE BEGIN DCMI_MspInit 0 */ 93 | 94 | /* USER CODE END DCMI_MspInit 0 */ 95 | /* Peripheral clock enable */ 96 | __HAL_RCC_DCMI_CLK_ENABLE(); 97 | 98 | __HAL_RCC_GPIOE_CLK_ENABLE(); 99 | __HAL_RCC_GPIOA_CLK_ENABLE(); 100 | __HAL_RCC_GPIOH_CLK_ENABLE(); 101 | __HAL_RCC_GPIOB_CLK_ENABLE(); 102 | /**DCMI GPIO Configuration 103 | PE4 ------> DCMI_D4 104 | PE5 ------> DCMI_D6 105 | PE6 ------> DCMI_D7 106 | PA4 ------> DCMI_HSYNC 107 | PA6 ------> DCMI_PIXCLK 108 | PH9 ------> DCMI_D0 109 | PH10 ------> DCMI_D1 110 | PH11 ------> DCMI_D2 111 | PH12 ------> DCMI_D3 112 | PB6 ------> DCMI_D5 113 | PB7 ------> DCMI_VSYNC 114 | */ 115 | GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6; 116 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 117 | GPIO_InitStruct.Pull = GPIO_NOPULL; 118 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 119 | GPIO_InitStruct.Alternate = GPIO_AF13_DCMI; 120 | HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); 121 | 122 | GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_6; 123 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 124 | GPIO_InitStruct.Pull = GPIO_PULLUP; 125 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 126 | GPIO_InitStruct.Alternate = GPIO_AF13_DCMI; 127 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 128 | 129 | GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; 130 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 131 | GPIO_InitStruct.Pull = GPIO_NOPULL; 132 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 133 | GPIO_InitStruct.Alternate = GPIO_AF13_DCMI; 134 | HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); 135 | 136 | GPIO_InitStruct.Pin = GPIO_PIN_6; 137 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 138 | GPIO_InitStruct.Pull = GPIO_NOPULL; 139 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 140 | GPIO_InitStruct.Alternate = GPIO_AF13_DCMI; 141 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 142 | 143 | GPIO_InitStruct.Pin = GPIO_PIN_7; 144 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 145 | GPIO_InitStruct.Pull = GPIO_PULLUP; 146 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 147 | GPIO_InitStruct.Alternate = GPIO_AF13_DCMI; 148 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 149 | 150 | /* DCMI DMA Init */ 151 | /* DCMI Init */ 152 | hdma_dcmi.Instance = DMA2_Stream1; 153 | hdma_dcmi.Init.Channel = DMA_CHANNEL_1; 154 | hdma_dcmi.Init.Direction = DMA_PERIPH_TO_MEMORY; 155 | hdma_dcmi.Init.PeriphInc = DMA_PINC_DISABLE; 156 | hdma_dcmi.Init.MemInc = DMA_MINC_ENABLE; 157 | hdma_dcmi.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; 158 | hdma_dcmi.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; 159 | hdma_dcmi.Init.Mode = DMA_NORMAL; 160 | hdma_dcmi.Init.Priority = DMA_PRIORITY_LOW; 161 | hdma_dcmi.Init.FIFOMode = DMA_FIFOMODE_DISABLE; 162 | if (HAL_DMA_Init(&hdma_dcmi) != HAL_OK) 163 | { 164 | Error_Handler(); 165 | } 166 | 167 | __HAL_LINKDMA(hdcmi,DMA_Handle,hdma_dcmi); 168 | 169 | /* USER CODE BEGIN DCMI_MspInit 1 */ 170 | 171 | /* USER CODE END DCMI_MspInit 1 */ 172 | } 173 | 174 | } 175 | 176 | /** 177 | * @brief DCMI MSP De-Initialization 178 | * This function freeze the hardware resources used in this example 179 | * @param hdcmi: DCMI handle pointer 180 | * @retval None 181 | */ 182 | void HAL_DCMI_MspDeInit(DCMI_HandleTypeDef* hdcmi) 183 | { 184 | if(hdcmi->Instance==DCMI) 185 | { 186 | /* USER CODE BEGIN DCMI_MspDeInit 0 */ 187 | 188 | /* USER CODE END DCMI_MspDeInit 0 */ 189 | /* Peripheral clock disable */ 190 | __HAL_RCC_DCMI_CLK_DISABLE(); 191 | 192 | /**DCMI GPIO Configuration 193 | PE4 ------> DCMI_D4 194 | PE5 ------> DCMI_D6 195 | PE6 ------> DCMI_D7 196 | PA4 ------> DCMI_HSYNC 197 | PA6 ------> DCMI_PIXCLK 198 | PH9 ------> DCMI_D0 199 | PH10 ------> DCMI_D1 200 | PH11 ------> DCMI_D2 201 | PH12 ------> DCMI_D3 202 | PB6 ------> DCMI_D5 203 | PB7 ------> DCMI_VSYNC 204 | */ 205 | HAL_GPIO_DeInit(GPIOE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6); 206 | 207 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_6); 208 | 209 | HAL_GPIO_DeInit(GPIOH, GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12); 210 | 211 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7); 212 | 213 | /* DCMI DMA DeInit */ 214 | HAL_DMA_DeInit(hdcmi->DMA_Handle); 215 | /* USER CODE BEGIN DCMI_MspDeInit 1 */ 216 | 217 | /* USER CODE END DCMI_MspDeInit 1 */ 218 | } 219 | 220 | } 221 | 222 | /** 223 | * @brief SPI MSP Initialization 224 | * This function configures the hardware resources used in this example 225 | * @param hspi: SPI handle pointer 226 | * @retval None 227 | */ 228 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 229 | { 230 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 231 | if(hspi->Instance==SPI3) 232 | { 233 | /* USER CODE BEGIN SPI3_MspInit 0 */ 234 | 235 | /* USER CODE END SPI3_MspInit 0 */ 236 | /* Peripheral clock enable */ 237 | __HAL_RCC_SPI3_CLK_ENABLE(); 238 | 239 | __HAL_RCC_GPIOC_CLK_ENABLE(); 240 | /**SPI3 GPIO Configuration 241 | PC10 ------> SPI3_SCK 242 | PC11 ------> SPI3_MISO 243 | PC12 ------> SPI3_MOSI 244 | */ 245 | GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; 246 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 247 | GPIO_InitStruct.Pull = GPIO_NOPULL; 248 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 249 | GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; 250 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 251 | 252 | /* USER CODE BEGIN SPI3_MspInit 1 */ 253 | 254 | /* USER CODE END SPI3_MspInit 1 */ 255 | } 256 | 257 | } 258 | 259 | /** 260 | * @brief SPI MSP De-Initialization 261 | * This function freeze the hardware resources used in this example 262 | * @param hspi: SPI handle pointer 263 | * @retval None 264 | */ 265 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 266 | { 267 | if(hspi->Instance==SPI3) 268 | { 269 | /* USER CODE BEGIN SPI3_MspDeInit 0 */ 270 | 271 | /* USER CODE END SPI3_MspDeInit 0 */ 272 | /* Peripheral clock disable */ 273 | __HAL_RCC_SPI3_CLK_DISABLE(); 274 | 275 | /**SPI3 GPIO Configuration 276 | PC10 ------> SPI3_SCK 277 | PC11 ------> SPI3_MISO 278 | PC12 ------> SPI3_MOSI 279 | */ 280 | HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12); 281 | 282 | /* USER CODE BEGIN SPI3_MspDeInit 1 */ 283 | 284 | /* USER CODE END SPI3_MspDeInit 1 */ 285 | } 286 | 287 | } 288 | 289 | /* USER CODE BEGIN 1 */ 290 | 291 | /* USER CODE END 1 */ 292 | 293 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 294 | -------------------------------------------------------------------------------- /STM32/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 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 | * www.st.com/SLA0044 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 | /* 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 PD */ 35 | 36 | /* USER CODE END PD */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN PM */ 40 | 41 | /* USER CODE END PM */ 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 | /* Private user code ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN 0 */ 55 | 56 | /* USER CODE END 0 */ 57 | 58 | /* External variables --------------------------------------------------------*/ 59 | extern PCD_HandleTypeDef hpcd_USB_OTG_HS; 60 | extern DMA_HandleTypeDef hdma_dcmi; 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 DMA2 stream1 global interrupt. 203 | */ 204 | void DMA2_Stream1_IRQHandler(void) 205 | { 206 | /* USER CODE BEGIN DMA2_Stream1_IRQn 0 */ 207 | 208 | /* USER CODE END DMA2_Stream1_IRQn 0 */ 209 | HAL_DMA_IRQHandler(&hdma_dcmi); 210 | /* USER CODE BEGIN DMA2_Stream1_IRQn 1 */ 211 | 212 | /* USER CODE END DMA2_Stream1_IRQn 1 */ 213 | } 214 | 215 | /** 216 | * @brief This function handles USB On The Go HS End Point 1 Out global interrupt. 217 | */ 218 | void OTG_HS_EP1_OUT_IRQHandler(void) 219 | { 220 | /* USER CODE BEGIN OTG_HS_EP1_OUT_IRQn 0 */ 221 | 222 | /* USER CODE END OTG_HS_EP1_OUT_IRQn 0 */ 223 | HAL_PCD_IRQHandler(&hpcd_USB_OTG_HS); 224 | /* USER CODE BEGIN OTG_HS_EP1_OUT_IRQn 1 */ 225 | 226 | /* USER CODE END OTG_HS_EP1_OUT_IRQn 1 */ 227 | } 228 | 229 | /** 230 | * @brief This function handles USB On The Go HS End Point 1 In global interrupt. 231 | */ 232 | void OTG_HS_EP1_IN_IRQHandler(void) 233 | { 234 | /* USER CODE BEGIN OTG_HS_EP1_IN_IRQn 0 */ 235 | 236 | /* USER CODE END OTG_HS_EP1_IN_IRQn 0 */ 237 | HAL_PCD_IRQHandler(&hpcd_USB_OTG_HS); 238 | /* USER CODE BEGIN OTG_HS_EP1_IN_IRQn 1 */ 239 | 240 | /* USER CODE END OTG_HS_EP1_IN_IRQn 1 */ 241 | } 242 | 243 | /** 244 | * @brief This function handles USB On The Go HS global interrupt. 245 | */ 246 | void OTG_HS_IRQHandler(void) 247 | { 248 | /* USER CODE BEGIN OTG_HS_IRQn 0 */ 249 | 250 | /* USER CODE END OTG_HS_IRQn 0 */ 251 | HAL_PCD_IRQHandler(&hpcd_USB_OTG_HS); 252 | /* USER CODE BEGIN OTG_HS_IRQn 1 */ 253 | 254 | /* USER CODE END OTG_HS_IRQn 1 */ 255 | } 256 | 257 | /* USER CODE BEGIN 1 */ 258 | 259 | /* USER CODE END 1 */ 260 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 261 | -------------------------------------------------------------------------------- /STM32/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_cdc.h" 28 | #include "usbd_cdc_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 hUsbDeviceHS; 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(&hUsbDeviceHS, &HS_Desc, DEVICE_HS) != USBD_OK) 73 | { 74 | Error_Handler(); 75 | } 76 | if (USBD_RegisterClass(&hUsbDeviceHS, &USBD_CDC) != USBD_OK) 77 | { 78 | Error_Handler(); 79 | } 80 | if (USBD_CDC_RegisterInterface(&hUsbDeviceHS, &USBD_Interface_fops_HS) != USBD_OK) 81 | { 82 | Error_Handler(); 83 | } 84 | if (USBD_Start(&hUsbDeviceHS) != 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 | -------------------------------------------------------------------------------- /STM32/Src/usbd_cdc_if.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : usbd_cdc_if.c 5 | * @version : v1.0_Cube 6 | * @brief : Usb device for Virtual Com Port. 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_cdc_if.h" 24 | 25 | /* USER CODE BEGIN INCLUDE */ 26 | #include "usb_tmc_proto.h" 27 | #include "usb_tmc.h" 28 | #include 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 library. 42 | * @{ 43 | */ 44 | 45 | /** @addtogroup USBD_CDC_IF 46 | * @{ 47 | */ 48 | 49 | /** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions 50 | * @brief Private types. 51 | * @{ 52 | */ 53 | 54 | /* USER CODE BEGIN PRIVATE_TYPES */ 55 | 56 | /* USER CODE END PRIVATE_TYPES */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines 63 | * @brief Private defines. 64 | * @{ 65 | */ 66 | 67 | /* USER CODE BEGIN PRIVATE_DEFINES */ 68 | /* Define size for the receive and transmit buffer over CDC */ 69 | /* It's up to user to redefine and/or remove those define */ 70 | #define APP_RX_DATA_SIZE (USB_TMC_HDR_SZ + USB_TMC_RX_MAX_DATA_SZ) 71 | #define APP_TX_DATA_SIZE (USB_TMC_HDR_SZ + USB_TMC_TX_MAX_DATA_SZ) 72 | 73 | /* USER CODE END PRIVATE_DEFINES */ 74 | 75 | /** 76 | * @} 77 | */ 78 | 79 | /** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros 80 | * @brief Private macros. 81 | * @{ 82 | */ 83 | 84 | /* USER CODE BEGIN PRIVATE_MACRO */ 85 | 86 | /* USER CODE END PRIVATE_MACRO */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables 93 | * @brief Private variables. 94 | * @{ 95 | */ 96 | 97 | /* Create buffer for reception and transmission */ 98 | /* It's up to user to redefine and/or remove those define */ 99 | /** Received data over USB are stored in this buffer */ 100 | uint8_t UserRxBufferHS[APP_RX_DATA_SIZE]; 101 | 102 | /** Data to send over USB CDC are stored in this buffer */ 103 | uint8_t UserTxBufferHS[APP_TX_DATA_SIZE]; 104 | 105 | /* USER CODE BEGIN PRIVATE_VARIABLES */ 106 | 107 | /* USER CODE END PRIVATE_VARIABLES */ 108 | 109 | /** 110 | * @} 111 | */ 112 | 113 | /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables 114 | * @brief Public variables. 115 | * @{ 116 | */ 117 | 118 | extern USBD_HandleTypeDef hUsbDeviceHS; 119 | 120 | /* USER CODE BEGIN EXPORTED_VARIABLES */ 121 | 122 | /* USER CODE END EXPORTED_VARIABLES */ 123 | 124 | /** 125 | * @} 126 | */ 127 | 128 | /** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes 129 | * @brief Private functions declaration. 130 | * @{ 131 | */ 132 | 133 | static int8_t CDC_Init_HS(void); 134 | static int8_t CDC_DeInit_HS(void); 135 | static int8_t CDC_Control_HS(uint8_t cmd, uint8_t* pbuf, uint16_t length); 136 | static int8_t CDC_Receive_HS(uint8_t* pbuf, uint32_t *Len); 137 | 138 | /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ 139 | 140 | // Error counters for debug 141 | unsigned usb_tmc_rx_ignored = 0; 142 | unsigned usb_tmc_tx_invalid = 0; 143 | unsigned usb_tmc_tx_busy = 0; 144 | 145 | uint8_t* USB_TMC_TxDataBuffer(void) 146 | { 147 | return UserTxBufferHS + USB_TMC_HDR_SZ; 148 | } 149 | 150 | /* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | USBD_CDC_ItfTypeDef USBD_Interface_fops_HS = 157 | { 158 | CDC_Init_HS, 159 | CDC_DeInit_HS, 160 | CDC_Control_HS, 161 | CDC_Receive_HS 162 | }; 163 | 164 | /* Private functions ---------------------------------------------------------*/ 165 | 166 | /** 167 | * @brief Initializes the CDC media low layer over the USB HS IP 168 | * @retval USBD_OK if all operations are OK else USBD_FAIL 169 | */ 170 | static int8_t CDC_Init_HS(void) 171 | { 172 | /* USER CODE BEGIN 8 */ 173 | /* Set Application Buffers */ 174 | USBD_CDC_SetTxBuffer(&hUsbDeviceHS, UserTxBufferHS, 0); 175 | USBD_CDC_SetRxBuffer(&hUsbDeviceHS, UserRxBufferHS); 176 | return (USBD_OK); 177 | /* USER CODE END 8 */ 178 | } 179 | 180 | /** 181 | * @brief DeInitializes the CDC media low layer 182 | * @param None 183 | * @retval USBD_OK if all operations are OK else USBD_FAIL 184 | */ 185 | static int8_t CDC_DeInit_HS(void) 186 | { 187 | /* USER CODE BEGIN 9 */ 188 | return (USBD_OK); 189 | /* USER CODE END 9 */ 190 | } 191 | 192 | /** 193 | * @brief Manage the CDC class requests 194 | * @param cmd: Command code 195 | * @param pbuf: Buffer containing command data (request parameters) 196 | * @param length: Number of data to be sent (in bytes) 197 | * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL 198 | */ 199 | static int8_t CDC_Control_HS(uint8_t cmd, uint8_t* pbuf, uint16_t length) 200 | { 201 | /* USER CODE BEGIN 10 */ 202 | switch(cmd) 203 | { 204 | case USB_TMC_GET_CAPABILITIES: 205 | pbuf[0] = USB_TMC_STATUS_SUCCESS; 206 | pbuf[1] = 0; 207 | pbuf[2] = 0; 208 | pbuf[3] = 1; // Version 1.0 209 | pbuf[4] = 0; 210 | pbuf[5] = 0; 211 | pbuf[6] = 0; 212 | pbuf[7] = 0; 213 | pbuf[8] = 0; 214 | pbuf[9] = 0; 215 | pbuf[10] = 0; 216 | pbuf[11] = 0; 217 | pbuf[12] = 0; 218 | break; 219 | 220 | default: 221 | break; 222 | } 223 | return (USBD_OK); 224 | /* USER CODE END 10 */ 225 | } 226 | 227 | /** 228 | * @brief Data received over USB OUT endpoint are sent over CDC interface 229 | * through this function. 230 | * 231 | * @note 232 | * This function will block any OUT packet reception on USB endpoint 233 | * untill exiting this function. If you exit this function before transfer 234 | * is complete on CDC interface (ie. using DMA controller) it will result 235 | * in receiving more data while previous ones are still not sent. 236 | * 237 | * @param Buf: Buffer of data to be received 238 | * @param Len: Number of data received (in bytes) 239 | * @retval USBD_OK if all operations are OK else USBD_FAIL 240 | */ 241 | static int8_t CDC_Receive_HS(uint8_t* Buf, uint32_t *Len) 242 | { 243 | /* USER CODE BEGIN 11 */ 244 | uint8_t msg_type = UserRxBufferHS[0]; 245 | uint32_t msg_len = *(uint32_t*)(UserRxBufferHS + 4); 246 | uint8_t* rx_buff = UserRxBufferHS; 247 | if ( 248 | (msg_type != USB_TMC_DEV_DEP_MSG_OUT && msg_type != USB_TMC_REQUEST_DEV_DEP_MSG_IN) || 249 | (0xff ^ UserRxBufferHS[1] ^ UserRxBufferHS[2]) || UserRxBufferHS[3] != 0 250 | ) { 251 | // Ignore bad packets 252 | ++usb_tmc_rx_ignored; 253 | goto rx_restart; 254 | } 255 | 256 | if (msg_type == USB_TMC_DEV_DEP_MSG_OUT) { 257 | if (msg_len > USB_TMC_RX_MAX_DATA_SZ) { 258 | // Ignore bad packets 259 | ++usb_tmc_rx_ignored; 260 | goto rx_restart; 261 | } 262 | if (Buf + *Len >= UserRxBufferHS + USB_TMC_HDR_SZ + msg_len) { 263 | // packet receive competed 264 | USB_TMC_Receive(UserRxBufferHS + USB_TMC_HDR_SZ, msg_len); 265 | } else if (Buf + *Len + USB_HS_MAX_PACKET_SIZE <= UserRxBufferHS + sizeof(UserRxBufferHS)) { 266 | // receive more 267 | rx_buff = Buf + *Len; 268 | } else { 269 | ++usb_tmc_rx_ignored; 270 | } 271 | } else { 272 | // msg_type == USB_TMC_REQUEST_DEV_DEP_MSG_IN 273 | if (msg_len > USB_TMC_TX_MAX_DATA_SZ) 274 | msg_len = USB_TMC_TX_MAX_DATA_SZ; 275 | USB_TMC_RequestResponse(UserRxBufferHS[1], msg_len); 276 | } 277 | 278 | rx_restart: 279 | USBD_CDC_SetRxBuffer(&hUsbDeviceHS, rx_buff); 280 | USBD_CDC_ReceivePacket(&hUsbDeviceHS); 281 | return (USBD_OK); 282 | /* USER CODE END 11 */ 283 | } 284 | 285 | /** 286 | * @brief Data to send over USB IN endpoint are sent over CDC interface 287 | * through this function. 288 | * @param Buf: Buffer of data to be sent 289 | * @param Len: Number of data to be sent (in bytes) 290 | * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY 291 | */ 292 | uint8_t CDC_Transmit_HS(uint8_t* Buf, uint16_t Len) 293 | { 294 | uint8_t result = USBD_OK; 295 | /* USER CODE BEGIN 12 */ 296 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceHS.pClassData; 297 | if (hcdc->TxState != 0){ 298 | return USBD_BUSY; 299 | } 300 | USBD_CDC_SetTxBuffer(&hUsbDeviceHS, Buf, Len); 301 | result = USBD_CDC_TransmitPacket(&hUsbDeviceHS); 302 | /* USER CODE END 12 */ 303 | return result; 304 | } 305 | 306 | /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ 307 | 308 | uint8_t USB_TMC_Reply(unsigned len, uint8_t tag) 309 | { 310 | if (len > USB_TMC_TX_MAX_DATA_SZ) { 311 | ++usb_tmc_tx_invalid; 312 | return USBD_FAIL; 313 | } 314 | 315 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceHS.pClassData; 316 | if (hcdc->TxState != 0) { 317 | ++usb_tmc_tx_busy; 318 | return USBD_BUSY; 319 | } 320 | 321 | UserTxBufferHS[0] = USB_TMC_DEV_DEP_MSG_IN; 322 | UserTxBufferHS[1] = tag; 323 | UserTxBufferHS[2] = ~tag; 324 | UserTxBufferHS[3] = 0; 325 | *(uint32_t*)(UserTxBufferHS + 4) = len; 326 | *(uint32_t*)(UserTxBufferHS + 8) = 1; 327 | 328 | USBD_CDC_SetTxBuffer(&hUsbDeviceHS, UserTxBufferHS, USB_TMC_HDR_SZ + len); 329 | return USBD_CDC_TransmitPacket(&hUsbDeviceHS); 330 | } 331 | 332 | /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ 333 | 334 | /** 335 | * @} 336 | */ 337 | 338 | /** 339 | * @} 340 | */ 341 | 342 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 343 | -------------------------------------------------------------------------------- /doc/Spartan6Configuration.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/Spartan6Configuration.pdf -------------------------------------------------------------------------------- /doc/USBTMC_1_00.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/USBTMC_1_00.pdf -------------------------------------------------------------------------------- /doc/XCore407I-Schematic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/XCore407I-Schematic.pdf -------------------------------------------------------------------------------- /doc/XME0601SCH.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/XME0601SCH.pdf -------------------------------------------------------------------------------- /doc/prototype.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/prototype.jpg -------------------------------------------------------------------------------- /doc/schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/schematic.png -------------------------------------------------------------------------------- /doc/schematic.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/schematic.vsdx -------------------------------------------------------------------------------- /doc/scpi-99.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/scpi-99.pdf -------------------------------------------------------------------------------- /doc/stm32f407ig.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/stm32f407ig.pdf -------------------------------------------------------------------------------- /doc/usbtmc_usb488_subclass_1_00.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/usbtmc_usb488_subclass_1_00.pdf -------------------------------------------------------------------------------- /doc/w25q16jv.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/doc/w25q16jv.pdf -------------------------------------------------------------------------------- /hdl/lib/dcmi_util.v: -------------------------------------------------------------------------------- 1 | `timescale 1ns / 1ps 2 | 3 | // 4 | // Make output clock by dividing it to power of 2 5 | // 6 | module DCMIClkGen 7 | #( 8 | parameter DIV_BITS = 1 9 | ) 10 | ( 11 | output DCLK, // DCMI output clock 12 | output CLKEN, // One CLK period strobe for updating DCMI output 13 | 14 | // Global clock 15 | input CLK 16 | ); 17 | 18 | reg [DIV_BITS-1:0] clk_div; 19 | assign CLKEN = &clk_div; 20 | assign DCLK = clk_div[DIV_BITS-1]; 21 | 22 | always @(posedge CLK) 23 | begin 24 | clk_div <= clk_div + 1; 25 | end 26 | 27 | endmodule 28 | 29 | // 30 | // The DCMITester transmits packet filled with incrementing counter bytes starting from zero 31 | // 32 | module DCMITester 33 | #( 34 | parameter LEN_BITS = 2 // Packet length bits 35 | ) 36 | ( 37 | // Frame start trigger 38 | input TX_START, 39 | // DCMI master interface 40 | output [7:0] DATA, 41 | output DSYNC, 42 | input CLKEN, 43 | // Global clock 44 | input CLK 45 | ); 46 | 47 | reg tx_trig; 48 | reg tx_active = 0; 49 | reg [LEN_BITS-1:0] cnt; 50 | 51 | assign DATA = tx_active ? cnt : 8'b0; 52 | assign DSYNC = tx_active; 53 | 54 | always @(posedge CLK) 55 | begin 56 | if (CLKEN) 57 | tx_trig <= 0; 58 | if (TX_START) begin 59 | cnt <= 0; 60 | tx_trig <= 1; 61 | end 62 | if (CLKEN) begin 63 | if (tx_trig) 64 | tx_active <= 1; 65 | if (tx_active) 66 | cnt <= cnt + 1; 67 | if (&cnt) 68 | tx_active <= 0; 69 | end 70 | end 71 | 72 | endmodule 73 | 74 | 75 | // 76 | // The DCMI transmitter with buffer that can be filled with data 77 | // by writing bytes sequentially. Output the same amount of data 78 | // that were written to the buffer. 79 | // 80 | 81 | module DCMITxBuffer 82 | #( 83 | parameter LEN_BITS = 10 84 | ) 85 | ( 86 | // Data input API 87 | input [7:0] DI, // Data input 88 | input WR, // Write enable 89 | input RST, // Write pointer reset 90 | 91 | // Frame start trigger 92 | input TX_START, 93 | 94 | // DCMI master interface 95 | output [7:0] DATA, 96 | output DSYNC, 97 | input CLKEN, // One CLK period strobe for updating DCMI output 98 | 99 | // Global clock 100 | input CLK 101 | ); 102 | 103 | localparam BUFF_SZ = 1 << LEN_BITS; 104 | reg [7:0] data_buff[0:BUFF_SZ-1]; 105 | reg [LEN_BITS-1:0] data_addr; 106 | 107 | reg tx_trig; 108 | reg tx_active = 0; 109 | reg [7:0] data_out; 110 | reg [LEN_BITS-1:0] data_len; 111 | 112 | assign DATA = tx_active ? data_out : 8'b0; 113 | assign DSYNC = tx_active; 114 | 115 | always @(posedge CLK) 116 | begin 117 | if (RST) 118 | data_addr <= 0; 119 | if (WR) begin 120 | data_buff[data_addr] <= DI; 121 | data_addr <= data_addr + 1; 122 | end 123 | if (TX_START) begin 124 | tx_trig <= 1; 125 | data_len <= data_addr; 126 | data_addr <= 0; 127 | end 128 | if (CLKEN) begin 129 | if (tx_trig) begin 130 | tx_trig <= 0; 131 | tx_active <= 1; 132 | data_out <= data_buff[data_addr]; 133 | data_addr <= data_addr + 1; 134 | end 135 | if (tx_active) begin 136 | data_out <= data_buff[data_addr]; 137 | if (data_addr == data_len) 138 | tx_active <= 0; 139 | data_addr <= data_addr + 1; 140 | end 141 | end 142 | end 143 | 144 | endmodule 145 | 146 | // 147 | // The DCMI transmitter capturing full buffer of bytes on rising edge of the TRIG. 148 | // Can be used as chip scope for in-system debugging. 149 | // 150 | 151 | module DCMICaptureBuffer 152 | #( 153 | parameter LEN_BITS = 12, 154 | parameter DELAY = 8 155 | ) 156 | ( 157 | input [7:0] DI, // Data input 158 | input TRIG, // Capture starts on rising edge 159 | 160 | // DCMI frame transmit start trigger 161 | input TX_START, 162 | 163 | // DCMI master interface 164 | output [7:0] DATA, 165 | output DSYNC, 166 | input CLKEN, // One CLK period strobe for updating DCMI output 167 | 168 | // Global clock 169 | input CLK 170 | ); 171 | 172 | localparam BUFF_SZ = 1 << LEN_BITS; 173 | reg [7:0] data_buff[0:BUFF_SZ-1]; 174 | reg [LEN_BITS-1:0] data_addr = 0; 175 | 176 | reg buff_full = 0; 177 | reg start_req = 0; 178 | reg tx_trig = 0; 179 | reg tx_active = 0; 180 | reg [7:0] data_out; 181 | 182 | assign DATA = tx_active ? data_out : 8'b0; 183 | assign DSYNC = tx_active; 184 | 185 | integer i; 186 | reg [7:0] data_delay[0:DELAY-1]; 187 | wire [7:0] data_delayed = data_delay[DELAY-1]; 188 | 189 | reg last_capture; 190 | wire capturing = !buff_full && (data_addr != 0); 191 | wire ready_to_capture = ~buff_full & ~capturing; 192 | 193 | always @(posedge CLK) 194 | begin 195 | data_delay[0] <= DI; 196 | for (i = 1; i < DELAY; i = i + 1) 197 | data_delay[i] <= data_delay[i-1]; 198 | end 199 | 200 | always @(posedge CLK) 201 | begin 202 | last_capture <= TRIG; 203 | end 204 | 205 | wire capture_trigger = TRIG & ~last_capture; 206 | 207 | always @(posedge CLK) 208 | begin 209 | if (ready_to_capture && capture_trigger) begin 210 | data_buff[data_addr] <= data_delayed; 211 | data_addr <= data_addr + 1; 212 | end 213 | if (capturing) begin 214 | data_buff[data_addr] <= data_delayed; 215 | data_addr <= data_addr + 1; 216 | if (&data_addr) 217 | buff_full <= 1; 218 | end 219 | if (TX_START) 220 | start_req <= 1; 221 | if (CLKEN) begin 222 | if (start_req && buff_full) begin 223 | start_req <= 0; 224 | tx_trig <= 1; 225 | data_addr <= 0; 226 | end 227 | if (tx_trig) begin 228 | tx_trig <= 0; 229 | tx_active <= 1; 230 | data_out <= data_buff[data_addr]; 231 | data_addr <= data_addr + 1; 232 | end 233 | if (tx_active) begin 234 | data_out <= data_buff[data_addr]; 235 | if (data_addr == 0) begin 236 | tx_active <= 0; 237 | buff_full <= 0; 238 | end else 239 | data_addr <= data_addr + 1; 240 | end 241 | end 242 | end 243 | 244 | endmodule 245 | -------------------------------------------------------------------------------- /hdl/lib/spi_gate.v: -------------------------------------------------------------------------------- 1 | // 2 | // The SPI gateway to host controller 3 | // 4 | 5 | module SPIGate( 6 | // Host interface 7 | input SCLK, 8 | input MOSI, 9 | output MISO, 10 | input nCS, 11 | // Internal bus 12 | output [7:0] RXD, // Data received from the host 13 | input [7:0] TXD, // Data to be transmitted to the host 14 | output [7:0] ADDR, // Port address received from the host 15 | output SEL, // Port selected. Become active when the the address is valid. Reset after host deselect interface on transfer completion. 16 | output RXE, // Receive enable. If active, receiving port should latch RXD on rising edge of the clock. 17 | // Global clock 18 | input CLK 19 | ); 20 | 21 | parameter CS_FLT_TAPS = 3; 22 | 23 | reg [CS_FLT_TAPS-1:0] cs_flt; 24 | reg cs_in; 25 | 26 | reg sclk_in; 27 | reg data_in; 28 | reg last_sclk; 29 | 30 | always @(posedge CLK) 31 | begin 32 | cs_flt <= {cs_flt[CS_FLT_TAPS-2:0], ~nCS}; 33 | if (cs_flt == 'b1) 34 | cs_in <= 1; 35 | if (cs_flt == 'b0) 36 | cs_in <= 0; 37 | sclk_in <= SCLK; 38 | data_in <= MOSI; 39 | last_sclk <= sclk_in; 40 | end 41 | 42 | wire sclk_edge = sclk_in && sclk_in != last_sclk; 43 | 44 | reg[7:0] address; 45 | reg[3:0] address_bits; 46 | wire address_valid = address_bits[3]; 47 | 48 | always @(posedge CLK) 49 | begin 50 | if (!cs_in) 51 | address_bits <= 0; 52 | else if (!address_valid && sclk_edge) begin 53 | address <= {address[6:0], data_in}; 54 | address_bits <= address_bits + 1; 55 | end; 56 | end 57 | 58 | assign ADDR = address; 59 | 60 | reg[7:0] data; 61 | reg[3:0] data_bits; 62 | wire data_valid = data_bits[3]; 63 | reg need_data; 64 | reg load_data; 65 | reg selected; 66 | 67 | always @(posedge CLK) 68 | begin 69 | if (!cs_in) begin 70 | data_bits <= 0; 71 | need_data <= 0; 72 | load_data <= 0; 73 | selected <= 0; 74 | end else if (address_valid) begin 75 | if (sclk_edge) begin 76 | data <= {data[6:0], data_in}; 77 | data_bits <= data_bits + 1; 78 | end; 79 | selected <= 1; 80 | if (data_valid) 81 | data_bits <= 0; 82 | need_data <= 0; 83 | if (!selected || data_valid) 84 | need_data <= 1; 85 | load_data <= need_data; 86 | if (load_data) 87 | data <= TXD; 88 | end 89 | end 90 | 91 | assign MISO = data[7]; 92 | assign SEL = selected; 93 | assign RXD = data; 94 | assign RXE = data_valid; 95 | 96 | endmodule 97 | 98 | module IOPort8 99 | #( 100 | parameter ADDRESS = 0, // Port address 101 | // If set to 1 the output will only be active for single clock period. After that it will be set to all 0s. 102 | parameter ONE_SHOT = 0 103 | ) 104 | ( 105 | input [7:0] DI, // Data input 106 | output [7:0] DO, // Data output 107 | output STRB, // Data strobe - becomes active for one clock period whenever DO is updated 108 | output STRT, // Frame start strobe - becomes active for one clock period whenever port is selected 109 | output DONE, // Frame done strobe - becomes active for one clock period whenever port is deselected 110 | 111 | // Internal bus 112 | input [7:0] RXD, // Data received from the host 113 | output [7:0] TXD, // Data to be transmitted to the host. Getaway latches the data on second clock edge after STRT or STRB signals becoming active. 114 | input [7:0] ADDR, // Port address received from the host 115 | input SEL, // Port selected. Become active when the the address is valid. Reset after host deselect interface on transfer completion. 116 | input RXE, // Receive enable. If active, receiving port should latch RXD on rising edge of the clock. 117 | // Global clock 118 | input CLK 119 | ); 120 | 121 | reg [7:0] data_rx; 122 | assign DO = data_rx; 123 | 124 | wire addr_valid = SEL && ADDR == ADDRESS; 125 | assign TXD = addr_valid ? DI : 8'bz; 126 | 127 | reg strobe; 128 | assign STRB = strobe; 129 | 130 | reg selected; 131 | assign STRT = addr_valid & ~selected; 132 | assign DONE = ~addr_valid & selected; 133 | 134 | always @(posedge CLK) 135 | begin 136 | selected <= addr_valid; 137 | strobe <= 0; 138 | if (ONE_SHOT) 139 | data_rx <= 'b0; 140 | if (RXE && addr_valid) begin 141 | data_rx <= RXD; 142 | strobe <= 1; 143 | end 144 | end 145 | 146 | endmodule 147 | 148 | module IOPort16 149 | #( 150 | parameter ADDRESS = 0, // Port address 151 | // If set to 1 the output will only be active for single clock period. After that it will be set to all 0s. 152 | parameter ONE_SHOT = 0 153 | ) 154 | ( 155 | input [15:0] DI, // Data input 156 | output [15:0] DO, // Data output 157 | output STRB, // Strobe - becomes active for one clock period whenever DO is updated 158 | 159 | // Internal bus 160 | input [7:0] RXD, // Data received from the host 161 | output [7:0] TXD, // Data to be transmitted to the host 162 | input [7:0] ADDR, // Port address received from the host 163 | input SEL, // Port selected. Become active when the the address is valid. Reset after host deselect interface on transfer completion. 164 | input RXE, // Receive enable. If active, receiving port should latch RXD on rising edge of the clock. 165 | // Global clock 166 | input CLK 167 | ); 168 | 169 | reg [15:0] data_rx; 170 | reg [15:0] data_out; 171 | assign DO = data_out; 172 | 173 | reg strobe; 174 | assign STRB = strobe; 175 | 176 | reg got_byte; 177 | wire addr_valid = SEL && ADDR == ADDRESS; 178 | assign TXD = addr_valid ? (!got_byte ? DI[7:0] : DI[15:8]) : 8'bz; 179 | 180 | always @(posedge CLK) 181 | begin 182 | strobe <= 0; 183 | if (ONE_SHOT) 184 | data_out <= 'b0; 185 | if (!addr_valid && got_byte) begin 186 | got_byte <= 0; 187 | data_out <= data_rx; 188 | strobe <= 1; 189 | end 190 | if (RXE && addr_valid) begin 191 | if (!got_byte) 192 | data_rx[7:0] <= RXD; 193 | else 194 | data_rx[15:8] <= RXD; 195 | got_byte <= 1; 196 | end 197 | end 198 | 199 | endmodule 200 | -------------------------------------------------------------------------------- /hdl/test/XME0601blink/blink.ucf: -------------------------------------------------------------------------------- 1 | 2 | ###### Global clock ################### 3 | NET Clk LOC = P8 | TNM_NET = sys_clk_pin | IOSTANDARD = "LVCMOS33"; 4 | TIMESPEC TS_sys_clk_pin = PERIOD sys_clk_pin 50000 kHz; 5 | ## 6 | 7 | 8 | ## 9 | NET nRst LOC = T6 | IOSTANDARD = "LVCMOS33"; ## Reset Button 10 | ## 11 | 12 | ######## LED pins ##################### 13 | NET Led<0> LOC = L7 | IOSTANDARD = "LVCMOS33"; ## LED1 14 | NET Led<1> LOC = L8 | IOSTANDARD = "LVCMOS33"; ## LED2 15 | -------------------------------------------------------------------------------- /hdl/test/XME0601blink/blink.v: -------------------------------------------------------------------------------- 1 | `timescale 1ns / 1ps 2 | ////////////////////////////////////////////////////////////////////////////////// 3 | // Company: 4 | // Engineer: 5 | // 6 | // Create Date: 17:07:13 04/12/2020 7 | // Design Name: 8 | // Module Name: blink 9 | // Project Name: 10 | // Target Devices: 11 | // Tool versions: 12 | // Description: 13 | // 14 | // Dependencies: 15 | // 16 | // Revision: 17 | // Revision 0.01 - File Created 18 | // Additional Comments: 19 | // 20 | ////////////////////////////////////////////////////////////////////////////////// 21 | module blink( 22 | input Clk, 23 | input nRst, 24 | output [1:0] Led 25 | ); 26 | parameter N = 25; 27 | reg[N:0] cnt; 28 | 29 | always @(posedge Clk) 30 | begin 31 | if (!nRst) 32 | cnt <= 0; 33 | else 34 | cnt <= cnt + 1; 35 | end 36 | 37 | assign Led[0] = cnt[N]; 38 | assign Led[1] = ~cnt[N]; 39 | 40 | endmodule 41 | -------------------------------------------------------------------------------- /hdl/test/XME0601echo/echo.ucf: -------------------------------------------------------------------------------- 1 | 2 | ###### Global clock ################### 3 | NET Clk LOC = P8 | TNM_NET = sys_clk_pin | IOSTANDARD = "LVCMOS33"; 4 | TIMESPEC TS_sys_clk_pin = PERIOD sys_clk_pin 50000 kHz; 5 | ## 6 | 7 | ###### SPI slave interface ####################### 8 | 9 | NET SCLK LOC = R11 | IOSTANDARD = "LVCMOS33"; 10 | NET MOSI LOC = T10 | IOSTANDARD = "LVCMOS33"; 11 | NET MISO LOC = P10 | IOSTANDARD = "LVCMOS33"; 12 | NET nCS LOC = R12 | IOSTANDARD = "LVCMOS33"; 13 | 14 | ###### DCMI master interface ####################### 15 | 16 | NET DATA<0> LOC = T12 | IOSTANDARD = "LVCMOS33"; 17 | NET DATA<1> LOC = T13 | IOSTANDARD = "LVCMOS33"; 18 | NET DATA<2> LOC = T15 | IOSTANDARD = "LVCMOS33"; 19 | NET DATA<3> LOC = M14 | IOSTANDARD = "LVCMOS33"; 20 | NET DATA<4> LOC = R16 | IOSTANDARD = "LVCMOS33"; 21 | NET DATA<5> LOC = L13 | IOSTANDARD = "LVCMOS33"; 22 | NET DATA<6> LOC = P16 | IOSTANDARD = "LVCMOS33"; 23 | NET DATA<7> LOC = P15 | IOSTANDARD = "LVCMOS33"; 24 | NET DSYNC LOC = L12 | IOSTANDARD = "LVCMOS33"; 25 | NET DCLK LOC = R15 | IOSTANDARD = "LVCMOS33"; 26 | 27 | ## 28 | # NET nRst LOC = T6 | IOSTANDARD = "LVCMOS33"; ## Reset Button 29 | ## 30 | 31 | ######## LED pins ##################### 32 | NET Led<0> LOC = L7 | IOSTANDARD = "LVCMOS33"; ## LED1 33 | NET Led<1> LOC = L8 | IOSTANDARD = "LVCMOS33"; ## LED2 34 | 35 | -------------------------------------------------------------------------------- /hdl/test/XME0601echo/echo.v: -------------------------------------------------------------------------------- 1 | `timescale 1ns / 1ps 2 | ////////////////////////////////////////////////////////////////////////////////// 3 | // Company: 4 | // Engineer: 5 | // 6 | // Create Date: 08:34:36 04/13/2020 7 | // Design Name: 8 | // Module Name: echo 9 | // Project Name: 10 | // Target Devices: 11 | // Tool versions: 12 | // Description: 13 | // 14 | // Dependencies: 15 | // 16 | // Revision: 17 | // Revision 0.01 - File Created 18 | // Additional Comments: 19 | // 20 | ////////////////////////////////////////////////////////////////////////////////// 21 | 22 | module echo( 23 | // SPI slave interface 24 | input SCLK, 25 | input MOSI, 26 | output MISO, 27 | input nCS, 28 | // DCMI master interface 29 | output [7:0] DATA, 30 | output DSYNC, 31 | output DCLK, 32 | // Global clock 33 | input Clk, 34 | // On board LEDs 35 | output [1:0] Led 36 | ); 37 | 38 | wire [7:0] rxd; 39 | wire [7:0] txd; 40 | wire [7:0] addr; 41 | wire sel; 42 | wire txe; 43 | wire rxe; 44 | 45 | wire [7:0] data0; 46 | wire [7:0] data1; 47 | wire [7:0] data2; 48 | wire dsync0; 49 | wire dsync1; 50 | wire dsync2; 51 | 52 | assign DATA = data0 | data1 | data2; 53 | assign DSYNC = dsync0 | dsync1 | dsync2; 54 | 55 | // The gate instance provide interface between external SPI bus 56 | // and internal parallel bus where IO ports are attached 57 | 58 | SPIGate gate( 59 | .SCLK(SCLK), 60 | .MOSI(MOSI), 61 | .MISO(MISO), 62 | .nCS(nCS), 63 | .RXD(rxd), 64 | .TXD(txd), 65 | .ADDR(addr), 66 | .SEL(sel), 67 | .RXE(rxe), 68 | .CLK(Clk) 69 | ); 70 | 71 | wire dcmi_clken; 72 | 73 | DCMIClkGen dcmi_clk_gen( 74 | .DCLK(DCLK), 75 | .CLKEN(dcmi_clken), 76 | .CLK(Clk) 77 | ); 78 | 79 | // 80 | // Port #0 controls on-board LEDs 81 | // 82 | wire [7:0] p0data; 83 | assign Led = ~p0data[1:0]; 84 | 85 | IOPort8 #(.ADDRESS(0)) port0 ( 86 | .DI(8'hde), 87 | .DO(p0data), 88 | .RXD(rxd), 89 | .TXD(txd), 90 | .ADDR(addr), 91 | .SEL(sel), 92 | .RXE(rxe), 93 | .CLK(Clk) 94 | ); 95 | 96 | // 97 | // Port #1 outputs the same data as was written to it 98 | // 99 | 100 | wire [7:0] p1out; 101 | reg [7:0] p1data = 0; 102 | wire p1strobe; 103 | 104 | IOPort8 #(.ADDRESS(1), .ONE_SHOT(1)) port1 ( 105 | .DI(p1data), 106 | .DO(p1out), 107 | .STRB(p1strobe), 108 | .RXD(rxd), 109 | .TXD(txd), 110 | .ADDR(addr), 111 | .SEL(sel), 112 | .RXE(rxe), 113 | .CLK(Clk) 114 | ); 115 | 116 | // We don't really need to latch data in order to echo it back 117 | // This code here just to verify that we can do it 118 | always @(posedge Clk) 119 | begin 120 | if (p1strobe) 121 | p1data <= p1out; 122 | end 123 | 124 | // 125 | // Port #2 is 16 bit wide. It outputs the same data as was written to it. 126 | // The only difference with 8 bit port is that the latter may echo stream of data 127 | // while the 16 bit version is not suitable for streaming. 128 | // 129 | 130 | wire [15:0] p2data; 131 | 132 | IOPort16 #(.ADDRESS(2)) port2 ( 133 | .DI(p2data), 134 | .DO(p2data), 135 | .RXD(rxd), 136 | .TXD(txd), 137 | .ADDR(addr), 138 | .SEL(sel), 139 | .RXE(rxe), 140 | .CLK(Clk) 141 | ); 142 | 143 | // Port #3 triggers DCMI test frame transmission 144 | 145 | wire [7:0] p3data; 146 | 147 | IOPort8 #(.ADDRESS(3), .ONE_SHOT(1)) port3 ( 148 | .DI(8'hdc), 149 | .DO(p3data), 150 | .RXD(rxd), 151 | .TXD(txd), 152 | .ADDR(addr), 153 | .SEL(sel), 154 | .RXE(rxe), 155 | .CLK(Clk) 156 | ); 157 | 158 | wire dcmi_start = p3data[0]; 159 | 160 | DCMITester dcmi_test ( 161 | .TX_START(dcmi_start), 162 | .DATA(data0), 163 | .DSYNC(dsync0), 164 | .CLKEN(dcmi_clken), 165 | .CLK(Clk) 166 | ); 167 | 168 | // 169 | // Port #4 serves for DCMI bus testing 170 | // The data written to it is buffered and then 171 | // transmitted to DCMI bus once the port is deselected 172 | // 173 | 174 | wire [7:0] p4data; 175 | wire p4strobe; 176 | wire p4start; 177 | 178 | IOPort8 #(.ADDRESS(4)) port4 ( 179 | .DI(8'hdc), 180 | .DO(p4data), 181 | .STRB(p4strobe), 182 | .STRT(p4start), 183 | .DONE(p4done), 184 | .RXD(rxd), 185 | .TXD(txd), 186 | .ADDR(addr), 187 | .SEL(sel), 188 | .RXE(rxe), 189 | .CLK(Clk) 190 | ); 191 | 192 | DCMITxBuffer dcmi_tx ( 193 | .DI(p4data), 194 | .WR(p4strobe), 195 | .RST(p4start), 196 | .TX_START(p4done), 197 | .DATA(data1), 198 | .DSYNC(dsync1), 199 | .CLKEN(dcmi_clken), 200 | .CLK(Clk) 201 | ); 202 | 203 | // 204 | // Port #5 transmit the sequence on sequential numbers. 205 | // This is the example of the streaming data to MCU using IOPort8 206 | // If you need to stream data in the opposite direction via SPI bus 207 | // see DCMITransmitter implementation 208 | // 209 | 210 | reg [7:0] p5data; 211 | wire p5strobe; 212 | wire p5start; 213 | 214 | IOPort8 #(.ADDRESS(5)) port5 ( 215 | .DI(p5data), 216 | .STRB(p5strobe), 217 | .STRT(p5start), 218 | .RXD(rxd), 219 | .TXD(txd), 220 | .ADDR(addr), 221 | .SEL(sel), 222 | .RXE(rxe), 223 | .CLK(Clk) 224 | ); 225 | 226 | always @(posedge Clk) 227 | begin 228 | if (p5start) 229 | p5data <= 'b0; 230 | if (p5strobe) 231 | p5data <= p5data + 1; 232 | end 233 | 234 | // 235 | // Writing to port 6 triggers the transmission of the chip scope 236 | // data collected on falling edge of nCS signal 237 | // 238 | 239 | wire p6strobe; 240 | wire p6start; 241 | wire p6done; 242 | 243 | IOPort8 #(.ADDRESS(6)) port6 ( 244 | .STRB(p6strobe), 245 | .STRT(p6start), 246 | .DONE(p6done), 247 | .RXD(rxd), 248 | .TXD(txd), 249 | .ADDR(addr), 250 | .SEL(sel), 251 | .RXE(rxe), 252 | .CLK(Clk) 253 | ); 254 | 255 | wire [7:0] capture; 256 | 257 | assign capture[0] = nCS; 258 | assign capture[1] = SCLK; 259 | assign capture[2] = MOSI; 260 | assign capture[3] = sel; 261 | assign capture[4] = rxe; 262 | assign capture[5] = p6start; 263 | assign capture[6] = p6strobe; 264 | assign capture[7] = p6done; 265 | 266 | DCMICaptureBuffer dcmi_capture ( 267 | .DI(capture), 268 | .TRIG(~nCS), 269 | .TX_START(p6start), 270 | .DATA(data2), 271 | .DSYNC(dsync2), 272 | .CLKEN(dcmi_clken), 273 | .CLK(Clk) 274 | ); 275 | 276 | endmodule 277 | -------------------------------------------------------------------------------- /hdl/test/XME0601echo/test/blink.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | 4 | sys.path.append('../../../../python') 5 | import pl 6 | 7 | LED_PORT = 0 8 | LED_RD_VAL = '\xde' 9 | 10 | dev = pl.open() 11 | print 'PL is', pl.get_status_name(dev) 12 | while True: 13 | assert pl.tx(dev, LED_PORT, '\x01') == LED_RD_VAL 14 | time.sleep(.5) 15 | assert pl.tx(dev, LED_PORT, '\x02') == LED_RD_VAL 16 | time.sleep(.5) 17 | -------------------------------------------------------------------------------- /hdl/test/XME0601echo/test/capture.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append('../../../../python') 3 | import pl 4 | import chipscope as cs 5 | 6 | # 7 | # Capture SPI receiver signals, see XME0601echo/echo.v for details 8 | # 9 | CAPTURE_PORT = 6 10 | CAPTURE_CMD = '\1\2\3\4' 11 | HDRS = ('nCS', 'SCLK', 'MOSI', 'SEL', 'RXE', 'START', 'STRB', 'DONE') 12 | 13 | cs.print_trace(cs.capture_trace(pl.open(), CAPTURE_PORT, CAPTURE_CMD), sys.stdout, hdrs = HDRS) 14 | -------------------------------------------------------------------------------- /hdl/test/XME0601echo/test/echo16.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | 4 | sys.path.append('../../../../python') 5 | import pl 6 | 7 | ECHO16_PORT = 2 8 | 9 | dev = pl.open() 10 | print 'PL is', pl.get_status_name(dev) 11 | cnt, last = 0, None 12 | while True: 13 | data = str(bytearray(random.getrandbits(8) for _ in range(2))) 14 | resp = pl.tx(dev, ECHO16_PORT, data) 15 | assert last is None or resp == last 16 | last = data 17 | cnt += 1 18 | if cnt % 100 == 0: 19 | print '*', 20 | -------------------------------------------------------------------------------- /hdl/test/XME0601echo/test/echo8.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | 4 | sys.path.append('../../../../python') 5 | import pl 6 | 7 | ECHO8_PORT = 1 8 | 9 | dev = pl.open() 10 | print 'PL is', pl.get_status_name(dev) 11 | cnt, last_byte = 0, None 12 | while True: 13 | sz = random.randrange(1, 1024) 14 | data = str(bytearray(random.getrandbits(8) for _ in xrange(sz))) 15 | resp = pl.tx(dev, ECHO8_PORT, data) 16 | if last_byte != None: 17 | assert resp[0] == last_byte 18 | assert resp[1:] == data[:-1] 19 | last_byte = data[-1] 20 | cnt += 1 21 | if cnt % 100 == 0: 22 | print '*', 23 | -------------------------------------------------------------------------------- /hdl/test/XME0601echo/test/echo_cnt.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | 4 | sys.path.append('../../../../python') 5 | import pl 6 | 7 | ECHO_CNT_PORT = 5 8 | 9 | cnt_str = ''.join([chr(i) for i in range(256)]) 10 | master_str = cnt_str * 4 11 | 12 | dev = pl.open() 13 | print 'PL is', pl.get_status_name(dev) 14 | cnt = 0 15 | while True: 16 | sz = random.randrange(1, len(master_str) + 1) 17 | resp = pl.tx(dev, ECHO_CNT_PORT, '\0' * sz) 18 | assert resp == master_str[:sz] 19 | cnt += 1 20 | if cnt % 100 == 0: 21 | print '*', 22 | -------------------------------------------------------------------------------- /hdl/test/XME0601echo/test/echo_dcmi.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | 4 | sys.path.append('../../../../python') 5 | import pl 6 | 7 | ECHO8_PORT = 1 8 | ECHO16_PORT = 2 9 | ECHO_DCMI_PORT = 4 10 | DCMI_ECHO_MAX = 1024 11 | 12 | cnt = 0 13 | dev = pl.open() 14 | print 'PL is', pl.get_status_name(dev) 15 | while True: 16 | sz = random.randrange(1, 1 + DCMI_ECHO_MAX / 4) # in 32 bit words 17 | data = str(bytearray(random.getrandbits(8) for _ in xrange(sz*4))) 18 | rdata = pl.pull(dev, ECHO_DCMI_PORT, data, sz) 19 | assert rdata == data 20 | cnt += 1 21 | if cnt % 100 == 0: 22 | print '*', 23 | 24 | -------------------------------------------------------------------------------- /python/chipscope.py: -------------------------------------------------------------------------------- 1 | # 2 | # Capture and print chip scope traces. 3 | # The chip scope is implemented as DCMICaptureBuffer 4 | # module in hdl/lib/dcmi_util.v. See hdl/test/XME0601echo/echo.v 5 | # and hdl/test/XME0601echo/test/capture.py for usage example. 6 | # 7 | 8 | import pl 9 | 10 | TRACE_LEN = 1024 # In 32 bit words 11 | 12 | def capture_trace(dev, addr, cmd): 13 | return pl.pull(dev, addr, cmd, TRACE_LEN) 14 | 15 | def print_trace(t, f, line_len = 128, hdrs = ()): 16 | size, off = len(t), 0 17 | hwidth = 0 18 | if hdrs: hwidth = max(len(h) for h in hdrs) 19 | hwidth = 2 + max(1, hwidth) 20 | skip, last_byte = False, None 21 | while size: 22 | chunk = min(size, line_len) 23 | for c in t[off:off+chunk]: 24 | if c != last_byte: 25 | break 26 | else: 27 | if not skip: 28 | skip = True 29 | f.write('...\n\n') 30 | size -= chunk 31 | off += chunk 32 | continue 33 | 34 | skip = False 35 | f.write('+%u\n' % off) 36 | for b in range(8): 37 | if b < len(hdrs): 38 | h = hdrs[b] 39 | else: 40 | h = '_' 41 | f.write(h + ' ' * (hwidth - len(h))) 42 | bit = 1 << b 43 | for i in range(chunk): 44 | if ord(t[off + i]) & bit: 45 | f.write('-') 46 | else: 47 | f.write('_') 48 | f.write('\n') 49 | f.write('\n') 50 | last_byte = t[off + chunk - 1] 51 | size -= chunk 52 | off += chunk 53 | -------------------------------------------------------------------------------- /python/pl.py: -------------------------------------------------------------------------------- 1 | import pyvisa as pv 2 | import struct 3 | import sys 4 | 5 | # 6 | # FPGA status values 7 | # 8 | STA_INACTIVE = 0 # inactive (PROGRAM_B low) 9 | STA_ACTIVE = 1 # active, not configured 10 | STA_CONFIGURED = 2 # active, configured 11 | 12 | sta_names = { 13 | STA_INACTIVE : "Inactive", 14 | STA_ACTIVE : "Active", 15 | STA_CONFIGURED : "Configured" 16 | } 17 | 18 | def status_name(sta): 19 | if sta in sta_names: 20 | return sta_names[sta] 21 | else: 22 | return "Unknown" 23 | 24 | def open(res = None): 25 | """Open device""" 26 | rm = pv.ResourceManager() 27 | if not res: 28 | res = rm.list_resources()[0] 29 | return rm.open_resource(res) 30 | 31 | def get_status(dev): 32 | """Get FPGA status""" 33 | dev.write_raw('PL:ACTIVE?') 34 | r = dev.read_raw() 35 | assert len(r) == 1 36 | return ord(r[0]) - ord('0') 37 | 38 | def get_status_name(dev): 39 | """Get FPGA status string representation""" 40 | return status_name(get_status(dev)) 41 | 42 | def tx(dev, addr, data): 43 | """ 44 | Exchange data with FPGA over SPI bus given the target port address and data to transmit. 45 | Returns data receiving during SPI data exchange. 46 | """ 47 | dev.write_raw('PL:TX' + chr(addr) + data) 48 | r = dev.read_raw() 49 | assert len(r) == 1 + len(data) 50 | return r[1:] 51 | 52 | def pull_raw(dev, addr, cmd, frame_words): 53 | """ 54 | Receive data over DCMI bus given the port address and command that should be sent over SPI to 55 | trigger DCMI data transfer as well as the number of 4 byte words to receive. Returns the 56 | concatenation of the SPI and DCMI data received with possible padding in between. 57 | """ 58 | dev.write_raw('PL:PULL #H%X#' % frame_words + chr(addr) + cmd) 59 | return dev.read_raw() 60 | 61 | def pull(dev, addr, cmd, frame_words): 62 | """ 63 | Receive data over DCMI bus given the port address and command that should be sent over SPI to 64 | trigger DCMI data transfer as well as the number of 4 byte words to receive. Returns the DCMI 65 | data frame received. 66 | """ 67 | r = pull_raw(dev, addr, cmd, frame_words) 68 | return r[-frame_words*4:] 69 | 70 | if __name__ == '__main__': 71 | dev = open() 72 | print 'PL is', get_status_name(dev) 73 | 74 | -------------------------------------------------------------------------------- /python/pl_flash.py: -------------------------------------------------------------------------------- 1 | """ 2 | The module provides API for accessing SPI flash via USB TMC interface. 3 | It is tested with Winbond 25Q16 flash. Flash chips from other manufacturers may 4 | require minor modifications to the code. 5 | """ 6 | 7 | import pyvisa as pv 8 | import time 9 | 10 | class PLFlash: 11 | STATUS_BUSY = 1 12 | max_rd_chunk = 4096 13 | program_page = 256 14 | 15 | def __init__(self, res = None): 16 | rm = pv.ResourceManager() 17 | if not res: 18 | res = rm.list_resources()[0] 19 | self.dev = rm.open_resource(res) 20 | 21 | def pl_status(self): 22 | """Returns the FPGA status: 0 - inactive, 1 - active, 2 - configured""" 23 | self.dev.write_raw('PL:ACTIVE?') 24 | sta = self.dev.read_raw() 25 | assert len(sta) == 1 26 | return ord(sta[0]) - ord('0') 27 | 28 | def __enter__(self): 29 | """Reset FPGA to gain access to the flash""" 30 | self.dev.write_raw('PL:ACTIVE#0') 31 | started = time.time() 32 | while self.pl_status() != 0: 33 | if time.time() - started > 1000: 34 | raise RuntimeError('Timeout waiting PL inactive status') 35 | return self 36 | 37 | def __exit__(self, type, value, traceback): 38 | """Resume FPGA""" 39 | self.dev.write_raw('PL:ACTIVE#1') 40 | 41 | def write(self, data): 42 | """Send data to flash""" 43 | self.dev.write_raw('PL:FLASH:WR' + data) 44 | r = self.dev.read_raw() 45 | if len(r) > 0: 46 | raise RuntimeError('unexpected PL:FLASH:WR response') 47 | 48 | def read(self, data, sz): 49 | """Send data and read response""" 50 | self.dev.write_raw('PL:FLASH:RD #H%X#' % sz + data) 51 | r = self.dev.read_raw() 52 | if len(r) != len(data) + sz: 53 | raise RuntimeError('unexpected PL:FLASH:RD response: expect %u + %u, got %u bytes' % ( 54 | len(data), sz, len(r))) 55 | return r[len(data):] 56 | 57 | def read_id(self): 58 | """Read flash ID tuple""" 59 | r = self.read('\x9f', 3) 60 | return ord(r[0]), ord(r[1]), ord(r[2]) 61 | 62 | def query_size(self): 63 | """Returns flash size in bytes""" 64 | man, mod, lsz = self.read_id() 65 | return 1 << lsz 66 | 67 | def read_status(self, i = 1): 68 | """Read one of the 2 status registers""" 69 | assert i == 1 or i == 2 70 | r = self.read('\x05' if i == 1 else '\x35', 1) 71 | return ord(r[0]) 72 | 73 | def write_en(self, en): 74 | """Enable / disable writing to flash""" 75 | self.write('\x06' if en else '\x04') 76 | 77 | def wait_busy(self, tout_ms): 78 | """Wait flash busy status clear""" 79 | tout = self.dev.timeout 80 | self.dev.timeout = tout_ms + 1000 81 | self.dev.write_raw('PL:FLASH:WAit #%u' % tout_ms) 82 | r = self.dev.read_raw() 83 | self.dev.timeout = tout 84 | if len(r) != 1: 85 | raise RuntimeError('unexpected PL:FLASH:WAit response') 86 | return (ord(r[0]) & PLFlash.STATUS_BUSY) == 0 87 | 88 | def write_safe(self, data, tout_ms): 89 | """Combines waiting non-busy status, enabling write and writing data in single request""" 90 | tout = self.dev.timeout 91 | self.dev.timeout = tout_ms + 1000 92 | self.dev.write_raw('PL:FLASH:PRog #%u#' % tout_ms + data) 93 | r = self.dev.read_raw() 94 | self.dev.timeout = tout 95 | if len(r) != 1: 96 | raise RuntimeError('unexpected PL:FLASH:PRog response') 97 | return (ord(r[0]) & PLFlash.STATUS_BUSY) == 0 98 | 99 | def erase_all(self): 100 | """Erase entire chip""" 101 | return self.write_safe('\xC7', 1000) and self.wait_busy(4000) 102 | 103 | def read_chunk(self, off, sz): 104 | """Read chunk of flash content starting from the specified address""" 105 | assert sz <= PLFlash.max_rd_chunk 106 | addr = chr((off >> 16) & 0xff) + chr((off >> 8) & 0xff) + chr(off & 0xff) 107 | return self.read('\x03' + addr, sz) 108 | 109 | def read_content(self, addr, sz): 110 | """Read flash content starting from the specified address""" 111 | buff = '' 112 | while sz: 113 | chunk = min(sz, PLFlash.max_rd_chunk) 114 | buff += self.read_chunk(addr, chunk) 115 | addr += chunk 116 | sz -= chunk 117 | return buff 118 | 119 | def prog_page(self, off, data): 120 | """Program flash page or some part of it""" 121 | assert len(data) <= PLFlash.program_page - (off & (PLFlash.program_page-1)) 122 | addr = chr((off >> 16) & 0xff) + chr((off >> 8) & 0xff) + chr(off & 0xff) 123 | return self.write_safe('\x02' + addr + data, 1000) 124 | 125 | def program(self, addr, data): 126 | sz, off = len(data), 0 127 | while sz: 128 | chunk = min(PLFlash.program_page - (addr & (PLFlash.program_page-1)), sz) 129 | if not self.prog_page(addr, data[off:off+chunk]): 130 | return False 131 | addr += chunk 132 | off += chunk 133 | sz -= chunk 134 | return self.wait_busy(1000) 135 | 136 | 137 | if __name__ == '__main__': 138 | import sys 139 | import random 140 | 141 | with PLFlash() as dev: 142 | if '--program' in sys.argv: 143 | sys.argv.remove('--program') 144 | if len(sys.argv) < 2: 145 | print 'need filename to program' 146 | else: 147 | data = open(sys.argv[-1], 'rb').read() 148 | print 'erasing ..' 149 | assert dev.erase_all() 150 | print 'programming %u bytes ..' % len(data) 151 | assert dev.program(0, data) 152 | print 'verifying ..' 153 | rdata = dev.read_content(0, len(data)) 154 | assert rdata == data 155 | print 'done' 156 | 157 | elif '--erase' in sys.argv: 158 | if dev.erase_all(): 159 | print 'chip erased' 160 | else: 161 | print 'failed to erase' 162 | 163 | elif '--chk-empty' in sys.argv: 164 | size = dev.query_size() 165 | print 'reading', size, 'bytes ..', 166 | content = dev.read_content(0, size) 167 | print 'done' 168 | for i, c in enumerate(content): 169 | if c != '\xff': 170 | print '%#0.2x @%#x' % (ord(c), i) 171 | break 172 | else: 173 | print 'empty' 174 | 175 | elif '--test' in sys.argv: 176 | size = dev.query_size() 177 | off = random.randrange(0, size / 2) 178 | sz = random.randrange(1, size - off + 1) 179 | data = str(bytearray(random.getrandbits(8) for _ in xrange(sz))) 180 | print 'erasing ..' 181 | assert dev.erase_all() 182 | print 'writing %u bytes at offset %u ..' % (sz, off) 183 | assert dev.program(off, data) 184 | print 'verifying ..' 185 | rdata = dev.read_content(off, sz) 186 | assert len(rdata) == sz 187 | for i, c in enumerate(rdata): 188 | if c != data[i]: 189 | print '%#0.2x != %#0.2x @%#x' % (ord(c), ord(data[i]), i) 190 | break 191 | print 'done' 192 | 193 | else: 194 | print 'ID =', dev.read_id() 195 | 196 | print 'status: %#x, %#x' % (dev.read_status(1), dev.read_status(2)) 197 | 198 | -------------------------------------------------------------------------------- /test/echo.py: -------------------------------------------------------------------------------- 1 | import pyvisa as pv 2 | import random 3 | import time 4 | 5 | max_size = 1024 6 | rand_buff = None 7 | 8 | def init(): 9 | global rand_buff 10 | l = [chr(i) for i in range(255)] 11 | random.shuffle(l) 12 | l = l * (2 * max_size / len(l)) 13 | random.shuffle(l) 14 | rand_buff = ''.join(l) 15 | 16 | def open_device(): 17 | rm = pv.ResourceManager() 18 | r = rm.list_resources() 19 | print 'opening', r[0] 20 | return rm.open_resource(r[0]) 21 | 22 | def random_buff(): 23 | sz = random.randrange(0, max_size + 1) 24 | off = random.randrange(0, len(rand_buff) - sz + 1) 25 | return rand_buff[off:off+sz] 26 | 27 | def echo(dev, b): 28 | dev.write_raw(':TEST :ECHO' + b) 29 | r = dev.read_raw(max_size) 30 | if r != b: 31 | print 'data mismatch' 32 | print len(b), 'written', len(r), 'read' 33 | raise RuntimeError 34 | 35 | def test(): 36 | init() 37 | dev = open_device() 38 | print dev.query('*IDN?') 39 | assert dev.read_raw() == '' 40 | loops, bytes = 0, 0 41 | started = time.time() 42 | try: 43 | while True: 44 | b = random_buff() 45 | echo(dev, b) 46 | loops += 1 47 | bytes += len(b) 48 | if loops % 100 == 0: 49 | print '*', 50 | except KeyboardInterrupt: 51 | pass 52 | elapsed = time.time() - started 53 | print 54 | print loops / elapsed, 'reqs / sec' 55 | print bytes / (1000 * elapsed), 'KB / sec' 56 | 57 | if __name__ == '__main__': 58 | test() 59 | 60 | 61 | -------------------------------------------------------------------------------- /test/imtest.vi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olegv142/STM32AllProgrammable/6978b11dd95e532b11a5bc0bee21b8383a0eb162/test/imtest.vi --------------------------------------------------------------------------------