bluerobotics / navigator-lib

Library to unleash the hardware capabilities, packed with features and fuel for your coding adventures
https://docs.bluerobotics.com/navigator-lib/python/
MIT License
9 stars 5 forks source link

Support for CM4 #74

Closed DRL closed 3 months ago

DRL commented 3 months ago

Dear devs,

hope you are doing well!

we bought another Navigator board and would like to use it on a Raspberry Pi Compute Module 4 (CM4)

we followed your instructions from the readme but (obviously) ran into problems.

Initially the configure_board.sh script could not diagnose the board type because it enters the if-block about /proc/device-tree/model and doesn't match the model (in our case: Raspberry Pi Compute Module 4 Rev 1.1 )

When flipped around the if-blocks and it could diagnose the board type via /proc/cpuinfo (which is BCM2835) and prints the following:

$ sudo bash configure_board.sh
Detecting board type
Detected BCM28XX via cpuinfo
Configuring BCM28XX board (Raspberry Pi zero, 1, 2, 3)..
- Enable I2C, SPI and UART.
dtparam=i2c_arm=on
dtparam=spi=on
dtoverlay=spi1-3cs
dtoverlay=uart1
- Set up kernel modules.
bcm2835-v4l2
i2c-bcm2835
i2c-dev
- Configure serial.
- Enable cgroup with memory and cpu

But then when running bluerobotic_navigator.init() it complains:

>>> import bluerobotics_navigator as navigator
>>> navigator.init()
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })', /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/navigator-rs-0.3.2/src/lib.rs:280:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })

Since this suggested something being off about /dev/i2c-4 i added the following line to /boot/config.txt

dtoverlay=i2c4,pins_6_7,baudrate=1000000

which seemed to fix that error. After which it error'd as follows:

>>> import bluerobotics_navigator as navigator
>>> navigator.init()
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })', /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/navigator-rs-0.3.2/src/lib.rs:298:75
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })

This suggests to me the errors might be fixable but I lack to knowledge in device-tree-syntax/etc to configure this myself. Could you provide us with guidance on how to set up /boot/config.txt?

We would really like to use the navigator in combination with the CM4.

All the best,

dom

DRL commented 3 months ago

I forgot to add that the Navigator board is sitting on a CM4 IO board

And I also just realised that the processor of the CM4 is a BCM2711 (and got misdiagnosed with /proc/cpuinfo as BCM2835 which cause us to run the wrong configuration script: bcm_28xx.sh).

Should we try executing the bcm_27xx.sh script?

RaulTrombin commented 3 months ago

Hey @DRL !

Yes, probably some issue with the script, CM4 should be equal the Pi4. Could you try it manually on /boot/config.txt?

[pi4] tag should work for both pi4 and cm4.

[pi4]
enable_uart=1
dtoverlay=uart1
dtoverlay=uart3
dtoverlay=uart4
dtoverlay=uart5
dtparam=i2c_vc=on
dtoverlay=i2c1
dtparam=i2c_arm_baudrate=1000000
dtoverlay=i2c4,pins_6_7,baudrate=1000000
dtoverlay=i2c6,pins_22_23,baudrate=400000
dtparam=spi=on
dtoverlay=spi0-led
dtoverlay=spi1-3cs
gpio=11,24,25=op,pu,dh
gpio=37=op,pd,dl
dtoverlay=dwc2,dr_mode=otg
dtoverlay=vc4-fkms-v3d
# Run as fast as firmware / board allows
arm_boost=1

Next, we need to check if the overlays worked and confirm that we can list the devices on the I2C buses.

pi@raspbian-armv7-kernel-5:~ $ i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
pi@raspbian-armv7-kernel-5:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- 0c -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- 76 --                         
pi@raspbian-armv7-kernel-5:~ $ i2cdetect -y 4
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --                         
pi@raspbian-armv7-kernel-5:~ 
DRL commented 3 months ago

Hey @RaulTrombin,

we added that configuration (with the [pi4] tag) but the CM4 is not happy with this and does not boot correctly.

It starts to boot but then the screen turns black and it does not respond.

The OS is the following:

$ uname -a
Linux apnea 5.15.84-v8+ #1613 SMP PREEMPT Thu Jan 5 12:03:08 GMT 2023 aarch64 GNU/Linux

After flashing the eMMC again it boots without problem.

I assume one or more lines in this configuration are not compatible with the CM4.

RaulTrombin commented 3 months ago

Hey @RaulTrombin,

we added that configuration (with the [pi4] tag) but the CM4 is not happy with this and does not boot correctly.

It starts to boot but then the screen turns black and it does not respond.

The OS is the following:

$ uname -a
Linux apnea 5.15.84-v8+ #1613 SMP PREEMPT Thu Jan 5 12:03:08 GMT 2023 aarch64 GNU/Linux

After flashing the eMMC again it boots without problem.

I assume one or more lines in this configuration are not compatible with the CM4.

Can you try removing the following lines?

dtoverlay=spi0-led
dtoverlay=dwc2,dr_mode=otg
dtoverlay=vc4-fkms-v3d

I think it shouldn't break the booting process, but if it doesn't fix it, we can try loading them manually.

RaulTrombin commented 3 months ago

Loading overlays manually. Example:

sudo dtparam i2c_vc
sudo dtoverlay i2c6 pins_22_23 baudrate=400000
DRL commented 3 months ago

Can you try removing the following lines?

dtoverlay=spi0-led
dtoverlay=dwc2,dr_mode=otg
dtoverlay=vc4-fkms-v3d

Awesome! This worked! CM4 boots and i2cdetect gives output:

$ i2cdetect -l
i2c-20   i2c         Broadcom STB :                    I2C adapter
i2c-10   i2c         i2c-22-mux (chan_id 1)            I2C adapter
i2c-1   i2c         bcm2835 (i2c@7e804000)            I2C adapter
i2c-6   i2c         bcm2835 (i2c@7e205c00)            I2C adapter
i2c-4   i2c         bcm2835 (i2c@7e205800)            I2C adapter
i2c-21   i2c         Broadcom STB :                    I2C adapter
i2c-0   i2c         i2c-22-mux (chan_id 0)            I2C adapter
i2c-22   i2c         bcm2835 (i2c@7e205000)            I2C adapter
$ i2cdetect -y 0
    0 1 2 3 4 5 6 7 8 9 a b c d e f
00:                        -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                        
$ i2cdetect -y 1
    0 1 2 3 4 5 6 7 8 9 a b c d e f
00:                        -- -- -- -- 0c -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- 76 --                        
$ i2cdetect -y 4
    0 1 2 3 4 5 6 7 8 9 a b c d e f
00:                        -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- -- 

What do the three omitted lines do? Do we need them? And is the idea that we activate them and then deactivate them before each reboot?

Sorry if these are stupid questions...

cheers,

dom

DRL commented 3 months ago

We are still getting this error for bluerobotics_navigator.init() though:

>>> import bluerobotics_navigator as navigator
>>> navigator.init()
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })', /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/navigator-rs-0.3.2/src/lib.rs:298:75
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" })

... which probably is related to dtoverlay=spi0-led

RaulTrombin commented 3 months ago

Ok, we need to fix the spi0-led now, it's custom overlay.

DRL commented 3 months ago

the plot thickens ... seems like cm4 does not know about this .dtbo

$ sudo dtoverlay spi0-led
DTOVERLAY[error]: failed to open '/boot/overlays/spi0-led.dtbo'
* Failed to read '/boot/overlays/spi0-led.dtbo'

EDIT: sudo dtoverlay vc4-fkms-v3d worked

RaulTrombin commented 3 months ago

@DRL please try the following commands:

curl -fsSL -o /tmp/spi0-led https://raw.githubusercontent.com/bluerobotics/BlueOS/43f7a54bd5e59c8fcdc8918ff3c0981f1a12c4d6/install/overlays/spi0-led.dts

sudo dtc -@ -Hepapr -I dts -O dtb -o /boot/overlays/spi0-led.dtbo  /tmp/spi0-led

Then we can load the spi0-led.

DRL commented 3 months ago

Just left the base. Will check tomorrow.

patrickelectric commented 3 months ago

Hi @DRL, it's a bit weird that install.sh is not working for you. Did you run it in a fresh installation ?

What happens is the following. If the string in "/proc/device-tree/model" does not match what we currently have, it'll do the configuration based on the cpu model provided in /proc/cpuinfo.

And that should work.

DRL commented 3 months ago

Hi @DRL, it's a bit weird that install.sh is not working for you. Did you run it in a fresh installation ?

What happens is the following. If the string in "/proc/device-tree/model" does not match what we currently have, it'll do the configuration based on the cpu model provided in /proc/cpuinfo.

And that should work.

The script misbehaves because of

$ cat /proc/device-tree/model
Raspberry Pi Compute Module 4 Rev 1.1

which makes it go into board_not_detected "/proc/device-tree/model" "$CPU_MODEL"

And the logic based on /proc/cpuinfo does not work because that one returns BCM2835 on the CM4 (which is a lie, it has the BCM2711)

patrickelectric commented 3 months ago

which OS are you using ? Did you installed the 64bits OS / kernel ?

patrickelectric commented 3 months ago

Hi @DRL, it's a bit weird that install.sh is not working for you. Did you run it in a fresh installation ? What happens is the following. If the string in "/proc/device-tree/model" does not match what we currently have, it'll do the configuration based on the cpu model provided in /proc/cpuinfo. And that should work.

The script misbehaves because of

$ cat /proc/device-tree/model
Raspberry Pi Compute Module 4 Rev 1.1

which makes it go into board_not_detected "/proc/device-tree/model" "$CPU_MODEL"

And the logic based on /proc/cpuinfo does not work because that one returns BCM2835 on the CM4 (which is a lie, it has the BCM2711)

Just found it: https://github.com/raspberrypi/documentation/blob/develop/documentation/asciidoc/computers/raspberry-pi/revision-codes.adoc

We are going to update the script to support CM4

DRL commented 3 months ago

which OS are you using ? Did you installed the 64bits OS / kernel ?

Yeah.

$ uname -a
Linux xxxx 5.15.84-v8+ #1613 SMP PREEMPT Thu Jan 5 12:03:08 GMT 2023 aarch64 GNU/Linux

You recommended this one in the past and suggested we should not update kernel etc.

That's why we mark the following packages to not be updated

sudo apt-mark hold libraspberrypi-bin libraspberrypi-dev libraspberrypi-doc libraspberrypi0 raspberrypi-bootloader raspberrypi-kernel raspberrypi-kernel-headers

please, let us know if this is not needed anymore.

DRL commented 3 months ago

@DRL please try the following commands:

curl -fsSL -o /tmp/spi0-led https://raw.githubusercontent.com/bluerobotics/BlueOS/43f7a54bd5e59c8fcdc8918ff3c0981f1a12c4d6/install/overlays/spi0-led.dts

sudo dtc -@ -Hepapr -I dts -O dtb -o /boot/overlays/spi0-led.dtbo  /tmp/spi0-led

Then we can load the spi0-led.

This works. Added it now to our /boot/config.txt and all is well.

Both bluerobotics_navigator.init() and bluerobotics_navigator.self_test() are happy.

Here is the complete content of our /proc/cpuinfo, since our revision code is not part of the docs you linked.

$ cat /proc/cpuinfo
processor   : 0
BogoMIPS   : 108.00
Features   : fp asimd evtstrm crc32 cpuid
CPU implementer   : 0x41
CPU architecture: 8
CPU variant   : 0x0
CPU part   : 0xd08
CPU revision   : 3

processor   : 1
BogoMIPS   : 108.00
Features   : fp asimd evtstrm crc32 cpuid
CPU implementer   : 0x41
CPU architecture: 8
CPU variant   : 0x0
CPU part   : 0xd08
CPU revision   : 3

processor   : 2
BogoMIPS   : 108.00
Features   : fp asimd evtstrm crc32 cpuid
CPU implementer   : 0x41
CPU architecture: 8
CPU variant   : 0x0
CPU part   : 0xd08
CPU revision   : 3

processor   : 3
BogoMIPS   : 108.00
Features   : fp asimd evtstrm crc32 cpuid
CPU implementer   : 0x41
CPU architecture: 8
CPU variant   : 0x0
CPU part   : 0xd08
CPU revision   : 3

Hardware   : BCM2835
Revision   : c03141
Serial      : 100000001d68ce20
Model      : Raspberry Pi Compute Module 4 Rev 1.1

Thanks a lot!

I will close this issue now, feel free to open again if more discussion is needed.