Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Flashing via BDM now reasonably fast again

I rewrote the RAM flash routine (again!), keeping the beginning the same, and
adding some crazy loop-unrolled madness at the end for the use of the BDM
code.

Tickled a bug in my BDM USB firmware, where zero-length writes were not
queuing up a status IN request.

While not *lightning* fast, it's fast enough that it's not embarrassing.

Maybe now I can get back to work on the AVR code... ;-)
  • Loading branch information...
commit e4adac04396b1b8f261d70f0eef0e6bd97c2cc6a 1 parent 5492412
@nimblemachines authored
View
18 target/HC08/S08flash.mu4
@@ -47,6 +47,7 @@ __meta
h @ ( save memory region)
1 xvar flash-command
+1 xvar flash-count
ram
here 0100 xor .if ." Flash routine not at 0100 hex" .then
@@ -66,14 +67,17 @@ flash-command 0ff xor .if ." flash-command not at 00ff hex" .then
label flash-byte
0 ,x sta ( store byte into Flash array)
-label do-flash-command
- begin
- flash-command ) lda FCMD ) sta 80 # lda FSTAT ) sta .a lsr
- begin FSTAT ) bit 0!= until
+ flash-command ) lda FCMD ) sta 80 # lda FSTAT ) sta .a lsr
+ begin FSTAT ) bit 0!= until
label flash-exit
- rts ( Gets rewritten every time we run flash-setup. If flashing)
- ( via BDM, this will get rewritten to a bgnd instruction.)
- again ( for BDM, so we don't have to keep resetting the PC)
+ rts ( For BDM use, gets rewritten in b.Hi to a nop.)
+ 1 # aix
+ flash-count ) dec 0!= if
+label flash-row ( entry point -- for BDM use only!)
+ .a pul ( SP points to buffer of bytes to program; HX has flash addr)
+ flash-byte j
+ then
+ bgnd
label flash-end ;c
h ! ( restore memory region)
View
43 target/HC08/bdm-S08-target.mu4
@@ -95,12 +95,6 @@ comment Commands
: b.setup-chunk ( 'target len buffer - len)
p! swap b.SetAddr ;
-: b.ReadChunk ( 'target len buffer)
- b.setup-chunk for b.ReadNext c& next ;
-
-: b.WriteChunk ( 'target len buffer)
- b.setup-chunk for c* b.WriteNext next ;
-
( It's a bummer to have to have this ifdef here, but otherwise splitting up
the serial and USB code for doing fast chunked reads and writes gets way
too complicated. We need to have, eg, b.SetAddr defined for both
@@ -120,7 +114,7 @@ comment Commands
firmware checks for this, and does nothing. This means that we cannot use
repeat = 0 to mean repeat = 256.)
-: b.ReadChunkFast ( 'target len buffer)
+: b.ReadChunk ( 'target len buffer)
b.setup-chunk
#16 /mod ( r q) ?for #16 read-usb-buffer next then
( rem) read-usb-buffer ;
@@ -133,11 +127,20 @@ comment Commands
firmware checks for this, and does nothing. This means that we cannot use
repeat = 0 to mean repeat = 256.)
-: b.WriteChunkFast ( 'target len buffer)
+: b.WriteChunk ( 'target len buffer)
+ -- cr ." write-chunk " rot dup u. rot dup u. rot dup u.
b.setup-chunk
#16 /mod ( r q) ?for #16 write-usb-buffer next then
( rem) write-usb-buffer ;
+.else
+
+: b.ReadChunk ( 'target len buffer)
+ b.setup-chunk for b.ReadNext c& next ;
+
+: b.WriteChunk ( 'target len buffer)
+ b.setup-chunk for c* b.WriteNext next ;
+
.then
( Order of regs in memory: H CC A X PC)
@@ -168,15 +171,18 @@ variable bdm-flash-command
.else ( bdm-flash-using-ram)
-( We've already written the byte, so jump to lda command)
-: b.flash-byte ( byte)
- b.WriteNext b.RunWait ;
-
: b.FlashChunk ( 'target len buffer cmd - status)
30 \l FSTAT b.WriteByte ( clear flash errors)
- ( cmd) \l flash-command b.WriteByte
- \l do-flash-command b.WritePC
- b.setup-chunk for c* b.flash-byte next
+ ( cmd) \l flash-command b.WriteByte
+ \l flash-row b.WritePC
+ push ( buffer)
+ dup ( len) \l flash-count b.WriteByte
+
+ ( copy buffer to ram just after the flash-row routine)
+ \l flash-end ( rambuf) dup b.WriteSP ( 'target len rambuf)
+ swap ( len) pop b.WriteChunk ( clobbers HX)
+ ( 'target) b.WriteHX
+ b.RunWait ( flash the buffer)
\l FSTAT b.ReadByte ( return flash status) ;
.then
@@ -270,7 +276,7 @@ comment misguided
: b.Hi
SetupClock ( trim & fcdiv) NoWatchdog ResetSP
\l flash-byte \l flash-end over - put-region
- 82 ( bgnd) \l flash-exit b.WriteByte ;
+ 9d ( nop) \l flash-exit b.WriteByte ;
-- hi ( copy ram flash routine)
-- broken because chat copies to
@@ -319,13 +325,8 @@ decimal
['] b.GetAddr is t.GetAddr
['] b.ReadNext is t.Read
['] b.WriteNext is t.Write
-.ifdef usb-target
- ['] b.ReadChunkFast is t.ReadChunk
- ['] b.WriteChunkFast is t.WriteChunk
-.else
['] b.ReadChunk is t.ReadChunk
['] b.WriteChunk is t.WriteChunk
-.then
['] b.FlashChunk is t.FlashChunk
( We'd like to set BDM clock from Sync pulse, but it doesn't seem to
View
12 target/HC08/bdm-usb-core.mu4
@@ -237,13 +237,13 @@ label bdm-read
nothing if it is.)
label bdm-write
- repeated ) lda 0!= if
- ( Save cmd and other metadata for later handling.)
- bdm-cmd ) ldhx bdm-cmd-saved ) sthx ( save first two bytes)
- bdm-cmd 2 + ) ldhx bdm-cmd-saved 2 + ) sthx ( save next two bytes)
+ repeated ) lda 0!= finish-control-write until
- size ) lda 0!= handle-out until ( no data payload -- just send the command)
- then
+ ( Save cmd and other metadata for later handling.)
+ bdm-cmd ) ldhx bdm-cmd-saved ) sthx ( save first two bytes)
+ bdm-cmd 2 + ) ldhx bdm-cmd-saved 2 + ) sthx ( save next two bytes)
+
+ size ) lda 0!= handle-out until ( no data payload -- just send the command)
expect-setup-token j ;c
label setup-token
View
5 target/HC08/interact.mu4
@@ -95,7 +95,10 @@ variable chat-sp ( current value of target's SP)
dup @ ( to) swap cell+ ! ( set from = to) ^
then drop ;
-: copy-ram 'zram put 'ram put ;
+: copy-ram
+ -- 'zram put ( crashes if connected chip has different @ram from target)
+ 'ram put ;
+
: hi copy-ram GetRegs .regs ;
variable chatting
Please sign in to comment.
Something went wrong with that request. Please try again.