有时候有、有时候没有问题,那就是有问题的时候没有正常写入,最好在软件里写入之后再读回判断一下有没有写对了
或者直接用库函数代替你那个操作
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] Programs option byte
- * @param Address : option byte address to program
- * @param Data : Value to write
- * @retval None
- */
- void FLASH_ProgramOptionByte(uint16_t Address, uint8_t Data)
- {
- /* Check parameter */
- assert_param(IS_OPTION_BYTE_ADDRESS_OK(Address));
- /* Enable write access to option bytes */
- FLASH->CR2 |= FLASH_CR2_OPT;
- FLASH->NCR2 &= (uint8_t)(~FLASH_NCR2_NOPT);
- /* check if the option byte to program is ROP*/
- if (Address == 0x4800)
- {
- /* Program option byte*/
- *((NEAR uint8_t*)Address) = Data;
- }
- else
- {
- /* Program option byte and his complement */
- *((NEAR uint8_t*)Address) = Data;
- *((NEAR uint8_t*)((uint16_t)(Address + 1))) = (uint8_t)(~Data);
- }
- FLASH_WaitForLastOperation(FLASH_MEMTYPE_PROG);
- /* Disable write access to option bytes */
- FLASH->CR2 &= (uint8_t)(~FLASH_CR2_OPT);
- FLASH->NCR2 |= FLASH_NCR2_NOPT;
- }
|