Configuring Torizon Extensions so that when you run your application within the Studio '19 it starts docker with the correct environment flags to see the /dev/i2c in user space

To probe my i2c buses, I run a Debian docker command and add the libi2c-dev and i2c-tools tookits.

$ docker run -it --privileged torizon/debian:$CT_TAG_DEBIAN /bin/bash

“apt update && apt install --fix-missing libi2c-dev i2c-tools -y”

On the “standard i2c” device which maps to the /dev/i2c-17 in user space.

root@colibri-imx8x-06800883:/home/torizon# i2cdetect -l

i2c-17 unknown 5a810000.i2c N/A

i2c-18 unknown 56226000.i2c N/A

i2c-16 unknown 5a800000.i2c N/A

root@1622d8fba750:/# i2cdetect -y 17

 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

00: – – – – – – – – – – 0d – –

10: – – – – – – – – – – – – – – – –

20: – – – – – – – – – – – – – – – –

30: – – – – – – – – – – – – – – – –

40: – – – – – – – – – – – – – – – –

50: – – – – – – – – – – – – – – – –

60: – – – – – – – – UU – – – – – – –

70: – – – – – – – –

The device is 0x0d ready to register to. So back to Microsoft Studio with the Torizon extensions.

The thing I need to know I think, is how to set things up so that Studio '19 on using the extensions runs docker with the --privileged flag so it can see the devices.

The tutorial “Install Debian Packages on Torizon Container” doesnt explain how this can be achieved. I.e. how the Torizon container is set up in Studio, so that it compiles and runs in the docker container. All day so far, I have looked around and can’t see how this is done.

I tried creating a custom container
https://developer.toradex.com/knowledge-base/modifying-our-based-container-images

colibri-imx8x-06800883:~$ cat Dockerfile

FROM torizon/debian:$CT_TAG_DEBIAN
RUN apt update -y && apt install -y i2c-tools -y && apt clean && apt autoremove && rm -rf /var/lib/apt/lists/*

colibri-imx8x-06800883:~$ docker build .
Sending build context to Docker daemon 19.46kB
Step 1/2 : FROM torizon/debian:$CT_TAG_DEBIAN
invalid reference format
colibri-imx8x-06800883:~$

That didn’t work either…

The technical note C/C++ Development and Debugging on Torizon Using Visual Studio doesn’t really help me.

I know I need to modify the containers somehow, as I think I need to add ‘libi2c-dev.h’ at least, but how!!!

If you know please can you signpost me to it !!

Regards

Richard

— Here is my C++ code to access my battery on i2c-17 -------------------------

I have a simple program (two snippets shown below)

a) main

int main(void)
{
printf("\nSmart Battery Interface Tests %i\n\n", VERSION);

Smart_battery_interface battery(17);

};

b) which sets up the battery

Smart_battery_interface::Smart_battery_interface(uint8_t bus_number) : bus_number(bus_number)
{
device_file = invalid_device_file;
}

Smart_battery_interface::~Smart_battery_interface(void)
{
terminate();
}

bool Smart_battery_interface::initialise(void)
{
bool result = false;
char device_filename[FILENAME_MAX];
snprintf(device_filename, sizeof(device_filename), “/dev/i2c-%d”, bus_number);
printf(“filename is %s\n”, device_filename);
device_file = open(device_filename, O_RDWR);
printf(“device file came back %i\n”, device_file);

if (0 > device_file)
{
    printf("Failed to open I2C bus number /dev/i2c-%d\n", bus_number);
    printf("Failed to open I2C device_file %s\n", device_filename);
}
else if (0 > ioctl(device_file, I2C_SLAVE, smart_battery_address))
{
    printf("ioctl of smart battery I2C_SLAVE address 0x%02X failed...", smart_battery_address);
    terminate();
}
else
{
    result = true;
}
return result;

}

Which when it runs sends this out to the Linux window

Smart Battery Interface Tests 1

filename is /dev/i2c-17
device file came back -1
Failed to open I2C bus number /dev/i2c-17
Failed to open I2C device_file /dev/i2c-17
Error initialising smart battery interface

Hi @FatLinux,

It’s all a matter of configuring the Extension parameters.

Please have a look at this article, which talks bout I2C Development on Torizon.

In specific, please have a look at the section about “User-space Container Access”.

I don’t know if you are familiar with the windows for changing Torizon Application properties, but you can find more details at Visual Studio Extension for Torizon.

See this gif with instructions on how to get to that panel.

Please let me know if that helped.

Best regards,
André Curvello

Hi Andre,

No still struggling with this.

Just want to write code in Vis Studio and access the user space devices on the board. Not much more!

Ideally I want to develop my app, and allow visual tools to do the abstraction between the app and containers.

There is no help file or examples to demonstrate how I would apply the settings what would normally reside in a Dockerfile, applied to the container that the Torizon extension builds

I need to add this flag onto the command to build the container… --device /dev/i2c-17

So does the platform/application.devices field in the torizon application properties dialog allow me to define the devices I want to use?

Otherwise, where in the Torizon extension is this to be specified?

So I need to add these to the Dockerfile, which appears to be the property: application.buildcommands, which doesn’t work as yet, as I haven’t guessed the syntax quite yet.

RUN apt-get -y update && apt-get install -y i2c-tools && apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*

RUN usermod -a -G i2cdev torizon
maybe also add…

RUN groupadd --gid 51 i2cdev

The actual Visual Studio Extension for Torizon is brilliant. The Visual studio has extension has a dialog with the option to add a variety of Torizon Application Properties, but then the documentation for the Visual Studio Extension for Torizon is very weak.

Any help gratefully received

Regards

Richard

Hi @FatLinux,

We are discussing internally about the improvements on Torizon Extension for Visual Studio.

In order to get to the Application configuration Panel, have you seen this gif?

On Configuration Properties, there is a “Device” section, in which you can add the devices you want to map.

Any input you think would be valuable to mention, @jeremias.tx ?

Please let me know if that helped.

Best regards,
André Curvello

The article here shows how to do the same process but with GPIO: https://developer.toradex.com/gpio-visual-studio-plugin#Add_libgpiod_library_and_the_GPIO_device_to_the_application

Just need to alter for I2C devices/access, otherwise it’s similar syntax.

Hi Jeremias / Andrea,

Thanks for the pointer. I just didnt see this article, even after searching. With it I had the job done.

So for future reference, to get a second I2C on the colibri with an imx8 module, a tiny change to the device tree did the trick: the i2c-18 up and running in about 3 minutes, on pins (SCL =140, and SDA =142)

// enable the i2c0_mipi_lvds0

&i2c0_mipi_lvds0 {

status = “okay”; /* SMBUS standard device */

};

So using the I2C on VS-19 with torizon extensions, you need the following settings added to the GIF screen that Andre talks about in the previous comment.

(this one: https://docs.toradex.com/107292-bqohvmbsqn.gif)

buildcommands: RUN usermod -a -G i2cdev torizon
devpackages: i2c-tools:arm64 libi2c-dev:arm64
extrapackages: i2c-tools

plus

Devices: /dev/i2c-18 and /dev/i2c-17

So far, all the unit testing I have done and /dev/i2c-18 works just fine for a device that needs a standard speed. Just the ticket for the SM-bus battery.

I just got to get to grips with the UART and my first hardware bring up on this platform is done. Not too painful at all!

Best of luck,

Richard

Hi @FatLinux,

Thanks for providing this very well and detailed feedback.

I’m glad to know that your issue is solved.

Best regards,
André Curvello