CTRLSTAT = 0xffffffff

Sir,

I am working on Cortex-M4 over serial wire debug protocol, i am able to read IDCODE(0x2ba01477) which is correct as per arm cortex m4 technical reference manual, and i am writing 0x50000000 to CTRLSTAT register to enable CSYSPWRUPREQ and CDBGPWRREQ which is also success without any ACK error,but the thing is when i am trying to read the CTRLSTAT register i got 0xffffffff . I don't understand what might be the problem,Please suggest me what would be the problem??

Thanks & Regards

Parents
  • Most likely your Flash memory is protected.

    It's important that you know there are two unlock sequences.

    First you will need to check that the LOCK bit of FLASH_CR is zero. If it is not zero, you will want to unlock it by sending the unlock sequence mentioned earlier:

    0x40023c04=0x45670123. 0x40023c04=0xcdef89ab.

    Then you may need to wait for a few milliseconds; I do not know how long, but try giving it a good delay at first, then you can reduce it and see when it fails.

    Now read FLASH_SR first. It is important to check all the things in this register that can go wrong. In particular, we're interested in bit 4, the WRPERR bit.

    -If the WRPERR bit is set, we're in trouble, but we'll also need to be free of other errors.

    If there are no errors, however, then we can proceed and read FLASH_CR again, to verify that the LOCK bit is now zero.

    If the LOCK bit of FLASH_CR is zero, then we can proceed.

    Read the FLASH_OPTCR register. by reading address 0x40023c14. If this register does not contain 0x0fffaae1, then you'll most likely get write protection errors in FLASH_SR after attempting to write to the flash-memory.

    So if FLASH_OPTCR register's bits 27:16 are not all 1, then we'll need to modify them. Bits 15:8 must be 0xaa. So we'll write the following:

    0x40023c08=0x08192a3b. 0x40023c08=0x4c5d6e7f. 0x40023c14=0x0fffaaed.

    Right after that sequence, we should read FLASH_SR, to check for errors.

    Then read FLASH_CR and verify that the LOCK bit is still zero.

    After that, we should read the FLASH_OPTCR register, to verify that the value is now changed; expect 0x0fffaae1.

    OK, we're about to flash-program the device, so now we'll do the checking again.

    Read the FLASH_OPTCR register (address 0x40023c14), if bits 27:16 are not all ones, we can't write to the flash-memory.

    Now read FLASH_SR, and verify that there were no error reading FLASH_OPTCR.

    Finally, read FLASH_CR and verify that the LOCK bit is still zero (I expect that it always is zero).

    If all checks out, try writing a block of data to the Flash memory.

    Right after writing the last 32-bit word of your data block, you should immediately read FLASH_SR and check for any errors.

    If bit 4 is set, then you could not write to the flash memory, because it's write-protected (somehow that means that the FLASH_OPTCR does not contain the value we'd expect by now).

    If any of the above sequences do not contain the values I wrote, please let me know, I could have made a typo.

Reply
  • Most likely your Flash memory is protected.

    It's important that you know there are two unlock sequences.

    First you will need to check that the LOCK bit of FLASH_CR is zero. If it is not zero, you will want to unlock it by sending the unlock sequence mentioned earlier:

    0x40023c04=0x45670123. 0x40023c04=0xcdef89ab.

    Then you may need to wait for a few milliseconds; I do not know how long, but try giving it a good delay at first, then you can reduce it and see when it fails.

    Now read FLASH_SR first. It is important to check all the things in this register that can go wrong. In particular, we're interested in bit 4, the WRPERR bit.

    -If the WRPERR bit is set, we're in trouble, but we'll also need to be free of other errors.

    If there are no errors, however, then we can proceed and read FLASH_CR again, to verify that the LOCK bit is now zero.

    If the LOCK bit of FLASH_CR is zero, then we can proceed.

    Read the FLASH_OPTCR register. by reading address 0x40023c14. If this register does not contain 0x0fffaae1, then you'll most likely get write protection errors in FLASH_SR after attempting to write to the flash-memory.

    So if FLASH_OPTCR register's bits 27:16 are not all 1, then we'll need to modify them. Bits 15:8 must be 0xaa. So we'll write the following:

    0x40023c08=0x08192a3b. 0x40023c08=0x4c5d6e7f. 0x40023c14=0x0fffaaed.

    Right after that sequence, we should read FLASH_SR, to check for errors.

    Then read FLASH_CR and verify that the LOCK bit is still zero.

    After that, we should read the FLASH_OPTCR register, to verify that the value is now changed; expect 0x0fffaae1.

    OK, we're about to flash-program the device, so now we'll do the checking again.

    Read the FLASH_OPTCR register (address 0x40023c14), if bits 27:16 are not all ones, we can't write to the flash-memory.

    Now read FLASH_SR, and verify that there were no error reading FLASH_OPTCR.

    Finally, read FLASH_CR and verify that the LOCK bit is still zero (I expect that it always is zero).

    If all checks out, try writing a block of data to the Flash memory.

    Right after writing the last 32-bit word of your data block, you should immediately read FLASH_SR and check for any errors.

    If bit 4 is set, then you could not write to the flash memory, because it's write-protected (somehow that means that the FLASH_OPTCR does not contain the value we'd expect by now).

    If any of the above sequences do not contain the values I wrote, please let me know, I could have made a typo.

Children