115 Commits

Author SHA1 Message Date
Knaifhogg
9863406346 fix: stm32 i2c slave blocking r/w
This fixes an issue where the slave interface would time out when the
master goes from a short write to a read (e.g. when accessing memory
registers) with a START signal between. The previous implementation
would expect the full buffer length to be written before starting to
listen to new commands.

This also adds debug trace printing which helped during implemention and
testing.

Places error checking into a function inspired from a C implementation
of HAL.
2025-07-24 23:56:49 +02:00
jrmoulton
fb71139522
fix name change 2025-06-10 15:53:06 -06:00
jrmoulton
3b2dd2bad8
fmt 2025-06-10 15:53:02 -06:00
jrmoulton
cfad9798ff
merge new embassy changes 2025-06-10 15:48:36 -06:00
Fredrik Reinholdsen
47869d122a fix: Fix for #3888 async I2C read bug for introduced in #3887 in STM32 I2C v2 driver
In fixing a different timing related bug, #3887, a new bug was introduced causing I2C reads longer than 255 bytes to timeout for some I2C devices, #3888.
The issue was caused by incorrect branch order, and poll function being called unnecessarily.

Async I2C read poll function now only looks for I2C transfer complete reload (TCR) interrupts, intead of TCR and transfer complete (TC) interrupts,
since TC interrupts are not raised when AUTOEND bit is set.
2025-04-01 21:28:07 +02:00
Aaron Griffith
03f73ce339 stm32/i2c: disable peripheral when changing timings 2025-02-27 06:50:01 -05:00
Dario Nieuwenhuis
1780f8479e
Merge pull request #3878 from showier-drastic/i2c-v2-add-nack
stm32: i2c-v2: Add error handling
2025-02-17 19:52:41 +01:00
Fredrik Reinholdsen
7f4cce536a fix: Fix for async I2C v2 driver sequential read/write reads. Fixes #3887
For I2C devices that support variable length reads, sending chunks of data as long as the master keeps ACK:ing after each received byte, sequential reads will sometimes get out of sync, causing additional reads to return invalid data.

This was caused by a delay between awaiting the DMA read and sending the software STOP signal, which may result in the slave to have time to send a byte of data in between, causing potential miss-alignment. This would then cause subsequent reads to return invalid data.

Async write-reads now no longer send STOP after the initial write, matching the behaviour of the blocking version.
2025-02-15 12:06:49 +01:00
Shaw Drastin
1c1aea62d0 stm32: i2c-v2: Add error handling
Currently when error occurres, we have to wait for timeout, which is
less than ideal. Enable related interrupts, and return Err when error
occurres.
2025-02-12 21:16:18 +08:00
elagil
eba8089601 chore: fix build 2025-01-03 18:18:00 +01:00
jrmoulton
fc342915e6
add stm32 i2c slave example 2024-08-13 12:53:58 -06:00
jrmoulton
b4eb4a3d18
remove 10 bit support 2024-08-13 09:46:17 -06:00
jrmoulton
d1f5a4c5c7
fix ci 2024-08-13 09:46:17 -06:00
jrmoulton
c7b4a076cc
add drop guard, clear interrupts, fix len return 2024-08-13 09:46:17 -06:00
jrmoulton
8b50f2a58b
remove dead code when v1 2024-08-13 09:46:17 -06:00
jrmoulton
98437e39ee
move addr mask impl to be v2 only 2024-08-13 09:46:16 -06:00
jrmoulton
31f224f43c
move embedded hal impl to version modules to allow for 10bit addr on v2 2024-08-13 09:46:16 -06:00
jrmoulton
70dfbc03b0
Add more docs 2024-08-13 09:46:16 -06:00
jrmoulton
49357709ed
Move slave constructor to v2 module 2024-08-13 09:46:16 -06:00
jrmoulton
967fa1b2a2
stm32 i2c slave 2024-08-13 09:46:15 -06:00
Jamie Bird
18ba56534b Fix Formatting Issues 2024-06-21 15:29:02 +01:00
Jamie Bird
060d1f6e6f Fix: Ensure I2C bus is free before master-write operation
The I2C master-write function was failing when executed immediately after an I2C read operation, requiring manual delays to function correctly. This fix introduces a check to ensure the I2C bus is free before initiating the write operation.

According to the RM0399 manual for STM32H7 chips, the BUSY bit (Bit 15 in the I2C ISR register) indicates whether a communication is in progress on the bus. The BUSY bit is set by hardware when a START condition is detected and cleared when a STOP condition is detected or when PE = 0.

This fix prevents the write operation from starting until the BUSY bit is cleared.
2024-06-21 15:09:57 +01:00
Jan Špaček
41711195e3 stm32/i2c: use new_pin! macro 2024-06-01 19:46:39 +02:00
Jan Špaček
081afca3f0 stm32/rcc: replace generated enable/disable code with runtime info 2024-05-25 18:44:55 +02:00
Dario Nieuwenhuis
45a12fd41f stm32/i2c: remove peripheral generic param. 2024-05-21 01:25:49 +02:00
Dario Nieuwenhuis
913bb19a34 stm32/i2c: remove DMA generic params. 2024-04-15 23:40:12 +02:00
Sebastian Goll
0cfb65abc2 Add transaction stub to I2C v2 2024-03-27 01:36:06 +01:00
Dario Nieuwenhuis
eca9aac194 Fix warnings in recent nightly. 2024-03-20 16:39:09 +01:00
Sebastian Goll
4eb4108952 Fix build for I2C v2 targets 2024-03-20 03:33:15 +01:00
Dario Nieuwenhuis
7044e53af4 stm32/i2c: remove _timeout public API, share more code between v1/v2. 2023-12-18 18:24:55 +01:00
Dario Nieuwenhuis
bc65b8f7ec stm32/i2c: add async, dual interrupt scaffolding. 2023-11-24 23:55:45 +01:00
Andres Vahter
4f8c79c911 stm32 i2c: allow EHA traits without time feature 2023-11-24 15:56:19 +02:00
Andres Vahter
0f2208c0af stm32 i2c: remove mod dummy_time 2023-11-11 14:29:24 +02:00
Andres Vahter
6c42885d4a stm32 i2c: remove pub _timeout api 2023-11-11 14:05:58 +02:00
Andres Vahter
3b33cc4691 i2c: expose async api without needing time
This exposes I2C async API without needing "time" feature. With "time" feature additional async API with timeouts is exposed.
2023-11-10 16:04:25 +02:00
Dario Nieuwenhuis
66e399b5c6
Merge pull request #2035 from pbert519/stm_reset_and_enable
STM32: combine RccPeripherals reset() and enable() to enable_and_reset()
2023-10-12 14:09:13 +00:00
pbert
ecdd7c0e2f enable clock first 2023-10-12 11:04:44 +02:00
pbert
f65a96c541 STM32: combine RccPeripherals reset() and enable() to reset_and_enable() 2023-10-12 11:04:19 +02:00
Andres Oliva
e6c47c3718 cargo fmt 2023-10-11 23:47:24 +02:00
Andres Oliva
2f7c2750d1 Feature guarded more unused stuff 2023-10-11 23:45:47 +02:00
Andres Oliva
032b1f2d59 Fix some issues with unused stuff 2023-10-11 23:42:40 +02:00
Andres Oliva
f76d50e837 cfg! macro didn't work, had to duplicate functions with different guards 2023-10-11 23:39:24 +02:00
Andres Oliva
ee5ea7aa06 cargo fmt 2023-10-11 23:34:02 +02:00
Andres Oliva
251d004708 Try using cfg! macro 2023-10-11 23:32:40 +02:00
Andres Oliva
cd68f85501 Added guards to individual APIs 2023-10-11 23:25:13 +02:00
Andres Oliva
cd12c9cbce stm32: add timeout to I2C driver 2023-10-10 18:20:46 +02:00
xoviat
05218a52e6 stm32: update set_config 2023-10-01 09:39:10 -05:00
xoviat
274f63a879 stm32: fix refcounts for usart, spi, and i2c 2023-09-04 15:47:33 -05:00
Matt Ickstadt
26cc0e634d stm32: add async timeout functions to I2c and TimeoutI2c 2023-07-31 13:47:03 -05:00
Dario Nieuwenhuis
036e6ae30c
Rename embassy-hal-common to embassy-hal-internal, document it's for internal use only. (#1700) 2023-07-28 13:23:22 +02:00