├── .gitignore ├── CHANGELOG.md ├── Drivers ├── CMSIS │ ├── Device │ │ └── ST │ │ │ └── STM32L4xx │ │ │ └── Include │ │ │ ├── stm32l476xx.h │ │ │ ├── stm32l496xx.h │ │ │ ├── stm32l4xx.h │ │ │ └── system_stm32l4xx.h │ └── Include │ │ ├── arm_common_tables.h │ │ ├── arm_const_structs.h │ │ ├── arm_math.h │ │ ├── cmsis_armcc.h │ │ ├── cmsis_armcc_V6.h │ │ ├── cmsis_gcc.h │ │ ├── core_cm0.h │ │ ├── core_cm0plus.h │ │ ├── core_cm3.h │ │ ├── core_cm4.h │ │ ├── core_cm7.h │ │ ├── core_cmFunc.h │ │ ├── core_cmInstr.h │ │ ├── core_cmSimd.h │ │ ├── core_sc000.h │ │ └── core_sc300.h └── STM32L4xx_HAL_Driver │ ├── Inc │ ├── Legacy │ │ ├── stm32_hal_legacy.h │ │ └── stm32l4xx_hal_can_legacy.h │ ├── stm32l4xx_hal.h │ ├── stm32l4xx_hal_cortex.h │ ├── stm32l4xx_hal_crc.h │ ├── stm32l4xx_hal_crc_ex.h │ ├── stm32l4xx_hal_def.h │ ├── stm32l4xx_hal_dma.h │ ├── stm32l4xx_hal_dma_ex.h │ ├── stm32l4xx_hal_flash.h │ ├── stm32l4xx_hal_flash_ex.h │ ├── stm32l4xx_hal_flash_ramfunc.h │ ├── stm32l4xx_hal_gpio.h │ ├── stm32l4xx_hal_gpio_ex.h │ ├── stm32l4xx_hal_pwr.h │ ├── stm32l4xx_hal_pwr_ex.h │ ├── stm32l4xx_hal_rcc.h │ ├── stm32l4xx_hal_rcc_ex.h │ ├── stm32l4xx_hal_sd.h │ ├── stm32l4xx_hal_sd_ex.h │ └── stm32l4xx_ll_sdmmc.h │ └── Src │ ├── Legacy │ └── stm32l4xx_hal_can.c │ ├── stm32l4xx_hal.c │ ├── stm32l4xx_hal_cortex.c │ ├── stm32l4xx_hal_crc.c │ ├── stm32l4xx_hal_crc_ex.c │ ├── stm32l4xx_hal_dma.c │ ├── stm32l4xx_hal_dma_ex.c │ ├── stm32l4xx_hal_flash.c │ ├── stm32l4xx_hal_flash_ex.c │ ├── stm32l4xx_hal_flash_ramfunc.c │ ├── stm32l4xx_hal_gpio.c │ ├── stm32l4xx_hal_pwr.c │ ├── stm32l4xx_hal_pwr_ex.c │ ├── stm32l4xx_hal_rcc.c │ ├── stm32l4xx_hal_rcc_ex.c │ ├── stm32l4xx_hal_sd.c │ ├── stm32l4xx_hal_sd_ex.c │ └── stm32l4xx_ll_sdmmc.c ├── EWARM ├── Project.eww ├── startup_stm32l476xx.s ├── startup_stm32l496xx.s ├── stm32-bootloader.dep ├── stm32-bootloader.ewd ├── stm32-bootloader.ewp ├── stm32-bootloader.ewt ├── stm32l476xx_flash.icf ├── stm32l476xx_sram.icf ├── stm32l496xx_flash.icf └── stm32l496xx_sram.icf ├── Inc ├── bootloader.h ├── bsp_driver_sd.h ├── fatfs.h ├── ffconf.h ├── main.h ├── stm32l4xx_hal_conf.h └── stm32l4xx_it.h ├── LICENSE.md ├── Middlewares └── Third_Party │ └── FatFs │ └── src │ ├── diskio.c │ ├── diskio.h │ ├── driver │ ├── sd_diskio.c │ └── sd_diskio.h │ ├── ff.c │ ├── ff.h │ ├── ff_gen_drv.c │ ├── ff_gen_drv.h │ ├── integer.h │ └── option │ ├── cc932.c │ ├── cc936.c │ ├── cc949.c │ ├── cc950.c │ ├── ccsbcs.c │ ├── syscall.c │ └── unicode.c ├── README.md ├── Src ├── bootloader.c ├── bsp_driver_sd.c ├── fatfs.c ├── main.c ├── stm32l4xx_it.c └── system_stm32l4xx.c ├── bootloader-sequence.png ├── flash-organization.png └── system-overview.png /.gitignore: -------------------------------------------------------------------------------- 1 | EWARM/settings/ 2 | EWARM/L476/ 3 | EWARM/L496/ 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog for STM32 Bootloader 2 | 3 | ## [Unreleased] 4 | - Check checksum of application found on SD card before programming 5 | - Switch to semantic versioning 6 | 7 | 8 | ## [1.08](https://github.com/akospasztor/stm32-bootloader/releases/tag/v1.08) - 2018-04-18 9 | ### Added 10 | - Verify flash content after programming 11 | - Introduced changelog file 12 | ### Changed 13 | - The bootloader is now optimized for a new hardware. Due to new pinout of LEDs, user button and SD card switch, the appropriate defines have been changed in main.h file. 14 | - Bootloader sequence with richer error and debug messages 15 | - Updated SD card driver with DMA support 16 | - Project now uses IAR CMSIS pack 17 | - Updated STM32L4xx CMSIS to 1.4.2 18 | - Updated STM32L4xx HAL library to 1.8.2 19 | ### Fixed 20 | - Changed appropriate variable types 21 | - Updated README and sequence graph 22 | - Updated header files 23 | 24 | 25 | ## [1.07](https://github.com/akospasztor/stm32-bootloader/releases/tag/v1.07) - 2017-12-08 26 | ### Added 27 | - SD card power on/off support 28 | ### Changed 29 | - As a result of recent hardware changes introduced in a device that is developed as part of our ongoing projects, the SD card is now powered on/off with a FET controlled by the MCU to minimize energy consumption. Therefore, the SD card has to be manually powered on during initialization. 30 | 31 | 32 | ## [1.06](https://github.com/akospasztor/stm32-bootloader/releases/tag/v1.06) - 2017-11-13 33 | ### Added 34 | - Introduced RAM_SIZE define to precisely check whether the flash contains valid application upon startup 35 | ### Fixed 36 | - CheckForApplication() function 37 | 38 | 39 | ## [1.05](https://github.com/akospasztor/stm32-bootloader/releases/tag/v1.05) - 2017-10-30 40 | ### Added 41 | - Application-specific configuration defines 42 | ### Changed 43 | - Updated STM32L4xx CMSIS to 1.4.1 44 | - Updated STM32L4xx HAL library to 1.8.1 45 | 46 | 47 | ## [1.04](https://github.com/akospasztor/stm32-bootloader/releases/tag/v1.04) - 2017-10-16 48 | ### Added 49 | - Option to skip programming after flash erase operation 50 | ### Changed 51 | - Better visual feedback when no application is found in flash 52 | ### Fixed 53 | - General improvements 54 | 55 | 56 | ## [1.03](https://github.com/akospasztor/stm32-bootloader/releases/tag/v1.03) - 2017-09-21 57 | ### Added 58 | - Support for STM32L496VG MCU 59 | - Multiple build configurations for each supported microcontroller 60 | - Change between different builds with a single click 61 | ### Changed 62 | - Updated FatFs to R0.12c 63 | - Updated Cortex-M CMSIS to 4.5 64 | - Updated STM32L4xx CMSIS to 1.4.0 65 | - Updated STM32L4xx HAL library to 1.8.0 66 | 67 | 68 | ## [1.02](https://github.com/akospasztor/stm32-bootloader/releases/tag/v1.02) - 2017-08-11 69 | ### Fixed 70 | - General improvements 71 | 72 | 73 | ## [1.01](https://github.com/akospasztor/stm32-bootloader/releases/tag/v1.01) - 2017-07-25 74 | ### Added 75 | - Option for clearing reset flags after startup 76 | ### Fixed 77 | - Bootloader sequence graph 78 | - Readme updates 79 | - General improvements 80 | 81 | 82 | ## [1.00](https://github.com/akospasztor/stm32-bootloader/releases/tag/v1.00) - 2017-05-21 83 | ### Added 84 | Initial release 85 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dy011/stm32-bootloader/d5c4adc14ea200b0b608fb07e04adc2554dcdfe9/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l496xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dy011/stm32-bootloader/d5c4adc14ea200b0b608fb07e04adc2554dcdfe9/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l496xx.h -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dy011/stm32-bootloader/d5c4adc14ea200b0b608fb07e04adc2554dcdfe9/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h -------------------------------------------------------------------------------- /Drivers/CMSIS/Device/ST/STM32L4xx/Include/system_stm32l4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32l4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32L4xx 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 stm32l4xx_system 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Define to prevent recursive inclusion 46 | */ 47 | #ifndef __SYSTEM_STM32L4XX_H 48 | #define __SYSTEM_STM32L4XX_H 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | /** @addtogroup STM32L4xx_System_Includes 55 | * @{ 56 | */ 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | 63 | /** @addtogroup STM32L4xx_System_Exported_Variables 64 | * @{ 65 | */ 66 | /* The SystemCoreClock variable is updated in three ways: 67 | 1) by calling CMSIS function SystemCoreClockUpdate() 68 | 2) by calling HAL API function HAL_RCC_GetSysClockFreq() 69 | 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency 70 | Note: If you use this function to configure the system clock; then there 71 | is no need to call the 2 first functions listed above, since SystemCoreClock 72 | variable is updated automatically. 73 | */ 74 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 75 | 76 | extern const uint8_t AHBPrescTable[16]; /*!< AHB prescalers table values */ 77 | extern const uint8_t APBPrescTable[8]; /*!< APB prescalers table values */ 78 | extern const uint32_t MSIRangeTable[12]; /*!< MSI ranges table values */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @addtogroup STM32L4xx_System_Exported_Constants 85 | * @{ 86 | */ 87 | 88 | /** 89 | * @} 90 | */ 91 | 92 | /** @addtogroup STM32L4xx_System_Exported_Macros 93 | * @{ 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /** @addtogroup STM32L4xx_System_Exported_Functions 101 | * @{ 102 | */ 103 | 104 | extern void SystemInit(void); 105 | extern void SystemCoreClockUpdate(void); 106 | /** 107 | * @} 108 | */ 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /*__SYSTEM_STM32L4XX_H */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | /** 121 | * @} 122 | */ 123 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 124 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/arm_common_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 19. October 2015 5 | * $Revision: V.1.4.5 a 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_common_tables.h 9 | * 10 | * Description: This file has extern declaration for common tables like Bitreverse, reciprocal etc which are used across different functions 11 | * 12 | * Target Processor: Cortex-M4/Cortex-M3 13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted provided that the following conditions 16 | * are met: 17 | * - Redistributions of source code must retain the above copyright 18 | * notice, this list of conditions and the following disclaimer. 19 | * - Redistributions in binary form must reproduce the above copyright 20 | * notice, this list of conditions and the following disclaimer in 21 | * the documentation and/or other materials provided with the 22 | * distribution. 23 | * - Neither the name of ARM LIMITED nor the names of its contributors 24 | * may be used to endorse or promote products derived from this 25 | * software without specific prior written permission. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 30 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 31 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 33 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 38 | * POSSIBILITY OF SUCH DAMAGE. 39 | * -------------------------------------------------------------------- */ 40 | 41 | #ifndef _ARM_COMMON_TABLES_H 42 | #define _ARM_COMMON_TABLES_H 43 | 44 | #include "arm_math.h" 45 | 46 | extern const uint16_t armBitRevTable[1024]; 47 | extern const q15_t armRecipTableQ15[64]; 48 | extern const q31_t armRecipTableQ31[64]; 49 | /* extern const q31_t realCoefAQ31[1024]; */ 50 | /* extern const q31_t realCoefBQ31[1024]; */ 51 | extern const float32_t twiddleCoef_16[32]; 52 | extern const float32_t twiddleCoef_32[64]; 53 | extern const float32_t twiddleCoef_64[128]; 54 | extern const float32_t twiddleCoef_128[256]; 55 | extern const float32_t twiddleCoef_256[512]; 56 | extern const float32_t twiddleCoef_512[1024]; 57 | extern const float32_t twiddleCoef_1024[2048]; 58 | extern const float32_t twiddleCoef_2048[4096]; 59 | extern const float32_t twiddleCoef_4096[8192]; 60 | #define twiddleCoef twiddleCoef_4096 61 | extern const q31_t twiddleCoef_16_q31[24]; 62 | extern const q31_t twiddleCoef_32_q31[48]; 63 | extern const q31_t twiddleCoef_64_q31[96]; 64 | extern const q31_t twiddleCoef_128_q31[192]; 65 | extern const q31_t twiddleCoef_256_q31[384]; 66 | extern const q31_t twiddleCoef_512_q31[768]; 67 | extern const q31_t twiddleCoef_1024_q31[1536]; 68 | extern const q31_t twiddleCoef_2048_q31[3072]; 69 | extern const q31_t twiddleCoef_4096_q31[6144]; 70 | extern const q15_t twiddleCoef_16_q15[24]; 71 | extern const q15_t twiddleCoef_32_q15[48]; 72 | extern const q15_t twiddleCoef_64_q15[96]; 73 | extern const q15_t twiddleCoef_128_q15[192]; 74 | extern const q15_t twiddleCoef_256_q15[384]; 75 | extern const q15_t twiddleCoef_512_q15[768]; 76 | extern const q15_t twiddleCoef_1024_q15[1536]; 77 | extern const q15_t twiddleCoef_2048_q15[3072]; 78 | extern const q15_t twiddleCoef_4096_q15[6144]; 79 | extern const float32_t twiddleCoef_rfft_32[32]; 80 | extern const float32_t twiddleCoef_rfft_64[64]; 81 | extern const float32_t twiddleCoef_rfft_128[128]; 82 | extern const float32_t twiddleCoef_rfft_256[256]; 83 | extern const float32_t twiddleCoef_rfft_512[512]; 84 | extern const float32_t twiddleCoef_rfft_1024[1024]; 85 | extern const float32_t twiddleCoef_rfft_2048[2048]; 86 | extern const float32_t twiddleCoef_rfft_4096[4096]; 87 | 88 | 89 | /* floating-point bit reversal tables */ 90 | #define ARMBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 ) 91 | #define ARMBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 ) 92 | #define ARMBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 ) 93 | #define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 ) 94 | #define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 ) 95 | #define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 ) 96 | #define ARMBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800) 97 | #define ARMBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808) 98 | #define ARMBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032) 99 | 100 | extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE__16_TABLE_LENGTH]; 101 | extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE__32_TABLE_LENGTH]; 102 | extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE__64_TABLE_LENGTH]; 103 | extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH]; 104 | extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH]; 105 | extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH]; 106 | extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE1024_TABLE_LENGTH]; 107 | extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE2048_TABLE_LENGTH]; 108 | extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE4096_TABLE_LENGTH]; 109 | 110 | /* fixed-point bit reversal tables */ 111 | #define ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 ) 112 | #define ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 ) 113 | #define ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 ) 114 | #define ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 ) 115 | #define ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 ) 116 | #define ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 ) 117 | #define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 ) 118 | #define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) 119 | #define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) 120 | 121 | extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH]; 122 | extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH]; 123 | extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH]; 124 | extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH]; 125 | extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH]; 126 | extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH]; 127 | extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; 128 | extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; 129 | extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; 130 | 131 | /* Tables for Fast Math Sine and Cosine */ 132 | extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; 133 | extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1]; 134 | extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1]; 135 | 136 | #endif /* ARM_COMMON_TABLES_H */ 137 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/arm_const_structs.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Copyright (C) 2010-2014 ARM Limited. All rights reserved. 3 | * 4 | * $Date: 19. March 2015 5 | * $Revision: V.1.4.5 6 | * 7 | * Project: CMSIS DSP Library 8 | * Title: arm_const_structs.h 9 | * 10 | * Description: This file has constant structs that are initialized for 11 | * user convenience. For example, some can be given as 12 | * arguments to the arm_cfft_f32() function. 13 | * 14 | * Target Processor: Cortex-M4/Cortex-M3 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted provided that the following conditions 18 | * are met: 19 | * - Redistributions of source code must retain the above copyright 20 | * notice, this list of conditions and the following disclaimer. 21 | * - Redistributions in binary form must reproduce the above copyright 22 | * notice, this list of conditions and the following disclaimer in 23 | * the documentation and/or other materials provided with the 24 | * distribution. 25 | * - Neither the name of ARM LIMITED nor the names of its contributors 26 | * may be used to endorse or promote products derived from this 27 | * software without specific prior written permission. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 32 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 33 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 34 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 35 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 36 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 37 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 39 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 40 | * POSSIBILITY OF SUCH DAMAGE. 41 | * -------------------------------------------------------------------- */ 42 | 43 | #ifndef _ARM_CONST_STRUCTS_H 44 | #define _ARM_CONST_STRUCTS_H 45 | 46 | #include "arm_math.h" 47 | #include "arm_common_tables.h" 48 | 49 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16; 50 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32; 51 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64; 52 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128; 53 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256; 54 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512; 55 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024; 56 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048; 57 | extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096; 58 | 59 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16; 60 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32; 61 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64; 62 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128; 63 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256; 64 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512; 65 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024; 66 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048; 67 | extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096; 68 | 69 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16; 70 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32; 71 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64; 72 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128; 73 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256; 74 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512; 75 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024; 76 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048; 77 | extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096; 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/core_cmFunc.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmFunc.h 3 | * @brief CMSIS Cortex-M Core Function Access Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMFUNC_H 42 | #define __CORE_CMFUNC_H 43 | 44 | 45 | /* ########################### Core Function Access ########################### */ 46 | /** \ingroup CMSIS_Core_FunctionInterface 47 | \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions 48 | @{ 49 | */ 50 | 51 | /*------------------ RealView Compiler -----------------*/ 52 | #if defined ( __CC_ARM ) 53 | #include "cmsis_armcc.h" 54 | 55 | /*------------------ ARM Compiler V6 -------------------*/ 56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 57 | #include "cmsis_armcc_V6.h" 58 | 59 | /*------------------ GNU Compiler ----------------------*/ 60 | #elif defined ( __GNUC__ ) 61 | #include "cmsis_gcc.h" 62 | 63 | /*------------------ ICC Compiler ----------------------*/ 64 | #elif defined ( __ICCARM__ ) 65 | #include 66 | 67 | /*------------------ TI CCS Compiler -------------------*/ 68 | #elif defined ( __TMS470__ ) 69 | #include 70 | 71 | /*------------------ TASKING Compiler ------------------*/ 72 | #elif defined ( __TASKING__ ) 73 | /* 74 | * The CMSIS functions have been implemented as intrinsics in the compiler. 75 | * Please use "carm -?i" to get an up to date list of all intrinsics, 76 | * Including the CMSIS ones. 77 | */ 78 | 79 | /*------------------ COSMIC Compiler -------------------*/ 80 | #elif defined ( __CSMC__ ) 81 | #include 82 | 83 | #endif 84 | 85 | /*@} end of CMSIS_Core_RegAccFunctions */ 86 | 87 | #endif /* __CORE_CMFUNC_H */ 88 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/core_cmInstr.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmInstr.h 3 | * @brief CMSIS Cortex-M Core Instruction Access Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMINSTR_H 42 | #define __CORE_CMINSTR_H 43 | 44 | 45 | /* ########################## Core Instruction Access ######################### */ 46 | /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface 47 | Access to dedicated instructions 48 | @{ 49 | */ 50 | 51 | /*------------------ RealView Compiler -----------------*/ 52 | #if defined ( __CC_ARM ) 53 | #include "cmsis_armcc.h" 54 | 55 | /*------------------ ARM Compiler V6 -------------------*/ 56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 57 | #include "cmsis_armcc_V6.h" 58 | 59 | /*------------------ GNU Compiler ----------------------*/ 60 | #elif defined ( __GNUC__ ) 61 | #include "cmsis_gcc.h" 62 | 63 | /*------------------ ICC Compiler ----------------------*/ 64 | #elif defined ( __ICCARM__ ) 65 | #include 66 | 67 | /*------------------ TI CCS Compiler -------------------*/ 68 | #elif defined ( __TMS470__ ) 69 | #include 70 | 71 | /*------------------ TASKING Compiler ------------------*/ 72 | #elif defined ( __TASKING__ ) 73 | /* 74 | * The CMSIS functions have been implemented as intrinsics in the compiler. 75 | * Please use "carm -?i" to get an up to date list of all intrinsics, 76 | * Including the CMSIS ones. 77 | */ 78 | 79 | /*------------------ COSMIC Compiler -------------------*/ 80 | #elif defined ( __CSMC__ ) 81 | #include 82 | 83 | #endif 84 | 85 | /*@}*/ /* end of group CMSIS_Core_InstructionInterface */ 86 | 87 | #endif /* __CORE_CMINSTR_H */ 88 | -------------------------------------------------------------------------------- /Drivers/CMSIS/Include/core_cmSimd.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmSimd.h 3 | * @brief CMSIS Cortex-M SIMD Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMSIMD_H 42 | #define __CORE_CMSIMD_H 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | 49 | /* ################### Compiler specific Intrinsics ########################### */ 50 | /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics 51 | Access to dedicated SIMD instructions 52 | @{ 53 | */ 54 | 55 | /*------------------ RealView Compiler -----------------*/ 56 | #if defined ( __CC_ARM ) 57 | #include "cmsis_armcc.h" 58 | 59 | /*------------------ ARM Compiler V6 -------------------*/ 60 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 61 | #include "cmsis_armcc_V6.h" 62 | 63 | /*------------------ GNU Compiler ----------------------*/ 64 | #elif defined ( __GNUC__ ) 65 | #include "cmsis_gcc.h" 66 | 67 | /*------------------ ICC Compiler ----------------------*/ 68 | #elif defined ( __ICCARM__ ) 69 | #include 70 | 71 | /*------------------ TI CCS Compiler -------------------*/ 72 | #elif defined ( __TMS470__ ) 73 | #include 74 | 75 | /*------------------ TASKING Compiler ------------------*/ 76 | #elif defined ( __TASKING__ ) 77 | /* 78 | * The CMSIS functions have been implemented as intrinsics in the compiler. 79 | * Please use "carm -?i" to get an up to date list of all intrinsics, 80 | * Including the CMSIS ones. 81 | */ 82 | 83 | /*------------------ COSMIC Compiler -------------------*/ 84 | #elif defined ( __CSMC__ ) 85 | #include 86 | 87 | #endif 88 | 89 | /*@} end of group CMSIS_SIMD_intrinsics */ 90 | 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* __CORE_CMSIMD_H */ 97 | -------------------------------------------------------------------------------- /Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_crc_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_crc_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of CRC HAL extended module. 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 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32L4xx_HAL_CRC_EX_H 38 | #define __STM32L4xx_HAL_CRC_EX_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Includes ------------------------------------------------------------------*/ 45 | #include "stm32l4xx_hal_def.h" 46 | 47 | /** @addtogroup STM32L4xx_HAL_Driver 48 | * @{ 49 | */ 50 | 51 | /** @addtogroup CRCEx 52 | * @{ 53 | */ 54 | 55 | /* Exported types ------------------------------------------------------------*/ 56 | /* Exported constants --------------------------------------------------------*/ 57 | /** @defgroup CRCEx_Exported_Constants CRCEx Exported Constants 58 | * @{ 59 | */ 60 | 61 | /** @defgroup CRCEx_Input_Data_Inversion Input Data Inversion Modes 62 | * @{ 63 | */ 64 | #define CRC_INPUTDATA_INVERSION_NONE (0x00000000U) /*!< No input data inversion */ 65 | #define CRC_INPUTDATA_INVERSION_BYTE (CRC_CR_REV_IN_0) /*!< Byte-wise input data inversion */ 66 | #define CRC_INPUTDATA_INVERSION_HALFWORD (CRC_CR_REV_IN_1) /*!< HalfWord-wise input data inversion */ 67 | #define CRC_INPUTDATA_INVERSION_WORD (CRC_CR_REV_IN) /*!< Word-wise input data inversion */ 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup CRCEx_Output_Data_Inversion Output Data Inversion Modes 73 | * @{ 74 | */ 75 | #define CRC_OUTPUTDATA_INVERSION_DISABLE (0x00000000U) /*!< No output data inversion */ 76 | #define CRC_OUTPUTDATA_INVERSION_ENABLE (CRC_CR_REV_OUT) /*!< Bit-wise output data inversion */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | /* Exported macro ------------------------------------------------------------*/ 86 | /** @defgroup CRCEx_Exported_Macros CRCEx Exported Macros 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @brief Set CRC output reversal 92 | * @param __HANDLE__: CRC handle 93 | * @retval None 94 | */ 95 | #define __HAL_CRC_OUTPUTREVERSAL_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= CRC_CR_REV_OUT) 96 | 97 | /** 98 | * @brief Unset CRC output reversal 99 | * @param __HANDLE__: CRC handle 100 | * @retval None 101 | */ 102 | #define __HAL_CRC_OUTPUTREVERSAL_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(CRC_CR_REV_OUT)) 103 | 104 | /** 105 | * @brief Set CRC non-default polynomial 106 | * @param __HANDLE__: CRC handle 107 | * @param __POLYNOMIAL__: 7, 8, 16 or 32-bit polynomial 108 | * @retval None 109 | */ 110 | #define __HAL_CRC_POLYNOMIAL_CONFIG(__HANDLE__, __POLYNOMIAL__) ((__HANDLE__)->Instance->POL = (__POLYNOMIAL__)) 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /* Private macros --------------------------------------------------------*/ 117 | /** @addtogroup CRCEx_Private_Macros CRCEx Private Macros 118 | * @{ 119 | */ 120 | 121 | #define IS_CRC_INPUTDATA_INVERSION_MODE(MODE) (((MODE) == CRC_INPUTDATA_INVERSION_NONE) || \ 122 | ((MODE) == CRC_INPUTDATA_INVERSION_BYTE) || \ 123 | ((MODE) == CRC_INPUTDATA_INVERSION_HALFWORD) || \ 124 | ((MODE) == CRC_INPUTDATA_INVERSION_WORD)) 125 | 126 | 127 | #define IS_CRC_OUTPUTDATA_INVERSION_MODE(MODE) (((MODE) == CRC_OUTPUTDATA_INVERSION_DISABLE) || \ 128 | ((MODE) == CRC_OUTPUTDATA_INVERSION_ENABLE)) 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /* Exported functions --------------------------------------------------------*/ 135 | 136 | /** @addtogroup CRCEx_Exported_Functions CRC Extended Exported Functions 137 | * @{ 138 | */ 139 | 140 | /** @addtogroup CRCEx_Exported_Functions_Group1 Extended Initialization/de-initialization functions 141 | * @{ 142 | */ 143 | 144 | /* Initialization and de-initialization functions ****************************/ 145 | HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol, uint32_t PolyLength); 146 | HAL_StatusTypeDef HAL_CRCEx_Input_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t InputReverseMode); 147 | HAL_StatusTypeDef HAL_CRCEx_Output_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t OutputReverseMode); 148 | 149 | /** 150 | * @} 151 | */ 152 | 153 | /** 154 | * @} 155 | */ 156 | 157 | /** 158 | * @} 159 | */ 160 | 161 | /** 162 | * @} 163 | */ 164 | 165 | #ifdef __cplusplus 166 | } 167 | #endif 168 | 169 | #endif /* __STM32L4xx_HAL_CRC_EX_H */ 170 | 171 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 172 | -------------------------------------------------------------------------------- /Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_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 | * 12 | * Redistribution and use in source and binary forms, with or without modification, 13 | * are permitted provided that the following conditions are met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | ****************************************************************************** 35 | */ 36 | 37 | /* Define to prevent recursive inclusion -------------------------------------*/ 38 | #ifndef __STM32L4xx_HAL_DEF 39 | #define __STM32L4xx_HAL_DEF 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* Includes ------------------------------------------------------------------*/ 46 | #include "stm32l4xx.h" 47 | #include "Legacy/stm32_hal_legacy.h" /* Aliases file for old names compatibility */ 48 | #include 49 | 50 | /* Exported types ------------------------------------------------------------*/ 51 | 52 | /** 53 | * @brief HAL Status structures definition 54 | */ 55 | typedef enum 56 | { 57 | HAL_OK = 0x00, 58 | HAL_ERROR = 0x01, 59 | HAL_BUSY = 0x02, 60 | HAL_TIMEOUT = 0x03 61 | } HAL_StatusTypeDef; 62 | 63 | /** 64 | * @brief HAL Lock structures definition 65 | */ 66 | typedef enum 67 | { 68 | HAL_UNLOCKED = 0x00, 69 | HAL_LOCKED = 0x01 70 | } HAL_LockTypeDef; 71 | 72 | /* Exported macros -----------------------------------------------------------*/ 73 | 74 | #define HAL_MAX_DELAY 0xFFFFFFFFU 75 | 76 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) == (BIT)) 77 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == RESET) 78 | 79 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 80 | do{ \ 81 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 82 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 83 | } while(0) 84 | 85 | #define UNUSED(x) ((void)(x)) 86 | 87 | /** @brief Reset the Handle's State field. 88 | * @param __HANDLE__: specifies the Peripheral Handle. 89 | * @note This macro can be used for the following purpose: 90 | * - When the Handle is declared as local variable; before passing it as parameter 91 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro 92 | * to set to 0 the Handle's "State" field. 93 | * Otherwise, "State" field may have any random value and the first time the function 94 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed 95 | * (i.e. HAL_PPP_MspInit() will not be executed). 96 | * - When there is a need to reconfigure the low level hardware: instead of calling 97 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init(). 98 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function 99 | * HAL_PPP_MspInit() which will reconfigure the low level hardware. 100 | * @retval None 101 | */ 102 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0) 103 | 104 | #if (USE_RTOS == 1) 105 | /* Reserved for future use */ 106 | #error " USE_RTOS should be 0 in the current HAL release " 107 | #else 108 | #define __HAL_LOCK(__HANDLE__) \ 109 | do{ \ 110 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 111 | { \ 112 | return HAL_BUSY; \ 113 | } \ 114 | else \ 115 | { \ 116 | (__HANDLE__)->Lock = HAL_LOCKED; \ 117 | } \ 118 | }while (0) 119 | 120 | #define __HAL_UNLOCK(__HANDLE__) \ 121 | do{ \ 122 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 123 | }while (0) 124 | #endif /* USE_RTOS */ 125 | 126 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 127 | #ifndef __weak 128 | #define __weak __attribute__((weak)) 129 | #endif /* __weak */ 130 | #ifndef __packed 131 | #define __packed __attribute__((__packed__)) 132 | #endif /* __packed */ 133 | #endif /* __GNUC__ */ 134 | 135 | 136 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */ 137 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ 138 | #ifndef __ALIGN_END 139 | #define __ALIGN_END __attribute__ ((aligned (4))) 140 | #endif /* __ALIGN_END */ 141 | #ifndef __ALIGN_BEGIN 142 | #define __ALIGN_BEGIN 143 | #endif /* __ALIGN_BEGIN */ 144 | #else 145 | #ifndef __ALIGN_END 146 | #define __ALIGN_END 147 | #endif /* __ALIGN_END */ 148 | #ifndef __ALIGN_BEGIN 149 | #if defined (__CC_ARM) /* ARM Compiler */ 150 | #define __ALIGN_BEGIN __align(4) 151 | #elif defined (__ICCARM__) /* IAR Compiler */ 152 | #define __ALIGN_BEGIN 153 | #endif /* __CC_ARM */ 154 | #endif /* __ALIGN_BEGIN */ 155 | #endif /* __GNUC__ */ 156 | 157 | /** 158 | * @brief __RAM_FUNC definition 159 | */ 160 | #if defined ( __CC_ARM ) 161 | /* ARM Compiler 162 | ------------ 163 | RAM functions are defined using the toolchain options. 164 | Functions that are executed in RAM should reside in a separate source module. 165 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 166 | area of a module to a memory space in physical RAM. 167 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 168 | dialog. 169 | */ 170 | #define __RAM_FUNC HAL_StatusTypeDef 171 | 172 | #elif defined ( __ICCARM__ ) 173 | /* ICCARM Compiler 174 | --------------- 175 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 176 | */ 177 | #define __RAM_FUNC __ramfunc HAL_StatusTypeDef 178 | 179 | #elif defined ( __GNUC__ ) 180 | /* GNU Compiler 181 | ------------ 182 | RAM functions are defined using a specific toolchain attribute 183 | "__attribute__((section(".RamFunc")))". 184 | */ 185 | #define __RAM_FUNC HAL_StatusTypeDef __attribute__((section(".RamFunc"))) 186 | 187 | #endif 188 | 189 | /** 190 | * @brief __NOINLINE definition 191 | */ 192 | #if defined ( __CC_ARM ) || defined ( __GNUC__ ) 193 | /* ARM & GNUCompiler 194 | ---------------- 195 | */ 196 | #define __NOINLINE __attribute__ ( (noinline) ) 197 | 198 | #elif defined ( __ICCARM__ ) 199 | /* ICCARM Compiler 200 | --------------- 201 | */ 202 | #define __NOINLINE _Pragma("optimize = no_inline") 203 | 204 | #endif 205 | 206 | 207 | #ifdef __cplusplus 208 | } 209 | #endif 210 | 211 | #endif /* ___STM32L4xx_HAL_DEF */ 212 | 213 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 214 | -------------------------------------------------------------------------------- /Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_flash_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH HAL Extended module. 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 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32L4xx_HAL_FLASH_EX_H 38 | #define __STM32L4xx_HAL_FLASH_EX_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Includes ------------------------------------------------------------------*/ 45 | #include "stm32l4xx_hal_def.h" 46 | 47 | /** @addtogroup STM32L4xx_HAL_Driver 48 | * @{ 49 | */ 50 | 51 | /** @addtogroup FLASHEx 52 | * @{ 53 | */ 54 | 55 | /* Exported types ------------------------------------------------------------*/ 56 | 57 | /* Exported constants --------------------------------------------------------*/ 58 | #if defined (FLASH_CFGR_LVEN) 59 | /** @addtogroup FLASHEx_Exported_Constants 60 | * @{ 61 | */ 62 | /** @defgroup FLASHEx_LVE_PIN_CFG FLASHEx LVE pin configuration 63 | * @{ 64 | */ 65 | #define FLASH_LVE_PIN_CTRL 0x00000000U /*!< LVE FLASH pin controlled by power controller */ 66 | #define FLASH_LVE_PIN_FORCED FLASH_CFGR_LVEN /*!< LVE FLASH pin enforced to low (external SMPS used) */ 67 | /** 68 | * @} 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | #endif /* FLASH_CFGR_LVEN */ 75 | 76 | /* Exported macro ------------------------------------------------------------*/ 77 | 78 | /* Exported functions --------------------------------------------------------*/ 79 | /** @addtogroup FLASHEx_Exported_Functions 80 | * @{ 81 | */ 82 | 83 | /* Extended Program operation functions *************************************/ 84 | /** @addtogroup FLASHEx_Exported_Functions_Group1 85 | * @{ 86 | */ 87 | HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError); 88 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit); 89 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit); 90 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit); 91 | /** 92 | * @} 93 | */ 94 | 95 | #if defined (FLASH_CFGR_LVEN) 96 | /** @addtogroup FLASHEx_Exported_Functions_Group2 97 | * @{ 98 | */ 99 | HAL_StatusTypeDef HAL_FLASHEx_ConfigLVEPin(uint32_t ConfigLVE); 100 | /** 101 | * @} 102 | */ 103 | #endif /* FLASH_CFGR_LVEN */ 104 | 105 | /** 106 | * @} 107 | */ 108 | 109 | /* Private macros ------------------------------------------------------------*/ 110 | /** 111 | @cond 0 112 | */ 113 | #if defined (FLASH_CFGR_LVEN) 114 | #define IS_FLASH_LVE_PIN(CFG) (((CFG) == FLASH_LVE_PIN_CTRL) || ((CFG) == FLASH_LVE_PIN_FORCED)) 115 | #endif /* FLASH_CFGR_LVEN */ 116 | /** 117 | @endcond 118 | */ 119 | 120 | /** 121 | * @} 122 | */ 123 | 124 | /** 125 | * @} 126 | */ 127 | 128 | #ifdef __cplusplus 129 | } 130 | #endif 131 | 132 | #endif /* __STM32L4xx_HAL_FLASH_EX_H */ 133 | 134 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 135 | -------------------------------------------------------------------------------- /Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_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 | * 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 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32L4xx_FLASH_RAMFUNC_H 38 | #define __STM32L4xx_FLASH_RAMFUNC_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* Includes ------------------------------------------------------------------*/ 45 | #include "stm32l4xx_hal_def.h" 46 | 47 | /** @addtogroup STM32L4xx_HAL_Driver 48 | * @{ 49 | */ 50 | 51 | /** @addtogroup FLASH_RAMFUNC 52 | * @{ 53 | */ 54 | 55 | /* Exported types ------------------------------------------------------------*/ 56 | /* Exported macro ------------------------------------------------------------*/ 57 | /** 58 | * @brief __RAM_FUNC definition 59 | */ 60 | #if defined ( __CC_ARM ) 61 | /* ARM Compiler 62 | ------------ 63 | RAM functions are defined using the toolchain options. 64 | Functions that are executed in RAM should reside in a separate source module. 65 | Using the 'Options for File' dialog you can simply change the 'Code / Const' 66 | area of a module to a memory space in physical RAM. 67 | Available memory areas are declared in the 'Target' tab of the 'Options for Target' 68 | dialog. 69 | */ 70 | #define __RAM_FUNC HAL_StatusTypeDef 71 | 72 | #elif defined ( __ICCARM__ ) 73 | /* ICCARM Compiler 74 | --------------- 75 | RAM functions are defined using a specific toolchain keyword "__ramfunc". 76 | */ 77 | #define __RAM_FUNC __ramfunc HAL_StatusTypeDef 78 | 79 | #elif defined ( __GNUC__ ) 80 | /* GNU Compiler 81 | ------------ 82 | RAM functions are defined using a specific toolchain attribute 83 | "__attribute__((section(".RamFunc")))". 84 | */ 85 | #define __RAM_FUNC HAL_StatusTypeDef __attribute__((section(".RamFunc"))) 86 | 87 | #endif 88 | 89 | 90 | /* Exported functions --------------------------------------------------------*/ 91 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 92 | * @{ 93 | */ 94 | 95 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 96 | * @{ 97 | */ 98 | /* Peripheral Control functions ************************************************/ 99 | __RAM_FUNC HAL_FLASHEx_EnableRunPowerDown(void); 100 | __RAM_FUNC HAL_FLASHEx_DisableRunPowerDown(void); 101 | #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) 102 | __RAM_FUNC HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig); 103 | #endif 104 | /** 105 | * @} 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | /** 117 | * @} 118 | */ 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | 124 | #endif /* __STM32L4xx_FLASH_RAMFUNC_H */ 125 | 126 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 127 | -------------------------------------------------------------------------------- /Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal_sd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_sd_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of SD HAL extended module. 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 | /* Define to prevent recursive inclusion -------------------------------------*/ 37 | #ifndef __STM32L4xx_HAL_SD_EX_H 38 | #define __STM32L4xx_HAL_SD_EX_H 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 45 | 46 | /* Includes ------------------------------------------------------------------*/ 47 | #include "stm32l4xx_hal_def.h" 48 | 49 | /** @addtogroup STM32L4xx_HAL_Driver 50 | * @{ 51 | */ 52 | 53 | /** @addtogroup SDEx 54 | * @{ 55 | */ 56 | 57 | /* Exported types ------------------------------------------------------------*/ 58 | /** @defgroup SDEx_Exported_Types SDEx Exported Types 59 | * @{ 60 | */ 61 | 62 | /** @defgroup SDEx_Exported_Types_Group1 SD Card Internal DMA Buffer structure 63 | * @{ 64 | */ 65 | typedef enum 66 | { 67 | SD_DMA_BUFFER0 = 0x00U, /*!< selects SD internal DMA Buffer 0 */ 68 | SD_DMA_BUFFER1 = 0x01U, /*!< selects SD internal DMA Buffer 1 */ 69 | 70 | }HAL_SDEx_DMABuffer_MemoryTypeDef; 71 | 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** 78 | * @} 79 | */ 80 | /* Exported constants --------------------------------------------------------*/ 81 | /* Exported macro ------------------------------------------------------------*/ 82 | /* Exported functions --------------------------------------------------------*/ 83 | /** @defgroup SDEx_Exported_Functions SDEx Exported Functions 84 | * @{ 85 | */ 86 | 87 | /** @defgroup SDEx_Exported_Functions_Group1 HighSpeed functions 88 | * @{ 89 | */ 90 | uint32_t HAL_SDEx_HighSpeed (SD_HandleTypeDef *hsd); 91 | 92 | void HAL_SDEx_DriveTransceiver_1_8V_Callback(FlagStatus status); 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** @defgroup SDEx_Exported_Functions_Group2 MultiBuffer functions 99 | * @{ 100 | */ 101 | HAL_StatusTypeDef HAL_SDEx_ConfigDMAMultiBuffer(SD_HandleTypeDef *hsd, uint32_t * pDataBuffer0, uint32_t * pDataBuffer1, uint32_t BufferSize); 102 | HAL_StatusTypeDef HAL_SDEx_ReadBlocksDMAMultiBuffer(SD_HandleTypeDef *hsd, uint32_t BlockAdd, uint32_t NumberOfBlocks); 103 | HAL_StatusTypeDef HAL_SDEx_WriteBlocksDMAMultiBuffer(SD_HandleTypeDef *hsd, uint32_t BlockAdd, uint32_t NumberOfBlocks); 104 | HAL_StatusTypeDef HAL_SDEx_ChangeDMABuffer(SD_HandleTypeDef *hsd, HAL_SDEx_DMABuffer_MemoryTypeDef Buffer, uint32_t *pDataBuffer); 105 | 106 | void HAL_SDEx_Read_DMADoubleBuffer0CpltCallback(SD_HandleTypeDef *hsd); 107 | void HAL_SDEx_Read_DMADoubleBuffer1CpltCallback(SD_HandleTypeDef *hsd); 108 | void HAL_SDEx_Write_DMADoubleBuffer0CpltCallback(SD_HandleTypeDef *hsd); 109 | void HAL_SDEx_Write_DMADoubleBuffer1CpltCallback(SD_HandleTypeDef *hsd); 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /* Private types -------------------------------------------------------------*/ 120 | /* Private defines -----------------------------------------------------------*/ 121 | /* Private variables ---------------------------------------------------------*/ 122 | /* Private constants ---------------------------------------------------------*/ 123 | /* Private macros ------------------------------------------------------------*/ 124 | /* Private functions prototypes ----------------------------------------------*/ 125 | /* Private functions ---------------------------------------------------------*/ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */ 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | 142 | #endif /* __STM32L4xx_HAL_SDEx_H */ 143 | 144 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 145 | -------------------------------------------------------------------------------- /Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_crc_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_crc_ex.c 4 | * @author MCD Application Team 5 | * @brief Extended CRC HAL module driver. 6 | * This file provides firmware functions to manage the extended 7 | * functionalities of the CRC peripheral. 8 | * 9 | @verbatim 10 | ================================================================================ 11 | ##### How to use this driver ##### 12 | ================================================================================ 13 | [..] 14 | (+) Set user-defined generating polynomial thru HAL_CRCEx_Polynomial_Set() 15 | (+) Configure Input or Output data inversion 16 | 17 | @endverbatim 18 | ****************************************************************************** 19 | * @attention 20 | * 21 | *

