cpu/nrf52 i2c: Always buffer writes#20298
Merged
chrysn merged 2 commits intoRIOT-OS:masterfrom Jan 25, 2024
Merged
Conversation
The underlying peripheral can only read from RAM. This uses the existing infrastructure (already needed to work around the lack of a hardware support for I2C_NOSTART) to unconditionally copy any to-be-sent data into RAM.
benpicco
reviewed
Jan 25, 2024
benpicco
approved these changes
Jan 25, 2024
Member
|
The branch name is quite confusing :D |
Member
Author
|
If that's confusing than please don't look at #20299, which is |
kaspar030
reviewed
Jan 25, 2024
| int i2c_write_bytes(i2c_t dev, uint16_t addr, const void *data, size_t len, | ||
| uint8_t flags) | ||
| { | ||
| if ((unsigned int)data >= CPU_RAM_BASE && (unsigned int)data < CPU_RAM_BASE + CPU_RAM_SIZE) { |
Contributor
There was a problem hiding this comment.
This is done a bit simpler for spi:
Would that work here, too? Is that too relaxed for SPI?
Contributor
There was a problem hiding this comment.
... embassy-nrf does this:
const SRAM_LOWER: usize = 0x2000_0000;
const SRAM_UPPER: usize = 0x3000_0000;
ptr >= SRAM_LOWER && (ptr + len * core::mem::size_of::<T>()) < SRAM_UPPER
Member
Author
There was a problem hiding this comment.
The SPI version is probably good enough, we could unify. The embassy version is IMO excessive, as the slice is a single object, and objects don't span memmapping areas.
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.
Contribution description
The underlying peripheral can only read from RAM. This uses the existing infrastructure (already needed to work around the lack of a hardware support for I2C_NOSTART) to unconditionally copy any to-be-sent data into RAM.
There is certainly an alternative where we determine at runtime whether the data is in RAM or in ROM and only lock and copy if it's in ROM, but I'd only do that if we have concrete benchmarks that show that this is an issue.
Testing procedure