EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: beduino on October 24, 2017, 05:08:40 pm

Title: TSB (A tiny and safe bootloader for AVR-ATtinys and ATmegas) one wire usage
Post by: beduino on October 24, 2017, 05:08:40 pm
Hello,
I found this forum is full of skilled and smart people.

I'm in doubt with this TSB bootloader http://jtxp.org/tech/tinysafeboot_en.htm (http://jtxp.org/tech/tinysafeboot_en.htm) while I'd like to use it as one wire (not two pins RX/TX which is typical default operation mode),
but unfortunatelly I can't find any good example what to pass to tsb executable to enable in generated HEX file eg. PB1 on ATTiny 85.

I've found this great introduction  even wireless bootloader but they use two MPU pins for RX/TX : https://ladvien.com/robots/tsb/ (https://ladvien.com/robots/tsb/)
In this case Attiny85 bootloader HEX file with pins PB1/PB2 is created under Linux with command:

$ tsb tn85 b1b3

Additionally when calling under Linux Fedora downloaded executable:
$ tsb 2>err
I get strange error message:
tsb: Symbol `ospeed' has different size in shared object, consider re-linking

Maybe someone recompiled from provided source assembler file: tsb_tinymega.asm  ?
Howto recompile it under Linux to make tsb executable?
There is no makefile or compile script available in this package downloaded from linked project page above...

Thanks for any help in advance....

Bedu.



Title: Re: TSB (A tiny and safe bootloader for AVR-ATtinys and ATmegas) one wire usage
Post by: Bruce Abbott on October 24, 2017, 07:15:14 pm
To do One-Wire you simply assign both TX and RX to the same pin.

However the asm source is incomplete, so it is useless. To create a bootloader with One-Wire you must invoke the TSB command-line tool in mode 2 - Generate TSB-Installer. The command-line help gives an example:-

SYNTAX 2:     MAKE CUSTOM TSB FIRMWARE

tsb tnxxxx {RxTx} [Filename]   or   tsb mxxxx {RxTx} [Filename]

Generate TSB for designated ATtiny/ATmega using specified I/O.  Firmware file will be Hex (.hex) or Binary (other extension).

Examples:     

tsb tn2313 d0d1 mytiny.hex

Generate TSB installer 'mytiny.hex' for the ATtiny2313 using Port D0=RXD and D1=TXD for serial communications.

tsb m8515 e0e0

Generate TSB for ATmega8515 with bidirectional (One-Wire) interface on port E0. Filename automatically chosen.
 
Title: Re: TSB (A tiny and safe bootloader for AVR-ATtinys and ATmegas) one wire usage
Post by: beduino on October 24, 2017, 07:20:24 pm
Hopefully, I managed to output TSB firmware for ATTiny 85 with PB1 pin as I hope RXD/TXD bidirectional,
however this strange stderr message suggesting re-linking still exists:
Code: [Select]
$ tsb tn85 b1b1
tsb: Symbol `ospeed' has different size in shared object, consider re-linking

Make TSB from code template:   tsb_tn85_b1b1_20161027.hex

RXD = PB1 / TXD = PB1

Modifying reference code 03C0 ... OK

Saved TSB firmware file:   tsb_tn85_b1b1_20161027.hex

Tried nasm -f elf tsb_tinymega.asm  to make compiled assembler source included in linked ZIP file, but only tons of errors and no expected tsb_tinymega.o object file to link later to executable as described in: http://ccm.net/faq/1559-compiling-an-assembly-program-with-nasm (http://ccm.net/faq/1559-compiling-an-assembly-program-with-nasm)  ???

I will try to test generated HEX file and use precompiled tsb executable to connect to serial port with simple "CI-V" interface to see if i'm able flush program to Attiny85 using defined PB1 pin soon,
but it could be nice to recompile tsb to recent Linux distro, so it could be nice find a way to do so, but I have no idea why nasm doesn't work for the moment? Maybe other assembler co,piler is needed for TSB executable?  :-/O

Update: Thanks Bruce Abbott for compilation issues explanation. I hope I will be able run this precompiled TSB software on diffrent Linux distro too and access its build in serial port  :-+
Title: Re: TSB (A tiny and safe bootloader for AVR-ATtinys and ATmegas) one wire usage
Post by: Geoff_S on October 25, 2017, 01:08:33 pm
I used TSB for a bootloader with single-wire comms on a Tiny841 quite successfully.  It's been some time since I worked with it (and I only used it under Windows, so I can't help with the compilation issues).  I dug up some of my notes and found this note that I wrote to remind myself how to do it:
"Run tsb.exe from command line with following arguments (replace "mytsb.hex" with desired filename for bootloader hex file):
c:\> tsb tn841 a1a1 mytsb.hex 
this specifies target chip at a Tiny841, and RxD and TxD ports as a1 and a1 (ie one-wire comms)"