© COPYRIGHT(c) 2017 STMicroelectronics

22 | * 23 | * Redistribution and use in source and binary forms, with or without modification, 24 | * are permitted provided that the following conditions are met: 25 | * 1. Redistributions of source code must retain the above copyright notice, 26 | * this list of conditions and the following disclaimer. 27 | * 2. Redistributions in binary form must reproduce the above copyright notice, 28 | * this list of conditions and the following disclaimer in the documentation 29 | * and/or other materials provided with the distribution. 30 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 31 | * may be used to endorse or promote products derived from this software 32 | * without specific prior written permission. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 36 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 37 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 38 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 39 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 40 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 41 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 42 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 43 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | * 45 | ****************************************************************************** 46 | */ 47 | 48 | /* Includes ------------------------------------------------------------------*/ 49 | #include "stm32l4xx_hal.h" 50 | 51 | /** @addtogroup STM32L4xx_HAL_Driver 52 | * @{ 53 | */ 54 | 55 | /** @defgroup CRCEx CRCEx 56 | * @brief CRC Extended HAL module driver 57 | * @{ 58 | */ 59 | 60 | #ifdef HAL_CRC_MODULE_ENABLED 61 | 62 | /* Private typedef -----------------------------------------------------------*/ 63 | /* Private define ------------------------------------------------------------*/ 64 | /* Private macro -------------------------------------------------------------*/ 65 | /* Private variables ---------------------------------------------------------*/ 66 | /* Private function prototypes -----------------------------------------------*/ 67 | /* Exported functions --------------------------------------------------------*/ 68 | 69 | /** @defgroup CRCEx_Exported_Functions CRC Extended Exported Functions 70 | * @{ 71 | */ 72 | 73 | /** @defgroup CRCEx_Exported_Functions_Group1 Extended Initialization/de-initialization functions 74 | * @brief Extended Initialization and Configuration functions. 75 | * 76 | @verbatim 77 | =============================================================================== 78 | ##### Extended configuration functions ##### 79 | =============================================================================== 80 | [..] This section provides functions allowing to: 81 | (+) Configure the generating polynomial 82 | (+) Configure the input data inversion 83 | (+) Configure the output data inversion 84 | 85 | @endverbatim 86 | * @{ 87 | */ 88 | 89 | 90 | /** 91 | * @brief Initialize the CRC polynomial if different from default one. 92 | * @param hcrc: CRC handle 93 | * @param Pol: CRC generating polynomial (7, 8, 16 or 32-bit long). 94 | * This parameter is written in normal representation, e.g. 95 | * @arg for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65 96 | * @arg for a polynomial of degree 16, X^16 + X^12 + X^5 + 1 is written 0x1021 97 | * @param PolyLength: CRC polynomial length. 98 | * This parameter can be one of the following values: 99 | * @arg @ref CRC_POLYLENGTH_7B 7-bit long CRC (generating polynomial of degree 7) 100 | * @arg @ref CRC_POLYLENGTH_8B 8-bit long CRC (generating polynomial of degree 8) 101 | * @arg @ref CRC_POLYLENGTH_16B 16-bit long CRC (generating polynomial of degree 16) 102 | * @arg @ref CRC_POLYLENGTH_32B 32-bit long CRC (generating polynomial of degree 32) 103 | * @retval HAL status 104 | */ 105 | HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol, uint32_t PolyLength) 106 | { 107 | uint32_t msb = 31; /* polynomial degree is 32 at most, so msb is initialized to max value */ 108 | 109 | /* Check the parameters */ 110 | assert_param(IS_CRC_POL_LENGTH(PolyLength)); 111 | 112 | /* check polynomial definition vs polynomial size: 113 | * polynomial length must be aligned with polynomial 114 | * definition. HAL_ERROR is reported if Pol degree is 115 | * larger than that indicated by PolyLength. 116 | * Look for MSB position: msb will contain the degree of 117 | * the second to the largest polynomial member. E.g., for 118 | * X^7 + X^6 + X^5 + X^2 + 1, msb = 6. */ 119 | while (((Pol & (1U << msb)) == 0) && (msb-- > 0)) {} 120 | 121 | switch (PolyLength) 122 | { 123 | case CRC_POLYLENGTH_7B: 124 | if (msb >= HAL_CRC_LENGTH_7B) 125 | { 126 | return HAL_ERROR; 127 | } 128 | break; 129 | case CRC_POLYLENGTH_8B: 130 | if (msb >= HAL_CRC_LENGTH_8B) 131 | { 132 | return HAL_ERROR; 133 | } 134 | break; 135 | case CRC_POLYLENGTH_16B: 136 | if (msb >= HAL_CRC_LENGTH_16B) 137 | { 138 | return HAL_ERROR; 139 | } 140 | break; 141 | case CRC_POLYLENGTH_32B: 142 | /* no polynomial definition vs. polynomial length issue possible */ 143 | break; 144 | default: 145 | return HAL_ERROR; 146 | } 147 | 148 | /* set generating polynomial */ 149 | WRITE_REG(hcrc->Instance->POL, Pol); 150 | 151 | /* set generating polynomial size */ 152 | MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, PolyLength); 153 | 154 | /* Return function status */ 155 | return HAL_OK; 156 | } 157 | 158 | /** 159 | * @brief Set the Reverse Input data mode. 160 | * @param hcrc: CRC handle 161 | * @param InputReverseMode: Input Data inversion mode. 162 | * This parameter can be one of the following values: 163 | * @arg @ref CRC_INPUTDATA_INVERSION_NONE no change in bit order (default value) 164 | * @arg @ref CRC_INPUTDATA_INVERSION_BYTE Byte-wise bit reversal 165 | * @arg @ref CRC_INPUTDATA_INVERSION_HALFWORD HalfWord-wise bit reversal 166 | * @arg @ref CRC_INPUTDATA_INVERSION_WORD Word-wise bit reversal 167 | * @retval HAL status 168 | */ 169 | HAL_StatusTypeDef HAL_CRCEx_Input_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t InputReverseMode) 170 | { 171 | /* Check the parameters */ 172 | assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(InputReverseMode)); 173 | 174 | /* Change CRC peripheral state */ 175 | hcrc->State = HAL_CRC_STATE_BUSY; 176 | 177 | /* set input data inversion mode */ 178 | MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, InputReverseMode); 179 | /* Change CRC peripheral state */ 180 | hcrc->State = HAL_CRC_STATE_READY; 181 | 182 | /* Return function status */ 183 | return HAL_OK; 184 | } 185 | 186 | /** 187 | * @brief Set the Reverse Output data mode. 188 | * @param hcrc: CRC handle 189 | * @param OutputReverseMode: Output Data inversion mode. 190 | * This parameter can be one of the following values: 191 | * @arg @ref CRC_OUTPUTDATA_INVERSION_DISABLE no CRC inversion (default value) 192 | * @arg @ref CRC_OUTPUTDATA_INVERSION_ENABLE bit-level inversion (e.g. for a 8-bit CRC: 0xB5 becomes 0xAD) 193 | * @retval HAL status 194 | */ 195 | HAL_StatusTypeDef HAL_CRCEx_Output_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t OutputReverseMode) 196 | { 197 | /* Check the parameters */ 198 | assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(OutputReverseMode)); 199 | 200 | /* Change CRC peripheral state */ 201 | hcrc->State = HAL_CRC_STATE_BUSY; 202 | 203 | /* set output data inversion mode */ 204 | MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, OutputReverseMode); 205 | 206 | /* Change CRC peripheral state */ 207 | hcrc->State = HAL_CRC_STATE_READY; 208 | 209 | /* Return function status */ 210 | return HAL_OK; 211 | } 212 | 213 | 214 | 215 | 216 | /** 217 | * @} 218 | */ 219 | 220 | 221 | /** 222 | * @} 223 | */ 224 | 225 | 226 | #endif /* HAL_CRC_MODULE_ENABLED */ 227 | /** 228 | * @} 229 | */ 230 | 231 | /** 232 | * @} 233 | */ 234 | 235 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 236 | -------------------------------------------------------------------------------- /Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_dma_ex.c 4 | * @author MCD Application Team 5 | * @brief DMA Extension HAL module driver 6 | * This file provides firmware functions to manage the following 7 | * functionalities of the DMA Extension peripheral: 8 | * + Extended features functions 9 | * 10 | @verbatim 11 | ============================================================================== 12 | ##### How to use this driver ##### 13 | ============================================================================== 14 | [..] 15 | The DMA Extension HAL driver can be used as follows: 16 | 17 | (+) Configure the DMA_MUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function. 18 | (+) Configure the DMA_MUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function. 19 | Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used 20 | to respectively enable/disable the request generator. 21 | 22 | (+) To handle the DMAMUX Interrupts, the function HAL_DMAEx_MUX_IRQHandler should be called from 23 | the DMAMUX IRQ handler i.e DMAMUX1_OVR_IRQHandler. 24 | As only one interrupt line is available for all DMAMUX channels and request generators , HAL_DMAEx_MUX_IRQHandler should be 25 | called with, as parameter, the appropriate DMA handle as many as used DMAs in the user project 26 | (exception done if a given DMA is not using the DMAMUX SYNC block neither a request generator) 27 | 28 | @endverbatim 29 | ****************************************************************************** 30 | * @attention 31 | * 32 | *

© COPYRIGHT(c) 2017 STMicroelectronics

33 | * 34 | * Redistribution and use in source and binary forms, with or without modification, 35 | * are permitted provided that the following conditions are met: 36 | * 1. Redistributions of source code must retain the above copyright notice, 37 | * this list of conditions and the following disclaimer. 38 | * 2. Redistributions in binary form must reproduce the above copyright notice, 39 | * this list of conditions and the following disclaimer in the documentation 40 | * and/or other materials provided with the distribution. 41 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 42 | * may be used to endorse or promote products derived from this software 43 | * without specific prior written permission. 44 | * 45 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 46 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 47 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 48 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 49 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 50 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 51 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 52 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 53 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 54 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 | * 56 | ****************************************************************************** 57 | */ 58 | 59 | /* Includes ------------------------------------------------------------------*/ 60 | #include "stm32l4xx_hal.h" 61 | 62 | #if defined(DMAMUX1) 63 | 64 | /** @addtogroup STM32L4xx_HAL_Driver 65 | * @{ 66 | */ 67 | 68 | /** @defgroup DMAEx DMAEx 69 | * @brief DMA Extended HAL module driver 70 | * @{ 71 | */ 72 | 73 | #ifdef HAL_DMA_MODULE_ENABLED 74 | 75 | /* Private typedef -----------------------------------------------------------*/ 76 | /* Private define ------------------------------------------------------------*/ 77 | /* Private macro -------------------------------------------------------------*/ 78 | /* Private variables ---------------------------------------------------------*/ 79 | /* Private Constants ---------------------------------------------------------*/ 80 | /* Private function prototypes -----------------------------------------------*/ 81 | /* Private functions ---------------------------------------------------------*/ 82 | 83 | 84 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 85 | * @{ 86 | */ 87 | 88 | /** @defgroup DMAEx_Exported_Functions_Group1 DMAEx Extended features functions 89 | * @brief Extended features functions 90 | * 91 | @verbatim 92 | =============================================================================== 93 | ##### Extended features functions ##### 94 | =============================================================================== 95 | [..] This section provides functions allowing to: 96 | 97 | (+) Configure the DMAMUX Synchronization Block using HAL_DMAEx_ConfigMuxSync function. 98 | (+) Configure the DMAMUX Request Generator Block using HAL_DMAEx_ConfigMuxRequestGenerator function. 99 | Functions HAL_DMAEx_EnableMuxRequestGenerator and HAL_DMAEx_DisableMuxRequestGenerator can then be used 100 | to respectively enable/disable the request generator. 101 | 102 | @endverbatim 103 | * @{ 104 | */ 105 | 106 | 107 | /** 108 | * @brief Configure the DMAMUX synchronization parameters for a given DMA channel (instance). 109 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 110 | * the configuration information for the specified DMA channel. 111 | * @param pSyncConfig : pointer to HAL_DMA_MuxSyncConfigTypeDef : contains the DMAMUX synchronization parameters 112 | * @retval HAL status 113 | */ 114 | HAL_StatusTypeDef HAL_DMAEx_ConfigMuxSync(DMA_HandleTypeDef *hdma, HAL_DMA_MuxSyncConfigTypeDef *pSyncConfig) 115 | { 116 | /* Check the parameters */ 117 | assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 118 | 119 | assert_param(IS_DMAMUX_SYNC_SIGNAL_ID(pSyncConfig->SyncSignalID)); 120 | 121 | assert_param(IS_DMAMUX_SYNC_POLARITY(pSyncConfig-> SyncPolarity)); 122 | assert_param(IS_DMAMUX_SYNC_STATE(pSyncConfig->SyncEnable)); 123 | assert_param(IS_DMAMUX_SYNC_EVENT(pSyncConfig->EventEnable)); 124 | assert_param(IS_DMAMUX_SYNC_REQUEST_NUMBER(pSyncConfig->RequestNumber)); 125 | 126 | /*Check if the DMA state is ready */ 127 | if(hdma->State == HAL_DMA_STATE_READY) 128 | { 129 | /* Process Locked */ 130 | __HAL_LOCK(hdma); 131 | 132 | /* Set the new synchronization parameters (and keep the request ID filled during the Init)*/ 133 | MODIFY_REG( hdma->DMAmuxChannel->CCR, \ 134 | (~DMAMUX_CxCR_DMAREQ_ID) , \ 135 | ((pSyncConfig->SyncSignalID) << DMAMUX_CxCR_SYNC_ID_Pos) | ((pSyncConfig->RequestNumber - 1U) << DMAMUX_CxCR_NBREQ_Pos) | \ 136 | pSyncConfig->SyncPolarity | (pSyncConfig->SyncEnable << DMAMUX_CxCR_SE_Pos) | \ 137 | (pSyncConfig->EventEnable << DMAMUX_CxCR_EGE_Pos)); 138 | 139 | /* Process UnLocked */ 140 | __HAL_UNLOCK(hdma); 141 | 142 | return HAL_OK; 143 | } 144 | else 145 | { 146 | /*DMA State not Ready*/ 147 | return HAL_ERROR; 148 | } 149 | } 150 | 151 | /** 152 | * @brief Configure the DMAMUX request generator block used by the given DMA channel (instance). 153 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 154 | * the configuration information for the specified DMA channel. 155 | * @param pRequestGeneratorConfig : pointer to HAL_DMA_MuxRequestGeneratorConfigTypeDef : 156 | * contains the request generator parameters. 157 | * 158 | * @retval HAL status 159 | */ 160 | HAL_StatusTypeDef HAL_DMAEx_ConfigMuxRequestGenerator (DMA_HandleTypeDef *hdma, HAL_DMA_MuxRequestGeneratorConfigTypeDef *pRequestGeneratorConfig) 161 | { 162 | /* Check the parameters */ 163 | assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 164 | 165 | assert_param(IS_DMAMUX_REQUEST_GEN_SIGNAL_ID(pRequestGeneratorConfig->SignalID)); 166 | 167 | assert_param(IS_DMAMUX_REQUEST_GEN_POLARITY(pRequestGeneratorConfig->Polarity)); 168 | assert_param(IS_DMAMUX_REQUEST_GEN_REQUEST_NUMBER(pRequestGeneratorConfig->RequestNumber)); 169 | 170 | /* check if the DMA state is ready 171 | and DMA is using a DMAMUX request generator block 172 | */ 173 | if((hdma->State == HAL_DMA_STATE_READY) && (hdma->DMAmuxRequestGen != 0U)) 174 | { 175 | /* Process Locked */ 176 | __HAL_LOCK(hdma); 177 | 178 | /* Set the request generator new parameters*/ 179 | hdma->DMAmuxRequestGen->RGCR = pRequestGeneratorConfig->SignalID | \ 180 | ((pRequestGeneratorConfig->RequestNumber - 1U) << POSITION_VAL(DMAMUX_RGxCR_GNBREQ))| \ 181 | pRequestGeneratorConfig->Polarity; 182 | /* Process UnLocked */ 183 | __HAL_UNLOCK(hdma); 184 | 185 | return HAL_OK; 186 | } 187 | else 188 | { 189 | return HAL_ERROR; 190 | } 191 | } 192 | 193 | /** 194 | * @brief Enable the DMAMUX request generator block used by the given DMA channel (instance). 195 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 196 | * the configuration information for the specified DMA channel. 197 | * @retval HAL status 198 | */ 199 | HAL_StatusTypeDef HAL_DMAEx_EnableMuxRequestGenerator (DMA_HandleTypeDef *hdma) 200 | { 201 | /* Check the parameters */ 202 | assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 203 | 204 | /* check if the DMA state is ready 205 | and DMA is using a DMAMUX request generator block 206 | */ 207 | if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0)) 208 | { 209 | 210 | /* Enable the request generator*/ 211 | hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_GE; 212 | 213 | return HAL_OK; 214 | } 215 | else 216 | { 217 | return HAL_ERROR; 218 | } 219 | } 220 | 221 | /** 222 | * @brief Disable the DMAMUX request generator block used by the given DMA channel (instance). 223 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 224 | * the configuration information for the specified DMA channel. 225 | * @retval HAL status 226 | */ 227 | HAL_StatusTypeDef HAL_DMAEx_DisableMuxRequestGenerator (DMA_HandleTypeDef *hdma) 228 | { 229 | /* Check the parameters */ 230 | assert_param(IS_DMA_ALL_INSTANCE(hdma->Instance)); 231 | 232 | /* check if the DMA state is ready 233 | and DMA is using a DMAMUX request generator block 234 | */ 235 | if((hdma->State != HAL_DMA_STATE_RESET) && (hdma->DMAmuxRequestGen != 0)) 236 | { 237 | 238 | /* Disable the request generator*/ 239 | hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_GE; 240 | 241 | return HAL_OK; 242 | } 243 | else 244 | { 245 | return HAL_ERROR; 246 | } 247 | } 248 | 249 | /** 250 | * @brief Handles DMAMUX interrupt request. 251 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains 252 | * the configuration information for the specified DMA channel. 253 | * @retval None 254 | */ 255 | void HAL_DMAEx_MUX_IRQHandler(DMA_HandleTypeDef *hdma) 256 | { 257 | /* Check for DMAMUX Synchronization overrun */ 258 | if((hdma->DMAmuxChannelStatus->CSR & hdma->DMAmuxChannelStatusMask) != 0U) 259 | { 260 | /* Disable the synchro overrun interrupt */ 261 | hdma->DMAmuxChannel->CCR &= ~DMAMUX_CxCR_SOIE; 262 | 263 | /* Clear the DMAMUX synchro overrun flag */ 264 | hdma->DMAmuxChannelStatus->CFR = hdma->DMAmuxChannelStatusMask; 265 | 266 | /* Update error code */ 267 | hdma->ErrorCode |= HAL_DMA_ERROR_SYNC; 268 | 269 | if(hdma->XferErrorCallback != NULL) 270 | { 271 | /* Transfer error callback */ 272 | hdma->XferErrorCallback(hdma); 273 | } 274 | } 275 | 276 | if(hdma->DMAmuxRequestGen != 0) 277 | { 278 | /* if using a DMAMUX request generator block Check for DMAMUX request generator overrun */ 279 | if((hdma->DMAmuxRequestGenStatus->RGSR & hdma->DMAmuxRequestGenStatusMask) != 0U) 280 | { 281 | /* Disable the request gen overrun interrupt */ 282 | hdma->DMAmuxRequestGen->RGCR &= ~DMAMUX_RGxCR_OIE; 283 | 284 | /* Clear the DMAMUX request generator overrun flag */ 285 | hdma->DMAmuxRequestGenStatus->RGCFR = hdma->DMAmuxRequestGenStatusMask; 286 | 287 | /* Update error code */ 288 | hdma->ErrorCode |= HAL_DMA_ERROR_REQGEN; 289 | 290 | if(hdma->XferErrorCallback != NULL) 291 | { 292 | /* Transfer error callback */ 293 | hdma->XferErrorCallback(hdma); 294 | } 295 | } 296 | } 297 | } 298 | 299 | /** 300 | * @} 301 | */ 302 | 303 | /** 304 | * @} 305 | */ 306 | 307 | #endif /* HAL_DMA_MODULE_ENABLED */ 308 | 309 | /** 310 | * @} 311 | */ 312 | 313 | /** 314 | * @} 315 | */ 316 | 317 | #endif /* DMAMUX1 */ 318 | 319 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 320 | -------------------------------------------------------------------------------- /Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32l4xx_hal_flash_ramfunc.c 4 | * @author MCD Application Team 5 | * @brief FLASH RAMFUNC driver. 6 | * This file provides a Flash firmware functions which should be 7 | * executed from internal SRAM 8 | * + FLASH HalfPage Programming 9 | * + FLASH Power Down in Run mode 10 | * 11 | * @verbatim 12 | ============================================================================== 13 | ##### Flash RAM functions ##### 14 | ============================================================================== 15 | 16 | *** ARM Compiler *** 17 | -------------------- 18 | [..] RAM functions are defined using the toolchain options. 19 | Functions that are executed in RAM should reside in a separate 20 | source module. Using the 'Options for File' dialog you can simply change 21 | the 'Code / Const' area of a module to a memory space in physical RAM. 22 | Available memory areas are declared in the 'Target' tab of the 23 | Options for Target' dialog. 24 | 25 | *** ICCARM Compiler *** 26 | ----------------------- 27 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc". 28 | 29 | *** GNU Compiler *** 30 | -------------------- 31 | [..] RAM functions are defined using a specific toolchain attribute 32 | "__attribute__((section(".RamFunc")))". 33 | 34 | @endverbatim 35 | ****************************************************************************** 36 | * @attention 37 | * 38 | *

© COPYRIGHT(c) 2017 STMicroelectronics

