NEW: sync the code of DJI Payload-SDK version 2.2.1 released on January 20 2021.

Signed-off-by: DJI-Martin <DJI-Martin@dji.com>
This commit is contained in:
DJI-Martin
2022-01-12 21:44:58 +08:00
parent b1f481e0d4
commit ca41636cc6
1373 changed files with 1530617 additions and 650830 deletions

View File

@ -0,0 +1,81 @@
/**
********************************************************************
* @file apply_high_power.c
* @version V2.0.0
* @date 2019/9/20
* @brief
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "apply_high_power.h"
#include "stm32f4xx_hal.h"
/* Private constants ---------------------------------------------------------*/
#define HIGH_POWER_APPLY_PORT GPIOD
#define HIGH_POWER_APPLY_PIN GPIO_PIN_1
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_PsdkReturnCode PsdkTest_HighPowerApplyPinInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOD clock */
__HAL_RCC_GPIOD_CLK_ENABLE();
/* Configure pin as input floating */
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_PULLDOWN;
GPIO_InitStructure.Pin = HIGH_POWER_APPLY_PIN;
HAL_GPIO_Init(HIGH_POWER_APPLY_PORT, &GPIO_InitStructure);
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkTest_WriteHighPowerApplyPin(E_PsdkPowerManagementPinState pinState)
{
GPIO_PinState state;
switch (pinState) {
case PSDK_POWER_MANAGEMENT_PIN_STATE_RESET:
state = GPIO_PIN_RESET;
break;
case PSDK_POWER_MANAGEMENT_PIN_STATE_SET:
state = GPIO_PIN_SET;
break;
default:
PsdkLogger_UserLogError("pin state unknown: %d.", pinState);
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
HAL_GPIO_WritePin(HIGH_POWER_APPLY_PORT, HIGH_POWER_APPLY_PIN, state);
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,54 @@
/**
********************************************************************
* @file apply_high_power.h
* @version V2.0.0
* @date 2019/9/20
* @brief This is the header file for "apply_high_power.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef APPLY_HIGH_POWER_H
#define APPLY_HIGH_POWER_H
/* Includes ------------------------------------------------------------------*/
#include "psdk_core.h"
#include "psdk_power_management.h"
#include "psdk_logger.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_PsdkReturnCode PsdkTest_HighPowerApplyPinInit(void);
T_PsdkReturnCode PsdkTest_WriteHighPowerApplyPin(E_PsdkPowerManagementPinState pinState);
#ifdef __cplusplus
}
#endif
#endif // APPLY_HIGH_POWER_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,75 @@
/**
********************************************************************
* @file button.c
* @version V1.0.0
* @date 2019/01/01
* @brief
*
* @copyright (c) 2017-2018 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "button.h"
#include <stm32f4xx.h>
#include <stm32f4xx_hal_rcc_ex.h>
/* Private constants ---------------------------------------------------------*/
#define KEY1_BUTTON_PIN GPIO_PIN_15
#define KEY1_BUTTON_GPIO_PORT GPIOG
#define KEY1_BUTTON_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()
/* Private types -------------------------------------------------------------*/
#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__) do{ if((__INDEX__) == 0) KEY1_BUTTON_GPIO_CLK_ENABLE(); \
}while(0)
GPIO_TypeDef *BUTTON_PORT[BUTTON_NUM] = {KEY1_BUTTON_GPIO_PORT};
const uint16_t BUTTON_PIN[BUTTON_NUM] = {KEY1_BUTTON_PIN};
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
void Button_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* Enable the BUTTON clock */
BUTTONx_GPIO_CLK_ENABLE(Button);
if (Button_Mode == BUTTON_MODE_GPIO) {
/* Configure Button pin as input */
GPIO_InitStruct.Pin = BUTTON_PIN[Button];
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
}
}
uint32_t Button_GetState(Button_TypeDef Button)
{
return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,64 @@
/**
********************************************************************
* @file button.h
* @version V0.0.0
* @date 2019/01/01
* @brief This is the header file for "button.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2017-2018 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef BUTTON_H
#define BUTTON_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum
{
BUTTON_MODE_GPIO = 0,
}ButtonMode_TypeDef;
typedef enum
{
BUTTON_KEY1 = 0,
BUTTON_NUM = 1,
}Button_TypeDef;
/* Exported functions --------------------------------------------------------*/
void Button_Init(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode);
uint32_t Button_GetState(Button_TypeDef Button);
#ifdef __cplusplus
}
#endif
#endif // BUTTON_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,130 @@
/**
******************************************************************************
* @file dji_ringbuffer.c
* @version V1.0.0
* @date 2017/11/10
* @brief The file defines ring buffer related functions, including initialize, put data to buffer,
* get data from buffer and get unused count of bytes of buffer.
*
* @copyright (c) 2017-2018 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "dji_ringbuffer.h"
#include <string.h>
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
#define RINGBUF_MIN(a, b) (((a)<(b))?(a):(b))
/* Private variables ---------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Cut buffer size to power of 2, in order to increase the convenience of get and put operating of buffer.
* @param bufSize Original buffer size.
* @return Buffer size after handling.
*/
static uint16_t RingBuf_CutBufSizeToPowOfTwo(uint16_t bufSize)
{
uint16_t i = 0;
while ((1 << (++i)) <= bufSize);
return (uint16_t) (1 << (--i));
}
/* Exported functions --------------------------------------------------------*/
/**
* @brief Ring buffer initialization.
* @param pthis Pointer to ring buffer structure.
* @param pBuf Pointer to data buffer.
* @param bufSize Size of data buffer.
* @return None.
*/
void RingBuf_Init(T_RingBuffer *pthis, uint8_t *pBuf, uint16_t bufSize)
{
pthis->readIndex = 0;
pthis->writeIndex = 0;
pthis->bufferPtr = pBuf;
pthis->bufferSize = RingBuf_CutBufSizeToPowOfTwo(bufSize);
}
/**
* @brief Put a block of data into ring buffer.
* @param pthis Pointer to ring buffer structure.
* @param pData Pointer to data to be stored.
* @param dataLen Length of data to be stored.
* @return Length of data to be stored.
*/
uint16_t RingBuf_Put(T_RingBuffer *pthis, const uint8_t *pData, uint16_t dataLen)
{
uint16_t writeUpLen;
dataLen = RINGBUF_MIN(dataLen, (uint16_t) (pthis->bufferSize - pthis->writeIndex + pthis->readIndex));
//fill up data
writeUpLen = RINGBUF_MIN(dataLen, (uint16_t) (pthis->bufferSize - (pthis->writeIndex & (pthis->bufferSize - 1))));
memcpy(pthis->bufferPtr + (pthis->writeIndex & (pthis->bufferSize - 1)), pData, writeUpLen);
//fill begin data
memcpy(pthis->bufferPtr, pData + writeUpLen, dataLen - writeUpLen);
pthis->writeIndex += dataLen;
return dataLen;
}
/**
* @brief Get a block of data from ring buffer.
* @param pthis Pointer to ring buffer structure.
* @param pData Pointer to data to be read.
* @param dataLen Length of data to be read.
* @return Length of data to be read.
*/
uint16_t RingBuf_Get(T_RingBuffer *pthis, uint8_t *pData, uint16_t dataLen)
{
uint16_t readUpLen;
dataLen = RINGBUF_MIN(dataLen, (uint16_t) (pthis->writeIndex - pthis->readIndex));
//get up data
readUpLen = RINGBUF_MIN(dataLen, (uint16_t) (pthis->bufferSize - (pthis->readIndex & (pthis->bufferSize - 1))));
memcpy(pData, pthis->bufferPtr + (pthis->readIndex & (pthis->bufferSize - 1)), readUpLen);
//get begin data
memcpy(pData + readUpLen, pthis->bufferPtr, dataLen - readUpLen);
pthis->readIndex += dataLen;
return dataLen;
}
/**
* @brief Get unused size of ring buffer.
* @param pthis Pointer to ring buffer structure.
* @return Unused size of ring buffer.
*/
uint16_t RingBuf_GetUnusedSize(T_RingBuffer *pthis)
{
return (uint16_t) (pthis->bufferSize - pthis->writeIndex + pthis->readIndex);
}

View File

