[STM8] 请问这个问题是如何产生的?怎么解决?

[复制链接]
1290|3
 楼主| zyx1992106 发表于 2017-4-26 14:57 | 显示全部楼层 |阅读模式
用STVP总是出现:“Error on Option Bytes (complementary bytes). Reprogram Option Bytes of device”;有时候有这个问题有时候又没有队友同一个程序来说
Xflyan 发表于 2017-4-26 18:53 | 显示全部楼层
程序里有写OPB,但没有写补码,重启后就会有这种错误
 楼主| zyx1992106 发表于 2017-4-27 10:55 | 显示全部楼层
Xflyan 发表于 2017-4-26 18:53
程序里有写OPB,但没有写补码,重启后就会有这种错误

我有写啊:  *((unsigned char*)0x4803) = 0x01;
  *((unsigned char*)0x4804) = 0xfe;//PC5 PC6能输出PWM,option bytes;
其他选项字我没有写
Xflyan 发表于 2017-4-27 13:43 | 显示全部楼层
zyx1992106 发表于 2017-4-27 10:55
我有写啊:  *((unsigned char*)0x4803) = 0x01;
  *((unsigned char*)0x4804) = 0xfe;//PC5 PC6能输出PWM ...

有时候有、有时候没有问题,那就是有问题的时候没有正常写入,最好在软件里写入之后再读回判断一下有没有写对了
或者直接用库函数代替你那个操作
  1. /**
  2.   * [url=home.php?mod=space&uid=247401]@brief[/url]   Programs option byte
  3.   * @param  Address : option byte address to program
  4.   * @param  Data : Value to write
  5.   * @retval None
  6.   */
  7. void FLASH_ProgramOptionByte(uint16_t Address, uint8_t Data)
  8. {
  9.     /* Check parameter */
  10.     assert_param(IS_OPTION_BYTE_ADDRESS_OK(Address));

  11.     /* Enable write access to option bytes */
  12.     FLASH->CR2 |= FLASH_CR2_OPT;
  13.     FLASH->NCR2 &= (uint8_t)(~FLASH_NCR2_NOPT);

  14.     /* check if the option byte to program is ROP*/
  15.     if (Address == 0x4800)
  16.     {
  17.        /* Program option byte*/
  18.        *((NEAR uint8_t*)Address) = Data;
  19.     }
  20.     else
  21.     {
  22.        /* Program option byte and his complement */
  23.        *((NEAR uint8_t*)Address) = Data;
  24.        *((NEAR uint8_t*)((uint16_t)(Address + 1))) = (uint8_t)(~Data);
  25.     }
  26.     FLASH_WaitForLastOperation(FLASH_MEMTYPE_PROG);

  27.     /* Disable write access to option bytes */
  28.     FLASH->CR2 &= (uint8_t)(~FLASH_CR2_OPT);
  29.     FLASH->NCR2 |= FLASH_NCR2_NOPT;
  30. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

33

主题

81

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部