Skip to content
Browse files

AVR prog USB firmware careful about 0-length read and write

It used to "crash" -- ie, it would break the USB standard. Now it does the
right thing, so 0-length reads and writes -- though "wasteful" of USB
bandwidth -- are not a problem.
  • Loading branch information...
1 parent 0d6a360 commit b05d8cf855cd853a6e59a1a90f045297ece4584b @nimblemachines committed Feb 18, 2012
Showing with 17 additions and 13 deletions.
  1. +17 −13 target/HC08/avrprog-usb-core.mu4
View
30 target/HC08/avrprog-usb-core.mu4
@@ -183,26 +183,30 @@ label finish-control-write
.a clr prepare-in j ( zero-length DATA1 transaction) ;c
label bulk-read
- .h clr .h psh ( bulkptr)
- wLength ) lda .a psh ( repeat wLength times)
- begin
- .x clr
+ wLength ) lda 0!= if
+ .h clr .h psh ( bulkptr)
+ .a psh ( repeat wLength times)
+ begin
+ .x clr
- ( resend command, addr, and dummy bytes)
- begin avr-cmd ,x lda SpiTx c .x inc 4 # cpx 0= until
+ ( resend command, addr, and dummy bytes)
+ begin avr-cmd ,x lda SpiTx c .x inc 4 # cpx 0= until
- ( put last byte returned into in-buffer)
- 1 ,s ldx in-buffer ,x sta .x inc 1 ,s stx
+ ( put last byte returned into in-buffer)
+ 1 ,s ldx in-buffer ,x sta .x inc 1 ,s stx
- ( toggle cmd byte and incr addr-lo if toggled back to 0)
- toggle ) lda avr-cmd ) eor avr-cmd ) sta
- toggle ) and 0= if addr-lo ) lda .a inc addr-lo ) sta then
+ ( toggle cmd byte and incr addr-lo if toggled back to 0)
+ toggle ) lda avr-cmd ) eor avr-cmd ) sta
+ toggle ) and 0= if addr-lo ) lda .a inc addr-lo ) sta then
- 0 ,s decz? until 2 # ais ( pop repeat count and bulkptr)
- txa ( in-count to a)
+ 0 ,s decz? until 2 # ais ( pop repeat count and bulkptr)
+ txa ( in-count to a)
+ then
prepare-in j ;c
label bulk-write
+ wLength ) lda 0!= finish-control-write until
+
( Save avr command for later use -- when OUT arrives.)
avr-cmd ) ldhx avr-cmd-saved ) sthx
avr-cmd 2 + ) ldhx avr-cmd-saved 2 + ) sthx

0 comments on commit b05d8cf

Please sign in to comment.
Something went wrong with that request. Please try again.