Gpio driver linux for new board/target

I have a jetson tx2-nx and with a seeedstudio a203 carrier board. I assume that this board would need its own gpio driver like the rpi or bbb has. I see that the guides on the site to adding a new board dont mention anything linux related and hasnt been updated in a while. I wanted to use the gy-91 breakout board on a custom pcb made in easyeda but wanted to know about setting up a new board and whats required.

this is the board I have

Hi @awright424

How are you thinking to working with motors?
What interface spi or i2c you intend to use with gy-91?

I was planning to use the gy-91 like the obal board does. I have it connected to spi1 on the board and both chip selects for the spi01 bus. I need to do some more reading and take a look at the obal board to see how it is connected spi wise. unfortunately my only option for pwm would be the pca9685 connecteed via i2c. There are uart ports so my elrs receiver could be used there. I also need a guide of some sorts on creating a new board. I could definitely look at how one of the rpi based boards or bbb boards is setup in the code but would have hoped the wiki would be updated on that side of things.

The creator of the obal board does seem to have some videos about porting to another board so I will look at that as well.

But I do have the a203 dtb working on the tx2nx so at this point I would just need to compile a realtime kernel which is not too hard.

I’m in the process of building ardupilot on my tx2nx. It was surprisingly easier to add a board than I had expected. I need to work some things out in config for sensors etc but at the very least I think I should be able to get things recognizing the imu and barometer soon.

Great news.

You can test with the examples applications - baro, imu, rcinput

So I was able to get things built as mentioned. I tried the examples and am not sure why I could not get the gy-91 I had working. I will probably test the module with another board and see if it was dead on arrival. I did see data coming through using spidev_test. I switched over to a mpu9250 module and was able to get that detected by both the INS_generic and AHS_Test examples. I had weird behavior running copter. So ran waf clean and rebuilding to see if that helps any. By weird I mean I got no output from it. Before I at least got errors pertaining to no imu. Could also be the jumper wire setup.

I have been trying to figure out why I can’t get the gy-91 detected by the INS_generic or arducopter for that matter, but am able to get the mpu 9250 breakout by itself working. Also when runing arducopter after having rebuilt with changes made I get to this point and no further. I am not gettint the typical terminal output and I assume it may be that I do not have a barometer hooked up but I would assume I would get output in the terminal saying so.

Are you using i2c or spi?

spi. with mpu9250 sensors example works. gy91 doesnt . unable to get ardupilot to continue past the initial startup

And how are the values are you using in your spidevices.cpp and how you declare the guy-91 in the linux.h on the ap_hal/boards ?

GY-91 config I am using this config with the standalone mpu 9250 breakout as well and it works fine for the mpu9250. Havent hooked up a barometer with the mpu9250, hoped the gy-91 would work.

#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("bmp280",     0, 1, SPI_MODE_3, 8, SPI_CS_KERNEL,  10*MHZ,10*MHZ),
};

I also have this in libraries/AP_HAL/boards/linux.h

        #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_PROBE_EXTERNAL_I2C_COMPASSES

For the board as well. I am not sure if the lack of the barometer being connected would have arducopter stopping where it did.

Question,

are you sure about the CS of imu and Baro ? are they not inverted ?


first board is the obal board. the pinout is rpi compatible to a certain extent so I was able to use this extra pcb to test with. I can view the device through spidev_test but the INS_generic doesnt work with it. I can use the same compiled code and switch to the mpu9250 alone seen in the 2nd picture and have no problems with INS_generic. with both boards Arducopter just kinda hangs after erasing the eeprom.

root@linux:~# ./spidev_test -D /dev/spidev0.0
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
RX | 00 00 BB FD BE 17 33 4D 08 AC AE 7E 23 32 ED C4 F8 78 1A 42 3F 62 F9 F8 B5 13 A7 B2 F0 B2 69 25  | ..���.3M.��~#2���x.B?b���.���i%

trying the same command above on the spidev0.1 gives me nothing for the RX side when testing.

