//
//
/****************************************************************************************
** 文件名称: flash_option.c
** 功能描述: 做芯片保护和配置等功能
** 参    数: None
** 返 回 值: None
** 作　  者: 汪仁海QQ527148813
** 日  　期: 2018年12月29日
**---------------------------------------------------------------------------------------
** 修 改 人:
** 日　  期:
**---------------------------------------------------------------------------------------
*****************************************************************************************/ 

#ifndef __MY_FLASH_OPTION_C_
#define __MY_FLASH_OPTION_C_

#ifdef __cplusplus
 extern "C" {
#endif	 

#include "flash_option.h"

FLASH_OBProgramInitTypeDef *myMCU_option;

void myFlashOptionInit(void)	//初始化
{
	
	
}
	 
void myFlashOptionGet(void)	//读取配置
{
	u8 aa[40];
	uint32_t OptionType ; 
  uint32_t WRPState;
  uint32_t WRPPage; 
  uint8_t RDPLevel; 
  uint8_t USERConfig; 
  uint32_t DATAAddress; 
  uint8_t DATAData; 
	
//	HAL_FLASHEx_OBGetConfig(myMCU_option);
	
	OptionType=myMCU_option->OptionType ; 
  WRPState=myMCU_option->WRPState;
  WRPPage=myMCU_option->WRPPage; 
  RDPLevel=myMCU_option->RDPLevel; 
  USERConfig=myMCU_option->USERConfig; 
  DATAAddress=myMCU_option->DATAAddress; 
  DATAData=myMCU_option->DATAData; 

	aa[0]=0xff;
	aa[1]=OptionType>>24;
	aa[2]=OptionType>>16;
	aa[3]=OptionType>>8;
	aa[4]=OptionType;
	aa[5]=WRPState>>24;
	aa[6]=WRPState>>16;
	aa[7]=WRPState>>8;
	aa[8]=WRPState;
	aa[9]=WRPPage>>24;
	aa[10]=WRPPage>>16;
	aa[11]=WRPPage>>8;
	aa[12]=WRPPage;
	aa[13]=0xff;
	aa[14]=0xff;
	aa[15]=RDPLevel;
	aa[16]=USERConfig;
	aa[17]=DATAAddress>>24;
	aa[18]=DATAAddress>>16;
	aa[19]=DATAAddress>>8;
	aa[20]=DATAAddress;
	aa[21]=0xff;
	aa[22]=DATAData;
	aa[23]=0xff;
	aa[24]=0xff;
	
	myUSART_putData(aa,25);
}
	 
void myFlashOptionSet(void)	//设置配置
{
	HAL_FLASHEx_OBGetConfig(myMCU_option);
	
	if(myMCU_option->WRPState!=SET)
	{		
		
//		HAL_FLASHEx_OBProgram(myMCU_option);
		
	}
}
	 
u8 SetFlashRDP(void)//flash的RDP数据保护等级设置
{
	u8 flag=0;
  // OB_RDP_LEVEL_0 No protection
  // OB_RDP_LEVEL_1 Read protection of the memory
  // OB_RDP_LEVEL_2 Full chip protection
	//FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
	//FLASH_OB_GetRDP();
//	if(FLASH_OB_GetRDP()==OB_RDP_LEVEL_0)
//		FLASH_OB_RDP_LevelConfig(OB_RDP_LEVEL_1);
//	
	
	return flag;
}

#ifdef __cplusplus
}
#endif


#endif /*__MY_FLASH_OPTION_C_ */
