-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathavrprog-usb-host.mu4
50 lines (37 loc) · 1.57 KB
/
avrprog-usb-host.mu4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
| This file is part of muforth: https://muforth.dev/
|
| Copyright 2002-2025 David Frech. (Read the LICENSE for details.)
loading SPI over USB (AVR programming support) (host)
| Host-side code to drive the AVR programmer code in
| target/S08/avrprog-usb-core.mu4.
hex
| : usb ( bmRequest bRequest wValue wIndex wLength 'buffer)
| Since we're using wValue and wIndex to pass an array of four bytes, we
| need an easy way to assemble the two word values - little-endian! - from
| the avr-cmd, addr, and data.
: >setup ( avr-cmd addr data - wValue wIndex)
push >hilo push ( avr-cmd addr-hi) lohi> ( wValue)
pop pop ( addr-lo data) lohi> ( wIndex) ;
( Commands)
: avr.Read ( avr-cmd addr data) >setup 2push
0c0 20 2pop 4 pad usb ;
: avr.Write ( avr-cmd addr data) >setup 2push
40 20 2pop 0 0 usb ;
: avr.BulkRead ( avr-cmd addr toggle buf len) 2push >setup 2push
0c0 21 2pop pop pop usb ;
: avr.BulkWrite ( avr-cmd addr toggle buf len) 2push >setup 2push
40 22 2pop pop pop usb ;
: control-write
create , ( bRequest)
does> @ 40 swap 0 0 0 0 usb ;
00 control-write avr.Bye ( End session, return to chat command loop)
23 control-write avr.ResetLow
24 control-write avr.ResetHigh
25 control-write avr.SlowClock ( 250k)
26 control-write avr.FastClock ( 2M)
: avr.Hello ( start the AVR programming firmware on the connected device)
.ifdef in-ram
0112 u.SetPC u.Run ( run from ram - loads right after flash routine)
.else
@avrprog u.SetPC u.Run
.then ;