@ -0,0 +1,63 @@
/**
******************************************************************************
* @file dji_ringbuffer.h
* @version V1.0.0
* @date 2017/11/10
* @brief This is the header file for "dji_ringbuffer.c".
*
* @copyright (c) 2017-2018 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _DJI_RING_BUFFER_H_
#define _DJI_RING_BUFFER_H_
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
//Note: not need lock for just one producer / one consumer
//need mutex to protect for multi-producer / multi-consumer
typedef struct _ringBuffer {
uint8_t *bufferPtr;
uint16_t bufferSize;
uint16_t readIndex;
uint16_t writeIndex;
} T_RingBuffer;
/* Exported variables --------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
void RingBuf_Init(T_RingBuffer *pthis, uint8_t *pBuf, uint16_t bufSize);
uint16_t RingBuf_Put(T_RingBuffer *pthis, const uint8_t *pData, uint16_t dataLen);
uint16_t RingBuf_Get(T_RingBuffer *pthis, uint8_t *pData, uint16_t dataLen);
uint16_t RingBuf_GetUnusedSize(T_RingBuffer *pthis);
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#endif

View File

@ -0,0 +1,284 @@
/**
******************************************************************************
* @file IAP/IAP_Main/Src/flash_if.c
* @author MCD Application Team
* @brief This file provides all the memory related operation functions.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @statement DJI has modified some symbols' name.
*
******************************************************************************
*/
/** @addtogroup STM32F4xx_IAP_Main
* @{
*/
/* Includes ------------------------------------------------------------------*/
#include "flash_if.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static uint32_t GetSector(uint32_t Address);
/* Private functions ---------------------------------------------------------*/
/**
* @brief This function does an erase of all user flash area
* @param StartSector: start of user flash area
* @retval 0: user flash area successfully erased
* 1: error occurred
*/
uint32_t FLASH_If_Erase(uint32_t startAddress, uint32_t endAddress)
{
uint32_t startSector;
uint32_t endSector;
uint32_t SectorError;
FLASH_EraseInitTypeDef pEraseInit;
uint8_t sectorCount;
uint32_t ret;
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Clear pending flags (if any) */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
/* Get the sector where start the user flash area */
startSector = GetSector(startAddress);
endSector = GetSector(endAddress);
sectorCount = endSector - startSector + 1;
pEraseInit.TypeErase = TYPEERASE_SECTORS;
pEraseInit.Sector = startSector;
pEraseInit.NbSectors = sectorCount;
pEraseInit.VoltageRange = VOLTAGE_RANGE_3;
if (HAL_FLASHEx_Erase(&pEraseInit, &SectorError) != HAL_OK) {
/* Error occurred while page erase */
ret = FLASHIF_ERASE_ERROR;
goto out;
}
ret = FLASHIF_OK;
out:
HAL_FLASH_Lock();
return ret;
}
/**
* @brief This function writes a data buffer in flash (data are 32-bit aligned).
* @note After writing data buffer, the flash content is checked.
* @param FlashAddress: start address for writing data buffer
* @param Data: pointer on data buffer
* @param DataLength: length of data buffer
* @retval 0: Data successfully written to Flash memory
* 1: Error occurred while writing data in Flash memory
* 2: Written Data in flash memory is different from expected one
*/
uint32_t FLASH_If_Write(uint32_t FlashAddress, const uint8_t *Data, uint32_t DataLength)
{
uint32_t i = 0;
uint32_t dataLengthWord = DataLength / 4;
uint32_t writeAddress = FlashAddress;
uint32_t ret;
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Clear pending flags (if any) */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
for (i = 0; (i < dataLengthWord) && (writeAddress <= (FLASH_END_ADDRESS - 4)); i++) {
/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
be done by word */
if (HAL_FLASH_Program(TYPEPROGRAM_WORD, writeAddress, *(uint32_t *) (Data + 4 * i)) == HAL_OK) {
/* Check the written value */
if (*(uint32_t *) writeAddress != *(uint32_t *) (Data + 4 * i)) {
/* Flash content doesn't match SRAM content */
ret = FLASHIF_WRITINGCTRL_ERROR;
goto out;
}
/* Increment FLASH destination address */
writeAddress += 4;
} else {
/* Error occurred while writing data in Flash memory */
ret = FLASHIF_WRITING_ERROR;
goto out;
}
}
for (i = 0; i < DataLength % 4; i++) {
if (HAL_FLASH_Program(TYPEPROGRAM_BYTE, writeAddress,
*(uint8_t *) (Data + writeAddress - FlashAddress)) == HAL_OK) {
if (*(uint8_t *) writeAddress != *(uint8_t *) (Data + writeAddress - FlashAddress)) {
ret = FLASHIF_WRITINGCTRL_ERROR;
goto out;
}
writeAddress += 1;
} else {
ret = FLASHIF_WRITING_ERROR;
goto out;
}
}
ret = FLASHIF_OK;
out:
HAL_FLASH_Lock();
return ret;
}
/**
* @brief Returns the write protection status of user flash area.
* @param None
* @retval 0: No write protected sectors inside the user flash area
* 1: Some sectors inside the user flash area are write protected
*/
uint16_t FLASH_If_GetWriteProtectionStatus(void)
{
uint32_t ProtectedSECTOR = 0xFFF;
FLASH_OBProgramInitTypeDef OptionsBytesStruct;
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Check if there are write protected sectors inside the user flash area ****/
HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);
/* Lock the Flash to disable the flash control register access (recommended
to protect the FLASH memory against possible unwanted operation) *********/
HAL_FLASH_Lock();
/* Get pages already write protected ****************************************/
ProtectedSECTOR = ~(OptionsBytesStruct.WRPSector) & FLASH_SECTOR_TO_BE_PROTECTED;
/* Check if desired pages are already write protected ***********************/
if (ProtectedSECTOR != 0) {
/* Some sectors inside the user flash area are write protected */
return FLASHIF_PROTECTION_WRPENABLED;
} else {
/* No write protected sectors inside the user flash area */
return FLASHIF_PROTECTION_NONE;
}
}
/**
* @brief Gets the sector of a given address
* @param Address: Flash address
* @retval The sector of a given address
*/
static uint32_t GetSector(uint32_t Address)
{
uint32_t sector = 0;
if ((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0)) {
sector = FLASH_SECTOR_0;
} else if ((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1)) {
sector = FLASH_SECTOR_1;
} else if ((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2)) {
sector = FLASH_SECTOR_2;
} else if ((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3)) {
sector = FLASH_SECTOR_3;
} else if ((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4)) {
sector = FLASH_SECTOR_4;
} else if ((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5)) {
sector = FLASH_SECTOR_5;
} else if ((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6)) {
sector = FLASH_SECTOR_6;
} else if ((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7)) {
sector = FLASH_SECTOR_7;
} else if ((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8)) {
sector = FLASH_SECTOR_8;
} else if ((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9)) {
sector = FLASH_SECTOR_9;
} else if ((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10)) {
sector = FLASH_SECTOR_10;
} else /*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_11))*/
{
sector = FLASH_SECTOR_11;
}
return sector;
}
/**
* @brief Configure the write protection status of user flash area.
* @param modifier DISABLE or ENABLE the protection
* @retval HAL_StatusTypeDef HAL_OK if change is applied.
*/
HAL_StatusTypeDef FLASH_If_WriteProtectionConfig(uint32_t modifier)
{
uint32_t ProtectedSECTOR = 0xFFF;
FLASH_OBProgramInitTypeDef config_new, config_old;
HAL_StatusTypeDef result = HAL_OK;
/* Get pages write protection status ****************************************/
HAL_FLASHEx_OBGetConfig(&config_old);
/* The parameter says whether we turn the protection on or off */
config_new.WRPState = modifier;
/* We want to modify only the Write protection */
config_new.OptionType = OPTIONBYTE_WRP;
/* No read protection, keep BOR and reset settings */
config_new.RDPLevel = OB_RDP_LEVEL_0;
config_new.USERConfig = config_old.USERConfig;
/* Get pages already write protected ****************************************/
ProtectedSECTOR = config_old.WRPSector | FLASH_SECTOR_TO_BE_PROTECTED;
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Unlock the Options Bytes *************************************************/
HAL_FLASH_OB_Unlock();
config_new.WRPSector = ProtectedSECTOR;
result = HAL_FLASHEx_OBProgram(&config_new);
return result;
}
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,119 @@
/**
******************************************************************************
* @file IAP/IAP_Main/Inc/flash_if.h
* @author MCD Application Team
* @brief This file provides all the headers of the flash_if functions.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics International N.V.
* All rights reserved.</center></h2>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted, provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of other
* contributors to this software may be used to endorse or promote products
* derived from this software without specific written permission.
* 4. This software, including modifications and/or derivative works of this
* software, must execute solely and exclusively on microcontroller or
* microprocessor devices manufactured by or for STMicroelectronics.
* 5. Redistribution and use of this software other than as permitted under
* this license is void and will automatically terminate your rights under
* this license.
*
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @statement DJI has modified some symbols' name.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FLASH_IF_H
#define __FLASH_IF_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Base address of the Flash sectors */
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbyte */
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbyte */
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbyte */
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbyte */
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbyte */
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbyte */
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbyte */
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbyte */
#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbyte */
#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbyte */
#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbyte */
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbyte */
/* Error code */
enum {
FLASHIF_OK = 0,
FLASHIF_ERASE_ERROR,
FLASHIF_WRITINGCTRL_ERROR,
FLASHIF_WRITING_ERROR
};
enum {
FLASHIF_PROTECTION_NONE = 0,
FLASHIF_PROTECTION_PCROPENABLED = 0x1,
FLASHIF_PROTECTION_WRPENABLED = 0x2,
FLASHIF_PROTECTION_RDPENABLED = 0x4,
};
/* End of the Flash address */
#define FLASH_END_ADDRESS 0x080FFFFF
/* Define the address from where user application will be loaded.
Note: the 1st sector 0x08000000-0x08007FFF is reserved for the IAP code */
#define APPLICATION_ADDRESS ADDR_FLASH_SECTOR_4
#define APPLICATION_ADDRESS_END (ADDR_FLASH_SECTOR_8 - 1)
/* Define the user application size */
#define APPLICATION_FLASH_SIZE (APPLICATION_ADDRESS_END - APPLICATION_ADDRESS + 1)
/* Define the address from where user application will be stored in upgrade mode */
#define APPLICATION_STORE_ADDRESS ADDR_FLASH_SECTOR_8
#define APPLICATION_STORE_ADDRESS_END (FLASH_END_ADDRESS)
/* Define the address for param store */
#define APPLICATION_PARAM_STORE_ADDRESS ADDR_FLASH_SECTOR_2
#define APPLICATION_PARAM_STORE_ADDRESS_END (ADDR_FLASH_SECTOR_4 - 1)
/* Define bitmap representing user flash area that could be write protected (check restricted to pages 8-39). */
#define FLASH_SECTOR_TO_BE_PROTECTED (OB_WRP_SECTOR_0 | OB_WRP_SECTOR_1 | OB_WRP_SECTOR_2 | OB_WRP_SECTOR_3 |\
OB_WRP_SECTOR_4 | OB_WRP_SECTOR_5 | OB_WRP_SECTOR_6 | OB_WRP_SECTOR_7 |\
OB_WRP_SECTOR_8 | OB_WRP_SECTOR_9 | OB_WRP_SECTOR_10 | OB_WRP_SECTOR_11 )
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void FLASH_If_Init(void);
uint32_t FLASH_If_Erase(uint32_t StartAddress, uint32_t endAddress);
uint32_t FLASH_If_Write(uint32_t FlashAddress, const uint8_t *Data, uint32_t DataLength);
uint16_t FLASH_If_GetWriteProtectionStatus(void);
HAL_StatusTypeDef FLASH_If_WriteProtectionConfig(uint32_t modifier);
#endif /* __FLASH_IF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,102 @@
/**
********************************************************************
* @file pps.c
* @version V2.0.0
* @date 2019/9/20
* @brief
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
#include "pps.h"
#include "osal/osal.h"
#include "stdio.h"
/* Private constants ---------------------------------------------------------*/
#define PPS_PORT GPIOD
#define PPS_PIN GPIO_PIN_2
#define PPS_IRQn EXTI2_IRQn
#define PsdkTest_PpsIrqHandler EXTI2_IRQHandler
#define PPS_IRQ_PRIO_PRE 0x0F
#define PPS_IRQ_PRIO_SUB 0x0F
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static uint32_t s_ppsNewestTriggerLocalTimeMs = 0;
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
void PsdkTest_PpsIrqHandler(void)
{
T_PsdkReturnCode psdkStat;
uint32_t timeMs = 0;
/* EXTI line interrupt detected */
if (__HAL_GPIO_EXTI_GET_IT(PPS_PIN) != RESET) {
__HAL_GPIO_EXTI_CLEAR_IT(PPS_PIN);
psdkStat = Osal_GetTimeMs(&timeMs);
if (psdkStat == PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
s_ppsNewestTriggerLocalTimeMs = timeMs;
}
}
T_PsdkReturnCode PsdkTest_GetNewestPpsTriggerLocalTimeUs(uint64_t *localTimeUs)
{
if (localTimeUs == NULL) {
PsdkLogger_UserLogError("input pointer is null.");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (s_ppsNewestTriggerLocalTimeMs == 0) {
PsdkLogger_UserLogWarn("pps have not been triggered.");
return PSDK_ERROR_SYSTEM_MODULE_CODE_BUSY;
}
*localTimeUs = s_ppsNewestTriggerLocalTimeMs * 1000;
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkTest_PpsSignalResponseInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIOD clock */
__HAL_RCC_GPIOD_CLK_ENABLE();
/* Configure pin as input floating */
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Pin = PPS_PIN;
HAL_GPIO_Init(PPS_PORT, &GPIO_InitStructure);
/* Enable and set EXTI Line0 Interrupt to the lowest priority */
HAL_NVIC_SetPriority(PPS_IRQn, PPS_IRQ_PRIO_PRE, PPS_IRQ_PRIO_SUB);
HAL_NVIC_EnableIRQ(PPS_IRQn);
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,53 @@
/**
********************************************************************
* @file pps.h
* @version V2.0.0
* @date 2019/9/20
* @brief This is the header file for "pps.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef PPS_H
#define PPS_H
/* Includes ------------------------------------------------------------------*/
#include "psdk_core.h"
#include "psdk_logger.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_PsdkReturnCode PsdkTest_GetNewestPpsTriggerLocalTimeUs(uint64_t *localTimeUs);
T_PsdkReturnCode PsdkTest_PpsSignalResponseInit(void);
#ifdef __cplusplus
}
#endif
#endif // PPS_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,104 @@
/**
******************************************************************************
* @file IO_Toggle/stm32f4xx_conf.h
* @author MCD Application Team
* @version V1.0.0
* @date 19-September-2011
* @brief Library configuration file.
******************************************************************************
* @attention
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F4xx_CONF_H
#define __STM32F4xx_CONF_H
//NOTE : HSE VALUE Define in toolchains, maybe MDK or arm-gcc
//#if defined (HSE_VALUE)
///* Redefine the HSE value; it's equal to 12 MHz on the demo Kit */
// #undef HSE_VALUE
// #define HSE_VALUE ((uint32_t)12000000)
//#endif /* HSE_VALUE */
/* Includes ------------------------------------------------------------------*/
/* Uncomment the line below to enable peripheral header file inclusion */
#include "stm32f4xx_adc.h"
#include "stm32f4xx_can.h"
#include "stm32f4xx_crc.h"
#include "stm32f4xx_cryp.h"
#include "stm32f4xx_dac.h"
#include "stm32f4xx_dbgmcu.h"
#include "stm32f4xx_dcmi.h"
#include "stm32f4xx_dma.h"
#include "stm32f4xx_exti.h"
#include "stm32f4xx_flash.h"
#include "stm32f4xx_fsmc.h"
#include "stm32f4xx_hash.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_iwdg.h"
#include "stm32f4xx_pwr.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_rng.h"
#include "stm32f4xx_rtc.h"
#include "stm32f4xx_sdio.h"
#include "stm32f4xx_spi.h"
#include "stm32f4xx_syscfg.h"
#include "stm32f4xx_tim.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx_wwdg.h"
#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported variables --------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/* If an external clock source is used, then the value of the following define
should be set to the value of the external clock source, else, if no external
clock is used, keep this define commented */
/*#define I2S_EXTERNAL_CLOCK_VAL 12288000 */ /* Value of the external clock in Hz */
/* Uncomment the line below to expanse the "assert_param" macro in the
Standard Peripheral Library drivers code */
//#define USE_FULL_ASSERT 1
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#endif /* __STM32F4xx_CONF_H */
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,413 @@
/**
******************************************************************************
* @file UART/UART_TwoBoards_ComIT/Inc/stm32f4xx_hal_conf.h
* @author MCD Application Team
* @brief HAL configuration file
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F4xx_HAL_CONF_H
#define __STM32F4xx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
/* #define HAL_ADC_MODULE_ENABLED */
/* #define HAL_CAN_MODULE_ENABLED */
/* #define HAL_CAN_LEGACY_MODULE_ENABLED */
/* #define HAL_CRC_MODULE_ENABLED */
/* #define HAL_CRYP_MODULE_ENABLED */
/* #define HAL_DAC_MODULE_ENABLED */
/* #define HAL_DCMI_MODULE_ENABLED */
#define HAL_DMA_MODULE_ENABLED
/* #define HAL_DMA2D_MODULE_ENABLED */
/* #define HAL_ETH_MODULE_ENABLED */
#define HAL_FLASH_MODULE_ENABLED
/* #define HAL_NAND_MODULE_ENABLED */
/* #define HAL_NOR_MODULE_ENABLED */
/* #define HAL_PCCARD_MODULE_ENABLED */
/* #define HAL_SRAM_MODULE_ENABLED */
/* #define HAL_SDRAM_MODULE_ENABLED */
/* #define HAL_HASH_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
/*#define HAL_I2C_MODULE_ENABLED*/
/* #define HAL_I2S_MODULE_ENABLED */
/* #define HAL_IWDG_MODULE_ENABLED */
/* #define HAL_LTDC_MODULE_ENABLED */
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
/* #define HAL_RNG_MODULE_ENABLED */
#define HAL_RTC_MODULE_ENABLED
/* #define HAL_SAI_MODULE_ENABLED */
/* #define HAL_SD_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */
/* #define HAL_TIM_MODULE_ENABLED */
#define HAL_UART_MODULE_ENABLED
#define HAL_USART_MODULE_ENABLED
/* #define HAL_IRDA_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */
/* #define HAL_WWDG_MODULE_ENABLED */
#define HAL_CORTEX_MODULE_ENABLED
/* #define HAL_PCD_MODULE_ENABLED */
/* #define HAL_HCD_MODULE_ENABLED */
/* ########################## HSE/HSI Values adaptation ##################### */
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE (8000000U) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT (100U) /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE (16000000U) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
#define LSI_VALUE (32000U)
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature. */
/**
* @brief External Low Speed oscillator (LSE) value.
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE (32768U) /*!< Value of the External Low Speed oscillator in Hz */
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT (5000U) /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */
/**
* @brief External clock source for I2S peripheral
* This value is used by the I2S HAL module to compute the I2S clock source
* frequency, this source is inserted directly through I2S_CKIN pad.
*/
#if !defined (EXTERNAL_CLOCK_VALUE)
#define EXTERNAL_CLOCK_VALUE (12288000U) /*!< Value of the External oscillator in Hz*/
#endif /* EXTERNAL_CLOCK_VALUE */
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE (3300U) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY (0x0FU) /*!< tick interrupt priority */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 0U /* The prefetch will be enabled in SystemClock_Config(), depending on the used
STM32F405/415/07/417 device: RevA (prefetch must be off) or RevZ (prefetch can be on/off) */
#define INSTRUCTION_CACHE_ENABLE 1U
#define DATA_CACHE_ENABLE 1U
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */
#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U /* DFSDM register callback disabled */
#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */
#define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
#define USE_HAL_FMPI2C_REGISTER_CALLBACKS 0U /* FMPI2C register callback disabled */
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */
#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U /* QSPI register callback disabled */
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */
#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
#define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
#define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1U */
/* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver
*/
#define USE_SPI_CRC 1U
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32f4xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32f4xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32f4xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32f4xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32f4xx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_CAN_MODULE_ENABLED
#include "stm32f4xx_hal_can.h"
#endif /* HAL_CAN_MODULE_ENABLED */
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
#include "stm32f4xx_hal_can_legacy.h"
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32f4xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_CRYP_MODULE_ENABLED
#include "stm32f4xx_hal_cryp.h"
#endif /* HAL_CRYP_MODULE_ENABLED */
#ifdef HAL_DMA2D_MODULE_ENABLED
#include "stm32f4xx_hal_dma2d.h"
#endif /* HAL_DMA2D_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32f4xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_DCMI_MODULE_ENABLED
#include "stm32f4xx_hal_dcmi.h"
#endif /* HAL_DCMI_MODULE_ENABLED */
#ifdef HAL_ETH_MODULE_ENABLED
#include "stm32f4xx_hal_eth.h"
#endif /* HAL_ETH_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32f4xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_SRAM_MODULE_ENABLED
#include "stm32f4xx_hal_sram.h"
#endif /* HAL_SRAM_MODULE_ENABLED */
#ifdef HAL_NOR_MODULE_ENABLED
#include "stm32f4xx_hal_nor.h"
#endif /* HAL_NOR_MODULE_ENABLED */
#ifdef HAL_NAND_MODULE_ENABLED
#include "stm32f4xx_hal_nand.h"
#endif /* HAL_NAND_MODULE_ENABLED */
#ifdef HAL_PCCARD_MODULE_ENABLED
#include "stm32f4xx_hal_pccard.h"
#endif /* HAL_PCCARD_MODULE_ENABLED */
#ifdef HAL_SDRAM_MODULE_ENABLED
#include "stm32f4xx_hal_sdram.h"
#endif /* HAL_SDRAM_MODULE_ENABLED */
#ifdef HAL_HASH_MODULE_ENABLED
#include "stm32f4xx_hal_hash.h"
#endif /* HAL_HASH_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32f4xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED
#include "stm32f4xx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32f4xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_LTDC_MODULE_ENABLED
#include "stm32f4xx_hal_ltdc.h"
#endif /* HAL_LTDC_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32f4xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_RNG_MODULE_ENABLED
#include "stm32f4xx_hal_rng.h"
#endif /* HAL_RNG_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32f4xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SAI_MODULE_ENABLED
#include "stm32f4xx_hal_sai.h"
#endif /* HAL_SAI_MODULE_ENABLED */
#ifdef HAL_SD_MODULE_ENABLED
#include "stm32f4xx_hal_sd.h"
#endif /* HAL_SD_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32f4xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32f4xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32f4xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32f4xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32f4xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32f4xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32f4xx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32f4xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_HCD_MODULE_ENABLED
#include "stm32f4xx_hal_hcd.h"
#endif /* HAL_HCD_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* __STM32F4xx_HAL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,276 @@
/**
******************************************************************************
* @file UART/UART_TwoBoards_ComIT/Src/stm32f4xx_hal_msp.c
* @author MCD Application Team
* @brief HAL MSP module.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
/** @addtogroup STM32F4xx_HAL_Examples
* @{
*/
/** @defgroup UART_TwoBoards_ComIT
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
//USART1
#define USART1_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define USART1_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
#define USART1_FORCE_RESET() __HAL_RCC_USART1_FORCE_RESET()
#define USART1_RELEASE_RESET() __HAL_RCC_USART1_RELEASE_RESET()
/* Definition for USART1 Pins */
#define USART1_TX_PIN GPIO_PIN_6
#define USART1_TX_GPIO_PORT GPIOB
#define USART1_TX_AF GPIO_AF7_USART1
#define USART1_RX_PIN GPIO_PIN_7
#define USART1_RX_GPIO_PORT GPIOB
#define USART1_RX_AF GPIO_AF7_USART1
#define USART1_IRQ_PRIO_PRE 5
#define USART1_IRQ_PRIO_SUB 0
//USART2
#define USART2_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART2_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOA_CLK_ENABLE()
#define USART2_FORCE_RESET() __HAL_RCC_USART2_FORCE_RESET()
#define USART2_RELEASE_RESET() __HAL_RCC_USART2_RELEASE_RESET()
/* Definition for USART2 Pins */
#define USART2_TX_PIN GPIO_PIN_2
#define USART2_TX_GPIO_PORT GPIOA
#define USART2_TX_AF GPIO_AF7_USART2
#define USART2_RX_PIN GPIO_PIN_3
#define USART2_RX_GPIO_PORT GPIOA
#define USART2_RX_AF GPIO_AF7_USART2
#define USART2_IRQ_PRIO_PRE 5
#define USART2_IRQ_PRIO_SUB 0
//USART3
#define USART3_RX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define USART3_TX_GPIO_CLK_ENABLE() __HAL_RCC_GPIOC_CLK_ENABLE()
#define USART3_FORCE_RESET() __HAL_RCC_USART3_FORCE_RESET()
#define USART3_RELEASE_RESET() __HAL_RCC_USART3_RELEASE_RESET()
/* Definition for USART3 Pins */
#define USART3_TX_PIN GPIO_PIN_10
#define USART3_TX_GPIO_PORT GPIOC
#define USART3_TX_AF GPIO_AF7_USART3
#define USART3_RX_PIN GPIO_PIN_11
#define USART3_RX_GPIO_PORT GPIOC
#define USART3_RX_AF GPIO_AF7_USART3
#define USART3_IRQ_PRIO_PRE 5
#define USART3_IRQ_PRIO_SUB 0
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/** @defgroup HAL_MSP_Private_Functions
* @{
*/
/**
* @brief UART MSP Initialization
* This function configures the hardware resources used in this example:
* - Peripheral's clock enable
* - Peripheral's GPIO Configuration
* - NVIC configuration for UART interrupt request enable
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
GPIO_InitTypeDef GPIO_InitStruct;
if (huart->Instance == USART1) {
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* Enable GPIO TX/RX clock */
USART1_TX_GPIO_CLK_ENABLE();
USART1_RX_GPIO_CLK_ENABLE();
/* Enable USART clock */
__HAL_RCC_USART1_CLK_ENABLE();
/*##-2- Configure peripheral GPIO ##########################################*/
/* UART TX GPIO pin configuration */
GPIO_InitStruct.Pin = USART1_TX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Alternate = USART1_TX_AF;
HAL_GPIO_Init(USART1_TX_GPIO_PORT, &GPIO_InitStruct);
/* UART RX GPIO pin configuration */
GPIO_InitStruct.Pin = USART1_RX_PIN;
GPIO_InitStruct.Alternate = USART1_RX_AF;
HAL_GPIO_Init(USART1_RX_GPIO_PORT, &GPIO_InitStruct);
/*##-3- Configure the NVIC for UART ########################################*/
/* NVIC for USART1 */
HAL_NVIC_SetPriority(USART1_IRQn, USART1_IRQ_PRIO_PRE, USART1_IRQ_PRIO_SUB);
HAL_NVIC_EnableIRQ(USART1_IRQn);
} else if (huart->Instance == USART2) {
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* Enable GPIO TX/RX clock */
USART2_TX_GPIO_CLK_ENABLE();
USART2_RX_GPIO_CLK_ENABLE();
/* Enable USART clock */
__HAL_RCC_USART2_CLK_ENABLE();
/*##-2- Configure peripheral GPIO ##########################################*/
/* UART TX GPIO pin configuration */
GPIO_InitStruct.Pin = USART2_TX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Alternate = USART2_TX_AF;
HAL_GPIO_Init(USART2_TX_GPIO_PORT, &GPIO_InitStruct);
/* UART RX GPIO pin configuration */
GPIO_InitStruct.Pin = USART2_RX_PIN;
GPIO_InitStruct.Alternate = USART2_RX_AF;
HAL_GPIO_Init(USART2_RX_GPIO_PORT, &GPIO_InitStruct);
/*##-3- Configure the NVIC for UART ########################################*/
/* NVIC for USART2 */
HAL_NVIC_SetPriority(USART2_IRQn, USART2_IRQ_PRIO_PRE, USART2_IRQ_PRIO_SUB);
HAL_NVIC_EnableIRQ(USART2_IRQn);
} else if (huart->Instance == USART3) {
/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* Enable GPIO TX/RX clock */
USART3_TX_GPIO_CLK_ENABLE();
USART3_RX_GPIO_CLK_ENABLE();
/* Enable USART clock */
__HAL_RCC_USART3_CLK_ENABLE();
/*##-2- Configure peripheral GPIO ##########################################*/
/* UART TX GPIO pin configuration */
GPIO_InitStruct.Pin = USART3_TX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
GPIO_InitStruct.Alternate = USART3_TX_AF;
HAL_GPIO_Init(USART3_TX_GPIO_PORT, &GPIO_InitStruct);
/* UART RX GPIO pin configuration */
GPIO_InitStruct.Pin = USART3_RX_PIN;
GPIO_InitStruct.Alternate = USART3_RX_AF;
HAL_GPIO_Init(USART3_RX_GPIO_PORT, &GPIO_InitStruct);
/*##-3- Configure the NVIC for UART ########################################*/
/* NVIC for USART3 */
HAL_NVIC_SetPriority(USART3_IRQn, USART3_IRQ_PRIO_PRE, USART3_IRQ_PRIO_SUB);
HAL_NVIC_EnableIRQ(USART3_IRQn);
}
}
/**
* @brief UART MSP De-Initialization
* This function frees the hardware resources used in this example:
* - Disable the Peripheral's clock
* - Revert GPIO and NVIC configuration to their default state
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
{
if (huart->Instance == USART1) {
/*##-1- Reset peripherals ##################################################*/
USART1_FORCE_RESET();
USART1_RELEASE_RESET();
/*##-2- Disable peripherals and GPIO Clocks #################################*/
/* Configure UART Tx as alternate function */
HAL_GPIO_DeInit(USART1_TX_GPIO_PORT, USART1_TX_PIN);
/* Configure UART Rx as alternate function */
HAL_GPIO_DeInit(USART1_RX_GPIO_PORT, USART1_RX_PIN);
/*##-3- Disable the NVIC for UART ##########################################*/
HAL_NVIC_DisableIRQ(USART1_IRQn);
} else if (huart->Instance == USART2) {
/*##-1- Reset peripherals ##################################################*/
USART2_FORCE_RESET();
USART2_RELEASE_RESET();
/*##-2- Disable peripherals and GPIO Clocks #################################*/
/* Configure UART Tx as alternate function */
HAL_GPIO_DeInit(USART2_TX_GPIO_PORT, USART2_TX_PIN);
/* Configure UART Rx as alternate function */
HAL_GPIO_DeInit(USART2_RX_GPIO_PORT, USART2_RX_PIN);
/*##-3- Disable the NVIC for UART ##########################################*/
HAL_NVIC_DisableIRQ(USART2_IRQn);
} else if (huart->Instance == USART3) {
/*##-1- Reset peripherals ##################################################*/
USART3_FORCE_RESET();
USART3_RELEASE_RESET();
/*##-2- Disable peripherals and GPIO Clocks #################################*/
/* Configure UART Tx as alternate function */
HAL_GPIO_DeInit(USART3_TX_GPIO_PORT, USART3_TX_PIN);
/* Configure UART Rx as alternate function */
HAL_GPIO_DeInit(USART3_RX_GPIO_PORT, USART3_RX_PIN);
/*##-3- Disable the NVIC for UART ##########################################*/
HAL_NVIC_DisableIRQ(USART3_IRQn);
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,154 @@
/**
******************************************************************************
* @file UART/UART_TwoBoards_ComIT/Src/stm32f4xx_it.c
* @author MCD Application Team
* @brief Main Interrupt Service Routines.
* This file provides template for all exceptions handler and
* peripherals interrupt service routine.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "FreeRTOSConfig.h"
#include "stm32f4xx_it.h"
#include "stm32f4xx_hal.h"
#include "FreeRTOS.h"
#include "task.h"
/** @addtogroup STM32F4xx_HAL_Examples
* @{
*/
/** @addtogroup UART_TwoBoards_ComIT
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/******************************************************************************/
/* Cortex-M4 Processor Exceptions Handlers */
/******************************************************************************/
/**
* @brief This function handles NMI exception.
* @param None
* @retval None
*/
void NMI_Handler(void)
{
}
/**
* @brief This function handles Hard Fault exception.
* @param None
* @retval None
*/
void HardFault_Handler(void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1) {
}
}
/**
* @brief This function handles Memory Manage exception.
* @param None
* @retval None
*/
void MemManage_Handler(void)
{
/* Go to infinite loop when Memory Manage exception occurs */
while (1) {
}
}
/**
* @brief This function handles Bus Fault exception.
* @param None
* @retval None
*/
void BusFault_Handler(void)
{
/* Go to infinite loop when Bus Fault exception occurs */
while (1) {
}
}
/**
* @brief This function handles Usage Fault exception.
* @param None
* @retval None
*/
void UsageFault_Handler(void)
{
/* Go to infinite loop when Usage Fault exception occurs */
while (1) {
}
}
/**
* @brief This function handles Debug Monitor exception.
* @param None
* @retval None
*/
void DebugMon_Handler(void)
{
}
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
#if (INCLUDE_xTaskGetSchedulerState == 1)
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
#endif /* INCLUDE_xTaskGetSchedulerState */
xPortSysTickHandler();
#if (INCLUDE_xTaskGetSchedulerState == 1)
}
#endif /* INCLUDE_xTaskGetSchedulerState */
}
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,68 @@
/**
******************************************************************************
* @file UART/UART_TwoBoards_ComIT/Inc/stm32f4xx_it.h
* @author MCD Application Team
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F4xx_IT_H
#define __STM32F4xx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void DebugMon_Handler(void);
void SysTick_Handler(void);
extern void xPortSysTickHandler(void);
#ifdef __cplusplus
}
#endif
#endif /* __STM32F4xx_IT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -0,0 +1,421 @@
/**
******************************************************************************
* @file uart.c
* @version V1.0.0
* @date 2017/11/10
* @brief The file define UART interface driver functions.
*
* @copyright (c) 2017-2018 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "uart.h"
#include "stm32f4xx_hal.h"
#include "dji_ringbuffer.h"
#include "FreeRTOS.h"
#include "osal/osal.h"
#include "task.h"
#include "utils/util_misc.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
//uart uart buffer size define
#define UART1_READ_BUF_SIZE 1024
#define UART1_WRITE_BUF_SIZE 1024
#define UART2_READ_BUF_SIZE 1024
#define UART2_WRITE_BUF_SIZE 4096
#define UART3_READ_BUF_SIZE 2048
#define UART3_WRITE_BUF_SIZE 2048
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
#ifdef USING_UART_PORT_1
//UART1 read ring buffer structure
static T_RingBuffer s_uart1ReadRingBuffer;
//USART1 read buffer state
static T_UartBufferState s_uart1ReadBufferState;
//UART1 write ring buffer structure
static T_RingBuffer s_uart1WriteRingBuffer;
//USART1 write buffer state
static T_UartBufferState s_uart1WriteBufferState;
//UART1 read buffer
static uint8_t s_uart1ReadBuf[UART1_READ_BUF_SIZE];
//UART1 write buffer
static uint8_t s_uart1WriteBuf[UART1_WRITE_BUF_SIZE];
//UART1 mutex
static T_PsdkMutexHandle s_uart1Mutex;
//USART1 handle
static UART_HandleTypeDef s_uart1Handle;
#endif
#ifdef USING_UART_PORT_2
static T_RingBuffer s_uart2ReadRingBuffer;
static T_UartBufferState s_uart2ReadBufferState;
static T_RingBuffer s_uart2WriteRingBuffer;
static T_UartBufferState s_uart2WriteBufferState;
static uint8_t s_uart2ReadBuf[UART2_READ_BUF_SIZE];
static uint8_t s_uart2WriteBuf[UART2_WRITE_BUF_SIZE];
static T_PsdkMutexHandle s_uart2Mutex;
static UART_HandleTypeDef s_uart2Handle;
#endif
#ifdef USING_UART_PORT_3
static T_RingBuffer s_uart3ReadRingBuffer;
static T_UartBufferState s_uart3ReadBufferState;
static T_RingBuffer s_uart3WriteRingBuffer;
static T_UartBufferState s_uart3WriteBufferState;
static uint8_t s_uart3ReadBuf[UART3_READ_BUF_SIZE];
static uint8_t s_uart3WriteBuf[UART3_WRITE_BUF_SIZE];
static T_PsdkMutexHandle s_uart3Mutex;
static UART_HandleTypeDef s_uart3Handle;
#endif
/* Exported variables --------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/**
* @brief UART initialization function.
* @param uartNum UART number to be initialized.
* @param baudRate UART baudrate.
* @return None.
*/
void UART_Init(E_UartNum uartNum, uint32_t baudRate)
{
switch (uartNum) {
#ifdef USING_UART_PORT_1
case UART_NUM_1: {
RingBuf_Init(&s_uart1ReadRingBuffer, s_uart1ReadBuf, UART1_READ_BUF_SIZE);
RingBuf_Init(&s_uart1WriteRingBuffer, s_uart1WriteBuf, UART1_WRITE_BUF_SIZE);
s_uart1Handle.Instance = USART1;
s_uart1Handle.Init.BaudRate = baudRate;
s_uart1Handle.Init.WordLength = UART_WORDLENGTH_8B;
s_uart1Handle.Init.StopBits = UART_STOPBITS_1;
s_uart1Handle.Init.Parity = UART_PARITY_NONE;
s_uart1Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
s_uart1Handle.Init.Mode = UART_MODE_TX_RX;
s_uart1Handle.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&s_uart1Handle);
__HAL_UART_ENABLE_IT(&s_uart1Handle, UART_IT_RXNE);
Osal_MutexCreate(&s_uart1Mutex);
}
break;
#endif
#ifdef USING_UART_PORT_2
case UART_NUM_2: {
RingBuf_Init(&s_uart2ReadRingBuffer, s_uart2ReadBuf, UART2_READ_BUF_SIZE);
RingBuf_Init(&s_uart2WriteRingBuffer, s_uart2WriteBuf, UART2_WRITE_BUF_SIZE);
s_uart2Handle.Instance = USART2;
s_uart2Handle.Init.BaudRate = baudRate;
s_uart2Handle.Init.WordLength = UART_WORDLENGTH_8B;
s_uart2Handle.Init.StopBits = UART_STOPBITS_1;
s_uart2Handle.Init.Parity = UART_PARITY_NONE;
s_uart2Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
s_uart2Handle.Init.Mode = UART_MODE_TX_RX;
s_uart2Handle.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&s_uart2Handle);
__HAL_UART_ENABLE_IT(&s_uart2Handle, UART_IT_RXNE);
Osal_MutexCreate(&s_uart2Mutex);
}
break;
#endif
#ifdef USING_UART_PORT_3
case UART_NUM_3: {
RingBuf_Init(&s_uart3ReadRingBuffer, s_uart3ReadBuf, UART3_READ_BUF_SIZE);
RingBuf_Init(&s_uart3WriteRingBuffer, s_uart3WriteBuf, UART3_WRITE_BUF_SIZE);
s_uart3Handle.Instance = USART3;
s_uart3Handle.Init.BaudRate = baudRate;
s_uart3Handle.Init.WordLength = UART_WORDLENGTH_8B;
s_uart3Handle.Init.StopBits = UART_STOPBITS_1;
s_uart3Handle.Init.Parity = UART_PARITY_NONE;
s_uart3Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
s_uart3Handle.Init.Mode = UART_MODE_TX_RX;
s_uart3Handle.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&s_uart3Handle);
__HAL_UART_ENABLE_IT(&s_uart3Handle, UART_IT_RXNE);
Osal_MutexCreate(&s_uart3Mutex);
}
break;
#endif
default:
break;
}
}
/**
* @brief Read UART data.
* @param uartNum UART number.
* @param buf Pointer to buffer used to store data.
* @param readSize Size of data to be read.
* @return Size of data read actually.
*/
int UART_Read(E_UartNum uartNum, uint8_t *buf, uint16_t readSize)
{
uint16_t readRealSize;
switch (uartNum) {
#ifdef USING_UART_PORT_1
case UART_NUM_1: {
Osal_MutexLock(s_uart1Mutex);
readRealSize = RingBuf_Get(&s_uart1ReadRingBuffer, buf, readSize);
Osal_MutexUnlock(s_uart1Mutex);
}
break;
#endif
#ifdef USING_UART_PORT_2
case UART_NUM_2: {
Osal_MutexLock(s_uart2Mutex);
readRealSize = RingBuf_Get(&s_uart2ReadRingBuffer, buf, readSize);
Osal_MutexUnlock(s_uart2Mutex);
}
break;
#endif
#ifdef USING_UART_PORT_3
case UART_NUM_3: {
Osal_MutexLock(s_uart3Mutex);
readRealSize = RingBuf_Get(&s_uart3ReadRingBuffer, buf, readSize);
Osal_MutexUnlock(s_uart3Mutex);
}
break;
#endif
default:
return UART_ERROR;
}
return readRealSize;
}
/**
* @brief Write UART data.
* @param uartNum UART number.
* @param buf Pointer to buffer used to store data.
* @param writeSize Size of data to be write.
* @return Size of data wrote actually.
*/
int UART_Write(E_UartNum uartNum, const uint8_t *buf, uint16_t writeSize)
{
int writeRealLen;
uint16_t usedCapacityOfBuffer = 0;
switch (uartNum) {
#ifdef USING_UART_PORT_1
case UART_NUM_1: {
Osal_MutexLock(s_uart1Mutex);
writeRealLen = RingBuf_Put(&s_uart1WriteRingBuffer, buf, writeSize);
__HAL_USART_ENABLE_IT(&s_uart1Handle, USART_IT_TXE);
usedCapacityOfBuffer = UART1_WRITE_BUF_SIZE - RingBuf_GetUnusedSize(&s_uart1WriteRingBuffer);
s_uart1WriteBufferState.maxUsedCapacityOfBuffer =
usedCapacityOfBuffer > s_uart1WriteBufferState.maxUsedCapacityOfBuffer ? usedCapacityOfBuffer
: s_uart1WriteBufferState.maxUsedCapacityOfBuffer;
s_uart1WriteBufferState.countOfLostData += writeSize - writeRealLen;
Osal_MutexUnlock(s_uart1Mutex);
}
break;
#endif
#ifdef USING_UART_PORT_2
case UART_NUM_2: {
Osal_MutexLock(s_uart2Mutex);
writeRealLen = RingBuf_Put(&s_uart2WriteRingBuffer, buf, writeSize);
__HAL_USART_ENABLE_IT(&s_uart2Handle, USART_IT_TXE);
usedCapacityOfBuffer = UART2_WRITE_BUF_SIZE - RingBuf_GetUnusedSize(&s_uart2WriteRingBuffer);
s_uart2WriteBufferState.maxUsedCapacityOfBuffer =
usedCapacityOfBuffer > s_uart2WriteBufferState.maxUsedCapacityOfBuffer ? usedCapacityOfBuffer
: s_uart2WriteBufferState.maxUsedCapacityOfBuffer;
s_uart2WriteBufferState.countOfLostData += writeSize - writeRealLen;
Osal_MutexUnlock(s_uart2Mutex);
}
break;
#endif
#ifdef USING_UART_PORT_3
case UART_NUM_3: {
Osal_MutexLock(s_uart3Mutex);
writeRealLen = RingBuf_Put(&s_uart3WriteRingBuffer, buf, writeSize);
__HAL_USART_ENABLE_IT(&s_uart3Handle, USART_IT_TXE);
usedCapacityOfBuffer = UART3_WRITE_BUF_SIZE - RingBuf_GetUnusedSize(&s_uart3WriteRingBuffer);
s_uart3WriteBufferState.maxUsedCapacityOfBuffer =
usedCapacityOfBuffer > s_uart3WriteBufferState.maxUsedCapacityOfBuffer ? usedCapacityOfBuffer
: s_uart3WriteBufferState.maxUsedCapacityOfBuffer;
s_uart3WriteBufferState.countOfLostData += writeSize - writeRealLen;
Osal_MutexUnlock(s_uart3Mutex);
}
break;
#endif
default:
return UART_ERROR;
}
return writeRealLen;
}
void UART_GetBufferState(E_UartNum uartNum, T_UartBufferState *readBufferState, T_UartBufferState *writeBufferState)
{
switch (uartNum) {
#ifdef USING_UART_PORT_1
case UART_NUM_1:
memcpy(readBufferState, &s_uart1ReadBufferState, sizeof(T_UartBufferState));
memcpy(writeBufferState, &s_uart1WriteBufferState, sizeof(T_UartBufferState));
break;
#endif
#ifdef USING_UART_PORT_2
case UART_NUM_2:
memcpy(readBufferState, &s_uart2ReadBufferState, sizeof(T_UartBufferState));
memcpy(writeBufferState, &s_uart2WriteBufferState, sizeof(T_UartBufferState));
break;
#endif
#ifdef USING_UART_PORT_3
case UART_NUM_3:
memcpy(readBufferState, &s_uart3ReadBufferState, sizeof(T_UartBufferState));
memcpy(writeBufferState, &s_uart3WriteBufferState, sizeof(T_UartBufferState));
break;
#endif
default:
break;
}
}
/**
* @brief UART1 interrupt request handler fucntion.
*/
#ifdef USING_UART_PORT_1
void USART1_IRQHandler(void)
{
uint8_t data;
uint16_t usedCapacityOfBuffer = 0;
uint16_t realCountPutBuffer = 0;
if (__HAL_USART_GET_IT_SOURCE(&s_uart1Handle, USART_IT_RXNE) != RESET &&
__HAL_USART_GET_FLAG(&s_uart1Handle, USART_FLAG_RXNE) != RESET) {
data = (uint8_t) ((uint16_t) (s_uart1Handle.Instance->DR & (uint16_t) 0x01FF) & (uint16_t) 0x00FF);
realCountPutBuffer = RingBuf_Put(&s_uart1ReadRingBuffer, &data, 1);
usedCapacityOfBuffer = UART1_READ_BUF_SIZE - RingBuf_GetUnusedSize(&s_uart1ReadRingBuffer);
s_uart1ReadBufferState.maxUsedCapacityOfBuffer =
usedCapacityOfBuffer > s_uart1ReadBufferState.maxUsedCapacityOfBuffer ? usedCapacityOfBuffer
: s_uart1ReadBufferState.maxUsedCapacityOfBuffer;
s_uart1ReadBufferState.countOfLostData += 1 - realCountPutBuffer;
}
if (__HAL_USART_GET_IT_SOURCE(&s_uart1Handle, USART_IT_TXE) != RESET &&
__HAL_USART_GET_FLAG(&s_uart1Handle, USART_FLAG_TXE) != RESET) {
if (RingBuf_Get(&s_uart1WriteRingBuffer, &data, 1)) {
/* Transmit Data */
s_uart1Handle.Instance->DR = ((uint16_t) data & (uint16_t) 0x01FF);
} else {
__HAL_USART_DISABLE_IT(&s_uart1Handle, USART_IT_TXE);
}
}
}
#endif
/**
* @brief UART2 interrupt request handler fucntion.
*/
#ifdef USING_UART_PORT_2
void USART2_IRQHandler(void)
{
uint8_t data;
uint16_t usedCapacityOfBuffer = 0;
uint16_t realCountPutBuffer = 0;
if (__HAL_USART_GET_IT_SOURCE(&s_uart2Handle, USART_IT_RXNE) != RESET &&
__HAL_USART_GET_FLAG(&s_uart2Handle, USART_FLAG_RXNE) != RESET) {
data = (uint8_t) ((uint16_t) (s_uart2Handle.Instance->DR & (uint16_t) 0x01FF) & (uint16_t) 0x00FF);
realCountPutBuffer = RingBuf_Put(&s_uart2ReadRingBuffer, &data, 1);
usedCapacityOfBuffer = UART2_READ_BUF_SIZE - RingBuf_GetUnusedSize(&s_uart2ReadRingBuffer);
s_uart2ReadBufferState.maxUsedCapacityOfBuffer =
usedCapacityOfBuffer > s_uart2ReadBufferState.maxUsedCapacityOfBuffer ? usedCapacityOfBuffer
: s_uart2ReadBufferState.maxUsedCapacityOfBuffer;
s_uart2ReadBufferState.countOfLostData += 1 - realCountPutBuffer;
}
if (__HAL_USART_GET_IT_SOURCE(&s_uart2Handle, USART_IT_TXE) != RESET &&
__HAL_USART_GET_FLAG(&s_uart2Handle, USART_FLAG_TXE) != RESET) {
if (RingBuf_Get(&s_uart2WriteRingBuffer, &data, 1)) {
/* Transmit Data */
s_uart2Handle.Instance->DR = ((uint16_t) data & (uint16_t) 0x01FF);
} else {
__HAL_USART_DISABLE_IT(&s_uart2Handle, USART_IT_TXE);
}
}
}
#endif
/**
* @brief UART3 interrupt request handler fucntion.
*/
#ifdef USING_UART_PORT_3
void USART3_IRQHandler(void)
{
uint8_t data;
uint16_t usedCapacityOfBuffer = 0;
uint16_t realCountPutBuffer = 0;
if (__HAL_USART_GET_IT_SOURCE(&s_uart3Handle, USART_IT_RXNE) != RESET &&
__HAL_USART_GET_FLAG(&s_uart3Handle, USART_FLAG_RXNE) != RESET) {
data = (uint8_t) ((uint16_t) (s_uart3Handle.Instance->DR & (uint16_t) 0x01FF) & (uint16_t) 0x00FF);
realCountPutBuffer = RingBuf_Put(&s_uart3ReadRingBuffer, &data, 1);
usedCapacityOfBuffer = UART3_READ_BUF_SIZE - RingBuf_GetUnusedSize(&s_uart3ReadRingBuffer);
s_uart3ReadBufferState.maxUsedCapacityOfBuffer =
usedCapacityOfBuffer > s_uart3ReadBufferState.maxUsedCapacityOfBuffer ? usedCapacityOfBuffer
: s_uart3ReadBufferState.maxUsedCapacityOfBuffer;
s_uart3ReadBufferState.countOfLostData += 1 - realCountPutBuffer;
}
if (__HAL_USART_GET_IT_SOURCE(&s_uart3Handle, USART_IT_TXE) != RESET &&
__HAL_USART_GET_FLAG(&s_uart3Handle, USART_FLAG_TXE) != RESET) {
if (RingBuf_Get(&s_uart3WriteRingBuffer, &data, 1)) {
/* Transmit Data */
s_uart3Handle.Instance->DR = ((uint16_t) data & (uint16_t) 0x01FF);
} else {
__HAL_USART_DISABLE_IT(&s_uart3Handle, USART_IT_TXE);
}
}
}
#endif

