Skip to main content
Graduate
December 13, 2023
Solved

Aligment error (PGAERR) on FLASH write. Error UNDEFINSTR joins the party

  • December 13, 2023
  • 3 replies
  • 2031 views

I dont know why this error happens. It is aligned as 0x0800F800.

Not only this, but i get a hardfault (UNDEFINSTR) error too, while printing the above error with the following:

printf("Error writeFLASHDoubleWord FLASH->SR: %02X", READ_REG(FLASH->SR));

    This topic has been closed for replies.
    Best answer by Tobe

    You are spot on. I did not think about how big a page actually is ;-).

    I put it now at the end to not get a problem again. But i found out, that after erasing pages, my writing does not work anymore. If i comment out the erase, i can write the flash. How can the erase prevent me from writin?

    erase blocks write.jpg

    3 replies

    Graduate II
    December 13, 2023

    You can read FLASH->SR directly, and its not at 0x800F800

    Your error is coming from something else. Decompose the Hard Fault, presenting those registers and the machine instructions that are faulting, so it might be more apparent what the actual issue is.

    The printf() doesn't look intrinsically wrong. Are you perhaps deleting the code/data that relate to the instruction, the library, the string?

    A double word would need to be on an 8-byte boundary, and the content properly erased.

    Going to need better presentation and context to understand why this is failing.

    TobeAuthorAnswer
    Graduate
    December 13, 2023

    You are spot on. I did not think about how big a page actually is ;-).

    I put it now at the end to not get a problem again. But i found out, that after erasing pages, my writing does not work anymore. If i comment out the erase, i can write the flash. How can the erase prevent me from writin?

    erase blocks write.jpg

    Graduate II
    December 13, 2023

    >>How can the erase prevent me from writing?

    It didn't complete yet?

    There's some pending error?

     

    Hard to tell anything from screen shot code fragment. Need to see output and sequences from an instrumented process. Best not to single-step in debugger, or dwell on the peripheral view. Print out info about the stages, and the register in hex at each point. Decimal not helpful.

    Graduate II
    December 13, 2023

    On these devices after erase every 64-bit cell can be written just once and in addition one can always invalidate the cell by writing zeros to it. All of it is explained in the reference manual.

    TobeAuthor
    Graduate
    December 14, 2023

    I was having some memory about invalidating, but could not find the part in the manual again...

    But with playing around with it, i can truly confirm that.

    Graduate II
    December 15, 2023

    RM0440 Rev 7 section 5.3.7 tells it in the second sentence...

    TobeAuthor
    Graduate
    December 15, 2023

    No, i think it was somewhere else. It is in general the case: with addresses that you have not programmed before, you can only write 0x0.

    Graduate II
    December 15, 2023

    What "no"? I showed where it is written. If it's also written in some other place... so what? And how many times un how many places it must be written for you to finally read it? Zero is the only value that can be written to addresses that have been programmed previously!