O believe the Hang is because there are some gpios be used by ardupilot - for leds and buzzer.
I really is not familiar with the obal board, but to confirm the hang’s cause, are you familiar with gdb ?

I haven’t gotten a gpio driver working for this board yet. So not sure if not having them defined is the cause of the hang. I rebuilt with debug etc but not sure what I should be looking for when running gdb. I see it starts for 4 threads

Try this one.

gdb ./arducopter

then after the console,
run -A udp:192.168.7.1:14550

this will start arducopter sending the telemetry data to a host.
When hang, run
backtrace
and send me the result.

After running the command I got no output. Ctrl c got me back to the gdb console and then had some output. not sure if its useful.

awright@linux:~/Copter-4.3.4/build/nxflight/bin$ sudo gdb ./arducopter
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "aarch64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./arducopter...done.
(gdb) run -A udp:192.168.4.29:14550
Starting program: /home/awright/Copter-4.3.4/build/nxflight/bin/arducopter -A udp:192.168.4.29:14550
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fb7ba41d0 (LWP 7965)]
[New Thread 0x7fb7aa31d0 (LWP 7966)]
[New Thread 0x7fb79a21d0 (LWP 7967)]
[New Thread 0x7fb78a11d0 (LWP 7968)]
Loaded defaults from /home/awright/ardupilot.parm
show threads

^C^C^Z^As




Thread 2 "ap-timer" received signal SIGINT, Interrupt.
[Switching to Thread 0x7fb7ba41d0 (LWP 7965)]
0x0000007fb7d335fc in __GI___nanosleep (requested_time=0x7fb7ba3938, remaining=0x7fb7ba3938)
    at ../sysdeps/unix/sysv/linux/nanosleep.c:28
28      ../sysdeps/unix/sysv/linux/nanosleep.c: No such file or directory.
(gdb) s

Thread 1 "arducopter" received signal SIGTSTP, Stopped (user).
[Switching to Thread 0x7fb7ff8fc0 (LWP 7962)]
ioctl () at ../sysdeps/unix/sysv/linux/aarch64/ioctl.S:26
26      ../sysdeps/unix/sysv/linux/aarch64/ioctl.S: No such file or directory.
(gdb)

Thread 1 "arducopter" received signal SIGTSTP, Stopped (user).
ioctl () at ../sysdeps/unix/sysv/linux/aarch64/ioctl.S:26
26      in ../sysdeps/unix/sysv/linux/aarch64/ioctl.S
(gdb)

Thread 4 "ap-rcin" received signal SIGTSTP, Stopped (user).
[Switching to Thread 0x7fb79a21d0 (LWP 7967)]
0x0000007fb7d335fc in __GI___nanosleep (requested_time=0x7fb79a1938, remaining=0x7fb79a1938)
    at ../sysdeps/unix/sysv/linux/nanosleep.c:28
28      ../sysdeps/unix/sysv/linux/nanosleep.c: No such file or directory.
(gdb)

Thread 2 "ap-timer" received signal SIGTSTP, Stopped (user).
[Switching to Thread 0x7fb7ba41d0 (LWP 7965)]
0x0000007fb7d33600 in __GI___nanosleep (requested_time=0x7fb7ba3938, remaining=0x7fb7ba3938)
    at ../sysdeps/unix/sysv/linux/nanosleep.c:28
28      in ../sysdeps/unix/sysv/linux/nanosleep.c
(gdb)

Right,

so you are not having a sigfault, maybe a resource not available or locking.
Have you had take a look at the syslog (dmesg) to see if there is any message ?