View File

@ -0,0 +1,67 @@
/**
******************************************************************************
* @file uart.h
* @version V1.0.0
* @date 2017/11/10
* @brief This is the header file for "uart.c".
*
* @copyright (c) 2017-2018 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USART_H__
#define __USART_H__
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
/* Exported constants --------------------------------------------------------*/
#define USING_UART_PORT_1
#define USING_UART_PORT_2
#define USING_UART_PORT_3
#define UART_ERROR (-1)
/* Exported macros -----------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef enum {
UART_NUM_1 = 1,
UART_NUM_2 = 2,
UART_NUM_3 = 3,
} E_UartNum;
typedef struct {
uint32_t countOfLostData; /*!< Count of data lost, unit: byte. */
uint16_t maxUsedCapacityOfBuffer; /*!< Max capacity of buffer that have been used, unit: byte. */
} T_UartBufferState;
/* Exported variables --------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
void UART_Init(E_UartNum uartNum, uint32_t baudRate);
int UART_Read(E_UartNum uartNum, uint8_t *buf, uint16_t readSize);
int UART_Write(E_UartNum uartNum, const uint8_t *buf, uint16_t writeSize);
void UART_GetBufferState(E_UartNum uartNum, T_UartBufferState *readBufferState, T_UartBufferState *writeBufferState);
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#endif

View File

@ -0,0 +1,182 @@
/**
********************************************************************
* @file upgrade_platform_opt_stm32.c
* @version V2.0.0
* @date 3/25/20
* @brief
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "upgrade_platform_opt_stm32.h"
#include <stm32f4xx_hal.h>
#include <flash_if.h>
/* Private constants ---------------------------------------------------------*/
#define PSDK_TEST_UPGRADE_FILE_INFO_STORE_ADDR (APPLICATION_STORE_ADDRESS_END - 1023)
#define PSDK_TEST_UPGRADE_REBOOT_KEY 0x11223344
/* Private types -------------------------------------------------------------*/
typedef struct {
uint32_t upgradeRebootKey;
T_PsdkUpgradeEndInfo upgradeEndInfo;
} T_PsdkTestUpgradeRebootParam;
/* Private values -------------------------------------------------------------*/
static T_PsdkUpgradeFileInfo s_upgradeFileInfo = {0};
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_PsdkReturnCode PsdkUpgradePlatformStm32_RebootSystem(void)
{
__disable_irq();
__disable_fiq();
NVIC_SystemReset();
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkUpgradePlatformStm32_CleanUpgradeProgramFileStoreArea(void)
{
uint32_t result;
result = FLASH_If_Erase(APPLICATION_STORE_ADDRESS, APPLICATION_STORE_ADDRESS_END);
if (result != FLASHIF_OK) {
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkUpgradePlatformStm32_CreateUpgradeProgramFile(const T_PsdkUpgradeFileInfo *fileInfo)
{
s_upgradeFileInfo = *fileInfo;
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkUpgradePlatformStm32_WriteUpgradeProgramFile(uint32_t offset, const uint8_t *data,
uint16_t dataLen)
{
uint32_t result;
result = FLASH_If_Write(APPLICATION_STORE_ADDRESS + offset, (uint8_t *) data, dataLen);
if (result != FLASHIF_OK) {
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkUpgradePlatformStm32_ReadUpgradeProgramFile(uint32_t offset, uint16_t readDataLen, uint8_t *data,
uint16_t *realLen)
{
memcpy(data, (const void *) (APPLICATION_STORE_ADDRESS + offset), readDataLen);
*realLen = readDataLen;
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkUpgradePlatformStm32_CloseUpgradeProgramFile(void)
{
FLASH_If_Write(PSDK_TEST_UPGRADE_FILE_INFO_STORE_ADDR, (uint8_t *) &s_upgradeFileInfo,
sizeof(T_PsdkUpgradeFileInfo));
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkUpgradePlatformStm32_ReplaceOldProgram(void)
{
uint32_t result;
T_PsdkUpgradeFileInfo *upgradeFileInfo = (T_PsdkUpgradeFileInfo *) (PSDK_TEST_UPGRADE_FILE_INFO_STORE_ADDR);
if (upgradeFileInfo->fileSize > APPLICATION_ADDRESS_END - APPLICATION_ADDRESS + 1)
{
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
result = FLASH_If_Erase(APPLICATION_ADDRESS, APPLICATION_ADDRESS_END);
if (result != FLASHIF_OK) {
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
result = FLASH_If_Write(APPLICATION_ADDRESS, (uint8_t *) APPLICATION_STORE_ADDRESS, upgradeFileInfo->fileSize);
if (result != FLASHIF_OK) {
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkUpgradePlatformStm32_SetUpgradeRebootState(const T_PsdkUpgradeEndInfo *upgradeEndInfo)
{
uint32_t result;
T_PsdkTestUpgradeRebootParam upgradeRebootParam;
upgradeRebootParam.upgradeRebootKey = PSDK_TEST_UPGRADE_REBOOT_KEY;
upgradeRebootParam.upgradeEndInfo = *upgradeEndInfo;
result = FLASH_If_Erase(APPLICATION_PARAM_STORE_ADDRESS, APPLICATION_PARAM_STORE_ADDRESS_END);
if (result != FLASHIF_OK) {
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
result = FLASH_If_Write(APPLICATION_PARAM_STORE_ADDRESS, (uint8_t *) &upgradeRebootParam,
sizeof(T_PsdkTestUpgradeRebootParam));
if (result != FLASHIF_OK) {
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkUpgradePlatformStm32_GetUpgradeRebootState(bool *isUpgradeReboot,
T_PsdkUpgradeEndInfo *upgradeEndInfo)
{
T_PsdkTestUpgradeRebootParam upgradeRebootParam;
upgradeRebootParam = *(T_PsdkTestUpgradeRebootParam *) (APPLICATION_PARAM_STORE_ADDRESS);
if (upgradeRebootParam.upgradeRebootKey == PSDK_TEST_UPGRADE_REBOOT_KEY) {
*isUpgradeReboot = true;
*upgradeEndInfo = upgradeRebootParam.upgradeEndInfo;
} else {
*isUpgradeReboot = false;
}
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkUpgradePlatformStm32_CleanUpgradeRebootState(void)
{
uint32_t result;
result = FLASH_If_Erase(APPLICATION_PARAM_STORE_ADDRESS, APPLICATION_PARAM_STORE_ADDRESS_END);
if (result != FLASHIF_OK) {
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,68 @@
/**
********************************************************************
* @file upgrade_platform_opt_stm32.h
* @version V2.0.0
* @date 3/25/20
* @brief This is the header file for "upgrade_platform_opt_stm32.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef UPGRADE_PLATFORM_OPT_STM32_H
#define UPGRADE_PLATFORM_OPT_STM32_H
/* Includes ------------------------------------------------------------------*/
#include <psdk_typedef.h>
#include <psdk_upgrade.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_PsdkReturnCode PsdkUpgradePlatformStm32_RebootSystem(void);
T_PsdkReturnCode PsdkUpgradePlatformStm32_CleanUpgradeProgramFileStoreArea(void);
T_PsdkReturnCode PsdkUpgradePlatformStm32_CreateUpgradeProgramFile(const T_PsdkUpgradeFileInfo *fileInfo);
T_PsdkReturnCode PsdkUpgradePlatformStm32_WriteUpgradeProgramFile(uint32_t offset, const uint8_t *data,
uint16_t dataLen);
T_PsdkReturnCode PsdkUpgradePlatformStm32_ReadUpgradeProgramFile(uint32_t offset, uint16_t readDataLen, uint8_t *data,
uint16_t *realLen);
T_PsdkReturnCode PsdkUpgradePlatformStm32_CloseUpgradeProgramFile(void);
T_PsdkReturnCode PsdkUpgradePlatformStm32_ReplaceOldProgram(void);
T_PsdkReturnCode PsdkUpgradePlatformStm32_SetUpgradeRebootState(const T_PsdkUpgradeEndInfo *upgradeEndInfo);
T_PsdkReturnCode PsdkUpgradePlatformStm32_GetUpgradeRebootState(bool *isUpgradeReboot,
T_PsdkUpgradeEndInfo *upgradeEndInfo);
T_PsdkReturnCode PsdkUpgradePlatformStm32_CleanUpgradeRebootState(void);
#ifdef __cplusplus
}
#endif
#endif // UPGRADE_PLATFORM_OPT_STM32_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/