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

Improve QSPIFBlockDevice conformance to SFDP #11531

Merged
merged 26 commits into from
Nov 13, 2019

Conversation

kyle-cypress
Copy link

@kyle-cypress kyle-cypress commented Sep 19, 2019

Description

Proposed fix for #11530 .

In several cases QSPIFBlockDevice does not conform to the SFDP standard JESD216. These include:

  • Status register reading and writing
  • Soft resetting
  • Enabling of 4-byte addressing
  • Enabling of quad output mode
  • Use of the legacy erase instruction

In these cases QSPIFBlockDevice often assumes that certain instructions or methods are universal across flash devices when they are not. This can cause issues in devices that do not match these assumptions. This pull request resolves many of these issues and better aligns QSPIFBlockDevice with JESD216.

This PR is dependent on #11604

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

Release Notes

@kyle-cypress
Copy link
Author

This is a WIP submission to gather feedback while we finalize our internal review and testing.

@ciarmcom ciarmcom requested review from a team September 19, 2019 21:00
@ciarmcom
Copy link
Member

@kyle-cypress, thank you for your changes.
@ARMmbed/mbed-os-storage @ARMmbed/mbed-os-core @ARMmbed/mbed-os-test @ARMmbed/mbed-os-hal @ARMmbed/mbed-os-maintainers please review.

@0xc0170 0xc0170 removed the request for review from a team September 20, 2019 08:28
@@ -380,7 +380,7 @@ int QSPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
int type = 0;
uint32_t offset = 0;
uint32_t chunk = 4096;
unsigned int cur_erase_inst = _erase_instruction;
qspi_inst_t cur_erase_inst = _erase_instruction;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this change? I dont see anything in the commit msg to explain.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency - the current code uses a mixture of signed and unsigned integers to represent instruction values
Clarity - convey the meaning better of the data than a generic int (and encourage consistency)
Efficiency: The instruction is only 8 bits wide, so size the data type to fit.

@0xc0170 0xc0170 removed request for a team September 26, 2019 14:24
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 26, 2019

@ARMmbed/mbed-os-storage Can you please review this proposal?

drivers/QSPI.h Outdated
@@ -160,7 +166,7 @@ class QSPI : private NonCopyable<QSPI> {
* @returns
* Returns QSPI_STATUS_SUCCESS on successful reads and QSPI_STATUS_ERROR on failed reads.
*/
qspi_status_t read(int instruction, int alt, int address, char *rx_buffer, size_t *rx_length);
qspi_status_t read(qspi_inst_t instruction, int alt, int address, char *rx_buffer, size_t *rx_length);
Copy link
Contributor

@0xc0170 0xc0170 Sep 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int should be sufficient for inst as it can be any number, narrow down this won't make much difference here.

Same as alt, address and others.

This is breaking change, so needs to be justified to go in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of this in the block device was wrong, should follow what the driver specifies.

Copy link
Author

@kyle-cypress kyle-cypress Sep 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of this in the block device was wrong, should follow what the driver specifies.

Can you clarify what you mean? Are you saying that the use of unsigned int instead of int in the block device was wrong?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int should be sufficient for inst as it can be any number, narrow down this won't make much difference here.

Same as alt, address and others.

This is breaking change, so needs to be justified to go in.

This change is not mandatory for the fix here so I can pull it out of this review and into a separate PR if it makes things easier. But in principle, shouldn't values which correspond to bit patterns of a particular width be represented as types of particular widths? If so, then I would argue that a separate PR should also replace alt and address with more specific types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not that familiar with SQPIF, but if commands are limited to 8 bytes, then I would say that this is acceptable, and it is not a breaking change.

Mbed OS have not guaranteed to have binary compatibility, so moving from int to uint8_t should be OK.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 26, 2019

This again changes a driver and the block device - as these are two different areas, it would be good to split them, driver first - if accepted, block device can be updated. Otherwise this takes a longer time to review and integrate (they are dependent on each other).

Copy link
Contributor

@SeppoTakalo SeppoTakalo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are lots of changes not related to QSPIF, can you split your changes to separate PRs so that we can properly review each change on its own.

Currently I'm not able to understand why this PR touches things like LittleFS, KVStore and DeviceKey.

@kyle-cypress
Copy link
Author

Yes, I will split out the related refactoring and cleanups into their own PRs that this one can then depend on.

@kyle-cypress
Copy link
Author

kyle-cypress commented Oct 1, 2019

Separated out #11604 for the qspi_inst_t change (will rebase this PR to remove that commit soon)

@kyle-cypress
Copy link
Author

I've made the following updates:


_mutex.lock();

// All commands other than Read and RSFDP use default 1-1-1 bus mode (Program/Erase are constrained by flash memory performance more than bus performance)
_qspi.configure_format(QSPI_CFG_BUS_SINGLE, QSPI_CFG_BUS_SINGLE, _address_size, QSPI_CFG_BUS_SINGLE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to check return value from configure_format()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the return value needs to be checked for configure_format across the board, but that is handled in #11603 (applying the check to additional/relocated configure_format calls would be handled during the rebase of whichever PR goes in second).

@maclobdell
Copy link
Contributor

@ARMmbed/mbed-os-maintainers - Can this be merged. It seems the issues have been addressed. Please confirm.

@adbridge
Copy link
Contributor

CI started

Kyle Kearney added 3 commits November 12, 2019 12:26
Use a vendor id check to only perform this enable on devices which define the
 second configuration register where the fast mode enable bit lives.
Change _enable_fast_mode to use the standard status register reading and writing functions
4-byte addressing has been seen to cause failures on NORDIC
boards and with Macronix memories. Suppress the attempt to enable it
on that hardware (via vendor quirks and a target check) until either
the failure cause can be fixed or a more robust suppression mechanism
is implemented.
The addition of trace logging during greentea tests pushes the multithreaded
read-write test beyond the limits of the stack it allocates for its threads.
The increase of 128 bytes was chosen by experimentation.
@kyle-cypress
Copy link
Author

kyle-cypress commented Nov 13, 2019

1.) Rebased on latest master in hopes that, if I understood the comment correctly, this will pull in a fix for the issue @jeromecoutant was encountering.
2.) Slightly increased the thread stack size for the block device multithreaded test to fix the stack overflow.

This will probably still fail on NRF52840_DK with a timeout. This is because the extensive debug-level tracing in QSPIFBlockDevice, which is now enabled during the CI, causes the general block device test to slow down substantially while it waits for the UART (in my testing it increased from ~2 minutes to 10-15). The kvstore static test looks like it has a similar issue. @maclobdell plans to seek agreement on the proper way to resolve this early tomorrow morning.

@jeromecoutant
Copy link
Collaborator

debug-level tracing (...) is now enabled during the CI

@0xc0170 Really? trace should not be enabled by default....

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 13, 2019

@jeromecoutant This was to help debugging the previous issues, before we start a new CI, will disable that.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 13, 2019

CI restarted (tracing disabled)

@mbed-ci
Copy link

mbed-ci commented Nov 13, 2019

Test run: FAILED

Summary: 1 of 11 test jobs failed
Build number : 8
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 13, 2019

@kyle-cypress One failure for k64f in the logs, please review

mbedgt: :463::FAIL: Expected 0 Was 263 [1573647330.85][CONN][RXD] :463::FAIL: Expected 0 Was 263

Looks like deinit test case failing only, @ARMmbed/mbed-os-storage would you be able to reproduce this one for k64f?

@adbridge
Copy link
Contributor

@kyle-cypress Looks like the failure is K64F on gcc_arm:

[1573647393.38][CONN][INF] found KV pair in stream: {{__testcase_finish;SEC_kvstore_deinit;1;0}}, queued...
[1573647393.48][CONN][RXD] >>> Test cases: 110 passed, 1 failed with reason 'Test Cases Failed'
[1573647393.48][CONN][RXD] >>> TESTS FAILED!

@maclobdell
Copy link
Contributor

@adbridge, @0xc0170 - K64F does not have QSPIF. I strongly believe these failures are unrelated to the changes in this PR and are a result of unstable kvstore tests.

@maclobdell
Copy link
Contributor

after talking to the maintainers, I think the K64F test fail could be real. I will test it manually. Since the kvstore tests were touched and this PR is the only one that K64F kvstore tests are failing, it needs t obe investigated. Perhaps another increase of stack size is necessary. Will try to resolve by the end of today. Any help and support anyone can provide is much appreciated.

@kyle-cypress
Copy link
Author

