Skip to content

Commit

Permalink
Merge branch 'master' into stm32f769i-disco-support
Browse files Browse the repository at this point in the history
  • Loading branch information
lains committed Feb 7, 2024
2 parents b801ed5 + e3b3aa3 commit 6339eea
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 64 deletions.
11 changes: 11 additions & 0 deletions inc/hal/Stm32LcdDriver.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#ifndef _STM32LCDDRIVER_H_
#define _STM32LCDDRIVER_H_

#ifdef STM32F469xx
#include "stm32f4xx_hal.h"
#endif
#ifdef STM32F769xx
#include "stm32f7xx_hal.h"
#endif

#ifdef USE_STM32469I_DISCOVERY
#include "stm32469i_discovery_lcd.h"
#endif
#ifdef USE_STM32F769I_DISCO
#include "stm32f769i_discovery_lcd.h"
#endif

extern "C" {
DSI_HandleTypeDef* get_hdsi(void); // C-linkage exported getter for hdsi handler
Expand Down
5 changes: 5 additions & 0 deletions inc/hal/Stm32SerialDriver.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#ifndef _STM32SERIALDRIVER_H_
#define _STM32SERIALDRIVER_H_

#ifdef STM32F469xx
#include "stm32f4xx_hal.h"
#endif
#ifdef STM32F769xx
#include "stm32f7xx_hal.h"
#endif
#include <cstdint>
#ifdef USE_ALLOCATION
#include <string>
Expand Down
92 changes: 67 additions & 25 deletions inc/main.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,67 @@
#ifndef __MAIN_H
#define __MAIN_H

/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include "stm32f7xx_hal.h"
#include "stm32f769i_discovery.h"
//#include "stm32f769i_discovery_ts.h"
#include "stm32f769i_discovery_lcd.h"
#include "stm32f769i_discovery_qspi.h"

/* LCD Frame buffer start address : starts at beginning of SDRAM */
#define ARBG8888_BYTE_PER_PIXEL 4
#define LCD_FB_LENGTH ((uint32_t)(OTM8009A_480X800_HEIGHT * OTM8009A_480X800_WIDTH * ARBG8888_BYTE_PER_PIXEL))
#define SDRAM_WRITE_READ_ADDR ((uint32_t)0xC0177000)

/* The Audio file is flashed with ST-Link Utility @ flash address = AUDIO_SRC_FILE_ADDRESS */
#define AUDIO_SRC_FILE_ADDRESS 0x08080000 /* Audio file address in flash */
#define AUDIO_FILE_SIZE 0x80000

void Error_Handler(void);
void OnError_Handler(uint32_t condition);

#endif /* __MAIN_H */
#ifndef __MAIN_H
#define __MAIN_H

/* Includes ------------------------------------------------------------------*/
#ifdef STM32F469xx
#include "stm32f4xx_hal.h"
#endif
#ifdef STM32F769xx
#include "stm32f7xx_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

#ifdef USE_STM32F769I_DISCO
#include "stm32f769i_discovery.h"
//#include "stm32f769i_discovery_ts.h"
#include "stm32f769i_discovery_lcd.h"
#include "stm32f769i_discovery_qspi.h"
#endif

#ifdef USE_STM32469I_DISCOVERY
#define LED_GREEN LED1
#define LED_ORANGE LED2
#define LED_RED LED3
#define LED_BLUE LED4
#endif
#ifdef USE_STM32F769I_DISCO
#define LED_RED LED1
#define LED_GREEN LED2
/* The defines below are probably not required */
/* LCD Frame buffer start address : starts at beginning of SDRAM */
#define ARBG8888_BYTE_PER_PIXEL 4
#define LCD_FB_LENGTH ((uint32_t)(OTM8009A_480X800_HEIGHT * OTM8009A_480X800_WIDTH * ARBG8888_BYTE_PER_PIXEL))
#define SDRAM_WRITE_READ_ADDR ((uint32_t)0xC0177000)

#endif

#ifdef LED_BLUE
#define LED_LCD_REFRESH LED_BLUE
#endif
#ifdef LED_RED
#define LED_ERROR LED_RED
#endif
#ifdef LED_ORANGE
#define LED_SERIAL_RX LED_ORANGE
#endif
#if defined(USE_STM32469I_DISCOVERY) && defined(LED_ORANGE)
#define LED_STARTUP_BLINK LED_ORANGE
#endif
#if defined(USE_STM32F769I_DISCO) && defined(LED_RED)
#define LED_STARTUP_BLINK LED_RED
#endif
#ifdef LED_GREEN
#define LED_TIC_FRAME_RX LED_GREEN
#endif

void Error_Handler(void);
void OnError_Handler(uint32_t condition);

#endif /* __MAIN_H */
82 changes: 69 additions & 13 deletions src/hal/Stm32LcdDriver.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
#include "Stm32LcdDriver.h"
extern "C" {
#include "main.h"
#ifdef USE_STM32469I_DISCOVERY
#include "stm32469i_discovery_lcd.h"

// 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

#ifdef USE_STM32F769I_DISCO
#include "stm32f769i_discovery.h"
#include "stm32f769i_discovery_lcd.h"

extern LTDC_HandleTypeDef hltdc_discovery; // Imported definition from stm32f769i_discovery_lcd.c
extern DSI_HandleTypeDef hdsi_discovery; // Imported definition from stm32f769i_discovery_lcd.c
// Imported definition from stm32f769i_discovery_lcd.c
extern LTDC_HandleTypeDef hltdc_discovery;
extern DSI_HandleTypeDef hdsi_discovery;
static DSI_VidCfgTypeDef hdsivideo_handle;
#define board_hltdc hltdc_discovery
#define board_hdsi hdsi_discovery
#endif
}

const unsigned int LCDWidth = 800;
Expand Down Expand Up @@ -44,7 +59,12 @@ void set_active_fb(void* fb) {
__HAL_DSI_WRAPPER_DISABLE(getLcdDsiHandle());
/* Update LTDC configuration */
LTDC_LAYER(getLcdLtdcHandle(), 0)->CFBAR = (uint32_t)(fb);
#ifdef USE_STM32469I_DISCOVERY
__HAL_LTDC_RELOAD_IMMEDIATE_CONFIG(getLcdLtdcHandle());
#endif
#ifdef USE_STM32F769I_DISCO
__HAL_LTDC_RELOAD_CONFIG(getLcdLtdcHandle());
#endif
/* Enable DSI Wrapper */
__HAL_DSI_WRAPPER_ENABLE(getLcdDsiHandle());
}
Expand All @@ -60,12 +80,16 @@ void HAL_DSI_EndOfRefreshCallback(DSI_HandleTypeDef *hdsi) {
if (Stm32LcdDriver::get().displayState == Stm32LcdDriver::SwitchToDraftIsPending) {
set_active_fb(Stm32LcdDriver::get().draftFramebuffer);
Stm32LcdDriver::get().displayState = Stm32LcdDriver::DisplayingDraft;
BSP_LED_Off(LED1);
#ifdef LED_LCD_REFRESH
BSP_LED_Off(LED_LCD_REFRESH);
#endif
}
else if (Stm32LcdDriver::get().displayState == Stm32LcdDriver::SwitchToFinalIsPending) {
set_active_fb(Stm32LcdDriver::get().finalFramebuffer);
Stm32LcdDriver::get().displayState = Stm32LcdDriver::DisplayingFinal;
BSP_LED_On(LED1);
#ifdef LED_LCD_REFRESH
BSP_LED_On(LED_LCD_REFRESH);
#endif
}
}

Expand Down Expand Up @@ -150,9 +174,20 @@ 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;
dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
#else
dsiPllInit.PLLNDIV = 125;
dsiPllInit.PLLIDF = DSI_PLL_IN_DIV2;
#endif /* USE_STM32469I_DISCO_REVA */
#endif // USE_STM32469I_DISCOVERY
#ifdef USE_STM32F769I_DISCO
dsiPllInit.PLLNDIV = 100;
dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5;
#endif
dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;

hdsi->Init.NumberOfLanes = DSI_TWO_DATA_LANES;
hdsi->Init.TXEscapeCkdiv = 0x4;
Expand All @@ -171,7 +206,7 @@ static uint8_t LCD_Init(DSI_HandleTypeDef* hdsi, LTDC_HandleTypeDef* hltdc) {
CmdCfg.AutomaticRefresh = DSI_AR_DISABLE;
CmdCfg.TEAcknowledgeRequest = DSI_TE_ACKNOWLEDGE_ENABLE;
HAL_DSI_ConfigAdaptedCommandMode(hdsi, &CmdCfg);

LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_ENABLE;
LPCmd.LPGenShortWriteOneP = DSI_LP_GSW1P_ENABLE;
LPCmd.LPGenShortWriteTwoP = DSI_LP_GSW2P_ENABLE;
Expand All @@ -185,11 +220,13 @@ static uint8_t LCD_Init(DSI_HandleTypeDef* hdsi, LTDC_HandleTypeDef* hltdc) {
LPCmd.LPDcsLongWrite = DSI_LP_DLW_ENABLE;
HAL_DSI_ConfigCommand(hdsi, &LPCmd);

#ifdef USE_STM32F769I_DISCO
/* Initialize LTDC */
LTDC_Init(hltdc);

/* Start DSI */
HAL_DSI_Start(hdsi);
#endif

/* Configure DSI PHY HS2LP and LP2HS timings */
PhyTimings.ClockLaneHS2LPTime = 35;
Expand All @@ -198,13 +235,28 @@ static uint8_t LCD_Init(DSI_HandleTypeDef* hdsi, LTDC_HandleTypeDef* hltdc) {
PhyTimings.DataLaneLP2HSTime = 35;
PhyTimings.DataLaneMaxReadTime = 0;
PhyTimings.StopWaitTime = 10;
HAL_DSI_ConfigPhyTimer(hdsi, &PhyTimings);
HAL_DSI_ConfigPhyTimer(hdsi, &PhyTimings);

/* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver)
* depending on configuration set in 'hdsivideo_handle'.
*/
OTM8009A_Init(OTM8009A_COLMOD_RGB888, LCD_ORIENTATION_LANDSCAPE);
/* Initialize LTDC */
LTDC_Init(hltdc);

/* Start DSI */
HAL_DSI_Start(hdsi);

#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
#ifdef USE_STM32F769I_DISCO
/* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver) */
OTM8009A_Init(OTM8009A_COLMOD_RGB888, LCD_ORIENTATION_LANDSCAPE);
#endif

LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_DISABLE;
LPCmd.LPGenShortWriteOneP = DSI_LP_GSW1P_DISABLE;
LPCmd.LPGenShortWriteTwoP = DSI_LP_GSW2P_DISABLE;
Expand All @@ -220,12 +272,14 @@ static uint8_t LCD_Init(DSI_HandleTypeDef* hdsi, LTDC_HandleTypeDef* hltdc) {

HAL_DSI_ConfigFlowControl(hdsi, DSI_FLOW_CONTROL_BTA);

#ifdef USE_STM32F769I_DISCO
/* Send Display Off DCS Command to display */
HAL_DSI_ShortWrite(hdsi,
0,
DSI_DCS_SHORT_PKT_WRITE_P1,
OTM8009A_CMD_DISPOFF,
0x00);
#endif

/* Refresh the display */
HAL_DSI_Refresh(hdsi);
Expand All @@ -238,8 +292,8 @@ static uint8_t LCD_Init(DSI_HandleTypeDef* hdsi, LTDC_HandleTypeDef* hltdc) {

Stm32LcdDriver::Stm32LcdDriver() :
displayState(SwitchToDraftIsPending),
hltdc(hltdc_discovery),
hdsi(hdsi_discovery)
hltdc(board_hltdc),
hdsi(board_hdsi)
{
}

Expand Down Expand Up @@ -270,12 +324,14 @@ bool Stm32LcdDriver::start() {

while (this->displayState == SwitchToDraftIsPending); /* Wait until the LCD displays the draft framebuffer */

#ifdef USE_STM32F769I_DISCO
/* Send Display On DCS Command to display */
HAL_DSI_ShortWrite(&(this->hdsi),
0,
DSI_DCS_SHORT_PKT_WRITE_P1,
OTM8009A_CMD_DISPON,
0x00);
#endif

this->copyDraftToFinal();

Expand Down
7 changes: 4 additions & 3 deletions src/hal/Stm32SerialDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ void HAL_UART_MspInit(UART_HandleTypeDef *huart) {
}
}


void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) {
/*##-1- Reset peripherals ##################################################*/
if (huart->Instance!=USART6 /*&& huart->Instance!=USART3*/) {
Expand Down Expand Up @@ -159,7 +158,9 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart)
if (huart->Instance==USART6) {
unsigned char Received_Data = UART6_rxBuffer[0];
onTicUartRx((uint8_t)Received_Data);
BSP_LED_Toggle(LED2); // Toggle the green LED when new serial data is received on the TIC UART
#ifdef LED_SERIAL_RX
BSP_LED_Toggle(LED_SERIAL_RX); // Toggle the orange LED when new serial data is received on the TIC UART
#endif
UART6_Enable_interrupt_callback(huart);
}
}
Expand Down Expand Up @@ -284,4 +285,4 @@ extern "C" {
UART_HandleTypeDef* get_huart6() {
return getTicUartHandle();
}
} // extern "C"
} // extern "C"
5 changes: 5 additions & 0 deletions src/hal/Stm32TimerDriver.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "Stm32TimerDriver.h"
extern "C" {
#ifdef STM32F469xx
#include "stm32f4xx_hal.h"
#endif
#ifdef STM32F769xx
#include "stm32f7xx_hal.h"
#endif
}

void waitDelayAndCondition(uint32_t delay, FHalDelayRefreshFunc toRunWhileWaiting, FHalDelayConditionFunc conditionCheck, void* context) {
Expand Down
Loading

0 comments on commit 6339eea

Please sign in to comment.