Skip to content

Commit

Permalink
Preparing for multiple board support
Browse files Browse the repository at this point in the history
  • Loading branch information
lains committed Feb 7, 2024
1 parent 5cfcd4f commit af4b66c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 9 deletions.
4 changes: 4 additions & 0 deletions inc/hal/Stm32LcdDriver.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions inc/hal/Stm32SerialDriver.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef _STM32SERIALDRIVER_H_
#define _STM32SERIALDRIVER_H_

#ifdef STM32F469xx
#include "stm32f4xx_hal.h"
#endif
#include <cstdint>
#ifdef USE_ALLOCATION
#include <string>
Expand Down
4 changes: 4 additions & 0 deletions inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 15 additions & 4 deletions src/hal/Stm32LcdDriver.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -148,13 +153,15 @@ 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;
#else
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/hal/Stm32SerialDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/hal/Stm32TimerDriver.cpp
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
19 changes: 16 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -459,35 +461,42 @@ 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();

/* The voltage scaling allows optimizing the power consumption when the device is
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) { ; }
Expand All @@ -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) { ; }
}
Expand Down

0 comments on commit af4b66c

Please sign in to comment.