From af4b66caf95867b71f3fbf9117e5e7fb2f0a8c33 Mon Sep 17 00:00:00 2001 From: lains <383502+lains@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:49:34 +0100 Subject: [PATCH] Preparing for multiple board support --- inc/hal/Stm32LcdDriver.h | 4 ++++ inc/hal/Stm32SerialDriver.h | 2 ++ inc/main.h | 4 ++++ src/hal/Stm32LcdDriver.cpp | 19 +++++++++++++++---- src/hal/Stm32SerialDriver.cpp | 4 ++-- src/hal/Stm32TimerDriver.cpp | 2 ++ src/main.cpp | 19 ++++++++++++++++--- 7 files changed, 45 insertions(+), 9 deletions(-) diff --git a/inc/hal/Stm32LcdDriver.h b/inc/hal/Stm32LcdDriver.h index a293ff7..d9736c1 100644 --- a/inc/hal/Stm32LcdDriver.h +++ b/inc/hal/Stm32LcdDriver.h @@ -1,8 +1,12 @@ #ifndef _STM32LCDDRIVER_H_ #define _STM32LCDDRIVER_H_ +#ifdef STM32F469xx #include "stm32f4xx_hal.h" +#endif +#ifdef USE_STM32469I_DISCOVERY #include "stm32469i_discovery_lcd.h" +#endif extern "C" { DSI_HandleTypeDef* get_hdsi(void); // C-linkage exported getter for hdsi handler diff --git a/inc/hal/Stm32SerialDriver.h b/inc/hal/Stm32SerialDriver.h index 66a83e7..afc77e2 100644 --- a/inc/hal/Stm32SerialDriver.h +++ b/inc/hal/Stm32SerialDriver.h @@ -1,7 +1,9 @@ #ifndef _STM32SERIALDRIVER_H_ #define _STM32SERIALDRIVER_H_ +#ifdef STM32F469xx #include "stm32f4xx_hal.h" +#endif #include #ifdef USE_ALLOCATION #include diff --git a/inc/main.h b/inc/main.h index 4c03436..9daa896 100644 --- a/inc/main.h +++ b/inc/main.h @@ -2,14 +2,18 @@ #define __MAIN_H /* Includes ------------------------------------------------------------------*/ +#ifdef STM32F469xx #include "stm32f4xx_hal.h" +#endif +#ifdef USE_STM32469I_DISCOVERY #include "stm32469i_discovery.h" //#include "stm32469i_discovery_ts.h" #include "stm32469i_discovery_sdram.h" //#include "stm32469i_discovery_sd.h" #include "stm32469i_discovery_lcd.h" #include "stm32469i_discovery_qspi.h" +#endif void Error_Handler(void); void OnError_Handler(uint32_t condition); diff --git a/src/hal/Stm32LcdDriver.cpp b/src/hal/Stm32LcdDriver.cpp index 2771147..ae01938 100644 --- a/src/hal/Stm32LcdDriver.cpp +++ b/src/hal/Stm32LcdDriver.cpp @@ -1,10 +1,15 @@ #include "Stm32LcdDriver.h" extern "C" { #include "main.h" +#ifdef USE_STM32469I_DISCOVERY #include "stm32469i_discovery_lcd.h" -extern LTDC_HandleTypeDef hltdc_eval; // Imported definition from stm32469i_discovery_lcd.c -extern DSI_HandleTypeDef hdsi_eval; // Imported definition from stm32469i_discovery_lcd.c +// Imported definition from stm32469i_discovery_lcd.c +extern LTDC_HandleTypeDef hltdc_eval; +extern DSI_HandleTypeDef hdsi_eval; +#define board_hltdc hltdc_eval +#define board_hdsi hdsi_eval +#endif } const unsigned int LCDWidth = 800; @@ -148,6 +153,7 @@ static uint8_t LCD_Init(DSI_HandleTypeDef* hdsi, LTDC_HandleTypeDef* hltdc) { HAL_DSI_DeInit(hdsi); +#ifdef USE_STM32469I_DISCOVERY #if defined(USE_STM32469I_DISCO_REVA) dsiPllInit.PLLNDIV = 100; dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5; @@ -155,6 +161,7 @@ static uint8_t LCD_Init(DSI_HandleTypeDef* hdsi, LTDC_HandleTypeDef* hltdc) { dsiPllInit.PLLNDIV = 125; dsiPllInit.PLLIDF = DSI_PLL_IN_DIV2; #endif /* USE_STM32469I_DISCO_REVA */ +#endif // USE_STM32469I_DISCOVERY dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1; hdsi->Init.NumberOfLanes = DSI_TWO_DATA_LANES; @@ -197,18 +204,22 @@ static uint8_t LCD_Init(DSI_HandleTypeDef* hdsi, LTDC_HandleTypeDef* hltdc) { PhyTimings.StopWaitTime = 10; HAL_DSI_ConfigPhyTimer(hdsi, &PhyTimings); +#ifdef USE_STM32469I_DISCOVERY /* Initialize LTDC */ LTDC_Init(hltdc); /* Start DSI */ HAL_DSI_Start(hdsi); +#endif +#ifdef USE_STM32469I_DISCOVERY #if defined (USE_STM32469I_DISCO_REVC) /* Initialize the NT35510 LCD Display IC Driver (3K138 LCD IC Driver) */ NT35510_Init(NT35510_FORMAT_RGB888, LCD_ORIENTATION_LANDSCAPE); #else /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver) */ OTM8009A_Init(OTM8009A_COLMOD_RGB888, LCD_ORIENTATION_LANDSCAPE); +#endif #endif LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_DISABLE; @@ -236,8 +247,8 @@ static uint8_t LCD_Init(DSI_HandleTypeDef* hdsi, LTDC_HandleTypeDef* hltdc) { Stm32LcdDriver::Stm32LcdDriver() : displayState(SwitchToDraftIsPending), -hltdc(hltdc_eval), -hdsi(hdsi_eval) +hltdc(board_hltdc), +hdsi(board_hdsi) { } diff --git a/src/hal/Stm32SerialDriver.cpp b/src/hal/Stm32SerialDriver.cpp index 2296f07..b8fd965 100644 --- a/src/hal/Stm32SerialDriver.cpp +++ b/src/hal/Stm32SerialDriver.cpp @@ -20,7 +20,7 @@ extern "C" { #define USART3_FORCE_RESET() __HAL_RCC_USART3_FORCE_RESET() #define USART3_RELEASE_RESET() __HAL_RCC_USART3_RELEASE_RESET() -/* Definition for USART3 Pins (forwarded to J-Link's virtual com port) */ +/* Definition for USART3 Pins (forwarded to ST-Link's virtual com port) */ #define USART3_TX_PIN GPIO_PIN_8 #define USART3_TX_GPIO_PORT GPIOD #define USART3_TX_AF GPIO_AF7_USART3 @@ -61,7 +61,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef *huart) { GPIO_InitTypeDef GPIO_InitStruct; memset(&GPIO_InitStruct, 0, sizeof(GPIO_InitStruct)); - if (huart->Instance!=USART6 /*&& huart->Instance!=USART3*/) { + if (huart->Instance!=USART6 /*&& huart->Instance!=USART3*/) { /* Initializing USART3 leads to a pinkish display, there is a probably a conflict on PINs */ return; } diff --git a/src/hal/Stm32TimerDriver.cpp b/src/hal/Stm32TimerDriver.cpp index 5aeeef0..7c26a2c 100644 --- a/src/hal/Stm32TimerDriver.cpp +++ b/src/hal/Stm32TimerDriver.cpp @@ -1,6 +1,8 @@ #include "Stm32TimerDriver.h" extern "C" { +#ifdef STM32F469xx #include "stm32f4xx_hal.h" +#endif } void waitDelayAndCondition(uint32_t delay, FHalDelayRefreshFunc toRunWhileWaiting, FHalDelayConditionFunc conditionCheck, void* context) { diff --git a/src/main.cpp b/src/main.cpp index 0074fbc..a02e0de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -111,11 +111,13 @@ int main(void) { /* Configure the system clock to 180 MHz */ SystemClock_Config(); - /* Configure LED1, LED2, LED3 and LED4 */ + /* Configure LED1, LED2, LED3 and LED4 on USE_STM32469I_DISCOVERY */ +#ifdef USE_STM32469I_DISCOVERY BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); +#endif BSP_LED_On(LED2); waitDelay(250); BSP_LED_Off(LED2); @@ -459,6 +461,7 @@ static void SystemClock_Config(void) RCC_OscInitTypeDef RCC_OscInitStruct; HAL_StatusTypeDef ret = HAL_OK; +#ifdef USE_STM32469I_DISCOVERY /* Enable Power Control clock */ __HAL_RCC_PWR_CLK_ENABLE(); @@ -466,28 +469,34 @@ static void SystemClock_Config(void) clocked below the maximum system frequency, to update the voltage scaling value regarding system frequency refer to product datasheet. */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); +#endif /* Enable HSE Oscillator and activate PLL with HSE as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; +#ifdef USE_STM32469I_DISCOVERY #if defined(USE_STM32469I_DISCO_REVA) RCC_OscInitStruct.PLL.PLLM = 25; #else RCC_OscInitStruct.PLL.PLLM = 8; #endif /* USE_STM32469I_DISCO_REVA */ + RCC_OscInitStruct.PLL.PLLN = 360; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 7; RCC_OscInitStruct.PLL.PLLR = 6; +#endif ret = HAL_RCC_OscConfig(&RCC_OscInitStruct); if (ret != HAL_OK) { while(1) { ; } } - /* Activate the OverDrive to reach the 180 MHz Frequency */ + /* Activate the OverDrive to reach: + - the 180 MHz Frequency on STM32F469I DISCOVERY + */ ret = HAL_PWREx_EnableOverDrive(); if (ret != HAL_OK) { while(1) { ; } @@ -500,7 +509,11 @@ static void SystemClock_Config(void) RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); +#ifdef USE_STM32469I_DISCOVERY +#define BOARD_FLASH_LATENCY FLASH_LATENCY_5 +#endif + ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, BOARD_FLASH_LATENCY); + if (ret != HAL_OK) { while(1) { ; } }