Use memory fence when disabling cache to avoid -O2 problems #7398
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #7279.
Disabling the cache on SAMx5x caused problems when compiling with -O2, apparently due to inlining the microcontroller cache control routines.. Access to the external flash chip did not work.
Changes made:
external_flash.c
tries a little harder to make sure the flash chip is ready, by retrying fetching the JEDEC ID if necessary. Without this, if the chip was not actually ready, the ID would not be read, andflash_device
ended up being NULL.flash_device
was not NULL when asking for the device size. Previously, this could have returned a garbage value. I saw this cause incorrect data to be returned for MSC queries.Right now we don't actually compile any SAMx5x builds with
-O2
, so this change doesn't fix any presentlybroken builds. The nRF builds are-O2 -fno-inline-functions
, which may not provoke the optimization problems seen in SAMx5x. I did not remove-fno-inline-functions
in nRF, because it makes the-O2
builds smaller. (A while ago,-fno-inline-functions
was also used with-O2
in SAMx5x builds, before they got too big, and started needing-Os
.)Cortex-M0 doesn't have a cache, so this is not a problem at all for M0 builds. I looked at cache routines in
broadcom
, and they include fencing, though not as much. (Maybe worth exploring later.)