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

TWAI: GPIO pins are not configured as input and output #1906

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix PARL_IO async-rx (#1851)
- SPI: Clear DMA interrupts before (not after) DMA starts (#1859)
- SPI: disable and re-enable MISO and MOSI in `start_transfer_dma`, `start_read_bytes_dma` and `start_write_bytes_dma` accordingly (#1894)
- TWAI: GPIO pins are not configured as input and output (#1906)

### Removed

Expand Down
27 changes: 27 additions & 0 deletions esp-hal/src/twai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,41 @@ where
// Enable the peripheral clock for the TWAI peripheral.
T::enable_peripheral();

// Set RESET bit to 1
T::register_block()
.mode()
.write(|w| w.reset_mode().set_bit());

// Set up the GPIO pins.
crate::into_ref!(tx_pin, rx_pin);
if no_transceiver {
tx_pin.set_to_open_drain_output(crate::private::Internal);
}
tx_pin.set_to_push_pull_output(crate::private::Internal);
tx_pin.connect_peripheral_to_output(T::OUTPUT_SIGNAL, crate::private::Internal);
rx_pin.set_to_input(crate::private::Internal);
rx_pin.connect_input_to_peripheral(T::INPUT_SIGNAL, crate::private::Internal);

// Set mod to listen only first
T::register_block()
.mode()
.modify(|_, w| w.listen_only_mode().set_bit());

// Set TEC to 0
T::register_block()
.tx_err_cnt()
.write(|w| unsafe { w.tx_err_cnt().bits(0) });

// Set REC to 0
T::register_block()
.rx_err_cnt()
.write(|w| unsafe { w.rx_err_cnt().bits(0) });

// Set EWL to 96
T::register_block()
.err_warning_limit()
.write(|w| unsafe { w.err_warning_limit().bits(96) });

let mut cfg = TwaiConfiguration {
peripheral: PhantomData,
phantom: PhantomData,
Expand Down