Gpio driver linux for new board/target

that worked. I assume that shouldnt be necessary though. the dtb being used is provided by seeedstudio for this board. I need to have the spidev module autoloaded also. I am not sure why when using the gy-91 I was not able to get it detected. It could also be that the pinout or something else is off

Loaded defaults from /home/awright/ardupilot.parm
000568182284091100425655212828100477782238891100568182284091100425655212828100477782238891100568182284091100425655212828100477782238891100425655212828100477782238891100425655212828100477782238891100425655212828100477782238891100425655212828100477782238891100Config Error: Baro: unable to initialise driver
Config Error: Baro: unable to initialise driver
Config Error: Baro: unable to initialise driver
Config Error: Baro: unable to initialise driver
Config Error: Baro: unable to initialise driver
Config Error: Baro: unable to initialise driver
Config Error: Baro: unable to initialise driver
Config Error: Baro: unable to initialise driver
Config Error: Baro: unable to initialise driver
Config Error: Baro: unable to initialise driver
Config Error: Baro: unable to initialise driver

Well,

Another test - using the gy-91.
When running the example BARO_generic example ?

With the gy-91 and the barometer test I also have issues with it being able to initialize the driver. I will need to see if I have another gy-91 breakout it may be a bad board.

In true,

are you having a sigfault running the Baro example?
If yes, don’t worry because I always receive a sigfault after a message of initializate or initialization baro.
and about the imu tests, is working with the gy ?

I didn’t explicitly receive a segfault or anything like that just almost the same behavior like it is being probed. I assume for the gy-91 it should be as simple as the chip select lines being set properly for it to work. I was able to get the mpu9250 detected fine on its own so maybe I need to look at the pinout again or get the dtc from the currently loaded dtb file to see if there is something there.

Some points.

Lets assume the mpu is working fine. Once the gy-91 use the same imu, when connecting the gy-91 the IMU is detected or not ?
Have you testes any kind of python script to test the gy-91 to isolate if the problem is the connection or the something in the ardupilot side ? like this one GitHub - ricardozago/GY91-MPU9250-BMP280: Libraries for use with GY91 10 dof board (MPU9250, MPU9255 and BMP280).

no I hadn’t found much libraries that seemed like they would work with spi. the majority has been i2c. I will definitely try this library. About to catch a flight in a couple hours and wont be able to test until sunday unfortunately.

Dont worry,

when testing you can ping me again. I believe the first thing is to isolate,if is a problem with the gy-91 connection and your board or ardupilot side.

So its been a while since my last update. I tried a few things and basically ended up RMA’ing the board through nvidia. I wasnt able to get the mpu9250 and other things that should work working. Even a simple spi loopback test was failing. I also treated myself to an orin nano. The jump from 18.04 to 22.04 may cause some issues when compiling ardupilot though. At the very least I should have a working tx2 nx in a few weeks hopefully. I can start messing the orin nano monday.

I’m back this time with the orin nano and an a603 carrier board. I have serial working and I can even see that the gy-91 is detected using the spidev-test. still unable to get gy-91 working with orin nano though, still works with the cm4 module. I was able to get the mpu9250 and assumed it would be a little config here and there to test a icm20948. Is the icm20948 supported under linux for ardupilot?

Once you have the spi device configured in the definition(AP_HAL/boards/linux.h) you can use the INS_generic test - compiled with ./waf examples

so I wasnt able to get the example compiled because of the mag. looking at the datasheet of the icm20948 it says the mag is a AK09916 and when using that it failed to compile.

define HAL_MAG_PROBE_LIST PROBE_MAG_IMU(AK09916, mpu9250, 0, ROTATION_NONE)

here is the error I get

../../libraries/AP_Compass/AP_Compass.cpp: In member function ‘void Compass::_detect_backends()’:
../../libraries/AP_HAL/board/linux.h:23:116: error: ‘probe_icm20948’ is not a member of ‘AP_Compass_AK09916’
   23 | #define PROBE_MAG_IMU(driver, imudev, imu_instance, args ...) ADD_BACKEND(DRIVER_ ##driver, AP_Compass_ ## driver::probe_ ## imudev(imu_instance,##args))
      |                                                                                                                    ^~~~~~
