Skip to content

Commit 42f4982

Browse files
Marcus Chang0xc0170
authored andcommitted
README file for NRF52 HAL implementation
Added SPI and I2C section.
1 parent bac9ded commit 42f4982

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Mbed HAL Implementation Details
2+
3+
### SPI and I2C
4+
5+
The TWI/TWIM (I2C) and SPI/SPIM module shares the same underlying hardware and each instance can only provide one functionality at a time. Both the NRF52832 and NRF52840 have 2 TWI/TWIM modules and 3 SPI/SPIM:
6+
7+
| Instance 0 | Instance 1 | Instance 2 |
8+
| :---: | :---: | :---: |
9+
| SPI0/SPIM0 | SPI1/SPIM1 | SPI2/SPIM2 |
10+
| TWI0/TWIM0 | TWI1/TWIM1 | |
11+
12+
When instantiating a new Mbed SPI object or I2C object, the object will be assigned a hardware instance. By default, the HAL implementation will automatically pick a hardware instance based on the assigned pins in the following order:
13+
14+
1. The driver will look up the pins in the configuration table and pick a pre-assigned instance.
15+
1. If the pins can't be found in the configuration table, the driver will check if a hardware instance has already been assigned to those pins so that objects using the same pins will share the same instance.
16+
1. If no instance has been assigned, the driver will look for a free instane. For I2C objects instances are assigned from 0 to 1. For SPI objects instances are assigned from 2 to 0. This ensures that no matter the order of instantiation the first three objects can be guaranteed to be on separate instances no matter the pins being used.
17+
1. If no unused instance can be found, objects not sharing any pins will be assigned to the same default instance, which is `Instance 0` for I2C and `Instance 2` for SPI.
18+
19+
#### Customization
20+
21+
A custom configuration table can be provided by overriding the weakly defined default empty table. In the example below, I2C objects using pins `p1` and `p2` for `SDA` and `SCL` will always be assigned to `Instance 1` and SPI objects using pins `p3`, `p4`, `p5` for `MOSI`, `MISO`, and `CLOCK` will be assigned to `Instance 2` and SPI objects using pins `p6`, `p7`, and `p8` will be assigned to `Instance 0`. The custom configuration table must always be terminated with a row of `NC`.
22+
23+
```
24+
const PinMapI2C PinMap_I2C[] = {
25+
{p1, p2, 1},
26+
{NC, NC, NC}
27+
};
28+
29+
const PinMapSPI PinMap_SPI[] = {
30+
{p3, p4, p5, 2},
31+
{p6, p7, p8, 0},
32+
{NC, NC, NC, NC}
33+
};
34+
```
35+
36+
The tables must be placed in a C compilation file.
37+
38+
#### Concurrency
39+
40+
1. When called from the same thread, it is safe to assign I2C and SPI objects to the same instance.
41+
1. If an instance is being used exclusively for either I2C or SPI, the objects can safely be called from multiple threads.
42+
1. If an instance is being used for both I2C and SPI, the user must provide thread safety between the objects.

0 commit comments

Comments
 (0)