Mbed-os: Nordic RF52 does not correctly support dynamically created SPI/I2C (TWI) devices

Created on 18 Jan 2018  路  9Comments  路  Source: ARMmbed/mbed-os

Mbed 5.6/5.7
Target: Nordic RF52832

The 52832 supports up to 3 simultaneous SPI/I2C buses. Our board requires 1xI2C and 3xSPI so we statically allocate an I2C and SPI bus then dynamically allocate the remaining bus controller as required.

Unfortunately the reallocation of both I2C and SPI TWO blocks is broken. This code will quickly fault...

 I2C *i2c = new I2C(p16, p15);
 SPI *storageSPI = new SPI(p9, p10, p14);
 while (true)
 {
SPI *gpsSpi = new SPI(p29, p28, p30, p31);
 delete gpsSpi;
SPI *espSpi = new SPI(p6, p8, p7);
delete espSpi;
}

There is a comment in spi_init that indicates that the mbed SPI class does not call spi_free from the destructor. This is true but even if the call is made and the 'bodge' code in spi_init is removed, it doesn't seem possible to correctly reuse previously-freed buses.

drivers nordic bug

All 9 comments

Adding @MarceloSalazar Might be fixed in https://github.com/ARMmbed/mbed-os/pull/5726

Related to https://github.com/ARMmbed/mbed-os/issues/5843
cc @dlfryar @marcuschangarm

Further info... If spi_free(&_spi); is called in the SPI destructor and the first block of code in spi_init is removed then it is possible to reallocate a previously deleted SPI block but it can't be read/written. The spi_free code appears to be sufficient to clear any hardware state in the TWI block and it then marks the initialised flag as false which means the hardware should be set up correctly on reallocation but perhaps there is a missing step? Needs input from Nordic.

@NeilMacMullen I wouldn't bet on #5726. Those changes are slated to enter a feature branch, not the main branch, and there's no eta as to when they'll be merged together.

@ARMmbed/team-nordic

Reproduced on a NRF52-DK.

cc @nvlsianpu

We have a PR up for our new SPI and I2C driver on our feature branch: https://github.com/ARMmbed/mbed-os/pull/6296

You can follow SDK 14.2 updates here: https://os.mbed.com/forum/upcoming-features/topic/29477/

The feature branch shared above was integrated, it's now on master. This should be resolved

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rbonghi picture rbonghi  路  3Comments

ghost picture ghost  路  4Comments

sarahmarshy picture sarahmarshy  路  4Comments

DuyTrandeLion picture DuyTrandeLion  路  3Comments

ccchang12 picture ccchang12  路  4Comments