avrdudes / avrdude

AVRDUDE is a utility to program AVR microcontrollers
GNU General Public License v2.0
737 stars 136 forks source link

v8 linuxspi won't connect - Reset Line Inverted ??? #1929

Open PeterHouseJr opened 1 week ago

PeterHouseJr commented 1 week ago

My Python App Turns on the power, turns on the 3.3v-5v level shifter, waits 100ms, call AVRDUDE, turns off level shifter, turns off power:

Sends this command using subprocess: command = 'sudo avrdude -n -p m328pb -c linuxspi -P /dev/spidev0.0:/dev/gpiochip0:26 -B 12kHz'

This command returns this to stderr: Error: AVR device not responding Error: initialization failed (rc = -2)

Here is the scope shot: {Complete Transaction} The connections are shown on the scope screen. The Reset line is mostly low with a lot of high pulses. Immediately BEFORE each reset pulse are four bytes, 0xAC 0x53 0x00 0x00, clocked out on MOSI.

Here is a close up of the four bytes and the first reset pulse. All reset pulses are preceded by the same four bytes. {Zoomed In}

You can see the reset line is mostly low (Active Reset).

A previous version, 6.3, of AVRDUDE worked fine on this hardware using this command: command = 'sudo avrdude -n -p atmega328pb -C avrdude_gpio.conf -c linuxspi -P /dev/spidev0.0 -b 125000'

It works exactly the same whether a target is connected or not. The target is a mature product and programs correctly, with the same cable using an Atmel-ICE.

I believe the target is connected properly since I used this same hardware setup with AVRDUDE v6.3

The reset line seems to be inverted using AVRDUDE 8.0

Any help would be appreciated.

MCUdude commented 1 week ago

Can you try modifying your avrdude.conf file and invert the reset pin there, by adding a ~ in front of the reset pin number?

https://github.com/avrdudes/avrdude/blob/0b92721af9aaa686095542cc54715a3fa06b5895/src/avrdude.conf.in#L862-L869

PeterHouseJr commented 1 week ago

Thank you for the quick response!

I copied the avrdude.conf file from the installation folder and placed it in the current folder and added the -C parameter to use the local conf file and modified the conf as you suggested only using my pin ~26 and removed pin 26 from the command line where the port is specified: command = 'sudo avrdude -n -p m328pb -C avrdude.conf -P /dev/spidev0.0:/dev/gpiochip0 -c linuxspi -B 12kHz'

programmer # linuxspi id = "linuxspi"; desc = "Use Linux SPI device in /dev/spidev*"; type = "linuxspi"; prog_modes = PM_TPI | PM_ISP; connection_type = spi; reset = ~26; # Pi GPIO number - this is J8:22 ;

The reset line is now inverted but still no MISO data. {D1488CCF-2F76-4856-9B73-09D86C7B982D}

Detail of One Reset Pulse {78F8BE34-121D-4D9D-B4E5-D4D042CBA969}

I have verified the voltage levels at the Target connector and all look good at the Target to Me. Tried multiple Targets and Not sure now why it does not work.

Any more ideas?

mcuee commented 1 week ago

Strange issue.

What about other avrdude official release versions? Say avrdude 7.3 and avrdude 7.2.

I have no issues using LinuxSPI with my Raspberry Pi 400 and ATmega328P.

mcuee commented 1 week ago

I tend to susepct there is a timing issue here.

My Python App Turns on the power, turns on the 3.3v-5v level shifter, waits 100ms, call AVRDUDE, turns off level shifter, turns off power.

PeterHouseJr commented 1 week ago

As shown in the scope shot:

  1. Power is turned on, the level shifter is turned on.
  2. The Reset line is taken inactive (high)
  3. ~225ms pass
  4. 4 bytes, 0xAC 0x53 0x00 0x00, are transfered to the 328PB with no response bytes returned (All 1s) by the target
  5. The reset line is pulsed active (low) for ~50us
  6. ~22ms pass
  7. steps 4-6 are repeated ~66 times
  8. ~25ms pass
  9. the reset line is taken active (low)
  10. ~10ms pass
  11. The level shifter is turned off, the power is turned off.

