sensor creator init split#2445
Merged
Merged
Conversation
sysinit stage for flash map is currently 2. It leaves very little space for additional code that should be executed before flash_map is initialized but after OS is created. If some package initialization is to be executed before flash_map, setting its stage to 1 is risky since OS is stage 1.
This splits existing function sensor_dev_create(). All the devices are still created in this function but code that actually accessed them is moved to separate function sensor_dev_init(). This is really needed in case when SPI flash is used in flash map. Flash map is initialized in early stage. If by that time devices that are connected to the same SPI bus are not created yet, GPIO that is used for chip selection may be perceived as active since it was not configured yet. In such case two devices (SPI flash and some SPI sensor) could try to respond at the same time and SPI flash command responses can be corrupted.
Style check summaryNo suggestions at this time! |
vrahane
approved these changes
Dec 18, 2020
Contributor
vrahane
left a comment
There was a problem hiding this comment.
Looks good. That was a really good catch. The config for the sensors should have taken care of this situation as it would configure the spi accordingly but this seems like a cleaner solution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This solves the problem of sensor_creator usage along with SPI flash that is present in flash map.
If BSP uses SPI flash and sensor creator with SPI devices that are connected to the same
SPI bus as flash, not initializing chip select pin for those other devices may lead to wrong
reads from flash.
It happens when uninitialized yet GPIO is still perceived by sensor as active and sensor responds
to requests that should be answered by flash.
This adds sensor_dev_init() that has initialization code taken from sensor_dev_create().
Thai also changes flash_map initialization stage to accommodate for other initialization that
could be needed before flash_map can be initialized.