├── BME280 └── I2C │ ├── BME280_STM32.c │ ├── BME280_STM32.h │ ├── README.md │ ├── TUT_BME280_F103.ioc │ └── main.c ├── EEPROM_STM32 ├── EEPROM.c ├── EEPROM.h ├── README.md └── main.c ├── F103_RegisterBased └── ADC with DMA │ ├── Delay_F103.c │ ├── Delay_F103.h │ ├── README.md │ └── main.c ├── FLASH_PROGRAM ├── F1 SERIES │ ├── FLASH_PAGE_F1.h │ ├── FlASH_PAGE_F1.c │ ├── README.md │ └── main.c ├── F4 SERIES │ ├── FLASH_SECTOR_F4.c │ ├── FLASH_SECTOR_F4.h │ ├── README.md │ └── main.c └── H7 SERIES │ ├── FLASH_SECTOR_H7.c │ ├── FLASH_SECTOR_H7.h │ ├── README.md │ └── main.c ├── INPUT CAPTURE DMA └── F446 │ ├── PWM_IN_OUT_F446.ioc │ ├── README.md │ └── main.c ├── LCD1602_I2C_NOHAL ├── Delay.c ├── Delay.h ├── I2C.c ├── I2C.h ├── README.md ├── RccConfig.c ├── RccConfig.h ├── i2c-lcd.c ├── i2c-lcd.h └── main.c ├── LVGL └── Simple_F446 │ ├── Core │ ├── Inc │ │ ├── lcd_lvgl.h │ │ ├── main.h │ │ ├── stm32f4xx_hal_conf.h │ │ ├── stm32f4xx_it.h │ │ ├── tft.h │ │ └── user_setting.h │ ├── Src │ │ ├── lcd_lvgl.c │ │ ├── main.c │ │ ├── stm32f4xx_hal_msp.c │ │ ├── stm32f4xx_it.c │ │ ├── syscalls.c │ │ ├── sysmem.c │ │ ├── system_stm32f4xx.c │ │ └── tft.c │ └── Startup │ │ └── startup_stm32f446retx.s │ ├── Drivers │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32F4xx │ │ │ │ ├── Include │ │ │ │ ├── stm32f446xx.h │ │ │ │ ├── stm32f4xx.h │ │ │ │ └── system_stm32f4xx.h │ │ │ │ └── License.md │ │ ├── Include │ │ │ ├── cmsis_armcc.h │ │ │ ├── cmsis_armclang.h │ │ │ ├── cmsis_compiler.h │ │ │ ├── cmsis_gcc.h │ │ │ ├── cmsis_iccarm.h │ │ │ ├── cmsis_version.h │ │ │ ├── core_armv8mbl.h │ │ │ ├── core_armv8mml.h │ │ │ ├── core_cm0.h │ │ │ ├── core_cm0plus.h │ │ │ ├── core_cm1.h │ │ │ ├── core_cm23.h │ │ │ ├── core_cm3.h │ │ │ ├── core_cm33.h │ │ │ ├── core_cm4.h │ │ │ ├── core_cm7.h │ │ │ ├── core_sc000.h │ │ │ ├── core_sc300.h │ │ │ ├── mpu_armv7.h │ │ │ ├── mpu_armv8.h │ │ │ └── tz_context.h │ │ └── LICENSE.txt │ └── STM32F4xx_HAL_Driver │ │ ├── Inc │ │ ├── Legacy │ │ │ └── stm32_hal_legacy.h │ │ ├── stm32f4xx_hal.h │ │ ├── stm32f4xx_hal_cortex.h │ │ ├── stm32f4xx_hal_def.h │ │ ├── stm32f4xx_hal_dma.h │ │ ├── stm32f4xx_hal_dma_ex.h │ │ ├── stm32f4xx_hal_exti.h │ │ ├── stm32f4xx_hal_flash.h │ │ ├── stm32f4xx_hal_flash_ex.h │ │ ├── stm32f4xx_hal_flash_ramfunc.h │ │ ├── stm32f4xx_hal_gpio.h │ │ ├── stm32f4xx_hal_gpio_ex.h │ │ ├── stm32f4xx_hal_pwr.h │ │ ├── stm32f4xx_hal_pwr_ex.h │ │ ├── stm32f4xx_hal_rcc.h │ │ ├── stm32f4xx_hal_rcc_ex.h │ │ ├── stm32f4xx_hal_tim.h │ │ └── stm32f4xx_hal_tim_ex.h │ │ ├── License.md │ │ └── Src │ │ ├── stm32f4xx_hal.c │ │ ├── stm32f4xx_hal_cortex.c │ │ ├── stm32f4xx_hal_dma.c │ │ ├── stm32f4xx_hal_dma_ex.c │ │ ├── stm32f4xx_hal_exti.c │ │ ├── stm32f4xx_hal_flash.c │ │ ├── stm32f4xx_hal_flash_ex.c │ │ ├── stm32f4xx_hal_flash_ramfunc.c │ │ ├── stm32f4xx_hal_gpio.c │ │ ├── stm32f4xx_hal_pwr.c │ │ ├── stm32f4xx_hal_pwr_ex.c │ │ ├── stm32f4xx_hal_rcc.c │ │ ├── stm32f4xx_hal_rcc_ex.c │ │ ├── stm32f4xx_hal_tim.c │ │ └── stm32f4xx_hal_tim_ex.c │ ├── README.md │ ├── STM32F446RETX_FLASH.ld │ ├── STM32F446RETX_RAM.ld │ ├── TUT_LVGL_F446 Debug.launch │ ├── TUT_LVGL_F446.ioc │ └── lv_conf.h ├── QSPI ├── MT25TLxxx │ ├── EXT_MEM_BOOT │ │ ├── QSPI_XIP_H745.ioc │ │ ├── README.md │ │ ├── STM32H745XIHX_FLASH.ld │ │ ├── main.c │ │ └── system_stm32h7xx_dualcore_boot_cm4_cm7.c │ ├── README.md │ ├── main.c │ ├── mt25tl01g.c │ ├── mt25tl01g.h │ ├── quadspi.c │ └── quadspi.h └── N25Qxxx │ ├── EXT_MEM_BOOT │ ├── QSPI_XIP__N25Q_F750.ioc │ ├── README.md │ ├── STM32F750N8HX_FLASH.ld │ ├── main.c │ └── system_stm32f7xx.c │ ├── README.md │ ├── main.c │ ├── n25q128a.h │ ├── quadspi.c │ └── quadspi.h ├── README.md ├── TIMER ENCODER MODE ├── README.md ├── TUT_ENCODER_TIMER.ioc ├── main.c └── stm32f1xx_it.c ├── TOUCH GFX └── ILI9341 SPI │ ├── README.md │ ├── STM32TouchController.cpp │ ├── TouchGFX_DataTransfer.c │ ├── TouchGFX_DataTransfer.h │ ├── ili9341.c │ ├── ili9341.h │ ├── main.c │ ├── xpt2046.c │ └── xpt2046.h └── UART CIRCULAR BUFFER ├── README.md ├── UART_F4_Multi_Test.ioc ├── main.c ├── stm32f4xx_it.c ├── uartRingBufDMA.c └── uartRingBufDMA.h /BME280/I2C/BME280_STM32.h: -------------------------------------------------------------------------------- 1 | /* 2 | *************************************************************************************************************** 3 | *************************************************************************************************************** 4 | *************************************************************************************************************** 5 | 6 | File: BME280_STM32.h 7 | Author: ControllersTech.com 8 | Updated: Dec 14, 2021 9 | 10 | *************************************************************************************************************** 11 | Copyright (C) 2017 ControllersTech.com 12 | 13 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 14 | of the GNU General Public License version 3 as published by the Free Software Foundation. 15 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 16 | or indirectly by this software, read more about this on the GNU General Public License. 17 | 18 | *************************************************************************************************************** 19 | */ 20 | 21 | 22 | #ifndef INC_BME280_STM32_H_ 23 | #define INC_BME280_STM32_H_ 24 | 25 | #include "stm32f1xx_hal.h" 26 | 27 | /* Configuration for the BME280 28 | 29 | * @osrs is the oversampling to improve the accuracy 30 | * if osrs is set to OSRS_OFF, the respective measurement will be skipped 31 | * It can be set to OSRS_1, OSRS_2, OSRS_4, etc. Check the header file 32 | * 33 | * @mode can be used to set the mode for the device 34 | * MODE_SLEEP will put the device in sleep 35 | * MODE_FORCED device goes back to sleep after one measurement. You need to use the BME280_WakeUP() function before every measurement 36 | * MODE_NORMAL device performs measurement in the normal mode. Check datasheet page no 16 37 | * 38 | * @t_sb is the standby time. The time sensor waits before performing another measurement 39 | * It is used along with the normal mode. Check datasheet page no 16 and page no 30 40 | * 41 | * @filter is the IIR filter coefficients 42 | * IIR is used to avoid the short term fluctuations 43 | * Check datasheet page no 18 and page no 30 44 | */ 45 | 46 | int BME280_Config (uint8_t osrs_t, uint8_t osrs_p, uint8_t osrs_h, uint8_t mode, uint8_t t_sb, uint8_t filter); 47 | 48 | 49 | // Read the Trimming parameters saved in the NVM ROM of the device 50 | void TrimRead(void); 51 | 52 | /* To be used when doing the force measurement 53 | * the Device need to be put in forced mode every time the measurement is needed 54 | */ 55 | void BME280_WakeUP(void); 56 | 57 | /* measure the temp, pressure and humidity 58 | * the values will be stored in the parameters passed to the function 59 | */ 60 | void BME280_Measure (void); 61 | 62 | 63 | // Oversampling definitions 64 | #define OSRS_OFF 0x00 65 | #define OSRS_1 0x01 66 | #define OSRS_2 0x02 67 | #define OSRS_4 0x03 68 | #define OSRS_8 0x04 69 | #define OSRS_16 0x05 70 | 71 | // MODE Definitions 72 | #define MODE_SLEEP 0x00 73 | #define MODE_FORCED 0x01 74 | #define MODE_NORMAL 0x03 75 | 76 | // Standby Time 77 | #define T_SB_0p5 0x00 78 | #define T_SB_62p5 0x01 79 | #define T_SB_125 0x02 80 | #define T_SB_250 0x03 81 | #define T_SB_500 0x04 82 | #define T_SB_1000 0x05 83 | #define T_SB_10 0x06 84 | #define T_SB_20 0x07 85 | 86 | // IIR Filter Coefficients 87 | #define IIR_OFF 0x00 88 | #define IIR_2 0x01 89 | #define IIR_4 0x02 90 | #define IIR_8 0x03 91 | #define IIR_16 0x04 92 | 93 | 94 | // REGISTERS DEFINITIONS 95 | #define ID_REG 0xD0 96 | #define RESET_REG 0xE0 97 | #define CTRL_HUM_REG 0xF2 98 | #define STATUS_REG 0xF3 99 | #define CTRL_MEAS_REG 0xF4 100 | #define CONFIG_REG 0xF5 101 | #define PRESS_MSB_REG 0xF7 102 | 103 | 104 | #endif /* INC_BME280_STM32_H_ */ 105 | -------------------------------------------------------------------------------- /BME280/I2C/README.md: -------------------------------------------------------------------------------- 1 | # Interface BME280 with STM32 using I2C 2 | 3 | 1. Define the I2C instance in ```BME280_STM32.c``` File 4 | 2. Define the ```64 Bit / 32 Bit Support ``` 5 | 6 | To watch the implementation, or How I manage to write the library using the datasheet, check out the video https://youtu.be/jDhkfe2YG_o 7 | 8 | To download the full project for Bluepill, goto https://controllerstech.com/bme280-with-stm32/ 9 | -------------------------------------------------------------------------------- /BME280/I2C/TUT_BME280_F103.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | File.Version=6 3 | KeepUserPlacement=false 4 | Mcu.Family=STM32F1 5 | Mcu.IP0=I2C1 6 | Mcu.IP1=NVIC 7 | Mcu.IP2=RCC 8 | Mcu.IP3=SYS 9 | Mcu.IPNb=4 10 | Mcu.Name=STM32F103C(8-B)Tx 11 | Mcu.Package=LQFP48 12 | Mcu.Pin0=PD0-OSC_IN 13 | Mcu.Pin1=PD1-OSC_OUT 14 | Mcu.Pin2=PA13 15 | Mcu.Pin3=PA14 16 | Mcu.Pin4=PB6 17 | Mcu.Pin5=PB7 18 | Mcu.Pin6=VP_SYS_VS_Systick 19 | Mcu.PinsNb=7 20 | Mcu.ThirdPartyNb=0 21 | Mcu.UserConstants= 22 | Mcu.UserName=STM32F103C8Tx 23 | MxCube.Version=6.4.0 24 | MxDb.Version=DB.6.0.40 25 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 26 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false 27 | NVIC.ForceEnableDMAVector=true 28 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 29 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false 30 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 31 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false 32 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 33 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false 34 | NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true 35 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 36 | PA13.Mode=Serial_Wire 37 | PA13.Signal=SYS_JTMS-SWDIO 38 | PA14.Mode=Serial_Wire 39 | PA14.Signal=SYS_JTCK-SWCLK 40 | PB6.Mode=I2C 41 | PB6.Signal=I2C1_SCL 42 | PB7.Mode=I2C 43 | PB7.Signal=I2C1_SDA 44 | PD0-OSC_IN.Mode=HSE-External-Oscillator 45 | PD0-OSC_IN.Signal=RCC_OSC_IN 46 | PD1-OSC_OUT.Mode=HSE-External-Oscillator 47 | PD1-OSC_OUT.Signal=RCC_OSC_OUT 48 | PinOutPanel.RotationAngle=0 49 | ProjectManager.AskForMigrate=true 50 | ProjectManager.BackupPrevious=false 51 | ProjectManager.CompilerOptimize=6 52 | ProjectManager.ComputerToolchain=false 53 | ProjectManager.CoupleFile=false 54 | ProjectManager.CustomerFirmwarePackage= 55 | ProjectManager.DefaultFWLocation=true 56 | ProjectManager.DeletePrevious=true 57 | ProjectManager.DeviceId=STM32F103C8Tx 58 | ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.4 59 | ProjectManager.FreePins=false 60 | ProjectManager.HalAssertFull=false 61 | ProjectManager.HeapSize=0x200 62 | ProjectManager.KeepUserCode=true 63 | ProjectManager.LastFirmware=true 64 | ProjectManager.LibraryCopy=1 65 | ProjectManager.MainLocation=Core/Src 66 | ProjectManager.NoMain=false 67 | ProjectManager.PreviousToolchain= 68 | ProjectManager.ProjectBuild=false 69 | ProjectManager.ProjectFileName=TUT_BME280_F103.ioc 70 | ProjectManager.ProjectName=TUT_BME280_F103 71 | ProjectManager.RegisterCallBack= 72 | ProjectManager.StackSize=0x400 73 | ProjectManager.TargetToolchain=STM32CubeIDE 74 | ProjectManager.ToolChainLocation= 75 | ProjectManager.UnderRoot=true 76 | ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false 77 | RCC.ADCFreqValue=36000000 78 | RCC.AHBFreq_Value=72000000 79 | RCC.APB1CLKDivider=RCC_HCLK_DIV2 80 | RCC.APB1Freq_Value=36000000 81 | RCC.APB1TimFreq_Value=72000000 82 | RCC.APB2Freq_Value=72000000 83 | RCC.APB2TimFreq_Value=72000000 84 | RCC.FCLKCortexFreq_Value=72000000 85 | RCC.FamilyName=M 86 | RCC.HCLKFreq_Value=72000000 87 | RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value 88 | RCC.MCOFreq_Value=72000000 89 | RCC.PLLCLKFreq_Value=72000000 90 | RCC.PLLMCOFreq_Value=36000000 91 | RCC.PLLMUL=RCC_PLL_MUL9 92 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 93 | RCC.SYSCLKFreq_VALUE=72000000 94 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 95 | RCC.TimSysFreq_Value=72000000 96 | RCC.USBFreq_Value=72000000 97 | RCC.VCOOutput2Freq_Value=8000000 98 | VP_SYS_VS_Systick.Mode=SysTick 99 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 100 | board=custom 101 | isbadioc=false 102 | -------------------------------------------------------------------------------- /BME280/I2C/main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "main.h" 21 | 22 | /* Private includes ----------------------------------------------------------*/ 23 | /* USER CODE BEGIN Includes */ 24 | #include "BME280_STM32.h" 25 | /* USER CODE END Includes */ 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* USER CODE BEGIN PTD */ 29 | 30 | /* USER CODE END PTD */ 31 | 32 | /* Private define ------------------------------------------------------------*/ 33 | /* USER CODE BEGIN PD */ 34 | /* USER CODE END PD */ 35 | 36 | /* Private macro -------------------------------------------------------------*/ 37 | /* USER CODE BEGIN PM */ 38 | 39 | /* USER CODE END PM */ 40 | 41 | /* Private variables ---------------------------------------------------------*/ 42 | I2C_HandleTypeDef hi2c1; 43 | 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | void SystemClock_Config(void); 50 | static void MX_GPIO_Init(void); 51 | static void MX_I2C1_Init(void); 52 | /* USER CODE BEGIN PFP */ 53 | 54 | /* USER CODE END PFP */ 55 | 56 | /* Private user code ---------------------------------------------------------*/ 57 | /* USER CODE BEGIN 0 */ 58 | 59 | float Temperature, Pressure, Humidity; 60 | 61 | /* USER CODE END 0 */ 62 | 63 | /** 64 | * @brief The application entry point. 65 | * @retval int 66 | */ 67 | int main(void) 68 | { 69 | /* USER CODE BEGIN 1 */ 70 | 71 | /* USER CODE END 1 */ 72 | 73 | /* MCU Configuration--------------------------------------------------------*/ 74 | 75 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 76 | HAL_Init(); 77 | 78 | /* USER CODE BEGIN Init */ 79 | 80 | /* USER CODE END Init */ 81 | 82 | /* Configure the system clock */ 83 | SystemClock_Config(); 84 | 85 | /* USER CODE BEGIN SysInit */ 86 | 87 | /* USER CODE END SysInit */ 88 | 89 | /* Initialize all configured peripherals */ 90 | MX_GPIO_Init(); 91 | MX_I2C1_Init(); 92 | /* USER CODE BEGIN 2 */ 93 | 94 | BME280_Config(OSRS_2, OSRS_16, OSRS_1, MODE_NORMAL, T_SB_0p5, IIR_16); 95 | 96 | /* USER CODE END 2 */ 97 | 98 | /* Infinite loop */ 99 | /* USER CODE BEGIN WHILE */ 100 | while (1) 101 | { 102 | /* USER CODE END WHILE */ 103 | 104 | /* USER CODE BEGIN 3 */ 105 | BME280_Measure(); 106 | HAL_Delay (500); 107 | } 108 | /* USER CODE END 3 */ 109 | } 110 | 111 | /** 112 | * @brief System Clock Configuration 113 | * @retval None 114 | */ 115 | void SystemClock_Config(void) 116 | { 117 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 118 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 119 | 120 | /** Initializes the RCC Oscillators according to the specified parameters 121 | * in the RCC_OscInitTypeDef structure. 122 | */ 123 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 124 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 125 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; 126 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 127 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 128 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 129 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; 130 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 131 | { 132 | Error_Handler(); 133 | } 134 | /** Initializes the CPU, AHB and APB buses clocks 135 | */ 136 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 137 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 138 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 139 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 140 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 141 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 142 | 143 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) 144 | { 145 | Error_Handler(); 146 | } 147 | } 148 | 149 | /** 150 | * @brief I2C1 Initialization Function 151 | * @param None 152 | * @retval None 153 | */ 154 | static void MX_I2C1_Init(void) 155 | { 156 | 157 | /* USER CODE BEGIN I2C1_Init 0 */ 158 | 159 | /* USER CODE END I2C1_Init 0 */ 160 | 161 | /* USER CODE BEGIN I2C1_Init 1 */ 162 | 163 | /* USER CODE END I2C1_Init 1 */ 164 | hi2c1.Instance = I2C1; 165 | hi2c1.Init.ClockSpeed = 100000; 166 | hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; 167 | hi2c1.Init.OwnAddress1 = 0; 168 | hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; 169 | hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; 170 | hi2c1.Init.OwnAddress2 = 0; 171 | hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; 172 | hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; 173 | if (HAL_I2C_Init(&hi2c1) != HAL_OK) 174 | { 175 | Error_Handler(); 176 | } 177 | /* USER CODE BEGIN I2C1_Init 2 */ 178 | 179 | /* USER CODE END I2C1_Init 2 */ 180 | 181 | } 182 | 183 | /** 184 | * @brief GPIO Initialization Function 185 | * @param None 186 | * @retval None 187 | */ 188 | static void MX_GPIO_Init(void) 189 | { 190 | 191 | /* GPIO Ports Clock Enable */ 192 | __HAL_RCC_GPIOD_CLK_ENABLE(); 193 | __HAL_RCC_GPIOA_CLK_ENABLE(); 194 | __HAL_RCC_GPIOB_CLK_ENABLE(); 195 | 196 | } 197 | 198 | /* USER CODE BEGIN 4 */ 199 | 200 | /* USER CODE END 4 */ 201 | 202 | /** 203 | * @brief This function is executed in case of error occurrence. 204 | * @retval None 205 | */ 206 | void Error_Handler(void) 207 | { 208 | /* USER CODE BEGIN Error_Handler_Debug */ 209 | /* User can add his own implementation to report the HAL error return state */ 210 | __disable_irq(); 211 | while (1) 212 | { 213 | } 214 | /* USER CODE END Error_Handler_Debug */ 215 | } 216 | 217 | #ifdef USE_FULL_ASSERT 218 | /** 219 | * @brief Reports the name of the source file and the source line number 220 | * where the assert_param error has occurred. 221 | * @param file: pointer to the source file name 222 | * @param line: assert_param error line source number 223 | * @retval None 224 | */ 225 | void assert_failed(uint8_t *file, uint32_t line) 226 | { 227 | /* USER CODE BEGIN 6 */ 228 | /* User can add his own implementation to report the file name and line number, 229 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 230 | /* USER CODE END 6 */ 231 | } 232 | #endif /* USE_FULL_ASSERT */ 233 | 234 | -------------------------------------------------------------------------------- /EEPROM_STM32/EEPROM.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | ****************************************************************************** 4 | 5 | EEPROM.c Using the HAL I2C Functions 6 | Author: ControllersTech 7 | Updated: Feb 16, 2021 8 | 9 | ****************************************************************************** 10 | Copyright (C) 2017 ControllersTech.com 11 | 12 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 13 | of the GNU General Public License version 3 as published by the Free Software Foundation. 14 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 15 | or indirectly by this software, read more about this on the GNU General Public License. 16 | 17 | ****************************************************************************** 18 | */ 19 | 20 | #include "EEPROM.h" 21 | #include "math.h" 22 | #include "string.h" 23 | 24 | // Define the I2C 25 | extern I2C_HandleTypeDef hi2c1; 26 | #define EEPROM_I2C &hi2c1 27 | 28 | // EEPROM ADDRESS (8bits) 29 | #define EEPROM_ADDR 0xA0 30 | 31 | // Define the Page Size and number of pages 32 | #define PAGE_SIZE 64 // in Bytes 33 | #define PAGE_NUM 512 // number of pages 34 | 35 | 36 | 37 | /*****************************************************************************************************************************************/ 38 | uint8_t bytes_temp[4]; 39 | 40 | // function to determine the remaining bytes 41 | uint16_t bytestowrite (uint16_t size, uint16_t offset) 42 | { 43 | if ((size+offset)APB1ENR |= (1<<0); // enable clock for TIM2 32 | /* 33 | TIM2->CR1 = 0; // reset all 34 | TIM2->CR1 |= (0<<1); // UDIS=0; UEV Enabled. The Update event will generate 35 | TIM2->CR1 |= (0<<4); // DIR=1; select UP COUNTER mode 36 | TIM2->CR1 |= (0<<5); // CMS=0; Edge-aligned mode, up or down count depends on DIR 37 | TIM2->CR1 |= (0<<8); // CKD=0; No clock DIVISION 38 | TIM2->CR1 |= (0<<7); // ARPE=0; ARR Auto Reload Disabled 39 | TIM2->RCR |= 0; // Repetition Counter 0 40 | */ 41 | TIM2->ARR = 0xffff-1; // ARR value 42 | TIM2->PSC = 72-1; // Prescalar value 43 | 44 | TIM2->CR1 |= (1<<0); // enable timer 45 | while (!(TIM2->SR & (1<<0))); // UIF: Update interrupt flag.. This bit is set by hardware when the registers are updated 46 | } 47 | 48 | void Delay_us (uint16_t us) 49 | { 50 | /************** STEPS TO FOLLOW ***************** 51 | 1. RESET the Counter 52 | 2. Wait for the Counter to reach the entered value. As each count will take 1 us, 53 | the total waiting time will be the required us delay 54 | ************************************************/ 55 | TIM2->CNT = 0; 56 | while (TIM2->CNT < us); 57 | } 58 | 59 | void Delay_ms (uint16_t ms) 60 | { 61 | for (uint16_t i=0; iAPB2ENR |= 1<<9; // enable ADC1 clock 22 | RCC->APB2ENR |= (1<<2); // enable GPIOA clock 23 | 24 | //2. Set the prescalar in the Clock configuration register (RCC_CFGR) 25 | RCC->CFGR |= (2<<14); // Prescaler 6, ADC Clock = 72/6 = 12 MHz 26 | 27 | //3. Set the Scan Mode and Resolution in the Control Register 1 (CR1) 28 | ADC1->CR1 = (1<<8); // SCAN mode enabled 29 | // Resolution is 12 bit in F103 30 | 31 | //4. Set the Continuous Conversion, EOC, and Data Alignment in Control Reg 2 (CR2) 32 | ADC1->CR2 = (1<<1); // enable continuous conversion mode 33 | // EOC after each conversion by default 34 | ADC1->CR2 |= (7<<17); // External Event selection pointed to SWSTART bit 35 | ADC1->CR2 &= ~(1<<11); // Data Alignment RIGHT 36 | 37 | //5. Set the Sampling Time for the channels 38 | ADC1->SMPR2 &= ~((7<<3) | (7<<12)); // Sampling time of 1.5 cycles for channel 1 and channel 4 39 | 40 | //6. Set the Regular channel sequence length in ADC_SQR1 41 | ADC1->SQR1 |= (2<<20); // SQR1_L =2 for 3 conversions 42 | 43 | //7. Set the Respective GPIO PINs in the Analog Mode 44 | GPIOA->CRL &= ~(0xf<<4); // analog mode for PA 1 45 | GPIOA->CRL &= ~(0xf<<16); // analog mode for PA 4 46 | 47 | 48 | /**************************************************************************************************/ 49 | 50 | 51 | // Sampling Freq for Temp Sensor 52 | ADC1->SMPR1 |= (7<<18); // Sampling time (71.5 cycles) of 7 us for channel 16.. It should be <17.1 us 53 | 54 | // Set the TSVREFE Bit to wake the sensor 55 | ADC1->CR2 |= (1<<23); 56 | 57 | // Enable DMA for ADC 58 | ADC1->CR2 |= (1<<8); 59 | 60 | // // Enable Continuous Request 61 | // ADC1->CR2 |= (1<<9); 62 | 63 | // Channel Sequence 64 | ADC1->SQR3 |= (1<<0); // SEQ1 for Channel 1 65 | ADC1->SQR3 |= (4<<5); // SEQ2 for CHannel 4 66 | ADC1->SQR3 |= (16<<10); // SEQ3 for CHannel 16 67 | } 68 | 69 | 70 | void ADC_Enable (void) 71 | { 72 | /************** STEPS TO FOLLOW ***************** 73 | 1. Enable the ADC by setting ADON bit in CR2 74 | 2. Wait for ADC to stabilize (approx 10us) 75 | ************************************************/ 76 | ADC1->CR2 |= 1<<0; // ADON =1 enable ADC1 77 | 78 | uint32_t delay = 10000; 79 | while (delay--); 80 | } 81 | 82 | void ADC_Start(void) 83 | { 84 | /************** STEPS TO FOLLOW ***************** 85 | 1. Clear the Status register 86 | 2. Start the Conversion by Setting the SWSTART bit in CR2 87 | *************************************************/ 88 | ADC1->SR = 0; // Clear Status register 89 | ADC1->CR2 |= (1<<20); // Conversion on external event enabled 90 | ADC1->CR2 |= 1<<22; // Start conversion 91 | } 92 | 93 | void DMA_Init (void) 94 | { 95 | /************** STEPS TO FOLLOW ***************** 96 | 1. Enable DMA clock 97 | 2. Set the DATA Direction 98 | 3. Enable/Disable the Circular Mode 99 | 4. Enable/Disable the Memory Increment and Peripheral Increment 100 | 5. Set the Data Size 101 | 6. Select the channel for the Stream 102 | ************************************************/ 103 | 104 | // 1. Enable DMA1 Clock 105 | RCC->AHBENR |= 1<<0; 106 | 107 | // 2. Set the Data Direction 108 | // DMA1_Channel7->CCR |= (1<<4); // Read From Memory 109 | DMA1_Channel1->CCR &= ~(1<<4); // Read From Peripheral 110 | 111 | // 2. Enable the circular mode (CIRC) 112 | DMA1_Channel1->CCR |= 1<<5; 113 | 114 | // 3. Enable the Memory Increment (MINC) 115 | DMA1_Channel1->CCR |= 1<<7; 116 | 117 | // 4. Set the Peripheral data size (PSIZE) 118 | DMA1_Channel1->CCR |= (1<<8); // 01 : 8 Bit Data 119 | 120 | // 5. Set the Memory data size (MSIZE) 121 | DMA1_Channel1->CCR |= (1<<10); // 01 : 8 Bit Data 122 | } 123 | 124 | 125 | void DMA_Config (uint32_t srcAdd, uint32_t destAdd, uint16_t size) 126 | { 127 | 128 | /************** STEPS TO FOLLOW ***************** 129 | 1. Set the Data Size in the CNDTR Register 130 | 2. Set the Peripheral Address and the Memory Address 131 | 3. Enable the DMA Stream 132 | 133 | Some peripherals don't need a start condition, like UART, So as soon as you enable the DMA, the transfer will begin 134 | While Peripherals like ADC needs the Start condition, so Start the ADC later in the program, to enable the transfer 135 | ************************************************/ 136 | 137 | DMA1_Channel1->CNDTR = size; // Set the size of the transfer 138 | 139 | DMA1_Channel1->CPAR = srcAdd; // Source address is peripheral address 140 | 141 | DMA1_Channel1->CMAR = destAdd; // Destination Address is memory address 142 | 143 | // Enable the DMA Stream 144 | DMA1_Channel1->CCR |= (1<<0); // EN =1 145 | } 146 | 147 | 148 | uint16_t RxData[3]; 149 | float Temperature; 150 | 151 | int main(void) 152 | { 153 | SystemInit(); 154 | TIM2_Config(); 155 | 156 | ADC_Init (); 157 | ADC_Enable (); 158 | DMA_Init (); 159 | 160 | DMA_Config ((uint32_t ) &ADC1->DR, (uint32_t) RxData, 3); 161 | 162 | ADC_Start (); 163 | 164 | while (1) 165 | { 166 | 167 | Temperature = ((1.43 - ((float)(3.3*RxData[2]/(float)4095))) / 0.0043) + 25; 168 | 169 | Delay_ms (1000); 170 | } 171 | 172 | } 173 | -------------------------------------------------------------------------------- /FLASH_PROGRAM/F1 SERIES/FLASH_PAGE_F1.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | *************************************************************************************************************** 4 | *************************************************************************************************************** 5 | *************************************************************************************************************** 6 | File: FLASH_PAGE_F1.h 7 | Modifier: ControllersTech.com 8 | Updated: 27th MAY 2021 9 | *************************************************************************************************************** 10 | Copyright (C) 2017 ControllersTech.com 11 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 12 | of the GNU General Public License version 3 as published by the Free Software Foundation. 13 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 14 | or indirectly by this software, read more about this on the GNU General Public License. 15 | *************************************************************************************************************** 16 | */ 17 | 18 | #ifndef INC_FLASH_PAGE_F1_H_ 19 | #define INC_FLASH_PAGE_F1_H_ 20 | 21 | #include "stm32f1xx_hal.h" 22 | 23 | 24 | uint32_t Flash_Write_Data (uint32_t StartPageAddress, uint32_t *Data, uint16_t numberofwords); 25 | 26 | void Flash_Read_Data (uint32_t StartPageAddress, uint32_t *RxBuf, uint16_t numberofwords); 27 | 28 | void Convert_To_Str (uint32_t *Data, char *Buf); 29 | 30 | void Flash_Write_NUM (uint32_t StartSectorAddress, float Num); 31 | 32 | float Flash_Read_NUM (uint32_t StartSectorAddress); 33 | 34 | 35 | 36 | /******************** FLASH_Error_Codes ***********************//* 37 | HAL_FLASH_ERROR_NONE 0x00U // No error 38 | HAL_FLASH_ERROR_PROG 0x01U // Programming error 39 | HAL_FLASH_ERROR_WRP 0x02U // Write protection error 40 | HAL_FLASH_ERROR_OPTV 0x04U // Option validity error 41 | */ 42 | 43 | 44 | #endif /* INC_FLASH_PAGE_F1_H_ */ 45 | -------------------------------------------------------------------------------- /FLASH_PROGRAM/F1 SERIES/FlASH_PAGE_F1.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | *************************************************************************************************************** 4 | *************************************************************************************************************** 5 | *************************************************************************************************************** 6 | File: FLASH_PAGE_F1.c 7 | Modifier: ControllersTech.com 8 | Updated: 27th MAY 2021 9 | *************************************************************************************************************** 10 | Copyright (C) 2017 ControllersTech.com 11 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 12 | of the GNU General Public License version 3 as published by the Free Software Foundation. 13 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 14 | or indirectly by this software, read more about this on the GNU General Public License. 15 | *************************************************************************************************************** 16 | */ 17 | 18 | #include "FLASH_PAGE_F1.h" 19 | #include "string.h" 20 | #include "stdio.h" 21 | 22 | 23 | /* STM32F103 have 128 PAGES (Page 0 to Page 127) of 1 KB each. This makes up 128 KB Flash Memory 24 | * Some STM32F103C8 have 64 KB FLASH Memory, so I guess they have Page 0 to Page 63 only. 25 | */ 26 | 27 | /* FLASH_PAGE_SIZE should be able to get the size of the Page according to the controller */ 28 | static uint32_t GetPage(uint32_t Address) 29 | { 30 | for (int indx=0; indx<128; indx++) 31 | { 32 | if((Address < (0x08000000 + (FLASH_PAGE_SIZE *(indx+1))) ) && (Address >= (0x08000000 + FLASH_PAGE_SIZE*indx))) 33 | { 34 | return (0x08000000 + FLASH_PAGE_SIZE*indx); 35 | } 36 | } 37 | 38 | return 0; 39 | } 40 | 41 | 42 | uint8_t bytes_temp[4]; 43 | 44 | 45 | void float2Bytes(uint8_t * ftoa_bytes_temp,float float_variable) 46 | { 47 | union { 48 | float a; 49 | uint8_t bytes[4]; 50 | } thing; 51 | 52 | thing.a = float_variable; 53 | 54 | for (uint8_t i = 0; i < 4; i++) { 55 | ftoa_bytes_temp[i] = thing.bytes[i]; 56 | } 57 | 58 | } 59 | 60 | float Bytes2float(uint8_t * ftoa_bytes_temp) 61 | { 62 | union { 63 | float a; 64 | uint8_t bytes[4]; 65 | } thing; 66 | 67 | for (uint8_t i = 0; i < 4; i++) { 68 | thing.bytes[i] = ftoa_bytes_temp[i]; 69 | } 70 | 71 | float float_variable = thing.a; 72 | return float_variable; 73 | } 74 | 75 | uint32_t Flash_Write_Data (uint32_t StartPageAddress, uint32_t *Data, uint16_t numberofwords) 76 | { 77 | 78 | static FLASH_EraseInitTypeDef EraseInitStruct; 79 | uint32_t PAGEError; 80 | int sofar=0; 81 | 82 | /* Unlock the Flash to enable the flash control register access *************/ 83 | HAL_FLASH_Unlock(); 84 | 85 | /* Erase the user Flash area*/ 86 | 87 | uint32_t StartPage = GetPage(StartPageAddress); 88 | uint32_t EndPageAdress = StartPageAddress + numberofwords*4; 89 | uint32_t EndPage = GetPage(EndPageAdress); 90 | 91 | /* Fill EraseInit structure*/ 92 | EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES; 93 | EraseInitStruct.PageAddress = StartPage; 94 | EraseInitStruct.NbPages = ((EndPage - StartPage)/FLASH_PAGE_SIZE) +1; 95 | 96 | if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK) 97 | { 98 | /*Error occurred while page erase.*/ 99 | return HAL_FLASH_GetError (); 100 | } 101 | 102 | /* Program the user Flash area word by word*/ 103 | 104 | while (sofar>(8*(i%4)); 144 | } 145 | } 146 | 147 | 148 | void Flash_Write_NUM (uint32_t StartSectorAddress, float Num) 149 | { 150 | 151 | float2Bytes(bytes_temp, Num); 152 | 153 | Flash_Write_Data (StartSectorAddress, (uint32_t *)bytes_temp, 1); 154 | } 155 | 156 | 157 | float Flash_Read_NUM (uint32_t StartSectorAddress) 158 | { 159 | uint8_t buffer[4]; 160 | float value; 161 | 162 | Flash_Read_Data(StartSectorAddress, (uint32_t *)buffer, 1); 163 | value = Bytes2float(buffer); 164 | return value; 165 | } 166 | -------------------------------------------------------------------------------- /FLASH_PROGRAM/F1 SERIES/README.md: -------------------------------------------------------------------------------- 1 | # How to write data in the FLASH memory of ```F1 Series``` MCU 2 | 3 | 4 | 1. Rewrite the PAGES according to your reference manual 5 | 2. Do not program the initial addresses (around 0x08000000). This is where the program is stored. 6 | 7 | ## Always Refer to the manual, as some sectors are write protected. 8 | 9 | To watch the video, goto https://youtu.be/BKgh896Bj8Q 10 | 11 | To read the content, goto https://controllerstech.com/flash-programming-in-stm32/ 12 | -------------------------------------------------------------------------------- /FLASH_PROGRAM/F4 SERIES/FLASH_SECTOR_F4.h: -------------------------------------------------------------------------------- 1 | /** 2 | *************************************************************************************************************** 3 | *************************************************************************************************************** 4 | *************************************************************************************************************** 5 | File: FLASH_SECTOR_H7.c 6 | Modifier: ControllersTech.com 7 | Updated: 27th MAY 2021 8 | *************************************************************************************************************** 9 | Copyright (C) 2017 ControllersTech.com 10 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 11 | of the GNU General Public License version 3 as published by the Free Software Foundation. 12 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 13 | or indirectly by this software, read more about this on the GNU General Public License. 14 | *************************************************************************************************************** 15 | */ 16 | 17 | #ifndef INC_FLASH_SECTOR_F4_H_ 18 | #define INC_FLASH_SECTOR_F4_H_ 19 | 20 | #include "stdint.h" 21 | 22 | uint32_t Flash_Write_Data (uint32_t StartSectorAddress, uint32_t *Data, uint16_t numberofwords); 23 | 24 | void Flash_Read_Data (uint32_t StartSectorAddress, uint32_t *RxBuf, uint16_t numberofwords); 25 | 26 | void Convert_To_Str (uint32_t *Data, char *Buf); 27 | 28 | void Flash_Write_NUM (uint32_t StartSectorAddress, float Num); 29 | 30 | float Flash_Read_NUM (uint32_t StartSectorAddress); 31 | 32 | 33 | #endif /* INC_FLASH_SECTOR_F4_H_ */ 34 | -------------------------------------------------------------------------------- /FLASH_PROGRAM/F4 SERIES/README.md: -------------------------------------------------------------------------------- 1 | # How to write data in the FLASH memory of ```F4 Series``` MCU 2 | 3 | 4 | 1. Rewrite the Sectors according to your reference manual 5 | 2. Do not program the initial addresses (around 0x08000000). This is where the program is stored. 6 | 7 | ## Always Refer to the manual, as some sectors are write protected. 8 | 9 | To watch the video, goto https://youtu.be/dqfgxS3D1k0 10 | 11 | To read the content, goto https://controllerstech.com/flash-programming-in-stm32/ 12 | -------------------------------------------------------------------------------- /FLASH_PROGRAM/F4 SERIES/main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include 23 | #include "main.h" 24 | 25 | /* Private includes ----------------------------------------------------------*/ 26 | /* USER CODE BEGIN Includes */ 27 | #include "string.h" 28 | 29 | /* USER CODE END Includes */ 30 | 31 | /* Private typedef -----------------------------------------------------------*/ 32 | /* USER CODE BEGIN PTD */ 33 | 34 | /* USER CODE END PTD */ 35 | 36 | /* Private define ------------------------------------------------------------*/ 37 | /* USER CODE BEGIN PD */ 38 | /* USER CODE END PD */ 39 | 40 | /* Private macro -------------------------------------------------------------*/ 41 | /* USER CODE BEGIN PM */ 42 | 43 | /* USER CODE END PM */ 44 | 45 | /* Private variables ---------------------------------------------------------*/ 46 | 47 | /* USER CODE BEGIN PV */ 48 | 49 | /* USER CODE END PV */ 50 | 51 | /* Private function prototypes -----------------------------------------------*/ 52 | void SystemClock_Config(void); 53 | static void MX_GPIO_Init(void); 54 | /* USER CODE BEGIN PFP */ 55 | 56 | /* USER CODE END PFP */ 57 | 58 | /* Private user code ---------------------------------------------------------*/ 59 | /* USER CODE BEGIN 0 */ 60 | 61 | char *data = "hello FLASH from ControllerTech\ 62 | This is a test to see how many words can we work with"; 63 | 64 | uint32_t data2[] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9}; 65 | 66 | uint32_t Rx_Data[30]; 67 | 68 | char string[100]; 69 | 70 | int number = 123; 71 | 72 | float val = 123.456; 73 | 74 | float RxVal; 75 | 76 | /* USER CODE END 0 */ 77 | 78 | /** 79 | * @brief The application entry point. 80 | * @retval int 81 | */ 82 | int main(void) 83 | { 84 | /* USER CODE BEGIN 1 */ 85 | 86 | /* USER CODE END 1 */ 87 | 88 | /* MCU Configuration--------------------------------------------------------*/ 89 | 90 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 91 | HAL_Init(); 92 | 93 | /* USER CODE BEGIN Init */ 94 | 95 | /* USER CODE END Init */ 96 | 97 | /* Configure the system clock */ 98 | SystemClock_Config(); 99 | 100 | /* USER CODE BEGIN SysInit */ 101 | 102 | /* USER CODE END SysInit */ 103 | 104 | /* Initialize all configured peripherals */ 105 | MX_GPIO_Init(); 106 | /* USER CODE BEGIN 2 */ 107 | 108 | /* Make Sure you cross check the protected Sectors in the reference manual of your board */ 109 | Flash_Write_Data(0x08004100 , (uint32_t *)data2, 9); 110 | Flash_Read_Data(0x0800C400 , Rx_Data, 10); 111 | 112 | 113 | int numofwords = (strlen(data)/4)+((strlen(data)%4)!=0); 114 | Flash_Write_Data(0x08008100 , (uint32_t *)data, numofwords); 115 | Flash_Read_Data(0x08008100 , Rx_Data, numofwords); 116 | Convert_To_Str(Rx_Data, string); 117 | 118 | 119 | Flash_Write_NUM(0x0800C100, number); 120 | RxVal = Flash_Read_NUM(0x0800C100); 121 | 122 | Flash_Write_NUM(0x0800D100, val); 123 | RxVal = Flash_Read_NUM(0x0800D100); 124 | 125 | /* USER CODE END 2 */ 126 | 127 | /* Infinite loop */ 128 | /* USER CODE BEGIN WHILE */ 129 | while (1) 130 | { 131 | /* USER CODE END WHILE */ 132 | 133 | /* USER CODE BEGIN 3 */ 134 | } 135 | /* USER CODE END 3 */ 136 | } 137 | 138 | /** 139 | * @brief System Clock Configuration 140 | * @retval None 141 | */ 142 | void SystemClock_Config(void) 143 | { 144 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 145 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 146 | 147 | /** Configure the main internal regulator output voltage 148 | */ 149 | __HAL_RCC_PWR_CLK_ENABLE(); 150 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); 151 | /** Initializes the CPU, AHB and APB busses clocks 152 | */ 153 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 154 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 155 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 156 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 157 | RCC_OscInitStruct.PLL.PLLM = 4; 158 | RCC_OscInitStruct.PLL.PLLN = 180; 159 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 160 | RCC_OscInitStruct.PLL.PLLQ = 2; 161 | RCC_OscInitStruct.PLL.PLLR = 2; 162 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 163 | { 164 | Error_Handler(); 165 | } 166 | /** Activate the Over-Drive mode 167 | */ 168 | if (HAL_PWREx_EnableOverDrive() != HAL_OK) 169 | { 170 | Error_Handler(); 171 | } 172 | /** Initializes the CPU, AHB and APB busses clocks 173 | */ 174 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 175 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 176 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 177 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 178 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 179 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 180 | 181 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) 182 | { 183 | Error_Handler(); 184 | } 185 | } 186 | 187 | /** 188 | * @brief GPIO Initialization Function 189 | * @param None 190 | * @retval None 191 | */ 192 | static void MX_GPIO_Init(void) 193 | { 194 | 195 | /* GPIO Ports Clock Enable */ 196 | __HAL_RCC_GPIOH_CLK_ENABLE(); 197 | 198 | } 199 | 200 | /* USER CODE BEGIN 4 */ 201 | 202 | /* USER CODE END 4 */ 203 | 204 | /** 205 | * @brief This function is executed in case of error occurrence. 206 | * @retval None 207 | */ 208 | void Error_Handler(void) 209 | { 210 | /* USER CODE BEGIN Error_Handler_Debug */ 211 | /* User can add his own implementation to report the HAL error return state */ 212 | 213 | /* USER CODE END Error_Handler_Debug */ 214 | } 215 | 216 | #ifdef USE_FULL_ASSERT 217 | /** 218 | * @brief Reports the name of the source file and the source line number 219 | * where the assert_param error has occurred. 220 | * @param file: pointer to the source file name 221 | * @param line: assert_param error line source number 222 | * @retval None 223 | */ 224 | void assert_failed(uint8_t *file, uint32_t line) 225 | { 226 | /* USER CODE BEGIN 6 */ 227 | /* User can add his own implementation to report the file name and line number, 228 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 229 | /* USER CODE END 6 */ 230 | } 231 | #endif /* USE_FULL_ASSERT */ 232 | 233 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 234 | -------------------------------------------------------------------------------- /FLASH_PROGRAM/H7 SERIES/FLASH_SECTOR_H7.h: -------------------------------------------------------------------------------- 1 | /** 2 | *************************************************************************************************************** 3 | *************************************************************************************************************** 4 | *************************************************************************************************************** 5 | 6 | File: FLASH_SECTOR_H7.h 7 | Modifier: ControllersTech.com 8 | Updated: 27th MAY 2021 9 | 10 | *************************************************************************************************************** 11 | Copyright (C) 2017 ControllersTech.com 12 | 13 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 14 | of the GNU General Public License version 3 as published by the Free Software Foundation. 15 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 16 | or indirectly by this software, read more about this on the GNU General Public License. 17 | 18 | *************************************************************************************************************** 19 | */ 20 | 21 | #ifndef INC_FLASH_SECTOR_H7_H_ 22 | #define INC_FLASH_SECTOR_H7_H_ 23 | 24 | #include "stm32h7xx_hal.h" 25 | 26 | uint32_t Flash_Write_Data (uint32_t StartSectorAddress, uint32_t *data, uint16_t numberofwords); 27 | void Flash_Read_Data (uint32_t StartSectorAddress, uint32_t *data, uint16_t numberofwords); 28 | void Convert_To_Str (uint32_t *Data, char *Buf); 29 | 30 | void Flash_Write_NUM (uint32_t StartSectorAddress, float Num); 31 | float Flash_Read_NUM (uint32_t StartSectorAddress); 32 | 33 | 34 | #endif /* INC_FLASH_SECTOR_H7_H_ */ 35 | -------------------------------------------------------------------------------- /FLASH_PROGRAM/H7 SERIES/README.md: -------------------------------------------------------------------------------- 1 | # How to write data in the FLASH memory of ```H7 Series``` MCU 2 | 3 | 4 | 1. Choose the MCU in ```FLASH_SECTOR_H7.c``` file 5 | 2. Rewrite the Sectors according to your reference manual 6 | 3. If VOLTAGE RANGE throws error, just comment it out 7 | 8 | ## Always Refer to the manual, as some sectors are write protected. 9 | -------------------------------------------------------------------------------- /FLASH_PROGRAM/H7 SERIES/main.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.c 5 | * @brief : Main program body 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | /* Includes ------------------------------------------------------------------*/ 21 | 22 | #include "main.h" 23 | 24 | /* Private includes ----------------------------------------------------------*/ 25 | /* USER CODE BEGIN Includes */ 26 | /* USER CODE END Includes */ 27 | #include"string.h" 28 | #include "FLASH_SECTOR_H7.h" 29 | /* Private typedef -----------------------------------------------------------*/ 30 | /* USER CODE BEGIN PTD */ 31 | 32 | /* USER CODE END PTD */ 33 | 34 | /* Private define ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN PD */ 36 | 37 | #ifndef HSEM_ID_0 38 | #define HSEM_ID_0 (0U) /* HW semaphore 0*/ 39 | #endif 40 | /* USER CODE END PD */ 41 | 42 | /* Private macro -------------------------------------------------------------*/ 43 | /* USER CODE BEGIN PM */ 44 | 45 | /* USER CODE END PM */ 46 | 47 | /* Private variables ---------------------------------------------------------*/ 48 | 49 | /* USER CODE BEGIN PV */ 50 | 51 | /* USER CODE END PV */ 52 | 53 | /* Private function prototypes -----------------------------------------------*/ 54 | void SystemClock_Config(void); 55 | static void MX_GPIO_Init(void); 56 | /* USER CODE BEGIN PFP */ 57 | 58 | /* USER CODE END PFP */ 59 | 60 | /* Private user code ---------------------------------------------------------*/ 61 | /* USER CODE BEGIN 0 */ 62 | 63 | char *data = "hello FLASH from ControllerTech\ 64 | This is a test to see how many words can we work with"; 65 | 66 | uint32_t data2[] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9}; 67 | 68 | uint32_t Rx_Data[30]; 69 | 70 | char string[100]; 71 | 72 | int number = 123; 73 | 74 | float val = 123.456; 75 | 76 | float RxVal; 77 | 78 | /* USER CODE END 0 */ 79 | 80 | /** 81 | * @brief The application entry point. 82 | * @retval int 83 | */ 84 | int main(void) 85 | { 86 | HAL_Init(); 87 | 88 | SystemClock_Config(); 89 | 90 | MX_GPIO_Init(); 91 | 92 | /* Make Sure you cross check the protected Sectors in the reference manula of your board */ 93 | Flash_Write_Data(0x080A0000 , (uint32_t *)data2, 9); 94 | Flash_Read_Data(0x080A0000 , Rx_Data, 10); 95 | 96 | 97 | int numofwords = (strlen(data)/4)+((strlen(data)%4)!=0); 98 | Flash_Write_Data(0x080A0000 , (uint32_t *)data, numofwords); 99 | Flash_Read_Data(0x080A0000 , Rx_Data, numofwords); 100 | Convert_To_Str(Rx_Data, string); 101 | 102 | 103 | Flash_Write_NUM(0x080A0000, number); 104 | RxVal = Flash_Read_NUM(0x080A0000); 105 | 106 | Flash_Write_NUM(0x080A0000, val); 107 | RxVal = Flash_Read_NUM(0x080A0000); 108 | 109 | while (1) 110 | { 111 | /* USER CODE END WHILE */ 112 | 113 | /* USER CODE BEGIN 3 */ 114 | } 115 | /* USER CODE END 3 */ 116 | } 117 | 118 | /** 119 | * @brief System Clock Configuration 120 | * @retval None 121 | */ 122 | void SystemClock_Config(void) 123 | { 124 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 125 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 126 | 127 | /** Supply configuration update enable 128 | */ 129 | HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY); 130 | /** Configure the main internal regulator output voltage 131 | */ 132 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0); 133 | 134 | while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {} 135 | /** Initializes the RCC Oscillators according to the specified parameters 136 | * in the RCC_OscInitTypeDef structure. 137 | */ 138 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 139 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 140 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 141 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 142 | RCC_OscInitStruct.PLL.PLLM = 5; 143 | RCC_OscInitStruct.PLL.PLLN = 192; 144 | RCC_OscInitStruct.PLL.PLLP = 2; 145 | RCC_OscInitStruct.PLL.PLLQ = 4; 146 | RCC_OscInitStruct.PLL.PLLR = 4; 147 | RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2; 148 | RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; 149 | RCC_OscInitStruct.PLL.PLLFRACN = 0; 150 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 151 | { 152 | Error_Handler(); 153 | } 154 | /** Initializes the CPU, AHB and APB buses clocks 155 | */ 156 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 157 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2 158 | |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1; 159 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 160 | RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1; 161 | RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2; 162 | RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2; 163 | RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2; 164 | RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2; 165 | RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2; 166 | 167 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) 168 | { 169 | Error_Handler(); 170 | } 171 | } 172 | 173 | /** 174 | * @brief This function is executed in case of error occurrence. 175 | * @retval None 176 | */ 177 | void Error_Handler(void) 178 | { 179 | /* USER CODE BEGIN Error_Handler_Debug */ 180 | /* User can add his own implementation to report the HAL error return state */ 181 | __disable_irq(); 182 | while (1) 183 | { 184 | } 185 | /* USER CODE END Error_Handler_Debug */ 186 | } 187 | 188 | #ifdef USE_FULL_ASSERT 189 | /** 190 | * @brief Reports the name of the source file and the source line number 191 | * where the assert_param error has occurred. 192 | * @param file: pointer to the source file name 193 | * @param line: assert_param error line source number 194 | * @retval None 195 | */ 196 | void assert_failed(uint8_t *file, uint32_t line) 197 | { 198 | /* USER CODE BEGIN 6 */ 199 | /* User can add his own implementation to report the file name and line number, 200 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 201 | /* USER CODE END 6 */ 202 | } 203 | #endif /* USE_FULL_ASSERT */ 204 | 205 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 206 | -------------------------------------------------------------------------------- /INPUT CAPTURE DMA/F446/README.md: -------------------------------------------------------------------------------- 1 | # Input Capture using the DMA 2 | 3 | It's useful for measuring the WIDTH and Frequency of the signal upto Few MHz Range ( 18 MHz in my Case) 4 | 5 | Width was measurable as low as 30 nanosec 6 | 7 | Follow the Configuration in the .IOC file 8 | 9 | Copy the code from the Main.c file 10 | 11 | 12 | ## Watch the Video https://youtu.be/qqzZ9C0umQ4 13 | -------------------------------------------------------------------------------- /LCD1602_I2C_NOHAL/Delay.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | ****************************************************************************** 4 | 5 | Timer Setup for Delay in STM32F446RE 6 | Author: ControllersTech 7 | Updated: 2nd Aug 2020 8 | 9 | ****************************************************************************** 10 | Copyright (C) 2017 ControllersTech.com 11 | 12 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 13 | of the GNU General Public License version 3 as published by the Free Software Foundation. 14 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 15 | or indirectly by this software, read more about this on the GNU General Public License. 16 | 17 | ****************************************************************************** 18 | */ 19 | 20 | #include "Delay.h" 21 | #include "RccConfig.h" 22 | 23 | void TIM6Config (void) 24 | { 25 | /************** STEPS TO FOLLOW ***************** 26 | 1. Enable Timer clock 27 | 2. Set the prescalar and the ARR 28 | 3. Enable the Timer, and wait for the update Flag to set 29 | ************************************************/ 30 | 31 | // 1. Enable Timer clock 32 | RCC->APB1ENR |= (1<<4); // Enable the timer6 clock 33 | 34 | // 2. Set the prescalar and the ARR 35 | TIM6->PSC = 90-1; // 90MHz/90 = 1 MHz ~~ 1 uS delay 36 | TIM6->ARR = 0xffff; // MAX ARR value 37 | 38 | // 3. Enable the Timer, and wait for the update Flag to set 39 | TIM6->CR1 |= (1<<0); // Enable the Counter 40 | while (!(TIM6->SR & (1<<0))); // UIF: Update interrupt flag.. This bit is set by hardware when the registers are updated 41 | } 42 | 43 | void Delay_us (uint16_t us) 44 | { 45 | /************** STEPS TO FOLLOW ***************** 46 | 1. RESET the Counter 47 | 2. Wait for the Counter to reach the entered value. As each count will take 1 us, 48 | the total waiting time will be the required us delay 49 | ************************************************/ 50 | TIM6->CNT = 0; 51 | while (TIM6->CNT < us); 52 | } 53 | 54 | void Delay_ms (uint16_t ms) 55 | { 56 | for (uint16_t i=0; i 22 | 23 | void TIM6Config (void); 24 | 25 | void Delay_us (uint16_t us); 26 | 27 | void Delay_ms (uint16_t ms); 28 | 29 | -------------------------------------------------------------------------------- /LCD1602_I2C_NOHAL/I2C.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | ****************************************************************************** 5 | 6 | I2C Setup For STM32F446RE 7 | Author: ControllersTech 8 | Updated: 31st Jan 2020 9 | 10 | ****************************************************************************** 11 | Copyright (C) 2017 ControllersTech.com 12 | 13 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 14 | of the GNU General Public License version 3 as published by the Free Software Foundation. 15 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 16 | or indirectly by this software, read more about this on the GNU General Public License. 17 | 18 | ****************************************************************************** 19 | */ 20 | 21 | #include 22 | 23 | void I2C_Config (void); 24 | 25 | void I2C_Start (void); 26 | 27 | void I2C_Write (uint8_t data); 28 | 29 | void I2C_Address (uint8_t Address); 30 | 31 | void I2C_Stop (void); 32 | 33 | void I2C_WriteMulti (uint8_t *data, uint8_t size); 34 | 35 | void I2C_Read (uint8_t Address, uint8_t *buffer, uint8_t size); 36 | -------------------------------------------------------------------------------- /LCD1602_I2C_NOHAL/README.md: -------------------------------------------------------------------------------- 1 | # LCD1602 using I2C and REGISTERS only 2 | 3 | 4 | 5 | ## USE THIS ONLY IF YOU KNOW HOW TO WORK WITH REGISTERS. 6 | 7 | 8 | The code here works with F446RE, But you can change the configuration according to your MCU 9 | 10 | All the files need to be modified except the ``` i2c-lcd.c ``` and ``` i2c-lcd.h ``` 11 | 12 | 13 | 14 | 15 | ## Check out the Register Based Programming Series for STM32 16 | 17 | https://www.youtube.com/playlist?list=PLfIJKC1ud8ghc4eFhI84z_3p3Ap2MCMV- 18 | -------------------------------------------------------------------------------- /LCD1602_I2C_NOHAL/RccConfig.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /** 4 | ****************************************************************************** 5 | 6 | CLOCK Setup For STM32F446RE 7 | Author: ControllersTech 8 | Updated: 2nd Aug 2020 9 | 10 | ****************************************************************************** 11 | Copyright (C) 2017 ControllersTech.com 12 | 13 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 14 | of the GNU General Public License version 3 as published by the Free Software Foundation. 15 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 16 | or indirectly by this software, read more about this on the GNU General Public License. 17 | 18 | ****************************************************************************** 19 | */ 20 | 21 | /** 22 | * @brief System Clock Configuration 23 | * The system Clock is configured as follow : 24 | * System Clock source = PLL (HSE) 25 | * SYSCLK(Hz) = 180000000 26 | * HCLK(Hz) = 180000000 27 | * AHB Prescaler = 1 28 | * APB1 Prescaler = 4 29 | * APB2 Prescaler = 2 30 | * HSE Frequency(Hz) = 8000000 31 | * PLL_M = 4 32 | * PLL_N = 180 33 | * PLL_P = 2 34 | * VDD(V) = 3.3 35 | * Main regulator output voltage = Scale1 mode 36 | * Flash Latency(WS) = 5 37 | * @param None 38 | * @retval None 39 | */ 40 | 41 | #include "RccConfig.h" 42 | 43 | void SysClockConfig (void) 44 | { 45 | /*************>>>>>>> STEPS FOLLOWED <<<<<<<<************ 46 | 47 | 1. ENABLE HSE and wait for the HSE to become Ready 48 | 2. Set the POWER ENABLE CLOCK and VOLTAGE REGULATOR 49 | 3. Configure the FLASH PREFETCH and the LATENCY Related Settings 50 | 4. Configure the PRESCALARS HCLK, PCLK1, PCLK2 51 | 5. Configure the MAIN PLL 52 | 6. Enable the PLL and wait for it to become ready 53 | 7. Select the Clock Source and wait for it to be set 54 | 55 | ********************************************************/ 56 | 57 | 58 | #define PLL_M 4 59 | #define PLL_N 180 60 | #define PLL_P 0 // PLLP = 2 61 | 62 | // 1. ENABLE HSE and wait for the HSE to become Ready 63 | RCC->CR |= RCC_CR_HSEON; 64 | while (!(RCC->CR & RCC_CR_HSERDY)); 65 | 66 | // 2. Set the POWER ENABLE CLOCK and VOLTAGE REGULATOR 67 | RCC->APB1ENR |= RCC_APB1ENR_PWREN; 68 | PWR->CR |= PWR_CR_VOS; 69 | 70 | 71 | // 3. Configure the FLASH PREFETCH and the LATENCY Related Settings 72 | FLASH->ACR = FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_PRFTEN | FLASH_ACR_LATENCY_5WS; 73 | 74 | // 4. Configure the PRESCALARS HCLK, PCLK1, PCLK2 75 | // AHB PR 76 | RCC->CFGR |= RCC_CFGR_HPRE_DIV1; 77 | 78 | // APB1 PR 79 | RCC->CFGR |= RCC_CFGR_PPRE1_DIV4; 80 | 81 | // APB2 PR 82 | RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; 83 | 84 | 85 | // 5. Configure the MAIN PLL 86 | RCC->PLLCFGR = (PLL_M <<0) | (PLL_N << 6) | (PLL_P <<16) | (RCC_PLLCFGR_PLLSRC_HSE); 87 | 88 | // 6. Enable the PLL and wait for it to become ready 89 | RCC->CR |= RCC_CR_PLLON; 90 | while (!(RCC->CR & RCC_CR_PLLRDY)); 91 | 92 | // 7. Select the Clock Source and wait for it to be set 93 | RCC->CFGR |= RCC_CFGR_SW_PLL; 94 | while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL); 95 | } 96 | 97 | -------------------------------------------------------------------------------- /LCD1602_I2C_NOHAL/RccConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | 4 | CLOCK Setup For STM32F446RE 5 | Author: ControllersTech 6 | Updated: 2nd Aug 2020 7 | 8 | ****************************************************************************** 9 | Copyright (C) 2017 ControllersTech.com 10 | 11 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 12 | of the GNU General Public License version 3 as published by the Free Software Foundation. 13 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 14 | or indirectly by this software, read more about this on the GNU General Public License. 15 | 16 | ****************************************************************************** 17 | */ 18 | 19 | #include "stm32f4xx.h" // Device header 20 | #include "stm32f446xx.h" 21 | 22 | void SysClockConfig (void); 23 | 24 | -------------------------------------------------------------------------------- /LCD1602_I2C_NOHAL/i2c-lcd.c: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | ****************************************************************************** 4 | 5 | LCD1602.c For STM32F446RE 6 | Author: ControllersTech 7 | Updated: 31st Jan 2020 8 | 9 | ****************************************************************************** 10 | Copyright (C) 2017 ControllersTech.com 11 | 12 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 13 | of the GNU General Public License version 3 as published by the Free Software Foundation. 14 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 15 | or indirectly by this software, read more about this on the GNU General Public License. 16 | 17 | ****************************************************************************** 18 | */ 19 | 20 | #include "i2c-lcd.h" 21 | #include "i2c.h" 22 | #include "delay.h" 23 | 24 | #define SLAVE_ADDRESS_LCD 0x4E // change this according to ur setup 25 | 26 | 27 | void LCD_Write (uint8_t Address, uint8_t *Data, int size) 28 | { 29 | I2C_Start (); 30 | I2C_Address (Address); 31 | for (int i=0; i40ms 90 | lcd_send_cmd (0x30); 91 | Delay_ms(5); // wait for >4.1ms 92 | lcd_send_cmd (0x30); 93 | Delay_us(150); // wait for >100us 94 | lcd_send_cmd (0x30); 95 | Delay_ms(10); 96 | lcd_send_cmd (0x20); // 4bit mode 97 | Delay_ms(10); 98 | 99 | // dislay initialisation 100 | lcd_send_cmd (0x28); // Function set --> DL=0 (4 bit mode), N = 1 (2 line display) F = 0 (5x8 characters) 101 | Delay_ms(1); 102 | lcd_send_cmd (0x08); //Display on/off control --> D=0,C=0, B=0 ---> display off 103 | Delay_ms(1); 104 | lcd_send_cmd (0x01); // clear display 105 | Delay_ms(1); 106 | Delay_ms(1); 107 | lcd_send_cmd (0x06); //Entry mode set --> I/D = 1 (increment cursor) & S = 0 (no shift) 108 | Delay_ms(1); 109 | lcd_send_cmd (0x0C); //Display on/off control --> D = 1, C and B = 0. (Cursor and blink, last two bits) 110 | } 111 | 112 | void lcd_send_string (char *str) 113 | { 114 | while (*str) lcd_send_data (*str++); 115 | } 116 | -------------------------------------------------------------------------------- /LCD1602_I2C_NOHAL/i2c-lcd.h: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | ****************************************************************************** 4 | 5 | LCD1602.h For STM32F446RE 6 | Author: ControllersTech 7 | Updated: 31st Jan 2020 8 | 9 | ****************************************************************************** 10 | Copyright (C) 2017 ControllersTech.com 11 | 12 | This is a free software under the GNU license, you can redistribute it and/or modify it under the terms 13 | of the GNU General Public License version 3 as published by the Free Software Foundation. 14 | This software library is shared with public for educational purposes, without WARRANTY and Author is not liable for any damages caused directly 15 | or indirectly by this software, read more about this on the GNU General Public License. 16 | 17 | ****************************************************************************** 18 | */ 19 | 20 | #include "RccConfig.h" 21 | 22 | void lcd_init (void); // initialize lcd 23 | 24 | void lcd_send_cmd (char cmd); // send command to the lcd 25 | 26 | void lcd_send_data (char data); // send data to the lcd 27 | 28 | void lcd_send_string (char *str); // send string to the lcd 29 | 30 | void lcd_put_cur(int row, int col); // put cursor at the entered position row (0 or 1), col (0-15); 31 | 32 | void lcd_clear (void); 33 | -------------------------------------------------------------------------------- /LCD1602_I2C_NOHAL/main.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "RccConfig.h" 4 | #include "Delay.h" 5 | #include "I2C.h" 6 | #include "i2c-lcd.h" 7 | 8 | 9 | int main () 10 | { 11 | SysClockConfig (); 12 | TIM6Config (); 13 | I2C_Config (); 14 | 15 | lcd_init (); 16 | lcd_put_cur (0,0); 17 | lcd_send_string ("hello"); 18 | while (1) 19 | { 20 | 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Core/Inc/lcd_lvgl.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef INC_LCD_LVGL_H_ 4 | #define INC_LCD_LVGL_H_ 5 | 6 | /********************* 7 | * INCLUDES 8 | *********************/ 9 | #include 10 | #include "../../lvgl/lvgl.h" 11 | 12 | /********************* 13 | * DEFINES 14 | *********************/ 15 | #define DISP_HOR_RES 240 16 | #define DISP_VER_RES 320 17 | 18 | 19 | /********************** 20 | * GLOBAL PROTOTYPES 21 | **********************/ 22 | void Display_init(int rotation); 23 | 24 | void DMA_Handler (void); 25 | #endif /* INC_LCD_LVGL_H_ */ 26 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Core/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __MAIN_H 23 | #define __MAIN_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f4xx_hal.h" 31 | 32 | /* Private includes ----------------------------------------------------------*/ 33 | /* USER CODE BEGIN Includes */ 34 | 35 | /* USER CODE END Includes */ 36 | 37 | /* Exported types ------------------------------------------------------------*/ 38 | /* USER CODE BEGIN ET */ 39 | 40 | /* USER CODE END ET */ 41 | 42 | /* Exported constants --------------------------------------------------------*/ 43 | /* USER CODE BEGIN EC */ 44 | 45 | /* USER CODE END EC */ 46 | 47 | /* Exported macro ------------------------------------------------------------*/ 48 | /* USER CODE BEGIN EM */ 49 | 50 | /* USER CODE END EM */ 51 | 52 | /* Exported functions prototypes ---------------------------------------------*/ 53 | void Error_Handler(void); 54 | 55 | /* USER CODE BEGIN EFP */ 56 | 57 | /* USER CODE END EFP */ 58 | 59 | /* Private defines -----------------------------------------------------------*/ 60 | #define RESET_Pin GPIO_PIN_1 61 | #define RESET_GPIO_Port GPIOC 62 | #define RD_Pin GPIO_PIN_0 63 | #define RD_GPIO_Port GPIOA 64 | #define WR_Pin GPIO_PIN_1 65 | #define WR_GPIO_Port GPIOA 66 | #define CD_Pin GPIO_PIN_4 67 | #define CD_GPIO_Port GPIOA 68 | #define CS_Pin GPIO_PIN_0 69 | #define CS_GPIO_Port GPIOB 70 | #define D6_Pin GPIO_PIN_10 71 | #define D6_GPIO_Port GPIOB 72 | #define D1_Pin GPIO_PIN_7 73 | #define D1_GPIO_Port GPIOC 74 | #define D7_Pin GPIO_PIN_8 75 | #define D7_GPIO_Port GPIOA 76 | #define D0_Pin GPIO_PIN_9 77 | #define D0_GPIO_Port GPIOA 78 | #define D2_Pin GPIO_PIN_10 79 | #define D2_GPIO_Port GPIOA 80 | #define D3_Pin GPIO_PIN_3 81 | #define D3_GPIO_Port GPIOB 82 | #define D5_Pin GPIO_PIN_4 83 | #define D5_GPIO_Port GPIOB 84 | #define D4_Pin GPIO_PIN_5 85 | #define D4_GPIO_Port GPIOB 86 | /* USER CODE BEGIN Private defines */ 87 | 88 | /* USER CODE END Private defines */ 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* __MAIN_H */ 95 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Core/Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_IT_H 22 | #define __STM32F4xx_IT_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Private includes ----------------------------------------------------------*/ 29 | /* USER CODE BEGIN Includes */ 30 | 31 | /* USER CODE END Includes */ 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN ET */ 35 | 36 | /* USER CODE END ET */ 37 | 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* USER CODE BEGIN EC */ 40 | 41 | /* USER CODE END EC */ 42 | 43 | /* Exported macro ------------------------------------------------------------*/ 44 | /* USER CODE BEGIN EM */ 45 | 46 | /* USER CODE END EM */ 47 | 48 | /* Exported functions prototypes ---------------------------------------------*/ 49 | void NMI_Handler(void); 50 | void HardFault_Handler(void); 51 | void MemManage_Handler(void); 52 | void BusFault_Handler(void); 53 | void UsageFault_Handler(void); 54 | void SVC_Handler(void); 55 | void DebugMon_Handler(void); 56 | void PendSV_Handler(void); 57 | void SysTick_Handler(void); 58 | /* USER CODE BEGIN EFP */ 59 | 60 | /* USER CODE END EFP */ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* __STM32F4xx_IT_H */ 67 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Core/Inc/tft.h: -------------------------------------------------------------------------------- 1 | 2 | /* Define to prevent recursive inclusion -------------------------------------*/ 3 | #ifndef __TFT_H 4 | #define __TFT_H 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* Includes ------------------------------------------------------------------*/ 11 | #include "stdint.h" 12 | 13 | #define WIDTH ((uint16_t)240) 14 | #define HEIGHT ((uint16_t)320) 15 | 16 | #define true 1 17 | #define false 0 18 | 19 | #define BLACK 0x0000 20 | #define BLUE 0x001F 21 | #define RED 0xF800 22 | #define GREEN 0x07E0 23 | #define CYAN 0x07FF 24 | #define MAGENTA 0xF81F 25 | #define YELLOW 0xFFE0 26 | #define WHITE 0xFFFF 27 | 28 | 29 | #define MIPI_DCS_REV1 (1<<0) 30 | #define AUTO_READINC (1<<1) 31 | #define READ_BGR (1<<2) 32 | #define READ_LOWHIGH (1<<3) 33 | #define READ_24BITS (1<<4) 34 | #define XSA_XEA_16BIT (1<<5) 35 | #define READ_NODUMMY (1<<6) 36 | #define INVERT_GS (1<<8) 37 | #define INVERT_SS (1<<9) 38 | #define MV_AXIS (1<<10) 39 | #define INVERT_RGB (1<<11) 40 | #define REV_SCREEN (1<<12) 41 | #define FLIP_VERT (1<<13) 42 | #define FLIP_HORIZ (1<<14) 43 | 44 | 45 | 46 | 47 | void tft_init(uint16_t ID); 48 | 49 | void reset(void); 50 | 51 | uint16_t readID(void); 52 | 53 | void setRotation(uint8_t r); 54 | void invertDisplay(uint8_t i); 55 | 56 | void setAddrWindow(int16_t x, int16_t y, int16_t x1, int16_t y1); 57 | 58 | void pushColors16b(uint16_t * block, int16_t n, uint8_t first); 59 | 60 | void fillFB(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t *color); 61 | 62 | void fillScreen(uint16_t color); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif /* __HX8347G_H */ 69 | 70 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Core/Inc/user_setting.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef USER_SETTING_H_ 4 | #define USER_SETTING_H_ 5 | 6 | #include "stm32f4xx_hal.h" 7 | 8 | 9 | #define RD_PORT GPIOA 10 | #define RD_PIN GPIO_PIN_0 11 | 12 | #define WR_PORT GPIOA 13 | #define WR_PIN GPIO_PIN_1 14 | 15 | #define CD_PORT GPIOA 16 | #define CD_PIN GPIO_PIN_4 17 | 18 | #define CS_PORT GPIOB 19 | #define CS_PIN GPIO_PIN_0 20 | 21 | #define RESET_PORT GPIOC 22 | #define RESET_PIN GPIO_PIN_1 23 | 24 | #define D0_PORT GPIOA 25 | #define D0_PIN GPIO_PIN_9 26 | 27 | #define D1_PORT GPIOC 28 | #define D1_PIN GPIO_PIN_7 29 | 30 | #define D2_PORT GPIOA 31 | #define D2_PIN GPIO_PIN_10 32 | 33 | #define D3_PORT GPIOB 34 | #define D3_PIN GPIO_PIN_3 35 | 36 | #define D4_PORT GPIOB 37 | #define D4_PIN GPIO_PIN_5 38 | 39 | #define D5_PORT GPIOB 40 | #define D5_PIN GPIO_PIN_4 41 | 42 | #define D6_PORT GPIOB 43 | #define D6_PIN GPIO_PIN_10 44 | 45 | #define D7_PORT GPIOA 46 | #define D7_PIN GPIO_PIN_8 47 | 48 | 49 | void lcd_delay (uint16_t t); 50 | 51 | 52 | 53 | // configure macros for the data pins. 54 | 55 | #define write_8(d) { \ 56 | GPIOA->BSRR = 0x0700 << 16; \ 57 | GPIOB->BSRR = 0x0438 << 16; \ 58 | GPIOC->BSRR = 0x0080 << 16; \ 59 | GPIOA->BSRR = (((d) & (1<<0)) << 9) \ 60 | | (((d) & (1<<2)) << 8) \ 61 | | (((d) & (1<<7)) << 1); \ 62 | GPIOB->BSRR = (((d) & (1<<3)) << 0) \ 63 | | (((d) & (1<<4)) << 1) \ 64 | | (((d) & (1<<5)) >> 1) \ 65 | | (((d) & (1<<6)) << 4); \ 66 | GPIOC->BSRR = (((d) & (1<<1)) << 6); \ 67 | } 68 | 69 | 70 | #define read_8() ( (((GPIOA->IDR & (1<<9)) >> 9) \ 71 | | ((GPIOC->IDR & (1<<7)) >> 6) \ 72 | | ((GPIOA->IDR & (1<<10)) >> 8) \ 73 | | ((GPIOB->IDR & (1<<3)) >> 0) \ 74 | | ((GPIOB->IDR & (1<<5)) >> 1) \ 75 | | ((GPIOB->IDR & (1<<4)) << 1) \ 76 | | ((GPIOB->IDR & (1<<10)) >> 4) \ 77 | | ((GPIOA->IDR & (1<<8)) >> 1))\ 78 | ) 79 | 80 | 81 | 82 | /********************* For 180 MHz *****************************/ 83 | //#define WRITE_DELAY { WR_ACTIVE8; } 84 | //#define READ_DELAY { RD_ACTIVE16;} 85 | 86 | 87 | /************************** For 72 MHZ ****************************/ 88 | #define WRITE_DELAY { } 89 | #define READ_DELAY { RD_ACTIVE; } 90 | 91 | 92 | /************************** For 100 MHZ ****************************/ 93 | //#define WRITE_DELAY { WR_ACTIVE2; } 94 | //#define READ_DELAY { RD_ACTIVE4; } 95 | 96 | 97 | /************************** For 216 MHZ ****************************/ 98 | //#define WRITE_DELAY { WR_ACTIVE8; WR_ACTIVE8; } //216MHz 99 | //#define IDLE_DELAY { WR_IDLE4;WR_IDLE4; } 100 | //#define READ_DELAY { RD_ACTIVE16;RD_ACTIVE16;RD_ACTIVE16;} 101 | 102 | 103 | /************************** For 48 MHZ ****************************/ 104 | //#define WRITE_DELAY { } 105 | //#define READ_DELAY { } 106 | 107 | 108 | /***************************** DEFINES FOR DIFFERENT TFTs ****************************************************/ 109 | 110 | //#define SUPPORT_0139 //S6D0139 +280 bytes 111 | //#define SUPPORT_0154 //S6D0154 +320 bytes 112 | //#define SUPPORT_05A1 //for S6D05A1 113 | //#define SUPPORT_1289 //SSD1289,SSD1297 (ID=0x9797) +626 bytes, 0.03s 114 | //#define SUPPORT_1580 //R61580 Untested 115 | //#define SUPPORT_1963 //only works with 16BIT bus anyway 116 | //#define SUPPORT_4532 //LGDP4532 +120 bytes. thanks Leodino 117 | //#define SUPPORT_4535 //LGDP4535 +180 bytes 118 | //#define SUPPORT_68140 //RM68140 +52 bytes defaults to PIXFMT=0x55 119 | //#define SUPPORT_7735 120 | //#define SUPPORT_7781 //ST7781 +172 bytes 121 | //#define SUPPORT_8230 //UC8230 +118 bytes 122 | #define SUPPORT_8347D //HX8347-D, HX8347-G, HX8347-I, HX8367-A +520 bytes, 0.27s 123 | //#define SUPPORT_8347A //HX8347-A +500 bytes, 0.27s 124 | //#define SUPPORT_8352A //HX8352A +486 bytes, 0.27s 125 | //#define SUPPORT_8352B //HX8352B 126 | //#define SUPPORT_8357D_GAMMA //monster 34 byte 127 | //#define SUPPORT_9163 // 128 | //#define SUPPORT_9225 //ILI9225-B, ILI9225-G ID=0x9225, ID=0x9226, ID=0x6813 +380 bytes 129 | //#define SUPPORT_9320 //ID=0x0001, R61505, SPFD5408, ILI9320 130 | //#define SUPPORT_9325 //RM68090, ILI9325, ILI9328, ILI9331, ILI9335 131 | //#define SUPPORT_9326_5420 //ILI9326, SPFD5420 +246 bytes 132 | //#define SUPPORT_9342 //costs +114 bytes 133 | //#define SUPPORT_9806 //UNTESTED 134 | #define SUPPORT_9488_555 //costs +230 bytes, 0.03s / 0.19s 135 | //#define SUPPORT_B509_7793 //R61509, ST7793 +244 bytes 136 | #define OFFSET_9327 32 //costs about 103 bytes, 0.08s 137 | 138 | 139 | #if (defined(USES_16BIT_BUS)) //only comes from SPECIALs 140 | #define USING_16BIT_BUS 1 141 | #else 142 | #define USING_16BIT_BUS 0 143 | #endif 144 | 145 | 146 | #endif /* USER_SETTING_H_ */ 147 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Core/Src/lcd_lvgl.c: -------------------------------------------------------------------------------- 1 | 2 | #include "../../lv_conf.h" 3 | #include "../../lvgl/lvgl.h" 4 | 5 | #include "lcd_lvgl.h" 6 | 7 | #include "tft.h" 8 | #include "user_setting.h" 9 | #include "string.h" 10 | //#include "functions.h" 11 | 12 | #define MAX(a,b) ((a)>(b) ? (a):(b)) 13 | 14 | uint16_t DISP_fb[(MAX(DISP_VER_RES,DISP_HOR_RES))]; // LCD FRAME Buffer for 1 ROW 15 | 16 | 17 | 18 | static lv_disp_drv_t disp_drv; 19 | //static int32_t x1_flush; 20 | //static int32_t y1_flush; 21 | //static int32_t x2_flush; 22 | //static int32_t y2_fill; 23 | //static int32_t y_fill_act; 24 | //static const lv_color_t * buf_to_flush; 25 | 26 | static lv_color_t disp_buf1[DISP_HOR_RES * 10]; 27 | static lv_color_t disp_buf2[DISP_HOR_RES * 10]; 28 | 29 | static volatile uint32_t t_saved = 0; 30 | void monitor_cb(lv_disp_drv_t * d, uint32_t t, uint32_t p) 31 | { 32 | t_saved = t; 33 | } 34 | 35 | 36 | /*These 3 functions are needed by LittlevGL*/ 37 | static void tft_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p); 38 | 39 | 40 | void Display_init(int rotation) 41 | { 42 | 43 | static lv_disp_draw_buf_t buf; 44 | 45 | lv_disp_draw_buf_init(&buf, disp_buf1, disp_buf2, DISP_HOR_RES * 10); 46 | 47 | lv_disp_drv_init(&disp_drv); 48 | 49 | uint16_t ID = readID(); 50 | tft_init(ID); 51 | setRotation(rotation); 52 | 53 | fillScreen(BLACK); 54 | 55 | disp_drv.draw_buf = &buf; 56 | disp_drv.flush_cb = tft_flush; 57 | disp_drv.monitor_cb = monitor_cb; 58 | disp_drv.hor_res = DISP_HOR_RES; 59 | disp_drv.ver_res = DISP_VER_RES; 60 | disp_drv.rotated = rotation; 61 | lv_disp_drv_register(&disp_drv); 62 | } 63 | 64 | 65 | 66 | /********************** 67 | * STATIC FUNCTIONS 68 | **********************/ 69 | 70 | /** 71 | * Flush a color buffer 72 | * @param x1 left coordinate of the rectangle 73 | * @param x2 right coordinate of the rectangle 74 | * @param y1 top coordinate of the rectangle 75 | * @param y2 bottom coordinate of the rectangle 76 | * @param color_p pointer to an array of colors 77 | */ 78 | static void tft_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p) 79 | { 80 | /*Return if the area is out the screen*/ 81 | 82 | if(area->x2 < 0) return; 83 | if(area->y2 < 0) return; 84 | if(area->x1 > DISP_HOR_RES - 1) return; 85 | if(area->y1 > DISP_VER_RES - 1) return; 86 | 87 | 88 | int indx = 0; 89 | // setAddrWindow(area->x1, area->y1, area->x2, area->y2); 90 | for(int y=area->y1;y<=area->y2;y++) 91 | { 92 | for(int x=area->x1;x<=area->x2;x++) 93 | { 94 | // drawPixel(x, y, color_p->full); 95 | DISP_fb[indx] = color_p->full; 96 | color_p++; 97 | indx++; 98 | } 99 | 100 | indx = 0; 101 | fillFB(area->x1, y, area->x2, y, DISP_fb); 102 | 103 | } 104 | 105 | lv_disp_flush_ready(drv); 106 | } 107 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Core/Src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | * Copyright (c) 2022 STMicroelectronics. 11 | * All rights reserved. 12 | * 13 | * This software is licensed under terms that can be found in the LICENSE file 14 | * in the root directory of this software component. 15 | * If no LICENSE file comes with this software, it is provided AS-IS. 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | /* USER CODE BEGIN Includes */ 24 | 25 | /* USER CODE END Includes */ 26 | 27 | /* Private typedef -----------------------------------------------------------*/ 28 | /* USER CODE BEGIN TD */ 29 | 30 | /* USER CODE END TD */ 31 | 32 | /* Private define ------------------------------------------------------------*/ 33 | /* USER CODE BEGIN Define */ 34 | 35 | /* USER CODE END Define */ 36 | 37 | /* Private macro -------------------------------------------------------------*/ 38 | /* USER CODE BEGIN Macro */ 39 | 40 | /* USER CODE END Macro */ 41 | 42 | /* Private variables ---------------------------------------------------------*/ 43 | /* USER CODE BEGIN PV */ 44 | 45 | /* USER CODE END PV */ 46 | 47 | /* Private function prototypes -----------------------------------------------*/ 48 | /* USER CODE BEGIN PFP */ 49 | 50 | /* USER CODE END PFP */ 51 | 52 | /* External functions --------------------------------------------------------*/ 53 | /* USER CODE BEGIN ExternalFunctions */ 54 | 55 | /* USER CODE END ExternalFunctions */ 56 | 57 | /* USER CODE BEGIN 0 */ 58 | 59 | /* USER CODE END 0 */ 60 | /** 61 | * Initializes the Global MSP. 62 | */ 63 | void HAL_MspInit(void) 64 | { 65 | /* USER CODE BEGIN MspInit 0 */ 66 | 67 | /* USER CODE END MspInit 0 */ 68 | 69 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 70 | __HAL_RCC_PWR_CLK_ENABLE(); 71 | 72 | /* System interrupt init*/ 73 | 74 | /* USER CODE BEGIN MspInit 1 */ 75 | 76 | /* USER CODE END MspInit 1 */ 77 | } 78 | 79 | /* USER CODE BEGIN 1 */ 80 | 81 | /* USER CODE END 1 */ 82 | 83 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Core/Src/stm32f4xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the LICENSE file 13 | * in the root directory of this software component. 14 | * If no LICENSE file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | /* USER CODE END Header */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "main.h" 22 | #include "stm32f4xx_it.h" 23 | /* Private includes ----------------------------------------------------------*/ 24 | /* USER CODE BEGIN Includes */ 25 | /* USER CODE END Includes */ 26 | #include "../../lvgl/lvgl.h" 27 | #include "lcd_lvgl.h" 28 | 29 | /* Private typedef -----------------------------------------------------------*/ 30 | /* USER CODE BEGIN TD */ 31 | 32 | /* USER CODE END TD */ 33 | 34 | /* Private define ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN PD */ 36 | 37 | /* USER CODE END PD */ 38 | 39 | /* Private macro -------------------------------------------------------------*/ 40 | /* USER CODE BEGIN PM */ 41 | 42 | /* USER CODE END PM */ 43 | 44 | /* Private variables ---------------------------------------------------------*/ 45 | /* USER CODE BEGIN PV */ 46 | 47 | /* USER CODE END PV */ 48 | 49 | /* Private function prototypes -----------------------------------------------*/ 50 | /* USER CODE BEGIN PFP */ 51 | 52 | /* USER CODE END PFP */ 53 | 54 | /* Private user code ---------------------------------------------------------*/ 55 | /* USER CODE BEGIN 0 */ 56 | 57 | /* USER CODE END 0 */ 58 | 59 | /* External variables --------------------------------------------------------*/ 60 | 61 | /* USER CODE BEGIN EV */ 62 | 63 | /* USER CODE END EV */ 64 | 65 | /******************************************************************************/ 66 | /* Cortex-M4 Processor Interruption and Exception Handlers */ 67 | /******************************************************************************/ 68 | /** 69 | * @brief This function handles Non maskable interrupt. 70 | */ 71 | void NMI_Handler(void) 72 | { 73 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 74 | 75 | /* USER CODE END NonMaskableInt_IRQn 0 */ 76 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 77 | while (1) 78 | { 79 | } 80 | /* USER CODE END NonMaskableInt_IRQn 1 */ 81 | } 82 | 83 | /** 84 | * @brief This function handles Hard fault interrupt. 85 | */ 86 | void HardFault_Handler(void) 87 | { 88 | /* USER CODE BEGIN HardFault_IRQn 0 */ 89 | 90 | /* USER CODE END HardFault_IRQn 0 */ 91 | while (1) 92 | { 93 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 94 | /* USER CODE END W1_HardFault_IRQn 0 */ 95 | } 96 | } 97 | 98 | /** 99 | * @brief This function handles Memory management fault. 100 | */ 101 | void MemManage_Handler(void) 102 | { 103 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 104 | 105 | /* USER CODE END MemoryManagement_IRQn 0 */ 106 | while (1) 107 | { 108 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 109 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 110 | } 111 | } 112 | 113 | /** 114 | * @brief This function handles Pre-fetch fault, memory access fault. 115 | */ 116 | void BusFault_Handler(void) 117 | { 118 | /* USER CODE BEGIN BusFault_IRQn 0 */ 119 | 120 | /* USER CODE END BusFault_IRQn 0 */ 121 | while (1) 122 | { 123 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 124 | /* USER CODE END W1_BusFault_IRQn 0 */ 125 | } 126 | } 127 | 128 | /** 129 | * @brief This function handles Undefined instruction or illegal state. 130 | */ 131 | void UsageFault_Handler(void) 132 | { 133 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 134 | 135 | /* USER CODE END UsageFault_IRQn 0 */ 136 | while (1) 137 | { 138 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 139 | /* USER CODE END W1_UsageFault_IRQn 0 */ 140 | } 141 | } 142 | 143 | /** 144 | * @brief This function handles System service call via SWI instruction. 145 | */ 146 | void SVC_Handler(void) 147 | { 148 | /* USER CODE BEGIN SVCall_IRQn 0 */ 149 | 150 | /* USER CODE END SVCall_IRQn 0 */ 151 | /* USER CODE BEGIN SVCall_IRQn 1 */ 152 | 153 | /* USER CODE END SVCall_IRQn 1 */ 154 | } 155 | 156 | /** 157 | * @brief This function handles Debug monitor. 158 | */ 159 | void DebugMon_Handler(void) 160 | { 161 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 162 | 163 | /* USER CODE END DebugMonitor_IRQn 0 */ 164 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 165 | 166 | /* USER CODE END DebugMonitor_IRQn 1 */ 167 | } 168 | 169 | /** 170 | * @brief This function handles Pendable request for system service. 171 | */ 172 | void PendSV_Handler(void) 173 | { 174 | /* USER CODE BEGIN PendSV_IRQn 0 */ 175 | 176 | /* USER CODE END PendSV_IRQn 0 */ 177 | /* USER CODE BEGIN PendSV_IRQn 1 */ 178 | 179 | /* USER CODE END PendSV_IRQn 1 */ 180 | } 181 | 182 | /** 183 | * @brief This function handles System tick timer. 184 | */ 185 | void SysTick_Handler(void) 186 | { 187 | /* USER CODE BEGIN SysTick_IRQn 0 */ 188 | 189 | /* USER CODE END SysTick_IRQn 0 */ 190 | HAL_IncTick(); 191 | /* USER CODE BEGIN SysTick_IRQn 1 */ 192 | lv_tick_inc(1); 193 | /* USER CODE END SysTick_IRQn 1 */ 194 | } 195 | 196 | /******************************************************************************/ 197 | /* STM32F4xx Peripheral Interrupt Handlers */ 198 | /* Add here the Interrupt Handlers for the used peripherals. */ 199 | /* For the available peripheral interrupt handler names, */ 200 | /* please refer to the startup file (startup_stm32f4xx.s). */ 201 | /******************************************************************************/ 202 | 203 | /* USER CODE BEGIN 1 */ 204 | 205 | /* USER CODE END 1 */ 206 | 207 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Core/Src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file syscalls.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @brief STM32CubeIDE Minimal System calls file 6 | * 7 | * For more information about which c-functions 8 | * need which of these lowlevel functions 9 | * please consult the Newlib libc-manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | * Copyright (c) 2021 STMicroelectronics. 14 | * All rights reserved. 15 | * 16 | * This software is licensed under terms that can be found in the LICENSE file 17 | * in the root directory of this software component. 18 | * If no LICENSE file comes with this software, it is provided AS-IS. 19 | * 20 | ****************************************************************************** 21 | */ 22 | 23 | /* Includes */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | 34 | /* Variables */ 35 | extern int __io_putchar(int ch) __attribute__((weak)); 36 | extern int __io_getchar(void) __attribute__((weak)); 37 | 38 | 39 | char *__env[1] = { 0 }; 40 | char **environ = __env; 41 | 42 | 43 | /* Functions */ 44 | void initialise_monitor_handles() 45 | { 46 | } 47 | 48 | int _getpid(void) 49 | { 50 | return 1; 51 | } 52 | 53 | int _kill(int pid, int sig) 54 | { 55 | errno = EINVAL; 56 | return -1; 57 | } 58 | 59 | void _exit (int status) 60 | { 61 | _kill(status, -1); 62 | while (1) {} /* Make sure we hang here */ 63 | } 64 | 65 | __attribute__((weak)) int _read(int file, char *ptr, int len) 66 | { 67 | int DataIdx; 68 | 69 | for (DataIdx = 0; DataIdx < len; DataIdx++) 70 | { 71 | *ptr++ = __io_getchar(); 72 | } 73 | 74 | return len; 75 | } 76 | 77 | __attribute__((weak)) int _write(int file, char *ptr, int len) 78 | { 79 | int DataIdx; 80 | 81 | for (DataIdx = 0; DataIdx < len; DataIdx++) 82 | { 83 | __io_putchar(*ptr++); 84 | } 85 | return len; 86 | } 87 | 88 | int _close(int file) 89 | { 90 | return -1; 91 | } 92 | 93 | 94 | int _fstat(int file, struct stat *st) 95 | { 96 | st->st_mode = S_IFCHR; 97 | return 0; 98 | } 99 | 100 | int _isatty(int file) 101 | { 102 | return 1; 103 | } 104 | 105 | int _lseek(int file, int ptr, int dir) 106 | { 107 | return 0; 108 | } 109 | 110 | int _open(char *path, int flags, ...) 111 | { 112 | /* Pretend like we always fail */ 113 | return -1; 114 | } 115 | 116 | int _wait(int *status) 117 | { 118 | errno = ECHILD; 119 | return -1; 120 | } 121 | 122 | int _unlink(char *name) 123 | { 124 | errno = ENOENT; 125 | return -1; 126 | } 127 | 128 | int _times(struct tms *buf) 129 | { 130 | return -1; 131 | } 132 | 133 | int _stat(char *file, struct stat *st) 134 | { 135 | st->st_mode = S_IFCHR; 136 | return 0; 137 | } 138 | 139 | int _link(char *old, char *new) 140 | { 141 | errno = EMLINK; 142 | return -1; 143 | } 144 | 145 | int _fork(void) 146 | { 147 | errno = EAGAIN; 148 | return -1; 149 | } 150 | 151 | int _execve(char *name, char **argv, char **env) 152 | { 153 | errno = ENOMEM; 154 | return -1; 155 | } 156 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Core/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sysmem.c 4 | * @author Generated by STM32CubeIDE 5 | * @brief STM32CubeIDE System Memory calls file 6 | * 7 | * For more information about which C functions 8 | * need which of these lowlevel functions 9 | * please consult the newlib libc manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | * Copyright (c) 2021 STMicroelectronics. 14 | * All rights reserved. 15 | * 16 | * This software is licensed under terms that can be found in the LICENSE file 17 | * in the root directory of this software component. 18 | * If no LICENSE file comes with this software, it is provided AS-IS. 19 | * 20 | ****************************************************************************** 21 | */ 22 | 23 | /* Includes */ 24 | #include 25 | #include 26 | 27 | /** 28 | * Pointer to the current high watermark of the heap usage 29 | */ 30 | static uint8_t *__sbrk_heap_end = NULL; 31 | 32 | /** 33 | * @brief _sbrk() allocates memory to the newlib heap and is used by malloc 34 | * and others from the C library 35 | * 36 | * @verbatim 37 | * ############################################################################ 38 | * # .data # .bss # newlib heap # MSP stack # 39 | * # # # # Reserved by _Min_Stack_Size # 40 | * ############################################################################ 41 | * ^-- RAM start ^-- _end _estack, RAM end --^ 42 | * @endverbatim 43 | * 44 | * This implementation starts allocating at the '_end' linker symbol 45 | * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack 46 | * The implementation considers '_estack' linker symbol to be RAM end 47 | * NOTE: If the MSP stack, at any point during execution, grows larger than the 48 | * reserved size, please increase the '_Min_Stack_Size'. 49 | * 50 | * @param incr Memory size 51 | * @return Pointer to allocated memory 52 | */ 53 | void *_sbrk(ptrdiff_t incr) 54 | { 55 | extern uint8_t _end; /* Symbol defined in the linker script */ 56 | extern uint8_t _estack; /* Symbol defined in the linker script */ 57 | extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ 58 | const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; 59 | const uint8_t *max_heap = (uint8_t *)stack_limit; 60 | uint8_t *prev_heap_end; 61 | 62 | /* Initialize heap end at first call */ 63 | if (NULL == __sbrk_heap_end) 64 | { 65 | __sbrk_heap_end = &_end; 66 | } 67 | 68 | /* Protect heap from growing into the reserved MSP stack */ 69 | if (__sbrk_heap_end + incr > max_heap) 70 | { 71 | errno = ENOMEM; 72 | return (void *)-1; 73 | } 74 | 75 | prev_heap_end = __sbrk_heap_end; 76 | __sbrk_heap_end += incr; 77 | 78 | return (void *)prev_heap_end; 79 | } 80 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/controllerstech/STM32/034758ed85bfca74d367c31dec64c32939faecf3/LVGL/Simple_F446/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /LVGL/Simple_F446/Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f4xx.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M4 Device System Source File for STM32F4xx devices. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© COPYRIGHT(c) 2017 STMicroelectronics

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

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

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

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 22 | #define __STM32F4xx_FLASH_RAMFUNC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 28 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal_def.h" 32 | 33 | /** @addtogroup STM32F4xx_HAL_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup FLASH_RAMFUNC 38 | * @{ 39 | */ 40 | 41 | /* Exported types ------------------------------------------------------------*/ 42 | /* Exported macro ------------------------------------------------------------*/ 43 | /* Exported functions --------------------------------------------------------*/ 44 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 45 | * @{ 46 | */ 47 | 48 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 49 | * @{ 50 | */ 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 53 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 54 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | 77 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/Drivers/STM32F4xx_HAL_Driver/License.md: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 STMicroelectronics 2 | 3 | This software component is licensed by STMicroelectronics under the **BSD-3-Clause** license. You may not use this file except in compliance with this license. You may obtain a copy of the license [here](https://opensource.org/licenses/BSD-3-Clause). -------------------------------------------------------------------------------- /LVGL/Simple_F446/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.c 4 | * @author MCD Application Team 5 | * @brief FLASH RAMFUNC module driver. 6 | * This file provides a FLASH firmware functions which should be 7 | * executed from internal SRAM 8 | * + Stop/Start the flash interface while System Run 9 | * + Enable/Disable the flash sleep while System Run 10 | @verbatim 11 | ============================================================================== 12 | ##### APIs executed from Internal RAM ##### 13 | ============================================================================== 14 | [..] 15 | *** ARM Compiler *** 16 | -------------------- 17 | [..] RAM functions are defined using the toolchain options. 18 | Functions that are be executed in RAM should reside in a separate 19 | source module. Using the 'Options for File' dialog you can simply change 20 | the 'Code / Const' area of a module to a memory space in physical RAM. 21 | Available memory areas are declared in the 'Target' tab of the 22 | Options for Target' dialog. 23 | 24 | *** ICCARM Compiler *** 25 | ----------------------- 26 | [..] RAM functions are defined using a specific toolchain keyword "__ramfunc". 27 | 28 | *** GNU Compiler *** 29 | -------------------- 30 | [..] RAM functions are defined using a specific toolchain attribute 31 | "__attribute__((section(".RamFunc")))". 32 | 33 | @endverbatim 34 | ****************************************************************************** 35 | * @attention 36 | * 37 | *

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

39 | * 40 | * This software component is licensed by ST under BSD 3-Clause license, 41 | * the "License"; You may not use this file except in compliance with the 42 | * License. You may obtain a copy of the License at: 43 | * opensource.org/licenses/BSD-3-Clause 44 | * 45 | ****************************************************************************** 46 | */ 47 | 48 | /* Includes ------------------------------------------------------------------*/ 49 | #include "stm32f4xx_hal.h" 50 | 51 | /** @addtogroup STM32F4xx_HAL_Driver 52 | * @{ 53 | */ 54 | 55 | /** @defgroup FLASH_RAMFUNC FLASH RAMFUNC 56 | * @brief FLASH functions executed from RAM 57 | * @{ 58 | */ 59 | #ifdef HAL_FLASH_MODULE_ENABLED 60 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ 61 | defined(STM32F412Rx) || defined(STM32F412Cx) 62 | 63 | /* Private typedef -----------------------------------------------------------*/ 64 | /* Private define ------------------------------------------------------------*/ 65 | /* Private macro -------------------------------------------------------------*/ 66 | /* Private variables ---------------------------------------------------------*/ 67 | /* Private function prototypes -----------------------------------------------*/ 68 | /* Exported functions --------------------------------------------------------*/ 69 | /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH RAMFUNC Exported Functions 70 | * @{ 71 | */ 72 | 73 | /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions executed from internal RAM 74 | * @brief Peripheral Extended features functions 75 | * 76 | @verbatim 77 | 78 | =============================================================================== 79 | ##### ramfunc functions ##### 80 | =============================================================================== 81 | [..] 82 | This subsection provides a set of functions that should be executed from RAM 83 | transfers. 84 | 85 | @endverbatim 86 | * @{ 87 | */ 88 | 89 | /** 90 | * @brief Stop the flash interface while System Run 91 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 92 | * @note This mode couldn't be set while executing with the flash itself. 93 | * It should be done with specific routine executed from RAM. 94 | * @retval HAL status 95 | */ 96 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void) 97 | { 98 | /* Enable Power ctrl clock */ 99 | __HAL_RCC_PWR_CLK_ENABLE(); 100 | /* Stop the flash interface while System Run */ 101 | SET_BIT(PWR->CR, PWR_CR_FISSR); 102 | 103 | return HAL_OK; 104 | } 105 | 106 | /** 107 | * @brief Start the flash interface while System Run 108 | * @note This mode is only available for STM32F411xx/STM32F446xx devices. 109 | * @note This mode couldn't be set while executing with the flash itself. 110 | * It should be done with specific routine executed from RAM. 111 | * @retval HAL status 112 | */ 113 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void) 114 | { 115 | /* Enable Power ctrl clock */ 116 | __HAL_RCC_PWR_CLK_ENABLE(); 117 | /* Start the flash interface while System Run */ 118 | CLEAR_BIT(PWR->CR, PWR_CR_FISSR); 119 | 120 | return HAL_OK; 121 | } 122 | 123 | /** 124 | * @brief Enable the flash sleep while System Run 125 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 126 | * @note This mode could n't be set while executing with the flash itself. 127 | * It should be done with specific routine executed from RAM. 128 | * @retval HAL status 129 | */ 130 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void) 131 | { 132 | /* Enable Power ctrl clock */ 133 | __HAL_RCC_PWR_CLK_ENABLE(); 134 | /* Enable the flash sleep while System Run */ 135 | SET_BIT(PWR->CR, PWR_CR_FMSSR); 136 | 137 | return HAL_OK; 138 | } 139 | 140 | /** 141 | * @brief Disable the flash sleep while System Run 142 | * @note This mode is only available for STM32F41xxx/STM32F446xx devices. 143 | * @note This mode couldn't be set while executing with the flash itself. 144 | * It should be done with specific routine executed from RAM. 145 | * @retval HAL status 146 | */ 147 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void) 148 | { 149 | /* Enable Power ctrl clock */ 150 | __HAL_RCC_PWR_CLK_ENABLE(); 151 | /* Disable the flash sleep while System Run */ 152 | CLEAR_BIT(PWR->CR, PWR_CR_FMSSR); 153 | 154 | return HAL_OK; 155 | } 156 | 157 | /** 158 | * @} 159 | */ 160 | 161 | /** 162 | * @} 163 | */ 164 | 165 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 166 | #endif /* HAL_FLASH_MODULE_ENABLED */ 167 | /** 168 | * @} 169 | */ 170 | 171 | /** 172 | * @} 173 | */ 174 | 175 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 176 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/README.md: -------------------------------------------------------------------------------- 1 | # LVGL and STM32 2 | 3 | ### Along with the project, you also need to download the LVGL libray, which can be downladed from https://github.com/lvgl/lvgl.git 4 | 5 | 6 | To watch the steps of implementation, check out https://youtu.be/X8aEXnSmPUI 7 | 8 | 9 | This version uses the simple FLushing technique by flushing one row at a time. 10 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/STM32F446RETX_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | ** @file : LinkerScript.ld 5 | ** 6 | ** @author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** @brief : Linker script for STM32F446RETx Device from STM32F4 series 9 | ** 512Kbytes FLASH 10 | ** 128Kbytes RAM 11 | ** 12 | ** Set heap size, stack size and stack location according 13 | ** to application requirements. 14 | ** 15 | ** Set memory bank area and size if external memory is used 16 | ** 17 | ** Target : STMicroelectronics STM32 18 | ** 19 | ** Distribution: The file is distributed as is, without any warranty 20 | ** of any kind. 21 | ** 22 | ****************************************************************************** 23 | ** @attention 24 | ** 25 | ** Copyright (c) 2022 STMicroelectronics. 26 | ** All rights reserved. 27 | ** 28 | ** This software is licensed under terms that can be found in the LICENSE file 29 | ** in the root directory of this software component. 30 | ** If no LICENSE file comes with this software, it is provided AS-IS. 31 | ** 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Entry Point */ 36 | ENTRY(Reset_Handler) 37 | 38 | /* Highest address of the user mode stack */ 39 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 40 | 41 | _Min_Heap_Size = 0x200 ; /* required amount of heap */ 42 | _Min_Stack_Size = 0x400 ; /* required amount of stack */ 43 | 44 | /* Memories definition */ 45 | MEMORY 46 | { 47 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 48 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K 49 | } 50 | 51 | /* Sections */ 52 | SECTIONS 53 | { 54 | /* The startup code into "FLASH" Rom type memory */ 55 | .isr_vector : 56 | { 57 | . = ALIGN(4); 58 | KEEP(*(.isr_vector)) /* Startup code */ 59 | . = ALIGN(4); 60 | } >FLASH 61 | 62 | /* The program code and other data into "FLASH" Rom type memory */ 63 | .text : 64 | { 65 | . = ALIGN(4); 66 | *(.text) /* .text sections (code) */ 67 | *(.text*) /* .text* sections (code) */ 68 | *(.glue_7) /* glue arm to thumb code */ 69 | *(.glue_7t) /* glue thumb to arm code */ 70 | *(.eh_frame) 71 | 72 | KEEP (*(.init)) 73 | KEEP (*(.fini)) 74 | 75 | . = ALIGN(4); 76 | _etext = .; /* define a global symbols at end of code */ 77 | } >FLASH 78 | 79 | /* Constant data into "FLASH" Rom type memory */ 80 | .rodata : 81 | { 82 | . = ALIGN(4); 83 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 84 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 85 | . = ALIGN(4); 86 | } >FLASH 87 | 88 | .ARM.extab : { 89 | . = ALIGN(4); 90 | *(.ARM.extab* .gnu.linkonce.armextab.*) 91 | . = ALIGN(4); 92 | } >FLASH 93 | 94 | .ARM : { 95 | . = ALIGN(4); 96 | __exidx_start = .; 97 | *(.ARM.exidx*) 98 | __exidx_end = .; 99 | . = ALIGN(4); 100 | } >FLASH 101 | 102 | .preinit_array : 103 | { 104 | . = ALIGN(4); 105 | PROVIDE_HIDDEN (__preinit_array_start = .); 106 | KEEP (*(.preinit_array*)) 107 | PROVIDE_HIDDEN (__preinit_array_end = .); 108 | . = ALIGN(4); 109 | } >FLASH 110 | 111 | .init_array : 112 | { 113 | . = ALIGN(4); 114 | PROVIDE_HIDDEN (__init_array_start = .); 115 | KEEP (*(SORT(.init_array.*))) 116 | KEEP (*(.init_array*)) 117 | PROVIDE_HIDDEN (__init_array_end = .); 118 | . = ALIGN(4); 119 | } >FLASH 120 | 121 | .fini_array : 122 | { 123 | . = ALIGN(4); 124 | PROVIDE_HIDDEN (__fini_array_start = .); 125 | KEEP (*(SORT(.fini_array.*))) 126 | KEEP (*(.fini_array*)) 127 | PROVIDE_HIDDEN (__fini_array_end = .); 128 | . = ALIGN(4); 129 | } >FLASH 130 | 131 | /* Used by the startup to initialize data */ 132 | _sidata = LOADADDR(.data); 133 | 134 | /* Initialized data sections into "RAM" Ram type memory */ 135 | .data : 136 | { 137 | . = ALIGN(4); 138 | _sdata = .; /* create a global symbol at data start */ 139 | *(.data) /* .data sections */ 140 | *(.data*) /* .data* sections */ 141 | *(.RamFunc) /* .RamFunc sections */ 142 | *(.RamFunc*) /* .RamFunc* sections */ 143 | 144 | . = ALIGN(4); 145 | _edata = .; /* define a global symbol at data end */ 146 | 147 | } >RAM AT> FLASH 148 | 149 | /* Uninitialized data section into "RAM" Ram type memory */ 150 | . = ALIGN(4); 151 | .bss : 152 | { 153 | /* This is used by the startup in order to initialize the .bss section */ 154 | _sbss = .; /* define a global symbol at bss start */ 155 | __bss_start__ = _sbss; 156 | *(.bss) 157 | *(.bss*) 158 | *(COMMON) 159 | 160 | . = ALIGN(4); 161 | _ebss = .; /* define a global symbol at bss end */ 162 | __bss_end__ = _ebss; 163 | } >RAM 164 | 165 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 166 | ._user_heap_stack : 167 | { 168 | . = ALIGN(8); 169 | PROVIDE ( end = . ); 170 | PROVIDE ( _end = . ); 171 | . = . + _Min_Heap_Size; 172 | . = . + _Min_Stack_Size; 173 | . = ALIGN(8); 174 | } >RAM 175 | 176 | /* Remove information from the compiler libraries */ 177 | /DISCARD/ : 178 | { 179 | libc.a ( * ) 180 | libm.a ( * ) 181 | libgcc.a ( * ) 182 | } 183 | 184 | .ARM.attributes 0 : { *(.ARM.attributes) } 185 | } 186 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/STM32F446RETX_RAM.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | ** @file : LinkerScript.ld (debug in RAM dedicated) 5 | ** 6 | ** @author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** @brief : Linker script for STM32F446RETx Device from STM32F4 series 9 | ** 512Kbytes FLASH 10 | ** 128Kbytes RAM 11 | ** 12 | ** Set heap size, stack size and stack location according 13 | ** to application requirements. 14 | ** 15 | ** Set memory bank area and size if external memory is used 16 | ** 17 | ** Target : STMicroelectronics STM32 18 | ** 19 | ** Distribution: The file is distributed as is, without any warranty 20 | ** of any kind. 21 | ** 22 | ****************************************************************************** 23 | ** @attention 24 | ** 25 | ** Copyright (c) 2022 STMicroelectronics. 26 | ** All rights reserved. 27 | ** 28 | ** This software is licensed under terms that can be found in the LICENSE file 29 | ** in the root directory of this software component. 30 | ** If no LICENSE file comes with this software, it is provided AS-IS. 31 | ** 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Entry Point */ 36 | ENTRY(Reset_Handler) 37 | 38 | /* Highest address of the user mode stack */ 39 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 40 | 41 | _Min_Heap_Size = 0x200; /* required amount of heap */ 42 | _Min_Stack_Size = 0x400; /* required amount of stack */ 43 | 44 | /* Memories definition */ 45 | MEMORY 46 | { 47 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 48 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K 49 | } 50 | 51 | /* Sections */ 52 | SECTIONS 53 | { 54 | /* The startup code into "RAM" Ram type memory */ 55 | .isr_vector : 56 | { 57 | . = ALIGN(4); 58 | KEEP(*(.isr_vector)) /* Startup code */ 59 | . = ALIGN(4); 60 | } >RAM 61 | 62 | /* The program code and other data into "RAM" Ram type memory */ 63 | .text : 64 | { 65 | . = ALIGN(4); 66 | *(.text) /* .text sections (code) */ 67 | *(.text*) /* .text* sections (code) */ 68 | *(.glue_7) /* glue arm to thumb code */ 69 | *(.glue_7t) /* glue thumb to arm code */ 70 | *(.eh_frame) 71 | *(.RamFunc) /* .RamFunc sections */ 72 | *(.RamFunc*) /* .RamFunc* sections */ 73 | 74 | KEEP (*(.init)) 75 | KEEP (*(.fini)) 76 | 77 | . = ALIGN(4); 78 | _etext = .; /* define a global symbols at end of code */ 79 | } >RAM 80 | 81 | /* Constant data into "RAM" Ram type memory */ 82 | .rodata : 83 | { 84 | . = ALIGN(4); 85 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 86 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 87 | . = ALIGN(4); 88 | } >RAM 89 | 90 | .ARM.extab : { 91 | . = ALIGN(4); 92 | *(.ARM.extab* .gnu.linkonce.armextab.*) 93 | . = ALIGN(4); 94 | } >RAM 95 | 96 | .ARM : { 97 | . = ALIGN(4); 98 | __exidx_start = .; 99 | *(.ARM.exidx*) 100 | __exidx_end = .; 101 | . = ALIGN(4); 102 | } >RAM 103 | 104 | .preinit_array : 105 | { 106 | . = ALIGN(4); 107 | PROVIDE_HIDDEN (__preinit_array_start = .); 108 | KEEP (*(.preinit_array*)) 109 | PROVIDE_HIDDEN (__preinit_array_end = .); 110 | . = ALIGN(4); 111 | } >RAM 112 | 113 | .init_array : 114 | { 115 | . = ALIGN(4); 116 | PROVIDE_HIDDEN (__init_array_start = .); 117 | KEEP (*(SORT(.init_array.*))) 118 | KEEP (*(.init_array*)) 119 | PROVIDE_HIDDEN (__init_array_end = .); 120 | . = ALIGN(4); 121 | } >RAM 122 | 123 | .fini_array : 124 | { 125 | . = ALIGN(4); 126 | PROVIDE_HIDDEN (__fini_array_start = .); 127 | KEEP (*(SORT(.fini_array.*))) 128 | KEEP (*(.fini_array*)) 129 | PROVIDE_HIDDEN (__fini_array_end = .); 130 | . = ALIGN(4); 131 | } >RAM 132 | 133 | /* Used by the startup to initialize data */ 134 | _sidata = LOADADDR(.data); 135 | 136 | /* Initialized data sections into "RAM" Ram type memory */ 137 | .data : 138 | { 139 | . = ALIGN(4); 140 | _sdata = .; /* create a global symbol at data start */ 141 | *(.data) /* .data sections */ 142 | *(.data*) /* .data* sections */ 143 | 144 | . = ALIGN(4); 145 | _edata = .; /* define a global symbol at data end */ 146 | 147 | } >RAM 148 | 149 | /* Uninitialized data section into "RAM" Ram type memory */ 150 | . = ALIGN(4); 151 | .bss : 152 | { 153 | /* This is used by the startup in order to initialize the .bss section */ 154 | _sbss = .; /* define a global symbol at bss start */ 155 | __bss_start__ = _sbss; 156 | *(.bss) 157 | *(.bss*) 158 | *(COMMON) 159 | 160 | . = ALIGN(4); 161 | _ebss = .; /* define a global symbol at bss end */ 162 | __bss_end__ = _ebss; 163 | } >RAM 164 | 165 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 166 | ._user_heap_stack : 167 | { 168 | . = ALIGN(8); 169 | PROVIDE ( end = . ); 170 | PROVIDE ( _end = . ); 171 | . = . + _Min_Heap_Size; 172 | . = . + _Min_Stack_Size; 173 | . = ALIGN(8); 174 | } >RAM 175 | 176 | /* Remove information from the compiler libraries */ 177 | /DISCARD/ : 178 | { 179 | libc.a ( * ) 180 | libm.a ( * ) 181 | libgcc.a ( * ) 182 | } 183 | 184 | .ARM.attributes 0 : { *(.ARM.attributes) } 185 | } 186 | -------------------------------------------------------------------------------- /LVGL/Simple_F446/TUT_LVGL_F446.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | File.Version=6 3 | KeepUserPlacement=false 4 | Mcu.Family=STM32F4 5 | Mcu.IP0=NVIC 6 | Mcu.IP1=RCC 7 | Mcu.IP2=SYS 8 | Mcu.IPNb=3 9 | Mcu.Name=STM32F446R(C-E)Tx 10 | Mcu.Package=LQFP64 11 | Mcu.Pin0=PH0-OSC_IN 12 | Mcu.Pin1=PH1-OSC_OUT 13 | Mcu.Pin10=PA9 14 | Mcu.Pin11=PA10 15 | Mcu.Pin12=PB3 16 | Mcu.Pin13=PB4 17 | Mcu.Pin14=PB5 18 | Mcu.Pin15=VP_SYS_VS_Systick 19 | Mcu.Pin2=PC1 20 | Mcu.Pin3=PA0-WKUP 21 | Mcu.Pin4=PA1 22 | Mcu.Pin5=PA4 23 | Mcu.Pin6=PB0 24 | Mcu.Pin7=PB10 25 | Mcu.Pin8=PC7 26 | Mcu.Pin9=PA8 27 | Mcu.PinsNb=16 28 | Mcu.ThirdPartyNb=0 29 | Mcu.UserConstants= 30 | Mcu.UserName=STM32F446RETx 31 | MxCube.Version=6.4.0 32 | MxDb.Version=DB.6.0.40 33 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 34 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false 35 | NVIC.ForceEnableDMAVector=true 36 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 37 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false 38 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 39 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false 40 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 41 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false 42 | NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true 43 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 44 | PA0-WKUP.GPIOParameters=GPIO_Label 45 | PA0-WKUP.GPIO_Label=RD 46 | PA0-WKUP.Locked=true 47 | PA0-WKUP.Signal=GPIO_Input 48 | PA1.GPIOParameters=GPIO_Speed,GPIO_Label 49 | PA1.GPIO_Label=WR 50 | PA1.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 51 | PA1.Locked=true 52 | PA1.Signal=GPIO_Output 53 | PA10.GPIOParameters=GPIO_Speed,GPIO_Label 54 | PA10.GPIO_Label=D2 55 | PA10.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 56 | PA10.Locked=true 57 | PA10.Signal=GPIO_Output 58 | PA4.GPIOParameters=GPIO_Speed,GPIO_Label 59 | PA4.GPIO_Label=CD 60 | PA4.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 61 | PA4.Locked=true 62 | PA4.Signal=GPIO_Output 63 | PA8.GPIOParameters=GPIO_Speed,GPIO_Label 64 | PA8.GPIO_Label=D7 65 | PA8.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 66 | PA8.Locked=true 67 | PA8.Signal=GPIO_Output 68 | PA9.GPIOParameters=GPIO_Speed,GPIO_Label 69 | PA9.GPIO_Label=D0 70 | PA9.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 71 | PA9.Locked=true 72 | PA9.Signal=GPIO_Output 73 | PB0.GPIOParameters=GPIO_Speed,GPIO_Label 74 | PB0.GPIO_Label=CS 75 | PB0.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 76 | PB0.Locked=true 77 | PB0.Signal=GPIO_Output 78 | PB10.GPIOParameters=GPIO_Speed,GPIO_Label 79 | PB10.GPIO_Label=D6 80 | PB10.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 81 | PB10.Locked=true 82 | PB10.Signal=GPIO_Output 83 | PB3.GPIOParameters=GPIO_Speed,GPIO_Label 84 | PB3.GPIO_Label=D3 85 | PB3.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 86 | PB3.Locked=true 87 | PB3.Signal=GPIO_Output 88 | PB4.GPIOParameters=GPIO_Speed,GPIO_Label 89 | PB4.GPIO_Label=D5 90 | PB4.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 91 | PB4.Locked=true 92 | PB4.Signal=GPIO_Output 93 | PB5.GPIOParameters=GPIO_Speed,GPIO_Label 94 | PB5.GPIO_Label=D4 95 | PB5.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 96 | PB5.Locked=true 97 | PB5.Signal=GPIO_Output 98 | PC1.GPIOParameters=GPIO_Speed,GPIO_Label 99 | PC1.GPIO_Label=RESET 100 | PC1.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 101 | PC1.Locked=true 102 | PC1.Signal=GPIO_Output 103 | PC7.GPIOParameters=GPIO_Speed,GPIO_Label 104 | PC7.GPIO_Label=D1 105 | PC7.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 106 | PC7.Locked=true 107 | PC7.Signal=GPIO_Output 108 | PH0-OSC_IN.Mode=HSE-External-Clock-Source 109 | PH0-OSC_IN.Signal=RCC_OSC_IN 110 | PH1-OSC_OUT.Mode=HSE-External-Clock-Source 111 | PH1-OSC_OUT.Signal=RCC_OSC_OUT 112 | PinOutPanel.RotationAngle=0 113 | ProjectManager.AskForMigrate=true 114 | ProjectManager.BackupPrevious=false 115 | ProjectManager.CompilerOptimize=6 116 | ProjectManager.ComputerToolchain=false 117 | ProjectManager.CoupleFile=false 118 | ProjectManager.CustomerFirmwarePackage= 119 | ProjectManager.DefaultFWLocation=true 120 | ProjectManager.DeletePrevious=true 121 | ProjectManager.DeviceId=STM32F446RETx 122 | ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.26.2 123 | ProjectManager.FreePins=false 124 | ProjectManager.HalAssertFull=false 125 | ProjectManager.HeapSize=0x200 126 | ProjectManager.KeepUserCode=true 127 | ProjectManager.LastFirmware=true 128 | ProjectManager.LibraryCopy=1 129 | ProjectManager.MainLocation=Core/Src 130 | ProjectManager.NoMain=false 131 | ProjectManager.PreviousToolchain= 132 | ProjectManager.ProjectBuild=false 133 | ProjectManager.ProjectFileName=TUT_LVGL_F446.ioc 134 | ProjectManager.ProjectName=TUT_LVGL_F446 135 | ProjectManager.RegisterCallBack= 136 | ProjectManager.StackSize=0x400 137 | ProjectManager.TargetToolchain=STM32CubeIDE 138 | ProjectManager.ToolChainLocation= 139 | ProjectManager.UnderRoot=true 140 | ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false 141 | RCC.AHBFreq_Value=180000000 142 | RCC.APB1CLKDivider=RCC_HCLK_DIV4 143 | RCC.APB1Freq_Value=45000000 144 | RCC.APB1TimFreq_Value=90000000 145 | RCC.APB2CLKDivider=RCC_HCLK_DIV2 146 | RCC.APB2Freq_Value=90000000 147 | RCC.APB2TimFreq_Value=180000000 148 | RCC.CECFreq_Value=32786.88524590164 149 | RCC.CortexFreq_Value=180000000 150 | RCC.FCLKCortexFreq_Value=180000000 151 | RCC.FMPI2C1Freq_Value=45000000 152 | RCC.FamilyName=M 153 | RCC.HCLKFreq_Value=180000000 154 | RCC.HSE_VALUE=8000000 155 | RCC.I2S1Freq_Value=48000000 156 | RCC.I2S2Freq_Value=48000000 157 | RCC.IPParameters=AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CECFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FMPI2C1Freq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,I2S1Freq_Value,I2S2Freq_Value,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLI2SPCLKFreq_Value,PLLI2SQCLKFreq_Value,PLLI2SRCLKFreq_Value,PLLI2SoutputFreq_Value,PLLM,PLLN,PLLQCLKFreq_Value,PLLRCLKFreq_Value,PLLSAIPCLKFreq_Value,PLLSAIQCLKFreq_Value,PLLSAIoutputFreq_Value,PLLSourceVirtual,PWRFreq_Value,SAIAFreq_Value,SAIBFreq_Value,SDIOFreq_Value,SPDIFRXFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,USBFreq_Value,VCOI2SInputFreq_Value,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VCOSAIInputFreq_Value,VCOSAIOutputFreq_Value 158 | RCC.MCO2PinFreq_Value=180000000 159 | RCC.PLLCLKFreq_Value=180000000 160 | RCC.PLLI2SPCLKFreq_Value=48000000 161 | RCC.PLLI2SQCLKFreq_Value=48000000 162 | RCC.PLLI2SRCLKFreq_Value=48000000 163 | RCC.PLLI2SoutputFreq_Value=48000000 164 | RCC.PLLM=4 165 | RCC.PLLN=180 166 | RCC.PLLQCLKFreq_Value=180000000 167 | RCC.PLLRCLKFreq_Value=180000000 168 | RCC.PLLSAIPCLKFreq_Value=48000000 169 | RCC.PLLSAIQCLKFreq_Value=48000000 170 | RCC.PLLSAIoutputFreq_Value=48000000 171 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 172 | RCC.PWRFreq_Value=180000000 173 | RCC.SAIAFreq_Value=48000000 174 | RCC.SAIBFreq_Value=48000000 175 | RCC.SDIOFreq_Value=180000000 176 | RCC.SPDIFRXFreq_Value=180000000 177 | RCC.SYSCLKFreq_VALUE=180000000 178 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 179 | RCC.USBFreq_Value=180000000 180 | RCC.VCOI2SInputFreq_Value=500000 181 | RCC.VCOI2SOutputFreq_Value=96000000 182 | RCC.VCOInputFreq_Value=2000000 183 | RCC.VCOOutputFreq_Value=360000000 184 | RCC.VCOSAIInputFreq_Value=500000 185 | RCC.VCOSAIOutputFreq_Value=96000000 186 | VP_SYS_VS_Systick.Mode=SysTick 187 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 188 | board=custom 189 | isbadioc=false 190 | -------------------------------------------------------------------------------- /QSPI/MT25TLxxx/EXT_MEM_BOOT/README.md: -------------------------------------------------------------------------------- 1 | 2 | # How to boot from external flash memory 3 | 4 | ## Following are the steps after creating a new project 5 | 6 | 1. If you are here, means you have already enabled the MEMORY MAPPED MODE. 7 | 2. Now you have to create a new project, which will boot from the external Flash. 8 | 3. Open the `system_stm32xxxx.c` file, goto System_Init, and add the following code to it. 9 | 10 | `RCC->CFGR = 0; // Reset the configuration register` 11 | 12 | `SCB->VTOR = QSPI_BASE; // 0x90000000` 13 | 14 | 4. Open the `Flash.ld` script file, and change the FLASH address to the QSPI FLASH. Also change the size 15 | 16 | `FLASH (rx) : ORIGIN = 0x90000000, LENGTH = 16M` 17 | 18 | 5. In the Debug configuration, goto debugger tab, and towards the bottom check the `external loader`. 19 | 20 | Click scan, select the board, and click apply 21 | 22 | 6. The Application will run from the External memory now. 23 | 24 | 25 | ## Check out the Respective files if you don't understand the steps. Also check the .ioc file for the MPU Configuration 26 | -------------------------------------------------------------------------------- /QSPI/MT25TLxxx/EXT_MEM_BOOT/STM32H745XIHX_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | ** File : LinkerScript.ld 5 | ** 6 | ** Author : STM32CubeIDE 7 | ** 8 | ** Abstract : Linker script for STM32H7 series 9 | ** 1024Kbytes FLASH 10 | ** 800Kbytes RAM 11 | ** 12 | ** Set heap size, stack size and stack location according 13 | ** to application requirements. 14 | ** 15 | ** Set memory bank area and size if external memory is used. 16 | ** 17 | ** Target : STMicroelectronics STM32 18 | ** 19 | ** Distribution: The file is distributed as is without any warranty 20 | ** of any kind. 21 | ** 22 | ***************************************************************************** 23 | ** @attention 24 | ** 25 | **

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

27 | ** 28 | ** This software component is licensed by ST under BSD 3-Clause license, 29 | ** the "License"; You may not use this file except in compliance with the 30 | ** License. You may obtain a copy of the License at: 31 | ** opensource.org/licenses/BSD-3-Clause 32 | ** 33 | ***************************************************************************** 34 | */ 35 | 36 | /* Entry Point */ 37 | ENTRY(Reset_Handler) 38 | 39 | /* Highest address of the user mode stack */ 40 | _estack = ORIGIN(RAM_D1) + LENGTH(RAM_D1); /* end of "RAM_D1" Ram type memory */ 41 | 42 | _Min_Heap_Size = 0x200 ; /* required amount of heap */ 43 | _Min_Stack_Size = 0x400 ; /* required amount of stack */ 44 | 45 | /* Memories definition */ 46 | MEMORY 47 | { 48 | RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K 49 | FLASH (rx) : ORIGIN = 0x90000000, LENGTH = 64M /* Memory is divided. Actual start is 0x08000000 and actual length is 2048K */ 50 | DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K 51 | RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K 52 | RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K 53 | ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K 54 | } 55 | 56 | /* Sections */ 57 | SECTIONS 58 | { 59 | /* The startup code into "FLASH" Rom type memory */ 60 | .isr_vector : 61 | { 62 | . = ALIGN(4); 63 | KEEP(*(.isr_vector)) /* Startup code */ 64 | . = ALIGN(4); 65 | } >FLASH 66 | 67 | /* The program code and other data into "FLASH" Rom type memory */ 68 | .text : 69 | { 70 | . = ALIGN(4); 71 | *(.text) /* .text sections (code) */ 72 | *(.text*) /* .text* sections (code) */ 73 | *(.glue_7) /* glue arm to thumb code */ 74 | *(.glue_7t) /* glue thumb to arm code */ 75 | *(.eh_frame) 76 | 77 | KEEP (*(.init)) 78 | KEEP (*(.fini)) 79 | 80 | . = ALIGN(4); 81 | _etext = .; /* define a global symbols at end of code */ 82 | } >FLASH 83 | 84 | /* Constant data into "FLASH" Rom type memory */ 85 | .rodata : 86 | { 87 | . = ALIGN(4); 88 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 89 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 90 | . = ALIGN(4); 91 | } >FLASH 92 | 93 | .ARM.extab : { 94 | . = ALIGN(4); 95 | *(.ARM.extab* .gnu.linkonce.armextab.*) 96 | . = ALIGN(4); 97 | } >FLASH 98 | 99 | .ARM : { 100 | . = ALIGN(4); 101 | __exidx_start = .; 102 | *(.ARM.exidx*) 103 | __exidx_end = .; 104 | . = ALIGN(4); 105 | } >FLASH 106 | 107 | .preinit_array : 108 | { 109 | . = ALIGN(4); 110 | PROVIDE_HIDDEN (__preinit_array_start = .); 111 | KEEP (*(.preinit_array*)) 112 | PROVIDE_HIDDEN (__preinit_array_end = .); 113 | . = ALIGN(4); 114 | } >FLASH 115 | 116 | .init_array : 117 | { 118 | . = ALIGN(4); 119 | PROVIDE_HIDDEN (__init_array_start = .); 120 | KEEP (*(SORT(.init_array.*))) 121 | KEEP (*(.init_array*)) 122 | PROVIDE_HIDDEN (__init_array_end = .); 123 | . = ALIGN(4); 124 | } >FLASH 125 | 126 | .fini_array : 127 | { 128 | . = ALIGN(4); 129 | PROVIDE_HIDDEN (__fini_array_start = .); 130 | KEEP (*(SORT(.fini_array.*))) 131 | KEEP (*(.fini_array*)) 132 | PROVIDE_HIDDEN (__fini_array_end = .); 133 | . = ALIGN(4); 134 | } >FLASH 135 | 136 | /* Used by the startup to initialize data */ 137 | _sidata = LOADADDR(.data); 138 | 139 | /* Initialized data sections into "RAM" Ram type memory */ 140 | .data : 141 | { 142 | . = ALIGN(4); 143 | _sdata = .; /* create a global symbol at data start */ 144 | *(.data) /* .data sections */ 145 | *(.data*) /* .data* sections */ 146 | *(.RamFunc) /* .RamFunc sections */ 147 | *(.RamFunc*) /* .RamFunc* sections */ 148 | 149 | . = ALIGN(4); 150 | _edata = .; /* define a global symbol at data end */ 151 | } >RAM_D1 AT> FLASH 152 | 153 | /* Uninitialized data section into "RAM" Ram type memory */ 154 | . = ALIGN(4); 155 | .bss : 156 | { 157 | /* This is used by the startup in order to initialize the .bss section */ 158 | _sbss = .; /* define a global symbol at bss start */ 159 | __bss_start__ = _sbss; 160 | *(.bss) 161 | *(.bss*) 162 | *(COMMON) 163 | 164 | . = ALIGN(4); 165 | _ebss = .; /* define a global symbol at bss end */ 166 | __bss_end__ = _ebss; 167 | } >RAM_D1 168 | 169 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 170 | ._user_heap_stack : 171 | { 172 | . = ALIGN(8); 173 | PROVIDE ( end = . ); 174 | PROVIDE ( _end = . ); 175 | . = . + _Min_Heap_Size; 176 | . = . + _Min_Stack_Size; 177 | . = ALIGN(8); 178 | } >RAM_D1 179 | 180 | /* Remove information from the compiler libraries */ 181 | /DISCARD/ : 182 | { 183 | libc.a ( * ) 184 | libm.a ( * ) 185 | libgcc.a ( * ) 186 | } 187 | 188 | .ARM.attributes 0 : { *(.ARM.attributes) } 189 | } 190 | -------------------------------------------------------------------------------- /QSPI/MT25TLxxx/README.md: -------------------------------------------------------------------------------- 1 | 2 | # How to write and Read data to MT25 Flash memory using the QSPI 3 | 4 | The steps are commented out in the main file itself 5 | 6 | The code is written for the MT25TL01G. But This part works fine for the 512 Mb Flash memories too. 7 | 8 | To make it work for 512 Mb Flash, follow the steps below 9 | 10 | 1. Change the FLASH SIZE in the MT25TL01G.h file. 11 | 2. Change the `MT25TL01G_DUMMY_CYCLES_READ_QUAD`, `MT25TL01G_DUMMY_CYCLES_READ`, `CONF_QSPI_DUMMY_CLOCK` to 10. These defines are in the beginning of the MT25TL01G.h 12 | 3. That's it. 13 | 14 | 15 | __________________________________________________________________________________________________________________ 16 | 17 | 18 | # How to configure MT25 in the memory mapped mode 19 | 20 | The steps are commented out in the main file itself 21 | 22 | You have to also use the Folder `EXT_MEM_BOOT` to boot from the External flash. 23 | Read the README File inside that folder for more details 24 | 25 | This part only works with MT25TL01G with the `DUAL FLASH MODE ENABLED`. 26 | -------------------------------------------------------------------------------- /QSPI/MT25TLxxx/quadspi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file quadspi.h 4 | * @brief This file contains all the function prototypes for 5 | * the quadspi.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __QUADSPI_H__ 21 | #define __QUADSPI_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | #include "mt25tl01g.h" 32 | /* USER CODE END Includes */ 33 | 34 | extern QSPI_HandleTypeDef hqspi; 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | /* USER CODE END Private defines */ 39 | 40 | void MX_QUADSPI_Init(void); 41 | 42 | /* USER CODE BEGIN Prototypes */ 43 | 44 | #define QSPI_Info_t MT25TL01G_Info_t 45 | #define QSPI_Interface_t MT25TL01G_Interface_t 46 | #define QSPI_Transfer_t MT25TL01G_Transfer_t 47 | #define QSPI_DualFlash_t MT25TL01G_DualFlash_t 48 | #define QSPI_ODS_t MT25TL01G_ODS_t 49 | 50 | typedef enum 51 | { 52 | QSPI_ERASE_8K = MT25TL01G_ERASE_4K , /*!< 8K size Sector erase = 2 x 4K as Dual flash mode is used for this board */ 53 | QSPI_ERASE_64K = MT25TL01G_ERASE_32K , /*!< 64K size Sector erase = 2 x 32K as Dual flash mode is used for this board */ 54 | QSPI_ERASE_128K = MT25TL01G_ERASE_64K , /*!< 128K size Sector erase = 2 x 64K as Dual mode is used for this board */ 55 | QSPI_ERASE_4K = MT25TL01G_ERASE_4K , /*!< 4K size Sector erase if DULA FLASH is Disabled */ 56 | QSPI_ERASE_32K = MT25TL01G_ERASE_32K , /*!< 32K size Sector erase if DULA FLASH is Disabled*/ 57 | QSPI_ERASE64K = MT25TL01G_ERASE_64K , /*!< 64K size Sector erase if DULA FLASH is Disabled */ 58 | QSPI_ERASE_CHIP = MT25TL01G_ERASE_CHIP /*!< Whole chip erase */ 59 | 60 | } QSPI_Erase_t; 61 | 62 | typedef enum 63 | { 64 | QSPI_ACCESS_NONE = 0, /*!< Instance not initialized, */ 65 | QSPI_ACCESS_INDIRECT, /*!< Instance use indirect mode access */ 66 | QSPI_ACCESS_MMP /*!< Instance use Memory Mapped Mode read */ 67 | } QSPI_Access_t; 68 | 69 | typedef struct 70 | { 71 | QSPI_Access_t IsInitialized; /*!< Instance access Flash method */ 72 | QSPI_Interface_t InterfaceMode; /*!< Flash Interface mode of Instance */ 73 | QSPI_Transfer_t TransferRate; /*!< Flash Transfer mode of Instance */ 74 | uint32_t DualFlashMode; /*!< Flash dual mode */ 75 | uint32_t IsMspCallbacksValid; 76 | } QSPI_Ctx_t; 77 | 78 | typedef struct 79 | { 80 | QSPI_Interface_t InterfaceMode; /*!< Current Flash Interface mode */ 81 | QSPI_Transfer_t TransferRate; /*!< Current Flash Transfer mode */ 82 | QSPI_DualFlash_t DualFlashMode; /*!< Dual Flash mode */ 83 | } QSPI_Init_t; 84 | 85 | typedef struct 86 | { 87 | uint32_t FlashSize; 88 | uint32_t ClockPrescaler; 89 | uint32_t SampleShifting; 90 | uint32_t DualFlashMode; 91 | }MX_QSPI_Init_t; 92 | 93 | 94 | /* QSPI instances number */ 95 | #define QSPI_INSTANCES_NUMBER 1U 96 | 97 | /* Definition for QSPI modes */ 98 | #define QSPI_SPI_MODE (QSPI_Interface_t)MT25TL01G_SPI_MODE /* 1 Cmd Line, 1 Address Line and 1 Data Line */ 99 | #define QSPI_SPI_1I2O_MODE (QSPI_Interface_t)MT25TL01G_SPI_1I2O_MODE /* 1 Cmd Line, 1 Address Line and 2 Data Lines */ 100 | #define QSPI_SPI_2IO_MODE (QSPI_Interface_t)MT25TL01G_SPI_2IO_MODE /* 1 Cmd Line, 2 Address Lines and 2 Data Lines */ 101 | #define QSPI_SPI_1I4O_MODE (QSPI_Interface_t)MT25TL01G_SPI_1I4O_MODE /* 1 Cmd Line, 1 Address Line and 4 Data Lines */ 102 | #define QSPI_SPI_4IO_MODE (QSPI_Interface_t)MT25TL01G_SPI_4IO_MODE /* 1 Cmd Line, 4 Address Lines and 4 Data Lines */ 103 | #define QSPI_DPI_MODE (QSPI_Interface_t)MT25TL01G_DPI_MODE /* 2 Cmd Lines, 2 Address Lines and 2 Data Lines */ 104 | #define QSPI_QPI_MODE (QSPI_Interface_t)MT25TL01G_QPI_MODE /* 4 Cmd Lines, 4 Address Lines and 4 Data Lines */ 105 | 106 | /* Definition for QSPI transfer rates */ 107 | #define QSPI_STR_TRANSFER (QSPI_Transfer_t)MT25TL01G_STR_TRANSFER /* Single Transfer Rate */ 108 | #define QSPI_DTR_TRANSFER (QSPI_Transfer_t)MT25TL01G_DTR_TRANSFER /* Double Transfer Rate */ 109 | 110 | /* Definition for QSPI dual flash mode */ 111 | //#define QSPI_DUALFLASH_DISABLE (QSPI_DualFlash_t)MT25TL01G_DUALFLASH_DISABLE /* Dual flash mode enabled */ 112 | /* Definition for QSPI Flash ID */ 113 | #define QSPI_FLASH_ID QSPI_FLASH_ID_1 114 | 115 | /* QSPI block sizes for dual flash */ 116 | #define QSPI_BLOCK_8K MT25TL01G_SECTOR_4K 117 | #define QSPI_BLOCK_64K MT25TL01G_BLOCK_32K 118 | #define QSPI_BLOCK_128K MT25TL01G_BLOCK_64K 119 | 120 | 121 | 122 | 123 | /* MT25TL01G Micron memory */ 124 | /* Size of the flash */ 125 | #define QSPI_FLASH_SIZE 26 /* Address bus width to access whole memory space */ 126 | #define QSPI_PAGE_SIZE 256 127 | 128 | 129 | uint8_t CSP_QUADSPI_Init(void); 130 | uint8_t CSP_QSPI_Erase_Chip(void); 131 | uint8_t CSP_QSPI_WriteMemory(uint8_t* buffer, uint32_t address, uint32_t buffer_size); 132 | uint8_t CSP_QSPI_EnableMemoryMappedMode(void); 133 | 134 | 135 | uint8_t CSP_QSPI_Read(uint8_t *pData, uint32_t ReadAddr, uint32_t Size); 136 | 137 | /* MT25TL01G support 4K, 32K, 64K size block erase commands. 138 | QSPI_ERASE_8K = MT25TL01G_ERASE_4K , 8K size Sector erase = 2 x 4K if Dual flash mode is used 139 | QSPI_ERASE_64K = MT25TL01G_ERASE_32K , 64K size Sector erase = 2 x 32K as Dual flash mode is used 140 | QSPI_ERASE_128K = MT25TL01G_ERASE_64K , 128K size Sector erase = 2 x 64K as Dual mode is used 141 | */ 142 | uint8_t CSP_QSPI_EraseBlock(uint32_t BlockAddress, QSPI_Erase_t BlockSize); 143 | 144 | 145 | 146 | /* USER CODE END Prototypes */ 147 | 148 | #ifdef __cplusplus 149 | } 150 | #endif 151 | 152 | #endif /* __QUADSPI_H__ */ 153 | 154 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 155 | -------------------------------------------------------------------------------- /QSPI/N25Qxxx/EXT_MEM_BOOT/README.md: -------------------------------------------------------------------------------- 1 | 2 | # How to boot from external flash memory 3 | 4 | ## Following are the steps after creating a new project 5 | 6 | 1. If you are here, means you have already enabled the MEMORY MAPPED MODE. 7 | 2. Now you have to create a new project, which will boot from the external Flash. 8 | 3. Open the `system_stm32xxxx.c` file, goto System_Init, and add the following code to it. 9 | 10 | `RCC->CFGR = 0; // Reset the configuration register` 11 | 12 | `SCB->VTOR = QSPI_BASE; // 0x90000000` 13 | 14 | 4. Open the `Flash.ld` script file, and change the FLASH address to the QSPI FLASH. Also change the size 15 | 16 | `FLASH (rx) : ORIGIN = 0x90000000, LENGTH = 16M` 17 | 18 | 5. In the Debug configuration, goto debugger tab, and towards the bottom check the `external loader`. 19 | 20 | Click scan, select the board, and click apply 21 | 22 | 6. The Application will run from the External memory now. 23 | 24 | 25 | ## Check out the Respective files if you don't understand the steps. Also check the .ioc file for the MPU Configuration 26 | 27 | 28 | ## Check out the video https://youtu.be/gAyuF20ok8c 29 | -------------------------------------------------------------------------------- /QSPI/N25Qxxx/EXT_MEM_BOOT/STM32F750N8HX_FLASH.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | ** 4 | ** @file : LinkerScript.ld 5 | ** 6 | ** @author : Auto-generated by STM32CubeIDE 7 | ** 8 | ** Abstract : Linker script for STM32F7508-DK Board embedding STM32F750N8Hx Device from stm32f7 series 9 | ** 64Kbytes FLASH 10 | ** 320Kbytes RAM 11 | ** 12 | ** Set heap size, stack size and stack location according 13 | ** to application requirements. 14 | ** 15 | ** Set memory bank area and size if external memory is used 16 | ** 17 | ** Target : STMicroelectronics STM32 18 | ** 19 | ** Distribution: The file is distributed as is, without any warranty 20 | ** of any kind. 21 | ** 22 | ****************************************************************************** 23 | ** @attention 24 | ** 25 | **

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

27 | ** 28 | ** This software component is licensed by ST under BSD 3-Clause license, 29 | ** the "License"; You may not use this file except in compliance with the 30 | ** License. You may obtain a copy of the License at: 31 | ** opensource.org/licenses/BSD-3-Clause 32 | ** 33 | ****************************************************************************** 34 | */ 35 | 36 | /* Entry Point */ 37 | ENTRY(Reset_Handler) 38 | 39 | /* Highest address of the user mode stack */ 40 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */ 41 | 42 | _Min_Heap_Size = 0x200 ; /* required amount of heap */ 43 | _Min_Stack_Size = 0x400 ; /* required amount of stack */ 44 | 45 | /* Memories definition */ 46 | MEMORY 47 | { 48 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K 49 | FLASH (rx) : ORIGIN = 0x90000000, LENGTH = 16M 50 | } 51 | 52 | /* Sections */ 53 | SECTIONS 54 | { 55 | /* The startup code into "FLASH" Rom type memory */ 56 | .isr_vector : 57 | { 58 | . = ALIGN(4); 59 | KEEP(*(.isr_vector)) /* Startup code */ 60 | . = ALIGN(4); 61 | } >FLASH 62 | 63 | /* The program code and other data into "FLASH" Rom type memory */ 64 | .text : 65 | { 66 | . = ALIGN(4); 67 | *(.text) /* .text sections (code) */ 68 | *(.text*) /* .text* sections (code) */ 69 | *(.glue_7) /* glue arm to thumb code */ 70 | *(.glue_7t) /* glue thumb to arm code */ 71 | *(.eh_frame) 72 | 73 | KEEP (*(.init)) 74 | KEEP (*(.fini)) 75 | 76 | . = ALIGN(4); 77 | _etext = .; /* define a global symbols at end of code */ 78 | } >FLASH 79 | 80 | /* Constant data into "FLASH" Rom type memory */ 81 | .rodata : 82 | { 83 | . = ALIGN(4); 84 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 85 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 86 | . = ALIGN(4); 87 | } >FLASH 88 | 89 | .ARM.extab : { 90 | . = ALIGN(4); 91 | *(.ARM.extab* .gnu.linkonce.armextab.*) 92 | . = ALIGN(4); 93 | } >FLASH 94 | 95 | .ARM : { 96 | . = ALIGN(4); 97 | __exidx_start = .; 98 | *(.ARM.exidx*) 99 | __exidx_end = .; 100 | . = ALIGN(4); 101 | } >FLASH 102 | 103 | .preinit_array : 104 | { 105 | . = ALIGN(4); 106 | PROVIDE_HIDDEN (__preinit_array_start = .); 107 | KEEP (*(.preinit_array*)) 108 | PROVIDE_HIDDEN (__preinit_array_end = .); 109 | . = ALIGN(4); 110 | } >FLASH 111 | 112 | .init_array : 113 | { 114 | . = ALIGN(4); 115 | PROVIDE_HIDDEN (__init_array_start = .); 116 | KEEP (*(SORT(.init_array.*))) 117 | KEEP (*(.init_array*)) 118 | PROVIDE_HIDDEN (__init_array_end = .); 119 | . = ALIGN(4); 120 | } >FLASH 121 | 122 | .fini_array : 123 | { 124 | . = ALIGN(4); 125 | PROVIDE_HIDDEN (__fini_array_start = .); 126 | KEEP (*(SORT(.fini_array.*))) 127 | KEEP (*(.fini_array*)) 128 | PROVIDE_HIDDEN (__fini_array_end = .); 129 | . = ALIGN(4); 130 | } >FLASH 131 | 132 | /* Used by the startup to initialize data */ 133 | _sidata = LOADADDR(.data); 134 | 135 | /* Initialized data sections into "RAM" Ram type memory */ 136 | .data : 137 | { 138 | . = ALIGN(4); 139 | _sdata = .; /* create a global symbol at data start */ 140 | *(.data) /* .data sections */ 141 | *(.data*) /* .data* sections */ 142 | *(.RamFunc) /* .RamFunc sections */ 143 | *(.RamFunc*) /* .RamFunc* sections */ 144 | 145 | . = ALIGN(4); 146 | _edata = .; /* define a global symbol at data end */ 147 | 148 | } >RAM AT> FLASH 149 | 150 | /* Uninitialized data section into "RAM" Ram type memory */ 151 | . = ALIGN(4); 152 | .bss : 153 | { 154 | /* This is used by the startup in order to initialize the .bss section */ 155 | _sbss = .; /* define a global symbol at bss start */ 156 | __bss_start__ = _sbss; 157 | *(.bss) 158 | *(.bss*) 159 | *(COMMON) 160 | 161 | . = ALIGN(4); 162 | _ebss = .; /* define a global symbol at bss end */ 163 | __bss_end__ = _ebss; 164 | } >RAM 165 | 166 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */ 167 | ._user_heap_stack : 168 | { 169 | . = ALIGN(8); 170 | PROVIDE ( end = . ); 171 | PROVIDE ( _end = . ); 172 | . = . + _Min_Heap_Size; 173 | . = . + _Min_Stack_Size; 174 | . = ALIGN(8); 175 | } >RAM 176 | 177 | /* Remove information from the compiler libraries */ 178 | /DISCARD/ : 179 | { 180 | libc.a ( * ) 181 | libm.a ( * ) 182 | libgcc.a ( * ) 183 | } 184 | 185 | .ARM.attributes 0 : { *(.ARM.attributes) } 186 | } 187 | -------------------------------------------------------------------------------- /QSPI/N25Qxxx/README.md: -------------------------------------------------------------------------------- 1 | # How to write and Read data to N25Qxxx using the QSPI 2 | 3 | The steps are commented out in the main file itself 4 | 5 | ## Check out the Video of implementation 6 | https://youtu.be/xIfh_uYy-OU 7 | 8 | __________________________________________________________________________________________________________________ 9 | 10 | # How to configure N25Q in the mmeory mapped mode 11 | 12 | The steps are commented out in the main file itself 13 | 14 | You have to also use the Folder `EXT_MEM_BOOT` to boot from the External flash. 15 | Read the README File inside that folder for more details 16 | 17 | ## Check out the Video of implementation 18 | https://youtu.be/gAyuF20ok8c 19 | -------------------------------------------------------------------------------- /QSPI/N25Qxxx/quadspi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file quadspi.h 4 | * @brief This file contains all the function prototypes for 5 | * the quadspi.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __QUADSPI_H__ 21 | #define __QUADSPI_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern QSPI_HandleTypeDef hqspi; 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | uint8_t CSP_QUADSPI_Init(void); 39 | uint8_t CSP_QSPI_EraseSector(uint32_t EraseStartAddress, uint32_t EraseEndAddress); 40 | uint8_t CSP_QSPI_Write(uint8_t* buffer, uint32_t address, uint32_t buffer_size); 41 | uint8_t CSP_QSPI_Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size); 42 | uint8_t CSP_QSPI_Erase_Block(uint32_t BlockAddress); 43 | uint8_t CSP_QSPI_EnableMemoryMappedMode(void); 44 | uint8_t CSP_QSPI_Erase_Chip (void); 45 | 46 | /* USER CODE END Private defines */ 47 | 48 | void MX_QUADSPI_Init(void); 49 | 50 | /* USER CODE BEGIN Prototypes */ 51 | 52 | /* USER CODE END Prototypes */ 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* __QUADSPI_H__ */ 59 | 60 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STM32 2 | ## STM32 Projects based on HAL functions 3 | 4 | Here I will only add those files which require frequent updation 5 | 6 | The full projects can be downloaded from the website www.controllerstech.com 7 | 8 | -------------------------------------------------------------------------------- /TIMER ENCODER MODE/README.md: -------------------------------------------------------------------------------- 1 | # STM32 TIMER in ENCODER Mode 2 | 3 | Watch the VIDEO for the Setup Process https://youtu.be/xqzWQgpqHmI 4 | 5 | ## Speed is Expreimental and need some testing 6 | 7 | Some code is written in the Interrupt.c File also. Basically we need the SysTick Handler to calculate the Speed 8 | -------------------------------------------------------------------------------- /TIMER ENCODER MODE/TUT_ENCODER_TIMER.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | Mcu.Family=STM32F1 3 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 4 | ProjectManager.MainLocation=Core/Src 5 | RCC.MCOFreq_Value=72000000 6 | ProjectManager.ProjectFileName=TUT_ENCODER_TIMER.ioc 7 | PD1-OSC_OUT.Mode=HSE-External-Oscillator 8 | ProjectManager.KeepUserCode=true 9 | Mcu.UserName=STM32F103C8Tx 10 | Mcu.PinsNb=7 11 | ProjectManager.NoMain=false 12 | RCC.PLLCLKFreq_Value=72000000 13 | ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false 14 | RCC.ADCFreqValue=36000000 15 | ProjectManager.DefaultFWLocation=true 16 | TIM2.EncoderMode=TIM_ENCODERMODE_TI12 17 | PD0-OSC_IN.Signal=RCC_OSC_IN 18 | ProjectManager.DeletePrevious=true 19 | RCC.APB1CLKDivider=RCC_HCLK_DIV2 20 | SH.S_TIM2_CH1_ETR.ConfNb=1 21 | PinOutPanel.RotationAngle=0 22 | RCC.FamilyName=M 23 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 24 | ProjectManager.StackSize=0x400 25 | PA0-WKUP.Signal=S_TIM2_CH1_ETR 26 | PD1-OSC_OUT.Signal=RCC_OSC_OUT 27 | PA13.Signal=SYS_JTMS-SWDIO 28 | RCC.FCLKCortexFreq_Value=72000000 29 | Mcu.IP2=SYS 30 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false 31 | Mcu.IP3=TIM2 32 | SH.S_TIM2_CH2.0=TIM2_CH2,Encoder_Interface 33 | Mcu.IP0=NVIC 34 | Mcu.IP1=RCC 35 | Mcu.UserConstants= 36 | ProjectManager.TargetToolchain=STM32CubeIDE 37 | Mcu.ThirdPartyNb=0 38 | RCC.HCLKFreq_Value=72000000 39 | Mcu.IPNb=4 40 | TIM2.IPParameters=EncoderMode,IC1Polarity,IC2Polarity 41 | ProjectManager.PreviousToolchain= 42 | RCC.APB2TimFreq_Value=72000000 43 | SH.S_TIM2_CH2.ConfNb=1 44 | Mcu.Pin6=VP_SYS_VS_Systick 45 | ProjectManager.RegisterCallBack= 46 | RCC.USBFreq_Value=72000000 47 | PA1.Signal=S_TIM2_CH2 48 | RCC.AHBFreq_Value=72000000 49 | Mcu.Pin0=PD0-OSC_IN 50 | Mcu.Pin1=PD1-OSC_OUT 51 | PD0-OSC_IN.Mode=HSE-External-Oscillator 52 | Mcu.Pin2=PA0-WKUP 53 | Mcu.Pin3=PA1 54 | Mcu.Pin4=PA13 55 | Mcu.Pin5=PA14 56 | ProjectManager.ProjectBuild=false 57 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 58 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false 59 | board=custom 60 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true 61 | ProjectManager.LastFirmware=true 62 | RCC.PLLMUL=RCC_PLL_MUL9 63 | RCC.VCOOutput2Freq_Value=8000000 64 | ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.3 65 | TIM2.IC2Polarity=TIM_ICPOLARITY_FALLING 66 | MxDb.Version=DB.6.0.21 67 | RCC.APB2Freq_Value=72000000 68 | ProjectManager.BackupPrevious=false 69 | MxCube.Version=6.2.1 70 | PA14.Mode=Serial_Wire 71 | NVIC.TIM2_IRQn=true\:0\:0\:false\:false\:true\:true\:true 72 | File.Version=6 73 | VP_SYS_VS_Systick.Mode=SysTick 74 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 75 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false 76 | PA13.Mode=Serial_Wire 77 | ProjectManager.FreePins=false 78 | RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value 79 | ProjectManager.AskForMigrate=true 80 | Mcu.Name=STM32F103C(8-B)Tx 81 | ProjectManager.HalAssertFull=false 82 | ProjectManager.ProjectName=TUT_ENCODER_TIMER 83 | ProjectManager.UnderRoot=true 84 | RCC.PLLMCOFreq_Value=36000000 85 | ProjectManager.CoupleFile=false 86 | RCC.SYSCLKFreq_VALUE=72000000 87 | Mcu.Package=LQFP48 88 | RCC.TimSysFreq_Value=72000000 89 | NVIC.ForceEnableDMAVector=true 90 | KeepUserPlacement=false 91 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false 92 | ProjectManager.CompilerOptimize=6 93 | ProjectManager.ToolChainLocation= 94 | TIM2.IC1Polarity=TIM_ICPOLARITY_FALLING 95 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 96 | SH.S_TIM2_CH1_ETR.0=TIM2_CH1,Encoder_Interface 97 | PA14.Signal=SYS_JTCK-SWCLK 98 | ProjectManager.HeapSize=0x200 99 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 100 | ProjectManager.ComputerToolchain=false 101 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 102 | RCC.APB1TimFreq_Value=72000000 103 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 104 | RCC.APB1Freq_Value=36000000 105 | ProjectManager.CustomerFirmwarePackage= 106 | ProjectManager.DeviceId=STM32F103C8Tx 107 | ProjectManager.LibraryCopy=1 108 | isbadioc=false 109 | -------------------------------------------------------------------------------- /TIMER ENCODER MODE/stm32f1xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f1xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | #include "stm32f1xx_it.h" 24 | /* Private includes ----------------------------------------------------------*/ 25 | /* USER CODE BEGIN Includes */ 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN PD */ 35 | 36 | /* USER CODE END PD */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN PM */ 40 | 41 | /* USER CODE END PM */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* Private user code ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN 0 */ 55 | 56 | extern int16_t position; 57 | int16_t oldpos = 0; 58 | extern int speed; 59 | int indx = 0; 60 | 61 | /* USER CODE END 0 */ 62 | 63 | /* External variables --------------------------------------------------------*/ 64 | extern TIM_HandleTypeDef htim2; 65 | /* USER CODE BEGIN EV */ 66 | 67 | /* USER CODE END EV */ 68 | 69 | /******************************************************************************/ 70 | /* Cortex-M3 Processor Interruption and Exception Handlers */ 71 | /******************************************************************************/ 72 | /** 73 | * @brief This function handles Non maskable interrupt. 74 | */ 75 | void NMI_Handler(void) 76 | { 77 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 78 | 79 | /* USER CODE END NonMaskableInt_IRQn 0 */ 80 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 81 | while (1) 82 | { 83 | } 84 | /* USER CODE END NonMaskableInt_IRQn 1 */ 85 | } 86 | 87 | /** 88 | * @brief This function handles Hard fault interrupt. 89 | */ 90 | void HardFault_Handler(void) 91 | { 92 | /* USER CODE BEGIN HardFault_IRQn 0 */ 93 | 94 | /* USER CODE END HardFault_IRQn 0 */ 95 | while (1) 96 | { 97 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 98 | /* USER CODE END W1_HardFault_IRQn 0 */ 99 | } 100 | } 101 | 102 | /** 103 | * @brief This function handles Memory management fault. 104 | */ 105 | void MemManage_Handler(void) 106 | { 107 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 108 | 109 | /* USER CODE END MemoryManagement_IRQn 0 */ 110 | while (1) 111 | { 112 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 113 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 114 | } 115 | } 116 | 117 | /** 118 | * @brief This function handles Prefetch fault, memory access fault. 119 | */ 120 | void BusFault_Handler(void) 121 | { 122 | /* USER CODE BEGIN BusFault_IRQn 0 */ 123 | 124 | /* USER CODE END BusFault_IRQn 0 */ 125 | while (1) 126 | { 127 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 128 | /* USER CODE END W1_BusFault_IRQn 0 */ 129 | } 130 | } 131 | 132 | /** 133 | * @brief This function handles Undefined instruction or illegal state. 134 | */ 135 | void UsageFault_Handler(void) 136 | { 137 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 138 | 139 | /* USER CODE END UsageFault_IRQn 0 */ 140 | while (1) 141 | { 142 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 143 | /* USER CODE END W1_UsageFault_IRQn 0 */ 144 | } 145 | } 146 | 147 | /** 148 | * @brief This function handles System service call via SWI instruction. 149 | */ 150 | void SVC_Handler(void) 151 | { 152 | /* USER CODE BEGIN SVCall_IRQn 0 */ 153 | 154 | /* USER CODE END SVCall_IRQn 0 */ 155 | /* USER CODE BEGIN SVCall_IRQn 1 */ 156 | 157 | /* USER CODE END SVCall_IRQn 1 */ 158 | } 159 | 160 | /** 161 | * @brief This function handles Debug monitor. 162 | */ 163 | void DebugMon_Handler(void) 164 | { 165 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 166 | 167 | /* USER CODE END DebugMonitor_IRQn 0 */ 168 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 169 | 170 | /* USER CODE END DebugMonitor_IRQn 1 */ 171 | } 172 | 173 | /** 174 | * @brief This function handles Pendable request for system service. 175 | */ 176 | void PendSV_Handler(void) 177 | { 178 | /* USER CODE BEGIN PendSV_IRQn 0 */ 179 | 180 | /* USER CODE END PendSV_IRQn 0 */ 181 | /* USER CODE BEGIN PendSV_IRQn 1 */ 182 | 183 | /* USER CODE END PendSV_IRQn 1 */ 184 | } 185 | 186 | /** 187 | * @brief This function handles System tick timer. 188 | */ 189 | void SysTick_Handler(void) 190 | { 191 | /* USER CODE BEGIN SysTick_IRQn 0 */ 192 | 193 | indx++; 194 | 195 | if (indx == 500) 196 | { 197 | speed = ((position - oldpos)*2); // speed in clicks/sec 198 | oldpos = position; 199 | indx = 0; 200 | } 201 | 202 | /* USER CODE END SysTick_IRQn 0 */ 203 | HAL_IncTick(); 204 | /* USER CODE BEGIN SysTick_IRQn 1 */ 205 | 206 | /* USER CODE END SysTick_IRQn 1 */ 207 | } 208 | 209 | /******************************************************************************/ 210 | /* STM32F1xx Peripheral Interrupt Handlers */ 211 | /* Add here the Interrupt Handlers for the used peripherals. */ 212 | /* For the available peripheral interrupt handler names, */ 213 | /* please refer to the startup file (startup_stm32f1xx.s). */ 214 | /******************************************************************************/ 215 | 216 | /** 217 | * @brief This function handles TIM2 global interrupt. 218 | */ 219 | void TIM2_IRQHandler(void) 220 | { 221 | /* USER CODE BEGIN TIM2_IRQn 0 */ 222 | 223 | /* USER CODE END TIM2_IRQn 0 */ 224 | HAL_TIM_IRQHandler(&htim2); 225 | /* USER CODE BEGIN TIM2_IRQn 1 */ 226 | 227 | /* USER CODE END TIM2_IRQn 1 */ 228 | } 229 | 230 | /* USER CODE BEGIN 1 */ 231 | 232 | /* USER CODE END 1 */ 233 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 234 | -------------------------------------------------------------------------------- /TOUCH GFX/ILI9341 SPI/README.md: -------------------------------------------------------------------------------- 1 | # How to use TOUCHGFX with ILI9341 based SPI Display 2 | 3 | I used the instructions provided at https://helentronica.com/2021/01/22/touchgfx-on-a-custom-made-low-cost-board-with-the-ili9341-controller-over-spi/ 4 | 5 | To undertsand the implementation, visit the link provided above. 6 | 7 | 8 | The steps to implement the code is shown in the video below 9 | 10 | https://youtu.be/suMytEyQTP4 11 | 12 | 13 | ## NOTE 14 | 1. Not all the boards support touchGFX. 15 | 2. Larger projects might not work due to low memory availability. 16 | 3. The code will not work in cubeIDE for now. I will update this later. 17 | 18 | 19 | ## You can download the full project from https://drive.google.com/file/d/1-FxMH2yGi-vVDK1OGVwLmmeGrzTMSGod/view?usp=sharing 20 | -------------------------------------------------------------------------------- /TOUCH GFX/ILI9341 SPI/STM32TouchController.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : STM32TouchController.cpp 4 | ****************************************************************************** 5 | * This file is generated by TouchGFX Generator 4.18.0. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* USER CODE BEGIN STM32TouchController */ 21 | 22 | #include 23 | #include "ili9341.h" 24 | #include "xpt2046.h" 25 | 26 | extern "C" { 27 | static void ConvXPTtoILI(uint16_t *x, uint16_t *y) 28 | { 29 | int16_t tx,ty; 30 | tx = (int16_t)(((int32_t)*x - XPT_XMIN) * GUI_WIDTH / XPT_WIDTH); 31 | tx = (tx < 0) ? 0 : tx; 32 | tx = (tx >= GUI_WIDTH) ? GUI_WIDTH-1 : tx; 33 | ty = (int16_t)(((int32_t)*y - XPT_YMIN) * GUI_HEIGHT / XPT_HEIGHT); 34 | ty = (ty < 0) ? 0 : ty; 35 | ty = (ty >= GUI_HEIGHT) ? GUI_HEIGHT-1 : ty; 36 | *x = tx; 37 | *y = ty; 38 | } 39 | } 40 | 41 | void STM32TouchController::init() 42 | { 43 | /** 44 | * Initialize touch controller and driver 45 | * 46 | */ 47 | } 48 | 49 | bool STM32TouchController::sampleTouch(int32_t& x, int32_t& y) 50 | { 51 | /** 52 | * By default sampleTouch returns false, 53 | * return true if a touch has been detected, otherwise false. 54 | * 55 | * Coordinates are passed to the caller by reference by x and y. 56 | * 57 | * This function is called by the TouchGFX framework. 58 | * By default sampleTouch is called every tick, this can be adjusted by HAL::setTouchSampleRate(int8_t); 59 | * 60 | */ 61 | 62 | static uint16_t prevx = GUI_WIDTH; 63 | static uint16_t prevy = GUI_HEIGHT; 64 | uint16_t intx, inty; 65 | XPT2046_Update(&intx, &inty); 66 | if (XPT2046_IsReasonable(intx, inty)) { 67 | ConvXPTtoILI(&intx, &inty); 68 | if (intx != prevx || inty != prevy) { 69 | prevx = intx; 70 | prevy = inty; 71 | x = (int32_t)intx; 72 | y = (int32_t)inty; 73 | return true; 74 | } 75 | } 76 | return false; 77 | } 78 | 79 | /* USER CODE END STM32TouchController */ 80 | 81 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 82 | -------------------------------------------------------------------------------- /TOUCH GFX/ILI9341 SPI/TouchGFX_DataTransfer.c: -------------------------------------------------------------------------------- 1 | /* Functions called by the TouchGFX HAL to invoke the actual data transfer to ILI9341. 2 | * Pero, 2021 3 | */ 4 | 5 | #include "ili9341.h" 6 | #include "TouchGFX_DataTransfer.h" 7 | 8 | extern void DisplayDriver_TransferCompleteCallback(); 9 | 10 | static uint8_t isTransmittingData = 0; 11 | 12 | uint32_t touchgfxDisplayDriverTransmitActive(void) 13 | { 14 | return isTransmittingData; 15 | } 16 | 17 | void touchgfxDisplayDriverTransmitBlock(uint8_t* pixels, uint16_t x, uint16_t y, uint16_t w, uint16_t h) 18 | { 19 | isTransmittingData = 1; 20 | ILI9341_SetWindow(x, y, x+w-1, y+h-1); 21 | ILI9341_DrawBitmap(w, h, pixels); 22 | } 23 | 24 | void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) 25 | { 26 | if (hspi->Instance == SPI1) { 27 | ILI9341_EndOfDrawBitmap(); 28 | isTransmittingData = 0; 29 | DisplayDriver_TransferCompleteCallback(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /TOUCH GFX/ILI9341 SPI/TouchGFX_DataTransfer.h: -------------------------------------------------------------------------------- 1 | /* Functions called by the TouchGFX HAL to invoke the actual data transfer to ILI9341. 2 | * Pero, 2021 3 | */ 4 | 5 | #ifndef TOUCHGFX_DATATRANSFER_H 6 | #define TOUCHGFX_DATATRANSFER_H 7 | 8 | #include 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | void touchgfxDisplayDriverTransmitBlock(uint8_t* pixels, uint16_t x, uint16_t y, uint16_t w, uint16_t h); 15 | uint32_t touchgfxDisplayDriverTransmitActive(void); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | #endif 21 | -------------------------------------------------------------------------------- /TOUCH GFX/ILI9341 SPI/ili9341.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ili9341.h 3 | * 4 | * Created on: 2019/12/26 5 | * Author: Kotetsu Yamamoto 6 | * Copyright [Kotetsu Yamamoto] 7 | 8 | MIT License 9 | 10 | Copyright (c) 2020 Kotestu Yamamoto 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy 13 | of this software and associated documentation files (the "Software"), to deal 14 | in the Software without restriction, including without limitation the rights 15 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 | copies of the Software, and to permit persons to whom the Software is 17 | furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in all 20 | copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | SOFTWARE. 29 | 30 | */ 31 | 32 | #ifndef INC_ILI9341_H_ 33 | #define INC_ILI9341_H_ 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #include "main.h" // For STM32F4 40 | 41 | #define GUI_WIDTH 320 42 | #define GUI_HEIGHT 240 43 | 44 | void ILI9341_Init(void); 45 | void ILI9341_SetWindow(uint16_t start_x, uint16_t start_y, uint16_t end_x, uint16_t end_y); 46 | void ILI9341_DrawBitmap(uint16_t w, uint16_t h, uint8_t *s); 47 | void ILI9341_WritePixel(uint16_t x, uint16_t y, uint16_t color); 48 | void ILI9341_EndOfDrawBitmap(void); 49 | 50 | void LCD_WR_REG(uint8_t data); 51 | void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif /* INC_ILI9341_H_ */ 58 | -------------------------------------------------------------------------------- /TOUCH GFX/ILI9341 SPI/xpt2046.c: -------------------------------------------------------------------------------- 1 | /* 2 | * xpt2046.c 3 | * 4 | * Created on: Jan 6, 2020 5 | * Author: Kotetsu Yamamoto 6 | * Copyright [Kotetsu Yamamoto] 7 | 8 | I refer https://github.com/PaulStoffregen/XPT2046_Touchscreen/blob/master/XPT2046_Touchscreen.cpp 9 | 10 | from Original source: 11 | 12 | * Copyright (c) 2015, Paul Stoffregen, paul@pjrc.com 13 | * 14 | * Permission is hereby granted, free of charge, to any person obtaining a copy 15 | * of this software and associated documentation files (the "Software"), to deal 16 | * in the Software without restriction, including without limitation the rights 17 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | * copies of the Software, and to permit persons to whom the Software is 19 | * furnished to do so, subject to the following conditions: 20 | * 21 | * The above copyright notice, development funding notice, and this permission 22 | * notice shall be included in all copies or substantial portions of the Software. 23 | * 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | * THE SOFTWARE. 31 | */ 32 | 33 | #include "xpt2046.h" 34 | 35 | #define T_IRQ XPT2046_ReadIRQ() 36 | #define T_CS_ON XPT2046_SetCS() 37 | #define T_CS_OFF XPT2046_ResetCS() 38 | 39 | #define READ_TIMES 5 40 | #define LOST_VAL 1 41 | #define ERR_RANGE 50 42 | #define Z_THRESHOLD 400 43 | #define Z_THRESHOLD_INT 75 44 | #define MSEC_THRESHOLD 3 45 | 46 | extern SPI_HandleTypeDef hspi2; 47 | extern void Error_Handler(void); 48 | static uint8_t XPT2046_initilazed = 0; 49 | 50 | static void XPT2046_SetCS(void) 51 | { 52 | HAL_GPIO_WritePin(T_CS_GPIO_Port, T_CS_Pin, GPIO_PIN_SET); 53 | } 54 | 55 | static void XPT2046_ResetCS(void) 56 | { 57 | HAL_GPIO_WritePin(T_CS_GPIO_Port, T_CS_Pin, GPIO_PIN_RESET); 58 | } 59 | 60 | static void XPT2046_Write_Byte(uint8_t num) 61 | { 62 | hspi2.Instance->CR2 &= ~(SPI_DATASIZE_16BIT); // Set 8 bit mode 63 | __HAL_SPI_ENABLE(&hspi2); 64 | if (HAL_SPI_Transmit(&hspi2, &num, 1, 1000) != HAL_OK) { 65 | Error_Handler(); 66 | } 67 | __HAL_SPI_DISABLE(&hspi2); 68 | } 69 | 70 | static uint16_t XPT2046_Read_AD(uint8_t CMD) 71 | { 72 | uint8_t num[2]; 73 | uint16_t ret; 74 | 75 | T_CS_OFF; 76 | XPT2046_Write_Byte(CMD); 77 | HAL_Delay(6); 78 | 79 | hspi2.Instance->CR2 |= SPI_DATASIZE_16BIT; // Set 16 bit mode 80 | __HAL_SPI_ENABLE(&hspi2); 81 | if (HAL_SPI_Receive(&hspi2, num, 1, 1000) != HAL_OK) { 82 | Error_Handler(); 83 | } 84 | __HAL_SPI_DISABLE(&hspi2); 85 | T_CS_ON; 86 | 87 | ret = num[0] << 8 | num[1]; 88 | ret >>= 3; 89 | ret &= (1<<12)-1; 90 | 91 | return ret; 92 | } 93 | 94 | static int16_t besttwoavg( int16_t x , int16_t y , int16_t z ) { 95 | int16_t da, db, dc; 96 | int16_t reta = 0; 97 | if ( x > y ) da = x - y; else da = y - x; 98 | if ( x > z ) db = x - z; else db = z - x; 99 | if ( z > y ) dc = z - y; else dc = y - z; 100 | 101 | if ( da <= db && da <= dc ) reta = (x + y) >> 1; 102 | else if ( db <= da && db <= dc ) reta = (x + z) >> 1; 103 | else reta = (y + z) >> 1; // else if ( dc <= da && dc <= db ) reta = (x + y) >> 1; 104 | 105 | return (reta); 106 | } 107 | 108 | void XPT2046_Init(void) 109 | { 110 | XPT2046_initilazed = 1; 111 | } 112 | 113 | void XPT2046_Update(uint16_t *x, uint16_t *y) 114 | { 115 | int16_t data[6]; 116 | static uint32_t ptime = 0; 117 | 118 | if (XPT2046_initilazed == 0) { 119 | return; 120 | } 121 | 122 | if (HAL_GetTick() - ptime < MSEC_THRESHOLD) { 123 | return; 124 | } 125 | 126 | int16_t z1 = XPT2046_Read_AD(0xb1); // z1 127 | int32_t z = z1 + 4095; 128 | int16_t z2 = XPT2046_Read_AD(0xc1); // z2 129 | z -= z2; 130 | if (z >= Z_THRESHOLD) { 131 | XPT2046_Read_AD(0x91); // dummy 1st X measure 132 | data[0] = XPT2046_Read_AD(0x91); 133 | data[1] = XPT2046_Read_AD(0xd1); 134 | data[2] = XPT2046_Read_AD(0x91); 135 | data[3] = XPT2046_Read_AD(0xd1); 136 | } else { 137 | data[0] = data[1] = data[2] = data[3] = 0; 138 | } 139 | data[4] = XPT2046_Read_AD(0x91); 140 | data[5] = XPT2046_Read_AD(0xd0); 141 | ptime = HAL_GetTick(); 142 | if (z < 0) z = 0; 143 | int16_t intx = besttwoavg( data[0], data[2], data[4] ); 144 | int16_t inty = besttwoavg( data[1], data[3], data[5] ); 145 | if (z >= Z_THRESHOLD) { 146 | *x = intx; 147 | *y = inty; 148 | } 149 | } 150 | 151 | uint8_t XPT2046_IsReasonable(uint16_t x, uint16_t y) 152 | { 153 | if (x >= XPT_XMIN && x <= XPT_XMAX && y >= XPT_YMIN && y <= XPT_YMAX) { 154 | return 1; 155 | } 156 | return 0; 157 | } 158 | -------------------------------------------------------------------------------- /TOUCH GFX/ILI9341 SPI/xpt2046.h: -------------------------------------------------------------------------------- 1 | /* 2 | * touch.h 3 | * 4 | * Created on: Jan 6, 2020 5 | * Author: Kotetsu Yamamoto 6 | * Copyright [Kotetsu Yamamoto] 7 | 8 | MIT License 9 | 10 | Copyright (c) 2020 Kotestu Yamamoto 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a copy 13 | of this software and associated documentation files (the "Software"), to deal 14 | in the Software without restriction, including without limitation the rights 15 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 | copies of the Software, and to permit persons to whom the Software is 17 | furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in all 20 | copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 | SOFTWARE. 29 | 30 | */ 31 | 32 | #ifndef INC_TOUCH_H_ 33 | #define INC_TOUCH_H_ 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #include "main.h" 40 | 41 | #define TP_PRES_DOWN 0x80 42 | #define TP_CATH_PRES 0x40 43 | #define CMD_RDX 0xD0 44 | #define CMD_RDY 0x90 45 | #define XPT_XMIN 350 46 | #define XPT_YMIN 350 47 | #define XPT_XMAX 3800 48 | #define XPT_YMAX 3600 49 | #define XPT_WIDTH (XPT_XMAX - XPT_XMIN) 50 | #define XPT_HEIGHT (XPT_YMAX - XPT_YMIN) 51 | 52 | void XPT2046_Init(void); 53 | void XPT2046_Update(uint16_t *x, uint16_t *y); 54 | uint8_t XPT2046_IsReasonable(uint16_t x, uint16_t y); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif /* INC_TOUCH_H_ */ 61 | -------------------------------------------------------------------------------- /UART CIRCULAR BUFFER/README.md: -------------------------------------------------------------------------------- 1 | ## UART CIRCULAR BUFFER with DMA 2 | 3 | 1. In the CubeMX, enable the UART interrupt 4 | 2. In the DMA section, use the NORMAL mode. 5 | 3. ``` IN the Generated code, make sure the DMA is initialized before the UART. CubeMX sometimes does the opposite and in that case, DMA won't work.``` 6 | 4. Change the UART and the DMA in the ``uartRingBufDMA.c`` file 7 | 5. Define the RxBuf and MainBuf Sizes 8 | 6. check how the timeout is defined as the external variable in the STM32xxxxIT.c file. Also put the ```TIMEOUT--``` in the systick handler 9 | 7. check the main file to see the usage of the functions 10 | 8. The functions are commented as per their usage, you can read them. 11 | 12 | ### CORTEX M7 Users needs to be careful about memory management. You can check out the video series on the same below 13 | https://www.youtube.com/playlist?list=PLfIJKC1ud8gjoY2McCCqkxXWuwiC2iSap 14 | 15 | ## Check out the Video on Usage and application https://youtu.be/ly3_JEC_d9w 16 | -------------------------------------------------------------------------------- /UART CIRCULAR BUFFER/UART_F4_Multi_Test.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | Dma.Request0=USART1_RX 3 | Dma.RequestsNb=1 4 | Dma.USART1_RX.0.Direction=DMA_PERIPH_TO_MEMORY 5 | Dma.USART1_RX.0.FIFOMode=DMA_FIFOMODE_DISABLE 6 | Dma.USART1_RX.0.Instance=DMA2_Stream2 7 | Dma.USART1_RX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE 8 | Dma.USART1_RX.0.MemInc=DMA_MINC_ENABLE 9 | Dma.USART1_RX.0.Mode=DMA_NORMAL 10 | Dma.USART1_RX.0.PeriphDataAlignment=DMA_PDATAALIGN_BYTE 11 | Dma.USART1_RX.0.PeriphInc=DMA_PINC_DISABLE 12 | Dma.USART1_RX.0.Priority=DMA_PRIORITY_LOW 13 | Dma.USART1_RX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode 14 | File.Version=6 15 | KeepUserPlacement=false 16 | Mcu.Family=STM32F4 17 | Mcu.IP0=DMA 18 | Mcu.IP1=NVIC 19 | Mcu.IP2=RCC 20 | Mcu.IP3=SYS 21 | Mcu.IP4=USART1 22 | Mcu.IP5=USART2 23 | Mcu.IPNb=6 24 | Mcu.Name=STM32F446R(C-E)Tx 25 | Mcu.Package=LQFP64 26 | Mcu.Pin0=PH0-OSC_IN 27 | Mcu.Pin1=PH1-OSC_OUT 28 | Mcu.Pin2=PA2 29 | Mcu.Pin3=PA3 30 | Mcu.Pin4=PA5 31 | Mcu.Pin5=PA10 32 | Mcu.Pin6=PB6 33 | Mcu.Pin7=VP_SYS_VS_Systick 34 | Mcu.PinsNb=8 35 | Mcu.ThirdPartyNb=0 36 | Mcu.UserConstants= 37 | Mcu.UserName=STM32F446RETx 38 | MxCube.Version=6.3.0 39 | MxDb.Version=DB.6.0.30 40 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 41 | NVIC.DMA2_Stream2_IRQn=true\:0\:0\:false\:false\:true\:false\:true 42 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false 43 | NVIC.ForceEnableDMAVector=true 44 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 45 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false 46 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false 47 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false 48 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 49 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false 50 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true 51 | NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true 52 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false 53 | PA10.Mode=Asynchronous 54 | PA10.Signal=USART1_RX 55 | PA2.Mode=Asynchronous 56 | PA2.Signal=USART2_TX 57 | PA3.Mode=Asynchronous 58 | PA3.Signal=USART2_RX 59 | PA5.Locked=true 60 | PA5.Signal=GPIO_Output 61 | PB6.Locked=true 62 | PB6.Mode=Asynchronous 63 | PB6.Signal=USART1_TX 64 | PH0-OSC_IN.Mode=HSE-External-Clock-Source 65 | PH0-OSC_IN.Signal=RCC_OSC_IN 66 | PH1-OSC_OUT.Mode=HSE-External-Clock-Source 67 | PH1-OSC_OUT.Signal=RCC_OSC_OUT 68 | PinOutPanel.RotationAngle=0 69 | ProjectManager.AskForMigrate=true 70 | ProjectManager.BackupPrevious=false 71 | ProjectManager.CompilerOptimize=6 72 | ProjectManager.ComputerToolchain=false 73 | ProjectManager.CoupleFile=false 74 | ProjectManager.CustomerFirmwarePackage= 75 | ProjectManager.DefaultFWLocation=true 76 | ProjectManager.DeletePrevious=true 77 | ProjectManager.DeviceId=STM32F446RETx 78 | ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.26.2 79 | ProjectManager.FreePins=false 80 | ProjectManager.HalAssertFull=false 81 | ProjectManager.HeapSize=0x200 82 | ProjectManager.KeepUserCode=true 83 | ProjectManager.LastFirmware=true 84 | ProjectManager.LibraryCopy=1 85 | ProjectManager.MainLocation=Core/Src 86 | ProjectManager.NoMain=false 87 | ProjectManager.PreviousToolchain= 88 | ProjectManager.ProjectBuild=false 89 | ProjectManager.ProjectFileName=UART_F4_Multi_Test.ioc 90 | ProjectManager.ProjectName=UART_F4_Multi_Test 91 | ProjectManager.RegisterCallBack= 92 | ProjectManager.StackSize=0x400 93 | ProjectManager.TargetToolchain=STM32CubeIDE 94 | ProjectManager.ToolChainLocation= 95 | ProjectManager.UnderRoot=true 96 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-MX_DMA_Init-DMA-false-HAL-true,3-SystemClock_Config-RCC-false-HAL-false,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_USART1_UART_Init-USART1-false-HAL-true 97 | RCC.AHBFreq_Value=180000000 98 | RCC.APB1CLKDivider=RCC_HCLK_DIV4 99 | RCC.APB1Freq_Value=45000000 100 | RCC.APB1TimFreq_Value=90000000 101 | RCC.APB2CLKDivider=RCC_HCLK_DIV2 102 | RCC.APB2Freq_Value=90000000 103 | RCC.APB2TimFreq_Value=180000000 104 | RCC.CECFreq_Value=32786.88524590164 105 | RCC.CortexFreq_Value=180000000 106 | RCC.FCLKCortexFreq_Value=180000000 107 | RCC.FMPI2C1Freq_Value=45000000 108 | RCC.FamilyName=M 109 | RCC.HCLKFreq_Value=180000000 110 | RCC.HSE_VALUE=8000000 111 | RCC.I2S1Freq_Value=48000000 112 | RCC.I2S2Freq_Value=48000000 113 | RCC.IPParameters=AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CECFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FMPI2C1Freq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,I2S1Freq_Value,I2S2Freq_Value,MCO2PinFreq_Value,PLLCLKFreq_Value,PLLI2SPCLKFreq_Value,PLLI2SQCLKFreq_Value,PLLI2SRCLKFreq_Value,PLLI2SoutputFreq_Value,PLLM,PLLN,PLLQCLKFreq_Value,PLLRCLKFreq_Value,PLLSAIPCLKFreq_Value,PLLSAIQCLKFreq_Value,PLLSAIoutputFreq_Value,PLLSourceVirtual,PWRFreq_Value,SAIAFreq_Value,SAIBFreq_Value,SDIOFreq_Value,SPDIFRXFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,USBFreq_Value,VCOI2SInputFreq_Value,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value,VCOSAIInputFreq_Value,VCOSAIOutputFreq_Value 114 | RCC.MCO2PinFreq_Value=180000000 115 | RCC.PLLCLKFreq_Value=180000000 116 | RCC.PLLI2SPCLKFreq_Value=48000000 117 | RCC.PLLI2SQCLKFreq_Value=48000000 118 | RCC.PLLI2SRCLKFreq_Value=48000000 119 | RCC.PLLI2SoutputFreq_Value=48000000 120 | RCC.PLLM=4 121 | RCC.PLLN=180 122 | RCC.PLLQCLKFreq_Value=180000000 123 | RCC.PLLRCLKFreq_Value=180000000 124 | RCC.PLLSAIPCLKFreq_Value=48000000 125 | RCC.PLLSAIQCLKFreq_Value=48000000 126 | RCC.PLLSAIoutputFreq_Value=48000000 127 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 128 | RCC.PWRFreq_Value=180000000 129 | RCC.SAIAFreq_Value=48000000 130 | RCC.SAIBFreq_Value=48000000 131 | RCC.SDIOFreq_Value=180000000 132 | RCC.SPDIFRXFreq_Value=180000000 133 | RCC.SYSCLKFreq_VALUE=180000000 134 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 135 | RCC.USBFreq_Value=180000000 136 | RCC.VCOI2SInputFreq_Value=500000 137 | RCC.VCOI2SOutputFreq_Value=96000000 138 | RCC.VCOInputFreq_Value=2000000 139 | RCC.VCOOutputFreq_Value=360000000 140 | RCC.VCOSAIInputFreq_Value=500000 141 | RCC.VCOSAIOutputFreq_Value=96000000 142 | USART1.IPParameters=VirtualMode 143 | USART1.VirtualMode=VM_ASYNC 144 | USART2.IPParameters=VirtualMode 145 | USART2.VirtualMode=VM_ASYNC 146 | VP_SYS_VS_Systick.Mode=SysTick 147 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 148 | board=custom 149 | isbadioc=false 150 | -------------------------------------------------------------------------------- /UART CIRCULAR BUFFER/stm32f4xx_it.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.c 5 | * @brief Interrupt Service Routines. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

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

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Includes ------------------------------------------------------------------*/ 22 | #include "main.h" 23 | #include "stm32f4xx_it.h" 24 | /* Private includes ----------------------------------------------------------*/ 25 | /* USER CODE BEGIN Includes */ 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN PD */ 35 | 36 | /* USER CODE END PD */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN PM */ 40 | 41 | /* USER CODE END PM */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* Private user code ---------------------------------------------------------*/ 54 | /* USER CODE BEGIN 0 */ 55 | extern int32_t TIMEOUT; 56 | /* USER CODE END 0 */ 57 | 58 | /* External variables --------------------------------------------------------*/ 59 | extern DMA_HandleTypeDef hdma_usart1_rx; 60 | extern UART_HandleTypeDef huart1; 61 | /* USER CODE BEGIN EV */ 62 | 63 | /* USER CODE END EV */ 64 | 65 | /******************************************************************************/ 66 | /* Cortex-M4 Processor Interruption and Exception Handlers */ 67 | /******************************************************************************/ 68 | /** 69 | * @brief This function handles Non maskable interrupt. 70 | */ 71 | void NMI_Handler(void) 72 | { 73 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 74 | 75 | /* USER CODE END NonMaskableInt_IRQn 0 */ 76 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 77 | while (1) 78 | { 79 | } 80 | /* USER CODE END NonMaskableInt_IRQn 1 */ 81 | } 82 | 83 | /** 84 | * @brief This function handles Hard fault interrupt. 85 | */ 86 | void HardFault_Handler(void) 87 | { 88 | /* USER CODE BEGIN HardFault_IRQn 0 */ 89 | 90 | /* USER CODE END HardFault_IRQn 0 */ 91 | while (1) 92 | { 93 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */ 94 | /* USER CODE END W1_HardFault_IRQn 0 */ 95 | } 96 | } 97 | 98 | /** 99 | * @brief This function handles Memory management fault. 100 | */ 101 | void MemManage_Handler(void) 102 | { 103 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 104 | 105 | /* USER CODE END MemoryManagement_IRQn 0 */ 106 | while (1) 107 | { 108 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ 109 | /* USER CODE END W1_MemoryManagement_IRQn 0 */ 110 | } 111 | } 112 | 113 | /** 114 | * @brief This function handles Pre-fetch fault, memory access fault. 115 | */ 116 | void BusFault_Handler(void) 117 | { 118 | /* USER CODE BEGIN BusFault_IRQn 0 */ 119 | 120 | /* USER CODE END BusFault_IRQn 0 */ 121 | while (1) 122 | { 123 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */ 124 | /* USER CODE END W1_BusFault_IRQn 0 */ 125 | } 126 | } 127 | 128 | /** 129 | * @brief This function handles Undefined instruction or illegal state. 130 | */ 131 | void UsageFault_Handler(void) 132 | { 133 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 134 | 135 | /* USER CODE END UsageFault_IRQn 0 */ 136 | while (1) 137 | { 138 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ 139 | /* USER CODE END W1_UsageFault_IRQn 0 */ 140 | } 141 | } 142 | 143 | /** 144 | * @brief This function handles System service call via SWI instruction. 145 | */ 146 | void SVC_Handler(void) 147 | { 148 | /* USER CODE BEGIN SVCall_IRQn 0 */ 149 | 150 | /* USER CODE END SVCall_IRQn 0 */ 151 | /* USER CODE BEGIN SVCall_IRQn 1 */ 152 | 153 | /* USER CODE END SVCall_IRQn 1 */ 154 | } 155 | 156 | /** 157 | * @brief This function handles Debug monitor. 158 | */ 159 | void DebugMon_Handler(void) 160 | { 161 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 162 | 163 | /* USER CODE END DebugMonitor_IRQn 0 */ 164 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 165 | 166 | /* USER CODE END DebugMonitor_IRQn 1 */ 167 | } 168 | 169 | /** 170 | * @brief This function handles Pendable request for system service. 171 | */ 172 | void PendSV_Handler(void) 173 | { 174 | /* USER CODE BEGIN PendSV_IRQn 0 */ 175 | 176 | /* USER CODE END PendSV_IRQn 0 */ 177 | /* USER CODE BEGIN PendSV_IRQn 1 */ 178 | 179 | /* USER CODE END PendSV_IRQn 1 */ 180 | } 181 | 182 | /** 183 | * @brief This function handles System tick timer. 184 | */ 185 | void SysTick_Handler(void) 186 | { 187 | /* USER CODE BEGIN SysTick_IRQn 0 */ 188 | 189 | /* USER CODE END SysTick_IRQn 0 */ 190 | HAL_IncTick(); 191 | /* USER CODE BEGIN SysTick_IRQn 1 */ 192 | 193 | TIMEOUT--; 194 | 195 | /* USER CODE END SysTick_IRQn 1 */ 196 | } 197 | 198 | /******************************************************************************/ 199 | /* STM32F4xx Peripheral Interrupt Handlers */ 200 | /* Add here the Interrupt Handlers for the used peripherals. */ 201 | /* For the available peripheral interrupt handler names, */ 202 | /* please refer to the startup file (startup_stm32f4xx.s). */ 203 | /******************************************************************************/ 204 | 205 | /** 206 | * @brief This function handles USART1 global interrupt. 207 | */ 208 | void USART1_IRQHandler(void) 209 | { 210 | /* USER CODE BEGIN USART1_IRQn 0 */ 211 | 212 | /* USER CODE END USART1_IRQn 0 */ 213 | HAL_UART_IRQHandler(&huart1); 214 | /* USER CODE BEGIN USART1_IRQn 1 */ 215 | 216 | /* USER CODE END USART1_IRQn 1 */ 217 | } 218 | 219 | /** 220 | * @brief This function handles DMA2 stream2 global interrupt. 221 | */ 222 | void DMA2_Stream2_IRQHandler(void) 223 | { 224 | /* USER CODE BEGIN DMA2_Stream2_IRQn 0 */ 225 | 226 | /* USER CODE END DMA2_Stream2_IRQn 0 */ 227 | HAL_DMA_IRQHandler(&hdma_usart1_rx); 228 | /* USER CODE BEGIN DMA2_Stream2_IRQn 1 */ 229 | 230 | /* USER CODE END DMA2_Stream2_IRQn 1 */ 231 | } 232 | 233 | /* USER CODE BEGIN 1 */ 234 | 235 | /* USER CODE END 1 */ 236 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 237 | -------------------------------------------------------------------------------- /UART CIRCULAR BUFFER/uartRingBufDMA.h: -------------------------------------------------------------------------------- 1 | /* 2 | * uartRingBufDMA.h 3 | * 4 | * Created on: Aug 12, 2021 5 | * Author: controllerstech.com 6 | */ 7 | 8 | #ifndef INC_UARTRINGBUFDMA_H_ 9 | #define INC_UARTRINGBUFDMA_H_ 10 | 11 | 12 | /* Initialize the Ring buffer 13 | * It will also initialize the UART RECEIVE DMA 14 | * */ 15 | void Ringbuf_Init (void); 16 | 17 | /* Reset the ring buffer 18 | * Resets the Head and Tail, also the buffers 19 | * */ 20 | void Ringbuf_Reset (void); 21 | 22 | 23 | uint8_t checkString (char *str, char *buffertolookinto); 24 | 25 | /* waits for a particular string in the Rx Buffer 26 | * By Default it is set to wait for "OK", you can change the string in the HAL_UARTEx_RxEventCallback function 27 | * This function will wait in the blocking mode, so to avoid the halt, we will also include the timeout 28 | * The timeout is in milliseconds 29 | * returns 1 on success 30 | * returns 0 on failure 31 | * */ 32 | uint8_t isConfirmed (int32_t Timeout); 33 | 34 | 35 | /* Waits for a particular string to arrive in the incoming buffer 36 | * returns 1, if the string is detected 37 | */ 38 | int waitFor (char *string, uint32_t Timeout); 39 | 40 | 41 | /* copies the data from the incoming buffer into the provided buffer 42 | * Must be used if you are sure that the data is being received 43 | * it will copy irrespective of, if the end string is there or not 44 | * if the end string gets copied, it returns 1 or else 0 45 | * 46 | */ 47 | int copyUpto (char *string, char *buffertocopyinto, uint32_t Timeout); 48 | 49 | 50 | /* Copies the entered number of characters, after the entered string (from the incoming buffer), into the buffer 51 | * returns 1 on success 52 | * returns 0 on failure 53 | */ 54 | int getAfter (char *string, uint8_t numberofchars, char *buffertocopyinto, uint32_t Timeout); 55 | 56 | 57 | 58 | 59 | #endif /* INC_UARTRINGBUFDMA_H_ */ 60 | --------------------------------------------------------------------------------