K74B/87400/drivers/core/inc/flash_sfrs.h
2024-01-25 14:22:18 +08:00

84 lines
2.6 KiB
C

/**
* @copyright 2015 Indie Semiconductor.
*
* This file is proprietary to Indie Semiconductor.
* All rights reserved. Reproduction or distribution, in whole
* or in part, is forbidden except by express written permission
* of Indie Semiconductor.
*
* @file flash_sfrs.h
*/
#ifndef FLASH_SFRS_H__
#define FLASH_SFRS_H__
#include <stddef.h>
#include <stdint.h>
#include <meta.h>
#define FLASH_WRITE_1_BYTE 0x01//
#define FLASH_WRITE_2_BYTE 0x01//
#define FLASH_WRITE_4_BYTE_L 0x0F//
#define FLASH_WRITE_4_BYTE_M_ECC 0x1F0//
#define FLASH_WRITE_8_BYTE 0xFF//
#define FLASH_WRITE_9_BYTE 0x1FF//
#define E_FLASH_ERASE_SECTOR 0//
#define E_FLASH_ERASE_CHIP 1//
#define E_FLASH_UNLOCK_WRITE 0x55555555U
#define E_FLASH_UNLOCK_ERASE 0x66666666U
#define E_FLASH_ERASE_START 0x99999999U
#define E_FLASH_WRITE_START 0xAAAAAAAAU
#define E_FLASH_UNLOCK_CTRL 0xACDC1972U
#define NVR_FLASH_WRITE_START 0x502901FFU
#define NVR_FLASH_ERASE_START 0x502901FFU
#define E_FLASH_CODE_PROTECT 0xF2E11047U
#define E_FLASH_WRITE_PROTECT 0x12100511U
/**
* @brief Flash memory erase sector function.
*
* @param address inside the sector to be erased.
*/
static __INLINE void f_FLASH_EraseSector(__IO uint32_t address)
{
/* load address */
FLASH_SFRS->FLADDR.FLASHADDR = (uint32_t)(address>>3U);
FLASH_SFRS->UNLOCK_CTRL_OP = E_FLASH_UNLOCK_CTRL;
FLASH_SFRS->CTRL_OPR.CHIPSEL = E_FLASH_ERASE_SECTOR;
FLASH_SFRS-> UNLOCK_ERASE = E_FLASH_UNLOCK_ERASE;
FLASH_SFRS-> ERASE_START = E_FLASH_ERASE_START;
while(FLASH_SFRS->OPBSY != 0U);
FLASH_SFRS->UNLOCK_CTRL_OP = 0;
}
/**
* @brief Flash memory write word function.
*
* @param address and data (byte) to be programmed into flash.
* @param data and data (byte) to be programmed into flash.
*/
static __INLINE void f_FLASH_Write2WordsWithECC(__IO uint32_t address, uint32_t dataL,uint32_t dataH)
{
FLASH_SFRS->UNLOCK_CTRL_OP = E_FLASH_UNLOCK_CTRL;
FLASH_SFRS->CTRL_OPR.BYTESEL = FLASH_WRITE_9_BYTE;
FLASH_SFRS->FLADDR.FLASHADDR = (uint32_t)(address >> 3);
FLASH_SFRS->DATAL = dataL;
FLASH_SFRS->DATAM = dataH;
FLASH_SFRS->UNLOCK_WRITE = E_FLASH_UNLOCK_WRITE;
FLASH_SFRS->FLADDR.NVR = 0;
FLASH_SFRS->WRITE_START = E_FLASH_WRITE_START;
while(FLASH_SFRS->OPBSY != 0);
FLASH_SFRS->UNLOCK_CTRL_OP = 0;
}
#endif /* __FLASH_SFRS_H__ */