Flashing M128

er9x is the best known firmware. It has a superb range of features and is well supported by the community. Well worth trying out.
User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Flashing M128

Post by MikeB » Thu Dec 18, 2014 3:24 pm

Those following the MegaSound board will know I ported the OptiBoot bootloader onto it to make flashing that easier.
I have just ported OptiBoot to the ATMEGA128 and have it running on my M128 9X board. I'm still testing it but so far I have successfully read both the EEPROM and the flash memory.
You run the bootloader by command, as with the ersky9x bootloader, you power on with both horizontal trims held inwards.

This 9X has a 'proper' RS232 buffer in it for telemetry, so I'm connecting using the module pins to a standard serial to USB adapter. I will test later using a logic level serial directly to the programming pins of the 10-way connector I normally use for programming.

At the moment, the bootloader uses 636 bytes of flash. This means it would fit in a M64, the last M64 (FrSky) build I did had 1750 bytes free. Whether this is the best use of the flash on the M64 may be another question.

One advantage of using this is you would no longer need a USBASP (except in disaster recovery), so you would not need to get the USBASP drivers installed.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Thu Dec 18, 2014 4:55 pm

woow, this one was unexpected :) So does that mean we just need a FTDI adapter inside the radio, or something else?

Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
KAL
Posts: 551
Joined: Thu Oct 10, 2013 4:36 pm
Country: Germany
Location: somewhere near Rothenburg ob der Tauber

Re: Flashing M128

Post by KAL » Thu Dec 18, 2014 5:15 pm

Wow,

do I understand this right: The 9x then can be flashed via the MicroSD of the megasound board?
Then it nearly would be worth to spend the 9X an external MicroSD slot ...

Klaus
( TH9X / 9XTreme / FrSky DHT / Spektrum / Multi / RotEnc )
( 9XR PRO / erSKY9x  / FrSky DHT / Spektrum / Multi / RotEnc / P3 as Slider )

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Thu Dec 18, 2014 5:19 pm

I like to spring the occasional surprise!

I would think a FTDI would work, I've still not tested logic level serial.

Code size is down to 578 bytes. I found a problem writing the flash when going over the 64K boundary, now fixed I think, I just flashed a copy of er9x to it apparantly OK.

The baudrate is 115200.

I think there is still a problem when getting to the processor boot section, looking into that now, but er9x-128 isn't anything like that big.

A version for the '2561 may follow!

KAL: Sorry, no. Just connect a serial interface to the '128 and flash from the PC, but using the same method you would use to flash the MegaSound board.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Thu Dec 18, 2014 5:29 pm

MikeB wrote:I like to spring the occasional surprise!
I would be careful if I were you ;) At this time of the year people might start calling you Santa :mrgreen: :mrgreen: :mrgreen:
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW


User avatar
KAL
Posts: 551
Joined: Thu Oct 10, 2013 4:36 pm
Country: Germany
Location: somewhere near Rothenburg ob der Tauber

Re: Flashing M128

Post by KAL » Thu Dec 18, 2014 5:34 pm

Ah, I see.

So my thoughts went the wrong direction ;)
Nevertheless a great way to overcome the USBASP driver problems with Win8.1

Klaus
( TH9X / 9XTreme / FrSky DHT / Spektrum / Multi / RotEnc )
( 9XR PRO / erSKY9x  / FrSky DHT / Spektrum / Multi / RotEnc / P3 as Slider )

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Thu Dec 18, 2014 7:31 pm

Having successfully read and written the EEPROM as well as the flash, here is the first test version:
er9x-128B.zip
18-Dec-2014 19:10
First test version of M128 serial bootloader
(157.16 KiB) Downloaded 70 times
er9x-128B.hex is the version of er9x-128 that includes the processing for the two horizontal trims. If you flash a version of er9x-128 without this in, you lose access to the bootloader. I could add code to the bootloader, and we could change the fuses to force power on to go to the bootloader as a future enhancement if required.

optiboot_atmega128.hex is the bootloader itself.
I have combined the two into er9x-128combi.hex, but I haven't flashed that (yet).

I have still to test a logic level serial connection.

As usual, backup your EEPROM before testing this!

Suggested flashing method.
1. Flash er9x-128B.hex using your normal flashing method.
2. Flash optiboot_atmega128.hex using the -D option to AvrDude to prevent a chip erase.