39 | * 40 | * Redistribution and use in source and binary forms, with or without modification, 41 | * are permitted provided that the following conditions are met: 42 | * 1. Redistributions of source code must retain the above copyright notice, 43 | * this list of conditions and the following disclaimer. 44 | * 2. Redistributions in binary form must reproduce the above copyright notice, 45 | * this list of conditions and the following disclaimer in the documentation 46 | * and/or other materials provided with the distribution. 47 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 48 | * may be used to endorse or promote products derived from this software 49 | * without specific prior written permission. 50 | * 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 52 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 54 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 57 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 58 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 59 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 61 | * 62 | ****************************************************************************** 63 | */ 64 | 65 | /* Includes ------------------------------------------------------------------*/ 66 | #include "stm32l4xx_hal.h" 67 | 68 | /** @addtogroup STM32L4xx_HAL_Driver 69 | * @{ 70 | */ 71 | 72 | /** @defgroup FLASH_RAMFUNC FLASH_RAMFUNC 73 | * @brief FLASH functions executed from RAM 74 | * @{ 75 | */ 76 | 77 | #ifdef HAL_FLASH_MODULE_ENABLED 78 | 79 | /* Private typedef -----------------------------------------------------------*/ 80 | /* Private define ------------------------------------------------------------*/ 81 | /* Private macro -------------------------------------------------------------*/ 82 | /* Private variables ---------------------------------------------------------*/ 83 | extern FLASH_ProcessTypeDef pFlash; 84 | 85 | /* Private function prototypes -----------------------------------------------*/ 86 | /* Exported functions -------------------------------------------------------*/ 87 | 88 | /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH in RAM function Exported Functions 89 | * @{ 90 | */ 91 | 92 | /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions 93 | * @brief Data transfers functions 94 | * 95 | @verbatim 96 | =============================================================================== 97 | ##### ramfunc functions ##### 98 | =============================================================================== 99 | [..] 100 | This subsection provides a set of functions that should be executed from RAM. 101 | 102 | @endverbatim 103 | * @{ 104 | */ 105 | 106 | /** 107 | * @brief Enable the Power down in Run Mode 108 | * @note This function should be called and executed from SRAM memory 109 | * @retval None 110 | */ 111 | __RAM_FUNC HAL_FLASHEx_EnableRunPowerDown(void) 112 | { 113 | /* Enable the Power Down in Run mode*/ 114 | __HAL_FLASH_POWER_DOWN_ENABLE(); 115 | 116 | return HAL_OK; 117 | 118 | } 119 | 120 | /** 121 | * @brief Disable the Power down in Run Mode 122 | * @note This function should be called and executed from SRAM memory 123 | * @retval None 124 | */ 125 | __RAM_FUNC HAL_FLASHEx_DisableRunPowerDown(void) 126 | { 127 | /* Disable the Power Down in Run mode*/ 128 | __HAL_FLASH_POWER_DOWN_DISABLE(); 129 | 130 | return HAL_OK; 131 | } 132 | 133 | #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) 134 | /** 135 | * @brief Program the FLASH DBANK User Option Byte. 136 | * 137 | * @note To configure the user option bytes, the option lock bit OPTLOCK must 138 | * be cleared with the call of the HAL_FLASH_OB_Unlock() function. 139 | * @note To modify the DBANK option byte, no PCROP region should be defined. 140 | * To deactivate PCROP, user should perform RDP changing 141 | * 142 | * @param DBankConfig: The FLASH DBANK User Option Byte value. 143 | * This parameter can be one of the following values: 144 | * @arg OB_DBANK_128_BITS: Single-bank with 128-bits data 145 | * @arg OB_DBANK_64_BITS: Dual-bank with 64-bits data 146 | * 147 | * @retval HAL status 148 | */ 149 | __RAM_FUNC HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig) 150 | { 151 | register uint32_t count, reg; 152 | HAL_StatusTypeDef status = HAL_ERROR; 153 | 154 | /* Process Locked */ 155 | __HAL_LOCK(&pFlash); 156 | 157 | /* Check if the PCROP is disabled */ 158 | reg = FLASH->PCROP1SR; 159 | if (reg > FLASH->PCROP1ER) 160 | { 161 | reg = FLASH->PCROP2SR; 162 | if (reg > FLASH->PCROP2ER) 163 | { 164 | /* Disable Flash prefetch */ 165 | __HAL_FLASH_PREFETCH_BUFFER_DISABLE(); 166 | 167 | if (READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != RESET) 168 | { 169 | /* Disable Flash instruction cache */ 170 | __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); 171 | 172 | /* Flush Flash instruction cache */ 173 | __HAL_FLASH_INSTRUCTION_CACHE_RESET(); 174 | } 175 | 176 | if (READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != RESET) 177 | { 178 | /* Disable Flash data cache */ 179 | __HAL_FLASH_DATA_CACHE_DISABLE(); 180 | 181 | /* Flush Flash data cache */ 182 | __HAL_FLASH_DATA_CACHE_RESET(); 183 | } 184 | 185 | /* Disable WRP zone 1 of 1st bank if needed */ 186 | reg = FLASH->WRP1AR; 187 | if (((reg & FLASH_WRP1AR_WRP1A_STRT) >> POSITION_VAL(FLASH_WRP1AR_WRP1A_STRT)) <= 188 | ((reg & FLASH_WRP1AR_WRP1A_END) >> POSITION_VAL(FLASH_WRP1AR_WRP1A_END))) 189 | { 190 | MODIFY_REG(FLASH->WRP1AR, (FLASH_WRP1AR_WRP1A_STRT | FLASH_WRP1AR_WRP1A_END), FLASH_WRP1AR_WRP1A_STRT); 191 | } 192 | 193 | /* Disable WRP zone 2 of 1st bank if needed */ 194 | reg = FLASH->WRP1BR; 195 | if (((reg & FLASH_WRP1BR_WRP1B_STRT) >> POSITION_VAL(FLASH_WRP1BR_WRP1B_STRT)) <= 196 | ((reg & FLASH_WRP1BR_WRP1B_END) >> POSITION_VAL(FLASH_WRP1BR_WRP1B_END))) 197 | { 198 | MODIFY_REG(FLASH->WRP1BR, (FLASH_WRP1BR_WRP1B_STRT | FLASH_WRP1BR_WRP1B_END), FLASH_WRP1BR_WRP1B_STRT); 199 | } 200 | 201 | /* Disable WRP zone 1 of 2nd bank if needed */ 202 | reg = FLASH->WRP2AR; 203 | if (((reg & FLASH_WRP2AR_WRP2A_STRT) >> POSITION_VAL(FLASH_WRP2AR_WRP2A_STRT)) <= 204 | ((reg & FLASH_WRP2AR_WRP2A_END) >> POSITION_VAL(FLASH_WRP2AR_WRP2A_END))) 205 | { 206 | MODIFY_REG(FLASH->WRP2AR, (FLASH_WRP2AR_WRP2A_STRT | FLASH_WRP2AR_WRP2A_END), FLASH_WRP2AR_WRP2A_STRT); 207 | } 208 | 209 | /* Disable WRP zone 2 of 2nd bank if needed */ 210 | reg = FLASH->WRP2BR; 211 | if (((reg & FLASH_WRP2BR_WRP2B_STRT) >> POSITION_VAL(FLASH_WRP2BR_WRP2B_STRT)) <= 212 | ((reg & FLASH_WRP2BR_WRP2B_END) >> POSITION_VAL(FLASH_WRP2BR_WRP2B_END))) 213 | { 214 | MODIFY_REG(FLASH->WRP2BR, (FLASH_WRP2BR_WRP2B_STRT | FLASH_WRP2BR_WRP2B_END), FLASH_WRP2BR_WRP2B_STRT); 215 | } 216 | 217 | /* Modify the DBANK user option byte */ 218 | MODIFY_REG(FLASH->OPTR, FLASH_OPTR_DBANK, DBankConfig); 219 | 220 | /* Set OPTSTRT Bit */ 221 | SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT); 222 | 223 | /* Wait for last operation to be completed */ 224 | /* 8 is the number of required instruction cycles for the below loop statement (timeout expressed in ms) */ 225 | count = FLASH_TIMEOUT_VALUE * (SystemCoreClock / 8 / 1000); 226 | do 227 | { 228 | if (count-- == 0) 229 | { 230 | break; 231 | } 232 | } while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET); 233 | 234 | /* If the option byte program operation is completed, disable the OPTSTRT Bit */ 235 | CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT); 236 | 237 | /* Set the bit to force the option byte reloading */ 238 | SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH); 239 | } 240 | } 241 | 242 | /* Process Unlocked */ 243 | __HAL_UNLOCK(&pFlash); 244 | 245 | return status; 246 | } 247 | #endif 248 | 249 | /** 250 | * @} 251 | */ 252 | 253 | /** 254 | * @} 255 | */ 256 | #endif /* HAL_FLASH_MODULE_ENABLED */ 257 | 258 | 259 | 260 | /** 261 | * @} 262 | */ 263 | 264 | /** 265 | * @} 266 | */ 267 | 268 | 269 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 270 | 271 | 272 | -------------------------------------------------------------------------------- /EWARM/Project.eww: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $WS_DIR$\stm32-bootloader.ewp 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /EWARM/stm32l476xx_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__ = 0x08007FFF; 9 | define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; 10 | define symbol __ICFEDIT_region_RAM_end__ = 0x20017FFF; 11 | define symbol __ICFEDIT_region_SRAM2_start__ = 0x10000000; 12 | define symbol __ICFEDIT_region_SRAM2_end__ = 0x10007FFF; 13 | 14 | /*-Sizes-*/ 15 | define symbol __ICFEDIT_size_cstack__ = 0x1000; 16 | define symbol __ICFEDIT_size_heap__ = 0x100; 17 | /**** End of ICF editor section. ###ICF###*/ 18 | 19 | 20 | define memory mem with size = 4G; 21 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; 22 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; 23 | define region SRAM2_region = mem:[from __ICFEDIT_region_SRAM2_start__ to __ICFEDIT_region_SRAM2_end__]; 24 | 25 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; 26 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; 27 | 28 | initialize by copy { readwrite }; 29 | do not initialize { section .noinit }; 30 | 31 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; 32 | 33 | place in ROM_region { readonly }; 34 | place in RAM_region { readwrite, 35 | block CSTACK, block HEAP }; 36 | place in SRAM2_region { }; 37 | -------------------------------------------------------------------------------- /EWARM/stm32l476xx_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__ = 0x20017FFF; 11 | define symbol __ICFEDIT_region_SRAM2_start__ = 0x10000000; 12 | define symbol __ICFEDIT_region_SRAM2_end__ = 0x10007FFF; 13 | 14 | /*-Sizes-*/ 15 | define symbol __ICFEDIT_size_cstack__ = 0x1000; 16 | define symbol __ICFEDIT_size_heap__ = 0x200; 17 | /**** End of ICF editor section. ###ICF###*/ 18 | 19 | 20 | define memory mem with size = 4G; 21 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; 22 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; 23 | define region SRAM2_region = mem:[from __ICFEDIT_region_SRAM2_start__ to __ICFEDIT_region_SRAM2_end__]; 24 | 25 | 26 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; 27 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; 28 | 29 | initialize by copy { readwrite }; 30 | do not initialize { section .noinit }; 31 | 32 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; 33 | 34 | place in ROM_region { readonly }; 35 | place in RAM_region { readwrite, 36 | block CSTACK, block HEAP }; 37 | place in SRAM2_region { }; 38 | -------------------------------------------------------------------------------- /EWARM/stm32l496xx_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__ = 0x08007FFF; 9 | define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; 10 | define symbol __ICFEDIT_region_RAM_end__ = 0x2003FFFF; 11 | define symbol __ICFEDIT_region_SRAM2_start__ = 0x10000000; 12 | define symbol __ICFEDIT_region_SRAM2_end__ = 0x1000FFFF; 13 | 14 | /*-Sizes-*/ 15 | define symbol __ICFEDIT_size_cstack__ = 0x1000; 16 | define symbol __ICFEDIT_size_heap__ = 0x100; 17 | /**** End of ICF editor section. ###ICF###*/ 18 | 19 | 20 | define memory mem with size = 4G; 21 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; 22 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; 23 | define region SRAM2_region = mem:[from __ICFEDIT_region_SRAM2_start__ to __ICFEDIT_region_SRAM2_end__]; 24 | 25 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; 26 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; 27 | 28 | initialize by copy { readwrite }; 29 | do not initialize { section .noinit }; 30 | 31 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; 32 | 33 | place in ROM_region { readonly }; 34 | place in RAM_region { readwrite, 35 | block CSTACK, block HEAP }; 36 | place in SRAM2_region { }; 37 | -------------------------------------------------------------------------------- /EWARM/stm32l496xx_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__ = 0x2002ABFF; 9 | define symbol __ICFEDIT_region_RAM_start__ = 0x2002AC00; 10 | define symbol __ICFEDIT_region_RAM_end__ = 0x2003FFFF; 11 | define symbol __ICFEDIT_region_SRAM2_start__ = 0x10000000; 12 | define symbol __ICFEDIT_region_SRAM2_end__ = 0x1000FFFF; 13 | 14 | /*-Sizes-*/ 15 | define symbol __ICFEDIT_size_cstack__ = 0x400; 16 | define symbol __ICFEDIT_size_heap__ = 0x200; 17 | /**** End of ICF editor section. ###ICF###*/ 18 | 19 | 20 | define memory mem with size = 4G; 21 | define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; 22 | define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; 23 | define region SRAM2_region = mem:[from __ICFEDIT_region_SRAM2_start__ to __ICFEDIT_region_SRAM2_end__]; 24 | 25 | define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; 26 | define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; 27 | 28 | initialize by copy { readwrite }; 29 | do not initialize { section .noinit }; 30 | 31 | place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; 32 | 33 | place in ROM_region { readonly }; 34 | place in RAM_region { readwrite, 35 | block CSTACK, block HEAP }; 36 | place in SRAM2_region { }; 37 | 38 | -------------------------------------------------------------------------------- /Inc/bootloader.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * STM32L4 Bootloader 4 | ****************************************************************************** 5 | * @author Akos Pasztor 6 | * @file bootloader.h 7 | * @brief Bootloader header 8 | * This file contains the bootloader configuration parameters, 9 | * function prototypes and other required macros and definitions. 10 | * @see Please refer to README for detailed information. 11 | ****************************************************************************** 12 | * Copyright (c) 2018 Akos Pasztor. https://akospasztor.com 13 | ****************************************************************************** 14 | **/ 15 | 16 | #ifndef __BOOTLOADER_H 17 | #define __BOOTLOADER_H 18 | 19 | /*** Bootloader Configuration *************************************************/ 20 | #define USE_CHECKSUM 0 /* Check application checksum on startup */ 21 | #define USE_WRITE_PROTECTION 0 /* Enable write protection after performing in-app-programming */ 22 | #define SET_VECTOR_TABLE 1 /* Automatically set vector table location before launching application */ 23 | #define CLEAR_RESET_FLAGS 1 /* If enabled: bootloader clears reset flags. (This occurs only when OBL RST flag is active.) 24 | If disabled: bootloader does not clear reset flags, not even when OBL RST is active. */ 25 | 26 | #define APP_ADDRESS (uint32_t)0x08008000 /* Start address of application space in flash */ 27 | #define END_ADDRESS (uint32_t)0x080FFFFB /* End address of application space (addr. of last byte) */ 28 | #define CRC_ADDRESS (uint32_t)0x080FFFFC /* Start address of application checksum in flash */ 29 | #define SYSMEM_ADDRESS (uint32_t)0x1FFF0000 /* Address of System Memory (ST Bootloader) */ 30 | 31 | /* MCU RAM size, used for checking accurately whether flash contains valid application */ 32 | #if (STM32L496xx) 33 | #define RAM_SIZE (uint32_t)0x00040000 34 | #elif (STM32L476xx) 35 | #define RAM_SIZE (uint32_t)0x00018000 36 | #endif 37 | /******************************************************************************/ 38 | 39 | /* Defines -------------------------------------------------------------------*/ 40 | #define FLASH_PAGE_NBPERBANK 256 /* Number of pages per bank in flash */ 41 | #define APP_SIZE (uint32_t)(((END_ADDRESS - APP_ADDRESS) + 3) / 4) /* Size of application in DWORD (32bits or 4bytes) */ 42 | 43 | /* Bootloader Error Codes */ 44 | enum 45 | { 46 | BL_OK = 0, 47 | BL_NO_APP, 48 | BL_SIZE_ERROR, 49 | BL_CHKS_ERROR, 50 | BL_ERASE_ERROR, 51 | BL_WRITE_ERROR, 52 | BL_OBP_ERROR 53 | }; 54 | 55 | /* Flash Protection Types */ 56 | enum 57 | { 58 | BL_PROTECTION_NONE = 0, 59 | BL_PROTECTION_WRP = 0x1, 60 | BL_PROTECTION_RDP = 0x2, 61 | BL_PROTECTION_PCROP = 0x4, 62 | }; 63 | 64 | /* Functions -----------------------------------------------------------------*/ 65 | void Bootloader_Init(void); 66 | uint8_t Bootloader_Erase(void); 67 | 68 | void Bootloader_FlashBegin(void); 69 | uint8_t Bootloader_FlashNext(uint64_t data); 70 | void Bootloader_FlashEnd(void); 71 | 72 | uint8_t Bootloader_GetProtectionStatus(void); 73 | uint8_t Bootloader_ConfigProtection(uint32_t protection); 74 | 75 | uint8_t Bootloader_CheckSize(uint32_t appsize); 76 | uint8_t Bootloader_VerifyChecksum(void); 77 | uint8_t Bootloader_CheckForApplication(void); 78 | void Bootloader_JumpToApplication(void); 79 | void Bootloader_JumpToSysMem(void); 80 | 81 | #endif /* __BOOTLOADER_H */ -------------------------------------------------------------------------------- /Inc/bsp_driver_sd.h: -------------------------------------------------------------------------------- 1 | #ifndef __BSP_DRIVER_SD_H 2 | #define __BSP_DRIVER_SD_H 3 | 4 | /* Includes ------------------------------------------------------------------*/ 5 | #include "stm32l4xx_hal.h" 6 | 7 | /* Exported types ------------------------------------------------------------*/ 8 | #define BSP_SD_CardInfo HAL_SD_CardInfoTypeDef 9 | 10 | /* Exported constants --------------------------------------------------------*/ 11 | #define MSD_OK ((uint8_t)0x00) 12 | #define MSD_ERROR ((uint8_t)0x01) 13 | #define MSD_ERROR_SD_NOT_PRESENT ((uint8_t)0x02) 14 | 15 | #define SD_TRANSFER_OK ((uint8_t)0x00) 16 | #define SD_TRANSFER_BUSY ((uint8_t)0x01) 17 | #define SD_TRANSFER_ERROR ((uint8_t)0x02) 18 | 19 | #define SD_PRESENT ((uint8_t)0x01) 20 | #define SD_NOT_PRESENT ((uint8_t)0x00) 21 | 22 | #define SD_DATATIMEOUT (150U) /* ms */ 23 | 24 | #define SDMMC_IRQ_PRIO 1 25 | #define SD_DMA_IRQ_PRIO 2 26 | 27 | /* Exported functions --------------------------------------------------------*/ 28 | uint8_t BSP_SD_Init(void); 29 | uint8_t BSP_SD_DeInit(void); 30 | uint8_t BSP_SD_ReadBlocks(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint32_t Timeout); 31 | uint8_t BSP_SD_WriteBlocks(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks, uint32_t Timeout); 32 | uint8_t BSP_SD_ReadBlocks_DMA(uint32_t *pData, uint32_t ReadAddr, uint32_t NumOfBlocks); 33 | uint8_t BSP_SD_WriteBlocks_DMA(uint32_t *pData, uint32_t WriteAddr, uint32_t NumOfBlocks); 34 | uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr); 35 | uint8_t BSP_SD_GetCardState(void); 36 | void BSP_SD_GetCardInfo(BSP_SD_CardInfo *CardInfo); 37 | uint8_t BSP_SD_IsDetected(void); 38 | 39 | __weak void BSP_SD_AbortCallback(void); 40 | __weak void BSP_SD_ErrorCallback(void); 41 | __weak void BSP_SD_WriteCpltCallback(void); 42 | __weak void BSP_SD_ReadCpltCallback(void); 43 | 44 | #endif /* __BSP_DRIVER_SD_H */ 45 | -------------------------------------------------------------------------------- /Inc/fatfs.h: -------------------------------------------------------------------------------- 1 | #ifndef __fatfs_H 2 | #define __fatfs_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* Includes ------------------------------------------------------------------*/ 9 | #include "ff.h" 10 | #include "ff_gen_drv.h" 11 | #include "sd_diskio.h" 12 | 13 | /* Exported functions --------------------------------------------------------*/ 14 | uint8_t FATFS_Init(void); 15 | uint8_t FATFS_DeInit(void); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif /* __fatfs_H */ 22 | 23 | -------------------------------------------------------------------------------- /Inc/ffconf.h: -------------------------------------------------------------------------------- 1 | #ifndef _FFCONF 2 | #define _FFCONF 68300 /* Revision ID */ 3 | 4 | /*-----------------------------------------------------------------------------/ 5 | / Additional user header to be used 6 | /-----------------------------------------------------------------------------*/ 7 | #include "stm32l4xx_hal.h" 8 | #include "bsp_driver_sd.h" 9 | 10 | /*-----------------------------------------------------------------------------/ 11 | / Function Configurations 12 | /-----------------------------------------------------------------------------*/ 13 | 14 | #define _FS_READONLY 1 /* 0:Read/Write or 1:Read only */ 15 | /* This option switches read-only configuration. (0:Read/Write or 1:Read-only) 16 | / Read-only configuration removes writing API functions, f_write(), f_sync(), 17 | / f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() 18 | / and optional writing functions as well. */ 19 | 20 | #define _FS_MINIMIZE 0 /* 0 to 3 */ 21 | /* This option defines minimization level to remove some basic API functions. 22 | / 23 | / 0: All basic functions are enabled. 24 | / 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() 25 | / are removed. 26 | / 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. 27 | / 3: f_lseek() function is removed in addition to 2. */ 28 | 29 | #define _USE_STRFUNC 2 /* 0:Disable or 1-2:Enable */ 30 | /* This option switches string functions, f_gets(), f_putc(), f_puts() and 31 | / f_printf(). 32 | / 33 | / 0: Disable string functions. 34 | / 1: Enable without LF-CRLF conversion. 35 | / 2: Enable with LF-CRLF conversion. */ 36 | 37 | #define _USE_FIND 0 38 | /* This option switches filtered directory read functions, f_findfirst() and 39 | / f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ 40 | 41 | #define _USE_MKFS 1 42 | /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ 43 | 44 | #define _USE_FASTSEEK 1 45 | /* This option switches fast seek feature. (0:Disable or 1:Enable) */ 46 | 47 | #define _USE_EXPAND 0 48 | /* This option switches f_expand function. (0:Disable or 1:Enable) */ 49 | 50 | #define _USE_CHMOD 0 51 | /* This option switches attribute manipulation functions, f_chmod() and f_utime(). 52 | / (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */ 53 | 54 | #define _USE_LABEL 0 55 | /* This option switches volume label functions, f_getlabel() and f_setlabel(). 56 | / (0:Disable or 1:Enable) */ 57 | 58 | #define _USE_FORWARD 0 59 | /* This option switches f_forward() function. (0:Disable or 1:Enable) */ 60 | 61 | /*-----------------------------------------------------------------------------/ 62 | / Locale and Namespace Configurations 63 | /-----------------------------------------------------------------------------*/ 64 | 65 | #define _CODE_PAGE 850 66 | /* This option specifies the OEM code page to be used on the target system. 67 | / Incorrect setting of the code page can cause a file open failure. 68 | / 69 | / 1 - ASCII (No extended character. Non-LFN cfg. only) 70 | / 437 - U.S. 71 | / 720 - Arabic 72 | / 737 - Greek 73 | / 771 - KBL 74 | / 775 - Baltic 75 | / 850 - Latin 1 76 | / 852 - Latin 2 77 | / 855 - Cyrillic 78 | / 857 - Turkish 79 | / 860 - Portuguese 80 | / 861 - Icelandic 81 | / 862 - Hebrew 82 | / 863 - Canadian French 83 | / 864 - Arabic 84 | / 865 - Nordic 85 | / 866 - Russian 86 | / 869 - Greek 2 87 | / 932 - Japanese (DBCS) 88 | / 936 - Simplified Chinese (DBCS) 89 | / 949 - Korean (DBCS) 90 | / 950 - Traditional Chinese (DBCS) 91 | */ 92 | 93 | #define _USE_LFN 1 /* 0 to 3 */ 94 | #define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ 95 | /* The _USE_LFN switches the support of long file name (LFN). 96 | / 97 | / 0: Disable support of LFN. _MAX_LFN has no effect. 98 | / 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. 99 | / 2: Enable LFN with dynamic working buffer on the STACK. 100 | / 3: Enable LFN with dynamic working buffer on the HEAP. 101 | / 102 | / To enable the LFN, Unicode handling functions (option/unicode.c) must be added 103 | / to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and 104 | / additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255. 105 | / It should be set 255 to support full featured LFN operations. 106 | / When use stack for the working buffer, take care on stack overflow. When use heap 107 | / memory for the working buffer, memory management functions, ff_memalloc() and 108 | / ff_memfree(), must be added to the project. */ 109 | 110 | #define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */ 111 | /* This option switches character encoding on the API. (0:ANSI/OEM or 1:UTF-16) 112 | / To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1. 113 | / This option also affects behavior of string I/O functions. */ 114 | 115 | #define _STRF_ENCODE 3 116 | /* When _LFN_UNICODE == 1, this option selects the character encoding ON THE FILE to 117 | / be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf(). 118 | / 119 | / 0: ANSI/OEM 120 | / 1: UTF-16LE 121 | / 2: UTF-16BE 122 | / 3: UTF-8 123 | / 124 | / This option has no effect when _LFN_UNICODE == 0. */ 125 | 126 | #define _FS_RPATH 0 /* 0 to 2 */ 127 | /* This option configures support of relative path. 128 | / 129 | / 0: Disable relative path and remove related functions. 130 | / 1: Enable relative path. f_chdir() and f_chdrive() are available. 131 | / 2: f_getcwd() function is available in addition to 1. 132 | */ 133 | 134 | /*---------------------------------------------------------------------------/ 135 | / Drive/Volume Configurations 136 | /----------------------------------------------------------------------------*/ 137 | 138 | #define _VOLUMES 1 139 | /* Number of volumes (logical drives) to be used. */ 140 | 141 | /* USER CODE BEGIN Volumes */ 142 | #define _STR_VOLUME_ID 0 /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */ 143 | #define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3" 144 | /* _STR_VOLUME_ID switches string support of volume ID. 145 | / When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive 146 | / number in the path name. _VOLUME_STRS defines the drive ID strings for each 147 | / logical drives. Number of items must be equal to _VOLUMES. Valid characters for 148 | / the drive ID strings are: A-Z and 0-9. */ 149 | /* USER CODE END Volumes */ 150 | 151 | #define _MULTI_PARTITION 0 /* 0:Single partition, 1:Multiple partition */ 152 | /* This option switches support of multi-partition on a physical drive. 153 | / By default (0), each logical drive number is bound to the same physical drive 154 | / number and only an FAT volume found on the physical drive will be mounted. 155 | / When multi-partition is enabled (1), each logical drive number can be bound to 156 | / arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() 157 | / funciton will be available. */ 158 | #define _MIN_SS 512 /* 512, 1024, 2048 or 4096 */ 159 | #define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */ 160 | /* These options configure the range of sector size to be supported. (512, 1024, 161 | / 2048 or 4096) Always set both 512 for most systems, all type of memory cards and 162 | / harddisk. But a larger value may be required for on-board flash memory and some 163 | / type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured 164 | / to variable sector size and GET_SECTOR_SIZE command must be implemented to the 165 | / disk_ioctl() function. */ 166 | 167 | #define _USE_TRIM 0 168 | /* This option switches support of ATA-TRIM. (0:Disable or 1:Enable) 169 | / To enable Trim function, also CTRL_TRIM command should be implemented to the 170 | / disk_ioctl() function. */ 171 | 172 | #define _FS_NOFSINFO 0 /* 0,1,2 or 3 */ 173 | /* If you need to know correct free space on the FAT32 volume, set bit 0 of this 174 | / option, and f_getfree() function at first time after volume mount will force 175 | / a full FAT scan. Bit 1 controls the use of last allocated cluster number. 176 | / 177 | / bit0=0: Use free cluster count in the FSINFO if available. 178 | / bit0=1: Do not trust free cluster count in the FSINFO. 179 | / bit1=0: Use last allocated cluster number in the FSINFO if available. 180 | / bit1=1: Do not trust last allocated cluster number in the FSINFO. 181 | */ 182 | 183 | /*---------------------------------------------------------------------------/ 184 | / System Configurations 185 | /----------------------------------------------------------------------------*/ 186 | 187 | #define _FS_TINY 0 /* 0:Normal or 1:Tiny */ 188 | /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) 189 | / At the tiny configuration, size of file object (FIL) is reduced _MAX_SS bytes. 190 | / Instead of private sector buffer eliminated from the file object, common sector 191 | / buffer in the file system object (FATFS) is used for the file data transfer. */ 192 | 193 | #define _FS_EXFAT 0 194 | /* This option switches support of exFAT file system. (0:Disable or 1:Enable) 195 | / When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1) 196 | / Note that enabling exFAT discards C89 compatibility. */ 197 | 198 | #define _FS_NORTC 0 199 | #define _NORTC_MON 6 200 | #define _NORTC_MDAY 4 201 | #define _NORTC_YEAR 2018 202 | /* The option _FS_NORTC switches timestamp functiton. If the system does not have 203 | / any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable 204 | / the timestamp function. All objects modified by FatFs will have a fixed timestamp 205 | / defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time. 206 | / To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be 207 | / added to the project to get current time form real-time clock. _NORTC_MON, 208 | / _NORTC_MDAY and _NORTC_YEAR have no effect. 209 | / These options have no effect at read-only configuration (_FS_READONLY = 1). */ 210 | 211 | #define _FS_LOCK 0 /* 0:Disable or >=1:Enable */ 212 | /* The option _FS_LOCK switches file lock function to control duplicated file open 213 | / and illegal operation to open objects. This option must be 0 when _FS_READONLY 214 | / is 1. 215 | / 216 | / 0: Disable file lock function. To avoid volume corruption, application program 217 | / should avoid illegal open, remove and rename to the open objects. 218 | / >0: Enable file lock function. The value defines how many files/sub-directories 219 | / can be opened simultaneously under file lock control. Note that the file 220 | / lock control is independent of re-entrancy. */ 221 | 222 | #define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */ 223 | #define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */ 224 | #define _SYNC_t osSemaphoreId 225 | /* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs 226 | / module itself. Note that regardless of this option, file access to different 227 | / volume is always re-entrant and volume control functions, f_mount(), f_mkfs() 228 | / and f_fdisk() function, are always not re-entrant. Only file/directory access 229 | / to the same volume is under control of this function. 230 | / 231 | / 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect. 232 | / 1: Enable re-entrancy. Also user provided synchronization handlers, 233 | / ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj() 234 | / function, must be added to the project. Samples are available in 235 | / option/syscall.c. 236 | / 237 | / The _FS_TIMEOUT defines timeout period in unit of time tick. 238 | / The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*, 239 | / SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be 240 | / included somewhere in the scope of ff.h. */ 241 | 242 | /* define the ff_malloc ff_free macros as standard malloc free */ 243 | #if !defined(ff_malloc) && !defined(ff_free) 244 | #include 245 | #define ff_malloc malloc 246 | #define ff_free free 247 | #endif 248 | 249 | #endif /* _FFCONF */ 250 | -------------------------------------------------------------------------------- /Inc/main.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAIN_H 2 | #define __MAIN_H 3 | 4 | /*** Application-Specific Configuration ***************************************/ 5 | #define CONF_BUILD "2018-04-18" /* Bootloader build date [YYYY-MM-DD] */ 6 | #define CONF_FILENAME "GPP.bin" /* File name of application located on SD card */ 7 | 8 | #define USE_SWO_TRACE 1 /* For development/debugging: stdout/stderr via SWO trace */ 9 | /******************************************************************************/ 10 | 11 | /* Hardware Defines ----------------------------------------------------------*/ 12 | #define BTN_Port GPIOB 13 | #define BTN_Pin GPIO_PIN_8 14 | 15 | #define LED_R_Port GPIOB 16 | #define LED_R_Pin GPIO_PIN_4 17 | #define LED_Y_Port GPIOB 18 | #define LED_Y_Pin GPIO_PIN_5 19 | #define LED_G_Port GPIOB 20 | #define LED_G_Pin GPIO_PIN_6 21 | 22 | #define SD_PWR_Port GPIOC 23 | #define SD_PWR_Pin GPIO_PIN_7 24 | 25 | /* Hardware Macros -----------------------------------------------------------*/ 26 | #define SDCARD_ON() HAL_GPIO_WritePin(SD_PWR_Port, SD_PWR_Pin, GPIO_PIN_RESET) 27 | #define SDCARD_OFF() HAL_GPIO_WritePin(SD_PWR_Port, SD_PWR_Pin, GPIO_PIN_SET) 28 | 29 | #define LED_G_ON() HAL_GPIO_WritePin(LED_G_Port, LED_G_Pin, GPIO_PIN_SET) 30 | #define LED_G_OFF() HAL_GPIO_WritePin(LED_G_Port, LED_G_Pin, GPIO_PIN_RESET) 31 | #define LED_G_TG() HAL_GPIO_TogglePin(LED_G_Port, LED_G_Pin) 32 | #define LED_Y_ON() HAL_GPIO_WritePin(LED_Y_Port, LED_Y_Pin, GPIO_PIN_SET) 33 | #define LED_Y_OFF() HAL_GPIO_WritePin(LED_Y_Port, LED_Y_Pin, GPIO_PIN_RESET) 34 | #define LED_Y_TG() HAL_GPIO_TogglePin(LED_Y_Port, LED_Y_Pin) 35 | #define LED_R_ON() HAL_GPIO_WritePin(LED_R_Port, LED_R_Pin, GPIO_PIN_SET) 36 | #define LED_R_OFF() HAL_GPIO_WritePin(LED_R_Port, LED_R_Pin, GPIO_PIN_RESET) 37 | #define LED_R_TG() HAL_GPIO_TogglePin(LED_R_Port, LED_R_Pin) 38 | 39 | #define LED_ALL_ON() do { LED_G_ON(); LED_Y_ON(); LED_R_ON(); } while(0) 40 | #define LED_ALL_OFF() do { LED_G_OFF(); LED_Y_OFF(); LED_R_OFF(); } while(0) 41 | 42 | #define IS_BTN_PRESSED() ((HAL_GPIO_ReadPin(BTN_Port, BTN_Pin) == GPIO_PIN_RESET) ? 1 : 0) 43 | 44 | 45 | #endif /* __MAIN_H */ 46 | -------------------------------------------------------------------------------- /Inc/stm32l4xx_hal_conf.h: -------------------------------------------------------------------------------- 1 | #ifndef __STM32L4xx_HAL_CONF_H 2 | #define __STM32L4xx_HAL_CONF_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "main.h" 9 | /* Exported types ------------------------------------------------------------*/ 10 | /* Exported constants --------------------------------------------------------*/ 11 | 12 | /* ######################### Custom Definitions ############################# */ 13 | #define SDMMC_HAL_TIMEOUT 500 /* [ms] */ 14 | 15 | /* ########################## Module Selection ############################## */ 16 | #define HAL_MODULE_ENABLED 17 | //#define HAL_ADC_MODULE_ENABLED 18 | //#define HAL_CAN_MODULE_ENABLED 19 | //#define HAL_COMP_MODULE_ENABLED 20 | #define HAL_CORTEX_MODULE_ENABLED 21 | #define HAL_CRC_MODULE_ENABLED 22 | //#define HAL_CRYP_MODULE_ENABLED 23 | //#define HAL_DAC_MODULE_ENABLED 24 | //#define HAL_DCMI_MODULE_ENABLED 25 | //#define HAL_DFSDM_MODULE_ENABLED 26 | #define HAL_DMA_MODULE_ENABLED 27 | //#define HAL_DMA2D_MODULE_ENABLED 28 | //#define HAL_DSI_MODULE_ENABLED 29 | //#define HAL_FIREWALL_MODULE_ENABLED 30 | #define HAL_FLASH_MODULE_ENABLED 31 | //#define HAL_GFXMMU_MODULE_ENABLED 32 | #define HAL_GPIO_MODULE_ENABLED 33 | //#define HAL_HASH_MODULE_ENABLED 34 | //#define HAL_HCD_MODULE_ENABLED 35 | //#define HAL_I2C_MODULE_ENABLED 36 | //#define HAL_I2S_MODULE_ENABLED 37 | //#define HAL_IRDA_MODULE_ENABLED 38 | //#define HAL_IWDG_MODULE_ENABLED 39 | //#define HAL_LCD_MODULE_ENABLED 40 | //#define HAL_LPTIM_MODULE_ENABLED 41 | //#define HAL_LTDC_MODULE_ENABLED 42 | //#define HAL_NAND_MODULE_ENABLED 43 | //#define HAL_NOR_MODULE_ENABLED 44 | //#define HAL_OPAMP_MODULE_ENABLED 45 | //#define HAL_OSPI_MODULE_ENABLED 46 | //#define HAL_PCD_MODULE_ENABLED 47 | #define HAL_PWR_MODULE_ENABLED 48 | //#define HAL_QSPI_MODULE_ENABLED 49 | #define HAL_RCC_MODULE_ENABLED 50 | //#define HAL_RNG_MODULE_ENABLED 51 | //#define HAL_RTC_MODULE_ENABLED 52 | //#define HAL_SAI_MODULE_ENABLED 53 | #define HAL_SD_MODULE_ENABLED 54 | //#define HAL_SMARTCARD_MODULE_ENABLED 55 | //#define HAL_SMBUS_MODULE_ENABLED 56 | //#define HAL_SPI_MODULE_ENABLED 57 | //#define HAL_SRAM_MODULE_ENABLED 58 | //#define HAL_SWPMI_MODULE_ENABLED 59 | //#define HAL_TIM_MODULE_ENABLED 60 | //#define HAL_TSC_MODULE_ENABLED 61 | //#define HAL_UART_MODULE_ENABLED 62 | //#define HAL_USART_MODULE_ENABLED 63 | //#define HAL_WWDG_MODULE_ENABLED 64 | 65 | /* ########################## Oscillator Values adaptation ####################*/ 66 | /** 67 | * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. 68 | * This value is used by the RCC HAL module to compute the system frequency 69 | * (when HSE is used as system clock source, directly or through the PLL). 70 | */ 71 | #if !defined (HSE_VALUE) 72 | #define HSE_VALUE ((uint32_t)8000000U) /*!< Value of the External oscillator in Hz */ 73 | #endif /* HSE_VALUE */ 74 | 75 | #if !defined (HSE_STARTUP_TIMEOUT) 76 | #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */ 77 | #endif /* HSE_STARTUP_TIMEOUT */ 78 | 79 | /** 80 | * @brief Internal Multiple Speed oscillator (MSI) default value. 81 | * This value is the default MSI range value after Reset. 82 | */ 83 | #if !defined (MSI_VALUE) 84 | #define MSI_VALUE ((uint32_t)4000000U) /*!< Value of the Internal oscillator in Hz*/ 85 | #endif /* MSI_VALUE */ 86 | /** 87 | * @brief Internal High Speed oscillator (HSI) value. 88 | * This value is used by the RCC HAL module to compute the system frequency 89 | * (when HSI is used as system clock source, directly or through the PLL). 90 | */ 91 | #if !defined (HSI_VALUE) 92 | #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ 93 | #endif /* HSI_VALUE */ 94 | 95 | /** 96 | * @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC and RNG. 97 | * This internal oscillator is mainly dedicated to provide a high precision clock to 98 | * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. 99 | * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency 100 | * which is subject to manufacturing process variations. 101 | */ 102 | #if !defined (HSI48_VALUE) 103 | #define HSI48_VALUE ((uint32_t)48000000U) /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz. 104 | The real value my vary depending on manufacturing process variations.*/ 105 | #endif /* HSI48_VALUE */ 106 | 107 | /** 108 | * @brief Internal Low Speed oscillator (LSI) value. 109 | */ 110 | #if !defined (LSI_VALUE) 111 | #define LSI_VALUE ((uint32_t)32000U) /*!< LSI Typical Value in Hz*/ 112 | #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz 113 | The real value may vary depending on the variations 114 | in voltage and temperature.*/ 115 | 116 | /** 117 | * @brief External Low Speed oscillator (LSE) value. 118 | * This value is used by the UART, RTC HAL module to compute the system frequency 119 | */ 120 | #if !defined (LSE_VALUE) 121 | #define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External oscillator in Hz*/ 122 | #endif /* LSE_VALUE */ 123 | 124 | #if !defined (LSE_STARTUP_TIMEOUT) 125 | #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */ 126 | #endif /* HSE_STARTUP_TIMEOUT */ 127 | 128 | /** 129 | * @brief External clock source for SAI1 peripheral 130 | * This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source 131 | * frequency. 132 | */ 133 | #if !defined (EXTERNAL_SAI1_CLOCK_VALUE) 134 | #define EXTERNAL_SAI1_CLOCK_VALUE ((uint32_t)2097000U) /*!< Value of the SAI1 External clock source in Hz*/ 135 | #endif /* EXTERNAL_SAI1_CLOCK_VALUE */ 136 | 137 | /** 138 | * @brief External clock source for SAI2 peripheral 139 | * This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source 140 | * frequency. 141 | */ 142 | #if !defined (EXTERNAL_SAI2_CLOCK_VALUE) 143 | #define EXTERNAL_SAI2_CLOCK_VALUE ((uint32_t)2097000U) /*!< Value of the SAI2 External clock source in Hz*/ 144 | #endif /* EXTERNAL_SAI2_CLOCK_VALUE */ 145 | 146 | /* Tip: To avoid modifying this file each time you need to use different HSE, 147 | === you can define the HSE value in your toolchain compiler preprocessor. */ 148 | 149 | /* ########################### System Configuration ######################### */ 150 | /** 151 | * @brief This is the HAL system configuration section 152 | */ 153 | 154 | #define VDD_VALUE ((uint32_t)3000U) /*!< Value of VDD in mv */ 155 | #define TICK_INT_PRIORITY ((uint32_t)0U) /*!< tick interrupt priority */ 156 | #define USE_RTOS 0U 157 | #define PREFETCH_ENABLE 0U 158 | #define INSTRUCTION_CACHE_ENABLE 1U 159 | #define DATA_CACHE_ENABLE 1U 160 | 161 | /* ########################## Assert Selection ############################## */ 162 | /** 163 | * @brief Uncomment the line below to expanse the "assert_param" macro in the 164 | * HAL drivers code 165 | */ 166 | /* #define USE_FULL_ASSERT 1U */ 167 | 168 | /* ################## SPI peripheral configuration ########################## */ 169 | 170 | /* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver 171 | * Activated: CRC code is present inside driver 172 | * Deactivated: CRC code cleaned from driver 173 | */ 174 | 175 | #define USE_SPI_CRC 0U 176 | 177 | /* Includes ------------------------------------------------------------------*/ 178 | /** 179 | * @brief Include module's header file 180 | */ 181 | 182 | #ifdef HAL_RCC_MODULE_ENABLED 183 | #include "stm32l4xx_hal_rcc.h" 184 | #include "stm32l4xx_hal_rcc_ex.h" 185 | #endif /* HAL_RCC_MODULE_ENABLED */ 186 | 187 | #ifdef HAL_GPIO_MODULE_ENABLED 188 | #include "stm32l4xx_hal_gpio.h" 189 | #endif /* HAL_GPIO_MODULE_ENABLED */ 190 | 191 | #ifdef HAL_DMA_MODULE_ENABLED 192 | #include "stm32l4xx_hal_dma.h" 193 | #include "stm32l4xx_hal_dma_ex.h" 194 | #endif /* HAL_DMA_MODULE_ENABLED */ 195 | 196 | #ifdef HAL_DFSDM_MODULE_ENABLED 197 | #include "stm32l4xx_hal_dfsdm.h" 198 | #endif /* HAL_DFSDM_MODULE_ENABLED */ 199 | 200 | #ifdef HAL_CORTEX_MODULE_ENABLED 201 | #include "stm32l4xx_hal_cortex.h" 202 | #endif /* HAL_CORTEX_MODULE_ENABLED */ 203 | 204 | #ifdef HAL_ADC_MODULE_ENABLED 205 | #include "stm32l4xx_hal_adc.h" 206 | #endif /* HAL_ADC_MODULE_ENABLED */ 207 | 208 | #ifdef HAL_CAN_MODULE_ENABLED 209 | #include "stm32l4xx_hal_can.h" 210 | #endif /* HAL_CAN_MODULE_ENABLED */ 211 | 212 | #ifdef HAL_COMP_MODULE_ENABLED 213 | #include "stm32l4xx_hal_comp.h" 214 | #endif /* HAL_COMP_MODULE_ENABLED */ 215 | 216 | #ifdef HAL_CRC_MODULE_ENABLED 217 | #include "stm32l4xx_hal_crc.h" 218 | #endif /* HAL_CRC_MODULE_ENABLED */ 219 | 220 | #ifdef HAL_CRYP_MODULE_ENABLED 221 | #include "stm32l4xx_hal_cryp.h" 222 | #endif /* HAL_CRYP_MODULE_ENABLED */ 223 | 224 | #ifdef HAL_DAC_MODULE_ENABLED 225 | #include "stm32l4xx_hal_dac.h" 226 | #endif /* HAL_DAC_MODULE_ENABLED */ 227 | 228 | #ifdef HAL_DCMI_MODULE_ENABLED 229 | #include "stm32l4xx_hal_dcmi.h" 230 | #endif /* HAL_DCMI_MODULE_ENABLED */ 231 | 232 | #ifdef HAL_DMA2D_MODULE_ENABLED 233 | #include "stm32l4xx_hal_dma2d.h" 234 | #endif /* HAL_DMA2D_MODULE_ENABLED */ 235 | 236 | #ifdef HAL_DSI_MODULE_ENABLED 237 | #include "stm32l4xx_hal_dsi.h" 238 | #endif /* HAL_DSI_MODULE_ENABLED */ 239 | 240 | #ifdef HAL_FIREWALL_MODULE_ENABLED 241 | #include "stm32l4xx_hal_firewall.h" 242 | #endif /* HAL_FIREWALL_MODULE_ENABLED */ 243 | 244 | #ifdef HAL_FLASH_MODULE_ENABLED 245 | #include "stm32l4xx_hal_flash.h" 246 | #endif /* HAL_FLASH_MODULE_ENABLED */ 247 | 248 | #ifdef HAL_HASH_MODULE_ENABLED 249 | #include "stm32l4xx_hal_hash.h" 250 | #endif /* HAL_HASH_MODULE_ENABLED */ 251 | 252 | #ifdef HAL_SRAM_MODULE_ENABLED 253 | #include "stm32l4xx_hal_sram.h" 254 | #endif /* HAL_SRAM_MODULE_ENABLED */ 255 | 256 | #ifdef HAL_NOR_MODULE_ENABLED 257 | #include "stm32l4xx_hal_nor.h" 258 | #endif /* HAL_NOR_MODULE_ENABLED */ 259 | 260 | #ifdef HAL_NAND_MODULE_ENABLED 261 | #include "stm32l4xx_hal_nand.h" 262 | #endif /* HAL_NAND_MODULE_ENABLED */ 263 | 264 | #ifdef HAL_I2C_MODULE_ENABLED 265 | #include "stm32l4xx_hal_i2c.h" 266 | #endif /* HAL_I2C_MODULE_ENABLED */ 267 | 268 | #ifdef HAL_IWDG_MODULE_ENABLED 269 | #include "stm32l4xx_hal_iwdg.h" 270 | #endif /* HAL_IWDG_MODULE_ENABLED */ 271 | 272 | #ifdef HAL_LCD_MODULE_ENABLED 273 | #include "stm32l4xx_hal_lcd.h" 274 | #endif /* HAL_LCD_MODULE_ENABLED */ 275 | 276 | #ifdef HAL_LPTIM_MODULE_ENABLED 277 | #include "stm32l4xx_hal_lptim.h" 278 | #endif /* HAL_LPTIM_MODULE_ENABLED */ 279 | 280 | #ifdef HAL_LTDC_MODULE_ENABLED 281 | #include "stm32l4xx_hal_ltdc.h" 282 | #endif /* HAL_LTDC_MODULE_ENABLED */ 283 | 284 | #ifdef HAL_OPAMP_MODULE_ENABLED 285 | #include "stm32l4xx_hal_opamp.h" 286 | #endif /* HAL_OPAMP_MODULE_ENABLED */ 287 | 288 | #ifdef HAL_OSPI_MODULE_ENABLED 289 | #include "stm32l4xx_hal_ospi.h" 290 | #endif /* HAL_OSPI_MODULE_ENABLED */ 291 | 292 | #ifdef HAL_PWR_MODULE_ENABLED 293 | #include "stm32l4xx_hal_pwr.h" 294 | #endif /* HAL_PWR_MODULE_ENABLED */ 295 | 296 | #ifdef HAL_QSPI_MODULE_ENABLED 297 | #include "stm32l4xx_hal_qspi.h" 298 | #endif /* HAL_QSPI_MODULE_ENABLED */ 299 | 300 | #ifdef HAL_RNG_MODULE_ENABLED 301 | #include "stm32l4xx_hal_rng.h" 302 | #endif /* HAL_RNG_MODULE_ENABLED */ 303 | 304 | #ifdef HAL_RTC_MODULE_ENABLED 305 | #include "stm32l4xx_hal_rtc.h" 306 | #endif /* HAL_RTC_MODULE_ENABLED */ 307 | 308 | #ifdef HAL_SAI_MODULE_ENABLED 309 | #include "stm32l4xx_hal_sai.h" 310 | #endif /* HAL_SAI_MODULE_ENABLED */ 311 | 312 | #ifdef HAL_SD_MODULE_ENABLED 313 | #include "stm32l4xx_hal_sd.h" 314 | #endif /* HAL_SD_MODULE_ENABLED */ 315 | 316 | #ifdef HAL_SMBUS_MODULE_ENABLED 317 | #include "stm32l4xx_hal_smbus.h" 318 | #endif /* HAL_SMBUS_MODULE_ENABLED */ 319 | 320 | #ifdef HAL_SPI_MODULE_ENABLED 321 | #include "stm32l4xx_hal_spi.h" 322 | #endif /* HAL_SPI_MODULE_ENABLED */ 323 | 324 | #ifdef HAL_SWPMI_MODULE_ENABLED 325 | #include "stm32l4xx_hal_swpmi.h" 326 | #endif /* HAL_SWPMI_MODULE_ENABLED */ 327 | 328 | #ifdef HAL_TIM_MODULE_ENABLED 329 | #include "stm32l4xx_hal_tim.h" 330 | #endif /* HAL_TIM_MODULE_ENABLED */ 331 | 332 | #ifdef HAL_TSC_MODULE_ENABLED 333 | #include "stm32l4xx_hal_tsc.h" 334 | #endif /* HAL_TSC_MODULE_ENABLED */ 335 | 336 | #ifdef HAL_UART_MODULE_ENABLED 337 | #include "stm32l4xx_hal_uart.h" 338 | #endif /* HAL_UART_MODULE_ENABLED */ 339 | 340 | #ifdef HAL_USART_MODULE_ENABLED 341 | #include "stm32l4xx_hal_usart.h" 342 | #endif /* HAL_USART_MODULE_ENABLED */ 343 | 344 | #ifdef HAL_IRDA_MODULE_ENABLED 345 | #include "stm32l4xx_hal_irda.h" 346 | #endif /* HAL_IRDA_MODULE_ENABLED */ 347 | 348 | #ifdef HAL_SMARTCARD_MODULE_ENABLED 349 | #include "stm32l4xx_hal_smartcard.h" 350 | #endif /* HAL_SMARTCARD_MODULE_ENABLED */ 351 | 352 | #ifdef HAL_WWDG_MODULE_ENABLED 353 | #include "stm32l4xx_hal_wwdg.h" 354 | #endif /* HAL_WWDG_MODULE_ENABLED */ 355 | 356 | #ifdef HAL_PCD_MODULE_ENABLED 357 | #include "stm32l4xx_hal_pcd.h" 358 | #endif /* HAL_PCD_MODULE_ENABLED */ 359 | 360 | #ifdef HAL_HCD_MODULE_ENABLED 361 | #include "stm32l4xx_hal_hcd.h" 362 | #endif /* HAL_HCD_MODULE_ENABLED */ 363 | 364 | #ifdef HAL_GFXMMU_MODULE_ENABLED 365 | #include "stm32l4xx_hal_gfxmmu.h" 366 | #endif /* HAL_GFXMMU_MODULE_ENABLED */ 367 | 368 | /* Exported macro ------------------------------------------------------------*/ 369 | #ifdef USE_FULL_ASSERT 370 | /** 371 | * @brief The assert_param macro is used for function's parameters check. 372 | * @param expr: If expr is false, it calls assert_failed function 373 | * which reports the name of the source file and the source 374 | * line number of the call that failed. 375 | * If expr is true, it returns no value. 376 | * @retval None 377 | */ 378 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 379 | /* Exported functions ------------------------------------------------------- */ 380 | void assert_failed(uint8_t* file, uint32_t line); 381 | #else 382 | #define assert_param(expr) ((void)0U) 383 | #endif /* USE_FULL_ASSERT */ 384 | 385 | #ifdef __cplusplus 386 | } 387 | #endif 388 | 389 | #endif /* __STM32L4xx_HAL_CONF_H */ 390 | 391 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 392 | -------------------------------------------------------------------------------- /Inc/stm32l4xx_it.h: -------------------------------------------------------------------------------- 1 | #ifndef __STM32L4xx_IT_H 2 | #define __STM32L4xx_IT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* Includes ------------------------------------------------------------------*/ 9 | /* Exported types ------------------------------------------------------------*/ 10 | /* Exported constants --------------------------------------------------------*/ 11 | /* Exported macro ------------------------------------------------------------*/ 12 | /* Exported functions ------------------------------------------------------- */ 13 | void NMI_Handler(void); 14 | void HardFault_Handler(void); 15 | void MemManage_Handler(void); 16 | void BusFault_Handler(void); 17 | void UsageFault_Handler(void); 18 | void SVC_Handler(void); 19 | void DebugMon_Handler(void); 20 | void PendSV_Handler(void); 21 | void SysTick_Handler(void); 22 | 23 | void DMA2_Channel5_IRQHandler(void); 24 | void SDMMC1_IRQHandler(void); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* __STM32L4xx_IT_H */ 31 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2017 Akos Pasztor. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | 16 | Apache License 17 | Version 2.0, January 2004 18 | http://www.apache.org/licenses/ 19 | 20 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 21 | 22 | 1. Definitions. 23 | 24 | "License" shall mean the terms and conditions for use, reproduction, 25 | and distribution as defined by Sections 1 through 9 of this document. 26 | 27 | "Licensor" shall mean the copyright owner or entity authorized by 28 | the copyright owner that is granting the License. 29 | 30 | "Legal Entity" shall mean the union of the acting entity and all 31 | other entities that control, are controlled by, or are under common 32 | control with that entity. For the purposes of this definition, 33 | "control" means (i) the power, direct or indirect, to cause the 34 | direction or management of such entity, whether by contract or 35 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 36 | outstanding shares, or (iii) beneficial ownership of such entity. 37 | 38 | "You" (or "Your") shall mean an individual or Legal Entity 39 | exercising permissions granted by this License. 40 | 41 | "Source" form shall mean the preferred form for making modifications, 42 | including but not limited to software source code, documentation 43 | source, and configuration files. 44 | 45 | "Object" form shall mean any form resulting from mechanical 46 | transformation or translation of a Source form, including but 47 | not limited to compiled object code, generated documentation, 48 | and conversions to other media types. 49 | 50 | "Work" shall mean the work of authorship, whether in Source or 51 | Object form, made available under the License, as indicated by a 52 | copyright notice that is included in or attached to the work 53 | (an example is provided in the Appendix below). 54 | 55 | "Derivative Works" shall mean any work, whether in Source or Object 56 | form, that is based on (or derived from) the Work and for which the 57 | editorial revisions, annotations, elaborations, or other modifications 58 | represent, as a whole, an original work of authorship. For the purposes 59 | of this License, Derivative Works shall not include works that remain 60 | separable from, or merely link (or bind by name) to the interfaces of, 61 | the Work and Derivative Works thereof. 62 | 63 | "Contribution" shall mean any work of authorship, including 64 | the original version of the Work and any modifications or additions 65 | to that Work or Derivative Works thereof, that is intentionally 66 | submitted to Licensor for inclusion in the Work by the copyright owner 67 | or by an individual or Legal Entity authorized to submit on behalf of 68 | the copyright owner. For the purposes of this definition, "submitted" 69 | means any form of electronic, verbal, or written communication sent 70 | to the Licensor or its representatives, including but not limited to 71 | communication on electronic mailing lists, source code control systems, 72 | and issue tracking systems that are managed by, or on behalf of, the 73 | Licensor for the purpose of discussing and improving the Work, but 74 | excluding communication that is conspicuously marked or otherwise 75 | designated in writing by the copyright owner as "Not a Contribution." 76 | 77 | "Contributor" shall mean Licensor and any individual or Legal Entity 78 | on behalf of whom a Contribution has been received by Licensor and 79 | subsequently incorporated within the Work. 80 | 81 | 2. Grant of Copyright License. Subject to the terms and conditions of 82 | this License, each Contributor hereby grants to You a perpetual, 83 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 84 | copyright license to reproduce, prepare Derivative Works of, 85 | publicly display, publicly perform, sublicense, and distribute the 86 | Work and such Derivative Works in Source or Object form. 87 | 88 | 3. Grant of Patent License. Subject to the terms and conditions of 89 | this License, each Contributor hereby grants to You a perpetual, 90 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 91 | (except as stated in this section) patent license to make, have made, 92 | use, offer to sell, sell, import, and otherwise transfer the Work, 93 | where such license applies only to those patent claims licensable 94 | by such Contributor that are necessarily infringed by their 95 | Contribution(s) alone or by combination of their Contribution(s) 96 | with the Work to which such Contribution(s) was submitted. If You 97 | institute patent litigation against any entity (including a 98 | cross-claim or counterclaim in a lawsuit) alleging that the Work 99 | or a Contribution incorporated within the Work constitutes direct 100 | or contributory patent infringement, then any patent licenses 101 | granted to You under this License for that Work shall terminate 102 | as of the date such litigation is filed. 103 | 104 | 4. Redistribution. You may reproduce and distribute copies of the 105 | Work or Derivative Works thereof in any medium, with or without 106 | modifications, and in Source or Object form, provided that You 107 | meet the following conditions: 108 | 109 | (a) You must give any other recipients of the Work or 110 | Derivative Works a copy of this License; and 111 | 112 | (b) You must cause any modified files to carry prominent notices 113 | stating that You changed the files; and 114 | 115 | (c) You must retain, in the Source form of any Derivative Works 116 | that You distribute, all copyright, patent, trademark, and 117 | attribution notices from the Source form of the Work, 118 | excluding those notices that do not pertain to any part of 119 | the Derivative Works; and 120 | 121 | (d) If the Work includes a "NOTICE" text file as part of its 122 | distribution, then any Derivative Works that You distribute must 123 | include a readable copy of the attribution notices contained 124 | within such NOTICE file, excluding those notices that do not 125 | pertain to any part of the Derivative Works, in at least one 126 | of the following places: within a NOTICE text file distributed 127 | as part of the Derivative Works; within the Source form or 128 | documentation, if provided along with the Derivative Works; or, 129 | within a display generated by the Derivative Works, if and 130 | wherever such third-party notices normally appear. The contents 131 | of the NOTICE file are for informational purposes only and 132 | do not modify the License. You may add Your own attribution 133 | notices within Derivative Works that You distribute, alongside 134 | or as an addendum to the NOTICE text from the Work, provided 135 | that such additional attribution notices cannot be construed 136 | as modifying the License. 137 | 138 | You may add Your own copyright statement to Your modifications and 139 | may provide additional or different license terms and conditions 140 | for use, reproduction, or distribution of Your modifications, or 141 | for any such Derivative Works as a whole, provided Your use, 142 | reproduction, and distribution of the Work otherwise complies with 143 | the conditions stated in this License. 144 | 145 | 5. Submission of Contributions. Unless You explicitly state otherwise, 146 | any Contribution intentionally submitted for inclusion in the Work 147 | by You to the Licensor shall be under the terms and conditions of 148 | this License, without any additional terms or conditions. 149 | Notwithstanding the above, nothing herein shall supersede or modify 150 | the terms of any separate license agreement you may have executed 151 | with Licensor regarding such Contributions. 152 | 153 | 6. Trademarks. This License does not grant permission to use the trade 154 | names, trademarks, service marks, or product names of the Licensor, 155 | except as required for reasonable and customary use in describing the 156 | origin of the Work and reproducing the content of the NOTICE file. 157 | 158 | 7. Disclaimer of Warranty. Unless required by applicable law or 159 | agreed to in writing, Licensor provides the Work (and each 160 | Contributor provides its Contributions) on an "AS IS" BASIS, 161 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 162 | implied, including, without limitation, any warranties or conditions 163 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 164 | PARTICULAR PURPOSE. You are solely responsible for determining the 165 | appropriateness of using or redistributing the Work and assume any 166 | risks associated with Your exercise of permissions under this License. 167 | 168 | 8. Limitation of Liability. In no event and under no legal theory, 169 | whether in tort (including negligence), contract, or otherwise, 170 | unless required by applicable law (such as deliberate and grossly 171 | negligent acts) or agreed to in writing, shall any Contributor be 172 | liable to You for damages, including any direct, indirect, special, 173 | incidental, or consequential damages of any character arising as a 174 | result of this License or out of the use or inability to use the 175 | Work (including but not limited to damages for loss of goodwill, 176 | work stoppage, computer failure or malfunction, or any and all 177 | other commercial damages or losses), even if such Contributor 178 | has been advised of the possibility of such damages. 179 | 180 | 9. Accepting Warranty or Additional Liability. While redistributing 181 | the Work or Derivative Works thereof, You may choose to offer, 182 | and charge a fee for, acceptance of support, warranty, indemnity, 183 | or other liability obligations and/or rights consistent with this 184 | License. However, in accepting such obligations, You may act only 185 | on Your own behalf and on Your sole responsibility, not on behalf 186 | of any other Contributor, and only if You agree to indemnify, 187 | defend, and hold each Contributor harmless for any liability 188 | incurred by, or claims asserted against, such Contributor by reason 189 | of your accepting any such warranty or additional liability. 190 | 191 | END OF TERMS AND CONDITIONS 192 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FatFs/src/diskio.c: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------*/ 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2017 */ 3 | /* */ 4 | /* Portions COPYRIGHT 2017 STMicroelectronics */ 5 | /* Portions Copyright (C) 2017, ChaN, all right reserved */ 6 | /*-----------------------------------------------------------------------*/ 7 | /* If a working storage control module is available, it should be */ 8 | /* attached to the FatFs via a glue function rather than modifying it. */ 9 | /* This is an example of glue functions to attach various existing */ 10 | /* storage control modules to the FatFs module with a defined API. */ 11 | /*-----------------------------------------------------------------------*/ 12 | 13 | /** 14 | ****************************************************************************** 15 | * 16 | *

© Copyright (c) 2017 STMicroelectronics International N.V. 17 | * All rights reserved.

18 | * 19 | * Redistribution and use in source and binary forms, with or without 20 | * modification, are permitted, provided that the following conditions are met: 21 | * 22 | * 1. Redistribution of source code must retain the above copyright notice, 23 | * this list of conditions and the following disclaimer. 24 | * 2. Redistributions in binary form must reproduce the above copyright notice, 25 | * this list of conditions and the following disclaimer in the documentation 26 | * and/or other materials provided with the distribution. 27 | * 3. Neither the name of STMicroelectronics nor the names of other 28 | * contributors to this software may be used to endorse or promote products 29 | * derived from this software without specific written permission. 30 | * 4. This software, including modifications and/or derivative works of this 31 | * software, must execute solely and exclusively on microcontroller or 32 | * microprocessor devices manufactured by or for STMicroelectronics. 33 | * 5. Redistribution and use of this software other than as permitted under 34 | * this license is void and will automatically terminate your rights under 35 | * this license. 36 | * 37 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 38 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 39 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 40 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 41 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 42 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 43 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 44 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 45 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 46 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 47 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 48 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 | * 50 | ****************************************************************************** 51 | */ 52 | 53 | /* Includes ------------------------------------------------------------------*/ 54 | #include "diskio.h" 55 | #include "ff_gen_drv.h" 56 | 57 | #if defined ( __GNUC__ ) 58 | #ifndef __weak 59 | #define __weak __attribute__((weak)) 60 | #endif 61 | #endif 62 | 63 | /* Private typedef -----------------------------------------------------------*/ 64 | /* Private define ------------------------------------------------------------*/ 65 | /* Private variables ---------------------------------------------------------*/ 66 | extern Disk_drvTypeDef disk; 67 | 68 | /* Private function prototypes -----------------------------------------------*/ 69 | /* Private functions ---------------------------------------------------------*/ 70 | 71 | /** 72 | * @brief Gets Disk Status 73 | * @param pdrv: Physical drive number (0..) 74 | * @retval DSTATUS: Operation status 75 | */ 76 | DSTATUS disk_status ( 77 | BYTE pdrv /* Physical drive number to identify the drive */ 78 | ) 79 | { 80 | DSTATUS stat; 81 | 82 | stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]); 83 | return stat; 84 | } 85 | 86 | /** 87 | * @brief Initializes a Drive 88 | * @param pdrv: Physical drive number (0..) 89 | * @retval DSTATUS: Operation status 90 | */ 91 | DSTATUS disk_initialize ( 92 | BYTE pdrv /* Physical drive nmuber to identify the drive */ 93 | ) 94 | { 95 | DSTATUS stat = RES_OK; 96 | 97 | if(disk.is_initialized[pdrv] == 0) 98 | { 99 | disk.is_initialized[pdrv] = 1; 100 | stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]); 101 | } 102 | return stat; 103 | } 104 | 105 | /** 106 | * @brief Reads Sector(s) 107 | * @param pdrv: Physical drive number (0..) 108 | * @param *buff: Data buffer to store read data 109 | * @param sector: Sector address (LBA) 110 | * @param count: Number of sectors to read (1..128) 111 | * @retval DRESULT: Operation result 112 | */ 113 | DRESULT disk_read ( 114 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ 115 | BYTE *buff, /* Data buffer to store read data */ 116 | DWORD sector, /* Sector address in LBA */ 117 | UINT count /* Number of sectors to read */ 118 | ) 119 | { 120 | DRESULT res; 121 | 122 | res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count); 123 | return res; 124 | } 125 | 126 | /** 127 | * @brief Writes Sector(s) 128 | * @param pdrv: Physical drive number (0..) 129 | * @param *buff: Data to be written 130 | * @param sector: Sector address (LBA) 131 | * @param count: Number of sectors to write (1..128) 132 | * @retval DRESULT: Operation result 133 | */ 134 | #if _USE_WRITE == 1 135 | DRESULT disk_write ( 136 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ 137 | const BYTE *buff, /* Data to be written */ 138 | DWORD sector, /* Sector address in LBA */ 139 | UINT count /* Number of sectors to write */ 140 | ) 141 | { 142 | DRESULT res; 143 | 144 | res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count); 145 | return res; 146 | } 147 | #endif /* _USE_WRITE == 1 */ 148 | 149 | /** 150 | * @brief I/O control operation 151 | * @param pdrv: Physical drive number (0..) 152 | * @param cmd: Control code 153 | * @param *buff: Buffer to send/receive control data 154 | * @retval DRESULT: Operation result 155 | */ 156 | #if _USE_IOCTL == 1 157 | DRESULT disk_ioctl ( 158 | BYTE pdrv, /* Physical drive nmuber (0..) */ 159 | BYTE cmd, /* Control code */ 160 | void *buff /* Buffer to send/receive control data */ 161 | ) 162 | { 163 | DRESULT res; 164 | 165 | res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff); 166 | return res; 167 | } 168 | #endif /* _USE_IOCTL == 1 */ 169 | 170 | /** 171 | * @brief Gets Time from RTC 172 | * @param None 173 | * @retval Time in DWORD 174 | */ 175 | __weak DWORD get_fattime (void) 176 | { 177 | return 0; 178 | } 179 | 180 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 181 | 182 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FatFs/src/diskio.h: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------/ 2 | / Low level disk interface modlue include file (C)ChaN, 2014 / 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO_DEFINED 6 | #define _DISKIO_DEFINED 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define _USE_WRITE 1 /* 1: Enable disk_write function */ 13 | #define _USE_IOCTL 1 /* 1: Enable disk_ioctl function */ 14 | 15 | #include "integer.h" 16 | 17 | 18 | /* Status of Disk Functions */ 19 | typedef BYTE DSTATUS; 20 | 21 | /* Results of Disk Functions */ 22 | typedef enum { 23 | RES_OK = 0, /* 0: Successful */ 24 | RES_ERROR, /* 1: R/W Error */ 25 | RES_WRPRT, /* 2: Write Protected */ 26 | RES_NOTRDY, /* 3: Not Ready */ 27 | RES_PARERR /* 4: Invalid Parameter */ 28 | } DRESULT; 29 | 30 | 31 | /*---------------------------------------*/ 32 | /* Prototypes for disk control functions */ 33 | 34 | 35 | DSTATUS disk_initialize (BYTE pdrv); 36 | DSTATUS disk_status (BYTE pdrv); 37 | DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); 38 | DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); 39 | DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); 40 | DWORD get_fattime (void); 41 | 42 | /* Disk Status Bits (DSTATUS) */ 43 | 44 | #define STA_NOINIT 0x01 /* Drive not initialized */ 45 | #define STA_NODISK 0x02 /* No medium in the drive */ 46 | #define STA_PROTECT 0x04 /* Write protected */ 47 | 48 | 49 | /* Command code for disk_ioctrl fucntion */ 50 | 51 | /* Generic command (Used by FatFs) */ 52 | #define CTRL_SYNC 0 /* Complete pending write process (needed at _FS_READONLY == 0) */ 53 | #define GET_SECTOR_COUNT 1 /* Get media size (needed at _USE_MKFS == 1) */ 54 | #define GET_SECTOR_SIZE 2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */ 55 | #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at _USE_MKFS == 1) */ 56 | #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */ 57 | 58 | /* Generic command (Not used by FatFs) */ 59 | #define CTRL_POWER 5 /* Get/Set power status */ 60 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 61 | #define CTRL_EJECT 7 /* Eject media */ 62 | #define CTRL_FORMAT 8 /* Create physical format on the media */ 63 | 64 | /* MMC/SDC specific ioctl command */ 65 | #define MMC_GET_TYPE 10 /* Get card type */ 66 | #define MMC_GET_CSD 11 /* Get CSD */ 67 | #define MMC_GET_CID 12 /* Get CID */ 68 | #define MMC_GET_OCR 13 /* Get OCR */ 69 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 70 | 71 | /* ATA/CF specific ioctl command */ 72 | #define ATA_GET_REV 20 /* Get F/W revision */ 73 | #define ATA_GET_MODEL 21 /* Get model name */ 74 | #define ATA_GET_SN 22 /* Get serial number */ 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FatFs/src/driver/sd_diskio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * STM32L4 Bootloader 4 | ****************************************************************************** 5 | * @author Akos Pasztor 6 | * @file sd_diskio.c 7 | * @brief SD diskio driver 8 | * This file contains the implementation of the SD diskio driver 9 | * used by the FatFs module. The driver uses the HAL library of ST. 10 | * 11 | ****************************************************************************** 12 | * Copyright (c) 2018 Akos Pasztor. https://akospasztor.com 13 | ****************************************************************************** 14 | **/ 15 | 16 | #include "ff_gen_drv.h" 17 | #include "sd_diskio.h" 18 | 19 | /* Defines -------------------------------------------------------------------*/ 20 | #define SD_TIMEOUT SD_DATATIMEOUT /* Defined in bsp_driver_sd.h */ 21 | 22 | /* 23 | * Depending on the use case, the SD card initialization could be done at the 24 | * application level: if it is the case, disable the define below to disable 25 | * the BSP_SD_Init() call in the SD_Initialize() and manually add a call to 26 | * BSP_SD_Init() elsewhere in the application. 27 | */ 28 | //#define ENABLE_SD_INIT 29 | 30 | /* Enable the define below to use the SD driver with DMA. 31 | * The define has effect in SD_read and SD_write. 32 | * BSP_DRIVER_SD should handle the DMA MSP initialization. 33 | */ 34 | #define ENABLE_SD_DMA_DRIVER 35 | 36 | /* 37 | * When using cachable memory region, it may be needed to maintain the cache 38 | * validity. Enable the define below to activate a cache maintenance at each 39 | * read and write operation. 40 | * Notice: This is applicable only for cortex M7 based platform. 41 | */ 42 | //#define ENABLE_SD_DMA_CACHE_MAINTENANCE 1 43 | 44 | /* Private variables ---------------------------------------------------------*/ 45 | static volatile DSTATUS Stat = STA_NOINIT; /* Disk status */ 46 | static volatile UINT ReadStatus = 0; 47 | static volatile UINT WriteStatus = 0; 48 | 49 | /* Private function prototypes -----------------------------------------------*/ 50 | static DSTATUS SD_CheckStatus(BYTE lun); 51 | DSTATUS SD_initialize (BYTE); 52 | DSTATUS SD_status (BYTE); 53 | DRESULT SD_read (BYTE, BYTE*, DWORD, UINT); 54 | 55 | #if _USE_WRITE == 1 56 | DRESULT SD_write (BYTE, const BYTE*, DWORD, UINT); 57 | #endif /* _USE_WRITE == 1 */ 58 | 59 | #if _USE_IOCTL == 1 60 | DRESULT SD_ioctl (BYTE, BYTE, void*); 61 | #endif /* _USE_IOCTL == 1 */ 62 | 63 | 64 | const Diskio_drvTypeDef SD_Driver = 65 | { 66 | SD_initialize, 67 | SD_status, 68 | SD_read, 69 | #if _USE_WRITE == 1 70 | SD_write, 71 | #endif /* _USE_WRITE == 1 */ 72 | #if _USE_IOCTL == 1 73 | SD_ioctl, 74 | #endif /* _USE_IOCTL == 1 */ 75 | }; 76 | 77 | 78 | /* Private functions ---------------------------------------------------------*/ 79 | static DSTATUS SD_CheckStatus(BYTE lun) 80 | { 81 | Stat = STA_NOINIT; 82 | 83 | if(BSP_SD_GetCardState() == MSD_OK) 84 | { 85 | Stat &= ~STA_NOINIT; 86 | } 87 | 88 | return Stat; 89 | } 90 | 91 | /** 92 | * @brief Initializes a Drive 93 | * @param lun : not used 94 | * @retval DSTATUS: Operation status 95 | */ 96 | DSTATUS SD_initialize(BYTE lun) 97 | { 98 | Stat = STA_NOINIT; 99 | 100 | #if defined(ENABLE_SD_INIT) 101 | if(BSP_SD_Init() == MSD_OK) 102 | { 103 | Stat = SD_CheckStatus(lun); 104 | } 105 | #else 106 | Stat = SD_CheckStatus(lun); 107 | #endif 108 | 109 | ReadStatus = 0; 110 | WriteStatus = 0; 111 | 112 | return Stat; 113 | } 114 | 115 | /** 116 | * @brief Gets Disk Status 117 | * @param lun : not used 118 | * @retval DSTATUS: Operation status 119 | */ 120 | DSTATUS SD_status(BYTE lun) 121 | { 122 | return SD_CheckStatus(lun); 123 | } 124 | 125 | /** 126 | * @brief Reads Sector(s) 127 | * @param lun : not used 128 | * @param *buff: Data buffer to store read data 129 | * @param sector: Sector address (LBA) 130 | * @param count: Number of sectors to read (1..128) 131 | * @retval DRESULT: Operation result 132 | */ 133 | DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count) 134 | { 135 | DRESULT res; 136 | uint32_t timeout; 137 | 138 | #if defined(ENABLE_SD_DMA_DRIVER) 139 | /* Use SD Driver in DMA mode */ 140 | 141 | #if defined(ENABLE_SD_DMA_CACHE_MAINTENANCE) 142 | uint32_t alignedAddr; 143 | #endif /* SD_DMA_CACHE_MAINTENANCE */ 144 | 145 | res = RES_ERROR; 146 | ReadStatus = 0; 147 | 148 | if(BSP_SD_ReadBlocks_DMA((uint32_t*)buff, (uint32_t)(sector), count) == MSD_OK) 149 | { 150 | /* Wait for DMA Complete */ 151 | timeout = HAL_GetTick(); 152 | while((ReadStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)) 153 | { 154 | } 155 | 156 | /* In case of a timeout return error */ 157 | if(ReadStatus == 0) 158 | { 159 | res = RES_ERROR; 160 | } 161 | else 162 | { 163 | ReadStatus = 0; 164 | timeout = HAL_GetTick(); 165 | while((HAL_GetTick() - timeout) < SD_TIMEOUT) 166 | { 167 | if(BSP_SD_GetCardState() == SD_TRANSFER_OK) 168 | { 169 | res = RES_OK; 170 | #if defined(ENABLE_SD_DMA_CACHE_MAINTENANCE) 171 | /* The SCB_InvalidateDCache_by_Addr() requires a 32-Byte aligned address, 172 | * adjust the address and the D-Cache size to invalidate accordingly. 173 | */ 174 | alignedAddr = (uint32_t)buff & ~0x1F; 175 | SCB_InvalidateDCache_by_Addr((uint32_t*)alignedAddr, count*BLOCKSIZE + ((uint32_t)buff - alignedAddr)); 176 | #endif /* SD_DMA_CACHE_MAINTENANCE */ 177 | break; 178 | } 179 | } 180 | } 181 | } 182 | 183 | return res; 184 | 185 | #else 186 | /* Use SD Driver in blocking mode */ 187 | res = RES_ERROR; 188 | if(BSP_SD_ReadBlocks((uint32_t*)buff, 189 | (uint32_t)(sector), 190 | count, SDMMC_HAL_TIMEOUT) == MSD_OK) 191 | { 192 | /* Wait until the read operation is finished */ 193 | timeout = HAL_GetTick(); 194 | while((HAL_GetTick() - timeout) < SD_TIMEOUT) 195 | { 196 | if(BSP_SD_GetCardState() == MSD_OK) 197 | { 198 | return RES_OK; 199 | } 200 | } 201 | } 202 | 203 | return res; 204 | #endif /* ENABLE_SD_DMA_DRIVER */ 205 | } 206 | 207 | 208 | /** 209 | * @brief Writes Sector(s) 210 | * @param lun : not used 211 | * @param *buff: Data to be written 212 | * @param sector: Sector address (LBA) 213 | * @param count: Number of sectors to write (1..128) 214 | * @retval DRESULT: Operation result 215 | */ 216 | #if _USE_WRITE == 1 217 | DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count) 218 | { 219 | DRESULT res; 220 | uint32_t timeout; 221 | 222 | #if defined(ENABLE_SD_DMA_DRIVER) 223 | /* Use SD Driver in DMA mode */ 224 | 225 | #if defined(ENABLE_SD_DMA_CACHE_MAINTENANCE) 226 | uint32_t alignedAddr; 227 | alignedAddr = (uint32_t)buff & ~0x1F; 228 | SCB_CleanDCache_by_Addr((uint32_t*)alignedAddr, count*BLOCKSIZE + ((uint32_t)buff - alignedAddr)); 229 | #endif 230 | 231 | res = RES_ERROR; 232 | WriteStatus = 0; 233 | 234 | if(BSP_SD_WriteBlocks_DMA((uint32_t*)buff, (uint32_t)(sector), count) == MSD_OK) 235 | { 236 | /* Wait for DMA complete */ 237 | timeout = HAL_GetTick(); 238 | while((WriteStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT)) 239 | { 240 | } 241 | 242 | /* In case of a timeout return error */ 243 | if(WriteStatus == 0) 244 | { 245 | res = RES_ERROR; 246 | } 247 | else 248 | { 249 | WriteStatus = 0; 250 | timeout = HAL_GetTick(); 251 | while((HAL_GetTick() - timeout) < SD_TIMEOUT) 252 | { 253 | if(BSP_SD_GetCardState() == SD_TRANSFER_OK) 254 | { 255 | res = RES_OK; 256 | break; 257 | } 258 | } 259 | } 260 | } 261 | 262 | return res; 263 | 264 | #else 265 | /* Use SD Driver in blocking mode */ 266 | res = RES_ERROR; 267 | if(BSP_SD_WriteBlocks((uint32_t*)buff, 268 | (uint32_t)(sector), 269 | count, SDMMC_HAL_TIMEOUT) == MSD_OK) 270 | { 271 | /* Wait until the Write operation is finished */ 272 | timeout = HAL_GetTick(); 273 | while((HAL_GetTick() - timeout) < SD_TIMEOUT) 274 | { 275 | if(BSP_SD_GetCardState() == MSD_OK) 276 | { 277 | return RES_OK; 278 | } 279 | } 280 | } 281 | 282 | return res; 283 | #endif /* ENABLE_SD_DMA_DRIVER */ 284 | } 285 | #endif /* _USE_WRITE == 1 */ 286 | 287 | /** 288 | * @brief I/O control operation 289 | * @param lun : not used 290 | * @param cmd: Control code 291 | * @param *buff: Buffer to send/receive control data 292 | * @retval DRESULT: Operation result 293 | */ 294 | #if _USE_IOCTL == 1 295 | DRESULT SD_ioctl(BYTE lun, BYTE cmd, void *buff) 296 | { 297 | DRESULT res = RES_ERROR; 298 | BSP_SD_CardInfo CardInfo; 299 | 300 | if(Stat & STA_NOINIT) 301 | { 302 | return RES_NOTRDY; 303 | } 304 | 305 | switch(cmd) 306 | { 307 | /* Make sure that no pending write process */ 308 | case CTRL_SYNC : 309 | res = RES_OK; 310 | break; 311 | 312 | /* Get number of sectors on the disk (DWORD) */ 313 | case GET_SECTOR_COUNT : 314 | BSP_SD_GetCardInfo(&CardInfo); 315 | *(DWORD*)buff = CardInfo.LogBlockNbr; 316 | res = RES_OK; 317 | break; 318 | 319 | /* Get R/W sector size (WORD) */ 320 | case GET_SECTOR_SIZE : 321 | BSP_SD_GetCardInfo(&CardInfo); 322 | *(WORD*)buff = CardInfo.LogBlockSize; 323 | res = RES_OK; 324 | break; 325 | 326 | /* Get erase block size in unit of sector (DWORD) */ 327 | case GET_BLOCK_SIZE : 328 | BSP_SD_GetCardInfo(&CardInfo); 329 | *(DWORD*)buff = CardInfo.LogBlockSize; 330 | res = RES_OK; 331 | break; 332 | 333 | default: 334 | res = RES_PARERR; 335 | } 336 | 337 | return res; 338 | } 339 | #endif /* _USE_IOCTL == 1 */ 340 | 341 | 342 | /** 343 | * @brief Rx Transfer complete callback 344 | * @param hsd: SD handle 345 | * @retval None 346 | */ 347 | void BSP_SD_ReadCpltCallback(void) 348 | { 349 | ReadStatus = 1; 350 | } 351 | 352 | /** 353 | * @brief Tx Transfer complete callback 354 | * @param hsd: SD handle 355 | * @retval None 356 | */ 357 | void BSP_SD_WriteCpltCallback(void) 358 | { 359 | WriteStatus = 1; 360 | } 361 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FatFs/src/driver/sd_diskio.h: -------------------------------------------------------------------------------- 1 | #ifndef __SD_DISKIO_H 2 | #define __SD_DISKIO_H 3 | 4 | /* Includes ------------------------------------------------------------------*/ 5 | #include "bsp_driver_sd.h" 6 | 7 | /* Exported constants --------------------------------------------------------*/ 8 | extern const Diskio_drvTypeDef SD_Driver; 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FatFs/src/ff_gen_drv.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ff_gen_drv.c 4 | * @author MCD Application Team 5 | * @version V2.0.1 6 | * @date 10-July-2017 7 | * @brief FatFs generic low level driver. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© Copyright (c) 2017 STMicroelectronics International N.V. 12 | * All rights reserved.

