了解py32芯片的flash内容,对于py32进行api升级有更好的了解的操作
//uiOffset = 0(4MHz), 1(8MHz), 2(16MHz), 3(22.12MHz), 4(24MHz)
void SetFlashParameter(uint32_t uiOffset)
{
WRITE_REG(FLASH->KEYR, FLASH_KEY1);
WRITE_REG(FLASH->KEYR, FLASH_KEY2); //解锁
FLASH->TS0 = ((M32(0x1FFF0F1C+uiOffset*0x14)>>0)&0x000000FF);
FLASH->TS3 = ((M32(0x1FFF0F1C+uiOffset*0x14)>>8)&0x000000FF);
FLASH->TS1 = ((M32(0x1FFF0F1C+uiOffset*0x14)>>16)&0x000001FF);
FLASH->TS2P = ((M32(0x1FFF0F20+uiOffset*0x14)>>0)&0x000000FF);
FLASH->TPS3 = ((M32(0x1FFF0F20+uiOffset*0x14)>>16)&0x000007FF);
FLASH->PERTPE = ((M32(0x1FFF0F24+uiOffset*0x14)>>0)&0x0001FFFF);
FLASH->SMERTPE = ((M32(0x1FFF0F28+uiOffset*0x14)>>0)&0x0001FFFF);
FLASH->PRGTPE = ((M32(0x1FFF0F2C+uiOffset*0x14)>>0)&0x0000FFFF);
FLASH->PRETPE = ((M32(0x1FFF0F2C+uiOffset*0x14)>>16)&0x0000FFFF);
SET_BIT(FLASH->CR, FLASH_CR_LOCK);//上锁
}
Flash_KEY定义的路径:Libraries\CMSIS\Device\PY32F030\Include\py32f030xx.h
/****************** FLASH Keys **********************************************/
#define FLASH_KEY1_Pos (0U)
#define FLASH_KEY1_Msk (0x45670123UL << FLASH_KEY1_Pos) /*!< 0x45670123 */
#define FLASH_KEY1 FLASH_KEY1_Msk /*!< Flash program erase key1 */
#define FLASH_KEY2_Pos (0U)
#define FLASH_KEY2_Msk (0xCDEF89ABUL << FLASH_KEY2_Pos) /*!< 0xCDEF89AB */
#define FLASH_KEY2 FLASH_KEY2_Msk