├── .gitignore ├── Inc ├── gpio.h ├── mxconstants.h ├── rng.h ├── spi.h ├── stm32f7xx_hal_conf.h ├── stm32f7xx_it.h ├── tim.h └── usart.h ├── LCD example project.rar ├── LCD.ioc ├── LICENSE ├── README.md └── Src ├── ILI9341 ├── 5x5_font.h ├── ILI9341_GFX.c ├── ILI9341_GFX.h ├── ILI9341_STM32_Driver.c ├── ILI9341_STM32_Driver.h ├── ILI9341_Touchscreen.c ├── ILI9341_Touchscreen.h └── snow_tiger.h ├── gpio.c ├── main.c ├── rng.c ├── spi.c ├── stm32f7xx_hal_msp.c ├── stm32f7xx_it.c ├── tim.c └── usart.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : gpio.h 4 | * Description : This file contains all the functions prototypes for 5 | * the gpio 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Define to prevent recursive inclusion -------------------------------------*/ 36 | #ifndef __gpio_H 37 | #define __gpio_H 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | #include "stm32f7xx_hal.h" 44 | 45 | /* USER CODE BEGIN Includes */ 46 | 47 | /* USER CODE END Includes */ 48 | 49 | /* USER CODE BEGIN Private defines */ 50 | 51 | /* USER CODE END Private defines */ 52 | 53 | void MX_GPIO_Init(void); 54 | 55 | /* USER CODE BEGIN Prototypes */ 56 | 57 | /* USER CODE END Prototypes */ 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | #endif /*__ pinoutConfig_H */ 63 | 64 | /** 65 | * @} 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 73 | -------------------------------------------------------------------------------- /Inc/mxconstants.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : mxconstants.h 4 | * Description : This file contains the common defines of the application 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2017 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | /* Define to prevent recursive inclusion -------------------------------------*/ 34 | #ifndef __MXCONSTANT_H 35 | #define __MXCONSTANT_H 36 | /* Includes ------------------------------------------------------------------*/ 37 | 38 | /* USER CODE BEGIN Includes */ 39 | 40 | /* USER CODE END Includes */ 41 | 42 | /* Private define ------------------------------------------------------------*/ 43 | 44 | #define T_IRQ_Pin GPIO_PIN_2 45 | #define T_IRQ_GPIO_Port GPIOE 46 | #define T_CLK_Pin GPIO_PIN_3 47 | #define T_CLK_GPIO_Port GPIOE 48 | #define T_MISO_Pin GPIO_PIN_4 49 | #define T_MISO_GPIO_Port GPIOE 50 | #define T_MOSI_Pin GPIO_PIN_5 51 | #define T_MOSI_GPIO_Port GPIOE 52 | #define T_CS_Pin GPIO_PIN_6 53 | #define T_CS_GPIO_Port GPIOE 54 | #define User_Blue_Button_Pin GPIO_PIN_13 55 | #define User_Blue_Button_GPIO_Port GPIOC 56 | #define MCO_Pin GPIO_PIN_0 57 | #define MCO_GPIO_Port GPIOH 58 | #define RMII_MDC_Pin GPIO_PIN_1 59 | #define RMII_MDC_GPIO_Port GPIOC 60 | #define RMII_REF_CLK_Pin GPIO_PIN_1 61 | #define RMII_REF_CLK_GPIO_Port GPIOA 62 | #define RMII_MDIO_Pin GPIO_PIN_2 63 | #define RMII_MDIO_GPIO_Port GPIOA 64 | #define RMII_CRS_DV_Pin GPIO_PIN_7 65 | #define RMII_CRS_DV_GPIO_Port GPIOA 66 | #define RMII_RXD0_Pin GPIO_PIN_4 67 | #define RMII_RXD0_GPIO_Port GPIOC 68 | #define RMII_RXD1_Pin GPIO_PIN_5 69 | #define RMII_RXD1_GPIO_Port GPIOC 70 | #define RMII_TXD1_Pin GPIO_PIN_13 71 | #define RMII_TXD1_GPIO_Port GPIOB 72 | #define LD3_Pin GPIO_PIN_14 73 | #define LD3_GPIO_Port GPIOB 74 | #define STLK_RX_Pin GPIO_PIN_8 75 | #define STLK_RX_GPIO_Port GPIOD 76 | #define STLK_TX_Pin GPIO_PIN_9 77 | #define STLK_TX_GPIO_Port GPIOD 78 | #define USB_PowerSwitchOn_Pin GPIO_PIN_6 79 | #define USB_PowerSwitchOn_GPIO_Port GPIOG 80 | #define USB_OverCurrent_Pin GPIO_PIN_7 81 | #define USB_OverCurrent_GPIO_Port GPIOG 82 | #define CS_Pin GPIO_PIN_8 83 | #define CS_GPIO_Port GPIOC 84 | #define DC_Pin GPIO_PIN_9 85 | #define DC_GPIO_Port GPIOC 86 | #define USB_SOF_Pin GPIO_PIN_8 87 | #define USB_SOF_GPIO_Port GPIOA 88 | #define USB_VBUS_Pin GPIO_PIN_9 89 | #define USB_VBUS_GPIO_Port GPIOA 90 | #define USB_ID_Pin GPIO_PIN_10 91 | #define USB_ID_GPIO_Port GPIOA 92 | #define USB_DM_Pin GPIO_PIN_11 93 | #define USB_DM_GPIO_Port GPIOA 94 | #define USB_DP_Pin GPIO_PIN_12 95 | #define USB_DP_GPIO_Port GPIOA 96 | #define TMS_Pin GPIO_PIN_13 97 | #define TMS_GPIO_Port GPIOA 98 | #define TCK_Pin GPIO_PIN_14 99 | #define TCK_GPIO_Port GPIOA 100 | #define RST_Pin GPIO_PIN_10 101 | #define RST_GPIO_Port GPIOC 102 | #define RMII_TX_EN_Pin GPIO_PIN_11 103 | #define RMII_TX_EN_GPIO_Port GPIOG 104 | #define RMII_TXD0_Pin GPIO_PIN_13 105 | #define RMII_TXD0_GPIO_Port GPIOG 106 | #define SWO_Pin GPIO_PIN_3 107 | #define SWO_GPIO_Port GPIOB 108 | #define LD2_Pin GPIO_PIN_7 109 | #define LD2_GPIO_Port GPIOB 110 | /* USER CODE BEGIN Private defines */ 111 | 112 | /* USER CODE END Private defines */ 113 | 114 | /** 115 | * @} 116 | */ 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | #endif /* __MXCONSTANT_H */ 123 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 124 | -------------------------------------------------------------------------------- /Inc/rng.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : RNG.h 4 | * Description : This file provides code for the configuration 5 | * of the RNG instances. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __rng_H 36 | #define __rng_H 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* Includes ------------------------------------------------------------------*/ 42 | #include "stm32f7xx_hal.h" 43 | 44 | /* USER CODE BEGIN Includes */ 45 | 46 | /* USER CODE END Includes */ 47 | 48 | extern RNG_HandleTypeDef hrng; 49 | 50 | /* USER CODE BEGIN Private defines */ 51 | 52 | /* USER CODE END Private defines */ 53 | 54 | extern void Error_Handler(void); 55 | 56 | void MX_RNG_Init(void); 57 | 58 | /* USER CODE BEGIN Prototypes */ 59 | 60 | /* USER CODE END Prototypes */ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | #endif /*__ rng_H */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 76 | -------------------------------------------------------------------------------- /Inc/spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : SPI.h 4 | * Description : This file provides code for the configuration 5 | * of the SPI instances. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __spi_H 36 | #define __spi_H 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* Includes ------------------------------------------------------------------*/ 42 | #include "stm32f7xx_hal.h" 43 | 44 | /* USER CODE BEGIN Includes */ 45 | 46 | /* USER CODE END Includes */ 47 | 48 | extern SPI_HandleTypeDef hspi5; 49 | 50 | /* USER CODE BEGIN Private defines */ 51 | 52 | /* USER CODE END Private defines */ 53 | 54 | extern void Error_Handler(void); 55 | 56 | void MX_SPI5_Init(void); 57 | 58 | /* USER CODE BEGIN Prototypes */ 59 | 60 | /* USER CODE END Prototypes */ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | #endif /*__ spi_H */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 76 | -------------------------------------------------------------------------------- /Inc/stm32f7xx_hal_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f7xx_hal_conf.h 4 | * @brief HAL configuration file. 5 | ****************************************************************************** 6 | * @attention 7 | * 8 | *

© COPYRIGHT(c) 2017 STMicroelectronics

9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Define to prevent recursive inclusion -------------------------------------*/ 36 | #ifndef __STM32F7xx_HAL_CONF_H 37 | #define __STM32F7xx_HAL_CONF_H 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #include "mxconstants.h" 44 | 45 | /* Exported types ------------------------------------------------------------*/ 46 | /* Exported constants --------------------------------------------------------*/ 47 | 48 | /* ########################## Module Selection ############################## */ 49 | /** 50 | * @brief This is the list of modules to be used in the HAL driver 51 | */ 52 | #define HAL_MODULE_ENABLED 53 | 54 | /* #define HAL_ADC_MODULE_ENABLED */ 55 | /* #define HAL_CAN_MODULE_ENABLED */ 56 | /* #define HAL_CEC_MODULE_ENABLED */ 57 | /* #define HAL_CRC_MODULE_ENABLED */ 58 | /* #define HAL_CRYP_MODULE_ENABLED */ 59 | /* #define HAL_DAC_MODULE_ENABLED */ 60 | /* #define HAL_DCMI_MODULE_ENABLED */ 61 | /* #define HAL_DMA2D_MODULE_ENABLED */ 62 | /* #define HAL_ETH_MODULE_ENABLED */ 63 | /* #define HAL_NAND_MODULE_ENABLED */ 64 | /* #define HAL_NOR_MODULE_ENABLED */ 65 | /* #define HAL_SRAM_MODULE_ENABLED */ 66 | /* #define HAL_SDRAM_MODULE_ENABLED */ 67 | /* #define HAL_HASH_MODULE_ENABLED */ 68 | /* #define HAL_I2S_MODULE_ENABLED */ 69 | /* #define HAL_IWDG_MODULE_ENABLED */ 70 | /* #define HAL_LPTIM_MODULE_ENABLED */ 71 | /* #define HAL_LTDC_MODULE_ENABLED */ 72 | /* #define HAL_QSPI_MODULE_ENABLED */ 73 | #define HAL_RNG_MODULE_ENABLED 74 | /* #define HAL_RTC_MODULE_ENABLED */ 75 | /* #define HAL_SAI_MODULE_ENABLED */ 76 | /* #define HAL_SD_MODULE_ENABLED */ 77 | /* #define HAL_SPDIFRX_MODULE_ENABLED */ 78 | #define HAL_SPI_MODULE_ENABLED 79 | #define HAL_TIM_MODULE_ENABLED 80 | #define HAL_UART_MODULE_ENABLED 81 | /* #define HAL_USART_MODULE_ENABLED */ 82 | /* #define HAL_IRDA_MODULE_ENABLED */ 83 | /* #define HAL_SMARTCARD_MODULE_ENABLED */ 84 | /* #define HAL_WWDG_MODULE_ENABLED */ 85 | /* #define HAL_PCD_MODULE_ENABLED */ 86 | /* #define HAL_HCD_MODULE_ENABLED */ 87 | /* #define HAL_DFSDM_MODULE_ENABLED */ 88 | /* #define HAL_DSI_MODULE_ENABLED */ 89 | /* #define HAL_JPEG_MODULE_ENABLED */ 90 | /* #define HAL_MDIOS_MODULE_ENABLED */ 91 | #define HAL_GPIO_MODULE_ENABLED 92 | #define HAL_DMA_MODULE_ENABLED 93 | #define HAL_RCC_MODULE_ENABLED 94 | #define HAL_FLASH_MODULE_ENABLED 95 | #define HAL_PWR_MODULE_ENABLED 96 | #define HAL_I2C_MODULE_ENABLED 97 | #define HAL_CORTEX_MODULE_ENABLED 98 | 99 | /* ########################## HSE/HSI Values adaptation ##################### */ 100 | /** 101 | * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. 102 | * This value is used by the RCC HAL module to compute the system frequency 103 | * (when HSE is used as system clock source, directly or through the PLL). 104 | */ 105 | #if !defined (HSE_VALUE) 106 | #define HSE_VALUE ((uint32_t)8000000U) /*!< Value of the External oscillator in Hz */ 107 | #endif /* HSE_VALUE */ 108 | 109 | #if !defined (HSE_STARTUP_TIMEOUT) 110 | #define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */ 111 | #endif /* HSE_STARTUP_TIMEOUT */ 112 | 113 | /** 114 | * @brief Internal High Speed oscillator (HSI) value. 115 | * This value is used by the RCC HAL module to compute the system frequency 116 | * (when HSI is used as system clock source, directly or through the PLL). 117 | */ 118 | #if !defined (HSI_VALUE) 119 | #define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/ 120 | #endif /* HSI_VALUE */ 121 | 122 | /** 123 | * @brief Internal Low Speed oscillator (LSI) value. 124 | */ 125 | #if !defined (LSI_VALUE) 126 | #define LSI_VALUE ((uint32_t)40000U) /*!< LSI Typical Value in Hz*/ 127 | #endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz 128 | The real value may vary depending on the variations 129 | in voltage and temperature. */ 130 | /** 131 | * @brief External Low Speed oscillator (LSE) value. 132 | */ 133 | #if !defined (LSE_VALUE) 134 | #define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External Low Speed oscillator in Hz */ 135 | #endif /* LSE_VALUE */ 136 | 137 | #if !defined (LSE_STARTUP_TIMEOUT) 138 | #define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */ 139 | #endif /* LSE_STARTUP_TIMEOUT */ 140 | 141 | /** 142 | * @brief External clock source for I2S peripheral 143 | * This value is used by the I2S HAL module to compute the I2S clock source 144 | * frequency, this source is inserted directly through I2S_CKIN pad. 145 | */ 146 | #if !defined (EXTERNAL_CLOCK_VALUE) 147 | #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000U) /*!< Value of the Internal oscillator in Hz*/ 148 | #endif /* EXTERNAL_CLOCK_VALUE */ 149 | 150 | /* Tip: To avoid modifying this file each time you need to use different HSE, 151 | === you can define the HSE value in your toolchain compiler preprocessor. */ 152 | 153 | /* ########################### System Configuration ######################### */ 154 | /** 155 | * @brief This is the HAL system configuration section 156 | */ 157 | #define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */ 158 | #define TICK_INT_PRIORITY ((uint32_t)0U) /*!< tick interrupt priority */ 159 | #define USE_RTOS 0U 160 | #define PREFETCH_ENABLE 1U 161 | #define ART_ACCLERATOR_ENABLE 1U /* To enable instruction cache and prefetch */ 162 | 163 | /* ########################## Assert Selection ############################## */ 164 | /** 165 | * @brief Uncomment the line below to expanse the "assert_param" macro in the 166 | * HAL drivers code 167 | */ 168 | /* #define USE_FULL_ASSERT 1 */ 169 | 170 | /* ################## Ethernet peripheral configuration ##################### */ 171 | 172 | /* Section 1 : Ethernet peripheral configuration */ 173 | 174 | /* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */ 175 | #define MAC_ADDR0 2U 176 | #define MAC_ADDR1 0U 177 | #define MAC_ADDR2 0U 178 | #define MAC_ADDR3 0U 179 | #define MAC_ADDR4 0U 180 | #define MAC_ADDR5 0U 181 | 182 | /* Definition of the Ethernet driver buffers size and count */ 183 | #define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */ 184 | #define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */ 185 | #define ETH_RXBUFNB ((uint32_t)4U) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */ 186 | #define ETH_TXBUFNB ((uint32_t)4U) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */ 187 | 188 | /* Section 2: PHY configuration section */ 189 | 190 | /* DP83848_PHY_ADDRESS Address*/ 191 | #define DP83848_PHY_ADDRESS 0x01U 192 | /* PHY Reset delay these values are based on a 1 ms Systick interrupt*/ 193 | #define PHY_RESET_DELAY ((uint32_t)0x000000FFU) 194 | /* PHY Configuration delay */ 195 | #define PHY_CONFIG_DELAY ((uint32_t)0x00000FFFU) 196 | 197 | #define PHY_READ_TO ((uint32_t)0x0000FFFFU) 198 | #define PHY_WRITE_TO ((uint32_t)0x0000FFFFU) 199 | 200 | /* Section 3: Common PHY Registers */ 201 | 202 | #define PHY_BCR ((uint16_t)0x00U) /*!< Transceiver Basic Control Register */ 203 | #define PHY_BSR ((uint16_t)0x01U) /*!< Transceiver Basic Status Register */ 204 | 205 | #define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */ 206 | #define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */ 207 | #define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */ 208 | #define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */ 209 | #define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */ 210 | #define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */ 211 | #define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */ 212 | #define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */ 213 | #define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */ 214 | #define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */ 215 | 216 | #define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */ 217 | #define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */ 218 | #define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */ 219 | 220 | /* Section 4: Extended PHY Registers */ 221 | 222 | #define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */ 223 | #define PHY_MICR ((uint16_t)0x11U) /*!< MII Interrupt Control Register */ 224 | #define PHY_MISR ((uint16_t)0x12U) /*!< MII Interrupt Status and Misc. Control Register */ 225 | 226 | #define PHY_LINK_STATUS ((uint16_t)0x0001U) /*!< PHY Link mask */ 227 | #define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */ 228 | #define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */ 229 | 230 | #define PHY_MICR_INT_EN ((uint16_t)0x0002U) /*!< PHY Enable interrupts */ 231 | #define PHY_MICR_INT_OE ((uint16_t)0x0001U) /*!< PHY Enable output interrupt events */ 232 | 233 | #define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020U) /*!< Enable Interrupt on change of link status */ 234 | #define PHY_LINK_INTERRUPT ((uint16_t)0x2000U) /*!< PHY link status interrupt mask */ 235 | 236 | /* ################## SPI peripheral configuration ########################## */ 237 | 238 | /* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver 239 | * Activated: CRC code is present inside driver 240 | * Deactivated: CRC code cleaned from driver 241 | */ 242 | 243 | #define USE_SPI_CRC 0U 244 | 245 | /* Includes ------------------------------------------------------------------*/ 246 | /** 247 | * @brief Include module's header file 248 | */ 249 | 250 | #ifdef HAL_RCC_MODULE_ENABLED 251 | #include "stm32f7xx_hal_rcc.h" 252 | #endif /* HAL_RCC_MODULE_ENABLED */ 253 | 254 | #ifdef HAL_GPIO_MODULE_ENABLED 255 | #include "stm32f7xx_hal_gpio.h" 256 | #endif /* HAL_GPIO_MODULE_ENABLED */ 257 | 258 | #ifdef HAL_DMA_MODULE_ENABLED 259 | #include "stm32f7xx_hal_dma.h" 260 | #endif /* HAL_DMA_MODULE_ENABLED */ 261 | 262 | #ifdef HAL_CORTEX_MODULE_ENABLED 263 | #include "stm32f7xx_hal_cortex.h" 264 | #endif /* HAL_CORTEX_MODULE_ENABLED */ 265 | 266 | #ifdef HAL_ADC_MODULE_ENABLED 267 | #include "stm32f7xx_hal_adc.h" 268 | #endif /* HAL_ADC_MODULE_ENABLED */ 269 | 270 | #ifdef HAL_CAN_MODULE_ENABLED 271 | #include "stm32f7xx_hal_can.h" 272 | #endif /* HAL_CAN_MODULE_ENABLED */ 273 | 274 | #ifdef HAL_CEC_MODULE_ENABLED 275 | #include "stm32f7xx_hal_cec.h" 276 | #endif /* HAL_CEC_MODULE_ENABLED */ 277 | 278 | #ifdef HAL_CRC_MODULE_ENABLED 279 | #include "stm32f7xx_hal_crc.h" 280 | #endif /* HAL_CRC_MODULE_ENABLED */ 281 | 282 | #ifdef HAL_CRYP_MODULE_ENABLED 283 | #include "stm32f7xx_hal_cryp.h" 284 | #endif /* HAL_CRYP_MODULE_ENABLED */ 285 | 286 | #ifdef HAL_DMA2D_MODULE_ENABLED 287 | #include "stm32f7xx_hal_dma2d.h" 288 | #endif /* HAL_DMA2D_MODULE_ENABLED */ 289 | 290 | #ifdef HAL_DAC_MODULE_ENABLED 291 | #include "stm32f7xx_hal_dac.h" 292 | #endif /* HAL_DAC_MODULE_ENABLED */ 293 | 294 | #ifdef HAL_DCMI_MODULE_ENABLED 295 | #include "stm32f7xx_hal_dcmi.h" 296 | #endif /* HAL_DCMI_MODULE_ENABLED */ 297 | 298 | #ifdef HAL_ETH_MODULE_ENABLED 299 | #include "stm32f7xx_hal_eth.h" 300 | #endif /* HAL_ETH_MODULE_ENABLED */ 301 | 302 | #ifdef HAL_FLASH_MODULE_ENABLED 303 | #include "stm32f7xx_hal_flash.h" 304 | #endif /* HAL_FLASH_MODULE_ENABLED */ 305 | 306 | #ifdef HAL_SRAM_MODULE_ENABLED 307 | #include "stm32f7xx_hal_sram.h" 308 | #endif /* HAL_SRAM_MODULE_ENABLED */ 309 | 310 | #ifdef HAL_NOR_MODULE_ENABLED 311 | #include "stm32f7xx_hal_nor.h" 312 | #endif /* HAL_NOR_MODULE_ENABLED */ 313 | 314 | #ifdef HAL_NAND_MODULE_ENABLED 315 | #include "stm32f7xx_hal_nand.h" 316 | #endif /* HAL_NAND_MODULE_ENABLED */ 317 | 318 | #ifdef HAL_SDRAM_MODULE_ENABLED 319 | #include "stm32f7xx_hal_sdram.h" 320 | #endif /* HAL_SDRAM_MODULE_ENABLED */ 321 | 322 | #ifdef HAL_HASH_MODULE_ENABLED 323 | #include "stm32f7xx_hal_hash.h" 324 | #endif /* HAL_HASH_MODULE_ENABLED */ 325 | 326 | #ifdef HAL_I2C_MODULE_ENABLED 327 | #include "stm32f7xx_hal_i2c.h" 328 | #endif /* HAL_I2C_MODULE_ENABLED */ 329 | 330 | #ifdef HAL_I2S_MODULE_ENABLED 331 | #include "stm32f7xx_hal_i2s.h" 332 | #endif /* HAL_I2S_MODULE_ENABLED */ 333 | 334 | #ifdef HAL_IWDG_MODULE_ENABLED 335 | #include "stm32f7xx_hal_iwdg.h" 336 | #endif /* HAL_IWDG_MODULE_ENABLED */ 337 | 338 | #ifdef HAL_LPTIM_MODULE_ENABLED 339 | #include "stm32f7xx_hal_lptim.h" 340 | #endif /* HAL_LPTIM_MODULE_ENABLED */ 341 | 342 | #ifdef HAL_LTDC_MODULE_ENABLED 343 | #include "stm32f7xx_hal_ltdc.h" 344 | #endif /* HAL_LTDC_MODULE_ENABLED */ 345 | 346 | #ifdef HAL_PWR_MODULE_ENABLED 347 | #include "stm32f7xx_hal_pwr.h" 348 | #endif /* HAL_PWR_MODULE_ENABLED */ 349 | 350 | #ifdef HAL_QSPI_MODULE_ENABLED 351 | #include "stm32f7xx_hal_qspi.h" 352 | #endif /* HAL_QSPI_MODULE_ENABLED */ 353 | 354 | #ifdef HAL_RNG_MODULE_ENABLED 355 | #include "stm32f7xx_hal_rng.h" 356 | #endif /* HAL_RNG_MODULE_ENABLED */ 357 | 358 | #ifdef HAL_RTC_MODULE_ENABLED 359 | #include "stm32f7xx_hal_rtc.h" 360 | #endif /* HAL_RTC_MODULE_ENABLED */ 361 | 362 | #ifdef HAL_SAI_MODULE_ENABLED 363 | #include "stm32f7xx_hal_sai.h" 364 | #endif /* HAL_SAI_MODULE_ENABLED */ 365 | 366 | #ifdef HAL_SD_MODULE_ENABLED 367 | #include "stm32f7xx_hal_sd.h" 368 | #endif /* HAL_SD_MODULE_ENABLED */ 369 | 370 | #ifdef HAL_SPDIFRX_MODULE_ENABLED 371 | #include "stm32f7xx_hal_spdifrx.h" 372 | #endif /* HAL_SPDIFRX_MODULE_ENABLED */ 373 | 374 | #ifdef HAL_SPI_MODULE_ENABLED 375 | #include "stm32f7xx_hal_spi.h" 376 | #endif /* HAL_SPI_MODULE_ENABLED */ 377 | 378 | #ifdef HAL_TIM_MODULE_ENABLED 379 | #include "stm32f7xx_hal_tim.h" 380 | #endif /* HAL_TIM_MODULE_ENABLED */ 381 | 382 | #ifdef HAL_UART_MODULE_ENABLED 383 | #include "stm32f7xx_hal_uart.h" 384 | #endif /* HAL_UART_MODULE_ENABLED */ 385 | 386 | #ifdef HAL_USART_MODULE_ENABLED 387 | #include "stm32f7xx_hal_usart.h" 388 | #endif /* HAL_USART_MODULE_ENABLED */ 389 | 390 | #ifdef HAL_IRDA_MODULE_ENABLED 391 | #include "stm32f7xx_hal_irda.h" 392 | #endif /* HAL_IRDA_MODULE_ENABLED */ 393 | 394 | #ifdef HAL_SMARTCARD_MODULE_ENABLED 395 | #include "stm32f7xx_hal_smartcard.h" 396 | #endif /* HAL_SMARTCARD_MODULE_ENABLED */ 397 | 398 | #ifdef HAL_WWDG_MODULE_ENABLED 399 | #include "stm32f7xx_hal_wwdg.h" 400 | #endif /* HAL_WWDG_MODULE_ENABLED */ 401 | 402 | #ifdef HAL_PCD_MODULE_ENABLED 403 | #include "stm32f7xx_hal_pcd.h" 404 | #endif /* HAL_PCD_MODULE_ENABLED */ 405 | 406 | #ifdef HAL_HCD_MODULE_ENABLED 407 | #include "stm32f7xx_hal_hcd.h" 408 | #endif /* HAL_HCD_MODULE_ENABLED */ 409 | 410 | #ifdef HAL_DFSDM_MODULE_ENABLED 411 | #include "stm32f7xx_hal_dfsdm.h" 412 | #endif /* HAL_DFSDM_MODULE_ENABLED */ 413 | 414 | #ifdef HAL_DSI_MODULE_ENABLED 415 | #include "stm32f7xx_hal_dsi.h" 416 | #endif /* HAL_DSI_MODULE_ENABLED */ 417 | 418 | #ifdef HAL_JPEG_MODULE_ENABLED 419 | #include "stm32f7xx_hal_jpeg.h" 420 | #endif /* HAL_JPEG_MODULE_ENABLED */ 421 | 422 | #ifdef HAL_MDIOS_MODULE_ENABLED 423 | #include "stm32f7xx_hal_mdios.h" 424 | #endif /* HAL_MDIOS_MODULE_ENABLED */ 425 | /* Exported macro ------------------------------------------------------------*/ 426 | #ifdef USE_FULL_ASSERT 427 | /** 428 | * @brief The assert_param macro is used for function's parameters check. 429 | * @param expr: If expr is false, it calls assert_failed function 430 | * which reports the name of the source file and the source 431 | * line number of the call that failed. 432 | * If expr is true, it returns no value. 433 | * @retval None 434 | */ 435 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 436 | /* Exported functions ------------------------------------------------------- */ 437 | void assert_failed(uint8_t* file, uint32_t line); 438 | #else 439 | #define assert_param(expr) ((void)0) 440 | #endif /* USE_FULL_ASSERT */ 441 | 442 | #ifdef __cplusplus 443 | } 444 | #endif 445 | 446 | #endif /* __STM32F7xx_HAL_CONF_H */ 447 | 448 | 449 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 450 | -------------------------------------------------------------------------------- /Inc/stm32f7xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f7xx_it.h 4 | * @brief This file contains the headers of the interrupt handlers. 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2017 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __STM32F7xx_IT_H 36 | #define __STM32F7xx_IT_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | /* Exported types ------------------------------------------------------------*/ 44 | /* Exported constants --------------------------------------------------------*/ 45 | /* Exported macro ------------------------------------------------------------*/ 46 | /* Exported functions ------------------------------------------------------- */ 47 | 48 | void SysTick_Handler(void); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* __STM32F7xx_IT_H */ 55 | 56 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 57 | -------------------------------------------------------------------------------- /Inc/tim.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : TIM.h 4 | * Description : This file provides code for the configuration 5 | * of the TIM instances. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __tim_H 36 | #define __tim_H 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* Includes ------------------------------------------------------------------*/ 42 | #include "stm32f7xx_hal.h" 43 | 44 | /* USER CODE BEGIN Includes */ 45 | 46 | /* USER CODE END Includes */ 47 | 48 | extern TIM_HandleTypeDef htim1; 49 | 50 | /* USER CODE BEGIN Private defines */ 51 | 52 | /* USER CODE END Private defines */ 53 | 54 | extern void Error_Handler(void); 55 | 56 | void MX_TIM1_Init(void); 57 | 58 | /* USER CODE BEGIN Prototypes */ 59 | 60 | /* USER CODE END Prototypes */ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | #endif /*__ tim_H */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 76 | -------------------------------------------------------------------------------- /Inc/usart.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : USART.h 4 | * Description : This file provides code for the configuration 5 | * of the USART instances. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __usart_H 36 | #define __usart_H 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* Includes ------------------------------------------------------------------*/ 42 | #include "stm32f7xx_hal.h" 43 | 44 | /* USER CODE BEGIN Includes */ 45 | 46 | /* USER CODE END Includes */ 47 | 48 | extern UART_HandleTypeDef huart3; 49 | 50 | /* USER CODE BEGIN Private defines */ 51 | 52 | /* USER CODE END Private defines */ 53 | 54 | extern void Error_Handler(void); 55 | 56 | void MX_USART3_UART_Init(void); 57 | 58 | /* USER CODE BEGIN Prototypes */ 59 | 60 | /* USER CODE END Prototypes */ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | #endif /*__ usart_H */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 76 | -------------------------------------------------------------------------------- /LCD example project.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martnak/STM32-ILI9341/2ed24b6fbbd080bb79a21d21ba395926898ce31a/LCD example project.rar -------------------------------------------------------------------------------- /LCD.ioc: -------------------------------------------------------------------------------- 1 | #MicroXplorer Configuration settings - do not modify 2 | CORTEX_M7.ART_ACCLERATOR_ENABLE=1 3 | CORTEX_M7.CPU_DCache=Enabled 4 | CORTEX_M7.CPU_ICache=Enabled 5 | CORTEX_M7.FlashInterface=AXI_Enabled 6 | CORTEX_M7.IPParameters=ART_ACCLERATOR_ENABLE,PREFETCH_ENABLE,CPU_ICache,CPU_DCache,FlashInterface 7 | CORTEX_M7.PREFETCH_ENABLE=1 8 | File.Version=6 9 | KeepUserPlacement=true 10 | Mcu.Family=STM32F7 11 | Mcu.IP0=CORTEX_M7 12 | Mcu.IP1=NVIC 13 | Mcu.IP2=RCC 14 | Mcu.IP3=RNG 15 | Mcu.IP4=SPI5 16 | Mcu.IP5=SYS 17 | Mcu.IP6=TIM1 18 | Mcu.IP7=USART3 19 | Mcu.IPNb=8 20 | Mcu.Name=STM32F746Z(E-G)Tx 21 | Mcu.Package=LQFP144 22 | Mcu.Pin0=PE2 23 | Mcu.Pin1=PE3 24 | Mcu.Pin10=PF9 25 | Mcu.Pin11=PH0/OSC_IN 26 | Mcu.Pin12=PH1/OSC_OUT 27 | Mcu.Pin13=PC1 28 | Mcu.Pin14=PA1 29 | Mcu.Pin15=PA2 30 | Mcu.Pin16=PA7 31 | Mcu.Pin17=PC4 32 | Mcu.Pin18=PC5 33 | Mcu.Pin19=PB13 34 | Mcu.Pin2=PE4 35 | Mcu.Pin20=PB14 36 | Mcu.Pin21=PD8 37 | Mcu.Pin22=PD9 38 | Mcu.Pin23=PG6 39 | Mcu.Pin24=PG7 40 | Mcu.Pin25=PC8 41 | Mcu.Pin26=PC9 42 | Mcu.Pin27=PA8 43 | Mcu.Pin28=PA9 44 | Mcu.Pin29=PA10 45 | Mcu.Pin3=PE5 46 | Mcu.Pin30=PA11 47 | Mcu.Pin31=PA12 48 | Mcu.Pin32=PA13 49 | Mcu.Pin33=PA14 50 | Mcu.Pin34=PC10 51 | Mcu.Pin35=PG11 52 | Mcu.Pin36=PG13 53 | Mcu.Pin37=PB3 54 | Mcu.Pin38=PB7 55 | Mcu.Pin39=VP_RNG_VS_RNG 56 | Mcu.Pin4=PE6 57 | Mcu.Pin40=VP_SYS_VS_Systick 58 | Mcu.Pin41=VP_TIM1_VS_ClockSourceINT 59 | Mcu.Pin5=PC13 60 | Mcu.Pin6=PC14/OSC32_IN 61 | Mcu.Pin7=PC15/OSC32_OUT 62 | Mcu.Pin8=PF7 63 | Mcu.Pin9=PF8 64 | Mcu.PinsNb=42 65 | Mcu.UserConstants= 66 | Mcu.UserName=STM32F746ZGTx 67 | MxCube.Version=4.15.1 68 | MxDb.Version=DB.4.0.151 69 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:false 70 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:false 71 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:false 72 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:false 73 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:false 74 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:false 75 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 76 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:false 77 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true 78 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:false 79 | PA1.GPIOParameters=GPIO_Label 80 | PA1.GPIO_Label=RMII_REF_CLK [LAN8742A-CZ-TR_REFCLK0] 81 | PA1.Locked=true 82 | PA1.Signal=ETH_REF_CLK 83 | PA10.GPIOParameters=GPIO_Label 84 | PA10.GPIO_Label=USB_ID 85 | PA10.Locked=true 86 | PA10.Signal=USB_OTG_FS_ID 87 | PA11.GPIOParameters=GPIO_Label 88 | PA11.GPIO_Label=USB_DM 89 | PA11.Locked=true 90 | PA11.Signal=USB_OTG_FS_DM 91 | PA12.GPIOParameters=GPIO_Label 92 | PA12.GPIO_Label=USB_DP 93 | PA12.Locked=true 94 | PA12.Signal=USB_OTG_FS_DP 95 | PA13.GPIOParameters=GPIO_Label 96 | PA13.GPIO_Label=TMS 97 | PA13.Locked=true 98 | PA13.Mode=Serial_Wire 99 | PA13.Signal=SYS_JTMS-SWDIO 100 | PA14.GPIOParameters=GPIO_Label 101 | PA14.GPIO_Label=TCK 102 | PA14.Locked=true 103 | PA14.Mode=Serial_Wire 104 | PA14.Signal=SYS_JTCK-SWCLK 105 | PA2.GPIOParameters=GPIO_Label 106 | PA2.GPIO_Label=RMII_MDIO [LAN8742A-CZ-TR_MDIO] 107 | PA2.Locked=true 108 | PA2.Signal=ETH_MDIO 109 | PA7.GPIOParameters=GPIO_Label 110 | PA7.GPIO_Label=RMII_CRS_DV [LAN8742A-CZ-TR_CRS_DV] 111 | PA7.Locked=true 112 | PA7.Signal=ETH_CRS_DV 113 | PA8.GPIOParameters=GPIO_Label 114 | PA8.GPIO_Label=USB_SOF [TP1] 115 | PA8.Locked=true 116 | PA8.Signal=USB_OTG_FS_SOF 117 | PA9.GPIOParameters=GPIO_Label 118 | PA9.GPIO_Label=USB_VBUS 119 | PA9.Locked=true 120 | PA9.Signal=USB_OTG_FS_VBUS 121 | PB13.GPIOParameters=GPIO_Label 122 | PB13.GPIO_Label=RMII_TXD1 [LAN8742A-CZ-TR_TXD1] 123 | PB13.Locked=true 124 | PB13.Signal=ETH_TXD1 125 | PB14.GPIOParameters=GPIO_Label 126 | PB14.GPIO_Label=LD3 [Red] 127 | PB14.Locked=true 128 | PB14.Signal=GPIO_Output 129 | PB3.GPIOParameters=GPIO_Label 130 | PB3.GPIO_Label=SWO 131 | PB3.Locked=true 132 | PB3.Signal=SYS_JTDO-SWO 133 | PB7.GPIOParameters=GPIO_Label 134 | PB7.GPIO_Label=LD2 [Blue] 135 | PB7.Locked=true 136 | PB7.Signal=GPIO_Output 137 | PC1.GPIOParameters=GPIO_Label 138 | PC1.GPIO_Label=RMII_MDC [LAN8742A-CZ-TR_MDC] 139 | PC1.Locked=true 140 | PC1.Signal=ETH_MDC 141 | PC10.GPIOParameters=GPIO_Label,GPIO_Speed 142 | PC10.GPIO_Label=RST 143 | PC10.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 144 | PC10.Locked=true 145 | PC10.Signal=GPIO_Output 146 | PC13.GPIOParameters=GPIO_Label 147 | PC13.GPIO_Label=User Blue Button [B1] 148 | PC13.Locked=true 149 | PC13.Signal=GPIO_Input 150 | PC14/OSC32_IN.Locked=true 151 | PC14/OSC32_IN.Mode=LSE-External-Oscillator 152 | PC14/OSC32_IN.Signal=RCC_OSC32_IN 153 | PC15/OSC32_OUT.Locked=true 154 | PC15/OSC32_OUT.Mode=LSE-External-Oscillator 155 | PC15/OSC32_OUT.Signal=RCC_OSC32_OUT 156 | PC4.GPIOParameters=GPIO_Label 157 | PC4.GPIO_Label=RMII_RXD0 [LAN8742A-CZ-TR_RXD0] 158 | PC4.Locked=true 159 | PC4.Signal=ETH_RXD0 160 | PC5.GPIOParameters=GPIO_Label 161 | PC5.GPIO_Label=RMII_RXD1 [LAN8742A-CZ-TR_RXD1] 162 | PC5.Locked=true 163 | PC5.Signal=ETH_RXD1 164 | PC8.GPIOParameters=GPIO_Label,GPIO_Speed 165 | PC8.GPIO_Label=CS 166 | PC8.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 167 | PC8.Locked=true 168 | PC8.Signal=GPIO_Output 169 | PC9.GPIOParameters=GPIO_Label,GPIO_Speed 170 | PC9.GPIO_Label=DC 171 | PC9.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 172 | PC9.Signal=GPIO_Output 173 | PCC.Checker=false 174 | PCC.Line=STM32F7x6 175 | PCC.MCU=STM32F746Z(E-G)Tx 176 | PCC.MXVersion=4.15.1 177 | PCC.PartNumber=STM32F746ZGTx 178 | PCC.Seq0=0 179 | PCC.Series=STM32F7 180 | PCC.Temperature=25 181 | PCC.Vdd=3.6 182 | PD8.GPIOParameters=GPIO_Label 183 | PD8.GPIO_Label=STLK_RX [STM32F103CBT6_PA3] 184 | PD8.Locked=true 185 | PD8.Mode=Asynchronous 186 | PD8.Signal=USART3_TX 187 | PD9.GPIOParameters=GPIO_Label 188 | PD9.GPIO_Label=STLK_TX [STM32F103CBT6_PA2] 189 | PD9.Locked=true 190 | PD9.Mode=Asynchronous 191 | PD9.Signal=USART3_RX 192 | PE2.GPIOParameters=GPIO_Label,GPIO_PuPd 193 | PE2.GPIO_Label=T_IRQ 194 | PE2.GPIO_PuPd=GPIO_NOPULL 195 | PE2.Locked=true 196 | PE2.Signal=GPIO_Input 197 | PE3.GPIOParameters=GPIO_Label,GPIO_Speed 198 | PE3.GPIO_Label=T_CLK 199 | PE3.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 200 | PE3.Locked=true 201 | PE3.Signal=GPIO_Output 202 | PE4.GPIOParameters=GPIO_Label,GPIO_PuPd 203 | PE4.GPIO_Label=T_MISO 204 | PE4.GPIO_PuPd=GPIO_PULLUP 205 | PE4.Locked=true 206 | PE4.Signal=GPIO_Input 207 | PE5.GPIOParameters=GPIO_Label,GPIO_Speed,GPIO_PuPd 208 | PE5.GPIO_Label=T_MOSI 209 | PE5.GPIO_PuPd=GPIO_NOPULL 210 | PE5.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 211 | PE5.Locked=true 212 | PE5.Signal=GPIO_Output 213 | PE6.GPIOParameters=GPIO_Label,GPIO_Speed,GPIO_PuPd 214 | PE6.GPIO_Label=T_CS 215 | PE6.GPIO_PuPd=GPIO_NOPULL 216 | PE6.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH 217 | PE6.Locked=true 218 | PE6.Signal=GPIO_Output 219 | PF7.Mode=Full_Duplex_Master 220 | PF7.Signal=SPI5_SCK 221 | PF8.Mode=Full_Duplex_Master 222 | PF8.Signal=SPI5_MISO 223 | PF9.Mode=Full_Duplex_Master 224 | PF9.Signal=SPI5_MOSI 225 | PG11.GPIOParameters=GPIO_Label 226 | PG11.GPIO_Label=RMII_TX_EN [LAN8742A-CZ-TR_TXEN] 227 | PG11.Locked=true 228 | PG11.Signal=ETH_TX_EN 229 | PG13.GPIOParameters=GPIO_Label 230 | PG13.GPIO_Label=RMII_TXD0 [LAN8742A-CZ-TR_TXD0] 231 | PG13.Locked=true 232 | PG13.Signal=ETH_TXD0 233 | PG6.GPIOParameters=GPIO_Label 234 | PG6.GPIO_Label=USB_PowerSwitchOn [STMPS2151STR_EN] 235 | PG6.Locked=true 236 | PG6.Signal=GPIO_Output 237 | PG7.GPIOParameters=GPIO_Label 238 | PG7.GPIO_Label=USB_OverCurrent [STMPS2151STR_FAULT] 239 | PG7.Locked=true 240 | PG7.Signal=GPIO_Input 241 | PH0/OSC_IN.GPIOParameters=GPIO_Label 242 | PH0/OSC_IN.GPIO_Label=MCO [STM32F103CBT6_PA8] 243 | PH0/OSC_IN.Locked=true 244 | PH0/OSC_IN.Mode=HSE-External-Clock-Source 245 | PH0/OSC_IN.Signal=RCC_OSC_IN 246 | PH1/OSC_OUT.Locked=true 247 | PH1/OSC_OUT.Mode=HSE-External-Clock-Source 248 | PH1/OSC_OUT.Signal=RCC_OSC_OUT 249 | ProjectManager.AskForMigrate=true 250 | ProjectManager.BackupPrevious=false 251 | ProjectManager.CompilerOptimize=2 252 | ProjectManager.ComputerToolchain=false 253 | ProjectManager.CoupleFile=true 254 | ProjectManager.DeletePrevious=true 255 | ProjectManager.DeviceId=STM32F746ZGTx 256 | ProjectManager.FirmwarePackage=STM32Cube FW_F7 V1.4.1 257 | ProjectManager.FreePins=false 258 | ProjectManager.HalAssertFull=false 259 | ProjectManager.HeapSize=0x200 260 | ProjectManager.KeepUserCode=true 261 | ProjectManager.LastFirmware=true 262 | ProjectManager.LibraryCopy=0 263 | ProjectManager.PreviousToolchain= 264 | ProjectManager.ProjectBuild=false 265 | ProjectManager.ProjectFileName=LCD.ioc 266 | ProjectManager.ProjectName=LCD 267 | ProjectManager.StackSize=0x400 268 | ProjectManager.TargetToolchain=MDK-ARM V5 269 | ProjectManager.ToolChainLocation=C\:\\Users\\Theoldknight\\Desktop\\BITBUCKET PROJECTS\\STM32F7 ILI9341\\LCD 270 | ProjectManager.UnderRoot=false 271 | ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false,2-MX_USART3_UART_Init-USART3-false,3-MX_SPI5_Init-SPI5-false,4-MX_RNG_Init-RNG-false,5-MX_TIM1_Init-TIM1-false 272 | RCC.48MHZClocksFreq_Value=24000000 273 | RCC.ADC12outputFreq_Value=72000000 274 | RCC.ADC34outputFreq_Value=72000000 275 | RCC.AHBFreq_Value=200000000 276 | RCC.APB1CLKDivider=RCC_HCLK_DIV4 277 | RCC.APB1Freq_Value=50000000 278 | RCC.APB1TimFreq_Value=100000000 279 | RCC.APB2CLKDivider=RCC_HCLK_DIV2 280 | RCC.APB2Freq_Value=100000000 281 | RCC.APB2TimFreq_Value=200000000 282 | RCC.CECFreq_Value=32786.88524590164 283 | RCC.CortexFreq_Value=200000000 284 | RCC.EthernetFreq_Value=200000000 285 | RCC.FCLKCortexFreq_Value=200000000 286 | RCC.FamilyName=M 287 | RCC.HCLKFreq_Value=200000000 288 | RCC.HSE_VALUE=8000000 289 | RCC.HSI_VALUE=16000000 290 | RCC.I2C1Freq_Value=50000000 291 | RCC.I2C2Freq_Value=50000000 292 | RCC.I2C3Freq_Value=50000000 293 | RCC.I2C4Freq_Value=50000000 294 | RCC.I2SClocksFreq_Value=48000000 295 | RCC.I2SFreq_Value=192000000 296 | RCC.IPParameters=48MHZClocksFreq_Value,ADC12outputFreq_Value,ADC34outputFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2CLKDivider,APB2Freq_Value,APB2TimFreq_Value,CECFreq_Value,CortexFreq_Value,EthernetFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2C4Freq_Value,I2SClocksFreq_Value,I2SFreq_Value,LCDTFToutputFreq_Value,LPTIM1Freq_Value,LSI_VALUE,MCO1PinFreq_Value,MCO2PinFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLI2SPCLKFreq_Value,PLLI2SQCLKFreq_Value,PLLI2SRCLKFreq_Value,PLLI2SRoutputFreq_Value,PLLM,PLLMCOFreq_Value,PLLMUL,PLLN,PLLQ,PLLQCLKFreq_Value,PLLQoutputFreq_Value,PLLSAIPCLKFreq_Value,PLLSAIQCLKFreq_Value,PLLSAIRCLKFreq_Value,PLLSAIoutputFreq_Value,PLLSourceVirtual,PRESCALERUSB,RNGFreq_Value,RTCFreq_Value,RTCHSEDivFreq_Value,SAI1Freq_Value,SAI2Freq_Value,SDMMCFreq_Value,SPDIFRXFreq_Value,SYSCLKFreq_VALUE,SYSCLKSource,SYSCLKSourceVirtual,TIM15Freq_Value,TIM16Freq_Value,TIM17Freq_Value,TIM1Freq_Value,TIM20Freq_Value,TIM2Freq_Value,TIM3Freq_Value,TIM8Freq_Value,UART4Freq_Value,UART5Freq_Value,UART7Freq_Value,UART8Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USART6Freq_Value,USBFreq_Value,VCOI2SOutputFreq_Value,VCOInputFreq_Value,VCOOutput2Freq_Value,VCOOutputFreq_Value,VCOSAIOutputFreq_Value,VcooutputI2S,WatchDogFreq_Value 297 | RCC.LCDTFToutputFreq_Value=96000000 298 | RCC.LPTIM1Freq_Value=50000000 299 | RCC.LSI_VALUE=40000 300 | RCC.MCO1PinFreq_Value=16000000 301 | RCC.MCO2PinFreq_Value=200000000 302 | RCC.MCOFreq_Value=72000000 303 | RCC.PLLCLKFreq_Value=200000000 304 | RCC.PLLI2SPCLKFreq_Value=192000000 305 | RCC.PLLI2SQCLKFreq_Value=192000000 306 | RCC.PLLI2SRCLKFreq_Value=192000000 307 | RCC.PLLI2SRoutputFreq_Value=192000000 308 | RCC.PLLM=4 309 | RCC.PLLMCOFreq_Value=72000000 310 | RCC.PLLMUL=RCC_PLL_MUL9 311 | RCC.PLLN=200 312 | RCC.PLLQ=9 313 | RCC.PLLQCLKFreq_Value=44444444.44444445 314 | RCC.PLLQoutputFreq_Value=44444444.44444445 315 | RCC.PLLSAIPCLKFreq_Value=192000000 316 | RCC.PLLSAIQCLKFreq_Value=192000000 317 | RCC.PLLSAIRCLKFreq_Value=192000000 318 | RCC.PLLSAIoutputFreq_Value=192000000 319 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE 320 | RCC.PRESCALERUSB=RCC_USBCLKSOURCE_PLL_DIV1_5 321 | RCC.RNGFreq_Value=44444444.44444445 322 | RCC.RTCFreq_Value=40000 323 | RCC.RTCHSEDivFreq_Value=4000000 324 | RCC.SAI1Freq_Value=192000000 325 | RCC.SAI2Freq_Value=192000000 326 | RCC.SDMMCFreq_Value=200000000 327 | RCC.SPDIFRXFreq_Value=192000000 328 | RCC.SYSCLKFreq_VALUE=200000000 329 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK 330 | RCC.SYSCLKSourceVirtual=RCC_SYSCLKSOURCE_PLLCLK 331 | RCC.TIM15Freq_Value=72000000 332 | RCC.TIM16Freq_Value=72000000 333 | RCC.TIM17Freq_Value=72000000 334 | RCC.TIM1Freq_Value=72000000 335 | RCC.TIM20Freq_Value=72000000 336 | RCC.TIM2Freq_Value=72000000 337 | RCC.TIM3Freq_Value=72000000 338 | RCC.TIM8Freq_Value=72000000 339 | RCC.UART4Freq_Value=50000000 340 | RCC.UART5Freq_Value=50000000 341 | RCC.UART7Freq_Value=50000000 342 | RCC.UART8Freq_Value=50000000 343 | RCC.USART1Freq_Value=100000000 344 | RCC.USART2Freq_Value=50000000 345 | RCC.USART3Freq_Value=50000000 346 | RCC.USART6Freq_Value=100000000 347 | RCC.USBFreq_Value=44444444.44444445 348 | RCC.VCOI2SOutputFreq_Value=384000000 349 | RCC.VCOInputFreq_Value=2000000 350 | RCC.VCOOutput2Freq_Value=8000000 351 | RCC.VCOOutputFreq_Value=400000000 352 | RCC.VCOSAIOutputFreq_Value=384000000 353 | RCC.VcooutputI2S=48000000 354 | RCC.WatchDogFreq_Value=40000 355 | SPI5.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_2 356 | SPI5.CalculateBaudRate=50.0 MBits/s 357 | SPI5.DataSize=SPI_DATASIZE_8BIT 358 | SPI5.IPParameters=Mode,CalculateBaudRate,BaudRatePrescaler,DataSize,NSSPMode 359 | SPI5.Mode=SPI_MODE_MASTER 360 | SPI5.NSSPMode=SPI_NSS_PULSE_DISABLE 361 | TIM1.ClockDivision=TIM_CLOCKDIVISION_DIV2 362 | TIM1.IPParameters=Period,Prescaler,ClockDivision 363 | TIM1.Period=65535 364 | TIM1.Prescaler=10000 365 | VP_RNG_VS_RNG.Mode=RNG_Activate 366 | VP_RNG_VS_RNG.Signal=RNG_VS_RNG 367 | VP_SYS_VS_Systick.Mode=SysTick 368 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick 369 | VP_TIM1_VS_ClockSourceINT.Mode=Internal 370 | VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT 371 | board=NUCLEO-F746ZG 372 | boardIOC=true 373 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 martnak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STM32-ILI9341 2 | Simple driver for ILI9341 320x240 TFT LCD with Touchscreen for STM32 microcontrollers 3 | 4 | Requires no DMA or Interrupts while still maintaining very fast screen draws. See performance analysis below 5 | 6 | The intent of this library is to provide a really simple way to get ILI9341 projects started without complex methods. 7 | Basic SPI and GPIO inputs/Outputs are enough to use the library. 8 | 9 | Contains: 10 | - main driver for initialization and basic functions "ILI9341_STM32_Driver" 11 | - GFX driver for advanced functionality (fonts, pictures) 12 | - Touchscreen driver 13 | - Example project with CubeMX built for STM32F746ZG Nucleo board 14 | - Example usage of functions 15 | 16 | Downloading project and setting up example based on STM32F7: 17 | - Extract the project into a folder and run CubeMX project 18 | - Generate code using CubeMX 19 | - Add ILI9341 folder to flash->configure flash tools->C/C++ ->Include paths 20 | - Add files in ILI9341 folder to project (Add existing files to group...) 21 | 22 | Alternatively download entire project in .rar file. Paths might be broken and might require re-linking. 23 | ¯\\_(ツ)_/¯ 24 | 25 | ILI9341 Driver library for STM32 26 | 27 | 28 | While there are other libraries for ILI9341 they mostly require either interrupts, DMA or both for fast drawing 29 | The intent of this library is to offer a simple yet still reasonably fast alternatives for those that 30 | do not wish to use interrupts or DMA in their projects. 31 | 32 | Library is written for STM32 HAL library and supports STM32CUBEMX. To use the library with Cube software 33 | you need to tick the box that generates peripheral initialization code in their own respective .c and .h file 34 | 35 | 36 | Performance 37 | 38 | Settings: 39 | - SPI @ 50MHz 40 | - STM32F746ZG Nucleo board 41 | - Redraw entire screen 42 | 43 | Theoretical maximum FPS with 50Mhz SPI calculated to be 40.69 FPS 44 | 45 | 320x240 = 76800 pixels, each pixel contains 16bit colour information (2x8) 46 | Theoretical Max FPS: 1/((320x240x16)/50000000) 47 | 48 | With ART Accelerator, instruction prefetch, CPU ICACHE and CPU DCACHE enabled: 49 | 50 | - FPS: 39.62 51 | - SPI utilization: 97.37% 52 | - MB/Second: 6.09 53 | 54 | With ART Accelerator, instruction prefetch, CPU ICACHE and CPU DCACHE disabled: 55 | 56 | - FPS: 35.45 57 | - SPI utilization: 87.12% 58 | - MB/Second: 5.44 59 | 60 | ART Accelerator, instruction prefetch, CPU ICACHE and CPU DCACHE settings found in MXCUBE under "System-> CORTEX M7 button" 61 | 62 | -------------------------------------------------------------------------------- /Src/ILI9341/5x5_font.h: -------------------------------------------------------------------------------- 1 | #ifndef BASIC_5X5_FONT_H 2 | #define BASIC_5X5_FONT_H 3 | 4 | #define CHAR_WIDTH 6 5 | #define CHAR_HEIGHT 8 6 | 7 | static const unsigned char font[96][6] = { 8 | {0x00,0x00,0x00,0x00,0x00,0x00}, // 9 | {0x5c,0x00,0x00,0x00,0x00,0x00}, // ! 10 | {0x06,0x00,0x06,0x00,0x00,0x00}, // " 11 | {0x28,0x7c,0x28,0x7c,0x28,0x00}, // # 12 | {0x5c,0x54,0xfe,0x54,0x74,0x00}, // $ 13 | {0x44,0x20,0x10,0x08,0x44,0x00}, // % 14 | {0x28,0x54,0x54,0x20,0x50,0x00}, // & 15 | {0x06,0x00,0x00,0x00,0x00,0x00}, // ' 16 | {0x38,0x44,0x00,0x00,0x00,0x00}, // ( 17 | {0x44,0x38,0x00,0x00,0x00,0x00}, // ) 18 | {0x02,0x07,0x02,0x00,0x00,0x00}, // * 19 | {0x10,0x10,0x7c,0x10,0x10,0x00}, // + 20 | {0xc0,0x00,0x00,0x00,0x00,0x00}, // , 21 | {0x10,0x10,0x10,0x10,0x10,0x00}, // - 22 | {0x40,0x00,0x00,0x00,0x00,0x00}, // . 23 | {0x60,0x10,0x0c,0x00,0x00,0x00}, // / 24 | {0x7c,0x64,0x54,0x4c,0x7c,0x00}, // 0 25 | {0x48,0x7c,0x40,0x00,0x00,0x00}, // 1 26 | {0x64,0x54,0x54,0x54,0x48,0x00}, // 2 27 | {0x44,0x54,0x54,0x54,0x6c,0x00}, // 3 28 | {0x3c,0x20,0x70,0x20,0x20,0x00}, // 4 29 | {0x5c,0x54,0x54,0x54,0x24,0x00}, // 5 30 | {0x7c,0x54,0x54,0x54,0x74,0x00}, // 6 31 | {0x04,0x04,0x64,0x14,0x0c,0x00}, // 7 32 | {0x7c,0x54,0x54,0x54,0x7c,0x00}, // 8 33 | {0x5c,0x54,0x54,0x54,0x7c,0x00}, // 9 34 | {0x44,0x00,0x00,0x00,0x00,0x00}, // : 35 | {0xc4,0x00,0x00,0x00,0x00,0x00}, // ; 36 | {0x10,0x28,0x44,0x00,0x00,0x00}, // < 37 | {0x28,0x28,0x28,0x28,0x28,0x00}, // = 38 | {0x44,0x28,0x10,0x00,0x00,0x00}, // > 39 | {0x08,0x04,0x54,0x08,0x00,0x00}, // ? 40 | {0x7c,0x44,0x54,0x54,0x5c,0x00}, // @ 41 | {0x7c,0x24,0x24,0x24,0x7c,0x00}, // A 42 | {0x7c,0x54,0x54,0x54,0x6c,0x00}, // B 43 | {0x7c,0x44,0x44,0x44,0x44,0x00}, // C 44 | {0x7c,0x44,0x44,0x44,0x38,0x00}, // D 45 | {0x7c,0x54,0x54,0x54,0x44,0x00}, // E 46 | {0x7c,0x14,0x14,0x14,0x04,0x00}, // F 47 | {0x7c,0x44,0x44,0x54,0x74,0x00}, // G 48 | {0x7c,0x10,0x10,0x10,0x7c,0x00}, // H 49 | {0x44,0x44,0x7c,0x44,0x44,0x00}, // I 50 | {0x60,0x40,0x40,0x44,0x7c,0x00}, // J 51 | {0x7c,0x10,0x10,0x28,0x44,0x00}, // K 52 | {0x7c,0x40,0x40,0x40,0x40,0x00}, // L 53 | {0x7c,0x08,0x10,0x08,0x7c,0x00}, // M 54 | {0x7c,0x08,0x10,0x20,0x7c,0x00}, // N 55 | {0x38,0x44,0x44,0x44,0x38,0x00}, // O 56 | {0x7c,0x14,0x14,0x14,0x08,0x00}, // P 57 | {0x3c,0x24,0x64,0x24,0x3c,0x00}, // Q 58 | {0x7c,0x14,0x14,0x14,0x68,0x00}, // R 59 | {0x5c,0x54,0x54,0x54,0x74,0x00}, // S 60 | {0x04,0x04,0x7c,0x04,0x04,0x00}, // T 61 | {0x7c,0x40,0x40,0x40,0x7c,0x00}, // U 62 | {0x0c,0x30,0x40,0x30,0x0c,0x00}, // V 63 | {0x3c,0x40,0x30,0x40,0x3c,0x00}, // W 64 | {0x44,0x28,0x10,0x28,0x44,0x00}, // X 65 | {0x0c,0x10,0x60,0x10,0x0c,0x00}, // Y 66 | {0x44,0x64,0x54,0x4c,0x44,0x00}, // Z 67 | {0x7c,0x44,0x00,0x00,0x00,0x00}, // [ 68 | {0x0c,0x10,0x60,0x00,0x00,0x00}, // "\" 69 | {0x44,0x7c,0x00,0x00,0x00,0x00}, // ] 70 | {0x00,0x01,0x00,0x01,0x00,0x00}, // ^ 71 | {0x40,0x40,0x40,0x40,0x40,0x40}, // _ 72 | {0x00,0x01,0x00,0x00,0x00,0x00}, // ` 73 | {0x7c,0x24,0x24,0x24,0x7c,0x00}, // a 74 | {0x7c,0x54,0x54,0x54,0x6c,0x00}, // b 75 | {0x7c,0x44,0x44,0x44,0x44,0x00}, // c 76 | {0x7c,0x44,0x44,0x44,0x38,0x00}, // d 77 | {0x7c,0x54,0x54,0x54,0x44,0x00}, // e 78 | {0x7c,0x14,0x14,0x14,0x04,0x00}, // f 79 | {0x7c,0x44,0x44,0x54,0x74,0x00}, // g 80 | {0x7c,0x10,0x10,0x10,0x7c,0x00}, // h 81 | {0x44,0x44,0x7c,0x44,0x44,0x00}, // i 82 | {0x60,0x40,0x40,0x44,0x7c,0x00}, // j 83 | {0x7c,0x10,0x10,0x28,0x44,0x00}, // k 84 | {0x7c,0x40,0x40,0x40,0x40,0x00}, // l 85 | {0x7c,0x08,0x10,0x08,0x7c,0x00}, // m 86 | {0x7c,0x08,0x10,0x20,0x7c,0x00}, // n 87 | {0x38,0x44,0x44,0x44,0x38,0x00}, // o 88 | {0x7c,0x14,0x14,0x14,0x08,0x00}, // p 89 | {0x3c,0x24,0x64,0x24,0x3c,0x00}, // q 90 | {0x7c,0x14,0x14,0x14,0x68,0x00}, // r 91 | {0x5c,0x54,0x54,0x54,0x74,0x00}, // s 92 | {0x04,0x04,0x7c,0x04,0x04,0x00}, // t 93 | {0x7c,0x40,0x40,0x40,0x7c,0x00}, // u 94 | {0x0c,0x30,0x40,0x30,0x0c,0x00}, // v 95 | {0x3c,0x40,0x30,0x40,0x3c,0x00}, // w 96 | {0x44,0x28,0x10,0x28,0x44,0x00}, // x 97 | {0x0c,0x10,0x60,0x10,0x0c,0x00}, // y 98 | {0x44,0x64,0x54,0x4c,0x44,0x00}, // z 99 | {0x10,0x7c,0x44,0x00,0x00,0x00}, // { 100 | {0x6c,0x00,0x00,0x00,0x00,0x00}, // | 101 | {0x44,0x7c,0x10,0x00,0x00,0x00}, // } 102 | {0x02,0x01,0x02,0x01,0x00,0x00}, // ~ 103 | {0x00,0x00,0x00,0x00,0x00,0x00} 104 | }; 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /Src/ILI9341/ILI9341_GFX.c: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017 Matej Artnak 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // 24 | // 25 | //----------------------------------- 26 | // ILI9341 GFX library for STM32 27 | //----------------------------------- 28 | // 29 | // Very simple GFX library built upon ILI9342_STM32_Driver library. 30 | // Adds basic shapes, image and font drawing capabilities to ILI9341 31 | // 32 | // Library is written for STM32 HAL library and supports STM32CUBEMX. To use the library with Cube software 33 | // you need to tick the box that generates peripheral initialization code in their own respective .c and .h file 34 | // 35 | // 36 | //----------------------------------- 37 | // How to use this library 38 | //----------------------------------- 39 | // 40 | // -If using MCUs other than STM32F7 you will have to change the #include "stm32f7xx_hal.h" in the ILI9341_GFX.h to your respective .h file 41 | // 42 | // If using "ILI9341_STM32_Driver" then all other prequisites to use the library have allready been met 43 | // Simply include the library and it is ready to be used 44 | // 45 | //----------------------------------- 46 | 47 | 48 | #include "ILI9341_STM32_Driver.h" 49 | #include "ILI9341_GFX.h" 50 | #include "5x5_font.h" 51 | #include "spi.h" 52 | 53 | /*Draw hollow circle at X,Y location with specified radius and colour. X and Y represent circles center */ 54 | void ILI9341_Draw_Hollow_Circle(uint16_t X, uint16_t Y, uint16_t Radius, uint16_t Colour) 55 | { 56 | int x = Radius-1; 57 | int y = 0; 58 | int dx = 1; 59 | int dy = 1; 60 | int err = dx - (Radius << 1); 61 | 62 | while (x >= y) 63 | { 64 | ILI9341_Draw_Pixel(X + x, Y + y, Colour); 65 | ILI9341_Draw_Pixel(X + y, Y + x, Colour); 66 | ILI9341_Draw_Pixel(X - y, Y + x, Colour); 67 | ILI9341_Draw_Pixel(X - x, Y + y, Colour); 68 | ILI9341_Draw_Pixel(X - x, Y - y, Colour); 69 | ILI9341_Draw_Pixel(X - y, Y - x, Colour); 70 | ILI9341_Draw_Pixel(X + y, Y - x, Colour); 71 | ILI9341_Draw_Pixel(X + x, Y - y, Colour); 72 | 73 | if (err <= 0) 74 | { 75 | y++; 76 | err += dy; 77 | dy += 2; 78 | } 79 | if (err > 0) 80 | { 81 | x--; 82 | dx += 2; 83 | err += (-Radius << 1) + dx; 84 | } 85 | } 86 | } 87 | 88 | /*Draw filled circle at X,Y location with specified radius and colour. X and Y represent circles center */ 89 | void ILI9341_Draw_Filled_Circle(uint16_t X, uint16_t Y, uint16_t Radius, uint16_t Colour) 90 | { 91 | 92 | int x = Radius; 93 | int y = 0; 94 | int xChange = 1 - (Radius << 1); 95 | int yChange = 0; 96 | int radiusError = 0; 97 | 98 | while (x >= y) 99 | { 100 | for (int i = X - x; i <= X + x; i++) 101 | { 102 | ILI9341_Draw_Pixel(i, Y + y,Colour); 103 | ILI9341_Draw_Pixel(i, Y - y,Colour); 104 | } 105 | for (int i = X - y; i <= X + y; i++) 106 | { 107 | ILI9341_Draw_Pixel(i, Y + x,Colour); 108 | ILI9341_Draw_Pixel(i, Y - x,Colour); 109 | } 110 | 111 | y++; 112 | radiusError += yChange; 113 | yChange += 2; 114 | if (((radiusError << 1) + xChange) > 0) 115 | { 116 | x--; 117 | radiusError += xChange; 118 | xChange += 2; 119 | } 120 | } 121 | //Really slow implementation, will require future overhaul 122 | //TODO: https://stackoverflow.com/questions/1201200/fast-algorithm-for-drawing-filled-circles 123 | } 124 | 125 | /*Draw a hollow rectangle between positions X0,Y0 and X1,Y1 with specified colour*/ 126 | void ILI9341_Draw_Hollow_Rectangle_Coord(uint16_t X0, uint16_t Y0, uint16_t X1, uint16_t Y1, uint16_t Colour) 127 | { 128 | uint16_t X_length = 0; 129 | uint16_t Y_length = 0; 130 | uint8_t Negative_X = 0; 131 | uint8_t Negative_Y = 0; 132 | float Calc_Negative = 0; 133 | 134 | Calc_Negative = X1 - X0; 135 | if(Calc_Negative < 0) Negative_X = 1; 136 | Calc_Negative = 0; 137 | 138 | Calc_Negative = Y1 - Y0; 139 | if(Calc_Negative < 0) Negative_Y = 1; 140 | 141 | 142 | //DRAW HORIZONTAL! 143 | if(!Negative_X) 144 | { 145 | X_length = X1 - X0; 146 | } 147 | else 148 | { 149 | X_length = X0 - X1; 150 | } 151 | ILI9341_Draw_Horizontal_Line(X0, Y0, X_length, Colour); 152 | ILI9341_Draw_Horizontal_Line(X0, Y1, X_length, Colour); 153 | 154 | 155 | 156 | //DRAW VERTICAL! 157 | if(!Negative_Y) 158 | { 159 | Y_length = Y1 - Y0; 160 | } 161 | else 162 | { 163 | Y_length = Y0 - Y1; 164 | } 165 | ILI9341_Draw_Vertical_Line(X0, Y0, Y_length, Colour); 166 | ILI9341_Draw_Vertical_Line(X1, Y0, Y_length, Colour); 167 | 168 | if((X_length > 0)||(Y_length > 0)) 169 | { 170 | ILI9341_Draw_Pixel(X1, Y1, Colour); 171 | } 172 | 173 | } 174 | 175 | /*Draw a filled rectangle between positions X0,Y0 and X1,Y1 with specified colour*/ 176 | void ILI9341_Draw_Filled_Rectangle_Coord(uint16_t X0, uint16_t Y0, uint16_t X1, uint16_t Y1, uint16_t Colour) 177 | { 178 | uint16_t X_length = 0; 179 | uint16_t Y_length = 0; 180 | uint8_t Negative_X = 0; 181 | uint8_t Negative_Y = 0; 182 | int32_t Calc_Negative = 0; 183 | 184 | uint16_t X0_true = 0; 185 | uint16_t Y0_true = 0; 186 | 187 | Calc_Negative = X1 - X0; 188 | if(Calc_Negative < 0) Negative_X = 1; 189 | Calc_Negative = 0; 190 | 191 | Calc_Negative = Y1 - Y0; 192 | if(Calc_Negative < 0) Negative_Y = 1; 193 | 194 | 195 | //DRAW HORIZONTAL! 196 | if(!Negative_X) 197 | { 198 | X_length = X1 - X0; 199 | X0_true = X0; 200 | } 201 | else 202 | { 203 | X_length = X0 - X1; 204 | X0_true = X1; 205 | } 206 | 207 | //DRAW VERTICAL! 208 | if(!Negative_Y) 209 | { 210 | Y_length = Y1 - Y0; 211 | Y0_true = Y0; 212 | } 213 | else 214 | { 215 | Y_length = Y0 - Y1; 216 | Y0_true = Y1; 217 | } 218 | 219 | ILI9341_Draw_Rectangle(X0_true, Y0_true, X_length, Y_length, Colour); 220 | } 221 | 222 | /*Draws a character (fonts imported from fonts.h) at X,Y location with specified font colour, size and Background colour*/ 223 | /*See fonts.h implementation of font on what is required for changing to a different font when switching fonts libraries*/ 224 | void ILI9341_Draw_Char(char Character, uint8_t X, uint8_t Y, uint16_t Colour, uint16_t Size, uint16_t Background_Colour) 225 | { 226 | uint8_t function_char; 227 | uint8_t i,j; 228 | 229 | function_char = Character; 230 | 231 | if (function_char < ' ') { 232 | Character = 0; 233 | } else { 234 | function_char -= 32; 235 | } 236 | 237 | char temp[CHAR_WIDTH]; 238 | for(uint8_t k = 0; k CORTEX M7 button" 63 | // 64 | // 65 | // 66 | //----------------------------------- 67 | // How to use this library 68 | //----------------------------------- 69 | // 70 | // -generate SPI peripheral and 3 GPIO_SPEED_FREQ_VERY_HIGH GPIO outputs 71 | // ++Library reinitializes GPIOs and SPIs generated by gpio.c/.h and spi.c/.h using MX_X_Init(); calls 72 | // ++reinitialization will not clash with previous initialization so generated initializations can be laft as they are 73 | // -If using MCUs other than STM32F7 you will have to change the #include "stm32f7xx_hal.h" in the ILI9341_STM32_Driver.h to your respective .h file 74 | // -define your HSPI_INSTANCE in ILI9341_STM32_Driver.h 75 | // -define your CS, DC and RST outputs in ILI9341_STM32_Driver.h 76 | // -check if ILI9341_SCREEN_HEIGHT and ILI9341_SCREEN_WIDTH match your LCD size 77 | // ++Library was written and tested for 320x240 screen size. Other sizes might have issues** 78 | // -in your main program initialize LCD with ILI9341_Init(); 79 | // -library is now ready to be used. Driver library has only basic functions, for more advanced functions see ILI9341_GFX library 80 | // 81 | //----------------------------------- 82 | 83 | /* Includes ------------------------------------------------------------------*/ 84 | #include "ILI9341_STM32_Driver.h" 85 | #include "spi.h" 86 | #include "gpio.h" 87 | 88 | /* Global Variables ------------------------------------------------------------------*/ 89 | volatile uint16_t LCD_HEIGHT = ILI9341_SCREEN_HEIGHT; 90 | volatile uint16_t LCD_WIDTH = ILI9341_SCREEN_WIDTH; 91 | 92 | /* Initialize SPI */ 93 | void ILI9341_SPI_Init(void) 94 | { 95 | MX_SPI5_Init(); //SPI INIT 96 | MX_GPIO_Init(); //GPIO INIT 97 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); //CS OFF 98 | } 99 | 100 | /*Send data (char) to LCD*/ 101 | void ILI9341_SPI_Send(unsigned char SPI_Data) 102 | { 103 | HAL_SPI_Transmit(HSPI_INSTANCE, &SPI_Data, 1, 1); 104 | } 105 | 106 | /* Send command (char) to LCD */ 107 | void ILI9341_Write_Command(uint8_t Command) 108 | { 109 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 110 | HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_RESET); 111 | ILI9341_SPI_Send(Command); 112 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); 113 | } 114 | 115 | /* Send Data (char) to LCD */ 116 | void ILI9341_Write_Data(uint8_t Data) 117 | { 118 | HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET); 119 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 120 | ILI9341_SPI_Send(Data); 121 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); 122 | } 123 | 124 | /* Set Address - Location block - to draw into */ 125 | void ILI9341_Set_Address(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2) 126 | { 127 | ILI9341_Write_Command(0x2A); 128 | ILI9341_Write_Data(X1>>8); 129 | ILI9341_Write_Data(X1); 130 | ILI9341_Write_Data(X2>>8); 131 | ILI9341_Write_Data(X2); 132 | 133 | ILI9341_Write_Command(0x2B); 134 | ILI9341_Write_Data(Y1>>8); 135 | ILI9341_Write_Data(Y1); 136 | ILI9341_Write_Data(Y2>>8); 137 | ILI9341_Write_Data(Y2); 138 | 139 | ILI9341_Write_Command(0x2C); 140 | } 141 | 142 | /*HARDWARE RESET*/ 143 | void ILI9341_Reset(void) 144 | { 145 | HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_RESET); 146 | HAL_Delay(200); 147 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 148 | HAL_Delay(200); 149 | HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_SET); 150 | } 151 | 152 | /*Ser rotation of the screen - changes x0 and y0*/ 153 | void ILI9341_Set_Rotation(uint8_t Rotation) 154 | { 155 | 156 | uint8_t screen_rotation = Rotation; 157 | 158 | ILI9341_Write_Command(0x36); 159 | HAL_Delay(1); 160 | 161 | switch(screen_rotation) 162 | { 163 | case SCREEN_VERTICAL_1: 164 | ILI9341_Write_Data(0x40|0x08); 165 | LCD_WIDTH = 240; 166 | LCD_HEIGHT = 320; 167 | break; 168 | case SCREEN_HORIZONTAL_1: 169 | ILI9341_Write_Data(0x20|0x08); 170 | LCD_WIDTH = 320; 171 | LCD_HEIGHT = 240; 172 | break; 173 | case SCREEN_VERTICAL_2: 174 | ILI9341_Write_Data(0x80|0x08); 175 | LCD_WIDTH = 240; 176 | LCD_HEIGHT = 320; 177 | break; 178 | case SCREEN_HORIZONTAL_2: 179 | ILI9341_Write_Data(0x40|0x80|0x20|0x08); 180 | LCD_WIDTH = 320; 181 | LCD_HEIGHT = 240; 182 | break; 183 | default: 184 | //EXIT IF SCREEN ROTATION NOT VALID! 185 | break; 186 | } 187 | } 188 | 189 | /*Enable LCD display*/ 190 | void ILI9341_Enable(void) 191 | { 192 | HAL_GPIO_WritePin(LCD_RST_PORT, LCD_RST_PIN, GPIO_PIN_SET); 193 | } 194 | 195 | /*Initialize LCD display*/ 196 | void ILI9341_Init(void) 197 | { 198 | 199 | ILI9341_Enable(); 200 | ILI9341_SPI_Init(); 201 | ILI9341_Reset(); 202 | 203 | //SOFTWARE RESET 204 | ILI9341_Write_Command(0x01); 205 | HAL_Delay(1000); 206 | 207 | //POWER CONTROL A 208 | ILI9341_Write_Command(0xCB); 209 | ILI9341_Write_Data(0x39); 210 | ILI9341_Write_Data(0x2C); 211 | ILI9341_Write_Data(0x00); 212 | ILI9341_Write_Data(0x34); 213 | ILI9341_Write_Data(0x02); 214 | 215 | //POWER CONTROL B 216 | ILI9341_Write_Command(0xCF); 217 | ILI9341_Write_Data(0x00); 218 | ILI9341_Write_Data(0xC1); 219 | ILI9341_Write_Data(0x30); 220 | 221 | //DRIVER TIMING CONTROL A 222 | ILI9341_Write_Command(0xE8); 223 | ILI9341_Write_Data(0x85); 224 | ILI9341_Write_Data(0x00); 225 | ILI9341_Write_Data(0x78); 226 | 227 | //DRIVER TIMING CONTROL B 228 | ILI9341_Write_Command(0xEA); 229 | ILI9341_Write_Data(0x00); 230 | ILI9341_Write_Data(0x00); 231 | 232 | //POWER ON SEQUENCE CONTROL 233 | ILI9341_Write_Command(0xED); 234 | ILI9341_Write_Data(0x64); 235 | ILI9341_Write_Data(0x03); 236 | ILI9341_Write_Data(0x12); 237 | ILI9341_Write_Data(0x81); 238 | 239 | //PUMP RATIO CONTROL 240 | ILI9341_Write_Command(0xF7); 241 | ILI9341_Write_Data(0x20); 242 | 243 | //POWER CONTROL,VRH[5:0] 244 | ILI9341_Write_Command(0xC0); 245 | ILI9341_Write_Data(0x23); 246 | 247 | //POWER CONTROL,SAP[2:0];BT[3:0] 248 | ILI9341_Write_Command(0xC1); 249 | ILI9341_Write_Data(0x10); 250 | 251 | //VCM CONTROL 252 | ILI9341_Write_Command(0xC5); 253 | ILI9341_Write_Data(0x3E); 254 | ILI9341_Write_Data(0x28); 255 | 256 | //VCM CONTROL 2 257 | ILI9341_Write_Command(0xC7); 258 | ILI9341_Write_Data(0x86); 259 | 260 | //MEMORY ACCESS CONTROL 261 | ILI9341_Write_Command(0x36); 262 | ILI9341_Write_Data(0x48); 263 | 264 | //PIXEL FORMAT 265 | ILI9341_Write_Command(0x3A); 266 | ILI9341_Write_Data(0x55); 267 | 268 | //FRAME RATIO CONTROL, STANDARD RGB COLOR 269 | ILI9341_Write_Command(0xB1); 270 | ILI9341_Write_Data(0x00); 271 | ILI9341_Write_Data(0x18); 272 | 273 | //DISPLAY FUNCTION CONTROL 274 | ILI9341_Write_Command(0xB6); 275 | ILI9341_Write_Data(0x08); 276 | ILI9341_Write_Data(0x82); 277 | ILI9341_Write_Data(0x27); 278 | 279 | //3GAMMA FUNCTION DISABLE 280 | ILI9341_Write_Command(0xF2); 281 | ILI9341_Write_Data(0x00); 282 | 283 | //GAMMA CURVE SELECTED 284 | ILI9341_Write_Command(0x26); 285 | ILI9341_Write_Data(0x01); 286 | 287 | //POSITIVE GAMMA CORRECTION 288 | ILI9341_Write_Command(0xE0); 289 | ILI9341_Write_Data(0x0F); 290 | ILI9341_Write_Data(0x31); 291 | ILI9341_Write_Data(0x2B); 292 | ILI9341_Write_Data(0x0C); 293 | ILI9341_Write_Data(0x0E); 294 | ILI9341_Write_Data(0x08); 295 | ILI9341_Write_Data(0x4E); 296 | ILI9341_Write_Data(0xF1); 297 | ILI9341_Write_Data(0x37); 298 | ILI9341_Write_Data(0x07); 299 | ILI9341_Write_Data(0x10); 300 | ILI9341_Write_Data(0x03); 301 | ILI9341_Write_Data(0x0E); 302 | ILI9341_Write_Data(0x09); 303 | ILI9341_Write_Data(0x00); 304 | 305 | //NEGATIVE GAMMA CORRECTION 306 | ILI9341_Write_Command(0xE1); 307 | ILI9341_Write_Data(0x00); 308 | ILI9341_Write_Data(0x0E); 309 | ILI9341_Write_Data(0x14); 310 | ILI9341_Write_Data(0x03); 311 | ILI9341_Write_Data(0x11); 312 | ILI9341_Write_Data(0x07); 313 | ILI9341_Write_Data(0x31); 314 | ILI9341_Write_Data(0xC1); 315 | ILI9341_Write_Data(0x48); 316 | ILI9341_Write_Data(0x08); 317 | ILI9341_Write_Data(0x0F); 318 | ILI9341_Write_Data(0x0C); 319 | ILI9341_Write_Data(0x31); 320 | ILI9341_Write_Data(0x36); 321 | ILI9341_Write_Data(0x0F); 322 | 323 | //EXIT SLEEP 324 | ILI9341_Write_Command(0x11); 325 | HAL_Delay(120); 326 | 327 | //TURN ON DISPLAY 328 | ILI9341_Write_Command(0x29); 329 | 330 | //STARTING ROTATION 331 | ILI9341_Set_Rotation(SCREEN_VERTICAL_1); 332 | } 333 | 334 | //INTERNAL FUNCTION OF LIBRARY, USAGE NOT RECOMENDED, USE Draw_Pixel INSTEAD 335 | /*Sends single pixel colour information to LCD*/ 336 | void ILI9341_Draw_Colour(uint16_t Colour) 337 | { 338 | //SENDS COLOUR 339 | unsigned char TempBuffer[2] = {Colour>>8, Colour}; 340 | HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET); 341 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 342 | HAL_SPI_Transmit(HSPI_INSTANCE, TempBuffer, 2, 1); 343 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); 344 | } 345 | 346 | //INTERNAL FUNCTION OF LIBRARY 347 | /*Sends block colour information to LCD*/ 348 | void ILI9341_Draw_Colour_Burst(uint16_t Colour, uint32_t Size) 349 | { 350 | //SENDS COLOUR 351 | uint32_t Buffer_Size = 0; 352 | if((Size*2) < BURST_MAX_SIZE) 353 | { 354 | Buffer_Size = Size; 355 | } 356 | else 357 | { 358 | Buffer_Size = BURST_MAX_SIZE; 359 | } 360 | 361 | HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET); 362 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 363 | 364 | unsigned char chifted = Colour>>8;; 365 | unsigned char burst_buffer[Buffer_Size]; 366 | for(uint32_t j = 0; j < Buffer_Size; j+=2) 367 | { 368 | burst_buffer[j] = chifted; 369 | burst_buffer[j+1] = Colour; 370 | } 371 | 372 | uint32_t Sending_Size = Size*2; 373 | uint32_t Sending_in_Block = Sending_Size/Buffer_Size; 374 | uint32_t Remainder_from_block = Sending_Size%Buffer_Size; 375 | 376 | if(Sending_in_Block != 0) 377 | { 378 | for(uint32_t j = 0; j < (Sending_in_Block); j++) 379 | { 380 | HAL_SPI_Transmit(HSPI_INSTANCE, (unsigned char *)burst_buffer, Buffer_Size, 10); 381 | } 382 | } 383 | 384 | //REMAINDER! 385 | HAL_SPI_Transmit(HSPI_INSTANCE, (unsigned char *)burst_buffer, Remainder_from_block, 10); 386 | 387 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); 388 | } 389 | 390 | //FILL THE ENTIRE SCREEN WITH SELECTED COLOUR (either #define-d ones or custom 16bit) 391 | /*Sets address (entire screen) and Sends Height*Width ammount of colour information to LCD*/ 392 | void ILI9341_Fill_Screen(uint16_t Colour) 393 | { 394 | ILI9341_Set_Address(0,0,LCD_WIDTH,LCD_HEIGHT); 395 | ILI9341_Draw_Colour_Burst(Colour, LCD_WIDTH*LCD_HEIGHT); 396 | } 397 | 398 | //DRAW PIXEL AT XY POSITION WITH SELECTED COLOUR 399 | // 400 | //Location is dependant on screen orientation. x0 and y0 locations change with orientations. 401 | //Using pixels to draw big simple structures is not recommended as it is really slow 402 | //Try using either rectangles or lines if possible 403 | // 404 | void ILI9341_Draw_Pixel(uint16_t X,uint16_t Y,uint16_t Colour) 405 | { 406 | if((X >=LCD_WIDTH) || (Y >=LCD_HEIGHT)) return; //OUT OF BOUNDS! 407 | 408 | //ADDRESS 409 | HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_RESET); 410 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 411 | ILI9341_SPI_Send(0x2A); 412 | HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET); 413 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); 414 | 415 | //XDATA 416 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 417 | unsigned char Temp_Buffer[4] = {X>>8,X, (X+1)>>8, (X+1)}; 418 | HAL_SPI_Transmit(HSPI_INSTANCE, Temp_Buffer, 4, 1); 419 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); 420 | 421 | //ADDRESS 422 | HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_RESET); 423 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 424 | ILI9341_SPI_Send(0x2B); 425 | HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET); 426 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); 427 | 428 | //YDATA 429 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 430 | unsigned char Temp_Buffer1[4] = {Y>>8,Y, (Y+1)>>8, (Y+1)}; 431 | HAL_SPI_Transmit(HSPI_INSTANCE, Temp_Buffer1, 4, 1); 432 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); 433 | 434 | //ADDRESS 435 | HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_RESET); 436 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 437 | ILI9341_SPI_Send(0x2C); 438 | HAL_GPIO_WritePin(LCD_DC_PORT, LCD_DC_PIN, GPIO_PIN_SET); 439 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); 440 | 441 | //COLOUR 442 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_RESET); 443 | unsigned char Temp_Buffer2[2] = {Colour>>8, Colour}; 444 | HAL_SPI_Transmit(HSPI_INSTANCE, Temp_Buffer2, 2, 1); 445 | HAL_GPIO_WritePin(LCD_CS_PORT, LCD_CS_PIN, GPIO_PIN_SET); 446 | 447 | } 448 | 449 | //DRAW RECTANGLE OF SET SIZE AND HEIGTH AT X and Y POSITION WITH CUSTOM COLOUR 450 | // 451 | //Rectangle is hollow. X and Y positions mark the upper left corner of rectangle 452 | //As with all other draw calls x0 and y0 locations dependant on screen orientation 453 | // 454 | 455 | void ILI9341_Draw_Rectangle(uint16_t X, uint16_t Y, uint16_t Width, uint16_t Height, uint16_t Colour) 456 | { 457 | if((X >=LCD_WIDTH) || (Y >=LCD_HEIGHT)) return; 458 | if((X+Width-1)>=LCD_WIDTH) 459 | { 460 | Width=LCD_WIDTH-X; 461 | } 462 | if((Y+Height-1)>=LCD_HEIGHT) 463 | { 464 | Height=LCD_HEIGHT-Y; 465 | } 466 | ILI9341_Set_Address(X, Y, X+Width-1, Y+Height-1); 467 | ILI9341_Draw_Colour_Burst(Colour, Height*Width); 468 | } 469 | 470 | //DRAW LINE FROM X,Y LOCATION to X+Width,Y LOCATION 471 | void ILI9341_Draw_Horizontal_Line(uint16_t X, uint16_t Y, uint16_t Width, uint16_t Colour) 472 | { 473 | if((X >=LCD_WIDTH) || (Y >=LCD_HEIGHT)) return; 474 | if((X+Width-1)>=LCD_WIDTH) 475 | { 476 | Width=LCD_WIDTH-X; 477 | } 478 | ILI9341_Set_Address(X, Y, X+Width-1, Y); 479 | ILI9341_Draw_Colour_Burst(Colour, Width); 480 | } 481 | 482 | //DRAW LINE FROM X,Y LOCATION to X,Y+Height LOCATION 483 | void ILI9341_Draw_Vertical_Line(uint16_t X, uint16_t Y, uint16_t Height, uint16_t Colour) 484 | { 485 | if((X >=LCD_WIDTH) || (Y >=LCD_HEIGHT)) return; 486 | if((Y+Height-1)>=LCD_HEIGHT) 487 | { 488 | Height=LCD_HEIGHT-Y; 489 | } 490 | ILI9341_Set_Address(X, Y, X, Y+Height-1); 491 | ILI9341_Draw_Colour_Burst(Colour, Height); 492 | } 493 | 494 | -------------------------------------------------------------------------------- /Src/ILI9341/ILI9341_STM32_Driver.h: -------------------------------------------------------------------------------- 1 | 2 | // MIT License 3 | // 4 | // Copyright (c) 2017 Matej Artnak 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | // SOFTWARE. 23 | // 24 | // 25 | // 26 | //----------------------------------- 27 | // ILI9341 Driver library for STM32 28 | //----------------------------------- 29 | // 30 | // While there are other libraries for ILI9341 they mostly require either interrupts, DMA or both for fast drawing 31 | // The intent of this library is to offer a simple yet still reasonably fast alternatives for those that 32 | // do not wish to use interrupts or DMA in their projects. 33 | // 34 | // Library is written for STM32 HAL library and supports STM32CUBEMX. To use the library with Cube software 35 | // you need to tick the box that generates peripheral initialization code in their own respective .c and .h file 36 | // 37 | // 38 | //----------------------------------- 39 | // Performance 40 | //----------------------------------- 41 | // Settings: 42 | // --SPI @ 50MHz 43 | // --STM32F746ZG Nucleo board 44 | // --Redraw entire screen 45 | // 46 | // ++ Theoretical maximum FPS with 50Mhz SPI calculated to be 40.69 FPS 47 | // ++ 320*240 = 76800 pixels, each pixel contains 16bit colour information (2x8) 48 | // ++ Theoretical Max FPS: 1/((320*240*16)/50000000) 49 | // 50 | // With ART Accelerator, instruction prefetch, CPI ICACHE and CPU DCACHE enabled: 51 | // 52 | // -FPS: 39.62 53 | // -SPI utilization: 97.37% 54 | // -MB/Second: 6.09 55 | // 56 | // With ART Accelerator, instruction prefetch, CPI ICACHE and CPU DCACHE disabled: 57 | // 58 | // -FPS: 35.45 59 | // -SPI utilization: 87.12% 60 | // -MB/Second: 5.44 61 | // 62 | // ART Accelerator, instruction prefetch, CPI ICACHE and CPU DCACHE settings found in MXCUBE under "System-> CORTEX M7 button" 63 | // 64 | // 65 | // 66 | //----------------------------------- 67 | // How to use this library 68 | //----------------------------------- 69 | // 70 | // -generate SPI peripheral and 3 GPIO_SPEED_FREQ_VERY_HIGH GPIO outputs 71 | // ++Library reinitializes GPIOs and SPIs generated by gpio.c/.h and spi.c/.h using MX_X_Init(); calls 72 | // ++reinitialization will not clash with previous initialization so generated initializations can be laft as they are 73 | // -If using MCUs other than STM32F7 you will have to change the #include "stm32f7xx_hal.h" in the ILI9341_STM32_Driver.h to your respective .h file 74 | // -define your HSPI_INSTANCE in ILI9341_STM32_Driver.h 75 | // -define your CS, DC and RST outputs in ILI9341_STM32_Driver.h 76 | // -check if ILI9341_SCREEN_HEIGHT and ILI9341_SCREEN_WIDTH match your LCD size 77 | // ++Library was written and tested for 320x240 screen size. Other sizes might have issues** 78 | // -in your main program initialize LCD with ILI9341_Init(); 79 | // -library is now ready to be used. Driver library has only basic functions, for more advanced functions see ILI9341_GFX library 80 | // 81 | //----------------------------------- 82 | 83 | 84 | #ifndef ILI9341_STM32_DRIVER_H 85 | #define ILI9341_STM32_DRIVER_H 86 | 87 | #include "stm32f7xx_hal.h" 88 | 89 | 90 | #define ILI9341_SCREEN_HEIGHT 240 91 | #define ILI9341_SCREEN_WIDTH 320 92 | 93 | //SPI INSTANCE 94 | #define HSPI_INSTANCE &hspi5 95 | 96 | //CHIP SELECT PIN AND PORT, STANDARD GPIO 97 | #define LCD_CS_PORT GPIOC 98 | #define LCD_CS_PIN CS_Pin 99 | 100 | //DATA COMMAND PIN AND PORT, STANDARD GPIO 101 | #define LCD_DC_PORT GPIOC 102 | #define LCD_DC_PIN DC_Pin 103 | 104 | //RESET PIN AND PORT, STANDARD GPIO 105 | #define LCD_RST_PORT GPIOC 106 | #define LCD_RST_PIN RST_Pin 107 | 108 | 109 | #define BURST_MAX_SIZE 500 110 | 111 | #define BLACK 0x0000 112 | #define NAVY 0x000F 113 | #define DARKGREEN 0x03E0 114 | #define DARKCYAN 0x03EF 115 | #define MAROON 0x7800 116 | #define PURPLE 0x780F 117 | #define OLIVE 0x7BE0 118 | #define LIGHTGREY 0xC618 119 | #define DARKGREY 0x7BEF 120 | #define BLUE 0x001F 121 | #define GREEN 0x07E0 122 | #define CYAN 0x07FF 123 | #define RED 0xF800 124 | #define MAGENTA 0xF81F 125 | #define YELLOW 0xFFE0 126 | #define WHITE 0xFFFF 127 | #define ORANGE 0xFD20 128 | #define GREENYELLOW 0xAFE5 129 | #define PINK 0xF81F 130 | 131 | #define SCREEN_VERTICAL_1 0 132 | #define SCREEN_HORIZONTAL_1 1 133 | #define SCREEN_VERTICAL_2 2 134 | #define SCREEN_HORIZONTAL_2 3 135 | 136 | void ILI9341_SPI_Init(void); 137 | void ILI9341_SPI_Send(unsigned char SPI_Data); 138 | void ILI9341_Write_Command(uint8_t Command); 139 | void ILI9341_Write_Data(uint8_t Data); 140 | void ILI9341_Set_Address(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2); 141 | void ILI9341_Reset(void); 142 | void ILI9341_Set_Rotation(uint8_t Rotation); 143 | void ILI9341_Enable(void); 144 | void ILI9341_Init(void); 145 | void ILI9341_Fill_Screen(uint16_t Colour); 146 | void ILI9341_Draw_Colour(uint16_t Colour); 147 | void ILI9341_Draw_Pixel(uint16_t X,uint16_t Y,uint16_t Colour); 148 | void ILI9341_Draw_Colour_Burst(uint16_t Colour, uint32_t Size); 149 | 150 | 151 | void ILI9341_Draw_Rectangle(uint16_t X, uint16_t Y, uint16_t Width, uint16_t Height, uint16_t Colour); 152 | void ILI9341_Draw_Horizontal_Line(uint16_t X, uint16_t Y, uint16_t Width, uint16_t Colour); 153 | void ILI9341_Draw_Vertical_Line(uint16_t X, uint16_t Y, uint16_t Height, uint16_t Colour); 154 | 155 | #endif 156 | 157 | -------------------------------------------------------------------------------- /Src/ILI9341/ILI9341_Touchscreen.c: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017 Matej Artnak 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // 24 | //----------------------------------- 25 | // ILI9341 Touchscreen library for STM32 26 | //----------------------------------- 27 | // 28 | // Very simple Touchscreen library for ILI9341. 29 | // Extremly basic reading of position. No runtime calibration, No prediction, basic noise removal. Simple but stupid. 30 | // Basic hardcoded calibration values saved in .h file 31 | // 32 | // Library is written for STM32 HAL library and supports STM32CUBEMX. To use the library with Cube software 33 | // you need to tick the box that generates peripheral initialization code in their own respective .c and .h file 34 | // 35 | // 36 | //----------------------------------- 37 | // How to use this library 38 | //----------------------------------- 39 | // 40 | // -If using MCUs other than STM32F7 you will have to change the #include "stm32f7xx_hal.h" in the ILI9341_Touchscreen.h to your respective .h file 41 | // -define GPIO inputs and outputs then map the Pins and Ports inside the ILI9341_Touchscreen.h 42 | // -Library does not require any initialization calls apart from GPIO initialization. Initialize GPIOs before calling library functions! 43 | // 44 | // Touchpad GPIO defines 45 | // Outputs: 46 | // CLK 47 | // MOSI 48 | // CS 49 | // 50 | // Inputs: 51 | // IRQ 52 | // MISO 53 | // 54 | // 55 | // -Touchpad library bitbangs SPI interface and only requires basic GPIOs. 56 | // -Setting GPIOs as FREQ_VERY_HIGH Recommended 57 | // 58 | // -Warning! Library is written for "ILI9341_Set_Rotation(SCREEN_VERTICAL_1)" (See ILI9341_STM32_Driver for information about function) 59 | // -If using different layout you will have to Re-Map X and Y coordinates of the Screen 60 | // 61 | // 62 | // -NO_OF_POSITION_SAMPLES makes location output less noisy but increases reading time. Increase and decrease to your liking 63 | // 64 | //----------EXAMPLE------------------ 65 | /* 66 | if(TP_Touchpad_Pressed()) 67 | { 68 | uint16_t x_pos = 0; 69 | uint16_t y_pos = 0; 70 | 71 | uint16_t position_array[2]; 72 | if(TP_Read_Coordinates(position_array) == TOUCHPAD_DATA_OK) 73 | { 74 | x_pos = position_array[0]; 75 | y_pos = position_array[1]; 76 | } 77 | } 78 | */ 79 | //----------------------------------- 80 | 81 | 82 | #include "ILI9341_Touchscreen.h" 83 | #include "stm32f7xx_hal.h" 84 | 85 | //Internal Touchpad command, do not call directly 86 | uint16_t TP_Read(void) 87 | { 88 | uint8_t i = 16; 89 | uint16_t value = 0; 90 | 91 | while(i > 0x00) 92 | { 93 | value <<= 1; 94 | 95 | HAL_GPIO_WritePin(TP_CLK_PORT, TP_CLK_PIN, GPIO_PIN_SET); 96 | HAL_GPIO_WritePin(TP_CLK_PORT, TP_CLK_PIN, GPIO_PIN_RESET); 97 | 98 | if(HAL_GPIO_ReadPin(TP_MISO_PORT, TP_MISO_PIN) != 0) 99 | { 100 | value++; 101 | } 102 | 103 | i--; 104 | }; 105 | 106 | return value; 107 | } 108 | 109 | //Internal Touchpad command, do not call directly 110 | void TP_Write(uint8_t value) 111 | { 112 | uint8_t i = 0x08; 113 | 114 | HAL_GPIO_WritePin(TP_CLK_PORT, TP_CLK_PIN, GPIO_PIN_RESET); 115 | 116 | while(i > 0) 117 | { 118 | if((value & 0x80) != 0x00) 119 | { 120 | HAL_GPIO_WritePin(TP_MOSI_PORT, TP_MOSI_PIN, GPIO_PIN_SET); 121 | } 122 | else 123 | { 124 | HAL_GPIO_WritePin(TP_MOSI_PORT, TP_MOSI_PIN, GPIO_PIN_RESET); 125 | } 126 | 127 | value <<= 1; 128 | HAL_GPIO_WritePin(TP_CLK_PORT, TP_CLK_PIN, GPIO_PIN_SET); 129 | HAL_GPIO_WritePin(TP_CLK_PORT, TP_CLK_PIN, GPIO_PIN_RESET); 130 | i--; 131 | }; 132 | } 133 | 134 | 135 | 136 | //Read coordinates of touchscreen press. Position[0] = X, Position[1] = Y 137 | uint8_t TP_Read_Coordinates(uint16_t Coordinates[2]) 138 | { 139 | HAL_GPIO_WritePin(TP_CLK_PORT, TP_CLK_PIN, GPIO_PIN_SET); 140 | HAL_GPIO_WritePin(TP_MOSI_PORT, TP_MOSI_PIN, GPIO_PIN_SET); 141 | HAL_GPIO_WritePin(TP_CS_PORT, TP_CS_PIN, GPIO_PIN_SET); 142 | 143 | 144 | 145 | uint32_t avg_x, avg_y = 0; 146 | uint16_t rawx, rawy = 0; 147 | uint32_t calculating_x, calculating_y = 0; 148 | 149 | uint32_t samples = NO_OF_POSITION_SAMPLES; 150 | uint32_t counted_samples = 0; 151 | 152 | HAL_GPIO_WritePin(TP_CS_PORT, TP_CS_PIN, GPIO_PIN_RESET); 153 | 154 | 155 | while((samples > 0)&&(HAL_GPIO_ReadPin(TP_IRQ_PORT, TP_IRQ_PIN) == 0)) 156 | { 157 | TP_Write(CMD_RDY); 158 | 159 | rawy = TP_Read(); 160 | avg_y += rawy; 161 | calculating_y += rawy; 162 | 163 | 164 | TP_Write(CMD_RDX); 165 | rawx = TP_Read(); 166 | avg_x += rawx; 167 | calculating_x += rawx; 168 | samples--; 169 | counted_samples++; 170 | }; 171 | 172 | HAL_GPIO_WritePin(TP_CS_PORT, TP_CS_PIN, GPIO_PIN_SET); 173 | 174 | 175 | if((counted_samples == NO_OF_POSITION_SAMPLES)&&(HAL_GPIO_ReadPin(TP_IRQ_PORT, TP_IRQ_PIN) == 0)) 176 | { 177 | 178 | calculating_x /= counted_samples; 179 | calculating_y /= counted_samples; 180 | 181 | rawx = calculating_x; 182 | rawy = calculating_y; 183 | 184 | rawx *= -1; 185 | rawy *= -1; 186 | 187 | //CONVERTING 16bit Value to Screen coordinates 188 | // 65535/273 = 240! 189 | // 65535/204 = 320! 190 | Coordinates[0] = ((240 - (rawx/X_TRANSLATION)) - X_OFFSET)*X_MAGNITUDE; 191 | Coordinates[1] = ((rawy/Y_TRANSLATION)- Y_OFFSET)*Y_MAGNITUDE; 192 | 193 | return TOUCHPAD_DATA_OK; 194 | } 195 | else 196 | { 197 | Coordinates[0] = 0; 198 | Coordinates[1] = 0; 199 | return TOUCHPAD_DATA_NOISY; 200 | } 201 | } 202 | 203 | //Check if Touchpad was pressed. Returns TOUCHPAD_PRESSED (1) or TOUCHPAD_NOT_PRESSED (0) 204 | uint8_t TP_Touchpad_Pressed(void) 205 | { 206 | if(HAL_GPIO_ReadPin(TP_IRQ_PORT, TP_IRQ_PIN) == 0) 207 | { 208 | return TOUCHPAD_PRESSED; 209 | } 210 | else 211 | { 212 | return TOUCHPAD_NOT_PRESSED; 213 | } 214 | } 215 | 216 | 217 | -------------------------------------------------------------------------------- /Src/ILI9341/ILI9341_Touchscreen.h: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017 Matej Artnak 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // 24 | //----------------------------------- 25 | // ILI9341 Touchscreen library for STM32 26 | //----------------------------------- 27 | // 28 | // Very simple Touchscreen library for ILI9341. 29 | // Extremly basic reading of position. No runtime calibration, No prediction, basic noise removal. Simple but stupid. 30 | // Basic hardcoded calibration values saved in .h file 31 | // 32 | // Library is written for STM32 HAL library and supports STM32CUBEMX. To use the library with Cube software 33 | // you need to tick the box that generates peripheral initialization code in their own respective .c and .h file 34 | // 35 | // 36 | //----------------------------------- 37 | // How to use this library 38 | //----------------------------------- 39 | // 40 | // -If using MCUs other than STM32F7 you will have to change the #include "stm32f7xx_hal.h" in the ILI9341_Touchscreen.h to your respective .h file 41 | // -define GPIO inputs and outputs then map the Pins and Ports inside the ILI9341_Touchscreen.h 42 | // -Library does not require any initialization calls apart from GPIO initialization. Initialize GPIOs before calling library functions! 43 | // 44 | // Touchpad GPIO defines 45 | // Outputs: 46 | // CLK 47 | // MOSI 48 | // CS 49 | // 50 | // Inputs: 51 | // IRQ 52 | // MISO 53 | // 54 | // 55 | // -Touchpad library bitbangs SPI interface and only requires basic GPIOs. 56 | // -Setting GPIOs as FREQ_VERY_HIGH Recommended 57 | // 58 | // -Warning! Library is written for "ILI9341_Set_Rotation(SCREEN_VERTICAL_1)" (See ILI9341_STM32_Driver for information about function) 59 | // -If using different layout you will have to Re-Map X and Y coordinates of the Screen 60 | // 61 | // 62 | // -NO_OF_POSITION_SAMPLES makes location output less noisy but increases reading time. Increase and decrease to your liking 63 | // 64 | //----------EXAMPLE------------------ 65 | /* 66 | if(TP_Touchpad_Pressed()) 67 | { 68 | uint16_t x_pos = 0; 69 | uint16_t y_pos = 0; 70 | 71 | uint16_t position_array[2]; 72 | if(TP_Read_Coordinates(position_array) == TOUCHPAD_DATA_OK) 73 | { 74 | x_pos = position_array[0]; 75 | y_pos = position_array[1]; 76 | } 77 | } 78 | */ 79 | //----------------------------------- 80 | 81 | 82 | #ifndef TOUCH_H 83 | #define TOUCH_H 84 | 85 | #include "stm32f7xx_hal.h" 86 | 87 | 88 | #define TP_CLK_PORT GPIOE 89 | #define TP_CLK_PIN T_CLK_Pin 90 | 91 | #define TP_CS_PORT GPIOE 92 | #define TP_CS_PIN T_CS_Pin 93 | 94 | #define TP_MISO_PORT GPIOE 95 | #define TP_MISO_PIN T_MISO_Pin 96 | 97 | #define TP_MOSI_PORT GPIOE 98 | #define TP_MOSI_PIN T_MOSI_Pin 99 | 100 | #define TP_IRQ_PORT GPIOE 101 | #define TP_IRQ_PIN T_IRQ_Pin 102 | 103 | #define CMD_RDY 0X90 104 | #define CMD_RDX 0XD0 105 | 106 | //RETURN VALUES FOR TP_Touchpad_Pressed 107 | #define TOUCHPAD_NOT_PRESSED 0 108 | #define TOUCHPAD_PRESSED 1 109 | 110 | //RETURN VALUES FOR TP_Read_Coordinates 111 | #define TOUCHPAD_DATA_OK 1 112 | #define TOUCHPAD_DATA_NOISY 0 113 | 114 | //HARDCODED CALIBRATION, CHANGE IF REQUIRED 115 | #define X_OFFSET 13 116 | #define Y_OFFSET 15 117 | #define X_MAGNITUDE 1.16 118 | #define Y_MAGNITUDE 1.16 119 | 120 | //CONVERTING 16bit Value to Screen coordinates 121 | // 65535/273 = 240! 122 | // 65535/204 = 320! 123 | #define X_TRANSLATION 273 124 | #define Y_TRANSLATION 204 125 | 126 | //In order to increase accuracy of location reads library samples 127 | //NO_OF_POSITION_SAMPLES numbers of locations and averages them 128 | //If library runs too slow decrease NO_OF_POSITION_SAMPLES, but 129 | //expect inreasingly noisy or incorrect locations returned 130 | 131 | #define NO_OF_POSITION_SAMPLES 1000 132 | 133 | //Internal Touchpad command, do not call directly 134 | uint16_t TP_Read(void); 135 | 136 | //Internal Touchpad command, do not call directly 137 | void TP_Write(uint8_t value); 138 | 139 | //Read coordinates of touchscreen press. Position[0] = X, Position[1] = Y 140 | uint8_t TP_Read_Coordinates(uint16_t Coordinates[2]); 141 | 142 | //Check if Touchpad was pressed. Returns TOUCHPAD_PRESSED (1) or TOUCHPAD_NOT_PRESSED (0) 143 | uint8_t TP_Touchpad_Pressed(void); 144 | 145 | #endif 146 | -------------------------------------------------------------------------------- /Src/gpio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : gpio.c 4 | * Description : This file provides code for the configuration 5 | * of all used GPIO pins. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "gpio.h" 37 | /* USER CODE BEGIN 0 */ 38 | 39 | /* USER CODE END 0 */ 40 | 41 | /*----------------------------------------------------------------------------*/ 42 | /* Configure GPIO */ 43 | /*----------------------------------------------------------------------------*/ 44 | /* USER CODE BEGIN 1 */ 45 | 46 | /* USER CODE END 1 */ 47 | 48 | /** Configure pins as 49 | * Analog 50 | * Input 51 | * Output 52 | * EVENT_OUT 53 | * EXTI 54 | PC1 ------> ETH_MDC 55 | PA1 ------> ETH_REF_CLK 56 | PA2 ------> ETH_MDIO 57 | PA7 ------> ETH_CRS_DV 58 | PC4 ------> ETH_RXD0 59 | PC5 ------> ETH_RXD1 60 | PB13 ------> ETH_TXD1 61 | PA8 ------> USB_OTG_FS_SOF 62 | PA10 ------> USB_OTG_FS_ID 63 | PA11 ------> USB_OTG_FS_DM 64 | PA12 ------> USB_OTG_FS_DP 65 | PG11 ------> ETH_TX_EN 66 | PG13 ------> ETH_TXD0 67 | */ 68 | void MX_GPIO_Init(void) 69 | { 70 | 71 | GPIO_InitTypeDef GPIO_InitStruct; 72 | 73 | /* GPIO Ports Clock Enable */ 74 | __HAL_RCC_GPIOE_CLK_ENABLE(); 75 | __HAL_RCC_GPIOC_CLK_ENABLE(); 76 | __HAL_RCC_GPIOF_CLK_ENABLE(); 77 | __HAL_RCC_GPIOH_CLK_ENABLE(); 78 | __HAL_RCC_GPIOA_CLK_ENABLE(); 79 | __HAL_RCC_GPIOB_CLK_ENABLE(); 80 | __HAL_RCC_GPIOD_CLK_ENABLE(); 81 | __HAL_RCC_GPIOG_CLK_ENABLE(); 82 | 83 | /*Configure GPIO pin : PtPin */ 84 | GPIO_InitStruct.Pin = T_IRQ_Pin; 85 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 86 | GPIO_InitStruct.Pull = GPIO_NOPULL; 87 | HAL_GPIO_Init(T_IRQ_GPIO_Port, &GPIO_InitStruct); 88 | 89 | /*Configure GPIO pins : PEPin PEPin PEPin */ 90 | GPIO_InitStruct.Pin = T_CLK_Pin|T_MOSI_Pin|T_CS_Pin; 91 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 92 | GPIO_InitStruct.Pull = GPIO_NOPULL; 93 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 94 | HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); 95 | 96 | /*Configure GPIO pin : PtPin */ 97 | GPIO_InitStruct.Pin = T_MISO_Pin; 98 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 99 | GPIO_InitStruct.Pull = GPIO_PULLUP; 100 | HAL_GPIO_Init(T_MISO_GPIO_Port, &GPIO_InitStruct); 101 | 102 | /*Configure GPIO pin : PtPin */ 103 | GPIO_InitStruct.Pin = User_Blue_Button_Pin; 104 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 105 | GPIO_InitStruct.Pull = GPIO_NOPULL; 106 | HAL_GPIO_Init(User_Blue_Button_GPIO_Port, &GPIO_InitStruct); 107 | 108 | /*Configure GPIO pins : PCPin PCPin PCPin */ 109 | GPIO_InitStruct.Pin = RMII_MDC_Pin|RMII_RXD0_Pin|RMII_RXD1_Pin; 110 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 111 | GPIO_InitStruct.Pull = GPIO_NOPULL; 112 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 113 | GPIO_InitStruct.Alternate = GPIO_AF11_ETH; 114 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 115 | 116 | /*Configure GPIO pins : PAPin PAPin PAPin */ 117 | GPIO_InitStruct.Pin = RMII_REF_CLK_Pin|RMII_MDIO_Pin|RMII_CRS_DV_Pin; 118 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 119 | GPIO_InitStruct.Pull = GPIO_NOPULL; 120 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 121 | GPIO_InitStruct.Alternate = GPIO_AF11_ETH; 122 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 123 | 124 | /*Configure GPIO pin : PtPin */ 125 | GPIO_InitStruct.Pin = RMII_TXD1_Pin; 126 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 127 | GPIO_InitStruct.Pull = GPIO_NOPULL; 128 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 129 | GPIO_InitStruct.Alternate = GPIO_AF11_ETH; 130 | HAL_GPIO_Init(RMII_TXD1_GPIO_Port, &GPIO_InitStruct); 131 | 132 | /*Configure GPIO pins : PBPin PBPin */ 133 | GPIO_InitStruct.Pin = LD3_Pin|LD2_Pin; 134 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 135 | GPIO_InitStruct.Pull = GPIO_NOPULL; 136 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 137 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 138 | 139 | /*Configure GPIO pin : PtPin */ 140 | GPIO_InitStruct.Pin = USB_PowerSwitchOn_Pin; 141 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 142 | GPIO_InitStruct.Pull = GPIO_NOPULL; 143 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 144 | HAL_GPIO_Init(USB_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct); 145 | 146 | /*Configure GPIO pin : PtPin */ 147 | GPIO_InitStruct.Pin = USB_OverCurrent_Pin; 148 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 149 | GPIO_InitStruct.Pull = GPIO_NOPULL; 150 | HAL_GPIO_Init(USB_OverCurrent_GPIO_Port, &GPIO_InitStruct); 151 | 152 | /*Configure GPIO pins : PCPin PCPin PCPin */ 153 | GPIO_InitStruct.Pin = CS_Pin|DC_Pin|RST_Pin; 154 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 155 | GPIO_InitStruct.Pull = GPIO_NOPULL; 156 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 157 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 158 | 159 | /*Configure GPIO pins : PAPin PAPin PAPin PAPin */ 160 | GPIO_InitStruct.Pin = USB_SOF_Pin|USB_ID_Pin|USB_DM_Pin|USB_DP_Pin; 161 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 162 | GPIO_InitStruct.Pull = GPIO_NOPULL; 163 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 164 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; 165 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 166 | 167 | /*Configure GPIO pins : PGPin PGPin */ 168 | GPIO_InitStruct.Pin = RMII_TX_EN_Pin|RMII_TXD0_Pin; 169 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 170 | GPIO_InitStruct.Pull = GPIO_NOPULL; 171 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 172 | GPIO_InitStruct.Alternate = GPIO_AF11_ETH; 173 | HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); 174 | 175 | /*Configure GPIO pin Output Level */ 176 | HAL_GPIO_WritePin(GPIOE, T_CLK_Pin|T_MOSI_Pin|T_CS_Pin, GPIO_PIN_RESET); 177 | 178 | /*Configure GPIO pin Output Level */ 179 | HAL_GPIO_WritePin(GPIOB, LD3_Pin|LD2_Pin, GPIO_PIN_RESET); 180 | 181 | /*Configure GPIO pin Output Level */ 182 | HAL_GPIO_WritePin(USB_PowerSwitchOn_GPIO_Port, USB_PowerSwitchOn_Pin, GPIO_PIN_RESET); 183 | 184 | /*Configure GPIO pin Output Level */ 185 | HAL_GPIO_WritePin(GPIOC, CS_Pin|DC_Pin|RST_Pin, GPIO_PIN_RESET); 186 | 187 | } 188 | 189 | /* USER CODE BEGIN 2 */ 190 | 191 | /* USER CODE END 2 */ 192 | 193 | /** 194 | * @} 195 | */ 196 | 197 | /** 198 | * @} 199 | */ 200 | 201 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 202 | -------------------------------------------------------------------------------- /Src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : main.c 4 | * Description : Main program body 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2017 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm32f7xx_hal.h" 35 | #include "rng.h" 36 | #include "spi.h" 37 | #include "tim.h" 38 | #include "usart.h" 39 | #include "gpio.h" 40 | 41 | /* USER CODE BEGIN Includes */ 42 | #include "ILI9341_Touchscreen.h" 43 | 44 | #include "ILI9341_STM32_Driver.h" 45 | #include "ILI9341_GFX.h" 46 | 47 | #include "snow_tiger.h" 48 | 49 | /* USER CODE END Includes */ 50 | 51 | /* Private variables ---------------------------------------------------------*/ 52 | 53 | /* USER CODE BEGIN PV */ 54 | /* Private variables ---------------------------------------------------------*/ 55 | 56 | /* USER CODE END PV */ 57 | 58 | /* Private function prototypes -----------------------------------------------*/ 59 | void SystemClock_Config(void); 60 | void Error_Handler(void); 61 | 62 | /* USER CODE BEGIN PFP */ 63 | /* Private function prototypes -----------------------------------------------*/ 64 | 65 | /* USER CODE END PFP */ 66 | 67 | /* USER CODE BEGIN 0 */ 68 | 69 | /* USER CODE END 0 */ 70 | 71 | int main(void) 72 | { 73 | 74 | /* USER CODE BEGIN 1 */ 75 | 76 | /* USER CODE END 1 */ 77 | 78 | /* Enable I-Cache-------------------------------------------------------------*/ 79 | SCB_EnableICache(); 80 | 81 | /* Enable D-Cache-------------------------------------------------------------*/ 82 | SCB_EnableDCache(); 83 | 84 | /* MCU Configuration----------------------------------------------------------*/ 85 | 86 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 87 | HAL_Init(); 88 | 89 | /* Configure the system clock */ 90 | SystemClock_Config(); 91 | 92 | /* Initialize all configured peripherals */ 93 | MX_GPIO_Init(); 94 | MX_USART3_UART_Init(); 95 | MX_SPI5_Init(); 96 | MX_RNG_Init(); 97 | MX_TIM1_Init(); 98 | 99 | /* USER CODE BEGIN 2 */ 100 | 101 | ILI9341_Init();//initial driver setup to drive ili9341 102 | 103 | 104 | /* USER CODE END 2 */ 105 | 106 | /* Infinite loop */ 107 | /* USER CODE BEGIN WHILE */ 108 | while (1) 109 | { 110 | /* USER CODE END WHILE */ 111 | 112 | /* USER CODE BEGIN 3 */ 113 | 114 | //----------------------------------------------------------PERFORMANCE TEST 115 | ILI9341_Fill_Screen(WHITE); 116 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 117 | ILI9341_Draw_Text("FPS TEST, 40 loop 2 screens", 10, 10, BLACK, 1, WHITE); 118 | HAL_Delay(2000); 119 | ILI9341_Fill_Screen(WHITE); 120 | 121 | uint32_t Timer_Counter = 0; 122 | for(uint32_t j = 0; j < 2; j++) 123 | { 124 | HAL_TIM_Base_Start(&htim1); 125 | for(uint16_t i = 0; i < 10; i++) 126 | { 127 | ILI9341_Fill_Screen(WHITE); 128 | ILI9341_Fill_Screen(BLACK); 129 | } 130 | 131 | //20.000 per second! 132 | HAL_TIM_Base_Stop(&htim1); 133 | Timer_Counter += __HAL_TIM_GET_COUNTER(&htim1); 134 | __HAL_TIM_SET_COUNTER(&htim1, 0); 135 | } 136 | Timer_Counter /= 2; 137 | 138 | char counter_buff[30]; 139 | ILI9341_Fill_Screen(WHITE); 140 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 141 | sprintf(counter_buff, "Timer counter value: %d", Timer_Counter*2); 142 | ILI9341_Draw_Text(counter_buff, 10, 10, BLACK, 1, WHITE); 143 | 144 | double seconds_passed = 2*((float)Timer_Counter / 20000); 145 | sprintf(counter_buff, "Time: %.3f Sec", seconds_passed); 146 | ILI9341_Draw_Text(counter_buff, 10, 30, BLACK, 2, WHITE); 147 | 148 | double timer_float = 20/(((float)Timer_Counter)/20000); //Frames per sec 149 | 150 | sprintf(counter_buff, "FPS: %.2f", timer_float); 151 | ILI9341_Draw_Text(counter_buff, 10, 50, BLACK, 2, WHITE); 152 | double MB_PS = timer_float*240*320*2/1000000; 153 | sprintf(counter_buff, "MB/S: %.2f", MB_PS); 154 | ILI9341_Draw_Text(counter_buff, 10, 70, BLACK, 2, WHITE); 155 | double SPI_utilized_percentage = (MB_PS/(6.25 ))*100; //50mbits / 8 bits 156 | sprintf(counter_buff, "SPI Utilized: %.2f", SPI_utilized_percentage); 157 | ILI9341_Draw_Text(counter_buff, 10, 90, BLACK, 2, WHITE); 158 | HAL_Delay(10000); 159 | 160 | 161 | static uint16_t x = 0; 162 | static uint16_t y = 0; 163 | 164 | char Temp_Buffer_text[40]; 165 | 166 | //----------------------------------------------------------COUNTING MULTIPLE SEGMENTS 167 | ILI9341_Fill_Screen(WHITE); 168 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 169 | ILI9341_Draw_Text("Counting multiple segments at once", 10, 10, BLACK, 1, WHITE); 170 | HAL_Delay(2000); 171 | ILI9341_Fill_Screen(WHITE); 172 | 173 | 174 | for(uint16_t i = 0; i <= 10; i++) 175 | { 176 | sprintf(Temp_Buffer_text, "Counting: %d", i); 177 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 10, BLACK, 2, WHITE); 178 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 30, BLUE, 2, WHITE); 179 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 50, RED, 2, WHITE); 180 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 70, GREEN, 2, WHITE); 181 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 90, BLACK, 2, WHITE); 182 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 110, BLUE, 2, WHITE); 183 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 130, RED, 2, WHITE); 184 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 150, GREEN, 2, WHITE); 185 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 170, WHITE, 2, BLACK); 186 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 190, BLUE, 2, BLACK); 187 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 210, RED, 2, BLACK); 188 | } 189 | 190 | HAL_Delay(1000); 191 | 192 | //----------------------------------------------------------COUNTING SINGLE SEGMENT 193 | ILI9341_Fill_Screen(WHITE); 194 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 195 | ILI9341_Draw_Text("Counting single segment", 10, 10, BLACK, 1, WHITE); 196 | HAL_Delay(2000); 197 | ILI9341_Fill_Screen(WHITE); 198 | 199 | for(uint16_t i = 0; i <= 100; i++) 200 | { 201 | sprintf(Temp_Buffer_text, "Counting: %d", i); 202 | ILI9341_Draw_Text(Temp_Buffer_text, 10, 10, BLACK, 3, WHITE); 203 | } 204 | 205 | HAL_Delay(1000); 206 | 207 | //----------------------------------------------------------ALIGNMENT TEST 208 | ILI9341_Fill_Screen(WHITE); 209 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 210 | ILI9341_Draw_Text("Rectangle alignment check", 10, 10, BLACK, 1, WHITE); 211 | HAL_Delay(2000); 212 | ILI9341_Fill_Screen(WHITE); 213 | 214 | ILI9341_Draw_Hollow_Rectangle_Coord(50, 50, 100, 100, BLACK); 215 | ILI9341_Draw_Filled_Rectangle_Coord(20, 20, 50, 50, BLACK); 216 | ILI9341_Draw_Hollow_Rectangle_Coord(10, 10, 19, 19, BLACK); 217 | HAL_Delay(1000); 218 | 219 | //----------------------------------------------------------LINES EXAMPLE 220 | ILI9341_Fill_Screen(WHITE); 221 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 222 | ILI9341_Draw_Text("Randomly placed and sized", 10, 10, BLACK, 1, WHITE); 223 | ILI9341_Draw_Text("Horizontal and Vertical lines", 10, 20, BLACK, 1, WHITE); 224 | HAL_Delay(2000); 225 | ILI9341_Fill_Screen(WHITE); 226 | 227 | for(uint32_t i = 0; i < 30000; i++) 228 | { 229 | uint32_t random_num = 0; 230 | uint16_t xr = 0; 231 | uint16_t yr = 0; 232 | uint16_t radiusr = 0; 233 | uint16_t colourr = 0; 234 | random_num = HAL_RNG_GetRandomNumber(&hrng); 235 | xr = random_num; 236 | random_num = HAL_RNG_GetRandomNumber(&hrng); 237 | yr = random_num; 238 | random_num = HAL_RNG_GetRandomNumber(&hrng); 239 | radiusr = random_num; 240 | random_num = HAL_RNG_GetRandomNumber(&hrng); 241 | colourr = random_num; 242 | 243 | xr &= 0x01FF; 244 | yr &= 0x01FF; 245 | radiusr &= 0x001F; 246 | //ili9341_drawpixel(xr, yr, WHITE); 247 | ILI9341_Draw_Horizontal_Line(xr, yr, radiusr, colourr); 248 | ILI9341_Draw_Vertical_Line(xr, yr, radiusr, colourr); 249 | } 250 | 251 | HAL_Delay(1000); 252 | 253 | //----------------------------------------------------------HOLLOW CIRCLES EXAMPLE 254 | ILI9341_Fill_Screen(WHITE); 255 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 256 | ILI9341_Draw_Text("Randomly placed and sized", 10, 10, BLACK, 1, WHITE); 257 | ILI9341_Draw_Text("Circles", 10, 20, BLACK, 1, WHITE); 258 | HAL_Delay(2000); 259 | ILI9341_Fill_Screen(WHITE); 260 | 261 | 262 | for(uint32_t i = 0; i < 3000; i++) 263 | { 264 | uint32_t random_num = 0; 265 | uint16_t xr = 0; 266 | uint16_t yr = 0; 267 | uint16_t radiusr = 0; 268 | uint16_t colourr = 0; 269 | random_num = HAL_RNG_GetRandomNumber(&hrng); 270 | xr = random_num; 271 | random_num = HAL_RNG_GetRandomNumber(&hrng); 272 | yr = random_num; 273 | random_num = HAL_RNG_GetRandomNumber(&hrng); 274 | radiusr = random_num; 275 | random_num = HAL_RNG_GetRandomNumber(&hrng); 276 | colourr = random_num; 277 | 278 | xr &= 0x01FF; 279 | yr &= 0x01FF; 280 | radiusr &= 0x001F; 281 | //ili9341_drawpixel(xr, yr, WHITE); 282 | ILI9341_Draw_Hollow_Circle(xr, yr, radiusr*2, colourr); 283 | } 284 | HAL_Delay(1000); 285 | 286 | //----------------------------------------------------------FILLED CIRCLES EXAMPLE 287 | ILI9341_Fill_Screen(WHITE); 288 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 289 | ILI9341_Draw_Text("Randomly placed and sized", 10, 10, BLACK, 1, WHITE); 290 | ILI9341_Draw_Text("Filled Circles", 10, 20, BLACK, 1, WHITE); 291 | HAL_Delay(2000); 292 | ILI9341_Fill_Screen(WHITE); 293 | 294 | for(uint32_t i = 0; i < 1000; i++) 295 | { 296 | uint32_t random_num = 0; 297 | uint16_t xr = 0; 298 | uint16_t yr = 0; 299 | uint16_t radiusr = 0; 300 | uint16_t colourr = 0; 301 | random_num = HAL_RNG_GetRandomNumber(&hrng); 302 | xr = random_num; 303 | random_num = HAL_RNG_GetRandomNumber(&hrng); 304 | yr = random_num; 305 | random_num = HAL_RNG_GetRandomNumber(&hrng); 306 | radiusr = random_num; 307 | random_num = HAL_RNG_GetRandomNumber(&hrng); 308 | colourr = random_num; 309 | 310 | xr &= 0x01FF; 311 | yr &= 0x01FF; 312 | radiusr &= 0x001F; 313 | //ili9341_drawpixel(xr, yr, WHITE); 314 | ILI9341_Draw_Filled_Circle(xr, yr, radiusr/2, colourr); 315 | } 316 | HAL_Delay(1000); 317 | 318 | //----------------------------------------------------------HOLLOW RECTANGLES EXAMPLE 319 | ILI9341_Fill_Screen(WHITE); 320 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 321 | ILI9341_Draw_Text("Randomly placed and sized", 10, 10, BLACK, 1, WHITE); 322 | ILI9341_Draw_Text("Rectangles", 10, 20, BLACK, 1, WHITE); 323 | HAL_Delay(2000); 324 | ILI9341_Fill_Screen(WHITE); 325 | 326 | for(uint32_t i = 0; i < 20000; i++) 327 | { 328 | uint32_t random_num = 0; 329 | uint16_t xr = 0; 330 | uint16_t yr = 0; 331 | uint16_t radiusr = 0; 332 | uint16_t colourr = 0; 333 | random_num = HAL_RNG_GetRandomNumber(&hrng); 334 | xr = random_num; 335 | random_num = HAL_RNG_GetRandomNumber(&hrng); 336 | yr = random_num; 337 | random_num = HAL_RNG_GetRandomNumber(&hrng); 338 | radiusr = random_num; 339 | random_num = HAL_RNG_GetRandomNumber(&hrng); 340 | colourr = random_num; 341 | 342 | xr &= 0x01FF; 343 | yr &= 0x01FF; 344 | radiusr &= 0x001F; 345 | //ili9341_drawpixel(xr, yr, WHITE); 346 | ILI9341_Draw_Hollow_Rectangle_Coord(xr, yr, xr+radiusr, yr+radiusr, colourr); 347 | } 348 | HAL_Delay(1000); 349 | 350 | //----------------------------------------------------------FILLED RECTANGLES EXAMPLE 351 | ILI9341_Fill_Screen(WHITE); 352 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 353 | ILI9341_Draw_Text("Randomly placed and sized", 10, 10, BLACK, 1, WHITE); 354 | ILI9341_Draw_Text("Filled Rectangles", 10, 20, BLACK, 1, WHITE); 355 | HAL_Delay(2000); 356 | ILI9341_Fill_Screen(WHITE); 357 | 358 | for(uint32_t i = 0; i < 20000; i++) 359 | { 360 | uint32_t random_num = 0; 361 | uint16_t xr = 0; 362 | uint16_t yr = 0; 363 | uint16_t radiusr = 0; 364 | uint16_t colourr = 0; 365 | random_num = HAL_RNG_GetRandomNumber(&hrng); 366 | xr = random_num; 367 | random_num = HAL_RNG_GetRandomNumber(&hrng); 368 | yr = random_num; 369 | random_num = HAL_RNG_GetRandomNumber(&hrng); 370 | radiusr = random_num; 371 | random_num = HAL_RNG_GetRandomNumber(&hrng); 372 | colourr = random_num; 373 | 374 | xr &= 0x01FF; 375 | yr &= 0x01FF; 376 | radiusr &= 0x001F; 377 | //ili9341_drawpixel(xr, yr, WHITE); 378 | ILI9341_Draw_Rectangle(xr, yr, radiusr, radiusr, colourr); 379 | } 380 | HAL_Delay(1000); 381 | 382 | //----------------------------------------------------------INDIVIDUAL PIXEL EXAMPLE 383 | 384 | ILI9341_Fill_Screen(WHITE); 385 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 386 | ILI9341_Draw_Text("Slow draw by selecting", 10, 10, BLACK, 1, WHITE); 387 | ILI9341_Draw_Text("and adressing pixels", 10, 20, BLACK, 1, WHITE); 388 | HAL_Delay(2000); 389 | ILI9341_Fill_Screen(WHITE); 390 | 391 | 392 | x = 0; 393 | y = 0; 394 | while (y < 240) 395 | { 396 | while ((x < 320) && (y < 240)) 397 | { 398 | 399 | if(x % 2) 400 | { 401 | ILI9341_Draw_Pixel(x, y, BLACK); 402 | } 403 | 404 | x++; 405 | } 406 | 407 | y++; 408 | x = 0; 409 | } 410 | 411 | x = 0; 412 | y = 0; 413 | 414 | 415 | while (y < 240) 416 | { 417 | while ((x < 320) && (y < 240)) 418 | { 419 | 420 | if(y % 2) 421 | { 422 | ILI9341_Draw_Pixel(x, y, BLACK); 423 | } 424 | 425 | x++; 426 | } 427 | 428 | y++; 429 | x = 0; 430 | } 431 | HAL_Delay(2000); 432 | 433 | //----------------------------------------------------------INDIVIDUAL PIXEL EXAMPLE 434 | ILI9341_Fill_Screen(WHITE); 435 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 436 | ILI9341_Draw_Text("Random position and colour", 10, 10, BLACK, 1, WHITE); 437 | ILI9341_Draw_Text("500000 pixels", 10, 20, BLACK, 1, WHITE); 438 | HAL_Delay(2000); 439 | ILI9341_Fill_Screen(WHITE); 440 | 441 | 442 | for(uint32_t i = 0; i < 500000; i++) 443 | { 444 | uint32_t random_num = 0; 445 | uint16_t xr = 0; 446 | uint16_t yr = 0; 447 | random_num = HAL_RNG_GetRandomNumber(&hrng); 448 | xr = random_num; 449 | random_num = HAL_RNG_GetRandomNumber(&hrng); 450 | yr = random_num; 451 | uint16_t color = HAL_RNG_GetRandomNumber(&hrng); 452 | 453 | xr &= 0x01FF; 454 | yr &= 0x01FF; 455 | ILI9341_Draw_Pixel(xr, yr, color); 456 | } 457 | HAL_Delay(2000); 458 | 459 | //----------------------------------------------------------565 COLOUR EXAMPLE, Grayscale 460 | ILI9341_Fill_Screen(WHITE); 461 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 462 | ILI9341_Draw_Text("Colour gradient", 10, 10, BLACK, 1, WHITE); 463 | ILI9341_Draw_Text("Grayscale", 10, 20, BLACK, 1, WHITE); 464 | HAL_Delay(2000); 465 | 466 | 467 | for(uint16_t i = 0; i <= (320); i++) 468 | { 469 | uint16_t Red = 0; 470 | uint16_t Green = 0; 471 | uint16_t Blue = 0; 472 | 473 | Red = i/(10); 474 | Red <<= 11; 475 | Green = i/(5); 476 | Green <<= 5; 477 | Blue = i/(10); 478 | 479 | 480 | 481 | uint16_t RGB_color = Red + Green + Blue; 482 | ILI9341_Draw_Rectangle(i, x, 1, 240, RGB_color); 483 | 484 | } 485 | HAL_Delay(2000); 486 | 487 | //----------------------------------------------------------IMAGE EXAMPLE, Snow Tiger 488 | ILI9341_Fill_Screen(WHITE); 489 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 490 | ILI9341_Draw_Text("RGB Picture", 10, 10, BLACK, 1, WHITE); 491 | ILI9341_Draw_Text("TIGER", 10, 20, BLACK, 1, WHITE); 492 | HAL_Delay(2000); 493 | ILI9341_Draw_Image((const char*)snow_tiger, SCREEN_VERTICAL_2); 494 | ILI9341_Set_Rotation(SCREEN_VERTICAL_1); 495 | HAL_Delay(10000); 496 | 497 | 498 | //----------------------------------------------------------TOUCHSCREEN EXAMPLE 499 | ILI9341_Fill_Screen(WHITE); 500 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 501 | ILI9341_Draw_Text("Touchscreen", 10, 10, BLACK, 2, WHITE); 502 | ILI9341_Draw_Text("Touch to draw", 10, 30, BLACK, 2, WHITE); 503 | ILI9341_Set_Rotation(SCREEN_VERTICAL_1); 504 | 505 | while(1) 506 | { 507 | 508 | if(TP_Touchpad_Pressed()) 509 | { 510 | 511 | uint16_t x_pos = 0; 512 | uint16_t y_pos = 0; 513 | 514 | 515 | HAL_GPIO_WritePin(GPIOB, LD3_Pin|LD2_Pin, GPIO_PIN_SET); 516 | 517 | uint16_t position_array[2]; 518 | 519 | if(TP_Read_Coordinates(position_array) == TOUCHPAD_DATA_OK) 520 | { 521 | x_pos = position_array[0]; 522 | y_pos = position_array[1]; 523 | ILI9341_Draw_Filled_Circle(x_pos, y_pos, 2, BLACK); 524 | 525 | ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2); 526 | char counter_buff[30]; 527 | sprintf(counter_buff, "POS X: %.3d", x_pos); 528 | ILI9341_Draw_Text(counter_buff, 10, 80, BLACK, 2, WHITE); 529 | sprintf(counter_buff, "POS Y: %.3d", y_pos); 530 | ILI9341_Draw_Text(counter_buff, 10, 120, BLACK, 2, WHITE); 531 | ILI9341_Set_Rotation(SCREEN_VERTICAL_1); 532 | } 533 | 534 | //ILI9341_Draw_Pixel(x_pos, y_pos, BLACK); 535 | 536 | } 537 | else 538 | { 539 | HAL_GPIO_WritePin(GPIOB, LD3_Pin|LD2_Pin, GPIO_PIN_RESET); 540 | } 541 | 542 | } 543 | 544 | 545 | } 546 | /* USER CODE END 3 */ 547 | 548 | } 549 | 550 | /** System Clock Configuration 551 | */ 552 | void SystemClock_Config(void) 553 | { 554 | 555 | RCC_OscInitTypeDef RCC_OscInitStruct; 556 | RCC_ClkInitTypeDef RCC_ClkInitStruct; 557 | RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; 558 | 559 | __HAL_RCC_PWR_CLK_ENABLE(); 560 | 561 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); 562 | 563 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 564 | RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; 565 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 566 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 567 | RCC_OscInitStruct.PLL.PLLM = 4; 568 | RCC_OscInitStruct.PLL.PLLN = 200; 569 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 570 | RCC_OscInitStruct.PLL.PLLQ = 9; 571 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 572 | { 573 | Error_Handler(); 574 | } 575 | 576 | if (HAL_PWREx_EnableOverDrive() != HAL_OK) 577 | { 578 | Error_Handler(); 579 | } 580 | 581 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 582 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 583 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 584 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 585 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 586 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 587 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) != HAL_OK) 588 | { 589 | Error_Handler(); 590 | } 591 | 592 | PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_CLK48; 593 | PeriphClkInitStruct.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1; 594 | PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLL; 595 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) 596 | { 597 | Error_Handler(); 598 | } 599 | 600 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); 601 | 602 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 603 | 604 | /* SysTick_IRQn interrupt configuration */ 605 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 606 | } 607 | 608 | /* USER CODE BEGIN 4 */ 609 | 610 | /* USER CODE END 4 */ 611 | 612 | /** 613 | * @brief This function is executed in case of error occurrence. 614 | * @param None 615 | * @retval None 616 | */ 617 | void Error_Handler(void) 618 | { 619 | /* USER CODE BEGIN Error_Handler */ 620 | /* User can add his own implementation to report the HAL error return state */ 621 | while(1) 622 | { 623 | } 624 | /* USER CODE END Error_Handler */ 625 | } 626 | 627 | #ifdef USE_FULL_ASSERT 628 | 629 | /** 630 | * @brief Reports the name of the source file and the source line number 631 | * where the assert_param error has occurred. 632 | * @param file: pointer to the source file name 633 | * @param line: assert_param error line source number 634 | * @retval None 635 | */ 636 | void assert_failed(uint8_t* file, uint32_t line) 637 | { 638 | /* USER CODE BEGIN 6 */ 639 | /* User can add his own implementation to report the file name and line number, 640 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 641 | /* USER CODE END 6 */ 642 | 643 | } 644 | 645 | #endif 646 | 647 | /** 648 | * @} 649 | */ 650 | 651 | /** 652 | * @} 653 | */ 654 | 655 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 656 | -------------------------------------------------------------------------------- /Src/rng.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : RNG.c 4 | * Description : This file provides code for the configuration 5 | * of the RNG instances. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "rng.h" 37 | 38 | /* USER CODE BEGIN 0 */ 39 | 40 | /* USER CODE END 0 */ 41 | 42 | RNG_HandleTypeDef hrng; 43 | 44 | /* RNG init function */ 45 | void MX_RNG_Init(void) 46 | { 47 | 48 | hrng.Instance = RNG; 49 | if (HAL_RNG_Init(&hrng) != HAL_OK) 50 | { 51 | Error_Handler(); 52 | } 53 | 54 | } 55 | 56 | void HAL_RNG_MspInit(RNG_HandleTypeDef* rngHandle) 57 | { 58 | 59 | if(rngHandle->Instance==RNG) 60 | { 61 | /* USER CODE BEGIN RNG_MspInit 0 */ 62 | 63 | /* USER CODE END RNG_MspInit 0 */ 64 | /* Peripheral clock enable */ 65 | __HAL_RCC_RNG_CLK_ENABLE(); 66 | /* USER CODE BEGIN RNG_MspInit 1 */ 67 | 68 | /* USER CODE END RNG_MspInit 1 */ 69 | } 70 | } 71 | 72 | void HAL_RNG_MspDeInit(RNG_HandleTypeDef* rngHandle) 73 | { 74 | 75 | if(rngHandle->Instance==RNG) 76 | { 77 | /* USER CODE BEGIN RNG_MspDeInit 0 */ 78 | 79 | /* USER CODE END RNG_MspDeInit 0 */ 80 | /* Peripheral clock disable */ 81 | __HAL_RCC_RNG_CLK_DISABLE(); 82 | } 83 | /* USER CODE BEGIN RNG_MspDeInit 1 */ 84 | 85 | /* USER CODE END RNG_MspDeInit 1 */ 86 | } 87 | 88 | /* USER CODE BEGIN 1 */ 89 | 90 | /* USER CODE END 1 */ 91 | 92 | /** 93 | * @} 94 | */ 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 101 | -------------------------------------------------------------------------------- /Src/spi.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : SPI.c 4 | * Description : This file provides code for the configuration 5 | * of the SPI instances. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "spi.h" 37 | 38 | #include "gpio.h" 39 | 40 | /* USER CODE BEGIN 0 */ 41 | 42 | /* USER CODE END 0 */ 43 | 44 | SPI_HandleTypeDef hspi5; 45 | 46 | /* SPI5 init function */ 47 | void MX_SPI5_Init(void) 48 | { 49 | 50 | hspi5.Instance = SPI5; 51 | hspi5.Init.Mode = SPI_MODE_MASTER; 52 | hspi5.Init.Direction = SPI_DIRECTION_2LINES; 53 | hspi5.Init.DataSize = SPI_DATASIZE_8BIT; 54 | hspi5.Init.CLKPolarity = SPI_POLARITY_LOW; 55 | hspi5.Init.CLKPhase = SPI_PHASE_1EDGE; 56 | hspi5.Init.NSS = SPI_NSS_SOFT; 57 | hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; 58 | hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB; 59 | hspi5.Init.TIMode = SPI_TIMODE_DISABLE; 60 | hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; 61 | hspi5.Init.CRCPolynomial = 7; 62 | hspi5.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; 63 | hspi5.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; 64 | if (HAL_SPI_Init(&hspi5) != HAL_OK) 65 | { 66 | Error_Handler(); 67 | } 68 | 69 | } 70 | 71 | void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) 72 | { 73 | 74 | GPIO_InitTypeDef GPIO_InitStruct; 75 | if(spiHandle->Instance==SPI5) 76 | { 77 | /* USER CODE BEGIN SPI5_MspInit 0 */ 78 | 79 | /* USER CODE END SPI5_MspInit 0 */ 80 | /* Peripheral clock enable */ 81 | __HAL_RCC_SPI5_CLK_ENABLE(); 82 | 83 | /**SPI5 GPIO Configuration 84 | PF7 ------> SPI5_SCK 85 | PF8 ------> SPI5_MISO 86 | PF9 ------> SPI5_MOSI 87 | */ 88 | GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9; 89 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 90 | GPIO_InitStruct.Pull = GPIO_NOPULL; 91 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 92 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI5; 93 | HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); 94 | 95 | /* USER CODE BEGIN SPI5_MspInit 1 */ 96 | 97 | /* USER CODE END SPI5_MspInit 1 */ 98 | } 99 | } 100 | 101 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) 102 | { 103 | 104 | if(spiHandle->Instance==SPI5) 105 | { 106 | /* USER CODE BEGIN SPI5_MspDeInit 0 */ 107 | 108 | /* USER CODE END SPI5_MspDeInit 0 */ 109 | /* Peripheral clock disable */ 110 | __HAL_RCC_SPI5_CLK_DISABLE(); 111 | 112 | /**SPI5 GPIO Configuration 113 | PF7 ------> SPI5_SCK 114 | PF8 ------> SPI5_MISO 115 | PF9 ------> SPI5_MOSI 116 | */ 117 | HAL_GPIO_DeInit(GPIOF, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9); 118 | 119 | } 120 | /* USER CODE BEGIN SPI5_MspDeInit 1 */ 121 | 122 | /* USER CODE END SPI5_MspDeInit 1 */ 123 | } 124 | 125 | /* USER CODE BEGIN 1 */ 126 | 127 | /* USER CODE END 1 */ 128 | 129 | /** 130 | * @} 131 | */ 132 | 133 | /** 134 | * @} 135 | */ 136 | 137 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 138 | -------------------------------------------------------------------------------- /Src/stm32f7xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : stm32f7xx_hal_msp.c 4 | * Description : This file provides code for the MSP Initialization 5 | * and de-Initialization codes. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | /* Includes ------------------------------------------------------------------*/ 35 | #include "stm32f7xx_hal.h" 36 | 37 | extern void Error_Handler(void); 38 | /* USER CODE BEGIN 0 */ 39 | 40 | /* USER CODE END 0 */ 41 | 42 | /** 43 | * Initializes the Global MSP. 44 | */ 45 | void HAL_MspInit(void) 46 | { 47 | /* USER CODE BEGIN MspInit 0 */ 48 | 49 | /* USER CODE END MspInit 0 */ 50 | 51 | HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); 52 | 53 | /* System interrupt init*/ 54 | /* MemoryManagement_IRQn interrupt configuration */ 55 | HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0); 56 | /* BusFault_IRQn interrupt configuration */ 57 | HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0); 58 | /* UsageFault_IRQn interrupt configuration */ 59 | HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0); 60 | /* SVCall_IRQn interrupt configuration */ 61 | HAL_NVIC_SetPriority(SVCall_IRQn, 0, 0); 62 | /* DebugMonitor_IRQn interrupt configuration */ 63 | HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0); 64 | /* PendSV_IRQn interrupt configuration */ 65 | HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0); 66 | /* SysTick_IRQn interrupt configuration */ 67 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 68 | 69 | /* USER CODE BEGIN MspInit 1 */ 70 | 71 | /* USER CODE END MspInit 1 */ 72 | } 73 | 74 | /* USER CODE BEGIN 1 */ 75 | 76 | /* USER CODE END 1 */ 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | -------------------------------------------------------------------------------- /Src/stm32f7xx_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f7xx_it.c 4 | * @brief Interrupt Service Routines. 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2017 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm32f7xx_hal.h" 35 | #include "stm32f7xx.h" 36 | #include "stm32f7xx_it.h" 37 | 38 | /* USER CODE BEGIN 0 */ 39 | 40 | /* USER CODE END 0 */ 41 | 42 | /* External variables --------------------------------------------------------*/ 43 | 44 | /******************************************************************************/ 45 | /* Cortex-M7 Processor Interruption and Exception Handlers */ 46 | /******************************************************************************/ 47 | 48 | /** 49 | * @brief This function handles System tick timer. 50 | */ 51 | void SysTick_Handler(void) 52 | { 53 | /* USER CODE BEGIN SysTick_IRQn 0 */ 54 | 55 | /* USER CODE END SysTick_IRQn 0 */ 56 | HAL_IncTick(); 57 | HAL_SYSTICK_IRQHandler(); 58 | /* USER CODE BEGIN SysTick_IRQn 1 */ 59 | 60 | /* USER CODE END SysTick_IRQn 1 */ 61 | } 62 | 63 | /******************************************************************************/ 64 | /* STM32F7xx Peripheral Interrupt Handlers */ 65 | /* Add here the Interrupt Handlers for the used peripherals. */ 66 | /* For the available peripheral interrupt handler names, */ 67 | /* please refer to the startup file (startup_stm32f7xx.s). */ 68 | /******************************************************************************/ 69 | 70 | /* USER CODE BEGIN 1 */ 71 | 72 | /* USER CODE END 1 */ 73 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 74 | -------------------------------------------------------------------------------- /Src/tim.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : TIM.c 4 | * Description : This file provides code for the configuration 5 | * of the TIM instances. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "tim.h" 37 | 38 | /* USER CODE BEGIN 0 */ 39 | 40 | /* USER CODE END 0 */ 41 | 42 | TIM_HandleTypeDef htim1; 43 | 44 | /* TIM1 init function */ 45 | void MX_TIM1_Init(void) 46 | { 47 | TIM_ClockConfigTypeDef sClockSourceConfig; 48 | TIM_MasterConfigTypeDef sMasterConfig; 49 | 50 | htim1.Instance = TIM1; 51 | htim1.Init.Prescaler = 10000; 52 | htim1.Init.CounterMode = TIM_COUNTERMODE_UP; 53 | htim1.Init.Period = 65535; 54 | htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV2; 55 | htim1.Init.RepetitionCounter = 0; 56 | if (HAL_TIM_Base_Init(&htim1) != HAL_OK) 57 | { 58 | Error_Handler(); 59 | } 60 | 61 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; 62 | if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) 63 | { 64 | Error_Handler(); 65 | } 66 | 67 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; 68 | sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET; 69 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; 70 | if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) 71 | { 72 | Error_Handler(); 73 | } 74 | 75 | } 76 | 77 | void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) 78 | { 79 | 80 | if(tim_baseHandle->Instance==TIM1) 81 | { 82 | /* USER CODE BEGIN TIM1_MspInit 0 */ 83 | 84 | /* USER CODE END TIM1_MspInit 0 */ 85 | /* Peripheral clock enable */ 86 | __HAL_RCC_TIM1_CLK_ENABLE(); 87 | /* USER CODE BEGIN TIM1_MspInit 1 */ 88 | 89 | /* USER CODE END TIM1_MspInit 1 */ 90 | } 91 | } 92 | 93 | void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) 94 | { 95 | 96 | if(tim_baseHandle->Instance==TIM1) 97 | { 98 | /* USER CODE BEGIN TIM1_MspDeInit 0 */ 99 | 100 | /* USER CODE END TIM1_MspDeInit 0 */ 101 | /* Peripheral clock disable */ 102 | __HAL_RCC_TIM1_CLK_DISABLE(); 103 | } 104 | /* USER CODE BEGIN TIM1_MspDeInit 1 */ 105 | 106 | /* USER CODE END TIM1_MspDeInit 1 */ 107 | } 108 | 109 | /* USER CODE BEGIN 1 */ 110 | 111 | /* USER CODE END 1 */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** 118 | * @} 119 | */ 120 | 121 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 122 | -------------------------------------------------------------------------------- /Src/usart.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : USART.c 4 | * Description : This file provides code for the configuration 5 | * of the USART instances. 6 | ****************************************************************************** 7 | * 8 | * COPYRIGHT(c) 2017 STMicroelectronics 9 | * 10 | * Redistribution and use in source and binary forms, with or without modification, 11 | * are permitted provided that the following conditions are met: 12 | * 1. Redistributions of source code must retain the above copyright notice, 13 | * this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright notice, 15 | * this list of conditions and the following disclaimer in the documentation 16 | * and/or other materials provided with the distribution. 17 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | ****************************************************************************** 33 | */ 34 | 35 | /* Includes ------------------------------------------------------------------*/ 36 | #include "usart.h" 37 | 38 | #include "gpio.h" 39 | 40 | /* USER CODE BEGIN 0 */ 41 | 42 | /* USER CODE END 0 */ 43 | 44 | UART_HandleTypeDef huart3; 45 | 46 | /* USART3 init function */ 47 | 48 | void MX_USART3_UART_Init(void) 49 | { 50 | 51 | huart3.Instance = USART3; 52 | huart3.Init.BaudRate = 115200; 53 | huart3.Init.WordLength = UART_WORDLENGTH_7B; 54 | huart3.Init.StopBits = UART_STOPBITS_1; 55 | huart3.Init.Parity = UART_PARITY_NONE; 56 | huart3.Init.Mode = UART_MODE_TX_RX; 57 | huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; 58 | huart3.Init.OverSampling = UART_OVERSAMPLING_16; 59 | huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 60 | huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 61 | if (HAL_UART_Init(&huart3) != HAL_OK) 62 | { 63 | Error_Handler(); 64 | } 65 | 66 | } 67 | 68 | void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) 69 | { 70 | 71 | GPIO_InitTypeDef GPIO_InitStruct; 72 | if(uartHandle->Instance==USART3) 73 | { 74 | /* USER CODE BEGIN USART3_MspInit 0 */ 75 | 76 | /* USER CODE END USART3_MspInit 0 */ 77 | /* Peripheral clock enable */ 78 | __HAL_RCC_USART3_CLK_ENABLE(); 79 | 80 | /**USART3 GPIO Configuration 81 | PD8 ------> USART3_TX 82 | PD9 ------> USART3_RX 83 | */ 84 | GPIO_InitStruct.Pin = STLK_RX_Pin|STLK_TX_Pin; 85 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 86 | GPIO_InitStruct.Pull = GPIO_PULLUP; 87 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 88 | GPIO_InitStruct.Alternate = GPIO_AF7_USART3; 89 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); 90 | 91 | /* USER CODE BEGIN USART3_MspInit 1 */ 92 | 93 | /* USER CODE END USART3_MspInit 1 */ 94 | } 95 | } 96 | 97 | void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) 98 | { 99 | 100 | if(uartHandle->Instance==USART3) 101 | { 102 | /* USER CODE BEGIN USART3_MspDeInit 0 */ 103 | 104 | /* USER CODE END USART3_MspDeInit 0 */ 105 | /* Peripheral clock disable */ 106 | __HAL_RCC_USART3_CLK_DISABLE(); 107 | 108 | /**USART3 GPIO Configuration 109 | PD8 ------> USART3_TX 110 | PD9 ------> USART3_RX 111 | */ 112 | HAL_GPIO_DeInit(GPIOD, STLK_RX_Pin|STLK_TX_Pin); 113 | 114 | } 115 | /* USER CODE BEGIN USART3_MspDeInit 1 */ 116 | 117 | /* USER CODE END USART3_MspDeInit 1 */ 118 | } 119 | 120 | /* USER CODE BEGIN 1 */ 121 | 122 | /* USER CODE END 1 */ 123 | 124 | /** 125 | * @} 126 | */ 127 | 128 | /** 129 | * @} 130 | */ 131 | 132 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 133 | --------------------------------------------------------------------------------