13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted, provided that the following conditions are met: 16 | * 17 | * 1. Redistribution of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of other 23 | * contributors to this software may be used to endorse or promote products 24 | * derived from this software without specific written permission. 25 | * 4. This software, including modifications and/or derivative works of this 26 | * software, must execute solely and exclusively on microcontroller or 27 | * microprocessor devices manufactured by or for STMicroelectronics. 28 | * 5. Redistribution and use of this software other than as permitted under 29 | * this license is void and will automatically terminate your rights under 30 | * this license. 31 | * 32 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 33 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 35 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 36 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 37 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 38 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 39 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 40 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 43 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | * 45 | ****************************************************************************** 46 | */ 47 | 48 | /* Includes ------------------------------------------------------------------*/ 49 | #include "ff_gen_drv.h" 50 | 51 | /* Private typedef -----------------------------------------------------------*/ 52 | /* Private define ------------------------------------------------------------*/ 53 | /* Private variables ---------------------------------------------------------*/ 54 | Disk_drvTypeDef disk = {{0},{0},{0},0}; 55 | 56 | /* Private function prototypes -----------------------------------------------*/ 57 | /* Private functions ---------------------------------------------------------*/ 58 | 59 | /** 60 | * @brief Links a compatible diskio driver/lun id and increments the number of active 61 | * linked drivers. 62 | * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits. 63 | * @param drv: pointer to the disk IO Driver structure 64 | * @param path: pointer to the logical drive path 65 | * @param lun : only used for USB Key Disk to add multi-lun management 66 | else the parameter must be equal to 0 67 | * @retval Returns 0 in case of success, otherwise 1. 68 | */ 69 | uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, uint8_t lun) 70 | { 71 | uint8_t ret = 1; 72 | uint8_t DiskNum = 0; 73 | 74 | if(disk.nbr < _VOLUMES) 75 | { 76 | disk.is_initialized[disk.nbr] = 0; 77 | disk.drv[disk.nbr] = drv; 78 | disk.lun[disk.nbr] = lun; 79 | DiskNum = disk.nbr++; 80 | path[0] = DiskNum + '0'; 81 | path[1] = ':'; 82 | path[2] = '/'; 83 | path[3] = 0; 84 | ret = 0; 85 | } 86 | 87 | return ret; 88 | } 89 | 90 | /** 91 | * @brief Links a compatible diskio driver and increments the number of active 92 | * linked drivers. 93 | * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits 94 | * @param drv: pointer to the disk IO Driver structure 95 | * @param path: pointer to the logical drive path 96 | * @retval Returns 0 in case of success, otherwise 1. 97 | */ 98 | uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path) 99 | { 100 | return FATFS_LinkDriverEx(drv, path, 0); 101 | } 102 | 103 | /** 104 | * @brief Unlinks a diskio driver and decrements the number of active linked 105 | * drivers. 106 | * @param path: pointer to the logical drive path 107 | * @param lun : not used 108 | * @retval Returns 0 in case of success, otherwise 1. 109 | */ 110 | uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun) 111 | { 112 | uint8_t DiskNum = 0; 113 | uint8_t ret = 1; 114 | 115 | if(disk.nbr >= 1) 116 | { 117 | DiskNum = path[0] - '0'; 118 | if(disk.drv[DiskNum] != 0) 119 | { 120 | disk.drv[DiskNum] = 0; 121 | disk.lun[DiskNum] = 0; 122 | disk.nbr--; 123 | ret = 0; 124 | } 125 | } 126 | 127 | return ret; 128 | } 129 | 130 | /** 131 | * @brief Unlinks a diskio driver and decrements the number of active linked 132 | * drivers. 133 | * @param path: pointer to the logical drive path 134 | * @retval Returns 0 in case of success, otherwise 1. 135 | */ 136 | uint8_t FATFS_UnLinkDriver(char *path) 137 | { 138 | return FATFS_UnLinkDriverEx(path, 0); 139 | } 140 | 141 | /** 142 | * @brief Gets number of linked drivers to the FatFs module. 143 | * @param None 144 | * @retval Number of attached drivers. 145 | */ 146 | uint8_t FATFS_GetAttachedDriversNbr(void) 147 | { 148 | return disk.nbr; 149 | } 150 | 151 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 152 | 153 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FatFs/src/ff_gen_drv.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ff_gen_drv.h 4 | * @author MCD Application Team 5 | * @version V2.0.1 6 | * @date 10-July-2017 7 | * @brief Header for ff_gen_drv.c module. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© Copyright (c) 2017 STMicroelectronics International N.V. 12 | * All rights reserved.

13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted, provided that the following conditions are met: 16 | * 17 | * 1. Redistribution of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of other 23 | * contributors to this software may be used to endorse or promote products 24 | * derived from this software without specific written permission. 25 | * 4. This software, including modifications and/or derivative works of this 26 | * software, must execute solely and exclusively on microcontroller or 27 | * microprocessor devices manufactured by or for STMicroelectronics. 28 | * 5. Redistribution and use of this software other than as permitted under 29 | * this license is void and will automatically terminate your rights under 30 | * this license. 31 | * 32 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 33 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 35 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 36 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 37 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 38 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 39 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 40 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 43 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | * 45 | ****************************************************************************** 46 | */ 47 | 48 | /* Define to prevent recursive inclusion -------------------------------------*/ 49 | #ifndef __FF_GEN_DRV_H 50 | #define __FF_GEN_DRV_H 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /* Includes ------------------------------------------------------------------*/ 57 | #include "diskio.h" 58 | #include "ff.h" 59 | #include "stdint.h" 60 | 61 | 62 | /* Exported types ------------------------------------------------------------*/ 63 | 64 | /** 65 | * @brief Disk IO Driver structure definition 66 | */ 67 | typedef struct 68 | { 69 | DSTATUS (*disk_initialize) (BYTE); /*!< Initialize Disk Drive */ 70 | DSTATUS (*disk_status) (BYTE); /*!< Get Disk Status */ 71 | DRESULT (*disk_read) (BYTE, BYTE*, DWORD, UINT); /*!< Read Sector(s) */ 72 | #if _USE_WRITE == 1 73 | DRESULT (*disk_write) (BYTE, const BYTE*, DWORD, UINT); /*!< Write Sector(s) when _USE_WRITE = 0 */ 74 | #endif /* _USE_WRITE == 1 */ 75 | #if _USE_IOCTL == 1 76 | DRESULT (*disk_ioctl) (BYTE, BYTE, void*); /*!< I/O control operation when _USE_IOCTL = 1 */ 77 | #endif /* _USE_IOCTL == 1 */ 78 | 79 | }Diskio_drvTypeDef; 80 | 81 | /** 82 | * @brief Global Disk IO Drivers structure definition 83 | */ 84 | typedef struct 85 | { 86 | uint8_t is_initialized[_VOLUMES]; 87 | const Diskio_drvTypeDef *drv[_VOLUMES]; 88 | uint8_t lun[_VOLUMES]; 89 | volatile uint8_t nbr; 90 | 91 | }Disk_drvTypeDef; 92 | 93 | /* Exported constants --------------------------------------------------------*/ 94 | /* Exported macro ------------------------------------------------------------*/ 95 | /* Exported functions ------------------------------------------------------- */ 96 | uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path); 97 | uint8_t FATFS_UnLinkDriver(char *path); 98 | uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, BYTE lun); 99 | uint8_t FATFS_UnLinkDriverEx(char *path, BYTE lun); 100 | uint8_t FATFS_GetAttachedDriversNbr(void); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* __FF_GEN_DRV_H */ 107 | 108 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 109 | 110 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FatFs/src/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _FF_INTEGER 6 | #define _FF_INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | typedef unsigned __int64 QWORD; 13 | 14 | 15 | #else /* Embedded platform */ 16 | 17 | /* These types MUST be 16-bit or 32-bit */ 18 | typedef int INT; 19 | typedef unsigned int UINT; 20 | 21 | /* This type MUST be 8-bit */ 22 | typedef unsigned char BYTE; 23 | 24 | /* These types MUST be 16-bit */ 25 | typedef short SHORT; 26 | typedef unsigned short WORD; 27 | typedef unsigned short WCHAR; 28 | 29 | /* These types MUST be 32-bit */ 30 | typedef long LONG; 31 | typedef unsigned long DWORD; 32 | 33 | /* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */ 34 | typedef unsigned long long QWORD; 35 | 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FatFs/src/option/syscall.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* Sample code of OS dependent controls for FatFs */ 3 | /* (C)ChaN, 2014 */ 4 | /* Portions COPYRIGHT 2017 STMicroelectronics */ 5 | /* Portions Copyright (C) 2014, ChaN, all right reserved */ 6 | /*------------------------------------------------------------------------*/ 7 | 8 | /** 9 | ****************************************************************************** 10 | * 11 | *

© Copyright (c) 2017 STMicroelectronics International N.V. 12 | * All rights reserved.

13 | * 14 | * Redistribution and use in source and binary forms, with or without 15 | * modification, are permitted, provided that the following conditions are met: 16 | * 17 | * 1. Redistribution of source code must retain the above copyright notice, 18 | * this list of conditions and the following disclaimer. 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, 20 | * this list of conditions and the following disclaimer in the documentation 21 | * and/or other materials provided with the distribution. 22 | * 3. Neither the name of STMicroelectronics nor the names of other 23 | * contributors to this software may be used to endorse or promote products 24 | * derived from this software without specific written permission. 25 | * 4. This software, including modifications and/or derivative works of this 26 | * software, must execute solely and exclusively on microcontroller or 27 | * microprocessor devices manufactured by or for STMicroelectronics. 28 | * 5. Redistribution and use of this software other than as permitted under 29 | * this license is void and will automatically terminate your rights under 30 | * this license. 31 | * 32 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 33 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 35 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 36 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 37 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 38 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 39 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 40 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 43 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 44 | * 45 | ****************************************************************************** 46 | */ 47 | 48 | 49 | 50 | #include "../ff.h" 51 | 52 | 53 | #if _FS_REENTRANT 54 | /*------------------------------------------------------------------------*/ 55 | /* Create a Synchronization Object */ 56 | /*------------------------------------------------------------------------*/ 57 | /* This function is called in f_mount() function to create a new 58 | / synchronization object, such as semaphore and mutex. When a 0 is returned, 59 | / the f_mount() function fails with FR_INT_ERR. 60 | */ 61 | 62 | int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */ 63 | BYTE vol, /* Corresponding volume (logical drive number) */ 64 | _SYNC_t *sobj /* Pointer to return the created sync object */ 65 | ) 66 | { 67 | 68 | int ret; 69 | 70 | osSemaphoreDef(SEM); 71 | *sobj = osSemaphoreCreate(osSemaphore(SEM), 1); 72 | ret = (*sobj != NULL); 73 | 74 | return ret; 75 | } 76 | 77 | 78 | 79 | /*------------------------------------------------------------------------*/ 80 | /* Delete a Synchronization Object */ 81 | /*------------------------------------------------------------------------*/ 82 | /* This function is called in f_mount() function to delete a synchronization 83 | / object that created with ff_cre_syncobj() function. When a 0 is returned, 84 | / the f_mount() function fails with FR_INT_ERR. 85 | */ 86 | 87 | int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to any error */ 88 | _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ 89 | ) 90 | { 91 | osSemaphoreDelete (sobj); 92 | return 1; 93 | } 94 | 95 | 96 | 97 | /*------------------------------------------------------------------------*/ 98 | /* Request Grant to Access the Volume */ 99 | /*------------------------------------------------------------------------*/ 100 | /* This function is called on entering file functions to lock the volume. 101 | / When a 0 is returned, the file function fails with FR_TIMEOUT. 102 | */ 103 | 104 | int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */ 105 | _SYNC_t sobj /* Sync object to wait */ 106 | ) 107 | { 108 | int ret = 0; 109 | 110 | if(osSemaphoreWait(sobj, _FS_TIMEOUT) == osOK) 111 | { 112 | ret = 1; 113 | } 114 | 115 | return ret; 116 | } 117 | 118 | 119 | 120 | /*------------------------------------------------------------------------*/ 121 | /* Release Grant to Access the Volume */ 122 | /*------------------------------------------------------------------------*/ 123 | /* This function is called on leaving file functions to unlock the volume. 124 | */ 125 | 126 | void ff_rel_grant ( 127 | _SYNC_t sobj /* Sync object to be signaled */ 128 | ) 129 | { 130 | osSemaphoreRelease(sobj); 131 | } 132 | 133 | #endif 134 | 135 | 136 | 137 | 138 | #if _USE_LFN == 3 /* LFN with a working buffer on the heap */ 139 | /*------------------------------------------------------------------------*/ 140 | /* Allocate a memory block */ 141 | /*------------------------------------------------------------------------*/ 142 | /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE. 143 | */ 144 | 145 | void* ff_memalloc ( /* Returns pointer to the allocated memory block */ 146 | UINT msize /* Number of bytes to allocate */ 147 | ) 148 | { 149 | return ff_malloc(msize); /* Allocate a new memory block with POSIX API */ 150 | } 151 | 152 | 153 | /*------------------------------------------------------------------------*/ 154 | /* Free a memory block */ 155 | /*------------------------------------------------------------------------*/ 156 | 157 | void ff_memfree ( 158 | void* mblock /* Pointer to the memory block to free */ 159 | ) 160 | { 161 | ff_free(mblock); /* Discard the memory block with POSIX API */ 162 | } 163 | 164 | #endif 165 | -------------------------------------------------------------------------------- /Middlewares/Third_Party/FatFs/src/option/unicode.c: -------------------------------------------------------------------------------- 1 | #include "../ff.h" 2 | 3 | #if _USE_LFN != 0 4 | 5 | #if _CODE_PAGE == 932 /* Japanese Shift_JIS */ 6 | #include "cc932.c" 7 | #elif _CODE_PAGE == 936 /* Simplified Chinese GBK */ 8 | #include "cc936.c" 9 | #elif _CODE_PAGE == 949 /* Korean */ 10 | #include "cc949.c" 11 | #elif _CODE_PAGE == 950 /* Traditional Chinese Big5 */ 12 | #include "cc950.c" 13 | #else /* Single Byte Character-Set */ 14 | #include "ccsbcs.c" 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STM32 Bootloader 2 | Customizable Bootloader for STM32 microcontrollers. This example demonstrates how to perform in-application-programming of a firmware located on external SD card with FAT32 file system. 3 | 4 | ## Table of Contents 5 | - [Bootloader features](#bootloader-features) 6 | - [Description](#description) 7 | - [Source code organization](#source-code-organization) 8 | - [How to use](#how-to-use) 9 | - [Configuration](#configuration) 10 | - [References](#references) 11 | 12 | ## Bootloader features 13 | - Configurable application space 14 | - Flash erase 15 | - Flash programming 16 | - Flash verification after programming 17 | - Checksum verification 18 | - Flash protection check, write protection enable/disable 19 | - Extended error handling, fail-safe design 20 | - Bootloader firmware update and the ability to perform full chip re-programming: enter ST's built-in bootloader from software (without triggering the BOOT pin) 21 | - SWO tracing for easier debugging and development 22 | - Easy to customize and port to other microcontrollers 23 | 24 | ## Description 25 | This demo is implemented on a custom hardware (see Figure 1) equipped with a STM32L496VG microcontroller [[1, 2]](#references). The microSD card is connected to the MCU over SDIO interface. The implementation uses the official HAL library of ST [[4]](#references) and is compiled with IAR EWARM. Programming and debugging is performed over SWD with a SEGGER J-Link debug probe. 26 | 27 | **Note:** The bootloader currently supports the STM32L496VG and STM32L476VG microcontrollers [[1, 3]](#references) out-of-the-box. The individual build configurations for different microcontrollers can be selected with a single click in IAR. Release v1.03 introduced support for the STM32L496VG microcontroller. Earlier versions support the STM32L476VG microcontroller only. For complete list of changes, please see the [CHANGELOG](CHANGELOG.md) file. 28 | 29 | ![System overview](system-overview.png) 30 | 31 | *Figure 1: System overview* 32 | 33 | The microcontroller flash is organized as follows: by default the first 32kBytes (16 pages) of the flash is reserved for the bootloader and the rest of the flash is the application space. 34 | 35 | ![Flash organization](flash-organization.png) 36 | 37 | *Figure 2: Flash organization* 38 | 39 | After power-up, the bootloader starts. All three LEDs are flashed for a second, then the bootloader checks for user-interaction: 40 | 41 | - If the button is not pressed, then the bootloader tries to launch the application: First it checks the application space. If there is a firmware located in the application space, the bootloader calculates the checksum over the application space and compares with the application checksum (if the checksum feature is enabled). Finally, the bootloader prepares for the jump by resetting the peripherals, disabling the SysTick, setting the vector table and stack pointer, then the bootloader performs a jump to the application. 42 | 43 | - If the button is pressed and released within 4 seconds: the bootloader tries to update the application firmware by performing the following sequence: 44 | 45 | 1. Checks for write protection. If the application space is write-protected, then the red LED is switched on and the yellow LED is flashed for five seconds. If the button is pressed within this interval, the bootloader disables the write protection by re-programming the flash option bytes and performs a system reset (required after flash option bytes programming). Please note that after disabling the write protection, the user has to invoke the application update procedure again by pressing the button in order to continue the firmware update. 46 | 2. Initializes SD card, looks for application binary and opens the file. 47 | 3. Checks the file size whether it fits the application space in the microcontroller flash. 48 | 4. Initializes microcontroller flash. 49 | 5. Erases the application space. During erase, the yellow LED is on. If the user presses the button and keeps it pressed until the end of the flash erase procedure, the bootloader then interrupts the firmware update and does not perform flash programming after the erase operation. This feature is useful if the user only wants to erase the application space. 50 | 6. Performs flash programming. During flashing, the green LED is blinking. 51 | 7. Verifies flash programming by re-opening the firmware file located on the SD card and comparing the content of the file with the flash content. 52 | 8. Enables write protection of application space if this feature is enabled in the configuration. 53 | 9. After successful in-application-programming, the bootloader launches the application. 54 | 55 | - If the button is pressed for more than 4 seconds: the bootloader launches ST's built-in bootloader located in the internal boot ROM (system memory) of the chip. For more information, please refer to [[5]](#references). With this method, the bootloader can be updated or even a full chip re-programming can be performed easily, for instance by connecting the hardware to the computer via USB and using DFU mode [[6, 7]](#references). 56 | 57 | - If the button is kept pressed for more than 9 seconds: the bootloader tries to launch the application located in the flash. This scenario is fully equivalent to the case when the user does not press the button after power-up (see above). 58 | 59 | ![Bootloader sequence](bootloader-sequence.png) 60 | 61 | *Figure 3: Bootloader sequence* 62 | 63 | ## Source code organization 64 | ``` 65 | stm32-bootloader/ 66 | |—— Drivers/ 67 | |—— EWARM/ 68 | |—— Inc/ 69 | |—— Middlewares/ 70 | `—— Src/ 71 | ``` 72 | `Drivers` and `Middlewares` folders contain the CMSIS, HAL and FatFs libraries. The bootloader source code and corresponding header files can be found in `Src` and `Inc` folders respectively. 73 | 74 | ## How to use 75 | The bootloader can be easily customized and tailored to the required hardware and environment, i.e. to perform firmware updates over various interfaces or even to implement over-the-air (OTA) updates if the hardware incorporates wireless communication modules. In order to perform successful in-application-programming, the following sequence has to be kept: 76 | 1. Check for flash write protection and disable it if necessary. 77 | 2. Initialize flash with `Bootloader_Init()`. 78 | 3. Erase application space with `Bootloader_Erase()` (optional, but recommended). 79 | 4. Prepare for programming by calling `Bootloader_FlashBegin()`. 80 | 5. Perform programming by repeatedly calling the `Bootloader_FlashNext(uint64_t data)` function. The programming procedure requires 8 bytes of data (double word) to be programmed at once into the flash. This function automatically increases the address where the data is being written. 81 | 6. Finalize programming by calling `Bootloader_FlashEnd()`. 82 | 83 | The application image has to be in binary format. If the checksum verification is enabled, the binary must include the checksum value at the end of the image. When creating the application image, the checksum has to be calculated over the entire image (except the checksum area) with the following parameters: 84 | - Algorithm: CRC32 85 | - Size: 4 bytes 86 | - Initial value: 0xFFFFFFFF 87 | - Bit order: MSB first 88 | 89 | __Important notice__: in order to perform a successful application jump from the bootloader, the vector table of the application firmware should be relocated. On system reset, the vector table is fixed at address 0x00000000. When creating an application, the microcontroller startup code sets the vector table offset to 0x0000 in the `system_stm32xxxx.c` file by default. This has to be either disabled (the bootloader can be configured to perform the vector table relocation before the jump) or manually set the the vector table offset register (VTOR) to the appropriate offset value which is the start address of the application space. For more information, please refer to [[8]](#references). 90 | 91 | ## Configuration 92 | The bootloader can be widely configured in the `bootloader.h` file. The file includes detailed comments and descriptions related to the configurable parameters and definitions. 93 | 94 | ## References 95 | [1] STM32L496VG, http://www.st.com/en/microcontrollers/stm32l496vg.html 96 | 97 | [2] RM0351, “STM32L4x5 and STM32L4x6 advanced ARM®-based 32-bit MCUs Reference Manual”, http://www.st.com/resource/en/reference_manual/dm00083560.pdf 98 | 99 | [3] STM32L476VG, http://www.st.com/en/microcontrollers/stm32l476vg.html 100 | 101 | [4] UM1884, “Description of STM32L4 HAL and Low Layer drivers”, http://www.st.com/resource/en/user_manual/dm00173145.pdf 102 | 103 | [5] AN2606, "STM32 microcontroller system memory boot mode", http://www.st.com/resource/en/application_note/cd00167594.pdf 104 | 105 | [6] AN3156, "USB DFU protocol used in the STM32 bootloader", http://www.st.com/resource/en/application_note/cd00264379.pdf 106 | 107 | [7] UM0412, "Getting started with DfuSe USB device firmware upgrade", http://www.st.com/resource/en/user_manual/cd00155676.pdf 108 | 109 | [8] PM0214, "STM32F3 Series, STM32F4 Series, STM32L4 Series and STM32L4+ Series Cortex®-M4 Programming Manual", http://www.st.com/resource/en/programming_manual/dm00046982.pdf 110 | -------------------------------------------------------------------------------- /Src/bootloader.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * STM32L4 Bootloader 4 | ****************************************************************************** 5 | * @author Akos Pasztor 6 | * @file bootloader.c 7 | * @brief Bootloader implementation 8 | * This file contains the functions of the bootloader. The bootloader 9 | * implementation uses the official HAL library of ST. 10 | * @see Please refer to README for detailed information. 11 | ****************************************************************************** 12 | * Copyright (c) 2018 Akos Pasztor. https://akospasztor.com 13 | ****************************************************************************** 14 | **/ 15 | 16 | #include "stm32l4xx.h" 17 | #include "bootloader.h" 18 | 19 | /* Private typedef -----------------------------------------------------------*/ 20 | typedef void (*pFunction)(void); 21 | 22 | /* Private variables ---------------------------------------------------------*/ 23 | static uint32_t flash_ptr = APP_ADDRESS; 24 | 25 | 26 | /*** Initialize bootloader and flash ******************************************/ 27 | void Bootloader_Init(void) 28 | { 29 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 30 | __HAL_RCC_FLASH_CLK_ENABLE(); 31 | 32 | /* Clear flash flags */ 33 | HAL_FLASH_Unlock(); 34 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS); 35 | HAL_FLASH_Lock(); 36 | } 37 | 38 | /*** Erase flash **************************************************************/ 39 | uint8_t Bootloader_Erase(void) 40 | { 41 | uint32_t NbrOfPages = 0; 42 | uint32_t PageError = 0; 43 | FLASH_EraseInitTypeDef pEraseInit; 44 | HAL_StatusTypeDef status = HAL_OK; 45 | 46 | HAL_FLASH_Unlock(); 47 | 48 | /* Get the number of pages to erase */ 49 | NbrOfPages = (FLASH_BASE + FLASH_SIZE - APP_ADDRESS) / FLASH_PAGE_SIZE; 50 | 51 | if(NbrOfPages > FLASH_PAGE_NBPERBANK) 52 | { 53 | pEraseInit.Banks = FLASH_BANK_1; 54 | pEraseInit.NbPages = NbrOfPages % FLASH_PAGE_NBPERBANK; 55 | pEraseInit.Page = FLASH_PAGE_NBPERBANK - pEraseInit.NbPages; 56 | pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES; 57 | status = HAL_FLASHEx_Erase(&pEraseInit, &PageError); 58 | 59 | NbrOfPages = FLASH_PAGE_NBPERBANK; 60 | } 61 | 62 | if(status == HAL_OK) 63 | { 64 | pEraseInit.Banks = FLASH_BANK_2; 65 | pEraseInit.NbPages = NbrOfPages; 66 | pEraseInit.Page = FLASH_PAGE_NBPERBANK - pEraseInit.NbPages; 67 | pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES; 68 | status = HAL_FLASHEx_Erase(&pEraseInit, &PageError); 69 | } 70 | 71 | HAL_FLASH_Lock(); 72 | 73 | return (status == HAL_OK) ? BL_OK : BL_ERASE_ERROR; 74 | } 75 | 76 | /*** Begin flash programming **************************************************/ 77 | void Bootloader_FlashBegin(void) 78 | { 79 | /* Reset flash destination address */ 80 | flash_ptr = APP_ADDRESS; 81 | 82 | /* Unlock flash */ 83 | HAL_FLASH_Unlock(); 84 | } 85 | 86 | /*** Program 64bit data into flash ********************************************/ 87 | uint8_t Bootloader_FlashNext(uint64_t data) 88 | { 89 | if( !(flash_ptr <= (FLASH_BASE + FLASH_SIZE - 8)) || (flash_ptr < APP_ADDRESS) ) 90 | { 91 | HAL_FLASH_Lock(); 92 | return BL_WRITE_ERROR; 93 | } 94 | 95 | if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, flash_ptr, data) == HAL_OK) 96 | { 97 | /* Check the written value */ 98 | if(*(uint64_t*)flash_ptr != data) 99 | { 100 | /* Flash content doesn't match source content */ 101 | HAL_FLASH_Lock(); 102 | return BL_WRITE_ERROR; 103 | } 104 | /* Increment Flash destination address */ 105 | flash_ptr += 8; 106 | } 107 | else 108 | { 109 | /* Error occurred while writing data into Flash */ 110 | HAL_FLASH_Lock(); 111 | return BL_WRITE_ERROR; 112 | } 113 | 114 | return BL_OK; 115 | } 116 | 117 | /*** Finish flash programming *************************************************/ 118 | void Bootloader_FlashEnd(void) 119 | { 120 | /* Lock flash */ 121 | HAL_FLASH_Lock(); 122 | } 123 | 124 | /*** Get flash protection status **********************************************/ 125 | uint8_t Bootloader_GetProtectionStatus(void) 126 | { 127 | FLASH_OBProgramInitTypeDef OBStruct = {0}; 128 | uint8_t protection = BL_PROTECTION_NONE; 129 | 130 | HAL_FLASH_Unlock(); 131 | 132 | /** Bank 1 **/ 133 | OBStruct.PCROPConfig = FLASH_BANK_1; 134 | OBStruct.WRPArea = OB_WRPAREA_BANK1_AREAA; 135 | HAL_FLASHEx_OBGetConfig(&OBStruct); 136 | /* PCROP */ 137 | if(OBStruct.PCROPEndAddr > OBStruct.PCROPStartAddr) 138 | { 139 | if(OBStruct.PCROPStartAddr >= APP_ADDRESS) 140 | { 141 | protection |= BL_PROTECTION_PCROP; 142 | } 143 | } 144 | /* WRP Area_A */ 145 | if(OBStruct.WRPEndOffset > OBStruct.WRPStartOffset) 146 | { 147 | if((OBStruct.WRPStartOffset * FLASH_PAGE_SIZE + FLASH_BASE) >= APP_ADDRESS) 148 | { 149 | protection |= BL_PROTECTION_WRP; 150 | } 151 | } 152 | 153 | OBStruct.WRPArea = OB_WRPAREA_BANK1_AREAB; 154 | HAL_FLASHEx_OBGetConfig(&OBStruct); 155 | /* WRP Area_B */ 156 | if(OBStruct.WRPEndOffset > OBStruct.WRPStartOffset) 157 | { 158 | if((OBStruct.WRPStartOffset * FLASH_PAGE_SIZE + FLASH_BASE) >= APP_ADDRESS) 159 | { 160 | protection |= BL_PROTECTION_WRP; 161 | } 162 | } 163 | 164 | /** Bank 2 **/ 165 | OBStruct.PCROPConfig = FLASH_BANK_2; 166 | OBStruct.WRPArea = OB_WRPAREA_BANK2_AREAA; 167 | HAL_FLASHEx_OBGetConfig(&OBStruct); 168 | /* PCROP */ 169 | if(OBStruct.PCROPEndAddr > OBStruct.PCROPStartAddr) 170 | { 171 | if(OBStruct.PCROPStartAddr >= APP_ADDRESS) 172 | { 173 | protection |= BL_PROTECTION_PCROP; 174 | } 175 | } 176 | /* WRP Area_A */ 177 | if(OBStruct.WRPEndOffset > OBStruct.WRPStartOffset) 178 | { 179 | if((OBStruct.WRPStartOffset * FLASH_PAGE_SIZE + FLASH_BASE + FLASH_PAGE_SIZE * FLASH_PAGE_NBPERBANK) >= APP_ADDRESS) 180 | { 181 | protection |= BL_PROTECTION_WRP; 182 | } 183 | } 184 | 185 | OBStruct.WRPArea = OB_WRPAREA_BANK2_AREAB; 186 | HAL_FLASHEx_OBGetConfig(&OBStruct); 187 | /* WRP Area_B */ 188 | if(OBStruct.WRPEndOffset > OBStruct.WRPStartOffset) 189 | { 190 | if((OBStruct.WRPStartOffset * FLASH_PAGE_SIZE + FLASH_BASE + FLASH_PAGE_SIZE * FLASH_PAGE_NBPERBANK) >= APP_ADDRESS) 191 | { 192 | protection |= BL_PROTECTION_WRP; 193 | } 194 | } 195 | 196 | /** RDP **/ 197 | if(OBStruct.RDPLevel != OB_RDP_LEVEL_0) 198 | { 199 | protection |= BL_PROTECTION_RDP; 200 | } 201 | 202 | HAL_FLASH_Lock(); 203 | return protection; 204 | } 205 | 206 | /*** Configure flash write protection ***********************************************/ 207 | uint8_t Bootloader_ConfigProtection(uint32_t protection) 208 | { 209 | FLASH_OBProgramInitTypeDef OBStruct = {0}; 210 | HAL_StatusTypeDef status = HAL_ERROR; 211 | 212 | status = HAL_FLASH_Unlock(); 213 | status |= HAL_FLASH_OB_Unlock(); 214 | 215 | /* Bank 1 */ 216 | OBStruct.WRPArea = OB_WRPAREA_BANK1_AREAA; 217 | OBStruct.OptionType = OPTIONBYTE_WRP; 218 | if(protection & BL_PROTECTION_WRP) 219 | { 220 | /* Enable WRP protection for application space */ 221 | OBStruct.WRPStartOffset = (APP_ADDRESS - FLASH_BASE) / FLASH_PAGE_SIZE; 222 | OBStruct.WRPEndOffset = FLASH_PAGE_NBPERBANK - 1; 223 | } 224 | else 225 | { 226 | /* Remove WRP protection */ 227 | OBStruct.WRPStartOffset = 0xFF; 228 | OBStruct.WRPEndOffset = 0x00; 229 | } 230 | status |= HAL_FLASHEx_OBProgram(&OBStruct); 231 | 232 | /* Area B is not used */ 233 | OBStruct.WRPArea = OB_WRPAREA_BANK1_AREAB; 234 | OBStruct.OptionType = OPTIONBYTE_WRP; 235 | OBStruct.WRPStartOffset = 0xFF; 236 | OBStruct.WRPEndOffset = 0x00; 237 | status |= HAL_FLASHEx_OBProgram(&OBStruct); 238 | 239 | /* Bank 2 */ 240 | OBStruct.WRPArea = OB_WRPAREA_BANK2_AREAA; 241 | OBStruct.OptionType = OPTIONBYTE_WRP; 242 | if(protection & BL_PROTECTION_WRP) 243 | { 244 | /* Enable WRP protection for application space */ 245 | OBStruct.WRPStartOffset = 0x00; 246 | OBStruct.WRPEndOffset = FLASH_PAGE_NBPERBANK - 1; 247 | } 248 | else 249 | { 250 | /* Remove WRP protection */ 251 | OBStruct.WRPStartOffset = 0xFF; 252 | OBStruct.WRPEndOffset = 0x00; 253 | } 254 | status |= HAL_FLASHEx_OBProgram(&OBStruct); 255 | 256 | /* Area B is not used */ 257 | OBStruct.WRPArea = OB_WRPAREA_BANK2_AREAB; 258 | OBStruct.OptionType = OPTIONBYTE_WRP; 259 | OBStruct.WRPStartOffset = 0xFF; 260 | OBStruct.WRPEndOffset = 0x00; 261 | status |= HAL_FLASHEx_OBProgram(&OBStruct); 262 | 263 | if(status == HAL_OK) 264 | { 265 | /* Loading Flash Option Bytes - this generates a system reset. */ 266 | status |= HAL_FLASH_OB_Launch(); 267 | } 268 | 269 | status |= HAL_FLASH_OB_Lock(); 270 | status |= HAL_FLASH_Lock(); 271 | 272 | return (status == HAL_OK) ? BL_OK : BL_OBP_ERROR; 273 | } 274 | 275 | /*** Check if application fits into user flash ********************************/ 276 | uint8_t Bootloader_CheckSize(uint32_t appsize) 277 | { 278 | return ((FLASH_BASE + FLASH_SIZE - APP_ADDRESS) >= appsize) ? BL_OK : BL_SIZE_ERROR; 279 | } 280 | 281 | /*** Verify checksum of application located in flash **************************/ 282 | uint8_t Bootloader_VerifyChecksum(void) 283 | { 284 | #if (USE_CHECKSUM) 285 | CRC_HandleTypeDef CrcHandle; 286 | volatile uint32_t calculatedCrc = 0; 287 | 288 | __HAL_RCC_CRC_CLK_ENABLE(); 289 | CrcHandle.Instance = CRC; 290 | CrcHandle.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; 291 | CrcHandle.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; 292 | CrcHandle.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; 293 | CrcHandle.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; 294 | CrcHandle.InputDataFormat = CRC_INPUTDATA_FORMAT_WORDS; 295 | if(HAL_CRC_Init(&CrcHandle) != HAL_OK) 296 | { 297 | return BL_CHKS_ERROR; 298 | } 299 | 300 | calculatedCrc = HAL_CRC_Calculate(&CrcHandle, (uint32_t*)APP_ADDRESS, APP_SIZE); 301 | 302 | __HAL_RCC_CRC_FORCE_RESET(); 303 | __HAL_RCC_CRC_RELEASE_RESET(); 304 | 305 | if( (*(uint32_t*)CRC_ADDRESS) == calculatedCrc ) 306 | { 307 | return BL_OK; 308 | } 309 | #endif 310 | return BL_CHKS_ERROR; 311 | } 312 | 313 | /*** Check for application in user flash **************************************/ 314 | uint8_t Bootloader_CheckForApplication(void) 315 | { 316 | return ( ((*(__IO uint32_t*)APP_ADDRESS) & ~(RAM_SIZE-1)) == 0x20000000 ) ? BL_OK : BL_NO_APP; 317 | } 318 | 319 | /*** Jump to application ******************************************************/ 320 | void Bootloader_JumpToApplication(void) 321 | { 322 | uint32_t JumpAddress = *(__IO uint32_t*)(APP_ADDRESS + 4); 323 | pFunction Jump = (pFunction)JumpAddress; 324 | 325 | HAL_RCC_DeInit(); 326 | HAL_DeInit(); 327 | 328 | SysTick->CTRL = 0; 329 | SysTick->LOAD = 0; 330 | SysTick->VAL = 0; 331 | 332 | #if (SET_VECTOR_TABLE) 333 | SCB->VTOR = APP_ADDRESS; 334 | #endif 335 | 336 | __set_MSP(*(__IO uint32_t*)APP_ADDRESS); 337 | Jump(); 338 | } 339 | 340 | /*** Jump to System Memory (ST Bootloader) ************************************/ 341 | void Bootloader_JumpToSysMem(void) 342 | { 343 | uint32_t JumpAddress = *(__IO uint32_t*)(SYSMEM_ADDRESS + 4); 344 | pFunction Jump = (pFunction)JumpAddress; 345 | 346 | HAL_RCC_DeInit(); 347 | HAL_DeInit(); 348 | 349 | SysTick->CTRL = 0; 350 | SysTick->LOAD = 0; 351 | SysTick->VAL = 0; 352 | 353 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 354 | __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); 355 | 356 | __set_MSP(*(__IO uint32_t*)SYSMEM_ADDRESS); 357 | Jump(); 358 | 359 | while(1); 360 | } 361 | -------------------------------------------------------------------------------- /Src/fatfs.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * STM32L4 Bootloader 4 | ****************************************************************************** 5 | * @author Akos Pasztor 6 | * @file fatfs.c 7 | * @brief FatFS application 8 | * Code for FatFS application 9 | * 10 | * 11 | ****************************************************************************** 12 | * Copyright (c) 2018 Akos Pasztor. https://akospasztor.com 13 | ****************************************************************************** 14 | **/ 15 | 16 | #include "fatfs.h" 17 | #include "main.h" 18 | 19 | /* Variables -----------------------------------------------------------------*/ 20 | char SDPath[4]; /* SD logical drive path */ 21 | FATFS SDFatFs; /* File system object for SD logical drive */ 22 | FIL SDFile; /* File object for SD */ 23 | 24 | /* Functions -----------------------------------------------------------------*/ 25 | uint8_t FATFS_Init(void) 26 | { 27 | return FATFS_LinkDriver(&SD_Driver, SDPath); 28 | } 29 | 30 | uint8_t FATFS_DeInit(void) 31 | { 32 | return FATFS_UnLinkDriver(SDPath); 33 | } 34 | 35 | /** 36 | * @brief Gets Time from RTC 37 | * @param None 38 | * @retval Time in DWORD 39 | */ 40 | DWORD get_fattime(void) 41 | { 42 | return (DWORD)0; 43 | } 44 | -------------------------------------------------------------------------------- /Src/stm32l4xx_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * STM32L4 Bootloader 4 | ****************************************************************************** 5 | * @author Akos Pasztor 6 | * @file stm32l4xx_it.c 7 | * @brief Interrupt Service Routines 8 | * This file contains the exception and peripheral interrupt handlers. 9 | * 10 | * 11 | ****************************************************************************** 12 | * Copyright (c) 2018 Akos Pasztor. https://akospasztor.com 13 | ****************************************************************************** 14 | **/ 15 | 16 | /* Includes ------------------------------------------------------------------*/ 17 | #include "stm32l4xx_hal.h" 18 | #include "stm32l4xx_it.h" 19 | 20 | /* External variables --------------------------------------------------------*/ 21 | extern SD_HandleTypeDef hsd1; 22 | 23 | /******************************************************************************/ 24 | /* Cortex-M4 Processor Interruption and Exception Handlers */ 25 | /******************************************************************************/ 26 | 27 | /** 28 | * @brief This function handles Non maskable interrupt. 29 | */ 30 | void NMI_Handler(void) 31 | { 32 | 33 | } 34 | 35 | /** 36 | * @brief This function handles Hard fault interrupt. 37 | */ 38 | void HardFault_Handler(void) 39 | { 40 | while(1) 41 | { 42 | } 43 | } 44 | 45 | /** 46 | * @brief This function handles Memory management fault. 47 | */ 48 | void MemManage_Handler(void) 49 | { 50 | while(1) 51 | { 52 | } 53 | } 54 | 55 | /** 56 | * @brief This function handles Prefetch fault, memory access fault. 57 | */ 58 | void BusFault_Handler(void) 59 | { 60 | while(1) 61 | { 62 | } 63 | } 64 | 65 | /** 66 | * @brief This function handles Undefined instruction or illegal state. 67 | */ 68 | void UsageFault_Handler(void) 69 | { 70 | while(1) 71 | { 72 | } 73 | } 74 | 75 | /** 76 | * @brief This function handles System service call via SWI instruction. 77 | */ 78 | void SVC_Handler(void) 79 | { 80 | 81 | } 82 | 83 | /** 84 | * @brief This function handles Debug monitor. 85 | */ 86 | void DebugMon_Handler(void) 87 | { 88 | 89 | } 90 | 91 | /** 92 | * @brief This function handles Pendable request for system service. 93 | */ 94 | void PendSV_Handler(void) 95 | { 96 | 97 | } 98 | 99 | /** 100 | * @brief This function handles System tick timer. 101 | */ 102 | void SysTick_Handler(void) 103 | { 104 | HAL_IncTick(); 105 | HAL_SYSTICK_IRQHandler(); 106 | } 107 | 108 | /******************************************************************************/ 109 | /* STM32L4xx Peripheral Interrupt Handlers */ 110 | /******************************************************************************/ 111 | 112 | /** 113 | * @brief DMA2 Channel5 ISR 114 | * @note SDMMC DMA Tx, Rx 115 | */ 116 | void DMA2_Channel5_IRQHandler(void) 117 | { 118 | if((hsd1.Context == (SD_CONTEXT_DMA | SD_CONTEXT_READ_SINGLE_BLOCK)) || 119 | (hsd1.Context == (SD_CONTEXT_DMA | SD_CONTEXT_READ_MULTIPLE_BLOCK))) 120 | { 121 | HAL_DMA_IRQHandler(hsd1.hdmarx); 122 | } 123 | else if((hsd1.Context == (SD_CONTEXT_DMA | SD_CONTEXT_WRITE_SINGLE_BLOCK)) || 124 | (hsd1.Context == (SD_CONTEXT_DMA | SD_CONTEXT_WRITE_MULTIPLE_BLOCK))) 125 | { 126 | HAL_DMA_IRQHandler(hsd1.hdmatx); 127 | } 128 | } 129 | 130 | /** 131 | * @brief SDMMC ISR 132 | */ 133 | void SDMMC1_IRQHandler(void) 134 | { 135 | HAL_SD_IRQHandler(&hsd1); 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /bootloader-sequence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dy011/stm32-bootloader/d5c4adc14ea200b0b608fb07e04adc2554dcdfe9/bootloader-sequence.png -------------------------------------------------------------------------------- /flash-organization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dy011/stm32-bootloader/d5c4adc14ea200b0b608fb07e04adc2554dcdfe9/flash-organization.png -------------------------------------------------------------------------------- /system-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dy011/stm32-bootloader/d5c4adc14ea200b0b608fb07e04adc2554dcdfe9/system-overview.png --------------------------------------------------------------------------------