diff --git a/ports/stm32f4/Makefile b/ports/stm32f4/Makefile
index 1e40715732..5f04b49011 100755
--- a/ports/stm32f4/Makefile
+++ b/ports/stm32f4/Makefile
@@ -143,7 +143,6 @@ CFLAGS += -DHSE_VALUE=8000000 -DCFG_TUSB_MCU=OPT_MCU_STM32F4 -DCFG_TUD_CDC_RX_BU
######################################
SRC_STM32 = \
- boards/$(BOARD)/stm32f4xx_hal_msp.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_gpio.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_adc.c \
stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c \
diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_msp.c b/ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_msp.c
deleted file mode 100644
index a892a8ff7e..0000000000
--- a/ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_msp.c
+++ /dev/null
@@ -1,427 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
- * File Name : stm32f4xx_hal_msp.c
- * Description : This file provides code for the MSP Initialization
- * and de-Initialization codes.
- ******************************************************************************
- * @attention
- *
- *
© Copyright (c) 2019 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
- *
- ******************************************************************************
- */
-/* USER CODE END Header */
-
-/* Includes ------------------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-#include "stm32f4xx_hal.h"
-/* USER CODE END Includes */
-
-/* Private typedef -----------------------------------------------------------*/
-/* USER CODE BEGIN TD */
-
-/* USER CODE END TD */
-
-/* Private define ------------------------------------------------------------*/
-/* USER CODE BEGIN Define */
-#define DATA_Ready_Pin GPIO_PIN_2
-#define DATA_Ready_GPIO_Port GPIOE
-#define CS_I2C_SPI_Pin GPIO_PIN_3
-#define CS_I2C_SPI_GPIO_Port GPIOE
-#define INT1_Pin GPIO_PIN_4
-#define INT1_GPIO_Port GPIOE
-#define INT2_Pin GPIO_PIN_5
-#define INT2_GPIO_Port GPIOE
-#define PC14_OSC32_IN_Pin GPIO_PIN_14
-#define PC14_OSC32_IN_GPIO_Port GPIOC
-#define PC15_OSC32_OUT_Pin GPIO_PIN_15
-#define PC15_OSC32_OUT_GPIO_Port GPIOC
-#define PH0_OSC_IN_Pin GPIO_PIN_0
-#define PH0_OSC_IN_GPIO_Port GPIOH
-#define PH1_OSC_OUT_Pin GPIO_PIN_1
-#define PH1_OSC_OUT_GPIO_Port GPIOH
-#define OTG_FS_PowerSwitchOn_Pin GPIO_PIN_0
-#define OTG_FS_PowerSwitchOn_GPIO_Port GPIOC
-#define PDM_OUT_Pin GPIO_PIN_3
-#define PDM_OUT_GPIO_Port GPIOC
-#define I2S3_WS_Pin GPIO_PIN_4
-#define I2S3_WS_GPIO_Port GPIOA
-#define SPI1_SCK_Pin GPIO_PIN_5
-#define SPI1_SCK_GPIO_Port GPIOA
-#define SPI1_MISO_Pin GPIO_PIN_6
-#define SPI1_MISO_GPIO_Port GPIOA
-#define SPI1_MOSI_Pin GPIO_PIN_7
-#define SPI1_MOSI_GPIO_Port GPIOA
-#define CLK_IN_Pin GPIO_PIN_10
-#define CLK_IN_GPIO_Port GPIOB
-#define LD4_Pin GPIO_PIN_12
-#define LD4_GPIO_Port GPIOD
-#define LD3_Pin GPIO_PIN_13
-#define LD3_GPIO_Port GPIOD
-#define LD5_Pin GPIO_PIN_14
-#define LD5_GPIO_Port GPIOD
-#define LD6_Pin GPIO_PIN_15
-#define LD6_GPIO_Port GPIOD
-#define I2S3_MCK_Pin GPIO_PIN_7
-#define I2S3_MCK_GPIO_Port GPIOC
-#define VBUS_FS_Pin GPIO_PIN_9
-#define VBUS_FS_GPIO_Port GPIOA
-#define OTG_FS_ID_Pin GPIO_PIN_10
-#define OTG_FS_ID_GPIO_Port GPIOA
-#define OTG_FS_DM_Pin GPIO_PIN_11
-#define OTG_FS_DM_GPIO_Port GPIOA
-#define OTG_FS_DP_Pin GPIO_PIN_12
-#define OTG_FS_DP_GPIO_Port GPIOA
-#define SWDIO_Pin GPIO_PIN_13
-#define SWDIO_GPIO_Port GPIOA
-#define SWCLK_Pin GPIO_PIN_14
-#define SWCLK_GPIO_Port GPIOA
-#define I2S3_SCK_Pin GPIO_PIN_10
-#define I2S3_SCK_GPIO_Port GPIOC
-#define I2S3_SD_Pin GPIO_PIN_12
-#define I2S3_SD_GPIO_Port GPIOC
-#define Audio_RST_Pin GPIO_PIN_4
-#define Audio_RST_GPIO_Port GPIOD
-#define OTG_FS_OverCurrent_Pin GPIO_PIN_5
-#define OTG_FS_OverCurrent_GPIO_Port GPIOD
-#define SWO_Pin GPIO_PIN_3
-#define SWO_GPIO_Port GPIOB
-#define Audio_SCL_Pin GPIO_PIN_6
-#define Audio_SCL_GPIO_Port GPIOB
-#define Audio_SDA_Pin GPIO_PIN_9
-#define Audio_SDA_GPIO_Port GPIOB
-#define MEMS_INT2_Pin GPIO_PIN_1
-#define MEMS_INT2_GPIO_Port GPIOE
-
-/* USER CODE END Define */
-
-/* Private macro -------------------------------------------------------------*/
-/* USER CODE BEGIN Macro */
-
-/* USER CODE END Macro */
-
-/* Private variables ---------------------------------------------------------*/
-/* USER CODE BEGIN PV */
-
-/* USER CODE END PV */
-
-/* Private function prototypes -----------------------------------------------*/
-/* USER CODE BEGIN PFP */
-
-/* USER CODE END PFP */
-
-/* External functions --------------------------------------------------------*/
-/* USER CODE BEGIN ExternalFunctions */
-
-/* USER CODE END ExternalFunctions */
-
-/* USER CODE BEGIN 0 */
-
-/* USER CODE END 0 */
-/**
- * Initializes the Global MSP.
- */
-void HAL_MspInit(void)
-{
- /* USER CODE BEGIN MspInit 0 */
-
- /* USER CODE END MspInit 0 */
-
- __HAL_RCC_SYSCFG_CLK_ENABLE();
- __HAL_RCC_PWR_CLK_ENABLE();
-
- HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
-
- /* System interrupt init*/
-
- /* USER CODE BEGIN MspInit 1 */
-
- /* USER CODE END MspInit 1 */
-}
-
-/**
-* @brief I2C MSP Initialization
-* This function configures the hardware resources used in this example
-* @param hi2c: I2C handle pointer
-* @retval None
-*/
-void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- if(hi2c->Instance==I2C1)
- {
- /* USER CODE BEGIN I2C1_MspInit 0 */
-
- /* USER CODE END I2C1_MspInit 0 */
-
- __HAL_RCC_GPIOB_CLK_ENABLE();
- /**I2C1 GPIO Configuration
- PB6 ------> I2C1_SCL
- PB9 ------> I2C1_SDA
- */
- GPIO_InitStruct.Pin = Audio_SCL_Pin|GPIO_PIN_7;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- /* Peripheral clock enable */
- __HAL_RCC_I2C1_CLK_ENABLE();
- /* USER CODE BEGIN I2C1_MspInit 1 */
-
- /* USER CODE END I2C1_MspInit 1 */
- }
-
-}
-
-/**
-* @brief I2C MSP De-Initialization
-* This function freeze the hardware resources used in this example
-* @param hi2c: I2C handle pointer
-* @retval None
-*/
-void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
-{
- if(hi2c->Instance==I2C1)
- {
- /* USER CODE BEGIN I2C1_MspDeInit 0 */
-
- /* USER CODE END I2C1_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_I2C1_CLK_DISABLE();
-
- /**I2C1 GPIO Configuration
- PB6 ------> I2C1_SCL
- PB9 ------> I2C1_SDA
- */
- HAL_GPIO_DeInit(GPIOB, Audio_SCL_Pin|Audio_SDA_Pin);
-
- /* USER CODE BEGIN I2C1_MspDeInit 1 */
-
- /* USER CODE END I2C1_MspDeInit 1 */
- }
-
-}
-
-/**
-* @brief I2S MSP Initialization
-* This function configures the hardware resources used in this example
-* @param hi2s: I2S handle pointer
-* @retval None
-*/
-void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s)
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- if(hi2s->Instance==SPI2)
- {
- /* USER CODE BEGIN SPI2_MspInit 0 */
-
- /* USER CODE END SPI2_MspInit 0 */
- /* Peripheral clock enable */
- __HAL_RCC_SPI2_CLK_ENABLE();
-
- __HAL_RCC_GPIOC_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- /**I2S2 GPIO Configuration
- PC2 ------> I2S2_ext_SD
- PC3 ------> I2S2_SD
- PB10 ------> I2S2_CK
- PB12 ------> I2S2_WS
- */
- GPIO_InitStruct.Pin = GPIO_PIN_2;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF6_I2S2ext;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = PDM_OUT_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
- HAL_GPIO_Init(PDM_OUT_GPIO_Port, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = CLK_IN_Pin|GPIO_PIN_12;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- /* USER CODE BEGIN SPI2_MspInit 1 */
-
- /* USER CODE END SPI2_MspInit 1 */
- }
- else if(hi2s->Instance==SPI3)
- {
- /* USER CODE BEGIN SPI3_MspInit 0 */
-
- /* USER CODE END SPI3_MspInit 0 */
- /* Peripheral clock enable */
- __HAL_RCC_SPI3_CLK_ENABLE();
-
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOC_CLK_ENABLE();
- /**I2S3 GPIO Configuration
- PA4 ------> I2S3_WS
- PC7 ------> I2S3_MCK
- PC10 ------> I2S3_CK
- PC12 ------> I2S3_SD
- */
- GPIO_InitStruct.Pin = I2S3_WS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
- HAL_GPIO_Init(I2S3_WS_GPIO_Port, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = I2S3_MCK_Pin|I2S3_SCK_Pin|I2S3_SD_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-
- /* USER CODE BEGIN SPI3_MspInit 1 */
-
- /* USER CODE END SPI3_MspInit 1 */
- }
-
-}
-
-/**
-* @brief I2S MSP De-Initialization
-* This function freeze the hardware resources used in this example
-* @param hi2s: I2S handle pointer
-* @retval None
-*/
-void HAL_I2S_MspDeInit(I2S_HandleTypeDef* hi2s)
-{
- if(hi2s->Instance==SPI2)
- {
- /* USER CODE BEGIN SPI2_MspDeInit 0 */
-
- /* USER CODE END SPI2_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_SPI2_CLK_DISABLE();
-
- /**I2S2 GPIO Configuration
- PC2 ------> I2S2_ext_SD
- PC3 ------> I2S2_SD
- PB10 ------> I2S2_CK
- PB12 ------> I2S2_WS
- */
- HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|PDM_OUT_Pin);
-
- HAL_GPIO_DeInit(GPIOB, CLK_IN_Pin|GPIO_PIN_12);
-
- /* USER CODE BEGIN SPI2_MspDeInit 1 */
-
- /* USER CODE END SPI2_MspDeInit 1 */
- }
- else if(hi2s->Instance==SPI3)
- {
- /* USER CODE BEGIN SPI3_MspDeInit 0 */
-
- /* USER CODE END SPI3_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_SPI3_CLK_DISABLE();
-
- /**I2S3 GPIO Configuration
- PA4 ------> I2S3_WS
- PC7 ------> I2S3_MCK
- PC10 ------> I2S3_CK
- PC12 ------> I2S3_SD
- */
- HAL_GPIO_DeInit(I2S3_WS_GPIO_Port, I2S3_WS_Pin);
-
- HAL_GPIO_DeInit(GPIOC, I2S3_MCK_Pin|I2S3_SCK_Pin|I2S3_SD_Pin);
-
- /* USER CODE BEGIN SPI3_MspDeInit 1 */
-
- /* USER CODE END SPI3_MspDeInit 1 */
- }
-
-}
-
-/**
-* @brief SPI MSP Initialization
-* This function configures the hardware resources used in this example
-* @param hspi: SPI handle pointer
-* @retval None
-*/
-void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- if(hspi->Instance==SPI1)
- {
- /* USER CODE BEGIN SPI1_MspInit 0 */
-
- /* USER CODE END SPI1_MspInit 0 */
- /* Peripheral clock enable */
- __HAL_RCC_SPI1_CLK_ENABLE();
-
- __HAL_RCC_GPIOA_CLK_ENABLE();
- /**SPI1 GPIO Configuration
- PA5 ------> SPI1_SCK
- PA6 ------> SPI1_MISO
- PA7 ------> SPI1_MOSI
- */
- GPIO_InitStruct.Pin = SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- /* USER CODE BEGIN SPI1_MspInit 1 */
-
- /* USER CODE END SPI1_MspInit 1 */
- }
-
-}
-
-/**
-* @brief SPI MSP De-Initialization
-* This function freeze the hardware resources used in this example
-* @param hspi: SPI handle pointer
-* @retval None
-*/
-void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
-{
- if(hspi->Instance==SPI1)
- {
- /* USER CODE BEGIN SPI1_MspDeInit 0 */
-
- /* USER CODE END SPI1_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_SPI1_CLK_DISABLE();
-
- /**SPI1 GPIO Configuration
- PA5 ------> SPI1_SCK
- PA6 ------> SPI1_MISO
- PA7 ------> SPI1_MOSI
- */
- HAL_GPIO_DeInit(GPIOA, SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin);
-
- /* USER CODE BEGIN SPI1_MspDeInit 1 */
-
- /* USER CODE END SPI1_MspDeInit 1 */
- }
-
-}
-
-/* USER CODE BEGIN 1 */
-
-/* USER CODE END 1 */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c b/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c
deleted file mode 100644
index df312fc29b..0000000000
--- a/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c
+++ /dev/null
@@ -1,832 +0,0 @@
-/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
- * File Name : stm32f4xx_hal_msp.c
- * Description : This file provides code for the MSP Initialization
- * and de-Initialization codes.
- ******************************************************************************
- * @attention
- *
- * © Copyright (c) 2019 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
- *
- ******************************************************************************
- */
-/* USER CODE END Header */
-
-/* Includes ------------------------------------------------------------------*/
-#include "stm32f4xx_hal.h"
-/* USER CODE BEGIN Includes */
-
-/* USER CODE END Includes */
-
-/* Private typedef -----------------------------------------------------------*/
-/* USER CODE BEGIN TD */
-
-/* USER CODE END TD */
-
-/* Private define ------------------------------------------------------------*/
-/* USER CODE BEGIN Define */
-#define LED3_Pin GPIO_PIN_2
-#define LED3_GPIO_Port GPIOE
-#define LED4_Pin GPIO_PIN_3
-#define LED4_GPIO_Port GPIOE
-#define DFSDM_DATIN3_Pin GPIO_PIN_4
-#define DFSDM_DATIN3_GPIO_Port GPIOE
-#define A0_Pin GPIO_PIN_0
-#define A0_GPIO_Port GPIOF
-#define LCD_BLCTRL_Pin GPIO_PIN_5
-#define LCD_BLCTRL_GPIO_Port GPIOF
-#define QSPI_BK1_IO3_Pin GPIO_PIN_6
-#define QSPI_BK1_IO3_GPIO_Port GPIOF
-#define QSPI_BK1_IO2_Pin GPIO_PIN_7
-#define QSPI_BK1_IO2_GPIO_Port GPIOF
-#define QSPI_BK1_IO0_Pin GPIO_PIN_8
-#define QSPI_BK1_IO0_GPIO_Port GPIOF
-#define QSPI_BK1_IO1_Pin GPIO_PIN_9
-#define QSPI_BK1_IO1_GPIO_Port GPIOF
-#define STLK_MCO_Pin GPIO_PIN_0
-#define STLK_MCO_GPIO_Port GPIOH
-#define DFSDM_CKOUT_Pin GPIO_PIN_2
-#define DFSDM_CKOUT_GPIO_Port GPIOC
-#define JOY_SEL_Pin GPIO_PIN_0
-#define JOY_SEL_GPIO_Port GPIOA
-#define STLINK_RX_Pin GPIO_PIN_2
-#define STLINK_RX_GPIO_Port GPIOA
-#define STLINK_TX_Pin GPIO_PIN_3
-#define STLINK_TX_GPIO_Port GPIOA
-#define CODEC_I2S3_WS_Pin GPIO_PIN_4
-#define CODEC_I2S3_WS_GPIO_Port GPIOA
-#define DFSDM_DATIN0_Pin GPIO_PIN_1
-#define DFSDM_DATIN0_GPIO_Port GPIOB
-#define QSPI_CLK_Pin GPIO_PIN_2
-#define QSPI_CLK_GPIO_Port GPIOB
-#define EXT_RESET_Pin GPIO_PIN_11
-#define EXT_RESET_GPIO_Port GPIOF
-#define CTP_RST_Pin GPIO_PIN_12
-#define CTP_RST_GPIO_Port GPIOF
-#define JOY_RIGHT_Pin GPIO_PIN_14
-#define JOY_RIGHT_GPIO_Port GPIOF
-#define JOY_LEFT_Pin GPIO_PIN_15
-#define JOY_LEFT_GPIO_Port GPIOF
-#define JOY_UP_Pin GPIO_PIN_0
-#define JOY_UP_GPIO_Port GPIOG
-#define JOY_DOWN_Pin GPIO_PIN_1
-#define JOY_DOWN_GPIO_Port GPIOG
-#define D4_Pin GPIO_PIN_7
-#define D4_GPIO_Port GPIOE
-#define D5_Pin GPIO_PIN_8
-#define D5_GPIO_Port GPIOE
-#define D6_Pin GPIO_PIN_9
-#define D6_GPIO_Port GPIOE
-#define D7_Pin GPIO_PIN_10
-#define D7_GPIO_Port GPIOE
-#define D8_Pin GPIO_PIN_11
-#define D8_GPIO_Port GPIOE
-#define D9_Pin GPIO_PIN_12
-#define D9_GPIO_Port GPIOE
-#define D10_Pin GPIO_PIN_13
-#define D10_GPIO_Port GPIOE
-#define D11_Pin GPIO_PIN_14
-#define D11_GPIO_Port GPIOE
-#define D12_Pin GPIO_PIN_15
-#define D12_GPIO_Port GPIOE
-#define I2C2_SCL_Pin GPIO_PIN_10
-#define I2C2_SCL_GPIO_Port GPIOB
-#define M2_CKIN_Pin GPIO_PIN_11
-#define M2_CKIN_GPIO_Port GPIOB
-#define CODEC_I2S3_SCK_Pin GPIO_PIN_12
-#define CODEC_I2S3_SCK_GPIO_Port GPIOB
-#define D13_Pin GPIO_PIN_8
-#define D13_GPIO_Port GPIOD
-#define D14_Pin GPIO_PIN_9
-#define D14_GPIO_Port GPIOD
-#define D15_Pin GPIO_PIN_10
-#define D15_GPIO_Port GPIOD
-#define LCD_RESET_Pin GPIO_PIN_11
-#define LCD_RESET_GPIO_Port GPIOD
-#define D0_Pin GPIO_PIN_14
-#define D0_GPIO_Port GPIOD
-#define D1_Pin GPIO_PIN_15
-#define D1_GPIO_Port GPIOD
-#define CODEC_INT_Pin GPIO_PIN_2
-#define CODEC_INT_GPIO_Port GPIOG
-#define LCD_TE_Pin GPIO_PIN_4
-#define LCD_TE_GPIO_Port GPIOG
-#define CTP_INT_Pin GPIO_PIN_5
-#define CTP_INT_GPIO_Port GPIOG
-#define QSPI_BK1_NCS_Pin GPIO_PIN_6
-#define QSPI_BK1_NCS_GPIO_Port GPIOG
-#define USB_OTGFS_OVRCR_Pin GPIO_PIN_7
-#define USB_OTGFS_OVRCR_GPIO_Port GPIOG
-#define USB_OTGFS_PPWR_EN_Pin GPIO_PIN_8
-#define USB_OTGFS_PPWR_EN_GPIO_Port GPIOG
-#define CODEC_I2S3_MCK_Pin GPIO_PIN_7
-#define CODEC_I2S3_MCK_GPIO_Port GPIOC
-#define uSD_D0_Pin GPIO_PIN_8
-#define uSD_D0_GPIO_Port GPIOC
-#define uSD_D1_Pin GPIO_PIN_9
-#define uSD_D1_GPIO_Port GPIOC
-#define M2_CKINA8_Pin GPIO_PIN_8
-#define M2_CKINA8_GPIO_Port GPIOA
-#define USB_OTGFS_VBUS_Pin GPIO_PIN_9
-#define USB_OTGFS_VBUS_GPIO_Port GPIOA
-#define USB_OTGFS_ID_Pin GPIO_PIN_10
-#define USB_OTGFS_ID_GPIO_Port GPIOA
-#define USB_OTGFS_DM_Pin GPIO_PIN_11
-#define USB_OTGFS_DM_GPIO_Port GPIOA
-#define USB_OTGFS_DP_Pin GPIO_PIN_12
-#define USB_OTGFS_DP_GPIO_Port GPIOA
-#define SWDIO_Pin GPIO_PIN_13
-#define SWDIO_GPIO_Port GPIOA
-#define SWCLK_Pin GPIO_PIN_14
-#define SWCLK_GPIO_Port GPIOA
-#define uSD_D2_Pin GPIO_PIN_10
-#define uSD_D2_GPIO_Port GPIOC
-#define uSD_D3_Pin GPIO_PIN_11
-#define uSD_D3_GPIO_Port GPIOC
-#define uSD_CLK_Pin GPIO_PIN_12
-#define uSD_CLK_GPIO_Port GPIOC
-#define D2_Pin GPIO_PIN_0
-#define D2_GPIO_Port GPIOD
-#define D3_Pin GPIO_PIN_1
-#define D3_GPIO_Port GPIOD
-#define uSD_CMD_Pin GPIO_PIN_2
-#define uSD_CMD_GPIO_Port GPIOD
-#define uSD_DETECT_Pin GPIO_PIN_3
-#define uSD_DETECT_GPIO_Port GPIOD
-#define FMC_NOE_Pin GPIO_PIN_4
-#define FMC_NOE_GPIO_Port GPIOD
-#define FMC_NWE_Pin GPIO_PIN_5
-#define FMC_NWE_GPIO_Port GPIOD
-#define FMC_NE1_Pin GPIO_PIN_7
-#define FMC_NE1_GPIO_Port GPIOD
-#define SWO_Pin GPIO_PIN_3
-#define SWO_GPIO_Port GPIOB
-#define CODEC_I2S3ext_SD_Pin GPIO_PIN_4
-#define CODEC_I2S3ext_SD_GPIO_Port GPIOB
-#define CODEC_I2S3_SD_Pin GPIO_PIN_5
-#define CODEC_I2S3_SD_GPIO_Port GPIOB
-#define I2C1_SCL_Pin GPIO_PIN_6
-#define I2C1_SCL_GPIO_Port GPIOB
-#define I2C1_SDA_Pin GPIO_PIN_7
-#define I2C1_SDA_GPIO_Port GPIOB
-#define I2C2_SDA_Pin GPIO_PIN_9
-#define I2C2_SDA_GPIO_Port GPIOB
-#define LED1_Pin GPIO_PIN_0
-#define LED1_GPIO_Port GPIOE
-#define LED2_Pin GPIO_PIN_1
-#define LED2_GPIO_Port GPIOE
-
-/* USER CODE END Define */
-
-/* Private macro -------------------------------------------------------------*/
-/* USER CODE BEGIN Macro */
-
-/* USER CODE END Macro */
-
-/* Private variables ---------------------------------------------------------*/
-/* USER CODE BEGIN PV */
-
-/* USER CODE END PV */
-
-/* Private function prototypes -----------------------------------------------*/
-/* USER CODE BEGIN PFP */
-
-/* USER CODE END PFP */
-
-/* External functions --------------------------------------------------------*/
-/* USER CODE BEGIN ExternalFunctions */
-
-/* USER CODE END ExternalFunctions */
-
-/* USER CODE BEGIN 0 */
-
-/* USER CODE END 0 */
-/**
- * Initializes the Global MSP.
- */
-void HAL_MspInit(void)
-{
- /* USER CODE BEGIN MspInit 0 */
-
- /* USER CODE END MspInit 0 */
-
- __HAL_RCC_SYSCFG_CLK_ENABLE();
- __HAL_RCC_PWR_CLK_ENABLE();
-
- /* System interrupt init*/
-
- /* USER CODE BEGIN MspInit 1 */
-
- /* USER CODE END MspInit 1 */
-}
-
-/**
-* @brief I2C MSP Initialization
-* This function configures the hardware resources used in this example
-* @param hi2c: I2C handle pointer
-* @retval None
-*/
-void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- if(hi2c->Instance==I2C1)
- {
- /* USER CODE BEGIN I2C1_MspInit 0 */
-
- /* USER CODE END I2C1_MspInit 0 */
-
- __HAL_RCC_GPIOB_CLK_ENABLE();
- /**I2C1 GPIO Configuration
- PB6 ------> I2C1_SCL
- PB7 ------> I2C1_SDA
- */
- GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- /* Peripheral clock enable */
- __HAL_RCC_I2C1_CLK_ENABLE();
- /* USER CODE BEGIN I2C1_MspInit 1 */
-
- /* USER CODE END I2C1_MspInit 1 */
- }
- else if(hi2c->Instance==I2C2)
- {
- /* USER CODE BEGIN I2C2_MspInit 0 */
-
- /* USER CODE END I2C2_MspInit 0 */
-
- __HAL_RCC_GPIOB_CLK_ENABLE();
- /**I2C2 GPIO Configuration
- PB10 ------> I2C2_SCL
- PB9 ------> I2C2_SDA
- */
- GPIO_InitStruct.Pin = I2C2_SCL_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
- GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF4_I2C2;
- HAL_GPIO_Init(I2C2_SCL_GPIO_Port, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = I2C2_SDA_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
- GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF9_I2C2;
- HAL_GPIO_Init(I2C2_SDA_GPIO_Port, &GPIO_InitStruct);
-
- /* Peripheral clock enable */
- __HAL_RCC_I2C2_CLK_ENABLE();
- /* USER CODE BEGIN I2C2_MspInit 1 */
-
- /* USER CODE END I2C2_MspInit 1 */
- }
-
-}
-
-/**
-* @brief I2C MSP De-Initialization
-* This function freeze the hardware resources used in this example
-* @param hi2c: I2C handle pointer
-* @retval None
-*/
-void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
-{
- if(hi2c->Instance==I2C1)
- {
- /* USER CODE BEGIN I2C1_MspDeInit 0 */
-
- /* USER CODE END I2C1_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_I2C1_CLK_DISABLE();
-
- /**I2C1 GPIO Configuration
- PB6 ------> I2C1_SCL
- PB7 ------> I2C1_SDA
- */
- HAL_GPIO_DeInit(GPIOB, I2C1_SCL_Pin|I2C1_SDA_Pin);
-
- /* USER CODE BEGIN I2C1_MspDeInit 1 */
-
- /* USER CODE END I2C1_MspDeInit 1 */
- }
- else if(hi2c->Instance==I2C2)
- {
- /* USER CODE BEGIN I2C2_MspDeInit 0 */
-
- /* USER CODE END I2C2_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_I2C2_CLK_DISABLE();
-
- /**I2C2 GPIO Configuration
- PB10 ------> I2C2_SCL
- PB9 ------> I2C2_SDA
- */
- HAL_GPIO_DeInit(GPIOB, I2C2_SCL_Pin|I2C2_SDA_Pin);
-
- /* USER CODE BEGIN I2C2_MspDeInit 1 */
-
- /* USER CODE END I2C2_MspDeInit 1 */
- }
-
-}
-
-/**
-* @brief I2S MSP Initialization
-* This function configures the hardware resources used in this example
-* @param hi2s: I2S handle pointer
-* @retval None
-*/
-void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s)
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- if(hi2s->Instance==SPI3)
- {
- /* USER CODE BEGIN SPI3_MspInit 0 */
-
- /* USER CODE END SPI3_MspInit 0 */
- /* Peripheral clock enable */
- __HAL_RCC_SPI3_CLK_ENABLE();
-
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- __HAL_RCC_GPIOC_CLK_ENABLE();
- /**I2S3 GPIO Configuration
- PA4 ------> I2S3_WS
- PB12 ------> I2S3_CK
- PC7 ------> I2S3_MCK
- PB4 ------> I2S3_ext_SD
- PB5 ------> I2S3_SD
- */
- GPIO_InitStruct.Pin = CODEC_I2S3_WS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
- HAL_GPIO_Init(CODEC_I2S3_WS_GPIO_Port, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = CODEC_I2S3_SCK_Pin|CODEC_I2S3ext_SD_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF7_SPI3;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = CODEC_I2S3_MCK_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
- HAL_GPIO_Init(CODEC_I2S3_MCK_GPIO_Port, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = CODEC_I2S3_SD_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
- HAL_GPIO_Init(CODEC_I2S3_SD_GPIO_Port, &GPIO_InitStruct);
-
- /* USER CODE BEGIN SPI3_MspInit 1 */
-
- /* USER CODE END SPI3_MspInit 1 */
- }
-
-}
-
-/**
-* @brief I2S MSP De-Initialization
-* This function freeze the hardware resources used in this example
-* @param hi2s: I2S handle pointer
-* @retval None
-*/
-void HAL_I2S_MspDeInit(I2S_HandleTypeDef* hi2s)
-{
- if(hi2s->Instance==SPI3)
- {
- /* USER CODE BEGIN SPI3_MspDeInit 0 */
-
- /* USER CODE END SPI3_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_SPI3_CLK_DISABLE();
-
- /**I2S3 GPIO Configuration
- PA4 ------> I2S3_WS
- PB12 ------> I2S3_CK
- PC7 ------> I2S3_MCK
- PB4 ------> I2S3_ext_SD
- PB5 ------> I2S3_SD
- */
- HAL_GPIO_DeInit(CODEC_I2S3_WS_GPIO_Port, CODEC_I2S3_WS_Pin);
-
- HAL_GPIO_DeInit(GPIOB, CODEC_I2S3_SCK_Pin|CODEC_I2S3ext_SD_Pin|CODEC_I2S3_SD_Pin);
-
- HAL_GPIO_DeInit(CODEC_I2S3_MCK_GPIO_Port, CODEC_I2S3_MCK_Pin);
-
- /* USER CODE BEGIN SPI3_MspDeInit 1 */
-
- /* USER CODE END SPI3_MspDeInit 1 */
- }
-
-}
-
-/**
-* @brief QSPI MSP Initialization
-* This function configures the hardware resources used in this example
-* @param hqspi: QSPI handle pointer
-* @retval None
-*/
-void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- if(hqspi->Instance==QUADSPI)
- {
- /* USER CODE BEGIN QUADSPI_MspInit 0 */
-
- /* USER CODE END QUADSPI_MspInit 0 */
- /* Peripheral clock enable */
- __HAL_RCC_QSPI_CLK_ENABLE();
-
- __HAL_RCC_GPIOF_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- __HAL_RCC_GPIOG_CLK_ENABLE();
- /**QUADSPI GPIO Configuration
- PF6 ------> QUADSPI_BK1_IO3
- PF7 ------> QUADSPI_BK1_IO2
- PF8 ------> QUADSPI_BK1_IO0
- PF9 ------> QUADSPI_BK1_IO1
- PB2 ------> QUADSPI_CLK
- PG6 ------> QUADSPI_BK1_NCS
- */
- GPIO_InitStruct.Pin = QSPI_BK1_IO3_Pin|QSPI_BK1_IO2_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF9_QSPI;
- HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = QSPI_BK1_IO0_Pin|QSPI_BK1_IO1_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
- HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = QSPI_CLK_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF9_QSPI;
- HAL_GPIO_Init(QSPI_CLK_GPIO_Port, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = QSPI_BK1_NCS_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
- HAL_GPIO_Init(QSPI_BK1_NCS_GPIO_Port, &GPIO_InitStruct);
-
- /* USER CODE BEGIN QUADSPI_MspInit 1 */
-
- /* USER CODE END QUADSPI_MspInit 1 */
- }
-
-}
-
-/**
-* @brief QSPI MSP De-Initialization
-* This function freeze the hardware resources used in this example
-* @param hqspi: QSPI handle pointer
-* @retval None
-*/
-void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
-{
- if(hqspi->Instance==QUADSPI)
- {
- /* USER CODE BEGIN QUADSPI_MspDeInit 0 */
-
- /* USER CODE END QUADSPI_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_QSPI_CLK_DISABLE();
-
- /**QUADSPI GPIO Configuration
- PF6 ------> QUADSPI_BK1_IO3
- PF7 ------> QUADSPI_BK1_IO2
- PF8 ------> QUADSPI_BK1_IO0
- PF9 ------> QUADSPI_BK1_IO1
- PB2 ------> QUADSPI_CLK
- PG6 ------> QUADSPI_BK1_NCS
- */
- HAL_GPIO_DeInit(GPIOF, QSPI_BK1_IO3_Pin|QSPI_BK1_IO2_Pin|QSPI_BK1_IO0_Pin|QSPI_BK1_IO1_Pin);
-
- HAL_GPIO_DeInit(QSPI_CLK_GPIO_Port, QSPI_CLK_Pin);
-
- HAL_GPIO_DeInit(QSPI_BK1_NCS_GPIO_Port, QSPI_BK1_NCS_Pin);
-
- /* USER CODE BEGIN QUADSPI_MspDeInit 1 */
-
- /* USER CODE END QUADSPI_MspDeInit 1 */
- }
-
-}
-
-/**
-* @brief SD MSP Initialization
-* This function configures the hardware resources used in this example
-* @param hsd: SD handle pointer
-* @retval None
-*/
-void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- if(hsd->Instance==SDIO)
- {
- /* USER CODE BEGIN SDIO_MspInit 0 */
-
- /* USER CODE END SDIO_MspInit 0 */
- /* Peripheral clock enable */
- __HAL_RCC_SDIO_CLK_ENABLE();
-
- __HAL_RCC_GPIOC_CLK_ENABLE();
- __HAL_RCC_GPIOD_CLK_ENABLE();
- /**SDIO GPIO Configuration
- PC8 ------> SDIO_D0
- PC9 ------> SDIO_D1
- PC10 ------> SDIO_D2
- PC11 ------> SDIO_D3
- PC12 ------> SDIO_CK
- PD2 ------> SDIO_CMD
- */
- GPIO_InitStruct.Pin = uSD_D0_Pin|uSD_D1_Pin|uSD_D2_Pin|uSD_D3_Pin
- |uSD_CLK_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = uSD_CMD_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
- HAL_GPIO_Init(uSD_CMD_GPIO_Port, &GPIO_InitStruct);
-
- /* USER CODE BEGIN SDIO_MspInit 1 */
-
- /* USER CODE END SDIO_MspInit 1 */
- }
-
-}
-
-/**
-* @brief SD MSP De-Initialization
-* This function freeze the hardware resources used in this example
-* @param hsd: SD handle pointer
-* @retval None
-*/
-void HAL_SD_MspDeInit(SD_HandleTypeDef* hsd)
-{
- if(hsd->Instance==SDIO)
- {
- /* USER CODE BEGIN SDIO_MspDeInit 0 */
-
- /* USER CODE END SDIO_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_SDIO_CLK_DISABLE();
-
- /**SDIO GPIO Configuration
- PC8 ------> SDIO_D0
- PC9 ------> SDIO_D1
- PC10 ------> SDIO_D2
- PC11 ------> SDIO_D3
- PC12 ------> SDIO_CK
- PD2 ------> SDIO_CMD
- */
- HAL_GPIO_DeInit(GPIOC, uSD_D0_Pin|uSD_D1_Pin|uSD_D2_Pin|uSD_D3_Pin
- |uSD_CLK_Pin);
-
- HAL_GPIO_DeInit(uSD_CMD_GPIO_Port, uSD_CMD_Pin);
-
- /* USER CODE BEGIN SDIO_MspDeInit 1 */
-
- /* USER CODE END SDIO_MspDeInit 1 */
- }
-
-}
-
-/**
-* @brief UART MSP Initialization
-* This function configures the hardware resources used in this example
-* @param huart: UART handle pointer
-* @retval None
-*/
-void HAL_UART_MspInit(UART_HandleTypeDef* huart)
-{
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- if(huart->Instance==USART2)
- {
- /* USER CODE BEGIN USART2_MspInit 0 */
-
- /* USER CODE END USART2_MspInit 0 */
- /* Peripheral clock enable */
- __HAL_RCC_USART2_CLK_ENABLE();
-
- __HAL_RCC_GPIOA_CLK_ENABLE();
- /**USART2 GPIO Configuration
- PA2 ------> USART2_TX
- PA3 ------> USART2_RX
- */
- GPIO_InitStruct.Pin = STLINK_RX_Pin|STLINK_TX_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
- HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- /* USER CODE BEGIN USART2_MspInit 1 */
-
- /* USER CODE END USART2_MspInit 1 */
- }
-
-}
-
-/**
-* @brief UART MSP De-Initialization
-* This function freeze the hardware resources used in this example
-* @param huart: UART handle pointer
-* @retval None
-*/
-void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
-{
- if(huart->Instance==USART2)
- {
- /* USER CODE BEGIN USART2_MspDeInit 0 */
-
- /* USER CODE END USART2_MspDeInit 0 */
- /* Peripheral clock disable */
- __HAL_RCC_USART2_CLK_DISABLE();
-
- /**USART2 GPIO Configuration
- PA2 ------> USART2_TX
- PA3 ------> USART2_RX
- */
- HAL_GPIO_DeInit(GPIOA, STLINK_RX_Pin|STLINK_TX_Pin);
-
- /* USER CODE BEGIN USART2_MspDeInit 1 */
-
- /* USER CODE END USART2_MspDeInit 1 */
- }
-
-}
-
-static uint32_t FSMC_Initialized = 0;
-
-static void HAL_FSMC_MspInit(void){
- /* USER CODE BEGIN FSMC_MspInit 0 */
-
- /* USER CODE END FSMC_MspInit 0 */
- GPIO_InitTypeDef GPIO_InitStruct ={0};
- if (FSMC_Initialized) {
- return;
- }
- FSMC_Initialized = 1;
- /* Peripheral clock enable */
- __HAL_RCC_FSMC_CLK_ENABLE();
-
- /** FSMC GPIO Configuration
- PF0 ------> FSMC_A0
- PE7 ------> FSMC_D4
- PE8 ------> FSMC_D5
- PE9 ------> FSMC_D6
- PE10 ------> FSMC_D7
- PE11 ------> FSMC_D8
- PE12 ------> FSMC_D9
- PE13 ------> FSMC_D10
- PE14 ------> FSMC_D11
- PE15 ------> FSMC_D12
- PD8 ------> FSMC_D13
- PD9 ------> FSMC_D14
- PD10 ------> FSMC_D15
- PD14 ------> FSMC_D0
- PD15 ------> FSMC_D1
- PD0 ------> FSMC_D2
- PD1 ------> FSMC_D3
- PD4 ------> FSMC_NOE
- PD5 ------> FSMC_NWE
- PD7 ------> FSMC_NE1
- */
- GPIO_InitStruct.Pin = A0_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
- HAL_GPIO_Init(A0_GPIO_Port, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = D4_Pin|D5_Pin|D6_Pin|D7_Pin
- |D8_Pin|D9_Pin|D10_Pin|D11_Pin
- |D12_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
- HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = D13_Pin|D14_Pin|D15_Pin|D0_Pin
- |D1_Pin|D2_Pin|D3_Pin|FMC_NOE_Pin
- |FMC_NWE_Pin|FMC_NE1_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_FSMC;
- HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
-
- /* USER CODE BEGIN FSMC_MspInit 1 */
-
- /* USER CODE END FSMC_MspInit 1 */
-}
-
-void HAL_SRAM_MspInit(SRAM_HandleTypeDef* hsram){
- /* USER CODE BEGIN SRAM_MspInit 0 */
-
- /* USER CODE END SRAM_MspInit 0 */
- HAL_FSMC_MspInit();
- /* USER CODE BEGIN SRAM_MspInit 1 */
-
- /* USER CODE END SRAM_MspInit 1 */
-}
-
-static uint32_t FSMC_DeInitialized = 0;
-
-static void HAL_FSMC_MspDeInit(void){
- /* USER CODE BEGIN FSMC_MspDeInit 0 */
-
- /* USER CODE END FSMC_MspDeInit 0 */
- if (FSMC_DeInitialized) {
- return;
- }
- FSMC_DeInitialized = 1;
- /* Peripheral clock enable */
- __HAL_RCC_FSMC_CLK_DISABLE();
-
- /** FSMC GPIO Configuration
- PF0 ------> FSMC_A0
- PE7 ------> FSMC_D4
- PE8 ------> FSMC_D5
- PE9 ------> FSMC_D6
- PE10 ------> FSMC_D7
- PE11 ------> FSMC_D8
- PE12 ------> FSMC_D9
- PE13 ------> FSMC_D10
- PE14 ------> FSMC_D11
- PE15 ------> FSMC_D12
- PD8 ------> FSMC_D13
- PD9 ------> FSMC_D14
- PD10 ------> FSMC_D15
- PD14 ------> FSMC_D0
- PD15 ------> FSMC_D1
- PD0 ------> FSMC_D2
- PD1 ------> FSMC_D3
- PD4 ------> FSMC_NOE
- PD5 ------> FSMC_NWE
- PD7 ------> FSMC_NE1
- */
- HAL_GPIO_DeInit(A0_GPIO_Port, A0_Pin);
-
- HAL_GPIO_DeInit(GPIOE, D4_Pin|D5_Pin|D6_Pin|D7_Pin
- |D8_Pin|D9_Pin|D10_Pin|D11_Pin
- |D12_Pin);
-
- HAL_GPIO_DeInit(GPIOD, D13_Pin|D14_Pin|D15_Pin|D0_Pin
- |D1_Pin|D2_Pin|D3_Pin|FMC_NOE_Pin
- |FMC_NWE_Pin|FMC_NE1_Pin);
-
- /* USER CODE BEGIN FSMC_MspDeInit 1 */
-
- /* USER CODE END FSMC_MspDeInit 1 */
-}
-
-void HAL_SRAM_MspDeInit(SRAM_HandleTypeDef* hsram){
- /* USER CODE BEGIN SRAM_MspDeInit 0 */
-
- /* USER CODE END SRAM_MspDeInit 0 */
- HAL_FSMC_MspDeInit();
- /* USER CODE BEGIN SRAM_MspDeInit 1 */
-
- /* USER CODE END SRAM_MspDeInit 1 */
-}
-
-/* USER CODE BEGIN 1 */
-
-/* USER CODE END 1 */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/ports/stm32f4/common-hal/busio/I2C.c b/ports/stm32f4/common-hal/busio/I2C.c
index 656ec6dcc0..5bf31b6f00 100644
--- a/ports/stm32f4/common-hal/busio/I2C.c
+++ b/ports/stm32f4/common-hal/busio/I2C.c
@@ -32,6 +32,7 @@
#include "shared-bindings/microcontroller/__init__.h"
#include "supervisor/shared/translate.h"
+#include "common-hal/microcontroller/Pin.h"
#include "stm32f4/periph.h"
STATIC I2C_HandleTypeDef hi2c;
@@ -57,7 +58,8 @@ STATIC I2C_TypeDef * I2Cbanks[3] =
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) {
-
+
+ I2C_TypeDef * I2Cx;
uint8_t i2cidx = 0;
uint8_t i2cidx_c = 0;
uint8_t len = sizeof(mcu_i2c_list)/sizeof(*mcu_i2c_list);
@@ -66,18 +68,27 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
i2cidx = mcu_i2c_list[i]->i2c_index;
}
if (mcu_i2c_list[i]->scl_pin == scl) {
- i2cidx_c = mcu_i2c_list[i]->i2c_index
+ i2cidx_c = mcu_i2c_list[i]->i2c_index;
}
}
- if(idcidx == i2cidx_c) {
- if(I2Cbanks[idcidx] == NULL || idcidx>=len) {
+ if(i2cidx == i2cidx_c) {
+ if(I2Cbanks[i2cidx] == NULL || i2cidx>=len) {
mp_raise_RuntimeError(translate("Bad I2C pin definition, check peripheral files"));
}
- I2Cx = I2Cbanks[idcidx];
+ I2Cx = I2Cbanks[i2cidx];
} else {
mp_raise_RuntimeError(translate("Invalid I2C pin selection"));
}
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
+ GPIO_InitStruct.Pin = pin_mask(sda->number)|pin_mask(scl->number);
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+ GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; //TODO; custom per pin? Or error if mixed is bad.
+ HAL_GPIO_Init(pin_port(sda->port), &GPIO_InitStruct);
+ __HAL_RCC_I2C1_CLK_ENABLE(); //TODO custom per periph
+
hi2c.Instance = I2Cx;
hi2c.Init.ClockSpeed = 100000;
hi2c.Init.DutyCycle = I2C_DUTYCYCLE_2;
@@ -93,15 +104,15 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
mp_printf(&mp_plat_print, "I2C INIT OK");
}
- self->sda_pin = sda->number;
- self->scl_pin = scl->number;
+ self->sda_pin = sda;
+ self->scl_pin = scl;
claim_pin(sda);
claim_pin(scl);
}
bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
- return self->sda_pin == NO_PIN;
+ return self->sda_pin == NULL;
}
void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
@@ -111,8 +122,8 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
HAL_I2C_MspDeInit(&hi2c);
- self->sda_pin = NO_PIN;
- self->scl_pin = NO_PIN;
+ self->sda_pin = NULL;
+ self->scl_pin = NULL;
}
bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
diff --git a/ports/stm32f4/common-hal/busio/I2C.h b/ports/stm32f4/common-hal/busio/I2C.h
index 5c801ab321..5d9663dfe3 100644
--- a/ports/stm32f4/common-hal/busio/I2C.h
+++ b/ports/stm32f4/common-hal/busio/I2C.h
@@ -38,8 +38,8 @@ typedef struct {
mp_obj_base_t base;
I2C_HandleTypeDef i2c_handle;
bool has_lock;
- uint8_t scl_pin;
- uint8_t sda_pin;
+ const mcu_pin_obj_t *scl_pin;
+ const mcu_pin_obj_t *sda_pin;
} busio_i2c_obj_t;
#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_I2C_H
diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/periph.c b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/periph.c
index 04f7f08b7f..21077015f4 100644
--- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/periph.c
+++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/periph.c
@@ -36,7 +36,7 @@
const mcu_i2c_periph_obj_t periph_I2C1_0 = I2C(1, 0, &pin_PB07, &pin_PB06);
const mcu_i2c_periph_obj_t periph_I2C1_1 = I2C(1, 1, &pin_PB09, &pin_PB08);
-//const mcu_i2c_periph_obj_t periph_I2C2 = I2C(1, NO_ALT, &pin_PB11, &pin_PB10); //not on LQFP100
+//const mcu_i2c_periph_obj_t periph_I2C2 = I2C(1, NO_ALT, &pin_PB11, &pin_PB10); //AFN only
const mcu_i2c_periph_obj_t periph_I2C3 = I2C(1, NO_ALT, &pin_PB09, &pin_PB08);
const mcu_i2c_periph_obj_t* mcu_i2c_list[3] = {&periph_I2C1_0,&periph_I2C1_1,&periph_I2C3};
diff --git a/ports/stm32f4/supervisor/port.c b/ports/stm32f4/supervisor/port.c
index ef2121b6c2..a12feca8a6 100644
--- a/ports/stm32f4/supervisor/port.c
+++ b/ports/stm32f4/supervisor/port.c
@@ -39,6 +39,8 @@
safe_mode_t port_init(void) {
HAL_Init();
+ __HAL_RCC_SYSCFG_CLK_ENABLE();
+ __HAL_RCC_PWR_CLK_ENABLE();
stm32f4_peripherals_clocks_init();
stm32f4_peripherals_gpio_init();