-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cpu/sam0_common: Implement time-sharing of SERCOMs #21029
base: master
Are you sure you want to change the base?
Conversation
@@ -104,7 +104,7 @@ static const adc_conf_chan_t adc_channels[] = { | |||
*/ | |||
static const i2c_conf_t i2c_config[] = { | |||
{ | |||
.dev = &(SERCOM3->I2CM), | |||
.sercom = 3, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have sercom_id()
, that would be less invasive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit more efficient, though. And the conversion is pretty straight-forward.
But I can change this to use sercom_id()
, if you prefer compatibility with out-of-tree boards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the verdict? Use uint8_t sercom
and touch all boards for better efficiency, or stick with void *dev
for backward compatibility with out-of-tree boards?
This adds a `periph_sercom` feature and implementation which `periph_i2c`, `periph_uart`, and `periph_spi` are implemented on top. This allows for sharing a single SERCOM instance to provide multiple serial interfaces (in round-robin time-sharing fashion). Note: In practice, a SERCOM can often not be shared if it needs to provide an UART. Background: While code using the I2C/SPI APIs is already optimized to share the peripheral with `i2c_acquire()`/`spi_acquire()` and `i2c_release()`/`spi_release()`, UARTs are typically not shared and most users will not call `uart_poweron()` and `uart_poweroff()` to only have the SERCOM in UART mode when actually needed. Worse: For many use cases (such as stdin), the UART will need to be constantly running, as receiving data happens asynchronously at unpredictable points in time.
Now that sharing SERCOMs is implemented, we can make use of that :) A warning is emitted if this is actually done, as sharing with UART is often not working as expected.
Calling `uart_poweroff()` when done with the UART test allows sharing the underlying hardware e.g. to provide other peripheral interfaces. One example of this would be the SERCOM3 on the Adafruit Metro M4 Express that is used to provide UART on D1/D0 and SPI on D11/D12/D13.
We cannot use the D0/D1 UART if it is also used for STDIO. However, the logic did not take into account whether `stdio_uart` was used at all. This fixes the issue.
The M4 Express does now have an I2C and an UART compatible with Arduino Shields, so we can expose them.
1baf069
to
f9c952d
Compare
Also detect TTY of bootloader with `MOST_RECENT_PORT=1`.
Contribution description
This adds a
periph_sercom
feature and implementation whichperiph_i2c
,periph_uart
, andperiph_spi
are implemented on top. This allows for sharing a single SERCOM instance to provide multiple serial interfaces (in round-robin time-sharing fashion).Note
In practice, a SERCOM can often not be shared if it needs to provide an UART.
Background:
While code using the I2C/SPI APIs is already optimized to share the peripheral with
i2c_acquire()
/spi_acquire()
andi2c_release()
/spi_release()
, UARTs are typically not shared and most users will not calluart_poweron()
anduart_poweroff()
to only have the SERCOM in UART mode when actually needed. Worse: For many use cases (such as stdin), the UART will need to be constantly running, as receiving data happens asynchronously at unpredictable points in time.Testing procedure
make BOARD=adafruit-metro-m4-express flash term -C tests/periph/selftest_shield
2024-11-21 20:29:42,410 # ALL TESTS SUCCEEDED
Issues/PRs references
None