Hope that helps.
Title: Re: TSB (A tiny and safe bootloader for AVR-ATtinys and ATmegas) one wire usage
Post by: beduino on October 25, 2017, 06:59:51 pm
Thanks everyone for help.

Meantime, I've made disassembled source of generated TSB HEX for Attiny85 one wire PB1 pin (attached as text file) and if it works as exepcted, I'd like to make RESET pin available as regular I/O on attiny85 and try to use it as bootloader one wire, which means If something goes wrong I will be able reflash only with HV programming, but it it not a problem if bootloader on enabled RESET pin as regular I/O worked as expected-no more need to reflash to load new firmware...

Lets see on disassembled code how one wire is used in TSB and how it works  :-/O
Title: Re: TSB (A tiny and safe bootloader for AVR-ATtinys and ATmegas) one wire usage
Post by: beduino on October 28, 2017, 07:13:16 pm
Now, since TSB firmware software is examined at assembler level, I'm looking for decent One-Wire adaptor for the Host, often referred to as "CI-V" interface to connect my MPU pin and test TSB after flashing generated TSB firmware HEX to Attiny85 MPU and started with this Icom CI-V interface: http://www.qsl.net/g3vgr/civ.html (http://www.qsl.net/g3vgr/civ.html) .

However, to use it with 5VCC or 3.3VCC  powered MPU I need 5V/3.3V voltage regulator between D1 and C1 capacitor, I guess, since typical voltage levels on DB9 might destroy my MPU input ports?  ???
I've made simple SMD prototype circuit fro DB9 male connector according to schematics at linked page above, but havent got time to test it...
Not sure, what D2 diode does? My guess is it protects Q1 NPN transistor emiter reverse voltage to stay at safe levels ?  :-\

Anyway, main concern is voltage output on Tip pin when Db9 pin 3 transmit data is low ... another story is some USB to RS-232 converters eg. based on not FTDI but silimar Silicon Labs CP210x USB to UART chips I have - probably voltage levels in such converter will not go above 5V at pin 1 , 4, 6 which are connected in this design?

Now thinking on something different.. maybe old good voltage level shifters used in I2C interface between output Tip and my MPU powered at 5v or maybe even 3.3V, however I prefere 5V for Attiny85 since I usually switch at the begining odf the program to internal 16MHz oscilator from default one used for flash programming, etc...

What do you think, howto connect such dongle with respect to corrent voltage levels to 5V/3.3V Attiny85 MPU for one-wire TSB working with different USB to RS-232 converters and oryginal DB9 PC female ports available?

Now, I like idea of voltage levels shifting but what do you think about it?
Galvanic separation not needed for the moment - my concern is correct voltage levels to do not burn MPU input port used for one-wire TSB as well as data echange using custom one-wire protocol.

Regards.
Bedu.
Title: Re: TSB (A tiny and safe bootloader for AVR-ATtinys and ATmegas) one wire usage
Post by: beduino on October 28, 2017, 08:10:14 pm
Yep, NXP application note on voltage level shifting in I2C interfaces looks like nice fits into my design, since I've already one-wire MPU pin with pull up resistor, so only one additional NPN mosfet should do the trick, so lets redesign slightly PCB  by adding mosfet for voltage level shifting in output stage and lets see how this circuit works  :-/O
Title: Re: TSB (A tiny and safe bootloader for AVR-ATtinys and ATmegas) one wire usage
Post by: beduino on October 28, 2017, 09:52:01 pm
Finally, we have updated prototype PCB with added ouput bidirectional voltage level shifting based on SOT23 n-channel mosfet with additional resistors to make optional pullup MPU side - when mosfet Drain and Source are connected without mosfet soldered we have oryginal circuit without voltage level shifting, so it looks like better starting point to play with CI-V connected to MPU pin for one-wire TSB bootloader  :popcorn:

(https://www.eevblog.com/forum/microcontrollers/tsb-(a-tiny-and-safe-bootloader-for-avr-attinys-and-atmegas)-one-wire-usage/?action=dlattach;attach=365017)