Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash programming sequence error caused by incorrect write procedure #382

Closed
ost-ing opened this issue Aug 18, 2022 · 2 comments
Closed

Comments

@ost-ing
Copy link
Contributor

ost-ing commented Aug 18, 2022

I've noticed that in certain circumstances the flash controller returns BankError::PROGRAMMING_SEQUENCE.

It doesn't seem to happen in all circumstances, but the following doesn't work for me within my application:

let mut buffer: [u8; 256] = [0xFF; 256];
// ... fill buffer with data
flash.erase_sector(Bank::UserBank2, 7).unwrap();
flash
    .write_sector(Bank::UserBank2, 7, 0, &buffer)
    .unwrap();

I believe the issue is due to an incorrect write procedure regarding the program enable bit (PG1/2)

cc. @richardeoin @lachlansneff-parallel

Kind regards

@ost-ing ost-ing changed the title Flash inconsistency error caused by incorrect write procedure Flash programming sequence error caused by incorrect write procedure Aug 18, 2022
@ost-ing
Copy link
Contributor Author

ost-ing commented Aug 18, 2022

@richardeoin , please see #383

bors bot added a commit that referenced this issue Aug 29, 2022
383: flash: fence ordering to ensure pg bit is set before write to flash memory r=richardeoin a=ostenning

Following from issue: #382

The following code in certain circumstances yields a `BankError::PROGRAMMING_SEQUENCE`:

```rust
let mut buffer: [u8; 256] = [0xFF; 256];
// ... fill buffer with data
flash.erase_sector(Bank::UserBank2, 7).unwrap();
flash
    .write_sector(Bank::UserBank2, 7, 0, &buffer)
    .unwrap();
```

Reading the PM0433 reference manual; 4.7.3:

```
Programming sequence error (PGSERR):

More specifically, PGSERR1/2 flag is set if one of below conditions is met:
• A write operation is requested but the program enable bit (PG1/2) has not been set in FLASH_CR1/2 register prior to the request.
• The inconsistency error (INCERR1/2) has not been cleared to 0 before requesting a new write operation.
```

**_Solution:_**

I've found that enabling the Program Enable Bit _before_ enabling parallelism resolves this issue.

Additionally I have fixed some clippy related issues and clarified some comments




Co-authored-by: Oliver Stenning <18360865+ostenning@users.noreply.github.com>
@richardeoin
Copy link
Member

Closed by #383

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants