stefanrueger / urboot

Small AVR bootloader using urprotocol
GNU General Public License v3.0
55 stars 8 forks source link

Provide options to build urboot autobaud firmware for other serial port #14

Closed mcuee closed 1 year ago

mcuee commented 1 year ago

It would be great to provide urboot hex files for non-default serial port. I think this is one of the major missing feature from urboot.

As per the previous discussions in avrdude, it may not be so easy to do this automatically though.

Maybe @MCUdude has some ideas since he has done this in optiboot_flash.

mcuee commented 1 year ago

Features like automatically detect which serial port to use may be even more troublesome and may not be worth the efforts.

stefanrueger commented 1 year ago

It's certainly possible to compile bootloaders for USART1, USART2, ... for fixed baud rates: When you compile an urboot bootloader you can set which USART you want the comms to be on: Just specify UARTNUM=x when using make or -DUARTNUM=x when compiling... (x=0, 1, 2, ...).

However, for autobaud urboot.c needs to know the RX line of the chosen USART to measure the baud rate before initialising the USART. The table here here needs filling in. The atdf files are not great for this. Maybe someone can help?

(As for the Optiboot Issue #285 I don't know of a valid use case, and cannot imagine one, for the bootloader "automatically" scanning where communications come from. In my world, bootloaders should utilise as few I/O lines as possible and these should be known and fixed; otherwise if the bootloader starts twiggling all sorts of I/O lines at each reset, the projects implemented on the board might do strange things while the I/O lines are scanned: just imagine one of the I/O lines opens the gate of the attached alligator compound... this does not bear thinking about :)

mcuee commented 1 year ago

The table is copied here fore reference.

I actually don't even have a table for now many USARTS any one part has (beyond 0 or > 0).

Here is an example of what would be good:

Part NUART RXD0 TXD0 RXD1 TXD1 RXD2 TXD2 RXD3 TXD3
attiny167 0
atmega328p 1 PD0 PD1
atmega328pb 2 PD0 PD1 PB4 PB3
atmega2560 4 PE0 PE1 PD2 PD3 PH0 PH1 PJ0 PJ1

Here is what I have in machine-readable format (you can tell my xml-fu with atdfs is waning). And there are likely some mistakes in that table, too :(

Incomplete RX/TX table for UART parts | Part | NUART || RXD0 | TXD0 || RXD1 | TXD1 || RXD2 | TXD2 || RXD3 | TXD3 | | --: |:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:| |ATtiny4|0|| | || | || | || | | |ATtiny5|0|| | || | || | || | | |ATtiny9|0|| | || | || | || | | |ATtiny10|0|| | || | || | || | | |ATtiny20|0|| | || | || | || | | |ATtiny40|0|| | || | || | || | | |ATtiny102| >0 ||PB3|PB2|| | || | || | | |ATtiny104| >0 ||PB3|PB2|| | || | || | | |ATtiny11|0|| | || | || | || | | |ATtiny12|0|| | || | || | || | | |ATtiny13|0|| | || | || | || | | |ATtiny13A|0|| | || | || | || | | |ATtiny15|0|| | || | || | || | | |ATtiny22| ?? || | || | || | || | | |ATtiny24|0|| | || | || | || | | |ATtiny24A|0|| | || | || | || | | |ATtiny25|0|| | || | || | || | | |ATtiny26|0|| | || | || | || | | |ATtiny28|0|| | || | || | || | | |ATtiny43U|0|| | || | || | || | | |ATtiny44|0|| | || | || | || | | |ATtiny44A|0|| | || | || | || | | |ATtiny45|0|| | || | || | || | | |ATtiny48|0|| | || | || | || | | |ATtiny84|0|| | || | || | || | | |ATtiny84A|0|| | || | || | || | | |ATtiny85|0|| | || | || | || | | |ATtiny87|0|| | || | || | || | | |ATtiny88|0|| | || | || | || | | |ATtiny167|0|| | || | || | || | | |ATtiny261|0|| | || | || | || | | |ATtiny261A|0|| | || | || | || | | |ATtiny441| >0 ||PA4|PA5|| | || | || | | |ATtiny461|0|| | || | || | || | | |ATtiny461A|0|| | || | || | || | | |ATtiny828| >0 ||PC2|PC3|| | || | || | | |ATtiny828R| ?? || | || | || | || | | |ATtiny841| >0 ||PA4|PA5|| | || | || | | |ATtiny861|0|| | || | || | || | | |ATtiny861A|0|| | || | || | || | | |ATtiny1634| >0 ||PA7|PB0|| | || | || | | |ATtiny1634R| ?? || | || | || | || | | |ATtiny2313| >0 ||PD0|PD1|| | || | || | | |ATtiny2313A| >0 ||PD0|PD1|| | || | || | | |ATtiny4313| >0 ||PD0|PD1|| | || | || | | |ATmega8| >0 ||PD0|PD1|| | || | || | | |ATmega8A| >0 ||PD0|PD1|| | || | || | | |ATmega8HVA|0|| | || | || | || | | |ATmega8U2| >0 ||PD2|PD3|| | || | || | | |ATmega16| >0 ||PD0|PD1|| | || | || | | |ATmega16A| >0 ||PD0|PD1|| | || | || | | |ATmega16HVA|0|| | || | || | || | | |ATmega16HVB|0|| | || | || | || | | |ATmega16HVBrevB|0|| | || | || | || | | |ATmega16M1|0|| | || | || | || | | |ATmega16HVA2|0|| | || | || | || | | |ATmega16U2| >0 ||PD2|PD3|| | || | || | | |ATmega16U4| >0 ||PD2|PD3|| | || | || | | |ATmega32| >0 ||PD0|PD1|| | || | || | | |ATmega32A| >0 ||PD0|PD1|| | || | || | | |ATmega32HVB|0|| | || | || | || | | |ATmega32HVBrevB|0|| | || | || | || | | |ATmega32C1|0|| | || | || | || | | |ATmega32M1|0|| | || | || | || | | |ATmega32U2| >0 ||PD2|PD3|| | || | || | | |ATmega32U4| >0 ||PD2|PD3|| | || | || | | |ATmega32U6| ?? || | || | || | || | | |ATmega48| >0 ||PD0|PD1|| | || | || | | |ATmega48A| >0 ||PD0|PD1|| | || | || | | |ATmega48P| >0 ||PD0|PD1|| | || | || | | |ATmega48PA| >0 ||PD0|PD1|| | || | || | | |ATmega48PB| >0 ||PD0|PD1|| | || | || | | |ATmega64| >0 ||PE0|PE1|| | || | || | | |ATmega64A| >0 ||PE0|PE1|| | || | || | | |ATmega64HVE|0|| | || | || | || | | |ATmega64C1|0|| | || | || | || | | |ATmega64M1|0|| | || | || | || | | |ATmega64HVE2|0|| | || | || | || | | |ATmega64RFR2| >0 ||PE0|PE1|| | || | || | | |ATmega88| >0 ||PD0|PD1|| | || | || | | |ATmega88A| >0 ||PD0|PD1|| | || | || | | |ATmega88P| >0 ||PD0|PD1|| | || | || | | |ATmega88PA| >0 ||PD0|PD1|| | || | || | | |ATmega88PB| >0 ||PD0|PD1|| | || | || | | |ATmega103| ?? || | || | || | || | | |ATmega128| >0 ||PE0|PE1|| | || | || | | |ATmega128A| >0 ||PE0|PE1|| | || | || | | |ATmega128RFA1| >0 ||PE0|PE1|| | || | || | | |ATmega128RFR2| >0 ||PE0|PE1|| | || | || | | |ATmega161| >0 ||PD0|PD1|| | || | || | | |ATmega162| >0 ||PD0|PD1|| | || | || | | |ATmega163| >0 ||PD0|PD1|| | || | || | | |ATmega164A| >0 ||PD0|PD1|| | || | || | | |ATmega164P| >0 ||PD0|PD1|| | || | || | | |ATmega164PA| >0 ||PD0|PD1|| | || | || | | |ATmega165| >0 ||PE0|PE1|| | || | || | | |ATmega165A| >0 ||PE0|PE1|| | || | || | | |ATmega165P| >0 ||PE0|PE1|| | || | || | | |ATmega165PA| >0 ||PE0|PE1|| | || | || | | |ATmega168| >0 ||PD0|PD1|| | || | || | | |ATmega168A| >0 ||PD0|PD1|| | || | || | | |ATmega168P| >0 ||PD0|PD1|| | || | || | | |ATmega168PA| >0 ||PD0|PD1|| | || | || | | |ATmega168PB| >0 ||PD0|PD1|| | || | || | | |ATmega169| >0 ||PE0|PE1|| | || | || | | |ATmega169A| >0 ||PE0|PE1|| | || | || | | |ATmega169P| >0 ||PE0|PE1|| | || | || | | |ATmega169PA| >0 ||PE0|PE1|| | || | || | | |ATmega256RFR2| >0 ||PE0|PE1|| | || | || | | |ATmega323| >0 ||PD0|PD1|| | || | || | | |ATmega324A| >0 ||PD0|PD1|| | || | || | | |ATmega324P| >0 ||PD0|PD1|| | || | || | | |ATmega324PA| >0 ||PD0|PD1|| | || | || | | |ATmega324PB| >0 ||PD0|PD1|| | || | || | | |ATmega325| >0 ||PE0|PE1|| | || | || | | |ATmega325A| >0 ||PE0|PE1|| | || | || | | |ATmega325P| >0 ||PE0|PE1|| | || | || | | |ATmega325PA| >0 ||PE0|PE1|| | || | || | | |ATmega328| >0 ||PD0|PD1|| | || | || | | |ATmega328P| >0 ||PD0|PD1|| | || | || | | |ATmega328PB| >0 ||PD0|PD1|| | || | || | | |ATmega329| >0 ||PE0|PE1|| | || | || | | |ATmega329A| >0 ||PE0|PE1|| | || | || | | |ATmega329P| >0 ||PE0|PE1|| | || | || | | |ATmega329PA| >0 ||PE0|PE1|| | || | || | | |ATmega406|0|| | || | || | || | | |ATmega640| >0 ||PE0|PE1|| | || | || | | |ATmega644| >0 ||PD0|PD1|| | || | || | | |ATmega644A| >0 ||PD0|PD1|| | || | || | | |ATmega644P| >0 ||PD0|PD1|| | || | || | | |ATmega644PA| >0 ||PD0|PD1|| | || | || | | |ATmega644RFR2| >0 ||PE0|PE1|| | || | || | | |ATmega645| >0 ||PE0|PE1|| | || | || | | |ATmega645A| >0 ||PE0|PE1|| | || | || | | |ATmega645P| >0 ||PE0|PE1|| | || | || | | |ATmega649| >0 ||PE0|PE1|| | || | || | | |ATmega649A| >0 ||PE0|PE1|| | || | || | | |ATmega649P| >0 ||PE0|PE1|| | || | || | | |ATmega1280| >0 ||PE0|PE1|| | || | || | | |ATmega1281| >0 ||PE0|PE1|| | || | || | | |ATmega1284| >0 ||PD0|PD1|| | || | || | | |ATmega1284P| >0 ||PD0|PD1|| | || | || | | |ATmega1284RFR2| >0 ||PE0|PE1|| | || | || | | |ATmega2560| >0 ||PE0|PE1|| | || | || | | |ATmega2561| >0 ||PE0|PE1|| | || | || | | |ATmega2564RFR2| >0 ||PE0|PE1|| | || | || | | |ATmega3250| >0 ||PE0|PE1|| | || | || | | |ATmega3250A| >0 ||PE0|PE1|| | || | || | | |ATmega3250P| >0 ||PE0|PE1|| | || | || | | |ATmega3250PA| >0 ||PE0|PE1|| | || | || | | |ATmega3290| >0 ||PE0|PE1|| | || | || | | |ATmega3290A| >0 ||PE0|PE1|| | || | || | | |ATmega3290P| >0 ||PE0|PE1|| | || | || | | |ATmega3290PA| >0 ||PE0|PE1|| | || | || | | |ATmega6450| >0 ||PE0|PE1|| | || | || | | |ATmega6450A| >0 ||PE0|PE1|| | || | || | | |ATmega6450P| >0 ||PE0|PE1|| | || | || | | |ATmega6490| >0 ||PE0|PE1|| | || | || | | |ATmega6490A| >0 ||PE0|PE1|| | || | || | | |ATmega6490P| >0 ||PE0|PE1|| | || | || | | |ATmega8515| >0 ||PD0|PD1|| | || | || | | |ATmega8535| >0 ||PD0|PD1|| | || | || | | |AT43USB320| ?? || | || | || | || | | |AT43USB355| ?? || | || | || | || | | |AT76C711| ?? || | || | || | || | | |AT86RF401| ?? || | || | || | || | | |AT90PWM1|0|| | || | || | || | | |AT90PWM2| ?? || | || | || | || | | |AT90PWM2B| ?? || | || | || | || | | |AT90PWM3| ?? || | || | || | || | | |AT90PWM3B| ?? || | || | || | || | | |AT90CAN32| >0 ||PD2|PD3|| | || | || | | |AT90CAN64| >0 ||PD2|PD3|| | || | || | | |AT90PWM81|0|| | || | || | || | | |AT90USB82| ?? || | || | || | || | | |AT90SCR100| ?? || | || | || | || | | |AT90CAN128| >0 ||PD2|PD3|| | || | || | | |AT90PWM161|0|| | || | || | || | | |AT90USB162| ?? || | || | || | || | | |AT90PWM216| ?? || | || | || | || | | |AT90PWM316| ?? || | || | || | || | | |AT90USB646| ?? || | || | || | || | | |AT90USB647| ?? || | || | || | || | | |AT90S1200| ?? || | || | || | || | | |AT90USB1286| ?? || | || | || | || | | |AT90USB1287| ?? || | || | || | || | | |AT90S2313| ?? || | || | || | || | | |AT90S2323| ?? || | || | || | || | | |AT90S2333| ?? || | || | || | || | | |AT90S2343| ?? || | || | || | || | | |AT90S4414| ?? || | || | || | || | | |AT90S4433| ?? || | || | || | || | | |AT90S4434| ?? || | || | || | || | | |AT90S8515| ?? || | || | || | || | | |AT90C8534| ?? || | || | || | || | | |AT90S8535| ?? || | || | || | || | | |AT94K| ?? || | || | || | || | | |ATA5272|0|| | || | || | || | | |ATA5505|0|| | || | || | || | | |ATA5700M322|0|| | || | || | || | | |ATA5702M322|0|| | || | || | || | | |ATA5781|0|| | || | || | || | | |ATA5782|0|| | || | || | || | | |ATA5783|0|| | || | || | || | | |ATA5787| ?? || | || | || | || | | |ATA5790|0|| | || | || | || | | |ATA5790N|0|| | || | || | || | | |ATA5791|0|| | || | || | || | | |ATA5795|0|| | || | || | || | | |ATA5831|0|| | || | || | || | | |ATA5832|0|| | || | || | || | | |ATA5833|0|| | || | || | || | | |ATA5835| ?? || | || | || | || | | |ATA6285|0|| | || | || | || | | |ATA6286|0|| | || | || | || | | |ATA6289|0|| | || | || | || | | |ATA6612C| ?? || | || | || | || | | |ATA6613C| ?? || | || | || | || | | |ATA6614Q| ?? || | || | || | || | | |ATA6616C|0|| | || | || | || | | |ATA6617C|0|| | || | || | || | | |ATA8210|0|| | || | || | || | | |ATA8215|0|| | || | || | || | | |ATA8510|0|| | || | || | || | | |ATA8515|0|| | || | || | || | | |ATA664251|0|| | || | || | || | | |M3000| ?? || | || | || | || | | |LGT8F88P| ?? || | || | || | || | | |LGT8F168P| ?? || | || | || | || | | |LGT8F328P| ?? || | || | || | || | | |ATxmega8E5| >0 ||PC2|PC3|| | || | || | | |ATxmega16A4| ?? || | || | || | || | | |ATxmega16A4U| >0 ||PC2|PC3|| | || | || | | |ATxmega16C4| >0 ||PC2|PC3|| | || | || | | |ATxmega16D4| >0 ||PC2|PC3|| | || | || | | |ATxmega16E5| >0 ||PC2|PC3|| | || | || | | |ATxmega32C3| >0 ||PC2|PC3|| | || | || | | |ATxmega32D3| >0 ||PC2|PC3|| | || | || | | |ATxmega32A4| ?? || | || | || | || | | |ATxmega32A4U| >0 ||PC2|PC3|| | || | || | | |ATxmega32C4| >0 ||PC2|PC3|| | || | || | | |ATxmega32D4| >0 ||PC2|PC3|| | || | || | | |ATxmega32E5| >0 ||PC2|PC3|| | || | || | | |ATxmega64A1| ?? || | || | || | || | | |ATxmega64A1U| >0 ||PC2|PC3|| | || | || | | |ATxmega64B1| >0 ||PC2|PC3|| | || | || | | |ATxmega64A3| ?? || | || | || | || | | |ATxmega64A3U| >0 ||PC2|PC3|| | || | || | | |ATxmega64B3| >0 ||PC2|PC3|| | || | || | | |ATxmega64C3| >0 ||PC2|PC3|| | || | || | | |ATxmega64D3| >0 ||PC2|PC3|| | || | || | | |ATxmega64A4| ?? || | || | || | || | | |ATxmega64A4U| >0 ||PC2|PC3|| | || | || | | |ATxmega64D4| >0 ||PC2|PC3|| | || | || | | |ATxmega128A1| ?? || | || | || | || | | |ATxmega128A1revD| ?? || | || | || | || | | |ATxmega128A1U| >0 ||PC2|PC3|| | || | || | | |ATxmega128B1| >0 ||PC2|PC3|| | || | || | | |ATxmega128A3| ?? || | || | || | || | | |ATxmega128A3U| >0 ||PC2|PC3|| | || | || | | |ATxmega128B3| >0 ||PC2|PC3|| | || | || | | |ATxmega128C3| >0 ||PC2|PC3|| | || | || | | |ATxmega128D3| >0 ||PC2|PC3|| | || | || | | |ATxmega128A4| ?? || | || | || | || | | |ATxmega128A4U| >0 ||PC2|PC3|| | || | || | | |ATxmega128D4| >0 ||PC2|PC3|| | || | || | | |ATxmega192A1| ?? || | || | || | || | | |ATxmega192A3| ?? || | || | || | || | | |ATxmega192A3U| >0 ||PC2|PC3|| | || | || | | |ATxmega192C3| ?? || | || | || | || | | |ATxmega192D3| >0 ||PC2|PC3|| | || | || | | |ATxmega256A1| ?? || | || | || | || | | |ATxmega256A3| ?? || | || | || | || | | |ATxmega256A3B| ?? || | || | || | || | | |ATxmega256A3BU| >0 ||PC2|PC3|| | || | || | | |ATxmega256A3U| >0 ||PC2|PC3|| | || | || | | |ATxmega256C3| >0 ||PC2|PC3|| | || | || | | |ATxmega256D3| >0 ||PC2|PC3|| | || | || | | |ATxmega384C3| >0 ||PC2|PC3|| | || | || | | |ATxmega384D3| >0 ||PC2|PC3|| | || | || | | |ATtiny202| >0 ||PA7|PA6|| | || | || | | |ATtiny204| >0 ||PB3|PB2|| | || | || | | |ATtiny212| >0 ||PA7|PA6|| | || | || | | |ATtiny214| >0 ||PB3|PB2|| | || | || | | |ATtiny402| >0 ||PA7|PA6|| | || | || | | |ATtiny404| >0 ||PB3|PB2|| | || | || | | |ATtiny406| >0 ||PB3|PB2|| | || | || | | |ATtiny412| >0 ||PA7|PA6|| | || | || | | |ATtiny414| >0 ||PB3|PB2|| | || | || | | |ATtiny416| >0 ||PB3|PB2|| | || | || | | |ATtiny416auto| >0 ||PB3|PB2|| | || | || | | |ATtiny417| >0 ||PB3|PB2|| | || | || | | |ATtiny424| >0 ||PB3|PB2|| | || | || | | |ATtiny426| >0 ||PB3|PB2|| | || | || | | |ATtiny427| >0 ||PB3|PB2|| | || | || | | |ATtiny804| >0 ||PB3|PB2|| | || | || | | |ATtiny806| >0 ||PB3|PB2|| | || | || | | |ATtiny807| >0 ||PB3|PB2|| | || | || | | |ATtiny814| >0 ||PB3|PB2|| | || | || | | |ATtiny816| >0 ||PB3|PB2|| | || | || | | |ATtiny817| >0 ||PB3|PB2|| | || | || | | |ATtiny824| >0 ||PB3|PB2|| | || | || | | |ATtiny826| >0 ||PB3|PB2|| | || | || | | |ATtiny827| >0 ||PB3|PB2|| | || | || | | |ATtiny1604| >0 ||PB3|PB2|| | || | || | | |ATtiny1606| >0 ||PB3|PB2|| | || | || | | |ATtiny1607| >0 ||PB3|PB2|| | || | || | | |ATtiny1614| >0 ||PB3|PB2|| | || | || | | |ATtiny1616| >0 ||PB3|PB2|| | || | || | | |ATtiny1617| >0 ||PB3|PB2|| | || | || | | |ATtiny1624| >0 ||PB3|PB2|| | || | || | | |ATtiny1626| >0 ||PB3|PB2|| | || | || | | |ATtiny1627| >0 ||PB3|PB2|| | || | || | | |ATtiny3214| ?? || | || | || | || | | |ATtiny3216| >0 ||PB3|PB2|| | || | || | | |ATtiny3217| >0 ||PB3|PB2|| | || | || | | |ATtiny3224| >0 ||PB3|PB2|| | || | || | | |ATtiny3226| >0 ||PB3|PB2|| | || | || | | |ATtiny3227| >0 ||PB3|PB2|| | || | || | | |ATmega808| >0 ||PA1|PA0|| | || | || | | |ATmega809| >0 ||PA1|PA0|| | || | || | | |ATmega1608| >0 ||PA1|PA0|| | || | || | | |ATmega1609| >0 ||PA1|PA0|| | || | || | | |ATmega3208| >0 ||PA1|PA0|| | || | || | | |ATmega3209| >0 ||PA1|PA0|| | || | || | | |ATmega4808| >0 ||PA1|PA0|| | || | || | | |ATmega4809| >0 ||PA1|PA0|| | || | || | | |AVR8EA28| ?? || | || | || | || | | |AVR8EA32| ?? || | || | || | || | | |AVR16DD14| >0 ||PA1|PA0|| | || | || | | |AVR16DD20| >0 ||PA1|PA0|| | || | || | | |AVR16DD28| >0 ||PA1|PA0|| | || | || | | |AVR16EA28| ?? || | || | || | || | | |AVR16DD32| >0 ||PA1|PA0|| | || | || | | |AVR16EA32| ?? || | || | || | || | | |AVR16EA48| ?? || | || | || | || | | |AVR32DD14| >0 ||PA1|PA0|| | || | || | | |AVR32DD20| >0 ||PA1|PA0|| | || | || | | |AVR32DA28| >0 ||PA1|PA0|| | || | || | | |AVR32DB28| >0 ||PA1|PA0|| | || | || | | |AVR32DD28| >0 ||PA1|PA0|| | || | || | | |AVR32EA28| ?? || | || | || | || | | |AVR32DA32| >0 ||PA1|PA0|| | || | || | | |AVR32DB32| >0 ||PA1|PA0|| | || | || | | |AVR32DD32| >0 ||PA1|PA0|| | || | || | | |AVR32EA32| ?? || | || | || | || | | |AVR32DA48| >0 ||PA1|PA0|| | || | || | | |AVR32DB48| >0 ||PA1|PA0|| | || | || | | |AVR32EA48| ?? || | || | || | || | | |AVR64DD14| >0 ||PA1|PA0|| | || | || | | |AVR64DD20| >0 ||PA1|PA0|| | || | || | | |AVR64DA28| >0 ||PA1|PA0|| | || | || | | |AVR64DB28| >0 ||PA1|PA0|| | || | || | | |AVR64DD28| >0 ||PA1|PA0|| | || | || | | |AVR64EA28| >0 ||PA1|PA0|| | || | || | | |AVR64DA32| >0 ||PA1|PA0|| | || | || | | |AVR64DB32| >0 ||PA1|PA0|| | || | || | | |AVR64DD32| >0 ||PA1|PA0|| | || | || | | |AVR64EA32| >0 ||PA1|PA0|| | || | || | | |AVR64DA48| >0 ||PA1|PA0|| | || | || | | |AVR64DB48| >0 ||PA1|PA0|| | || | || | | |AVR64EA48| >0 ||PA1|PA0|| | || | || | | |AVR64DA64| >0 ||PA1|PA0|| | || | || | | |AVR64DB64| >0 ||PA1|PA0|| | || | || | | |AVR128DA28| >0 ||PA1|PA0|| | || | || | | |AVR128DB28| >0 ||PA1|PA0|| | || | || | | |AVR128DA32| >0 ||PA1|PA0|| | || | || | | |AVR128DB32| >0 ||PA1|PA0|| | || | || | | |AVR128DA48| >0 ||PA1|PA0|| | || | || | | |AVR128DB48| >0 ||PA1|PA0|| | || | || | | |AVR128DA64| >0 ||PA1|PA0|| | || | || | | |AVR128DB64| >0 ||PA1|PA0|| | || | || | |
stefanrueger commented 1 year ago

I have now managed to collect the RX/TX lines for all UARTs of almost all 8-bit AVR. This has allowed me to create pre-compiled bootloaders for all serial ports of all classic parts. The autobaud feature needs to know on which RX line the host sends data in order to sample it and compute the correct baud rate register UBRRn. This includes the LIN/UARTs of ATtiny167/87 and a dozen or so other parts; that interface is designed for an automotive Local Interconnect Network and can be used as ordinary UART.

Here the table of RX/TX lines for all UARTs of parts in the bash script that creates pre-compiled bootloaders: https://github.com/stefanrueger/urboot/blob/74ecad651111878a53752a03896074d7230ce12f/src/mkurboots#L547-L918

Fun fact 1: Atmel's LIN/UARTs allow the setting of the sample rate 8..63 in addition to the BRR. Classic UARTs only can set the sample rate to 8 or 16. This means that LIN/UARTs can create almost all baud rates within 1% of quantisation error. Urboot bootloaders for these parts make use of that.

Fun fact 2: Classic UARTs struggle to generate 115200 baud from F_CPU = 8 MHz (a whopping 3.7% quantification error). In these cases an urboot bootloader with software I/O is generated instead.

Fun fact 3: The bash script always numbers UARTs of a part starting from UARTNUM=0, irrespective how the data sheet numbers them (some parts only have USART1, the XMEGA parts name their USARTs after the port, eg, USARTC0),

Fun fact 4: Some classic parts (ATtiny441andATtiny841) can assign different alternative pins to RX/TX for an UART. This is done with the CPP constant UARTALT=1 and noted in the file name with _alt1, see here, for example.

Fun fact 5: Some UARTs have RX/TX on a port that is outside the bit addressable I/O space. This happens for UART2 and UART3 on the ATmega2560, for example. As the autobaud sensing loop requires a fast scanning of the RX line, autobaud bootloaders cannot be generated for these UARTs.

Fun fact 6: Software I/O also relies on clock cycles of opcodes and is unable to deal with RX/TX ports outside the bit addressable I/O space (usually Port H and above). So no SWIO for UART2 or UART3 of ATmega2560 either. Bootloaders for ordinary fixed baud rates given F_CPU are possible, and generated, for UARTs with those non-bit-addressable ports though.

Fun fact 7: I have changed the naming scheme of the urboot bootloaders to always indicate the I/O mode (SWIO/UART) and the RX/TX lines that the user should interface the part with.

Fun fact 8: While reviewing the UART initialisation code I realised that almost all classic UARTs already have the UART character size bitfield set to 8N1 after reset, so could save typically 4 bytes.

Fun fact 9: I also realised that a lot of classic parts (around 50%) already initialise SP to RAMEND after reset, so could save that initialisation for a number of parts, too.

@mcuee and @MCUdude, have a look at the generated pre-compiled urboot bootloaders in the urboot.hex repository.

This should close the issue. In fact, I think once you have tested a sample of generated bootloaders, I will want to formally release v7.7 of urboot bootloaders.

mcuee commented 1 year ago

Nice one. I will carry out some tests and report here soon, probably over this weekend.

MCUdude commented 1 year ago

Fun fact 5: Some UARTs have RX/TX on a port that is outside the bit addressable I/O space. This happens for UART2 and UART3 on the ATmega2560, for example. As the autobaud sensing loop requires a fast scanning of the RX line, autobaud bootloaders cannot be generated for these UARTs.

Does "outside the bit addressable I/O space" means above the 8-bit address space? When looking at the ATmega2560 datasheet, it appears to me that only the USART3 registers have addresses above 0xFF:

image

For reference, here are the USART2 registers in the ATmega2560 datasheet:

image
stefanrueger commented 1 year ago

The problem is not where the USART registers are, but where the Port for the RX line is. It is this loop https://github.com/stefanrueger/urboot/blob/74ecad651111878a53752a03896074d7230ce12f/src/urboot.c#L1958-L1960 that needs bit access (using the sbis opcode) to the PIN of the Port of the RX line associated to USART2. And the PIN of Port H is way outside I/O space [0x20, 0x3f]. One loop iteration takes 5 cycles (mapping neatly to the 5 low bit that are measured after the start bit) and cannot afford to be substantially longer...

stefanrueger commented 1 year ago

Maybe I should have clarified: the bit-addressable I/O space is an address region of only 32 bytes (normally from 0x20 onwards, but in some parts from 0 onwards). Only in these 32 bytes can every single bit be individually addressed by the sbis, sbic, sbi, cbi opcodes.

stefanrueger commented 1 year ago

So, I have now refined the UART capabilities, and even cater for ATmega161's single byte that the two different msb-4 bit share between the two 12-bit BRR registers of UART0 and UART1. If anyone has an ATmega161, that's a good edge case to test (slow baud rate with high F_CPU on UART1).

mcuee commented 1 year ago

@stefanrueger

Tested the ATmega2560 115200bps bootloader for UART0/1/2/3 and they all work well. https://github.com/stefanrueger/urboot.hex/tree/main/boards/mega-r3/fcpu_16mhz/115200_bps

Test results here.

I use the avrdude patch from Marius for the testing of UART1/2/3 since I do not have the capacitors with me.

stefanrueger commented 1 year ago

Thanks for testing @mcuee!

So, I trust this issue can now be closed?

mcuee commented 1 year ago

Yes this can be closed.