stm8l内部eeprom块写问题用的库里的例子,测试有问题?
发现寄存器FLASH_CR2除了bit7 opt位外其它位不能写,一写就异常。
废话不说,直接上程序,stvd下测试
IN_RAM(void FLASH_ProgramBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType,
FLASH_ProgramMode_TypeDef FLASH_ProgMode, uint8_t *Buffer))
{
uint16_t Count = 0;
uint32_t startaddress = 0;
/* Check parameters */
assert_param(IS_FLASH_MEMORY_TYPE(FLASH_MemType));
assert_param(IS_FLASH_PROGRAM_MODE(FLASH_ProgMode));
if (FLASH_MemType == FLASH_MemType_Program)
{
assert_param(IS_FLASH_PROGRAM_BLOCK_NUMBER(BlockNum));
startaddress = FLASH_PROGRAM_START_PHYSICAL_ADDRESS;
}
else
{
assert_param(IS_FLASH_DATA_EEPROM_BLOCK_NUMBER(BlockNum));
startaddress = FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS;
}
/* Point to the first block address */
startaddress = startaddress + ((uint32_t)BlockNum * FLASH_BLOCK_SIZE);
/* Selection of Standard or Fast programming mode */
if (FLASH_ProgMode == FLASH_ProgramMode_Standard)
{
/* Standard programming mode */
//FLASH->CR2 |= FLASH_CR2_PRG;
#pragma asm
LD A,0x5051
OR A,#0X01
LD 0x5051,A
#pragma endasm
}
else
{
/* Fast programming mode */
//FLASH->CR2 |= FLASH_CR2_FPRG;
#pragma asm
LD A,0x5051
OR A,#0X10
LD 0x5051,A
#pragma endasm
}
tempdata=FLASH->CR2;
tempdata&=0x01;
if(tempdata==0x01)
{
GPIOF->ODR &= ~(0x01);
}
else
{
GPIOF->ODR |= 0x01;
}
/* Copy data bytes from RAM to FLASH memory */
for (Count = 0; Count < FLASH_BLOCK_SIZE; Count++)
{
#if defined (STM8L15X_MD) || defined (STM8L15X_MDP) || defined (STM8L15X_LD)
*((PointerAttr uint8_t*) (uint16_t)startaddress + Count) = ((uint8_t)(Buffer[Count]));
#elif defined (STM8L15X_HD)
*((PointerAttr uint8_t*) (uint32_t)startaddress + Count) = ((uint8_t)(Buffer[Count]));
#endif
}
} |