101 lines
2.4 KiB
C
Executable File
101 lines
2.4 KiB
C
Executable File
#include "bsp_init.h"
|
|
#include "stm32f7xx_ll_gpio.h"
|
|
#include "stm32f7xx_ll_bus.h"
|
|
#include "stdbool.h"
|
|
#include "stm32746g_discovery_qspi.h"
|
|
|
|
/**
|
|
* @brief Set flash read protection.
|
|
* @param [in] state: Flash read protection state, true: enable protection, false: disable protection.
|
|
* @retval true: Successful operation.
|
|
* @retval false: Operation failed.
|
|
*/
|
|
bool SetFlashReadProtection(bool state)
|
|
{
|
|
FLASH_OBProgramInitTypeDef OptionsBytesStruct = {0};
|
|
HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);
|
|
|
|
if(state == true)
|
|
{
|
|
if(OptionsBytesStruct.RDPLevel == OB_RDP_LEVEL_0)
|
|
{
|
|
OptionsBytesStruct.OptionType = OPTIONBYTE_RDP;
|
|
OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_1;
|
|
|
|
HAL_FLASH_Unlock();
|
|
HAL_FLASH_OB_Unlock();
|
|
|
|
if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)
|
|
{
|
|
HAL_FLASH_OB_Lock();
|
|
|
|
|
|
return false;
|
|
}
|
|
|
|
HAL_FLASH_Lock();
|
|
HAL_FLASH_OB_Launch();
|
|
HAL_FLASH_OB_Lock();
|
|
NVIC_SystemReset();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(OptionsBytesStruct.RDPLevel == OB_RDP_LEVEL_1)
|
|
{
|
|
OptionsBytesStruct.OptionType = OPTIONBYTE_RDP;
|
|
OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_0;
|
|
|
|
HAL_FLASH_OB_Unlock();
|
|
|
|
if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)
|
|
{
|
|
HAL_FLASH_OB_Lock();
|
|
|
|
return false;
|
|
}
|
|
|
|
HAL_FLASH_OB_Lock();
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
void TargetBSP_Init(void)
|
|
{
|
|
// CSP_QUADSPI_Init();
|
|
// CSP_QSPI_EnableMemoryMappedMode();
|
|
// SetFlashReadProtection(true);
|
|
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_CRC);
|
|
HAL_DBGMCU_EnableDBGStandbyMode();
|
|
HAL_DBGMCU_EnableDBGSleepMode();
|
|
HAL_DBGMCU_EnableDBGStopMode();
|
|
__HAL_DBGMCU_FREEZE_TIM2();
|
|
__HAL_DBGMCU_FREEZE_TIM3();
|
|
__HAL_DBGMCU_FREEZE_TIM4();
|
|
__HAL_DBGMCU_FREEZE_TIM5();
|
|
__HAL_DBGMCU_FREEZE_TIM6();
|
|
__HAL_DBGMCU_FREEZE_TIM7();
|
|
__HAL_DBGMCU_FREEZE_TIM12();
|
|
__HAL_DBGMCU_FREEZE_TIM13();
|
|
__HAL_DBGMCU_FREEZE_TIM14();
|
|
__HAL_DBGMCU_FREEZE_LPTIM1();
|
|
__HAL_DBGMCU_FREEZE_RTC();
|
|
__HAL_DBGMCU_FREEZE_WWDG();
|
|
__HAL_DBGMCU_FREEZE_IWDG();
|
|
__HAL_DBGMCU_FREEZE_I2C1_TIMEOUT();
|
|
__HAL_DBGMCU_FREEZE_I2C2_TIMEOUT();
|
|
__HAL_DBGMCU_FREEZE_I2C3_TIMEOUT();
|
|
__HAL_DBGMCU_FREEZE_CAN1();
|
|
__HAL_DBGMCU_FREEZE_CAN2();
|
|
__HAL_DBGMCU_FREEZE_TIM1();
|
|
__HAL_DBGMCU_FREEZE_TIM8();
|
|
__HAL_DBGMCU_FREEZE_TIM9();
|
|
__HAL_DBGMCU_FREEZE_TIM10();
|
|
__HAL_DBGMCU_FREEZE_TIM11();
|
|
|
|
|
|
}
|