cancel
Showing results for 
Search instead for 
Did you mean: 

Problem rewriting Macronix flash

FrankNatoli
Associate III

Using STM32H7B3I Discovery for program development.

Using stm32h7b3i_discovery_ospi.c thus BSP_OSPI_NOR_*** functions.

Which uses mx25lm51245g.c thus MX25LM51245G_*** functions.

Which uses stm32h7xx_hal_ospi.c thus HAL_OSPI_*** functions.

Can erase reliably calling BSP_OSPI_NOR_Erase_Block.

Can read reliably calling BSP_OSPI_NOR_Read.

Can write once to a particular offset reliably calling BSP_OSPI_NOR_Write.

But cannot rewrite to same offset.

Sometimes data is partly changed, sometimes not changed at all.

Writing 16 bytes of data each time.

Is there something about rewriting data that requires special handling?

1 ACCEPTED SOLUTION

Accepted Solutions

If you have different record types you can chain them, or use a linked list.

Generally you'd leave the cells in an erased state, 0xFF, and go back and write them later. Or knock ONE bits down to ZERO

If you need a file system, you can use UDF like one one used on CDR/DVDR media, although there are perhaps simpler ones, and ones more targeted at NOR/NAND Flash

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

6 REPLIES 6

Isn't writing once, or knocking down to zero, how NOR Flash normally works?

You'll either need to journal across unused/unwritten memory, or erase the sector you want to rewrite.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Tesla: you are providing me with a NOR flash education!

If I want to rewrite a limited section of NOR flash, can I first write all zeros [or all ones] to the area, then write the updated data?

Here is my application:

I have a section of NOR flash, which is a circular event log buffer.

I have a first record which has accounting information.

That is followed with event log entries.

If I cannot rewrite NOR flash, then I'll have to make the final record the accounting information record.

Thanks for your time.

TDK
Guru

You need to erase flash before you can write to the same location again. FLASH cannot be used the same as RAM. Writing 0xFF is not the same as erasing.

If you feel a post has answered your question, please click "Accept as Solution".

Yes, I now realize the truth.

I did an experiment: I wrote a record, read it back, all OK.

I then wrote all zeros to the same area, read it back, all zeroes.

I then wrote all ones to the same area, read it back, all still zeroes.

Thus, as you say, you can clear bits in NOR flash but you can't set them, except by erasing.

Many thanks for your time.

FrankNatoli
Associate III

Tesla and TDK have explained what can and cannot be done with NOR flash, many thanks.

If you have different record types you can chain them, or use a linked list.

Generally you'd leave the cells in an erased state, 0xFF, and go back and write them later. Or knock ONE bits down to ZERO

If you need a file system, you can use UDF like one one used on CDR/DVDR media, although there are perhaps simpler ones, and ones more targeted at NOR/NAND Flash

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..