Change folder name
This commit is contained in:
884
project/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery.c
Normal file
884
project/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery.c
Normal file
@@ -0,0 +1,884 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32746g_discovery.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides a set of firmware functions to manage LEDs,
|
||||
* push-buttons and COM ports available on STM32746G-Discovery
|
||||
* board(MB1191) from STMicroelectronics.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2016 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Dependencies
|
||||
- stm32f7xx_hal_cortex.c
|
||||
- stm32f7xx_hal_gpio.c
|
||||
- stm32f7xx_hal_uart.c
|
||||
- stm32f7xx_hal_i2c.c
|
||||
EndDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32746g_discovery.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LOW_LEVEL STM32746G_DISCOVERY_LOW_LEVEL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Private_TypesDefinitions STM32746G_DISCOVERY_LOW_LEVEL Private Types Definitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Private_Defines STM32746G_DISCOVERY_LOW_LEVEL Private Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @brief STM32746G DISCOVERY BSP Driver version number V2.0.4
|
||||
*/
|
||||
#define __STM32746G_DISCO_BSP_VERSION_MAIN (0x02) /*!< [31:24] main version */
|
||||
#define __STM32746G_DISCO_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
|
||||
#define __STM32746G_DISCO_BSP_VERSION_SUB2 (0x04) /*!< [15:8] sub2 version */
|
||||
#define __STM32746G_DISCO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
|
||||
#define __STM32746G_DISCO_BSP_VERSION ((__STM32746G_DISCO_BSP_VERSION_MAIN << 24)\
|
||||
|(__STM32746G_DISCO_BSP_VERSION_SUB1 << 16)\
|
||||
|(__STM32746G_DISCO_BSP_VERSION_SUB2 << 8 )\
|
||||
|(__STM32746G_DISCO_BSP_VERSION_RC))
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Private_Macros STM32746G_DISCOVERY_LOW_LEVEL Private Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Private_Variables STM32746G_DISCOVERY_LOW_LEVEL Private Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
const uint32_t GPIO_PIN[LEDn] = {LED1_PIN};
|
||||
|
||||
GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {WAKEUP_BUTTON_GPIO_PORT,
|
||||
TAMPER_BUTTON_GPIO_PORT,
|
||||
KEY_BUTTON_GPIO_PORT};
|
||||
|
||||
const uint16_t BUTTON_PIN[BUTTONn] = {WAKEUP_BUTTON_PIN,
|
||||
TAMPER_BUTTON_PIN,
|
||||
KEY_BUTTON_PIN};
|
||||
|
||||
const uint16_t BUTTON_IRQn[BUTTONn] = {WAKEUP_BUTTON_EXTI_IRQn,
|
||||
TAMPER_BUTTON_EXTI_IRQn,
|
||||
KEY_BUTTON_EXTI_IRQn};
|
||||
|
||||
USART_TypeDef* COM_USART[COMn] = {DISCOVERY_COM1};
|
||||
|
||||
GPIO_TypeDef* COM_TX_PORT[COMn] = {DISCOVERY_COM1_TX_GPIO_PORT};
|
||||
|
||||
GPIO_TypeDef* COM_RX_PORT[COMn] = {DISCOVERY_COM1_RX_GPIO_PORT};
|
||||
|
||||
const uint16_t COM_TX_PIN[COMn] = {DISCOVERY_COM1_TX_PIN};
|
||||
|
||||
const uint16_t COM_RX_PIN[COMn] = {DISCOVERY_COM1_RX_PIN};
|
||||
|
||||
const uint16_t COM_TX_AF[COMn] = {DISCOVERY_COM1_TX_AF};
|
||||
|
||||
const uint16_t COM_RX_AF[COMn] = {DISCOVERY_COM1_RX_AF};
|
||||
|
||||
static I2C_HandleTypeDef hI2cAudioHandler = {0};
|
||||
static I2C_HandleTypeDef hI2cExtHandler = {0};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Private_FunctionPrototypes STM32746G_DISCOVERY_LOW_LEVEL Private Function Prototypes
|
||||
* @{
|
||||
*/
|
||||
static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler);
|
||||
static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler);
|
||||
|
||||
static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
|
||||
static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler, uint8_t Addr, uint16_t Reg, uint16_t MemAddSize, uint8_t *Buffer, uint16_t Length);
|
||||
static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials);
|
||||
static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr);
|
||||
|
||||
/* AUDIO IO functions */
|
||||
void AUDIO_IO_Init(void);
|
||||
void AUDIO_IO_DeInit(void);
|
||||
void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value);
|
||||
uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg);
|
||||
void AUDIO_IO_Delay(uint32_t Delay);
|
||||
|
||||
/* TOUCHSCREEN IO functions */
|
||||
void TS_IO_Init(void);
|
||||
void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
|
||||
uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg);
|
||||
void TS_IO_Delay(uint32_t Delay);
|
||||
|
||||
/* CAMERA IO functions */
|
||||
void CAMERA_IO_Init(void);
|
||||
void CAMERA_Delay(uint32_t Delay);
|
||||
void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
|
||||
uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg);
|
||||
|
||||
/* I2C EEPROM IO function */
|
||||
void EEPROM_IO_Init(void);
|
||||
HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
|
||||
HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize);
|
||||
HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Exported_Functions STM32746G_DISCOVERY_LOW_LEVELSTM32746G_DISCOVERY_LOW_LEVEL Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This method returns the STM32746G DISCOVERY BSP Driver revision
|
||||
* @retval version: 0xXYZR (8bits for each decimal, R for RC)
|
||||
*/
|
||||
uint32_t BSP_GetVersion(void)
|
||||
{
|
||||
return __STM32746G_DISCO_BSP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures LED on GPIO.
|
||||
* @param Led: LED to be configured.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED1
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_LED_Init(Led_TypeDef Led)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
GPIO_TypeDef* gpio_led;
|
||||
|
||||
if (Led == LED1)
|
||||
{
|
||||
gpio_led = LED1_GPIO_PORT;
|
||||
/* Enable the GPIO_LED clock */
|
||||
LED1_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Configure the GPIO_LED pin */
|
||||
gpio_init_structure.Pin = GPIO_PIN[Led];
|
||||
gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
gpio_init_structure.Pull = GPIO_PULLUP;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_HIGH;
|
||||
|
||||
HAL_GPIO_Init(gpio_led, &gpio_init_structure);
|
||||
|
||||
/* By default, turn off LED */
|
||||
HAL_GPIO_WritePin(gpio_led, GPIO_PIN[Led], GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInit LEDs.
|
||||
* @param Led: LED to be configured.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED1
|
||||
* @note Led DeInit does not disable the GPIO clock
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_LED_DeInit(Led_TypeDef Led)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
GPIO_TypeDef* gpio_led;
|
||||
|
||||
if (Led == LED1)
|
||||
{
|
||||
gpio_led = LED1_GPIO_PORT;
|
||||
/* Turn off LED */
|
||||
HAL_GPIO_WritePin(gpio_led, GPIO_PIN[Led], GPIO_PIN_RESET);
|
||||
/* Configure the GPIO_LED pin */
|
||||
gpio_init_structure.Pin = GPIO_PIN[Led];
|
||||
HAL_GPIO_DeInit(gpio_led, gpio_init_structure.Pin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns selected LED On.
|
||||
* @param Led: LED to be set on
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED1
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_LED_On(Led_TypeDef Led)
|
||||
{
|
||||
GPIO_TypeDef* gpio_led;
|
||||
|
||||
if (Led == LED1) /* Switch On LED connected to GPIO */
|
||||
{
|
||||
gpio_led = LED1_GPIO_PORT;
|
||||
HAL_GPIO_WritePin(gpio_led, GPIO_PIN[Led], GPIO_PIN_SET);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns selected LED Off.
|
||||
* @param Led: LED to be set off
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED1
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_LED_Off(Led_TypeDef Led)
|
||||
{
|
||||
GPIO_TypeDef* gpio_led;
|
||||
|
||||
if (Led == LED1) /* Switch Off LED connected to GPIO */
|
||||
{
|
||||
gpio_led = LED1_GPIO_PORT;
|
||||
HAL_GPIO_WritePin(gpio_led, GPIO_PIN[Led], GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the selected LED.
|
||||
* @param Led: LED to be toggled
|
||||
* This parameter can be one of the following values:
|
||||
* @arg LED1
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_LED_Toggle(Led_TypeDef Led)
|
||||
{
|
||||
GPIO_TypeDef* gpio_led;
|
||||
|
||||
if (Led == LED1) /* Toggle LED connected to GPIO */
|
||||
{
|
||||
gpio_led = LED1_GPIO_PORT;
|
||||
HAL_GPIO_TogglePin(gpio_led, GPIO_PIN[Led]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures button GPIO and EXTI Line.
|
||||
* @param Button: Button to be configured
|
||||
* This parameter can be one of the following values:
|
||||
* @arg BUTTON_WAKEUP: Wakeup Push Button
|
||||
* @arg BUTTON_TAMPER: Tamper Push Button
|
||||
* @arg BUTTON_KEY: Key Push Button
|
||||
* @param ButtonMode: Button mode
|
||||
* This parameter can be one of the following values:
|
||||
* @arg BUTTON_MODE_GPIO: Button will be used as simple IO
|
||||
* @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line
|
||||
* with interrupt generation capability
|
||||
* @note On STM32746G-Discovery board, the three buttons (Wakeup, Tamper and key buttons)
|
||||
* are mapped on the same push button named "User"
|
||||
* on the board serigraphy.
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
/* Enable the BUTTON clock */
|
||||
BUTTONx_GPIO_CLK_ENABLE(Button);
|
||||
|
||||
if(ButtonMode == BUTTON_MODE_GPIO)
|
||||
{
|
||||
/* Configure Button pin as input */
|
||||
gpio_init_structure.Pin = BUTTON_PIN[Button];
|
||||
gpio_init_structure.Mode = GPIO_MODE_INPUT;
|
||||
gpio_init_structure.Pull = GPIO_NOPULL;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FAST;
|
||||
HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
|
||||
}
|
||||
|
||||
if(ButtonMode == BUTTON_MODE_EXTI)
|
||||
{
|
||||
/* Configure Button pin as input with External interrupt */
|
||||
gpio_init_structure.Pin = BUTTON_PIN[Button];
|
||||
gpio_init_structure.Pull = GPIO_NOPULL;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FAST;
|
||||
|
||||
if(Button != BUTTON_WAKEUP)
|
||||
{
|
||||
gpio_init_structure.Mode = GPIO_MODE_IT_FALLING;
|
||||
}
|
||||
else
|
||||
{
|
||||
gpio_init_structure.Mode = GPIO_MODE_IT_RISING;
|
||||
}
|
||||
|
||||
HAL_GPIO_Init(BUTTON_PORT[Button], &gpio_init_structure);
|
||||
|
||||
/* Enable and set Button EXTI Interrupt to the lowest priority */
|
||||
HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
|
||||
HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Push Button DeInit.
|
||||
* @param Button: Button to be configured
|
||||
* This parameter can be one of the following values:
|
||||
* @arg BUTTON_WAKEUP: Wakeup Push Button
|
||||
* @arg BUTTON_TAMPER: Tamper Push Button
|
||||
* @arg BUTTON_KEY: Key Push Button
|
||||
* @note On STM32746G-Discovery board, the three buttons (Wakeup, Tamper and key buttons)
|
||||
* are mapped on the same push button named "User"
|
||||
* on the board serigraphy.
|
||||
* @note PB DeInit does not disable the GPIO clock
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_PB_DeInit(Button_TypeDef Button)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
gpio_init_structure.Pin = BUTTON_PIN[Button];
|
||||
HAL_NVIC_DisableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
|
||||
HAL_GPIO_DeInit(BUTTON_PORT[Button], gpio_init_structure.Pin);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Returns the selected button state.
|
||||
* @param Button: Button to be checked
|
||||
* This parameter can be one of the following values:
|
||||
* @arg BUTTON_WAKEUP: Wakeup Push Button
|
||||
* @arg BUTTON_TAMPER: Tamper Push Button
|
||||
* @arg BUTTON_KEY: Key Push Button
|
||||
* @note On STM32746G-Discovery board, the three buttons (Wakeup, Tamper and key buttons)
|
||||
* are mapped on the same push button named "User"
|
||||
* on the board serigraphy.
|
||||
* @retval The Button GPIO pin value
|
||||
*/
|
||||
uint32_t BSP_PB_GetState(Button_TypeDef Button)
|
||||
{
|
||||
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configures COM port.
|
||||
* @param COM: COM port to be configured.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg COM1
|
||||
* @arg COM2
|
||||
* @param huart: Pointer to a UART_HandleTypeDef structure that contains the
|
||||
* configuration information for the specified USART peripheral.
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *huart)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
/* Enable GPIO clock */
|
||||
DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(COM);
|
||||
DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(COM);
|
||||
|
||||
/* Enable USART clock */
|
||||
DISCOVERY_COMx_CLK_ENABLE(COM);
|
||||
|
||||
/* Configure USART Tx as alternate function */
|
||||
gpio_init_structure.Pin = COM_TX_PIN[COM];
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FAST;
|
||||
gpio_init_structure.Pull = GPIO_PULLUP;
|
||||
gpio_init_structure.Alternate = COM_TX_AF[COM];
|
||||
HAL_GPIO_Init(COM_TX_PORT[COM], &gpio_init_structure);
|
||||
|
||||
/* Configure USART Rx as alternate function */
|
||||
gpio_init_structure.Pin = COM_RX_PIN[COM];
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
|
||||
gpio_init_structure.Alternate = COM_RX_AF[COM];
|
||||
HAL_GPIO_Init(COM_RX_PORT[COM], &gpio_init_structure);
|
||||
|
||||
/* USART configuration */
|
||||
huart->Instance = COM_USART[COM];
|
||||
HAL_UART_Init(huart);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInit COM port.
|
||||
* @param COM: COM port to be configured.
|
||||
* This parameter can be one of the following values:
|
||||
* @arg COM1
|
||||
* @arg COM2
|
||||
* @param huart: Pointer to a UART_HandleTypeDef structure that contains the
|
||||
* configuration information for the specified USART peripheral.
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart)
|
||||
{
|
||||
/* USART configuration */
|
||||
huart->Instance = COM_USART[COM];
|
||||
HAL_UART_DeInit(huart);
|
||||
|
||||
/* Enable USART clock */
|
||||
DISCOVERY_COMx_CLK_DISABLE(COM);
|
||||
|
||||
/* DeInit GPIO pins can be done in the application
|
||||
(by surcharging this __weak function) */
|
||||
|
||||
/* GPIO pins clock, DMA clock can be shut down in the application
|
||||
by surcharging this __weak function */
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
BUS OPERATIONS
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************* I2C Routines *********************************/
|
||||
/**
|
||||
* @brief Initializes I2C MSP.
|
||||
* @param i2c_handler : I2C handler
|
||||
* @retval None
|
||||
*/
|
||||
static void I2Cx_MspInit(I2C_HandleTypeDef *i2c_handler)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler))
|
||||
{
|
||||
/* AUDIO and LCD I2C MSP init */
|
||||
|
||||
/*** Configure the GPIOs ***/
|
||||
/* Enable GPIO clock */
|
||||
DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Configure I2C Tx as alternate function */
|
||||
gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SCL_PIN;
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_OD;
|
||||
gpio_init_structure.Pull = GPIO_NOPULL;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FAST;
|
||||
gpio_init_structure.Alternate = DISCOVERY_AUDIO_I2Cx_SCL_SDA_AF;
|
||||
HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/* Configure I2C Rx as alternate function */
|
||||
gpio_init_structure.Pin = DISCOVERY_AUDIO_I2Cx_SDA_PIN;
|
||||
HAL_GPIO_Init(DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/*** Configure the I2C peripheral ***/
|
||||
/* Enable I2C clock */
|
||||
DISCOVERY_AUDIO_I2Cx_CLK_ENABLE();
|
||||
|
||||
/* Force the I2C peripheral clock reset */
|
||||
DISCOVERY_AUDIO_I2Cx_FORCE_RESET();
|
||||
|
||||
/* Release the I2C peripheral clock reset */
|
||||
DISCOVERY_AUDIO_I2Cx_RELEASE_RESET();
|
||||
|
||||
/* Enable and set I2Cx Interrupt to a lower priority */
|
||||
HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_EV_IRQn, 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_EV_IRQn);
|
||||
|
||||
/* Enable and set I2Cx Interrupt to a lower priority */
|
||||
HAL_NVIC_SetPriority(DISCOVERY_AUDIO_I2Cx_ER_IRQn, 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ(DISCOVERY_AUDIO_I2Cx_ER_IRQn);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* External, camera and Arduino connector I2C MSP init */
|
||||
|
||||
/*** Configure the GPIOs ***/
|
||||
/* Enable GPIO clock */
|
||||
DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_CLK_ENABLE();
|
||||
|
||||
/* Configure I2C Tx as alternate function */
|
||||
gpio_init_structure.Pin = DISCOVERY_EXT_I2Cx_SCL_PIN;
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_OD;
|
||||
gpio_init_structure.Pull = GPIO_NOPULL;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FAST;
|
||||
gpio_init_structure.Alternate = DISCOVERY_EXT_I2Cx_SCL_SDA_AF;
|
||||
HAL_GPIO_Init(DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/* Configure I2C Rx as alternate function */
|
||||
gpio_init_structure.Pin = DISCOVERY_EXT_I2Cx_SDA_PIN;
|
||||
HAL_GPIO_Init(DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT, &gpio_init_structure);
|
||||
|
||||
/*** Configure the I2C peripheral ***/
|
||||
/* Enable I2C clock */
|
||||
DISCOVERY_EXT_I2Cx_CLK_ENABLE();
|
||||
|
||||
/* Force the I2C peripheral clock reset */
|
||||
DISCOVERY_EXT_I2Cx_FORCE_RESET();
|
||||
|
||||
/* Release the I2C peripheral clock reset */
|
||||
DISCOVERY_EXT_I2Cx_RELEASE_RESET();
|
||||
|
||||
/* Enable and set I2Cx Interrupt to a lower priority */
|
||||
HAL_NVIC_SetPriority(DISCOVERY_EXT_I2Cx_EV_IRQn, 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ(DISCOVERY_EXT_I2Cx_EV_IRQn);
|
||||
|
||||
/* Enable and set I2Cx Interrupt to a lower priority */
|
||||
HAL_NVIC_SetPriority(DISCOVERY_EXT_I2Cx_ER_IRQn, 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ(DISCOVERY_EXT_I2Cx_ER_IRQn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes I2C HAL.
|
||||
* @param i2c_handler : I2C handler
|
||||
* @retval None
|
||||
*/
|
||||
static void I2Cx_Init(I2C_HandleTypeDef *i2c_handler)
|
||||
{
|
||||
if(HAL_I2C_GetState(i2c_handler) == HAL_I2C_STATE_RESET)
|
||||
{
|
||||
if (i2c_handler == (I2C_HandleTypeDef*)(&hI2cAudioHandler))
|
||||
{
|
||||
/* Audio and LCD I2C configuration */
|
||||
i2c_handler->Instance = DISCOVERY_AUDIO_I2Cx;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* External, camera and Arduino connector I2C configuration */
|
||||
i2c_handler->Instance = DISCOVERY_EXT_I2Cx;
|
||||
}
|
||||
i2c_handler->Init.Timing = DISCOVERY_I2Cx_TIMING;
|
||||
i2c_handler->Init.OwnAddress1 = 0;
|
||||
i2c_handler->Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
i2c_handler->Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
i2c_handler->Init.OwnAddress2 = 0;
|
||||
i2c_handler->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
i2c_handler->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
|
||||
/* Init the I2C */
|
||||
I2Cx_MspInit(i2c_handler);
|
||||
HAL_I2C_Init(i2c_handler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads multiple data.
|
||||
* @param i2c_handler : I2C handler
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @param MemAddress: Memory address
|
||||
* @param Buffer: Pointer to data buffer
|
||||
* @param Length: Length of the data
|
||||
* @retval Number of read data
|
||||
*/
|
||||
static HAL_StatusTypeDef I2Cx_ReadMultiple(I2C_HandleTypeDef *i2c_handler,
|
||||
uint8_t Addr,
|
||||
uint16_t Reg,
|
||||
uint16_t MemAddress,
|
||||
uint8_t *Buffer,
|
||||
uint16_t Length)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
status = HAL_I2C_Mem_Read(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
|
||||
|
||||
/* Check the communication status */
|
||||
if(status != HAL_OK)
|
||||
{
|
||||
/* I2C error occurred */
|
||||
I2Cx_Error(i2c_handler, Addr);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a value in a register of the device through BUS in using DMA mode.
|
||||
* @param i2c_handler : I2C handler
|
||||
* @param Addr: Device address on BUS Bus.
|
||||
* @param Reg: The target register address to write
|
||||
* @param MemAddress: Memory address
|
||||
* @param Buffer: The target register value to be written
|
||||
* @param Length: buffer size to be written
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef I2Cx_WriteMultiple(I2C_HandleTypeDef *i2c_handler,
|
||||
uint8_t Addr,
|
||||
uint16_t Reg,
|
||||
uint16_t MemAddress,
|
||||
uint8_t *Buffer,
|
||||
uint16_t Length)
|
||||
{
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
status = HAL_I2C_Mem_Write(i2c_handler, Addr, (uint16_t)Reg, MemAddress, Buffer, Length, 1000);
|
||||
|
||||
/* Check the communication status */
|
||||
if(status != HAL_OK)
|
||||
{
|
||||
/* Re-Initiaize the I2C Bus */
|
||||
I2Cx_Error(i2c_handler, Addr);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if target device is ready for communication.
|
||||
* @note This function is used with Memory devices
|
||||
* @param i2c_handler : I2C handler
|
||||
* @param DevAddress: Target device address
|
||||
* @param Trials: Number of trials
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef I2Cx_IsDeviceReady(I2C_HandleTypeDef *i2c_handler, uint16_t DevAddress, uint32_t Trials)
|
||||
{
|
||||
return (HAL_I2C_IsDeviceReady(i2c_handler, DevAddress, Trials, 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Manages error callback by re-initializing I2C.
|
||||
* @param i2c_handler : I2C handler
|
||||
* @param Addr: I2C Address
|
||||
* @retval None
|
||||
*/
|
||||
static void I2Cx_Error(I2C_HandleTypeDef *i2c_handler, uint8_t Addr)
|
||||
{
|
||||
/* De-initialize the I2C communication bus */
|
||||
HAL_I2C_DeInit(i2c_handler);
|
||||
|
||||
/* Re-Initialize the I2C communication bus */
|
||||
I2Cx_Init(i2c_handler);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
LINK OPERATIONS
|
||||
*******************************************************************************/
|
||||
|
||||
/********************************* LINK AUDIO *********************************/
|
||||
|
||||
/**
|
||||
* @brief Initializes Audio low level.
|
||||
* @retval None
|
||||
*/
|
||||
void AUDIO_IO_Init(void)
|
||||
{
|
||||
I2Cx_Init(&hI2cAudioHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitializes Audio low level.
|
||||
* @retval None
|
||||
*/
|
||||
void AUDIO_IO_DeInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @param Value: Data to be written
|
||||
* @retval None
|
||||
*/
|
||||
void AUDIO_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value)
|
||||
{
|
||||
uint16_t tmp = Value;
|
||||
|
||||
Value = ((uint16_t)(tmp >> 8) & 0x00FF);
|
||||
|
||||
Value |= ((uint16_t)(tmp << 8)& 0xFF00);
|
||||
|
||||
I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_16BIT,(uint8_t*)&Value, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads a single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @retval Data to be read
|
||||
*/
|
||||
uint16_t AUDIO_IO_Read(uint8_t Addr, uint16_t Reg)
|
||||
{
|
||||
uint16_t read_value = 0, tmp = 0;
|
||||
|
||||
I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_16BIT, (uint8_t*)&read_value, 2);
|
||||
|
||||
tmp = ((uint16_t)(read_value >> 8) & 0x00FF);
|
||||
|
||||
tmp |= ((uint16_t)(read_value << 8)& 0xFF00);
|
||||
|
||||
read_value = tmp;
|
||||
|
||||
return read_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AUDIO Codec delay
|
||||
* @param Delay: Delay in ms
|
||||
* @retval None
|
||||
*/
|
||||
void AUDIO_IO_Delay(uint32_t Delay)
|
||||
{
|
||||
HAL_Delay(Delay);
|
||||
}
|
||||
|
||||
/********************************* LINK CAMERA ********************************/
|
||||
|
||||
/**
|
||||
* @brief Initializes Camera low level.
|
||||
* @retval None
|
||||
*/
|
||||
void CAMERA_IO_Init(void)
|
||||
{
|
||||
I2Cx_Init(&hI2cExtHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Camera writes single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Register address
|
||||
* @param Value: Data to be written
|
||||
* @retval None
|
||||
*/
|
||||
void CAMERA_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
|
||||
{
|
||||
I2Cx_WriteMultiple(&hI2cExtHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Camera reads single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Register address
|
||||
* @retval Read data
|
||||
*/
|
||||
uint8_t CAMERA_IO_Read(uint8_t Addr, uint8_t Reg)
|
||||
{
|
||||
uint8_t read_value = 0;
|
||||
|
||||
I2Cx_ReadMultiple(&hI2cExtHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1);
|
||||
|
||||
return read_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Camera delay
|
||||
* @param Delay: Delay in ms
|
||||
* @retval None
|
||||
*/
|
||||
void CAMERA_Delay(uint32_t Delay)
|
||||
{
|
||||
HAL_Delay(Delay);
|
||||
}
|
||||
|
||||
/******************************** LINK I2C EEPROM *****************************/
|
||||
|
||||
/**
|
||||
* @brief Initializes peripherals used by the I2C EEPROM driver.
|
||||
* @retval None
|
||||
*/
|
||||
void EEPROM_IO_Init(void)
|
||||
{
|
||||
I2Cx_Init(&hI2cExtHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write data to I2C EEPROM driver in using DMA channel.
|
||||
* @param DevAddress: Target device address
|
||||
* @param MemAddress: Internal memory address
|
||||
* @param pBuffer: Pointer to data buffer
|
||||
* @param BufferSize: Amount of data to be sent
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
|
||||
{
|
||||
return (I2Cx_WriteMultiple(&hI2cExtHandler, DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read data from I2C EEPROM driver in using DMA channel.
|
||||
* @param DevAddress: Target device address
|
||||
* @param MemAddress: Internal memory address
|
||||
* @param pBuffer: Pointer to data buffer
|
||||
* @param BufferSize: Amount of data to be read
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t* pBuffer, uint32_t BufferSize)
|
||||
{
|
||||
return (I2Cx_ReadMultiple(&hI2cExtHandler, DevAddress, MemAddress, I2C_MEMADD_SIZE_16BIT, pBuffer, BufferSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if target device is ready for communication.
|
||||
* @note This function is used with Memory devices
|
||||
* @param DevAddress: Target device address
|
||||
* @param Trials: Number of trials
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
|
||||
{
|
||||
return (I2Cx_IsDeviceReady(&hI2cExtHandler, DevAddress, Trials));
|
||||
}
|
||||
|
||||
/********************************* LINK TOUCHSCREEN *********************************/
|
||||
|
||||
/**
|
||||
* @brief Initializes Touchscreen low level.
|
||||
* @retval None
|
||||
*/
|
||||
void TS_IO_Init(void)
|
||||
{
|
||||
I2Cx_Init(&hI2cAudioHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes a single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @param Value: Data to be written
|
||||
* @retval None
|
||||
*/
|
||||
void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
|
||||
{
|
||||
I2Cx_WriteMultiple(&hI2cAudioHandler, Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT,(uint8_t*)&Value, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads a single data.
|
||||
* @param Addr: I2C address
|
||||
* @param Reg: Reg address
|
||||
* @retval Data to be read
|
||||
*/
|
||||
uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg)
|
||||
{
|
||||
uint8_t read_value = 0;
|
||||
|
||||
I2Cx_ReadMultiple(&hI2cAudioHandler, Addr, Reg, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&read_value, 1);
|
||||
|
||||
return read_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TS delay
|
||||
* @param Delay: Delay in ms
|
||||
* @retval None
|
||||
*/
|
||||
void TS_IO_Delay(uint32_t Delay)
|
||||
{
|
||||
HAL_Delay(Delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
321
project/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery.h
Normal file
321
project/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery.h
Normal file
@@ -0,0 +1,321 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32746g_discovery.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains definitions for STM32746G_DISCOVERY's LEDs,
|
||||
* push-buttons and COM ports hardware resources.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2016 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32746G_DISCOVERY_H
|
||||
#define __STM32746G_DISCOVERY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f7xx_hal.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY_LOW_LEVEL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Exported_Types STM32746G_DISCOVERY_LOW_LEVEL Exported Types
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
LED1 = 0,
|
||||
LED_GREEN = LED1,
|
||||
}Led_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_WAKEUP = 0,
|
||||
BUTTON_TAMPER = 1,
|
||||
BUTTON_KEY = 2
|
||||
}Button_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BUTTON_MODE_GPIO = 0,
|
||||
BUTTON_MODE_EXTI = 1
|
||||
}ButtonMode_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COM1 = 0,
|
||||
COM2 = 1
|
||||
}COM_TypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Exported_Constants STM32746G_DISCOVERY_LOW_LEVEL Exported Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Define for STM32746G_DISCOVERY board
|
||||
*/
|
||||
#if !defined (USE_STM32746G_DISCO)
|
||||
#define USE_STM32746G_DISCO
|
||||
#endif
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY_LOW_LEVEL_LED
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define LEDn ((uint8_t)1)
|
||||
|
||||
#define LED1_GPIO_PORT GPIOI
|
||||
#define LED1_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define LED1_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE()
|
||||
#define LED1_PIN GPIO_PIN_1
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY_LOW_LEVEL_BUTTON
|
||||
* @{
|
||||
*/
|
||||
#define BUTTONn ((uint8_t)3)
|
||||
|
||||
/**
|
||||
* @brief Wakeup push-button
|
||||
*/
|
||||
#define WAKEUP_BUTTON_PIN GPIO_PIN_11
|
||||
#define WAKEUP_BUTTON_GPIO_PORT GPIOI
|
||||
#define WAKEUP_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define WAKEUP_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE()
|
||||
#define WAKEUP_BUTTON_EXTI_IRQn EXTI15_10_IRQn
|
||||
|
||||
/**
|
||||
* @brief Tamper push-button
|
||||
*/
|
||||
#define TAMPER_BUTTON_PIN GPIO_PIN_11
|
||||
#define TAMPER_BUTTON_GPIO_PORT GPIOI
|
||||
#define TAMPER_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define TAMPER_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE()
|
||||
#define TAMPER_BUTTON_EXTI_IRQn EXTI15_10_IRQn
|
||||
|
||||
/**
|
||||
* @brief Key push-button
|
||||
*/
|
||||
#define KEY_BUTTON_PIN GPIO_PIN_11
|
||||
#define KEY_BUTTON_GPIO_PORT GPIOI
|
||||
#define KEY_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define KEY_BUTTON_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE()
|
||||
#define KEY_BUTTON_EXTI_IRQn EXTI15_10_IRQn
|
||||
|
||||
#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == 0) WAKEUP_BUTTON_GPIO_CLK_ENABLE(); else\
|
||||
if((__INDEX__) == 1) TAMPER_BUTTON_GPIO_CLK_ENABLE(); else\
|
||||
KEY_BUTTON_GPIO_CLK_ENABLE(); } while(0)
|
||||
|
||||
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? WAKEUP_BUTTON_GPIO_CLK_DISABLE() :\
|
||||
((__INDEX__) == 1) ? TAMPER_BUTTON_GPIO_CLK_DISABLE() : KEY_BUTTON_GPIO_CLK_DISABLE())
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY_LOW_LEVEL_SIGNAL
|
||||
* @{
|
||||
*/
|
||||
#define SIGNALn ((uint8_t)1)
|
||||
|
||||
/**
|
||||
* @brief SD-detect signal
|
||||
*/
|
||||
#define SD_DETECT_PIN GPIO_PIN_13
|
||||
#define SD_DETECT_GPIO_PORT GPIOC
|
||||
#define SD_DETECT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
|
||||
#define SD_DETECT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOC_CLK_DISABLE()
|
||||
#define SD_DETECT_EXTI_IRQn EXTI15_10_IRQn
|
||||
|
||||
/**
|
||||
* @brief Touch screen interrupt signal
|
||||
*/
|
||||
#define TS_INT_PIN GPIO_PIN_13
|
||||
#define TS_INT_GPIO_PORT GPIOI
|
||||
#define TS_INT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define TS_INT_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE()
|
||||
#define TS_INT_EXTI_IRQn EXTI15_10_IRQn
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY_LOW_LEVEL_COM
|
||||
* @{
|
||||
*/
|
||||
#define COMn ((uint8_t)1)
|
||||
|
||||
/**
|
||||
* @brief Definition for COM port1, connected to USART1
|
||||
*/
|
||||
#define DISCOVERY_COM1 USART1
|
||||
#define DISCOVERY_COM1_CLK_ENABLE() __HAL_RCC_USART1_CLK_ENABLE()
|
||||
#define DISCOVERY_COM1_CLK_DISABLE() __HAL_RCC_USART1_CLK_DISABLE()
|
||||
|
||||
#define DISCOVERY_COM1_TX_PIN GPIO_PIN_9
|
||||
#define DISCOVERY_COM1_TX_GPIO_PORT GPIOA
|
||||
#define DISCOVERY_COM1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
#define DISCOVERY_COM1_TX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOA_CLK_DISABLE()
|
||||
#define DISCOVERY_COM1_TX_AF GPIO_AF7_USART1
|
||||
|
||||
#define DISCOVERY_COM1_RX_PIN GPIO_PIN_7
|
||||
#define DISCOVERY_COM1_RX_GPIO_PORT GPIOB
|
||||
#define DISCOVERY_COM1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
#define DISCOVERY_COM1_RX_GPIO_CLK_DISABLE() __HAL_RCC_GPIOB_CLK_DISABLE()
|
||||
#define DISCOVERY_COM1_RX_AF GPIO_AF7_USART1
|
||||
|
||||
#define DISCOVERY_COM1_IRQn USART1_IRQn
|
||||
|
||||
#define DISCOVERY_COMx_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == COM1) DISCOVERY_COM1_CLK_ENABLE(); } while(0)
|
||||
#define DISCOVERY_COMx_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? DISCOVERY_COM1_CLK_DISABLE() : 0)
|
||||
|
||||
#define DISCOVERY_COMx_TX_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == COM1) DISCOVERY_COM1_TX_GPIO_CLK_ENABLE(); } while(0)
|
||||
#define DISCOVERY_COMx_TX_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? DISCOVERY_COM1_TX_GPIO_CLK_DISABLE() : 0)
|
||||
|
||||
#define DISCOVERY_COMx_RX_GPIO_CLK_ENABLE(__INDEX__) do { if((__INDEX__) == COM1) DISCOVERY_COM1_RX_GPIO_CLK_ENABLE(); } while(0)
|
||||
#define DISCOVERY_COMx_RX_GPIO_CLK_DISABLE(__INDEX__) (((__INDEX__) == 0) ? DISCOVERY_COM1_RX_GPIO_CLK_DISABLE() : 0)
|
||||
|
||||
/* Exported constant IO ------------------------------------------------------*/
|
||||
|
||||
#define LCD_I2C_ADDRESS ((uint16_t)0x70)
|
||||
#define CAMERA_I2C_ADDRESS ((uint16_t)0x60)
|
||||
#define AUDIO_I2C_ADDRESS ((uint16_t)0x34)
|
||||
#define EEPROM_I2C_ADDRESS_A01 ((uint16_t)0xA0)
|
||||
#define EEPROM_I2C_ADDRESS_A02 ((uint16_t)0xA6)
|
||||
#define TS_I2C_ADDRESS ((uint16_t)0x70)
|
||||
|
||||
/* I2C clock speed configuration (in Hz)
|
||||
WARNING:
|
||||
Make sure that this define is not already declared in other files (ie.
|
||||
stm32746g_discovery.h file). It can be used in parallel by other modules. */
|
||||
#ifndef I2C_SPEED
|
||||
#define I2C_SPEED ((uint32_t)100000)
|
||||
#endif /* I2C_SPEED */
|
||||
|
||||
/* User can use this section to tailor I2Cx/I2Cx instance used and associated
|
||||
resources */
|
||||
/* Definition for AUDIO and LCD I2Cx resources */
|
||||
#define DISCOVERY_AUDIO_I2Cx I2C3
|
||||
#define DISCOVERY_AUDIO_I2Cx_CLK_ENABLE() __HAL_RCC_I2C3_CLK_ENABLE()
|
||||
#define DISCOVERY_AUDIO_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
|
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOH_CLK_ENABLE()
|
||||
|
||||
#define DISCOVERY_AUDIO_I2Cx_FORCE_RESET() __HAL_RCC_I2C3_FORCE_RESET()
|
||||
#define DISCOVERY_AUDIO_I2Cx_RELEASE_RESET() __HAL_RCC_I2C3_RELEASE_RESET()
|
||||
|
||||
/* Definition for I2Cx Pins */
|
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_PIN GPIO_PIN_7
|
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_SDA_GPIO_PORT GPIOH
|
||||
#define DISCOVERY_AUDIO_I2Cx_SCL_SDA_AF GPIO_AF4_I2C3
|
||||
#define DISCOVERY_AUDIO_I2Cx_SDA_PIN GPIO_PIN_8
|
||||
|
||||
/* I2C interrupt requests */
|
||||
#define DISCOVERY_AUDIO_I2Cx_EV_IRQn I2C3_EV_IRQn
|
||||
#define DISCOVERY_AUDIO_I2Cx_ER_IRQn I2C3_ER_IRQn
|
||||
|
||||
/* Definition for external, camera and Arduino connector I2Cx resources */
|
||||
#define DISCOVERY_EXT_I2Cx I2C1
|
||||
#define DISCOVERY_EXT_I2Cx_CLK_ENABLE() __HAL_RCC_I2C1_CLK_ENABLE()
|
||||
#define DISCOVERY_EXT_DMAx_CLK_ENABLE() __HAL_RCC_DMA1_CLK_ENABLE()
|
||||
#define DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
|
||||
#define DISCOVERY_EXT_I2Cx_FORCE_RESET() __HAL_RCC_I2C1_FORCE_RESET()
|
||||
#define DISCOVERY_EXT_I2Cx_RELEASE_RESET() __HAL_RCC_I2C1_RELEASE_RESET()
|
||||
|
||||
/* Definition for I2Cx Pins */
|
||||
#define DISCOVERY_EXT_I2Cx_SCL_PIN GPIO_PIN_8
|
||||
#define DISCOVERY_EXT_I2Cx_SCL_SDA_GPIO_PORT GPIOB
|
||||
#define DISCOVERY_EXT_I2Cx_SCL_SDA_AF GPIO_AF4_I2C1
|
||||
#define DISCOVERY_EXT_I2Cx_SDA_PIN GPIO_PIN_9
|
||||
|
||||
/* I2C interrupt requests */
|
||||
#define DISCOVERY_EXT_I2Cx_EV_IRQn I2C1_EV_IRQn
|
||||
#define DISCOVERY_EXT_I2Cx_ER_IRQn I2C1_ER_IRQn
|
||||
|
||||
/* I2C TIMING Register define when I2C clock source is SYSCLK */
|
||||
/* I2C TIMING is calculated from APB1 source clock = 50 MHz */
|
||||
/* Due to the big MOFSET capacity for adapting the camera level the rising time is very large (>1us) */
|
||||
/* 0x40912732 takes in account the big rising and aims a clock of 100khz */
|
||||
#ifndef DISCOVERY_I2Cx_TIMING
|
||||
#define DISCOVERY_I2Cx_TIMING ((uint32_t)0x40912732)
|
||||
#endif /* DISCOVERY_I2Cx_TIMING */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LOW_LEVEL_Exported_Macros STM32746G_DISCOVERY_LOW_LEVEL Exported Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY_LOW_LEVEL_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint32_t BSP_GetVersion(void);
|
||||
void BSP_LED_Init(Led_TypeDef Led);
|
||||
void BSP_LED_DeInit(Led_TypeDef Led);
|
||||
void BSP_LED_On(Led_TypeDef Led);
|
||||
void BSP_LED_Off(Led_TypeDef Led);
|
||||
void BSP_LED_Toggle(Led_TypeDef Led);
|
||||
void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode);
|
||||
void BSP_PB_DeInit(Button_TypeDef Button);
|
||||
uint32_t BSP_PB_GetState(Button_TypeDef Button);
|
||||
void BSP_COM_Init(COM_TypeDef COM, UART_HandleTypeDef *husart);
|
||||
void BSP_COM_DeInit(COM_TypeDef COM, UART_HandleTypeDef *huart);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32746G_DISCOVERY_H */
|
||||
|
||||
1647
project/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.c
Normal file
1647
project/Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_lcd.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,249 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32746g_discovery_lcd.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* the stm32746g_discovery_lcd.c driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2016 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32746G_DISCOVERY_LCD_H
|
||||
#define __STM32746G_DISCOVERY_LCD_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* Include LCD component Driver */
|
||||
/* LCD RK043FN48H-CT672B 4,3" 480x272 pixels */
|
||||
#include "../Components/rk043fn48h/rk043fn48h.h"
|
||||
|
||||
/* Include SDRAM Driver */
|
||||
#include "stm32746g_discovery_sdram.h"
|
||||
|
||||
#include "stm32746g_discovery.h"
|
||||
#include "../../../Utilities/Fonts/fonts.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY_LCD
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LCD_Exported_Types STM32746G_DISCOVERY_LCD Exported Types
|
||||
* @{
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t TextColor;
|
||||
uint32_t BackColor;
|
||||
sFONT *pFont;
|
||||
}LCD_DrawPropTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int16_t X;
|
||||
int16_t Y;
|
||||
}Point, * pPoint;
|
||||
|
||||
/**
|
||||
* @brief Line mode structures definition
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CENTER_MODE = 0x01, /* Center mode */
|
||||
RIGHT_MODE = 0x02, /* Right mode */
|
||||
LEFT_MODE = 0x03 /* Left mode */
|
||||
}Text_AlignModeTypdef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_LCD_Exported_Constants STM32746G_DISCOVERY_LCD Exported Constants
|
||||
* @{
|
||||
*/
|
||||
#define MAX_LAYER_NUMBER ((uint32_t)2)
|
||||
|
||||
#define LCD_LayerCfgTypeDef LTDC_LayerCfgTypeDef
|
||||
|
||||
#define LTDC_ACTIVE_LAYER ((uint32_t)1) /* Layer 1 */
|
||||
/**
|
||||
* @brief LCD status structure definition
|
||||
*/
|
||||
#define LCD_OK ((uint8_t)0x00)
|
||||
#define LCD_ERROR ((uint8_t)0x01)
|
||||
#define LCD_TIMEOUT ((uint8_t)0x02)
|
||||
|
||||
/**
|
||||
* @brief LCD FB_StartAddress
|
||||
*/
|
||||
#define LCD_FB_START_ADDRESS ((uint32_t)0xC0000000)
|
||||
|
||||
/**
|
||||
* @brief LCD color
|
||||
*/
|
||||
#define LCD_COLOR_BLUE ((uint32_t)0xFF0000FF)
|
||||
#define LCD_COLOR_GREEN ((uint32_t)0xFF00FF00)
|
||||
#define LCD_COLOR_RED ((uint32_t)0xFFFF0000)
|
||||
#define LCD_COLOR_CYAN ((uint32_t)0xFF00FFFF)
|
||||
#define LCD_COLOR_MAGENTA ((uint32_t)0xFFFF00FF)
|
||||
#define LCD_COLOR_YELLOW ((uint32_t)0xFFFFFF00)
|
||||
#define LCD_COLOR_LIGHTBLUE ((uint32_t)0xFF8080FF)
|
||||
#define LCD_COLOR_LIGHTGREEN ((uint32_t)0xFF80FF80)
|
||||
#define LCD_COLOR_LIGHTRED ((uint32_t)0xFFFF8080)
|
||||
#define LCD_COLOR_LIGHTCYAN ((uint32_t)0xFF80FFFF)
|
||||
#define LCD_COLOR_LIGHTMAGENTA ((uint32_t)0xFFFF80FF)
|
||||
#define LCD_COLOR_LIGHTYELLOW ((uint32_t)0xFFFFFF80)
|
||||
#define LCD_COLOR_DARKBLUE ((uint32_t)0xFF000080)
|
||||
#define LCD_COLOR_DARKGREEN ((uint32_t)0xFF008000)
|
||||
#define LCD_COLOR_DARKRED ((uint32_t)0xFF800000)
|
||||
#define LCD_COLOR_DARKCYAN ((uint32_t)0xFF008080)
|
||||
#define LCD_COLOR_DARKMAGENTA ((uint32_t)0xFF800080)
|
||||
#define LCD_COLOR_DARKYELLOW ((uint32_t)0xFF808000)
|
||||
#define LCD_COLOR_WHITE ((uint32_t)0xFFFFFFFF)
|
||||
#define LCD_COLOR_LIGHTGRAY ((uint32_t)0xFFD3D3D3)
|
||||
#define LCD_COLOR_GRAY ((uint32_t)0xFF808080)
|
||||
#define LCD_COLOR_DARKGRAY ((uint32_t)0xFF404040)
|
||||
#define LCD_COLOR_BLACK ((uint32_t)0xFF000000)
|
||||
#define LCD_COLOR_BROWN ((uint32_t)0xFFA52A2A)
|
||||
#define LCD_COLOR_ORANGE ((uint32_t)0xFFFFA500)
|
||||
#define LCD_COLOR_TRANSPARENT ((uint32_t)0x00000000)
|
||||
|
||||
/**
|
||||
* @brief LCD default font
|
||||
*/
|
||||
#define LCD_DEFAULT_FONT Font24
|
||||
|
||||
/**
|
||||
* @brief LCD Reload Types
|
||||
*/
|
||||
#define LCD_RELOAD_IMMEDIATE ((uint32_t)LTDC_SRCR_IMR)
|
||||
#define LCD_RELOAD_VERTICAL_BLANKING ((uint32_t)LTDC_SRCR_VBR)
|
||||
|
||||
|
||||
/**
|
||||
* @brief LCD special pins
|
||||
*/
|
||||
/* Display enable pin */
|
||||
#define LCD_DISP_PIN GPIO_PIN_12
|
||||
#define LCD_DISP_GPIO_PORT GPIOI
|
||||
#define LCD_DISP_GPIO_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||
#define LCD_DISP_GPIO_CLK_DISABLE() __HAL_RCC_GPIOI_CLK_DISABLE()
|
||||
|
||||
/* Backlight control pin */
|
||||
#define LCD_BL_CTRL_PIN GPIO_PIN_3
|
||||
#define LCD_BL_CTRL_GPIO_PORT GPIOK
|
||||
#define LCD_BL_CTRL_GPIO_CLK_ENABLE() __HAL_RCC_GPIOK_CLK_ENABLE()
|
||||
#define LCD_BL_CTRL_GPIO_CLK_DISABLE() __HAL_RCC_GPIOK_CLK_DISABLE()
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY_LCD_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t BSP_LCD_Init(void);
|
||||
uint8_t BSP_LCD_DeInit(void);
|
||||
uint32_t BSP_LCD_GetXSize(void);
|
||||
uint32_t BSP_LCD_GetYSize(void);
|
||||
void BSP_LCD_SetXSize(uint32_t imageWidthPixels);
|
||||
void BSP_LCD_SetYSize(uint32_t imageHeightPixels);
|
||||
|
||||
/* Functions using the LTDC controller */
|
||||
void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FrameBuffer);
|
||||
void BSP_LCD_LayerRgb565Init(uint16_t LayerIndex, uint32_t FB_Address);
|
||||
void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency);
|
||||
void BSP_LCD_SetTransparency_NoReload(uint32_t LayerIndex, uint8_t Transparency);
|
||||
void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address);
|
||||
void BSP_LCD_SetLayerAddress_NoReload(uint32_t LayerIndex, uint32_t Address);
|
||||
void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue);
|
||||
void BSP_LCD_SetColorKeying_NoReload(uint32_t LayerIndex, uint32_t RGBValue);
|
||||
void BSP_LCD_ResetColorKeying(uint32_t LayerIndex);
|
||||
void BSP_LCD_ResetColorKeying_NoReload(uint32_t LayerIndex);
|
||||
void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
|
||||
void BSP_LCD_SetLayerWindow_NoReload(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
|
||||
void BSP_LCD_SelectLayer(uint32_t LayerIndex);
|
||||
void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State);
|
||||
void BSP_LCD_SetLayerVisible_NoReload(uint32_t LayerIndex, FunctionalState State);
|
||||
void BSP_LCD_Reload(uint32_t ReloadType);
|
||||
|
||||
void BSP_LCD_SetTextColor(uint32_t Color);
|
||||
uint32_t BSP_LCD_GetTextColor(void);
|
||||
void BSP_LCD_SetBackColor(uint32_t Color);
|
||||
uint32_t BSP_LCD_GetBackColor(void);
|
||||
void BSP_LCD_SetFont(sFONT *fonts);
|
||||
sFONT *BSP_LCD_GetFont(void);
|
||||
|
||||
uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos);
|
||||
void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t pixel);
|
||||
void BSP_LCD_Clear(uint32_t Color);
|
||||
void BSP_LCD_ClearStringLine(uint32_t Line);
|
||||
void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr);
|
||||
void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode);
|
||||
void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii);
|
||||
|
||||
void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
|
||||
void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
|
||||
void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
|
||||
void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
|
||||
void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount);
|
||||
void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius);
|
||||
void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp);
|
||||
|
||||
void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
|
||||
void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius);
|
||||
void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount);
|
||||
void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius);
|
||||
|
||||
void BSP_LCD_DisplayOff(void);
|
||||
void BSP_LCD_DisplayOn(void);
|
||||
|
||||
/* These functions can be modified in case the current settings
|
||||
need to be changed for specific application needs */
|
||||
void BSP_LCD_MspInit(LTDC_HandleTypeDef *hltdc, void *Params);
|
||||
void BSP_LCD_MspDeInit(LTDC_HandleTypeDef *hltdc, void *Params);
|
||||
void BSP_LCD_ClockConfig(LTDC_HandleTypeDef *hltdc, void *Params);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32746G_DISCOVERY_LCD_H */
|
||||
|
||||
@@ -0,0 +1,481 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32746g_discovery_sdram.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file includes the SDRAM driver for the MT48LC4M32B2B5-7 memory
|
||||
* device mounted on STM32746G-Discovery board.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2016 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@verbatim
|
||||
1. How To use this driver:
|
||||
--------------------------
|
||||
- This driver is used to drive the MT48LC4M32B2B5-7 SDRAM external memory mounted
|
||||
on STM32746G-Discovery board.
|
||||
- This driver does not need a specific component driver for the SDRAM device
|
||||
to be included with.
|
||||
|
||||
2. Driver description:
|
||||
---------------------
|
||||
+ Initialization steps:
|
||||
o Initialize the SDRAM external memory using the BSP_SDRAM_Init() function. This
|
||||
function includes the MSP layer hardware resources initialization and the
|
||||
FMC controller configuration to interface with the external SDRAM memory.
|
||||
o It contains the SDRAM initialization sequence to program the SDRAM external
|
||||
device using the function BSP_SDRAM_Initialization_sequence(). Note that this
|
||||
sequence is standard for all SDRAM devices, but can include some differences
|
||||
from a device to another. If it is the case, the right sequence should be
|
||||
implemented separately.
|
||||
|
||||
+ SDRAM read/write operations
|
||||
o SDRAM external memory can be accessed with read/write operations once it is
|
||||
initialized.
|
||||
Read/write operation can be performed with AHB access using the functions
|
||||
BSP_SDRAM_ReadData()/BSP_SDRAM_WriteData(), or by DMA transfer using the functions
|
||||
BSP_SDRAM_ReadData_DMA()/BSP_SDRAM_WriteData_DMA().
|
||||
o The AHB access is performed with 32-bit width transaction, the DMA transfer
|
||||
configuration is fixed at single (no burst) word transfer (see the
|
||||
SDRAM_MspInit() static function).
|
||||
o User can implement his own functions for read/write access with his desired
|
||||
configurations.
|
||||
o If interrupt mode is used for DMA transfer, the function BSP_SDRAM_DMA_IRQHandler()
|
||||
is called in IRQ handler file, to serve the generated interrupt once the DMA
|
||||
transfer is complete.
|
||||
o You can send a command to the SDRAM device in runtime using the function
|
||||
BSP_SDRAM_Sendcmd(), and giving the desired command as parameter chosen between
|
||||
the predefined commands of the "FMC_SDRAM_CommandTypeDef" structure.
|
||||
|
||||
@endverbatim
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Dependencies
|
||||
- stm32f7xx_hal_sdram.c
|
||||
- stm32f7xx_ll_fmc.c
|
||||
- stm32f7xx_hal_dma.c
|
||||
- stm32f7xx_hal_gpio.c
|
||||
- stm32f7xx_hal_cortex.c
|
||||
- stm32f7xx_hal_rcc_ex.h
|
||||
EndDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32746g_discovery_sdram.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_SDRAM STM32746G_DISCOVERY_SDRAM
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_SDRAM_Private_Types_Definitions STM32746G_DISCOVERY_SDRAM Private Types Definitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_SDRAM_Private_Defines STM32746G_DISCOVERY_SDRAM Private Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_SDRAM_Private_Macros STM32746G_DISCOVERY_SDRAM Private Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_SDRAM_Private_Variables STM32746G_DISCOVERY_SDRAM Private Variables
|
||||
* @{
|
||||
*/
|
||||
SDRAM_HandleTypeDef sdramHandle;
|
||||
static FMC_SDRAM_TimingTypeDef Timing;
|
||||
static FMC_SDRAM_CommandTypeDef Command;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_SDRAM_Private_Function_Prototypes STM32746G_DISCOVERY_SDRAM Private Function Prototypes
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_SDRAM_Exported_Functions STM32746G_DISCOVERY_SDRAM Exported Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initializes the SDRAM device.
|
||||
* @retval SDRAM status
|
||||
*/
|
||||
uint8_t BSP_SDRAM_Init(void)
|
||||
{
|
||||
static uint8_t sdramstatus = SDRAM_ERROR;
|
||||
/* SDRAM device configuration */
|
||||
sdramHandle.Instance = FMC_SDRAM_DEVICE;
|
||||
|
||||
/* Timing configuration for 100Mhz as SD clock frequency (System clock is up to 200Mhz) */
|
||||
Timing.LoadToActiveDelay = 2;
|
||||
Timing.ExitSelfRefreshDelay = 7;
|
||||
Timing.SelfRefreshTime = 4;
|
||||
Timing.RowCycleDelay = 7;
|
||||
Timing.WriteRecoveryTime = 2;
|
||||
Timing.RPDelay = 2;
|
||||
Timing.RCDDelay = 2;
|
||||
|
||||
sdramHandle.Init.SDBank = FMC_SDRAM_BANK1;
|
||||
sdramHandle.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
||||
sdramHandle.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
||||
sdramHandle.Init.MemoryDataWidth = SDRAM_MEMORY_WIDTH;
|
||||
sdramHandle.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
||||
sdramHandle.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_2;
|
||||
sdramHandle.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
||||
sdramHandle.Init.SDClockPeriod = SDCLOCK_PERIOD;
|
||||
sdramHandle.Init.ReadBurst = FMC_SDRAM_RBURST_ENABLE;
|
||||
sdramHandle.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;
|
||||
|
||||
/* SDRAM controller initialization */
|
||||
|
||||
BSP_SDRAM_MspInit(&sdramHandle, NULL); /* __weak function can be rewritten by the application */
|
||||
|
||||
if(HAL_SDRAM_Init(&sdramHandle, &Timing) != HAL_OK)
|
||||
{
|
||||
sdramstatus = SDRAM_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
sdramstatus = SDRAM_OK;
|
||||
}
|
||||
|
||||
/* SDRAM initialization sequence */
|
||||
BSP_SDRAM_Initialization_sequence(REFRESH_COUNT);
|
||||
|
||||
return sdramstatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes the SDRAM device.
|
||||
* @retval SDRAM status
|
||||
*/
|
||||
uint8_t BSP_SDRAM_DeInit(void)
|
||||
{
|
||||
static uint8_t sdramstatus = SDRAM_ERROR;
|
||||
/* SDRAM device de-initialization */
|
||||
sdramHandle.Instance = FMC_SDRAM_DEVICE;
|
||||
|
||||
if(HAL_SDRAM_DeInit(&sdramHandle) != HAL_OK)
|
||||
{
|
||||
sdramstatus = SDRAM_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
sdramstatus = SDRAM_OK;
|
||||
}
|
||||
|
||||
/* SDRAM controller de-initialization */
|
||||
BSP_SDRAM_MspDeInit(&sdramHandle, NULL);
|
||||
|
||||
return sdramstatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Programs the SDRAM device.
|
||||
* @param RefreshCount: SDRAM refresh counter value
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_SDRAM_Initialization_sequence(uint32_t RefreshCount)
|
||||
{
|
||||
__IO uint32_t tmpmrd = 0;
|
||||
|
||||
/* Step 1: Configure a clock configuration enable command */
|
||||
Command.CommandMode = FMC_SDRAM_CMD_CLK_ENABLE;
|
||||
Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1;
|
||||
Command.AutoRefreshNumber = 1;
|
||||
Command.ModeRegisterDefinition = 0;
|
||||
|
||||
/* Send the command */
|
||||
HAL_SDRAM_SendCommand(&sdramHandle, &Command, SDRAM_TIMEOUT);
|
||||
|
||||
/* Step 2: Insert 100 us minimum delay */
|
||||
/* Inserted delay is equal to 1 ms due to systick time base unit (ms) */
|
||||
HAL_Delay(1);
|
||||
|
||||
/* Step 3: Configure a PALL (precharge all) command */
|
||||
Command.CommandMode = FMC_SDRAM_CMD_PALL;
|
||||
Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1;
|
||||
Command.AutoRefreshNumber = 1;
|
||||
Command.ModeRegisterDefinition = 0;
|
||||
|
||||
/* Send the command */
|
||||
HAL_SDRAM_SendCommand(&sdramHandle, &Command, SDRAM_TIMEOUT);
|
||||
|
||||
/* Step 4: Configure an Auto Refresh command */
|
||||
Command.CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
|
||||
Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1;
|
||||
Command.AutoRefreshNumber = 8;
|
||||
Command.ModeRegisterDefinition = 0;
|
||||
|
||||
/* Send the command */
|
||||
HAL_SDRAM_SendCommand(&sdramHandle, &Command, SDRAM_TIMEOUT);
|
||||
|
||||
/* Step 5: Program the external memory mode register */
|
||||
tmpmrd = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_1 |\
|
||||
SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL |\
|
||||
SDRAM_MODEREG_CAS_LATENCY_2 |\
|
||||
SDRAM_MODEREG_OPERATING_MODE_STANDARD |\
|
||||
SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
|
||||
|
||||
Command.CommandMode = FMC_SDRAM_CMD_LOAD_MODE;
|
||||
Command.CommandTarget = FMC_SDRAM_CMD_TARGET_BANK1;
|
||||
Command.AutoRefreshNumber = 1;
|
||||
Command.ModeRegisterDefinition = tmpmrd;
|
||||
|
||||
/* Send the command */
|
||||
HAL_SDRAM_SendCommand(&sdramHandle, &Command, SDRAM_TIMEOUT);
|
||||
|
||||
/* Step 6: Set the refresh rate counter */
|
||||
/* Set the device refresh rate */
|
||||
HAL_SDRAM_ProgramRefreshRate(&sdramHandle, RefreshCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads an amount of data from the SDRAM memory in polling mode.
|
||||
* @param uwStartAddress: Read start address
|
||||
* @param pData: Pointer to data to be read
|
||||
* @param uwDataSize: Size of read data from the memory
|
||||
* @retval SDRAM status
|
||||
*/
|
||||
uint8_t BSP_SDRAM_ReadData(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize)
|
||||
{
|
||||
if(HAL_SDRAM_Read_32b(&sdramHandle, (uint32_t *)uwStartAddress, pData, uwDataSize) != HAL_OK)
|
||||
{
|
||||
return SDRAM_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SDRAM_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads an amount of data from the SDRAM memory in DMA mode.
|
||||
* @param uwStartAddress: Read start address
|
||||
* @param pData: Pointer to data to be read
|
||||
* @param uwDataSize: Size of read data from the memory
|
||||
* @retval SDRAM status
|
||||
*/
|
||||
uint8_t BSP_SDRAM_ReadData_DMA(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize)
|
||||
{
|
||||
if(HAL_SDRAM_Read_DMA(&sdramHandle, (uint32_t *)uwStartAddress, pData, uwDataSize) != HAL_OK)
|
||||
{
|
||||
return SDRAM_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SDRAM_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes an amount of data to the SDRAM memory in polling mode.
|
||||
* @param uwStartAddress: Write start address
|
||||
* @param pData: Pointer to data to be written
|
||||
* @param uwDataSize: Size of written data from the memory
|
||||
* @retval SDRAM status
|
||||
*/
|
||||
uint8_t BSP_SDRAM_WriteData(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize)
|
||||
{
|
||||
if(HAL_SDRAM_Write_32b(&sdramHandle, (uint32_t *)uwStartAddress, pData, uwDataSize) != HAL_OK)
|
||||
{
|
||||
return SDRAM_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SDRAM_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes an amount of data to the SDRAM memory in DMA mode.
|
||||
* @param uwStartAddress: Write start address
|
||||
* @param pData: Pointer to data to be written
|
||||
* @param uwDataSize: Size of written data from the memory
|
||||
* @retval SDRAM status
|
||||
*/
|
||||
uint8_t BSP_SDRAM_WriteData_DMA(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize)
|
||||
{
|
||||
if(HAL_SDRAM_Write_DMA(&sdramHandle, (uint32_t *)uwStartAddress, pData, uwDataSize) != HAL_OK)
|
||||
{
|
||||
return SDRAM_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SDRAM_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sends command to the SDRAM bank.
|
||||
* @param SdramCmd: Pointer to SDRAM command structure
|
||||
* @retval SDRAM status
|
||||
*/
|
||||
uint8_t BSP_SDRAM_Sendcmd(FMC_SDRAM_CommandTypeDef *SdramCmd)
|
||||
{
|
||||
if(HAL_SDRAM_SendCommand(&sdramHandle, SdramCmd, SDRAM_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return SDRAM_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SDRAM_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializes SDRAM MSP.
|
||||
* @param hsdram: SDRAM handle
|
||||
* @param Params
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SDRAM_MspInit(SDRAM_HandleTypeDef *hsdram, void *Params)
|
||||
{
|
||||
static DMA_HandleTypeDef dma_handle;
|
||||
GPIO_InitTypeDef gpio_init_structure;
|
||||
|
||||
/* Enable FMC clock */
|
||||
__HAL_RCC_FMC_CLK_ENABLE();
|
||||
|
||||
/* Enable chosen DMAx clock */
|
||||
__DMAx_CLK_ENABLE();
|
||||
|
||||
/* Enable GPIOs clock */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
|
||||
/* Common GPIO configuration */
|
||||
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
|
||||
gpio_init_structure.Pull = GPIO_PULLUP;
|
||||
gpio_init_structure.Speed = GPIO_SPEED_FAST;
|
||||
gpio_init_structure.Alternate = GPIO_AF12_FMC;
|
||||
|
||||
/* GPIOC configuration */
|
||||
gpio_init_structure.Pin = GPIO_PIN_3;
|
||||
HAL_GPIO_Init(GPIOC, &gpio_init_structure);
|
||||
|
||||
/* GPIOD configuration */
|
||||
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_8 | GPIO_PIN_9 |
|
||||
GPIO_PIN_10 | GPIO_PIN_14 | GPIO_PIN_15;
|
||||
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
|
||||
|
||||
/* GPIOE configuration */
|
||||
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_7| GPIO_PIN_8 | GPIO_PIN_9 |\
|
||||
GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
|
||||
GPIO_PIN_15;
|
||||
HAL_GPIO_Init(GPIOE, &gpio_init_structure);
|
||||
|
||||
/* GPIOF configuration */
|
||||
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
|
||||
GPIO_PIN_5 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
|
||||
GPIO_PIN_15;
|
||||
HAL_GPIO_Init(GPIOF, &gpio_init_structure);
|
||||
|
||||
/* GPIOG configuration */
|
||||
gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4| GPIO_PIN_5 | GPIO_PIN_8 |\
|
||||
GPIO_PIN_15;
|
||||
HAL_GPIO_Init(GPIOG, &gpio_init_structure);
|
||||
|
||||
/* GPIOH configuration */
|
||||
gpio_init_structure.Pin = GPIO_PIN_3 | GPIO_PIN_5;
|
||||
HAL_GPIO_Init(GPIOH, &gpio_init_structure);
|
||||
|
||||
/* Configure common DMA parameters */
|
||||
dma_handle.Init.Channel = SDRAM_DMAx_CHANNEL;
|
||||
dma_handle.Init.Direction = DMA_MEMORY_TO_MEMORY;
|
||||
dma_handle.Init.PeriphInc = DMA_PINC_ENABLE;
|
||||
dma_handle.Init.MemInc = DMA_MINC_ENABLE;
|
||||
dma_handle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
|
||||
dma_handle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
|
||||
dma_handle.Init.Mode = DMA_NORMAL;
|
||||
dma_handle.Init.Priority = DMA_PRIORITY_HIGH;
|
||||
dma_handle.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
||||
dma_handle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
||||
dma_handle.Init.MemBurst = DMA_MBURST_SINGLE;
|
||||
dma_handle.Init.PeriphBurst = DMA_PBURST_SINGLE;
|
||||
|
||||
dma_handle.Instance = SDRAM_DMAx_STREAM;
|
||||
|
||||
/* Associate the DMA handle */
|
||||
__HAL_LINKDMA(hsdram, hdma, dma_handle);
|
||||
|
||||
/* Deinitialize the stream for new transfer */
|
||||
HAL_DMA_DeInit(&dma_handle);
|
||||
|
||||
/* Configure the DMA stream */
|
||||
HAL_DMA_Init(&dma_handle);
|
||||
|
||||
/* NVIC configuration for DMA transfer complete interrupt */
|
||||
HAL_NVIC_SetPriority(SDRAM_DMAx_IRQn, 0x0F, 0);
|
||||
HAL_NVIC_EnableIRQ(SDRAM_DMAx_IRQn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeInitializes SDRAM MSP.
|
||||
* @param hsdram: SDRAM handle
|
||||
* @param Params
|
||||
* @retval None
|
||||
*/
|
||||
__weak void BSP_SDRAM_MspDeInit(SDRAM_HandleTypeDef *hsdram, void *Params)
|
||||
{
|
||||
static DMA_HandleTypeDef dma_handle;
|
||||
|
||||
/* Disable NVIC configuration for DMA interrupt */
|
||||
HAL_NVIC_DisableIRQ(SDRAM_DMAx_IRQn);
|
||||
|
||||
/* Deinitialize the stream for new transfer */
|
||||
dma_handle.Instance = SDRAM_DMAx_STREAM;
|
||||
HAL_DMA_DeInit(&dma_handle);
|
||||
|
||||
/* GPIO pins clock, FMC clock and DMA clock can be shut down in the applications
|
||||
by surcharging this __weak function */
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32746g_discovery_sdram.h
|
||||
* @author MCD Application Team
|
||||
* @brief This file contains the common defines and functions prototypes for
|
||||
* the stm32746g_discovery_sdram.c driver.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2016 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32746G_DISCOVERY_SDRAM_H
|
||||
#define __STM32746G_DISCOVERY_SDRAM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f7xx_hal.h"
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY_SDRAM
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_SDRAM_Exported_Types STM32746G_DISCOVERY_SDRAM Exported Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief SDRAM status structure definition
|
||||
*/
|
||||
#define SDRAM_OK ((uint8_t)0x00)
|
||||
#define SDRAM_ERROR ((uint8_t)0x01)
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_SDRAM_Exported_Constants STM32746G_DISCOVERY_SDRAM Exported Constants
|
||||
* @{
|
||||
*/
|
||||
#define SDRAM_DEVICE_ADDR ((uint32_t)0xC0000000)
|
||||
#define SDRAM_DEVICE_SIZE ((uint32_t)0x800000) /* SDRAM device size in MBytes */
|
||||
|
||||
/* #define SDRAM_MEMORY_WIDTH FMC_SDRAM_MEM_BUS_WIDTH_8 */
|
||||
#define SDRAM_MEMORY_WIDTH FMC_SDRAM_MEM_BUS_WIDTH_16
|
||||
|
||||
#define SDCLOCK_PERIOD FMC_SDRAM_CLOCK_PERIOD_2
|
||||
/* #define SDCLOCK_PERIOD FMC_SDRAM_CLOCK_PERIOD_3 */
|
||||
|
||||
#define REFRESH_COUNT ((uint32_t)0x0603) /* SDRAM refresh counter (100Mhz SD clock) */
|
||||
|
||||
#define SDRAM_TIMEOUT ((uint32_t)0xFFFF)
|
||||
|
||||
/* DMA definitions for SDRAM DMA transfer */
|
||||
#define __DMAx_CLK_ENABLE __HAL_RCC_DMA2_CLK_ENABLE
|
||||
#define __DMAx_CLK_DISABLE __HAL_RCC_DMA2_CLK_DISABLE
|
||||
#define SDRAM_DMAx_CHANNEL DMA_CHANNEL_0
|
||||
#define SDRAM_DMAx_STREAM DMA2_Stream0
|
||||
#define SDRAM_DMAx_IRQn DMA2_Stream0_IRQn
|
||||
#define BSP_SDRAM_DMA_IRQHandler DMA2_Stream0_IRQHandler
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief FMC SDRAM Mode definition register defines
|
||||
*/
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_1 ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_2 ((uint16_t)0x0001)
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_4 ((uint16_t)0x0002)
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_8 ((uint16_t)0x0004)
|
||||
#define SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_BURST_TYPE_INTERLEAVED ((uint16_t)0x0008)
|
||||
#define SDRAM_MODEREG_CAS_LATENCY_2 ((uint16_t)0x0020)
|
||||
#define SDRAM_MODEREG_CAS_LATENCY_3 ((uint16_t)0x0030)
|
||||
#define SDRAM_MODEREG_OPERATING_MODE_STANDARD ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_WRITEBURST_MODE_PROGRAMMED ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_WRITEBURST_MODE_SINGLE ((uint16_t)0x0200)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup STM32746G_DISCOVERY_SDRAM_Exported_Macro STM32746G_DISCOVERY_SDRAM Exported Macro
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32746G_DISCOVERY_SDRAM_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t BSP_SDRAM_Init(void);
|
||||
uint8_t BSP_SDRAM_DeInit(void);
|
||||
void BSP_SDRAM_Initialization_sequence(uint32_t RefreshCount);
|
||||
uint8_t BSP_SDRAM_ReadData(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize);
|
||||
uint8_t BSP_SDRAM_ReadData_DMA(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize);
|
||||
uint8_t BSP_SDRAM_WriteData(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize);
|
||||
uint8_t BSP_SDRAM_WriteData_DMA(uint32_t uwStartAddress, uint32_t *pData, uint32_t uwDataSize);
|
||||
uint8_t BSP_SDRAM_Sendcmd(FMC_SDRAM_CommandTypeDef *SdramCmd);
|
||||
|
||||
/* These functions can be modified in case the current settings (e.g. DMA stream)
|
||||
need to be changed for specific application needs */
|
||||
void BSP_SDRAM_MspInit(SDRAM_HandleTypeDef *hsdram, void *Params);
|
||||
void BSP_SDRAM_MspDeInit(SDRAM_HandleTypeDef *hsdram, void *Params);
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32746G_DISCOVERY_SDRAM_H */
|
||||
|
||||
Reference in New Issue
Block a user