If you power on normally, then er9x should run. If you power on with the two horizontal trims held towards the centre, you should see "Bootloader" on the display.

The next step is to test the bootloader. For this you need to connect a serial port to the 9X. Since I have a RS232 buffer on the module pins for telemetry I used these. Pin 5 (bottom pin) is TxD from the serial port and pin 2 is Rxd to the serial port, and pin 4 is ground (pin 3 is the battery voltage).
If you want to try a logic level serial, and have a 10-way connector soldered to the board (for a USBASP or other programmer) then pin 1 (MOSI) is the TxD from the serial, pin 9 (MISO) is RxD to the serial and pins 4,6,8 and 10 are ground. You may only have one of these wired to your 9X board.

Run eepe and go to the Burn|Configure dialog. Set the programmer to arduino, mcu to m128, Port to whatever serial port you are using and the Extra Arguments to -b 115200. I'm not sure if you have to set the -b value, but this is what I'm using.

If you have powered the 9X up in bootloader mode, then just try reading the EEPROM from eepe as a first test.

Should you write to the EEPROM, you might notice it writes a bit faster. This is because the bootloader code skips writing any value that is already correct.

Mike.
Edit: 152000 changed to 115200
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Thu Dec 18, 2014 8:16 pm

Mike, I wrote "-D" in the extra arguments, eepe flashed the bootloader but it did not finish correctly. Well, at least it is what the error said. The radio turns on normally, and also when powered with both trims to the center I get bootloader on the screen.. Here is the output report.
=================================================================================
Started AVRDUDE
C:/Program Files (x86)/eePe/avrdude.exe -c stk500v2 -p m128 -D -P com3 -U flash:w:D:/Modelismo/er9x/Firmware/er9x-128 with bootloader test/optiboot_atmega128.hex:i
=================================================================================

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude.exe: Device signature = 0x1e9702
avrdude.exe: reading input file "D:/Modelismo/er9x/Firmware/er9x-128 with bootloader test/optiboot_atmega128.hex"
avrdude.exe: writing flash (130636 bytes):

Writing | ################################################## | 100% 0.17s

avrdude.exe: 130636 bytes of flash written
avrdude.exe: verifying flash memory against D:/Modelismo/er9x/Firmware/er9x-128 with bootloader test/optiboot_atmega128.hex:
avrdude.exe: load data flash data from input file D:/Modelismo/er9x/Firmware/er9x-128 with bootloader test/optiboot_atmega128.hex:
avrdude.exe: input file D:/Modelismo/er9x/Firmware/er9x-128 with bootloader test/optiboot_atmega128.hex contains 130636 bytes
avrdude.exe: reading on-chip flash data:

Reading | ################################################## | 100% 18.45s

avrdude.exe: verifying ...
avrdude.exe: verification error, first mismatch at byte 0x0000
0xff != 0x0c
avrdude.exe: verification error; content mismatch
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Thu Dec 18, 2014 8:45 pm

That looks like an AvrDude problem. It says writing 130636 bytes, but is actually only writing about 600, hence the 0.17s time.
It then reads 130636 bytes of flash (taking 18.45 seconds). I think it then gets the verification completely wrong. There is no byte at 0 in the hex file, so it uses 0xFF which is clearly not what is actually at address 0x00.
I think the flash operation has worked OK.
AvrDude should only verify the bytes it has written.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Thu Dec 18, 2014 8:57 pm

Mike, whatever I do with the FTDI I get this error

avrdude.exe: stk500_getsync(): not in sync: resp=0x00

I have the FTDI connected to the 6 pin programmer header..
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Thu Dec 18, 2014 9:10 pm

I'll have to try the logic level serial myself.
Have you got a module plugged in?

Double checking you have the programmer set to arduino and the -b 115200 set?

If you have a 6-pin, not a 10-pin, connector then MISO is pin 1 (not 9) and MOSI is 4 (not 1). Ground is pin 6.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Thu Dec 18, 2014 9:24 pm

I got results now.. Mike, please edit your post above.. You wrote -b 152000 instead of -b 115200 ;) That was the reason it didn't work.. So, that line is needed in the extra arguments..

I have a successful eeprom read. FTDI works and I have a DHT installed inside this radio

Next step? ;) :D

João
=================================================================================
Started AVRDUDE
C:/Program Files (x86)/eePe/avrdude.exe -c arduino -p m128 -b 115200 -P com4 -U eeprom:r:C:/Users/Joao/AppData/Local/Temp/temp.hex:i
=================================================================================

avrdude.exe: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude.exe: Device signature = 0x1e9702
avrdude.exe: reading eeprom memory:

Reading | ################################################## | 100% 16.36s

avrdude.exe: writing output file "C:/Users/Joao/AppData/Local/Temp/temp.hex"

avrdude.exe done. Thank you.


=================================================================================
AVRDUDE done - SUCCESSFUL
=================================================================================
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Thu Dec 18, 2014 9:44 pm

Update: Flashed my other radio with the combined hex file, and also got a successful eeprom reading via FTDI.
This radio doesn't have the module connected but it has the level converter inside..

Up to now, all looking good I would say..

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Thu Dec 18, 2014 10:17 pm

I did a fw read. the resulting file is 308Kb long though.. the normal fw file is about 196Kb
File is attached here in case you want to have a look..

João
Attachments
Firmware_Read.zip
(71.61 KiB) Downloaded 34 times
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Thu Dec 18, 2014 11:00 pm

downloaded the eeprom, edited it, and flashed it back to the radio..

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Fri Dec 19, 2014 12:09 am

Sounds good. The firmware read is OK. The normal firmware file only has around 70K in it, the firmware read has the whole 128K in it.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Fri Dec 19, 2014 12:12 am

yes, but the read was 308Kb..

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Fri Dec 19, 2014 12:19 am

Yes, it's a .hex file so every byte is two hex characters, then you have the 'overhead' characters for each line with address, checksum and <cr><lf>. The 70K of code needs 196K of hex file so 128K of code going to 308K of hex file is about right.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Fri Dec 19, 2014 12:21 am

That's good then.. what's next? flash the fw? ;)
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Fri Dec 19, 2014 12:25 am

I should think so, make sure you use the file I posted (not the combi one that would try to overwrite the bootloader itself).
I probably should block writes to the bootloader!

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Fri Dec 19, 2014 12:27 am

I think it would be safer.. Ok, report in a few seconds ;) The file is the er9x.128B.hex I suppose?
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Fri Dec 19, 2014 12:34 am

Ok, flashed the radio, turned it on and it's working.. then read the eeprom to eepe, and it was successful..

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Sat Dec 20, 2014 10:43 pm

This seems to be working, and I've even got a copy on the M64. Since I just "found" over 800 spare bytes in the M64, and the bootloader for the M64 fits in 512 bytes, this isn't too bad.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Sat Dec 20, 2014 11:13 pm

Mike, can you fit the voice alarms in the m64? I think that would be important?

Thanks
João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Sat Dec 20, 2014 11:57 pm

I'll look again, but I'm fairly certain they take up much too much space to fit.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Sun Dec 21, 2014 12:37 am

wouldn't in this case the voice alarms be more important than the bootloader? I mean people can still flash the radio using the usbasp..
Having the ability to flash fw and eeprom with a FTDI is nice (still have to test if it doesn't get any conflict with the telemetry if I leave it connected) specially if we could leave it inside the radio.. Just plug the USB and you're good to go.. Only 3 wires to connect.
But the guys with the m64 still have the usbasp programmer and maybe there are more important things to leave in..

Just my 2c..

João.
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Sun Dec 21, 2014 10:08 am

I know, but the voice alarms still wouldn't fit, as I said I will check.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Sun Dec 21, 2014 10:31 am

Thanks ;)
João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

User avatar
MikeB
9x Developer
Posts: 15617
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Flashing M128

Post by MikeB » Sun Dec 21, 2014 12:29 pm

My best estimate for the M64-FrSky (without the bootlaoder) is there are 2574 spare bytes of flash and the voice alarms need at least 2658 bytes. These are only quite close now because I just saved 800 bytes with the RCALL compile option.

Mike.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 17814
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Flashing M128

Post by jhsa » Sun Dec 21, 2014 12:48 pm

Yep, still not enough space anyway.
what about if you remove the voice, audio and haptic from the safety switches? would you save flash then? In my opinion no point in having it twice as all that is already in the voice alarms, and much better and organized..That applies to the other boards too of course..

Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW

Post Reply

Return to “er9x”