[  602.926183] tegra-i2c 3180000.i2c: no acknowledge from address 0x38
[  602.932544] tegra-i2c 3180000.i2c: no acknowledge from address 0x38
[  602.938902] tegra-i2c 3180000.i2c: no acknowledge from address 0x38
[  602.945260] tegra-i2c 3180000.i2c: no acknowledge from address 0x38
[  602.951619] tegra-i2c 3180000.i2c: no acknowledge from address 0x38
[  602.957978] tegra-i2c 3180000.i2c: no acknowledge from address 0x38
[  602.964335] tegra-i2c 3180000.i2c: no acknowledge from address 0x38
[  602.970700] tegra-i2c 3180000.i2c: no acknowledge from address 0x38
[  602.977059] tegra-i2c 3180000.i2c: no acknowledge from address 0x38
[  602.983418] tegra-i2c 3180000.i2c: no acknowledge from address 0x38
[  602.989784] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  602.996141] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  603.002501] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  603.008863] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  603.015224] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  603.021585] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  603.027946] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  603.034306] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  603.040667] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  603.047025] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  603.053384] tegra-i2c 3180000.i2c: no acknowledge from address 0x39
[  613.205585] tegra-i2c 3190000.i2c: pio timed out addr: 0x38 tlen:16 rlen:0
[  613.212457] tegra-i2c 3190000.i2c: --- register dump for debugging ----
[  613.219061] tegra-i2c 3190000.i2c: I2C_CNFG - 0x22c00
[  613.224103] tegra-i2c 3190000.i2c: I2C_PACKET_TRANSFER_STATUS - 0x10001
[  613.230706] tegra-i2c 3190000.i2c: I2C_FIFO_CONTROL - 0xe0
[  613.236181] tegra-i2c 3190000.i2c: I2C_FIFO_STATUS - 0x800070
[  613.241916] tegra-i2c 3190000.i2c: I2C_INT_MASK - 0x7c
[  613.247045] tegra-i2c 3190000.i2c: I2C_INT_STATUS - 0x0
[  613.252262] tegra-i2c 3190000.i2c: i2c transfer timed out addr: 0x38
[  623.445776] tegra-i2c 3190000.i2c: pio timed out addr: 0x38 tlen:16 rlen:0
[  623.452648] tegra-i2c 3190000.i2c: --- register dump for debugging ----
[  623.459254] tegra-i2c 3190000.i2c: I2C_CNFG - 0x22c00
[  623.464296] tegra-i2c 3190000.i2c: I2C_PACKET_TRANSFER_STATUS - 0x10001
[  623.470899] tegra-i2c 3190000.i2c: I2C_FIFO_CONTROL - 0xe0
[  623.476374] tegra-i2c 3190000.i2c: I2C_FIFO_STATUS - 0x800070
[  623.482110] tegra-i2c 3190000.i2c: I2C_INT_MASK - 0x7c
[  623.487239] tegra-i2c 3190000.i2c: I2C_INT_STATUS - 0x0
[  623.492456] tegra-i2c 3190000.i2c: i2c transfer timed out addr: 0x38
[  633.685956] tegra-i2c 3190000.i2c: pio timed out addr: 0x38 tlen:16 rlen:0
[  633.692829] tegra-i2c 3190000.i2c: --- register dump for debugging ----
[  633.699434] tegra-i2c 3190000.i2c: I2C_CNFG - 0x22c00
[  633.704477] tegra-i2c 3190000.i2c: I2C_PACKET_TRANSFER_STATUS - 0x10001
[  633.711080] tegra-i2c 3190000.i2c: I2C_FIFO_CONTROL - 0xe0
[  633.716557] tegra-i2c 3190000.i2c: I2C_FIFO_STATUS - 0x800070
[  633.722292] tegra-i2c 3190000.i2c: I2C_INT_MASK - 0x7c
[  633.727422] tegra-i2c 3190000.i2c: I2C_INT_STATUS - 0x0
[  633.732639] tegra-i2c 3190000.i2c: i2c transfer timed out addr: 0x38
[  643.926131] tegra-i2c 3190000.i2c: pio timed out addr: 0x38 tlen:16 rlen:0
[  643.933005] tegra-i2c 3190000.i2c: --- register dump for debugging ----
[  643.939610] tegra-i2c 3190000.i2c: I2C_CNFG - 0x22c00
[  643.944654] tegra-i2c 3190000.i2c: I2C_PACKET_TRANSFER_STATUS - 0x10001
[  643.951256] tegra-i2c 3190000.i2c: I2C_FIFO_CONTROL - 0xe0
[  643.956733] tegra-i2c 3190000.i2c: I2C_FIFO_STATUS - 0x800070
[  643.962469] tegra-i2c 3190000.i2c: I2C_INT_MASK - 0x7c
[  643.967597] tegra-i2c 3190000.i2c: I2C_INT_STATUS - 0x0
[  643.972813] tegra-i2c 3190000.i2c: i2c transfer timed out addr: 0x38
[  654.166303] tegra-i2c 3190000.i2c: pio timed out addr: 0x38 tlen:16 rlen:0
[  654.173174] tegra-i2c 3190000.i2c: --- register dump for debugging ----
[  654.179779] tegra-i2c 3190000.i2c: I2C_CNFG - 0x22c00
[  654.184823] tegra-i2c 3190000.i2c: I2C_PACKET_TRANSFER_STATUS - 0x10001
[  654.191430] tegra-i2c 3190000.i2c: I2C_FIFO_CONTROL - 0xe0
[  654.196910] tegra-i2c 3190000.i2c: I2C_FIFO_STATUS - 0x800070
[  654.202651] tegra-i2c 3190000.i2c: I2C_INT_MASK - 0x7c
[  654.207786] tegra-i2c 3190000.i2c: I2C_INT_STATUS - 0x0
[  654.213009] tegra-i2c 3190000.i2c: i2c transfer timed out addr: 0x38
[  664.406464] tegra-i2c 3190000.i2c: pio timed out addr: 0x38 tlen:16 rlen:0
[  664.413338] tegra-i2c 3190000.i2c: --- register dump for debugging ----
[  664.419943] tegra-i2c 3190000.i2c: I2C_CNFG - 0x22c00
[  664.424987] tegra-i2c 3190000.i2c: I2C_PACKET_TRANSFER_STATUS - 0x10001
[  664.431589] tegra-i2c 3190000.i2c: I2C_FIFO_CONTROL - 0xe0
[  664.437065] tegra-i2c 3190000.i2c: I2C_FIFO_STATUS - 0x800070
[  664.442801] tegra-i2c 3190000.i2c: I2C_INT_MASK - 0x7c
[  664.447929] tegra-i2c 3190000.i2c: I2C_INT_STATUS - 0x0
[  664.453145] tegra-i2c 3190000.i2c: i2c transfer timed out addr: 0x38
[  674.646614] tegra-i2c 3190000.i2c: pio timed out addr: 0x38 tlen:16 rlen:0
[  674.653483] tegra-i2c 3190000.i2c: --- register dump for debugging ----
[  674.660089] tegra-i2c 3190000.i2c: I2C_CNFG - 0x22c00
[  674.665133] tegra-i2c 3190000.i2c: I2C_PACKET_TRANSFER_STATUS - 0x10001
[  674.671736] tegra-i2c 3190000.i2c: I2C_FIFO_CONTROL - 0xe0
[  674.677211] tegra-i2c 3190000.i2c: I2C_FIFO_STATUS - 0x800070
[  674.682946] tegra-i2c 3190000.i2c: I2C_INT_MASK - 0x7c
[  674.688074] tegra-i2c 3190000.i2c: I2C_INT_STATUS - 0x0
[  674.693290] tegra-i2c 3190000.i2c: i2c transfer timed out addr: 0x38
[  684.886785] tegra-i2c 3190000.i2c: pio timed out addr: 0x38 tlen:16 rlen:0
[  684.893658] tegra-i2c 3190000.i2c: --- register dump for debugging ----
[  684.900262] tegra-i2c 3190000.i2c: I2C_CNFG - 0x22c00
[  684.905305] tegra-i2c 3190000.i2c: I2C_PACKET_TRANSFER_STATUS - 0x10001
[  684.911907] tegra-i2c 3190000.i2c: I2C_FIFO_CONTROL - 0xe0
[  684.917382] tegra-i2c 3190000.i2c: I2C_FIFO_STATUS - 0x800070
[  684.923118] tegra-i2c 3190000.i2c: I2C_INT_MASK - 0x7c
[  684.928247] tegra-i2c 3190000.i2c: I2C_INT_STATUS - 0x0
[  684.933464] tegra-i2c 3190000.i2c: i2c transfer timed out addr: 0x38
[  695.126934] tegra-i2c 3190000.i2c: pio timed out addr: 0x38 tlen:16 rlen:0
[  695.133807] tegra-i2c 3190000.i2c: --- register dump for debugging ----
[  695.140413] tegra-i2c 3190000.i2c: I2C_CNFG - 0x22c00
[  695.145456] tegra-i2c 3190000.i2c: I2C_PACKET_TRANSFER_STATUS - 0x10001
[  695.152059] tegra-i2c 3190000.i2c: I2C_FIFO_CONTROL - 0xe0
[  695.157534] tegra-i2c 3190000.i2c: I2C_FIFO_STATUS - 0x800070
[  695.163271] tegra-i2c 3190000.i2c: I2C_INT_MASK - 0x7c
[  695.168400] tegra-i2c 3190000.i2c: I2C_INT_STATUS - 0x0
[  695.173618] tegra-i2c 3190000.i2c: i2c transfer timed out addr: 0x38
[  705.367077] tegra-i2c 3190000.i2c: pio timed out addr: 0x38 tlen:16 rlen:0
[  705.373947] tegra-i2c 3190000.i2c: --- register dump for debugging ----
[  705.380549] tegra-i2c 3190000.i2c: I2C_CNFG - 0x22c00
[  705.385592] tegra-i2c 3190000.i2c: I2C_PACKET_TRANSFER_STATUS - 0x10001
[  705.392194] tegra-i2c 3190000.i2c: I2C_FIFO_CONTROL - 0xe0
[  705.397671] tegra-i2c 3190000.i2c: I2C_FIFO_STATUS - 0x800070
[  705.403407] tegra-i2c 3190000.i2c: I2C_INT_MASK - 0x7c
[  705.408536] tegra-i2c 3190000.i2c: I2C_INT_STATUS - 0x0
[  705.413753] tegra-i2c 3190000.i2c: i2c transfer timed out addr: 0x38

Thats a sign of something. Don’t know why I didnt think to check dmesg. But it seems to be referring to i2c items.

I had this in libraries/AP_HAL/boards/linux.h I just commented out the pobing of the i2c compass. I am not sure it that is the cause. Going to recompile and see

#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NXFLIGHT
    #define HAL_GPIO_A_LED_PIN        27 // You can choose between 27,22,4,12
    #define HAL_GPIO_C_LED_PIN        22 // You can choose between 27,22,4,12
    #define HAL_GPIO_B_LED_PIN        4 // You can choose between 27,22,4,12
    #define HAL_GPIO_LED_ON           1
    #define HAL_GPIO_LED_OFF          0
    #define HAL_BOARD_STORAGE_DIRECTORY "/home/awright/apm"
    #define HAL_BOARD_LOG_DIRECTORY "/home/awright/apm/logs"
    #define HAL_BOARD_TERRAIN_DIRECTORY "/home/awright/apm/terrain"
    #define HAL_PARAM_DEFAULTS_PATH "/home/awright/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_PROBE_EXTERNAL_I2C_COMPASSES

Hi @awright424

I know what is happening.
Is a problem with I2C. In beagles, until I wrote a dtb file with I2C right I had several i2c timeouts - and for each interface this timeout demand 5 minutes.
I recommend you do something different.
Under AP_HAL_Linux/I2CDevices.cpp around line 377 - try this
I2CDeviceManager::_create_device(I2CBus &b, uint8_t address) const
{
// This will ignore the I2C devices
return nullptr;
auto dev = AP_HAL::OwnPtr<AP_HAL::I2CDevice>(new I2CDevice(b, address));