-
Notifications
You must be signed in to change notification settings - Fork 0
/
HOWTO.txt
130 lines (95 loc) · 4.51 KB
/
HOWTO.txt
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
AVR_Stick_Apps Quick Start Guide
================================
1. Hardware Alternatives
------------------------
While this repository was created mainly with the
Sparkfun AVR Stick[1] in mind most of the software will work
with practically any ATtiny85 board.
Depending on the particular configuration of your board you
will have to set the pins used for the USB connection and
the CPU frequency accordingly. All other information should
apply without change.
One readily available alternative to the AVR Stick would be the
Digistump Digispark[2].
If you choose to use a Digispark or a compatible device, you will
have to change the ports used for the USB connection from PB0 and
PB2 to PB3 and PB4 respectively. The micronucleus bootloader already
comes with a configuration suitable for the Digispark named
t85_default and pre-built binaries in case your controller comes
without a pre-installed bootloader.
As the AVR Stick is fully open source you can also create your
own PCBs or simply recreate be necessary circuit on a breadboard
using the schematics and design files provided at [3].
2. Using USB HID feature reports to transmit arbitrary data
-----------------------------------------------------------
If you want to transmit arbitrary data to and from your ATtiny85
you can use HID feature reports.
To do that you will have to enable the following configuration
options in your usbconfig.h:
#define USB_CFG_IMPLEMENT_FN_WRITE 1
#define USB_CFG_IMPLEMENT_FN_READ 1
In your code you then need to implement the following functions
that will handle the actual data transfers:
usbMsgLen_t usbFunctionSetup(uchar data[8]);
uchar usbFunctionWrite(uchar *data, uchar len);
uchar usbFunctionRead(uchar *data, uchar len);
By periodically calling usbPoll() in your main loop those
callback functions will be triggered if new data is available.
For detailed examples on how to use this method please refer to
apps/HID-RT/src/HID-RT.c
which implements a simple one-shot bi-directional data transfer, or
apps/avrsh/main.cpp
which implements a pseudo commandline interface over HID reports.
In addition to the target software you will also need a client
on your Windows or Linux host to talk to your device.
Example clients written in Python using python-libusb1[4] can
be found at:
apps/HID-RT/host/hid-rt.py
for sending a single command to the HID-RT firmware and at:
misc/avrsh/host/avrsh.py
for the pseudo commandline client for avrsh.
3. avrsh on the ATtiny85
------------------------
apps/avrsh contains a drastically stripped down port of avrsh[5]
to the ATtiny85.
Even though the functionality is greatly reduced compared to
the original avrsh, the binary is still to big to fit into the
ATTiny85's 8k flash together with micronucleus.
Therefore to use avrsh you need to flash it directly using
a programmer.
Using misc/avrsh/host/avrsh.py you will then be able to 'log in'
to your ATtiny85 and issue several interactive command to e.g.
set and read IO pins or read various system parameters like the
CPU frequency.
See apps/avrsh/README for more details.
4. Creating you own app for the AVR Stick
-----------------------------------------
Generally speaking every firmware compiled for the ATtiny85
will run on the AVR Stick.
Since the micronucleus bootloader takes up a little less than
2kB of flash memory if your firmware is larger than about 6kB
you will not be able to use it together with micronucleus and
will need to flash it using some other method.
To create an app that takes advantage of the AVR Stick's USB
interface you need to use the interface provided by V-USB to
expose the USB functionality.
This essentially means:
* Including an appropriate usbconfig.h file.
* Linking usbdrv.o usbdrvasm.o oddebug.o from V-USB.
* Periodially call usbPoll() in your main loop and implementing
the required callbacks.
The easiest way to get started is to copy one of the example
apps and just add more functionality from there.
Some good starting points would be:
apps/AnyKey
which implements a basic HID devices that only sends data to
the host but does not receive data back.
apps/HID-RT
which implements bi-directional communication between the
host and the target.
---------------------------------------------------------------------
[1]: https://www.sparkfun.com/products/retired/9147
[2]: http://digistump.com/products/1
[3]: https://github.com/sparkfun/AVR_Stick/tree/master/Hardware
[4]: https://github.com/vpelletier/python-libusb1
[5]: https://www.instructables.com/id/AVRSH-A-Command-Interpreter-Shell-for-ArduinoAVR/