Skip to content

[feature-nrf528xx] NRF52 SPI and I2C re-implementation #6296

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

Merged
merged 3 commits into from
Mar 15, 2018
Merged

[feature-nrf528xx] NRF52 SPI and I2C re-implementation #6296

merged 3 commits into from
Mar 15, 2018

Conversation

marcuschangarm
Copy link
Contributor

This PR re-implements SPI and I2C in a way that lets both drivers share the underlying hardware. From the new README.md file:

SPI and I2C

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:

Instance 0 Instance 1 Instance 2
SPI0/SPIM0 SPI1/SPIM1 SPI2/SPIM2
TWI0/TWIM0 TWI1/TWIM1

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:

  1. The driver will look up the pins in the configuration table and pick a pre-assigned instance.
  2. 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.
  3. 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.
  4. 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.

Customization

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.

const PinMapI2C PinMap_I2C[] = { 
    {p1, p2, 1},
    {NC, NC, NC}
};

const PinMapSPI PinMap_SPI[] = {
    {p3, p4, p5, 2},
    {p6, p7, p8, 0},
    {NC, NC, NC, NC}
};

The tables must be placed in a C compilation file.

Concurrency

  1. When called from the same thread, it is safe to assign I2C and SPI objects to the same instance.
  2. If an instance is being used exclusively for either I2C or SPI, the objects can safely be called from multiple threads.
  3. If an instance is being used for both I2C and SPI, the user must provide thread safety between the objects.

sarahmarshy and others added 3 commits March 7, 2018 12:52
Implement spi_api.c for NRF52X boards using SDK14.

This driver does not implement SPI slave functions and does not use SPIM.
When possible, the I2C HAL will now use the TWI driver in SDK 14.

The manual I2C API still maps onto the old TWI peripheral directly
because the TWI driver doesn't provide the needed low-level functionality.
Added SPI and I2C section.
@0xc0170
Copy link
Contributor

0xc0170 commented Mar 12, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Mar 12, 2018

Build : SUCCESS

Build number : 1420
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6296/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@cmonr
Copy link
Contributor

cmonr commented Mar 12, 2018

Test CI canceled due to 5.8.0-RC2 generation. Will resume once 5.8.0-RC2 is released.

@mbed-ci
Copy link

mbed-ci commented Mar 12, 2018

@cmonr
Copy link
Contributor

cmonr commented Mar 15, 2018

/morph test

@mbed-ci
Copy link

mbed-ci commented Mar 15, 2018

@0xc0170 0xc0170 merged commit 42f4982 into ARMmbed:feature-nrf528xx Mar 15, 2018
@marcuschangarm marcuschangarm deleted the feature-spi2c-2 branch April 5, 2018 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants