Author Topic: M0 OTA Programming  (Read 5699 times)

mah115

  • NewMember
  • *
  • Posts: 38
M0 OTA Programming
« on: August 21, 2019, 05:42:43 AM »
I the OTA programming examples aren't working for me, do I need to update the bootloader on the m0?
I wasn't sure if this page is saying I need to update it or it's compatible so I don't need to update it. https://lowpowerlab.com/guide/moteino/moteinom0/

The error I get in the Windows programmer app is:
Available serial ports found: COM1, COM3, COM6, COM8
Opening COM8 @ 115200baud ...
SET TARGET: TO:123FAIL: target set error, exiting...

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 OTA Programming
« Reply #1 on: August 21, 2019, 09:18:59 AM »
What is your setup in terms of hardware? (all nodes involved)

mah115

  • NewMember
  • *
  • Posts: 38
Re: M0 OTA Programming
« Reply #2 on: August 21, 2019, 01:36:50 PM »
I have 2 moteino M0s with the coil antenna, one as the programmer and one as the target.  Both have the external memory chip and are connected to my computer via USB.

From the order invoice:
Moteino M0
  - USB cable: None (default)
  - Transceiver: RFM69HCW - 868/915Mh..
  - Extra FLASH (for OTA, storage): Onboard 4MBit (25X40..

 I compiled and loaded firmwares from the examples, unmodified.  Then I tried to load the same target firmware with the Windows app.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 OTA Programming
« Reply #3 on: August 21, 2019, 02:02:11 PM »
Are you confident the COM8 is the programmer?
I'm not actually sure how the Windows program will act when trying to open an M0 at a specific baud rate.
Do you happen to have an AVR Moteino to try this with (as programmer)?

FWIW The FLASHMEM is only needed on the target.

mah115

  • NewMember
  • *
  • Posts: 38
Re: M0 OTA Programming
« Reply #4 on: August 21, 2019, 05:24:10 PM »
Yes, I'm sure my COM ports are correct.  Is there some way to print out more debug info?

Quote
I'm not actually sure how the Windows program will act when trying to open an M0 at a specific baud rate.

Unfortunately I only have M0 Moteinos.  Does this mean the OTA function hasn't been tested on M0->M0 pairs?

*edit*
Some progress: it may have something to do with the fact that I was trying to use the USB Serial.  I hooked up a USB->serial converter to the serial port of the programmer and use that instead, and I get a bit further:

Opening COM3 @ 115200baud ...
SET TARGET: TO:123
Moteino: [TO:123:OK]
TARGET SET OK
FLX?
Moteino: [HANDSHAKE FAIL]
FAIL: No response from Moteino Target, is Target listening on same Freq/NetworkID & OTA enabled?


and on the target side, I get this printout:
Got [254:4] > 464C583F
« Last Edit: August 21, 2019, 05:44:17 PM by mah115 »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 OTA Programming
« Reply #5 on: August 22, 2019, 10:16:30 AM »
I have a little setup for OTA and I've always used an AVR Moteino for this, never changed it. So yes I haven't tried an M0 yet. I'm pretty sure it has to do with the serial driver of the windows UI not being able to correctly open the serial port of the M0. So it might involve a software change.

Did you use the side header serial port? (ie Serial (vs SerialUSB))?

You can use this hex-ascii converter to look at any HEX output. What you got there is the FLX? handshake request.

Which sketch do you have loaded on your target M0?

mah115

  • NewMember
  • *
  • Posts: 38
Re: M0 OTA Programming
« Reply #6 on: August 22, 2019, 03:08:24 PM »
The result I got above was using pins 30/31 on the M0 as you are suggesting.  So that method does indeed get further than the USBSerial.
However, it seems like the target isn't responding to the FLX? handshake.

The sketch I have loaded on the target is the example target sketch, with one modification to change the LED pin to pin13.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 OTA Programming
« Reply #7 on: August 22, 2019, 04:08:43 PM »
The sketch I have loaded on the target is the example target sketch, with one modification to change the LED pin to pin13.

From here?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 OTA Programming
« Reply #8 on: August 22, 2019, 05:59:50 PM »
One thing I noticed in Target.ino, this section:

#ifdef __AVR_ATmega1284P__
  #define LED           15 // Moteino MEGAs have LEDs on D15
  #define FLASH_SS      23 // and FLASH SS on D23
#else
  #define LED           9 // Moteinos hsave LEDs on D9
  #define FLASH_SS      8 // and FLASH SS on D8
#endif

should be removed and:
- LED replaced by LED_BUILTIN
- FLASH_SS replaced by SS_FLASHMEM

mah115

  • NewMember
  • *
  • Posts: 38
Re: M0 OTA Programming
« Reply #9 on: August 22, 2019, 07:44:14 PM »
Fixing those gets me a bit further:

Opening COM3 @ 115200baud ...
SET TARGET: TO:123
Moteino: [TO:123:OK]
TARGET SET OK
FLX?
FLX?
Moteino: [FLX?OK]
HANDSHAKE OK!
TX > FLX:0:1020000000800020253D00000D3D00000D3D00003A
TIMEOUT: retrying...
TX > FLX:0:1020000000800020253D00000D3D00000D3D00003A
Moteino DEBUG: RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000RFTX > 464C583A303A00800020253D00000D3D00000D3D0000Timeo ut waiting for packet ACK, aborting FLASH operation ... RX > FLASH IMG TRANSMISSION FAIL
OUT OF SYNC: retrying...
TX > FLX:0:1020000000800020253D00000D3D00000D3D00003A RX > SERIAL IN > FLX:0:1020000000800020253D00000D3D00000D3D00003A
FAIL: out of sync (are you running the latest WP libs/sources?)

I'm using RFM69 library 1.3.0 and SPIFlash 101.1.2

mah115

  • NewMember
  • *
  • Posts: 38
Re: M0 OTA Programming
« Reply #10 on: August 24, 2019, 01:39:17 AM »
Poked around with the settings, but didn't get any further.  Has anyone ever gotten OTA working on an M0?

It seems to be hanging in the sendHEXPacket function.
There's these snippits in the code, does this look right?  The code comments say the function should "return the SEQ of the ACK received."  But it looks like we assign a value to tmp but never change it, and then return whether the seq == 0.

Code: [Select]
        uint16_t tmp=0;
        sscanf((const char*)radio.DATA, "FLX:%u:OK", &tmp);
        return tmp == seq;
« Last Edit: August 24, 2019, 03:33:58 AM by mah115 »

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: M0 OTA Programming
« Reply #11 on: August 24, 2019, 08:07:43 AM »
Poked around with the settings, but didn't get any further.  Has anyone ever gotten OTA working on an M0?

It seems to be hanging in the sendHEXPacket function.
There's these snippits in the code, does this look right?  The code comments say the function should "return the SEQ of the ACK received."  But it looks like we assign a value to tmp but never change it, and then return whether the seq == 0.

Code: [Select]
        uint16_t tmp=0;
        sscanf((const char*)radio.DATA, "FLX:%u:OK", &tmp);
        return tmp == seq;
"tmp" supposedly receives the integer value of the character string in radio.Data.  That's what sscanf does.   It would be useful to learn that.  However, since M0 is a 32 bit processor, I wonder if %u format code converts to uint32_t rather than uint16_t.  You might want to try changing the first line to uint32_t and see if that has any effect.  The comparison should still work (but you might get a compiler warning).

mah115

  • NewMember
  • *
  • Posts: 38
Re: M0 OTA Programming
« Reply #12 on: August 24, 2019, 01:52:20 PM »
That didn't fix it unfortunately.  I ordered some regular Moteinos, when they arrive I'll try to use that as a programmer and see if it works.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: M0 OTA Programming
« Reply #13 on: August 26, 2019, 02:46:49 PM »
I made some necessary changes in the OTA code, I believe that was at fault with reprogramming an M0.
I also updated the Programmer/Target examples.
Please download the latest RFM69 library (directly from Github) and replace your local copy (there is no release at this point).

This should at the very least allow you to program an AVR or M0 Target, with an AVR Programmer.

mah115

  • NewMember
  • *
  • Posts: 38
Re: M0 OTA Programming
« Reply #14 on: August 28, 2019, 05:08:33 PM »
Hi Felix,
I'm happy to report that I was able to get the example programs working for a AVR Moteino as programmer and M0 as target.  I still wasn't able to get the M0 working as the programmer, but that's ok for now.  Thanks for fixing this so quickly.

*edit 1*

Actually, not quite there yet.

*edit 2*
After cleaning the build directory and rebuilding, it seems to be working now.

-Mike
« Last Edit: August 29, 2019, 09:11:15 PM by mah115 »