SAM-BA protocols and operating principles


I would like to know if there are available documents describing the protocol implemented by SAM-BA when flashing devices like 20B / 30B. Details about messages and its answers, message sizes, acknowledgement of messages, command sequences, retries, timeouts, checksums, etc. should appear on such documents; along with a description of typical interchanges between SAM-BA and the devices.

Best regards, and thanks in advance.

Edited: 27 Oct 2011, 10:57 a.m.


I don't know what goes on once SAM-BA has downloaded a small program to the chip to which it then talks for flashing. The basic set-up commands are described in the Atmel AT91SAM7L128 Manual. I found it on the Atmel site for free download. The basic protocol allows reading and writing memory on the chip.

MySamba implements X modem if I recall correctly. It downloads a small ARM assembly language program which I present here in disassembled form:

200B40 47784770	Undefined instruction  ; [undefined instr]
200B44 E3A00601 MOV r0, #1<<20
200B48 E3A01C02 MOV r1, #1<<9
200B4C E3E030EB MVN r3, #&EB
200B50 E3C33C0D BIC r3, r3, #&D00
200B54 E3E0709B MVN r7, #&9B
200B58 E3A02043 MOV r2, #67
200B5C E5934000 LDR r4, [r3, #0]
200B60 E3140002 TST r4, #2
200B64 0AFFFFFC BEQ &00200B5C
200B68 E5832008 STR r2, [r3, #8]
200B6C E3A04000 MOV r4, #0
200B70 E3A02040 MOV r2, #64
200B74 E5936000 LDR r6, [r3, #0]
200B78 E3160001 TST r6, #1
200B7C 0AFFFFFC BEQ &00200B74
200B80 E5935004 LDR r5, [r3, #4]
200B84 E0244005 EOR r4, r4, r5
200B88 E5936000 LDR r6, [r3, #0]
200B8C E3160001 TST r6, #1
200B90 0AFFFFFC BEQ &00200B88
200B94 E5936004 LDR r6, [r3, #4]
200B98 E0244006 EOR r4, r4, r6
200B9C E0855406 ADD r5, r5, r6, LSL #8
200BA0 E5936000 LDR r6, [r3, #0]
200BA4 E3160001 TST r6, #1
200BA8 0AFFFFFC BEQ &00200BA0
200BAC E5936004 LDR r6, [r3, #4]
200BB0 E0244006 EOR r4, r4, r6
200BB4 E0855806 ADD r5, r5, r6, LSL #16
200BB8 E5936000 LDR r6, [r3, #0]
200BBC E3160001 TST r6, #1
200BC0 0AFFFFFC BEQ &00200BB8
200BC4 E5936004 LDR r6, [r3, #4]
200BC8 E0244006 EOR r4, r4, r6
200BCC E0855C06 ADD r5, r5, r6, LSL #24
200BD0 E4805004 STR r5, [r0], #4
200BD4 E2522001 SUBS r2, r2, #1
200BD8 1AFFFFE5 BNE &00200B74
200BDC E5932000 LDR r2, [r3, #0]
200BE0 E3120001 TST r2, #1
200BE8 E5932004 LDR r2, [r3, #4]
200BEC E1520004 CMP r2, r4
200BF0 12400C01 SUBNE r0, r0, #&100
200BF4 13A02058 MOVNE r2, #88
200BF8 1AFFFFD7 BNE &00200B5C
200BFC E3A02CFF MOV r2, #&FF00
200C00 E382280F ORR r2, r2, #&F0000
200C04 E0022000 AND r2, r2, r0
200C08 E2422C01 SUB r2, r2, #&100
200C0C E2822001 ADD r2, r2, #1
200C10 E382245A ORR r2, r2, #&5A000000
200C14 E5872000 STR r2, [r7, #0]
200C18 E5972004 LDR r2, [r7, #4]
200C1C E3120001 TST r2, #1
200C20 0AFFFFFC BEQ &00200C18
200C24 E3A02059 MOV r2, #89
200C28 E2511001 SUBS r1, r1, #1
200C2C 1AFFFFCA BNE &00200B5C
200C30 E3A0045A MOV r0, #&5A000000
200C34 E2800C01 ADD r0, r0, #&100
200C38 E280000B ADD r0, r0, #11
200C3C E5870000 STR r0, [r7, #0]
200C40 E5972004 LDR r2, [r7, #4]
200C44 E3120001 TST r2, #1
200C48 0AFFFFFC BEQ &00200C40
200C4C E5972004 LDR r2, [r7, #4]
200C50 E3120001 TST r2, #1
200C54 0AFFFFFC BEQ &00200C4C
200C58 E3E000FF MVN r0, #&FF
200C5C E3C00C02 BIC r0, r0, #1<<9
200C60 E3A0100D MOV r1, #13
200C64 E38114A5 ORR r1, r1, #&A5000000
200C68 E5801000 STR r1, [r0, #0]
200C6C EAFFFFFE B &00200C6C

This program receives the data in 256 byte chunks and does the actual flashing. It assumes a 128KB size download before it toggles the boot bit and resets the calculator. This should be modified for shorter files. My MySamba modification is a work-around: It toggles the bit before the download. That is the reason why you need to do a reset after flashing.


Marcus, thank you. I'll take a look at all this and will comment later (I hope).


Marcus, thank you. I'll take a look at all this and will comment later (I hope).

I know I have no standing to make a request, so I'll make some observations...

MySamba is written in Delphi (a Pascal variant). The code was offered and (as far as I know) Marcus was the only one to do anything with it.

C/C++ is far more popular and so is supported on more platforms. Python is another choice, one often possible to write true cross-platform code and where performance is surprisingly good. With popular languages like C and Python the pool of potential contributors is much larger.

I really like the *ix philosophy of a small commandline program that does one thing well, and provides a way for a GUI to wrap it later if desired.

That's my thoughts. :)


It was easier for me to just extend on the capabilities of Cyrille's work than to reinvent it. Otherwise I'm with you. Something that could be started from the Makefile would be great.

Possibly Related Threads...
Thread Author Replies Views Last Post
  PRIME: re-format the flash drive to recover the operating system Harold A Climer 2 560 11-06-2013, 12:22 AM
Last Post: Michael de Estrada
  Online tribute to Sam (E. Samuel Levy) hpnut 7 762 11-25-2012, 12:06 PM
Last Post: aurelio
  SAM-BA v 2.11 for flashing WP34S Tom Sauntry 6 608 05-22-2012, 11:02 AM
Last Post: Massimo Gnerucci (Italy)
  About Principles Juergen Keller 12 1,093 05-14-2012, 06:38 AM
Last Post: Mike (Stgt)
  Entering 34s SAM-BA bootloader without Erase button. Harald 4 496 03-04-2012, 03:03 PM
Last Post: Harald
  Using SAM-BA on Linux and flashing WP34s David Griffith 8 690 02-14-2012, 04:07 AM
Last Post: pascal_meheut
  WP34S flashed on Linux, with SAM-BA 2.10 Hubert Weikert 15 1,034 10-24-2011, 06:10 PM
Last Post: Egan Ford
  I keep getting a Fatal error with SAM-BA v.2.10 Eddie W. Shore 30 2,139 10-08-2011, 11:18 AM
Last Post: Egan Ford
  SAM-BA 2.10 for Linux not working. Egan Ford 5 571 10-07-2011, 10:00 AM
Last Post: Bart (UK)
  WP 34S Amtel SAM-BA download broken Howard Owen 6 696 09-27-2011, 06:34 PM
Last Post: Marcus von Cube, Germany

Forum Jump: