--- Quote Start ---
How do I check if the flash is write-protected?
--- Quote End ---
Flash memories can have two data protection methods:
- a Write Protect (/WP) pin which usually must be left floating or pulled up to allow write. If you tie it to ground you can't write data.
- a 'soft' protection you can enable/disable through appropriate commands on the flash interface. Depending on the device, you can restrict protection to single sectors or apply it to the whole device.
Refer to the component datasheet for both.
--- Quote Start ---
Yes, I did tried to write 50KB of data and it works fine.
I am using DE2 Board
--- Quote End ---
I think the alt_flash_write function provided by HAL driver can manage any data size. It should take care of splitting large data in actual flash sectors.
However, I believe that the function operates on a sector basis, so the entire sector is erased when you call alt_flash_write, even if you write only a few bytes. Same if your offset is not at the beginning of a sector: all data at lower addresses in that sector will be lost.
Usually sector size is 64kB, so I'd suggest you try to write up to this size; if the function fails with bigger size, then the problem is almost certainly due to some problem in spreading data writes across different sectors.