OpenMarine
Connections between RPi and nano for flashing - Printable Version

+- OpenMarine (https://forum.openmarine.net)
+-- Forum: Pypilot (https://forum.openmarine.net/forumdisplay.php?fid=17)
+--- Forum: General discussion (https://forum.openmarine.net/forumdisplay.php?fid=18)
+--- Thread: Connections between RPi and nano for flashing (/showthread.php?tid=2969)



Connections between RPi and nano for flashing - CapnKernel - 2020-09-30

I'd like to be able to reflash my nano from the RPi.  I can see there's support for it:

  https://github.com/pypilot/pypilot/blob/b75b935b71dca58b6bd1c6f2fd915395c46b46c8/hat/arduino.py#L327
  https://github.com/pypilot/pypilot/blob/b75b935b71dca58b6bd1c6f2fd915395c46b46c8/hat/arduino.py#L391

What pins do I need to connect?

On the nano side, I think it's D11, D12 and D13.  How about on the RPi?  Can I use GPIO9/GPIO10/GPIO11, with GPIO7 as the chip enable?  Will connecting these lines result in the nano's use of these lines interfering with the LCD?  Is it possible instead to use SPI1 on GPIO19/GPIO20/GPIO21, with GPIO16 as the chip enable?

Thank you.


RE: Connections between RPi and nano for flashing - seandepagnier - 2020-10-01

I reflash using the bootloader. So you can reflash the nano via usb or the hardware serial port. It's possible to use spi but why?


RE: Connections between RPi and nano for flashing - CapnKernel - 2020-10-01

(2020-10-01, 12:23 AM)seandepagnier Wrote: but why?

For my autopilot I'm aiming for something about the size of a cigarette pack so I can put it directly at my helm next to the compass.  Space on my board is really tight, so I want to put the ATmega directly on the PCB (ie, no nano carrier PCB).  This means the ATmega will have no USB.  

(2020-10-01, 12:23 AM)seandepagnier Wrote: It's possible to use spi

Great!  Looking at hat/arduino.pyavrdude is called with -c linuxspi, and a device of /dev/spidev0.1, so it seems that you've already been programming it over SPI.  I can see that reset is GPIO16.  But I'm trying to confirm the pins.  I had a look in tinypilot_2020_09_30.img.xz to see if there's a special avrdude.conf, but it looks standard.  So that means for spidev0.1 it's probably going to be GPIO9, GPIO10 and GPIO11.  Do I have it right?

Something I haven't yet found a solution for is level translation.  Will an atmega328 work at 3.3V with motor.ino? What will I need to change? Brownout fuses?)


RE: Connections between RPi and nano for flashing - seandepagnier - 2020-10-01

I'm using an arduino over spi on the hat to receive rf signals as well as other functions. This is not the same atmega as the motor controller.


RE: Connections between RPi and nano for flashing - CapnKernel - 2020-10-01

(2020-10-01, 06:00 AM)seandepagnier Wrote: I'm using an arduino over spi on the hat to receive rf signals as well as other functions.  This is not the same atmega as the motor controller.

I see, thanks.


RE: Connections between RPi and nano for flashing - CapnKernel - 2020-10-01

(2020-10-01, 06:00 AM)seandepagnier Wrote: I'm using an arduino over spi on the hat to receive rf signals as well as other functions.  This is not the same atmega as the motor controller.

Ok.  I got a bit confused because this command was in hat/arduino.py.

I looked into motor controller programming.  @seandepagnier, you probably know all this, so I'm half talking out loud for my own benefit, half for anyone else.

As you mentioned, if I burn optiboot into the ATmega, I'll be able to send new firmware over TX/RX with avrdude -c arduino.  The missing link is the reset signal.  I looked into avrdude, and there's no support for specifying a reset pin if you're using -c arduino.  I can see where such code could be added though.  

There are at least two terrible hacks people have done to get around this.  One uses strace to watch for the serial port ioctls that avrdude uses to pulse DTR/RTS, and when that happens, it twiddles a GPIO.  The other intercepts the serial traffic and listens for avrdude to send a particular string:

  https://github.com/deanmao/avrdude-rpi

They are both awful.

What I think I'll do is rely on the fact that optiboot waits one second before falling through.  I can see in the pypilot source that GPIO16 is being used to reset the ATmega.  I'll pulse RESET, then start avrdude over the serial port, and thus I'll hit the programming window.  Sounds feasible? 

(In other news, I need to program optiboot before I solder the ATmega onto the board.  I'm planning to use thisSmile

  https://www.thingiverse.com/thing:2615599


RE: Connections between RPi and nano for flashing - seandepagnier - 2020-10-01

Since the motor controller is optically isolated there is no way to send the reset pulse without an extra isolator just for that which I don't intend to ever use.

What I do is press the reset button on the arduino exactly when running avrdude, or if there is no reset button, apply power to the motor controller at this same moment.

The gpio16 is used to reset the hat arduino which is programmed over spi directly, but again, it is not optically isolated, it runs at 3.3v and is used only to receive RF, IR, and provide an extra serial port and some gpio and analog inputs.