Thanks @maclobdell . Please let me know if you need any help debugging. For reference, the commit that changed that test is 92829bd (a1c7403 also touches that file, but just to add PSOC6 to the set of targets on which it runs).

@kyle-cypress
Copy link
Author

The kvstore failure on K64F definitely seems to be intermittent though. In the second run of the results referenced by #11531 (comment), the kvstore tests pass on K64F and the only failure was networking related.

@adbridge
Copy link
Contributor

@0xc0170 CI now seems to have passed on this ?

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 13, 2019

yes, restarted as above made a point about the last run (this confirms it, 2x subsequent run are all OK). Lets get this in and check nightly in the morning

@0xc0170 0xc0170 merged commit 539779f into ARMmbed:master Nov 13, 2019
@maclobdell
Copy link
Contributor

I have been running kvstore tests on 3 different FRDM-K64F on the master branch, before and after this PR was merged. I see different intermittent failures across different boards, but I see the same failures before and after this PR.

mostly I see these tests failing, but it doesn't seem to be related at all to this PR, unless the flash is getting left in a weird state and causing the test to fail subsequent runs.

features-storage-tests-kvstore-filesystemstore_tests | Testing Edge Cases
features-storage-tests-kvstore-general_tests_phase_1 | TDB_kvstore_init

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 14, 2019

Thanks @maclobdell for the report. I've just noticed failures in some other PRs and nightly as well, going to create a new issue to track this.

Jookia added a commit to Jookia/mbed-os that referenced this pull request Mar 11, 2023
mbed-os PR 11531 introduced 4-byte addressing in the QSPIF block device:

ARMmbed#11531

During testing it was found that this code broke on the NRF52840_DK and
DISCO_F769NI.

The NRF52840_DK controller seems unable to handle 4-byte addressing at
all and has been disabled entirely in another code section.

The DISCO_F769NI breakage was attributed to the flash chip but after more
research I believe this is related to the QSPI controller, not the 4-byte
addressing itself.

Now that the QSPI controller has a workaround, enable 4-byte addressing
again and hope it works fine this time.
Jookia added a commit to Jookia/mbed-os that referenced this pull request Mar 11, 2023
mbed-os PR 11531 introduced 4-byte addressing in the QSPIF block device:

ARMmbed#11531

During testing it was found that this code broke on the NRF52840_DK and
DISCO_F769NI.

The NRF52840_DK controller seems unable to handle 4-byte addressing at
all and has been disabled entirely in another code section.

The DISCO_F769NI breakage was attributed to the flash chip but after more
research I believe this is related to the QSPI controller, not the 4-byte
addressing itself.

Now that the QSPI controller has a workaround, enable 4-byte addressing
again and hope it works fine this time.
multiplemonomials pushed a commit to mbed-ce/mbed-os that referenced this pull request Mar 21, 2023
* STM32F7: Unconditionally enable QSPI workarounds

On the STM32769NI at least this patch is required for stable QSPI use.
Enable it uncondtionally in case other boards need it too.

Further discussions:

ARMmbed#10049
ARMmbed#15108

STMicroelectronics/STM32CubeF7#52
STMicroelectronics/STM32CubeF7#82

* QSPIF: Attempt 4-byte addressing on Macronix chips

mbed-os PR 11531 introduced 4-byte addressing in the QSPIF block device:

ARMmbed#11531

During testing it was found that this code broke on the NRF52840_DK and
DISCO_F769NI.

The NRF52840_DK controller seems unable to handle 4-byte addressing at
all and has been disabled entirely in another code section.

The DISCO_F769NI breakage was attributed to the flash chip but after more
research I believe this is related to the QSPI controller, not the 4-byte
addressing itself.

Now that the QSPI controller has a workaround, enable 4-byte addressing
again and hope it works fine this time.
Jookia added a commit to Jookia/mbed-os that referenced this pull request May 8, 2023
mbed-os PR 11531 introduced 4-byte addressing in the QSPIF block device:

ARMmbed#11531

During testing it was found that this code broke on the NRF52840_DK and
DISCO_F769NI.

The NRF52840_DK controller seems unable to handle 4-byte addressing at
all and has been disabled entirely in another code section.

The DISCO_F769NI breakage was attributed to the flash chip but after more
research I believe this is related to the QSPI controller, not the 4-byte
addressing itself.

Now that the QSPI controller has a workaround, enable 4-byte addressing
again and hope it works fine this time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants