Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble with Raspberry pi 5 #1748

Open
BastienCagna opened this issue Apr 14, 2024 · 8 comments
Open

Trouble with Raspberry pi 5 #1748

BastienCagna opened this issue Apr 14, 2024 · 8 comments
Labels
question Further information is requested

Comments

@BastienCagna
Copy link

Hello,
I was using avrdude to flash my MCU from an old Raspberry Pi 3 and recently move to the new Pi 5.
I was used to flash using this command:

sudo avrdude -p m162 -c linuxgpio -U flash:w:build/firmwares/main.hex 

But now, it return that:

avrdude OS error: cannot export GPIO 22, already exported/busy?: Invalid argumentavrdude error: unable to open programmer linuxgpio on port unknown

avrdude done.  Thank you.

I know that this new version of the raspberry use the new RP1 chip to control GPIO. Could it be the source of this trouble? May exist a workarround?

Regards,
Bastien

@BastienCagna BastienCagna changed the title Trouble using Raspberry pi 5 Trouble with Raspberry pi 5 Apr 14, 2024
@stefanrueger
Copy link
Collaborator

@mcuee mcuee added the question Further information is requested label Apr 15, 2024
@stefanrueger
Copy link
Collaborator

Apparently new kernel versions base the GPIO numbers at 512, not 0. So, another workaround is to add 512 to the gpio numbers of your linuxgpio entry in ~/.avrduderc.

@stefanrueger
Copy link
Collaborator

@BastienCagna It's been some time. Has your question been answered? Can the issue be closed?

@BastienCagna
Copy link
Author

BastienCagna commented May 7, 2024

Hey,
Thanks for your answers @stefanrueger !
Sorry I didn't work oon this project since my post. I guess I fixed the issue I was describing using libgpio. But now, it's looks like avrdude can not communicate with the MCU. Whe I execute the following command (which just worked few minutes ago on raspberry pi 3B), it says that the MCU is not responding :(

sudo /usr/local/bin/avrdude -p t2313 -c linuxgpio -P gpiochip0 -U flash:w:test.hex -v

avrdude: Version 7.3-20240428 (37ac6eba)
         Copyright the AVRDUDE authors;
         see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

         System wide configuration file is /usr/local/etc/avrdude.conf
         User configuration file is /root/.avrduderc
         User configuration file does not exist or is not a regular file, skipping

using libgpiod for linuxgpio
         Using port            : gpiochip0
         Using programmer      : linuxgpio
avrdude: input file test.hex auto detected as Intel Hex
         AVR Part              : ATtiny2313
         Programming modes     : ISP, HVPP, debugWIRE, SPM
         Programmer Type       : linuxgpio
         Description           : Use the Linux sysfs interface to bitbang GPIO lines
         Pin assignment        : libgpiod
           RESET   =  22
           SCK     =  11
           SDO     =  10
           SDI     =  9
avrdude bitbang_initialize() error: AVR device not responding
avrdude main() error: initialization failed, rc=-1
        - double check the connections and try again
        - use -B to set lower the bit clock frequency, e.g. -B 125kHz
        - use -F to override this check

avrdude done.  Thank you.

It tried to change baudrate (-B 100) but it also failed.
I also tried with gpiochip4 but same error.

Also, here is the state of pinctrl just after trying to flash:

$ pinctrl
 0: ip    pu | hi // ID_SDA/GPIO0 = input
 1: ip    pu | hi // ID_SCL/GPIO1 = input
 2: no    pu | -- // GPIO2 = none
 3: no    pu | -- // GPIO3 = none
 4: no    pu | -- // GPIO4 = none
 5: no    pu | -- // GPIO5 = none
 6: no    pu | -- // GPIO6 = none
 7: no    pu | -- // GPIO7 = none
 8: no    pu | -- // GPIO8 = none
 9: ip    pd | lo // GPIO9 = input
10: ip    pd | lo // GPIO10 = input
11: ip    pd | lo // GPIO11 = input
12: no    pd | -- // GPIO12 = none
13: no    pd | -- // GPIO13 = none
14: no    pd | -- // GPIO14 = none
15: no    pd | -- // GPIO15 = none
16: no    pd | -- // GPIO16 = none
17: no    pd | -- // GPIO17 = none
18: no    pd | -- // GPIO18 = none
19: no    pd | -- // GPIO19 = none
20: no    pd | -- // GPIO20 = none
21: no    pd | -- // GPIO21 = none
22: ip    pd | lo // GPIO22 = input
23: no    pd | -- // GPIO23 = none
24: no    pd | -- // GPIO24 = none
25: no    pd | -- // GPIO25 = none
26: op dh pd | hi // GPIO26 = output
27: no    pd | -- // GPIO27 = none
...

I then tried to set mannualy the pin to their needed function (using a0 for GPIO9 10 & 11 et setting 22 to ouput and high logical state). avrdude looks to not change those state and not reset is seen on the MCU.

I have no ~/.avrduderc but I guess it is equivalent to the global configuration made in avrdude.conf. So your workaround is to specify SCK = 512 + 11 = 523 ? For me it failed (but as I said, the first problem looks already fixed now for me).

If it may help, Here is a sample of my avrdude.conf (by the way, the empty default spi suprised me):

#
# Overall avrdude defaults; suitable for ~/.config/avrdude/avrdude.rc
#
default_parallel   = "/dev/parport0";
default_serial     = "/dev/ttyS0";
default_spi        = "";
# default_baudrate = 115200;
# default_bitclock = 2.5;
default_linuxgpio  = "gpiochip4";
allow_subshells    = no;





# This programmer bitbangs GPIO lines using the Linux libgpiod or sysfs GPIO interface
#
# To enable it set the configuration below to match the GPIO lines connected
# to the relevant ISP header pins and uncomment the entry definition. In case
# you don't have the required permissions to edit this system wide config
# file put the entry in a separate <your name>.conf file and use it with
# -C+<your name>.conf on the command line.
#
# To check if your avrdude build has support for the linuxgpio programmer
# compiled in, use -c?type on the command line and look for linuxgpio in the
# list. If it's not available you need pass the --enable-linuxgpio=yes option
# to configure and recompile avrdude.
#
#
# #------------------------------------------------------------
# # linuxgpio
# #------------------------------------------------------------
#
programmer
    id                   = "linuxgpio";
    desc                 = "Use the Linux sysfs interface to bitbang GPIO lines";
    type                 = "linuxgpio";
    prog_modes           = PM_ISP;
    connection_type      = linuxgpio;
    reset                = 22;
    sck                  = 11;
    sdo                  = 10;
    sdi                  = 9;
;


@stefanrueger
Copy link
Collaborator

@BastienCagna The short of it is that I don't have an answer. This requires more debugging. The posted run looks like libgpiod is compiled in and working; you are using the latest git-main. You tried -P gpiochip0 and also -P gpiochip4 (which seems to be suggested by the build system judging from your system avrdude.conf). You say it works with an RPi 3b. Is the failing run on an RPi 5? Have you installed libgpiod-dev and compiled avrdude on the RPi 5? @mcuee can you reproduce above? @BastienCagna Can you post a -vv output and upload the output of a -vvvv run?

the empty default spi suprised me

@BastienCagna If you know a method to set default_spi from the build system please let us know. @mcuee? @MCUdude?

@MCUdude
Copy link
Collaborator

MCUdude commented May 8, 2024

It looks like neither the auto tools nor Cmake deals with the default_spi port.

It may be as simple as adding set(DEFAULT_SPI_PORT "/dev/spidev0.0") here:

https://github.com/MCUdude/avrdude/blob/37ac6ebaa0330470d14cff37256dfd94293fda83/src/CMakeLists.txt#L90

And DEFAULT_SPI_PORT="/dev/spidev0.0" here:

https://github.com/MCUdude/avrdude/blob/37ac6ebaa0330470d14cff37256dfd94293fda83/src/configure.ac#L452-L462

@mcuee
Copy link
Collaborator

mcuee commented May 8, 2024

@stefanrueger and @BastienCagna

I do not have Raspberry Pi 5, but libgpiod and git main work well for me on my Raspberry Pi 400. I have no idea why it does not work on Raspberry Pi 5.

I can only suggest @BastienCagna to check the connection. The other suggestion is to try linuxspi as well to see if that works or not. Or try another MCU to see if that makes a difference or not.

Reference: my test results posted for PR #1792.

@stefanrueger
Copy link
Collaborator

It may be as simple as adding ...

@MCUdude Great idea! Do you want to do a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants