Skip to content

Commit a825735

Browse files
committed
drivers/periph_{i2c,spi}: fix doc on initialization
Both SPI and I2C peripheral drivers *MUST NOT* be initialized by the application code / (non-peripheral) device driver, as this is done automatically be default. Some peripheral drivers have a non-idempotent initialization and initializing them twice will break things. Sadly, the doc states the exact opposite. This updates the documentation to match the implementation. In addition the special case is pointed out of disabling the automatic initialization during boot, in which case the app indeed has to do the initialization.
1 parent 2416dc3 commit a825735

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

drivers/include/periph/i2c.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
* this example does not check any return values...):
2424
*
2525
* @code{c}
26-
* // initialize the bus (this is normally done during boot time)
27-
* i2c_init(dev);
28-
* ...
2926
* // before accessing the bus, we need to acquire it
3027
* i2c_acquire(dev);
3128
* // next we write the register address, but create no STOP condition when done
@@ -40,9 +37,6 @@
4037
* 7-bit device addressing:
4138
*
4239
* @code{c}
43-
* // initialize the bus
44-
* i2c_init(dev);
45-
* ...
4640
* // first, acquire the shared bus again
4741
* i2c_acquire(dev);
4842
* // write the 16-bit register address to the device and prevent STOP condition
@@ -205,6 +199,11 @@ typedef enum {
205199
* The bus MUST not be acquired before initializing it, as this is handled
206200
* internally by the i2c_init function!
207201
*
202+
* @warning This function **MUST NOT** be called by the user unless you add
203+
* `DISABLE_MODULE += periph_init_i2c` to your `Makefile`. If you
204+
* do so, call this function before any call to `i2c_acquire()`,
205+
* and call no more than **once**.
206+
*
208207
* @param[in] dev the device to initialize
209208
*/
210209
void i2c_init(i2c_t dev);

drivers/include/periph/spi.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
* low-power mode to save energy.
3535
*
3636
* The SPI unit's initialization is split into 3 parts:
37-
* 1. `spi_init()` should be called once for each SPI unit defined by a board
38-
* during system initialization.
37+
* 1. The SPI buses are automatically initialized during boot according to the
38+
* specification in board's `periph_conf.h`. (The exact format depends on the
39+
* MCU used.) See @ref spi_init for details.
3940
* 2. `spi_init_cs()` should be called during device driver initialization, as
4041
* each chip select pin/line is used uniquely by a specific device, i.e. chip
4142
* select lines are no shared resource.
@@ -198,14 +199,17 @@ typedef enum {
198199
* MISO, MOSI, and CLK pins. After initialization, the given device should be
199200
* in power down state.
200201
*
201-
* This function is intended to be called by the board initialization code
202-
* during system startup to prepare the (shared) SPI device for further usage.
203-
* It uses the board specific initialization parameters as defined in the
204-
* board's `periph_conf.h`.
202+
* This function is called internally during system startup to prepare the
203+
* (shared) SPI device for further usage. It uses the board specific
204+
* initialization parameters as defined in the board's `periph_conf.h`.
205205
*
206206
* Errors (e.g. invalid @p bus parameter) are not signaled through a return
207207
* value, but should be signaled using the assert() function internally.
208208
*
209+
* @warning This function **MUST NOT** be called by the user unless you add
210+
* `DISABLE_MODULE += periph_init_spi` to your `Makefile`. If you
211+
* do so, call this function before any call to `spi_acquire()`,
212+
* and call no more than **once**.
209213
* @note This function MUST not be called more than once per bus!
210214
*
211215
* @param[in] bus SPI device to initialize

0 commit comments

Comments
 (0)