../../libraries/AP_Compass/AP_Compass.cpp:1049:59: note: in definition of macro ‘ADD_BACKEND’
 1049 |     do { if (_driver_enabled(driver_type)) { _add_backend(backend); } \
      |                                                           ^~~~~~~
../../libraries/AP_HAL/board/linux.h:334:36: note: in expansion of macro ‘PROBE_MAG_IMU’
  334 |         #define HAL_MAG_PROBE_LIST PROBE_MAG_IMU(AK09916, icm20948, 0, ROTATION_NONE)
      |                                    ^~~~~~~~~~~~~
../../libraries/AP_Compass/AP_Compass.cpp:1283:5: note: in expansion of macro ‘HAL_MAG_PROBE_LIST’
 1283 |     HAL_MAG_PROBE_LIST;
      |     ^~~~~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

Waf: Leaving directory `/home/alex/ardupilot/build/nxflight'
Build failed
 -> task in 'objs/AP_Compass/UNKNOWN' failed (exit status 1): 
	{task 281473262116080: cxx AP_Compass.cpp -> AP_Compass.cpp.1.o}
 (run with -v to display more information)

Ok.

first thing first. The icm has a different declaration.
On linux.h
#define HAL_INS_PROBE_LIST PROBE_IMU_SPI(Invensensev2, “icm20948”, ROTATION_NONE)
#define HAL_MAG_PROBE_LIST PROBE_MAG_IMU(AK09916, ICM20948, 0, ROTATION_YAW_90 )

On SPIDevice.cpp under AP_HAL_Linux - The X is the SPI Bus number and the Y is the CS number
(for instance, running a ls /dev/spi* you should have something line spidev2.1 then X=2 and Y=1
SPIDesc(“icm20948”, X, Y, SPI_MODE_3, 8, SPI_CS_KERNEL, 1MHZ, 11MHZ),
SPIDesc(“ms5611”, X, Y, SPI_MODE_3, 8, SPI_CS_KERNEL, 10MHZ,10MHZ),

[203/814] Compiling libraries/AP_DAL/AP_DAL_Compass.cpp
../../libraries/AP_Compass/AP_Compass.cpp: In member function ‘void Compass::_detect_backends()’:
../../libraries/AP_HAL/board/linux.h:23:116: error: ‘probe_icm20948’ is not a member of ‘AP_Compass_AK09916’
   23 | #define PROBE_MAG_IMU(driver, imudev, imu_instance, args ...) ADD_BACKEND(DRIVER_ ##driver, AP_Compass_ ## driver::probe_ ## imudev(imu_instance,##args))
      |                                                                                                                    ^~~~~~
../../libraries/AP_Compass/AP_Compass.cpp:1049:59: note: in definition of macro ‘ADD_BACKEND’
 1049 |     do { if (_driver_enabled(driver_type)) { _add_backend(backend); } \
      |                                                           ^~~~~~~
../../libraries/AP_HAL/board/linux.h:334:36: note: in expansion of macro ‘PROBE_MAG_IMU’
  334 |         #define HAL_MAG_PROBE_LIST PROBE_MAG_IMU(AK09916, icm20948, 0, ROTATION_NONE)
      |                                    ^~~~~~~~~~~~~
../../libraries/AP_Compass/AP_Compass.cpp:1283:5: note: in expansion of macro ‘HAL_MAG_PROBE_LIST’
 1283 |     HAL_MAG_PROBE_LIST;
      |     ^~~~~~~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

Waf: Leaving directory `/home/alex/ardupilot/build/nxflight'
Build failed
 -> task in 'objs/AP_Compass/UNKNOWN' failed (exit status 1): 
	{task 281473836207344: cxx AP_Compass.cpp -> AP_Compass.cpp.1.o}
 (run with -v to display more information)
alex@orin:~/ardupilot$ git diff
diff --git a/libraries/AP_HAL/board/linux.h b/libraries/AP_HAL/board/linux.h
index 9ff5d25485..8835de35ac 100644
--- a/libraries/AP_HAL/board/linux.h
+++ b/libraries/AP_HAL/board/linux.h
@@ -330,9 +330,10 @@
         #define HAL_BOARD_TERRAIN_DIRECTORY "/home/alex/ardupilot/terrain"
         #define HAL_BOARD_STORAGE_DIRECTORY "/home/alex/ardupilot"
         #define HAL_PARAM_DEFAULTS_PATH "/home/alex/ardupilot.parm"
-        #define HAL_INS_PROBE_LIST PROBE_IMU_SPI(Invensense, "mpu9250", ROTATION_NONE)
-        #define HAL_MAG_PROBE_LIST PROBE_MAG_IMU(AK8963, mpu9250, 0, ROTATION_NONE)
-        #define HAL_BARO_PROBE_LIST PROBE_BARO_SPI(BMP280, "bmp280")
+        #define HAL_INS_PROBE_LIST PROBE_IMU_SPI(Invensensev2, "icm20948", ROTATION_NONE)
+        #define HAL_MAG_PROBE_LIST PROBE_MAG_IMU(AK09916, icm20948, 0, ROTATION_NONE)
+        #define HAL_BARO_PROBE_LIST PROBE_BARO_I2C(BMP085, 1, 0x77) 
+        //#define HAL_BARO_PROBE_LIST PROBE_BARO_SPI(BMP280, "bmp280")
         #define HAL_PROBE_EXTERNAL_I2C_COMPASSES
 
 #else
diff --git a/libraries/AP_HAL_Linux/SPIDevice.cpp b/libraries/AP_HAL_Linux/SPIDevice.cpp
index a7a8c564c9..5d5587f760 100644
--- a/libraries/AP_HAL_Linux/SPIDevice.cpp
+++ b/libraries/AP_HAL_Linux/SPIDevice.cpp
@@ -152,7 +152,7 @@ SPIDesc SPIDeviceManager::_device[] = {
 };
 #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NXFLIGHT
 SPIDesc SPIDeviceManager::_device[] = {
-    SPIDesc("mpu9250",    0, 0, SPI_MODE_3, 8, SPI_CS_KERNEL,  1*MHZ, 11*MHZ),
+    SPIDesc("icm20948",    0, 0, SPI_MODE_3, 8, SPI_CS_KERNEL,  1*MHZ, 11*MHZ),
     SPIDesc("bmp280",     0, 1, SPI_MODE_3, 8, SPI_CS_KERNEL,  10*MHZ,10*MHZ),
 };
 #else

the branch I am working from was cloned from Copter-4.3 should I be running master?

Maybe the case of the ICM ?
ICM20948 instead icm20948 for the mag?

so that was the issue and I am able to get the example compiled correctly. I am still however unable to get the example code to work. I am using a sparkfun icm20948 breakout which I assume shouldnt be an issue. I can definitely see that it is responding through a spidevtest

root@orin:~/spidev-test# ./spidev_test /dev/spidev0.0 -v
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
RX | 20 08 02 00 01 00 00 81 00 01 00 00 01 00 06 80 44 80 A0 90 20 00 00 00 08 90 3F FF FF FF FF FF  | .......�.......�D���.....�?.....
root@orin:~/spidev-test# exit
exit
alex@orin:~$ cd ardupilot/build/nxflight/examples/
alex@orin:~/ardupilot/build/nxflight/examples$ ls
INS_generic
alex@orin:~/ardupilot/build/nxflight/examples$ sudo ./INS_generic 
AP_InertialSensor startup...
INS: unable to initialise driver
TOGCS: INS: unable to initialise driver

And here is how the device is configured in the code

alex@orin:~/ardupilot$ git diff
diff --git a/libraries/AP_HAL/board/linux.h b/libraries/AP_HAL/board/linux.h
index 9ff5d25485..f01419346d 100644
--- a/libraries/AP_HAL/board/linux.h
+++ b/libraries/AP_HAL/board/linux.h
@@ -330,9 +330,10 @@
         #define HAL_BOARD_TERRAIN_DIRECTORY "/home/alex/ardupilot/terrain"
         #define HAL_BOARD_STORAGE_DIRECTORY "/home/alex/ardupilot"
         #define HAL_PARAM_DEFAULTS_PATH "/home/alex/ardupilot.parm"
-        #define HAL_INS_PROBE_LIST PROBE_IMU_SPI(Invensense, "mpu9250", ROTATION_NONE)
-        #define HAL_MAG_PROBE_LIST PROBE_MAG_IMU(AK8963, mpu9250, 0, ROTATION_NONE)
-        #define HAL_BARO_PROBE_LIST PROBE_BARO_SPI(BMP280, "bmp280")
+        #define HAL_INS_PROBE_LIST PROBE_IMU_SPI(Invensensev2, "icm20948", ROTATION_NONE)
+        #define HAL_MAG_PROBE_LIST PROBE_MAG_IMU(AK09916, ICM20948, 0, ROTATION_NONE)
+        #define HAL_BARO_PROBE_LIST PROBE_BARO_I2C(BMP085, 1, 0x77) 
+        //#define HAL_BARO_PROBE_LIST PROBE_BARO_SPI(BMP280, "bmp280")
         #define HAL_PROBE_EXTERNAL_I2C_COMPASSES
 
 #else
diff --git a/libraries/AP_HAL_Linux/SPIDevice.cpp b/libraries/AP_HAL_Linux/SPIDevice.cpp
index a7a8c564c9..5d5587f760 100644
--- a/libraries/AP_HAL_Linux/SPIDevice.cpp
+++ b/libraries/AP_HAL_Linux/SPIDevice.cpp
@@ -152,7 +152,7 @@ SPIDesc SPIDeviceManager::_device[] = {
 };
 #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NXFLIGHT
 SPIDesc SPIDeviceManager::_device[] = {
-    SPIDesc("mpu9250",    0, 0, SPI_MODE_3, 8, SPI_CS_KERNEL,  1*MHZ, 11*MHZ),
+    SPIDesc("icm20948",    0, 0, SPI_MODE_3, 8, SPI_CS_KERNEL,  1*MHZ, 11*MHZ),
     SPIDesc("bmp280",     0, 1, SPI_MODE_3, 8, SPI_CS_KERNEL,  10*MHZ,10*MHZ),
 };
 #else

Not sure if I would be having these issues if I built a pcb with the modules so I wanted to test things with breakout boards first.

Ok, let’s thing for a while.
There is any king of device tree file to define the spidev device under Linux kernel ?

You have a ins and a baro examples. The baro is working ? What is the result running the baro example ?

I am able to get it working fine with a mpu9250 breakout board fine. I wanted to use the gy-91 because it has all the sensors on one board but it isnt detected properly even though it works on a raspberry pi. This board does require a device tree that is loaded. I can verify spi is working using a loopback test and as shown in my last reply. I know the mpu9250 is eol. which is why I why wanted to test the icm20948

I know, I’m using the icm20948 in my last designs and is working fine with ardupilot.
have the baro example running fine ?
I asked about the device tree overlay because with beaglebone I had to use a customized dtb with linux kernel to enable correctly the spi - CS pin in case.
running the spi test with baro and imu and -v flag what is the result ?

so the icm20948 is using spidev0.0 and the bmp280 2.0

root@ubuntu:~/spidev-test# ./spidev_test /dev/spidev0.0 -v
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
RX | 00 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00  | .........@......................
root@ubuntu:~/spidev-test# ./spidev_test /dev/spidev0.0 -v
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
RX | 00 00 00 00 00 00 00 40 20 21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  | .......@.!......................
root@ubuntu:~/spidev-test# ./spidev_test /dev/spidev2.0 -v
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
RX | 00 00 00 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  | ................................
root@ubuntu:~/spidev-test# ./spidev_test /dev/spidev2.0 -v
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
RX | 00 00 00 00 00 00 10 00 00 40 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  | .........@......................

both the imu and baro test end with it being unable to initialize the device

alex@ubuntu:~/Copter-4.3$ sudo ./build/nxflight/examples/BARO_generic
Barometer library test
Config Error: Baro: unable to initialise driver
TOGCS: Config Error: Baro: unable to initialise driver