6 years, 8 months ago.

Program for STM32F411RE won't compile.

After about a week of MBED weirdness my program won't compile. I get the error

Error: "mbed::NonCopyable<T>::NonCopyable(const mbed::NonCopyable<T> &) [with T=mbed::I2C]" (declared at <a href="#" onmousedown="mbed_doc_goto('/Bicycl_Computer_NUCLEO-F411REextras/mbed_a97add6d7e64/platform/NonCopyable.h', '157'); return false;">/extras/mbed_a97add6d7e64/platform/NonCopyable.h:157</a>) is inaccessible in "extras/mbed_a97add6d7e64/drivers/I2C.h", Line: 57, Col: 22

This program use to compile just fine. I have checked that it has the correct hardware. NonCopyable.h?

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F411RET6 microcontroller.

It looks like you're trying to copy an I2C instance. What's your code?

posted by Jan Jongboom 02 Aug 2017

2 Answers

6 years, 8 months ago.

Quote:

just declare the SPI-interface globally

Libraries could not access your objects in your application, you have to pass them.

Quote:

delete that it inherits from NonCopyable.h

I think it is not a good idea to modify the mbed core. There is a reason for this limitation. Copying objects needs memory and CPU time. Instead, you should pass a pointer to the I2C, SPI, etc object without copying. Cleaner and faster. This is a new requirement in mbed, and a lot of libraries copies the object passed in their constructor. They have to be updated by their authors, or you can modify them and make a pull request. (I have to change my libs also.)

You have to change this

class ClassUsesI2C
{
public:
ClassUsesI2C(I2C &i2c) :
        _i2c(i2c),
    {};
private:
	I2C _i2c;
}

I2C i2c(PIN_I2C_SDA, PIN_I2C_SCL);
ClassUsesI2C instance(i2c);

To this

class ClassUsesI2C
{
public:
ClassUsesI2C(I2C *i2c) :
        _i2c(i2c),
    {};
private:
	I2C *_i2c;
}

I2C i2c(PIN_I2C_SDA, PIN_I2C_SCL);
ClassUsesI2C instance(&i2c);

Accepted Answer

I agree with Jan and Mark. I think in your case the issue is with the BNO055 library:

BNO055.h

...
    /** Configure data pin (with other devices on I2C line)
      * @param I2C previous definition
      * @param device address
      */
    BNO055(I2C& p_i2c, PinName p_reset, uint8_t addr, uint8_t mode);

    /** Configure data pin (with other devices on I2C line)
      * @param I2C previous definition
      * @param Other parameters are set default data
      */
    BNO055(I2C& p_i2c, PinName p_reset);
...


BNO055.cpp

...
BNO055::BNO055 (I2C& p_i2c, PinName p_reset, uint8_t addr, uint8_t mode) :
    _i2c(p_i2c), _res(p_reset)
{
    chip_addr = addr;
    chip_mode = mode;
    initialize ();
}

BNO055::BNO055 (I2C& p_i2c, PinName p_reset) :
    _i2c(p_i2c), _res(p_reset)
{
    chip_addr = BNO055_G_CHIP_ADDR;
    chip_mode = MODE_NDOF;
    initialize ();
}
...

Since you do not use any of these constructors a simple fix is to comment them out.

NOTE: You have done a nice job. Keep on!

posted by Zoltan Hudak 04 Aug 2017

You are all life savers! I have an offline version in Keil that worked because of the older library. Thanks for looking out for the hobbyist. I don't do this for a living. I am a electrical engineer. Thanks!

posted by Darren Ulrich 04 Aug 2017
6 years, 8 months ago.

I had a similar problem with SPI in the mbed-releases > 145. In my case the problem was, that I passed the SPI-interface as parameter to a function (which worked fine until mbed 146 was released). In my case there were two ways to get it done, first, - just declare the SPI-interface globally and let the function use the bus directly - use the mbed-dev library, look for the driver (i2c.h in your case) and delete that it inherits from NonCopyable.h (I don't know if there are any side-effects, in my case this also worked fine, but it was annoying to "fix" it after every update).

I hope I described it understandable, english isn't my native language, and sometimes complex things are a bit difficult to describe ;),.