Observations:

  1. This is very slow -B 12kHz faster or slower yields the same results only different clock rate.
  2. THe SPI clock should get a response from the target.
  3. My targets all program using an Atmel-Ice in SPI mode using AVRDUDE 8.0 under Windows.
  4. My targets all program using the same hardware connected to another Pi and AVRDUDE v6.3 - This is my reference platform and is used for production programming of my customers parts.
  5. I use Tag-Connect cables for all programming. www.tag-connect.com.
  6. I need v8.0 to read the serial number from the 328PB.

I will try (when I get in the office on Monday):

  1. Connect Atmel-ICE to Pi using AVRDUDE 8.0
  2. Verify MISO signal at target using scope analog channel.
  3. Study the 328PB programming documents to verify the signal timing and programming command sequence.

I am hoping someone can look at this and either know this is correct signaling for the 328PB or know it is incorrect and tell me what it should be.

Thank you for everyone who has helped so far.

PeterHouseJr commented 13 hours ago

Still having issues . . .

These two scope shots show the working Pi using avrdude 6.3. The first four bytes are the same: 0xAC 0x53, 0x00, 0x00 with the 328 returning 0xFF 0xFF 0x53 0x00 as shown in the second scope shot. image

Zoom in scope shot showing first four bytes: image

The Reset line should be low during the communication which I initially thought was wrong.

  1. Stopped trying to connect AtmelICE to Pi since it does lead to my end game of using linuxspi (and did not immediately work).
  2. The MISO signal never shows any activity when using AVRDUDE 9 as shown in the previous scope shots.

I do keep getting errors from AVRDUDE. but they seem innocuous or incorrect. For instance, the speed issue does not make sense to me.

`Try without specifying -B :sudo ./avrdude_80 -v -n -p m328pb -C ./avrdude_80.conf -c linuxspi -P /dev/spidev0.0:/dev/gpiochip0 -U signature:r:TmpHex/sig.hex:i

Avrdude_80 version 8.0-20241010 (0b92721a) Copyright see https://github.com/avrdudes/avrdude/blob/main/AUTHORS

System wide configuration file is /home/Peter/SDProg/avrdude_80.conf User configuration file /root/.avrduderc does not exist Warning: system wide configuration file version (@AVRDUDE_FULL_VERSION@) does not match Avrdude build version (8.0-20241010 (0b92721a))

Using port : /dev/spidev0.0:/dev/gpiochip0 Using programmer : linuxspi Defaulting bit clock to 200 kHz AVR part : ATmega328PB Programming modes : SPM, ISP, HVPP, debugWIRE Programmer type : linuxspi Description : Use Linux SPI device in /dev/spidev* Error: AVR device not responding Error: initialization failed (rc = -2)

Avrdude_80 done. Thank you. ` I have tried four -B options: 1kHz, 10kHz, 100kHz and no -B resulting in 6kHz, 10kHz, 100kHz and 166kHz respectively with the same error message. With no -B shows 200kHz as defult but the actual rate is 166kHz. The working unit runs at about 140kHz for comparison.

I copied the .conf file and the executable to my local directory in order to have the ability to change versions of avrdude for testing. I am working on getting avrdude 6.3 installed now alongside avrdude 8.0.

The exact same hardware works on another Pi running a previous version of Raspbian and avrdude 6.3 and run from a python script with a gui.

When I run the avrdude 6.3 executable, I get the following error: "bash: ./avrdude_63: cannot execute: required file not found". Probably since it is not installed and is missing libraries. Can two versions be installed at one time? Where can I get the 6.3 installer or source for compile? .github only goes back to 7 and I don't see v6.3 anywhere.

Any suggestions appreciated ! ! !