Menu

#72 STM32F2 write options clears FLASH_OPTCR

0.9.0
closed
None
targets
minor
bug
2014-06-03
2014-05-28
No

It appears there is a bug at the end of the option byte write function for STM32F2:
stm32f2x.c:375, in stm32x_write_options(). FLASH_OPTCR (option byte config register) is locked by writing 0x00000001 to it, but this clears the rest of the register bits, which appears to cause problems for the 'flash write_image' command with the unlock options specified. The subsequent sector erase fails with the WRPERR (write protect error) flag set in FLASH_SR. Instead, reading FLASH_OPTCR and ORing it with 0x00000001 seems to work fine.

Another solution would be to issue a reset after locking FLASH_OPTCR, which would reload the option byte configuration.

I can attach logs if necessary, but this seems pretty self-explanatory after looking at the source.

Discussion

  • Spencer Oliver

    Spencer Oliver - 2014-05-28

    Thanks for spotting this, are you able to push a patch to our review server, if not then I am happy to do this.

    perhaps the easiest thing todo @ line 375 is:
    retval = target_write_u32(target, STM32_FLASH_OPTCR, optiondata | OPT_LOCK);

     
    • Elliott Partridge

      I'll get the patch in. It's about time I figure out the process for this
      anyways, I use OpenOCD enough for it.

       

      Last edit: Elliott Partridge 2014-05-29
  • Spencer Oliver

    Spencer Oliver - 2014-05-29
    • status: new --> accepted
    • assigned_to: Spencer Oliver
     
  • Spencer Oliver

    Spencer Oliver - 2014-05-29
     
  • Spencer Oliver

    Spencer Oliver - 2014-06-03
    • status: accepted --> closed
     
  • Spencer Oliver

    Spencer Oliver - 2014-06-03

    merged

     

Log in to post a comment.