├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── help
├── Components-And-Porting.md
├── Differences-with-arduino-bootloaders.md
├── Encryption.md
├── Installation.md
├── Notes-about-the-License.md
├── Reliability.md
├── The-First-Project.md
├── files
│ ├── FirstRfbootProject.fzz
│ ├── FirstRfbootProject.jpg
│ ├── MenuEntry.png
│ ├── ftdi.jpg
│ ├── usb2rf1.jpg
│ ├── usb2rf2.jpg
│ ├── usb2rf3.jpg
│ └── usbasp.jpg
└── usb2rf-reset.md
├── rfboot
├── Makefile
├── README.md
├── cc1101
│ ├── COPYING
│ ├── README.md
│ ├── RELEASES.txt
│ ├── cc1101.c
│ ├── cc1101.h
│ ├── ccpacket.h
│ ├── keywords.txt
│ ├── pin_macros.h
│ ├── spi.c
│ └── spi.h
├── hardware_settings.mk
├── rfboot.c
└── xtea
│ ├── README.md
│ ├── xtea.c
│ └── xtea.h
├── rftool
├── Makefile
├── README.md
├── rftool
├── rftool.nim
├── vagga.yaml
├── xtea.c
└── xtea.h
├── skel
├── Makefile
└── skel.ino
└── usb2rf
├── Makefile
├── README.md
├── hardware
├── README.md
└── usb2rf.fzz
├── usb2rf.hex
└── usb2rf.ino
/.gitignore:
--------------------------------------------------------------------------------
1 | *.[oa]
2 | *~
3 | build-*
4 | nimcache
5 | /test
6 | old
7 | .vagga
8 | rust
9 | serial*
10 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | - 2018-08-12 rftool : Now uses the serial library
2 |
3 | - 2018-08-08 rftool: If a serial port is in use, rftool does not try to open a new serial terminal.
4 |
5 | - 2018-08-08 The-First-Project: Documentation improvements.
6 |
7 | - 2018-05-26 rftool: The default rftool binary is now 64 bit. The binary is statically linked and probably will work on any 64-bit kernel. The reason for this change is that it is quite inconvenient to generate the 32-bit binaries and at the same time 32-bit linuxes are almost extint nowdays. If anyone really needs the 32 bit binary, it can easily compiled in a 32 bit box.
8 |
9 | - 2018-05-26 rftool: Now rftool uses the standard /bin/fuser utility to stop/start the serial terminal program (gtkterm, putty etc.). Until now rftool looked at /var/lock/LCK.. files. This method however has the major disadvantage that only programs creating lockfiles are working. Gtkterm worked with ubuntu 16.04. The newer gtkterm shipped with ubuntu 18.04 does not create a lockfile anymore. The old method was very restrictive anyway, and the new method should work with any GUI serial terminal.
10 |
11 | - 2018-04-19 README.md Installation.md: Documentation improvements.
12 |
13 | - 2017-10-03 rftool: Fixed minor bug in rftool about the maximum firmware size. Improved rftool Makefile. Optional use of "vagga" container for compilation. Now rftool accepts "new" as synonymous to "create"
14 |
15 | - 2017-09-13 Installation.md: A lot of improvements in the documentation, new photos uploaded.
16 |
17 | - 2017-09-10 rftool: Now rftool accept "terminal" as synonymous to "monitor"
18 |
19 | - 2017-09-10 rftool: The special reset string "MANUAL" can be used inside app_settings.h to instruct rftool to not warn us about missing reset string. Useful if we use an external tool to reset the remote target.
20 |
21 | - 2017-09-09 rftool: Major code cleanup
22 |
23 | - 2017-09-09 rftool: Now upload supports .elf and .hex files, not only binary files. This in practice means that there is no need to convert the ELF file in binary format in the Makefile.
24 |
25 | - 2017-09-09 CHANGELOG file created: Maybe too late, as almost all functionality is there.
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rfboot
2 |
3 | # Importand note : As time passes, the limitations of rfboot become more and more obvious. Only atmega328 with cc1101 is supported and no itegration with platformio. If you are interested on OTA updates consider using another programmer like the excellent [esp-link](https://github.com/jeelabs/esp-link)
4 |
5 | Atmega328p Bootloader for wireless (OTA) code uploads, using the CC1101 RF chip.
6 |
7 | Included :
8 |
9 | - The actual atmega328 bootloader, intended to be installed to this MCU via an ISP programmer.
10 | - A suitable utility (rftool) to easily create new projects (the directory structure) using rfboot as bootloader.
11 | The same tool is used for code upload. Every project is created with unique RF settings and a
12 | preconfigured Makefile. While developing, a "make send" uploads the code wirelessly.
13 | - Instructions to assemble a **usb2rf module**, witch allows us to upload code to the target and,
14 | **equally important**, to use a Serial Terminal (like gtkterm) to send and receive text,
15 | analogous to Serial.print() and Serial.read().
16 |
17 | This project's emphasis is on reliability, security and usability.
18 |
19 | - [Installation.](help/Installation.md) Software and hardware you need, in order to upload code using rfboot.
20 | - [The first project.](help/The-First-Project.md) Instructions to successfully complete your first Arduino project using a bare atmega328 as target, and rfboot as bootloader.
21 | - [Reliability.](help/Reliability.md) Explains how rfboot does the job, under an inherently unreliable link (RF).
22 | - [Encryption.](help/Encryption.md) Discuses how the firmware is encrypted over the air, and why this is useful.
23 | - [Notes about the License.](help/Notes-about-the-License.md) Some clarifications of the License.
24 |
--------------------------------------------------------------------------------
/help/Components-And-Porting.md:
--------------------------------------------------------------------------------
1 | ### Components and Porting
2 |
3 | #### RF
4 | For RF connectivity, the most common solution is to use 2.4GHz
5 | transceivers like the very popular NRF24L01+ chip. I found however the distance range to be very short. Above 20m even the slightest obstacle can interrupt the signal. Also this
6 | band seems overcrowded with all WIFI routers/APs/MicrowaveOvens around. Signal theory also predicts that sub GHz signal has some advantages over 2.4GHz. Lower power to reach the same distance and more importantly much better penetration and obstacle tolerance. I tried a lot of sub-GHz transceivers and I found the CC1101 chip to be the most flexible and also to have simple libraries with adequate licence. The difference with the NRF24L01+ module when we speak about signal reception, is very big. Note however that the NRF24 modules are optimized for speed (minimum 250 Kpbs, probably the main target is keyboards, mice, and other wireless peripherals) so the comparison is not fair. The CC1101 also has support for WOR (wake on radio) which is basically mandatory for battery powered projects listening for radio signals.
7 |
8 | #### MCU
9 | The use of atmega328p is very natural. It is a well supported chip with tons of online
10 | information. It powers a lot of Arduino boards, and can be programmed with standard Arduino code. And the truth is that atmega328 has the right size (IO and RAM/Flash) for a lot of projects.
11 |
12 | #### Porting
13 | I expect that porting rfboot to another avr MCU should not be hard, if such a need arises. The use of another RF chip can be a little harder however, with the exception of CC2500 which is almost identical to CC1101 (It is a 2.4GHz transceiver) but I didn't try this.
14 |
--------------------------------------------------------------------------------
/help/Differences-with-arduino-bootloaders.md:
--------------------------------------------------------------------------------
1 | As software outside of this repository is evolving, some of these comparisons may be outdated/incorrect when you are reading this.
2 |
3 | # differences with optiboot / atmegaboot
4 |
5 | ### size
6 | The size of rfboot is about 3.5Kbytes witch means that eats 4Kb bootloader space. This is certainly big, especially
7 | compared to optiboot(512 bytes). However what is important is the **free** space that can be used for application code.
8 |
9 | - optiboot : 32-0.5 = 31.5 Kbytes
10 |
11 | - atmegaboot (proMini) : 32-2 = 30 Kbytes
12 |
13 | - rfboot : 32-4 = 28 Kbytes, wich is not as good as 31.5Kbytes but it is OK. If a project really needs more than 28Kb, then it probably needs another MCU anyway.
14 |
15 | ### MCU interface
16 | optiboot/atmegaboot uses Serial connection, while rfboot uses SPI to communicate with the CC1101 chip. This can be a plus or minus, if other components of your project compete for these recourses. One noteworthy case is if your project uses a serial module like a GSM modem or a GPS module. They can attached to the fast hardware serial port without the need for a Software Serial library. If you ever used one, you know they are slow, especially at 8MHz clock rate. SPI on the other hand is easier to work with multiple devices, and there are also Software SPI
17 | solutions (see Arduino shiftOut() )
18 |
19 | ### Easy of use
20 |
21 | The daily use of rfboot is surprisingly simple. Edit the code then "make send" and the code is sent to the correct
22 | MCU even if you happen to have 10 open projects in the editor.
23 | The first installation can be a problem however. Certainly a user should be familiar with basic concepts of MCU (and bootloaders) before try to use a different bootloader than the stock one witch is coming with the Arduinos for example.
24 |
25 | ### Arduino code and rfboot
26 | Generally speaking a bootloader is code agnostic. You can upload any firmware written in C or assembler or Arduino (Which uses the c++ compiler). Arduino is a first class citizen in this case. The arduino IDE is not
27 | used however. Instead the excelllent arduino-makefile is used, witch gives us the power to use any editor. The examples in this site use the **geany** editor, but obvioulsy you can use another.
28 |
29 | "rftool create ProjectName" creates a new arduino project with unique RF channel and SyncWord (To prevent RF collitions with other modules) and a unique XTEA key. All this customization is saved in the app_settings.h
30 | file inside the project's folder.
31 |
32 | A "make isp" burns the bootloader to the target MCU. This is done once per project.
33 |
34 | From now on a "make send" sends the code to the module wirelesly. Most editors can be customized to execute such commands with a click.
35 |
--------------------------------------------------------------------------------
/help/Encryption.md:
--------------------------------------------------------------------------------
1 | ### Εncryption
2 |
3 | When a new project is created with **"rftool create ProjectName"** a new rfboot .hex file is created
4 | with a unique RF channel, SyncWord, and XTEA key. These paramaters are stored in the FLASH (inside the hex file)
5 | and NOT in the eeprom.
6 |
7 | The idea of encryption emerged as a way to learn some things about encryption. The AES
8 | cipher resulted in an oversized bootloader, more than the 4Kb limit of atmega328 so XTEA
9 | is used because is very small and the code in wikipedia is in public domain by the
10 | algorithm creators.
11 |
12 | The use of encryption may seem overkill . Who cares to steal the firmware from the air, you may ask.
13 | In most cases the answer is nobody.
14 | But for a commercial project this can be a concern, and encryption offers peace in mind.
15 |
16 | And it turns out, even for a completely open
17 | source project the use of encryption is essential. The reason is that without encryption,
18 | the bootloader can easily be fooled to upload any code -by anyone- in the RF module's distance range.
19 | This can be done on purpose or even accidentally, if for example someone (or you) try to upload
20 | code to another module.
21 |
22 | Notice how different are bootloaders such as optiboot or atmegaboot.
23 | They don't need encryption, because code is transfered by wire, and
24 | physical access to the module is required.
25 |
26 | I found that encryption is not slowing down the uploading process.
27 | It is also transparent to the user, so it does not complicate the upload process.
28 |
29 | For these reasons encryption is permanently enabled in rfboot. If for some reason you need
30 | to disable encryption you have to edit the source code.
31 |
32 | The firmware is uploaded to the atmega328 encrypted with XTEA algorithm in CBC mode.
33 | As rfboot selects a different IV at every session, even if we upload the same file several times,
34 | the data on the air will be different every time. An "attacker" cannot use an old recorded
35 | session, and cannot send random data either, because rfboot checks if the first
36 | packet is encrypted with the correct XTEA key and the chosen IV. The IV is stored
37 | in the flash (Not the EEPROM) and uses 2 bytes. Only the first 65536 uploads will have unique IV's. This is OK
38 | as the FLASH can be written reliably only 10000 times.
39 |
40 | The firmware is not encrypted in the atmega flash. When the bootloader is first installed with
41 | "make isp", the fuses are set so an ISP programmer cannot read the FLASH
42 | neither the EEPROM,
43 | but I have no solid information if atmega328 can withstand FLASH/EEPROM read attacks.
44 |
45 | There is also the possibility that rfboot has some bug, and an exploit can trick it to
46 | reveal the code somehow. Or that the data are badly encrypted and can easily decrypted, and so on.
47 |
48 | Generally speaking, no warranties that the code works, offers any security, confidentiality,
49 | it is useful to any particular purpose, etc.
50 |
--------------------------------------------------------------------------------
/help/Installation.md:
--------------------------------------------------------------------------------
1 | ## Installation
2 |
3 | You need to:
4 | - Install the needed software in the PC
5 | - Assemble and configure the usb2rf module (Connects to a USB port of the PC)
6 | - Configure rftool to use the usb2rf module
7 | - Upload the apropriate firmware to usb2rf
8 |
9 | ### Install the apropriate software
10 | First of all, a linux PC is needed for the development. I don't use Windows neither MAC
11 | and is very difficult for me to support another platform. The instructions below are valid
12 | for Ubuntu 18.04 LTS (and Mint 19.X) and probably for Ubuntu 16.04 and the base debian release. Older releases (Ubuntu 14.04 LTS and Mint 17.X) may have a problem with "avrdude" but you can fix it by installing for example the [Ubuntu 16.04 avrdude](https://launchpad.net/ubuntu/+source/avrdude/6.2-5/+build/8794450/+files/avrdude_6.2-5_i386.deb). For other distributions you need to adapt the procedure for your environment.
13 |
14 |
15 | Open a terminal:
16 |
17 | ```bash
18 | # this is recommended before start
19 | > sudo apt-get update ; sudo apt-get upgrade
20 |
21 | # This also installs avr compiler and avr-libc
22 | > sudo apt-get install arduino-core arduino-mk
23 |
24 | # A programmers editor. You can use another if you like.
25 | # The instructions here, use geany as text editor
26 | > sudo apt-get install geany
27 |
28 | # a serial terminal. I suggest to use this serial terminal
29 | # before try your luck with another one.
30 | > sudo apt-get install gtkterm
31 |
32 | # To easily download rfboot.
33 | > sudo apt-get install git
34 | ```
35 |
36 | The ubuntu/debian/mint packages are old (1.0.6) but work perfectly for rfboot purposes. You
37 | can edit the Makefile of the project and point to locally installed, newer Arduino releases.
38 | You can do the same for newer Arduino-Makefile releases.
39 | The auto-generated Makefile (see below) has already commented some possible options.
40 |
41 | Now download the rfboot repository on your PC. Place it in some relatively safe place in your
42 | home like ~/programming/
43 |
44 | ```bash
45 | > mkdir ~/programming
46 | > cd ~/programming
47 | > git clone https://github.com/pkarsy/rfboot.git
48 | ```
49 | The "rftool" utility needs to be in the PATH.
50 | ```bash
51 | # if the ~/bin does not exist "mkdir ~/bin" and then logout and login again
52 | > cd ~/bin
53 | > chmod +x ~/programming/rfboot/rftool/rftool
54 | # Do NOT copy rftool, just symlink it
55 | > ln -s ~/programming/rfboot/rftool/rftool
56 | ```
57 | Now if you type
58 | ```bash
59 | > rftool
60 | ```
61 | should give you a small usage message. This means rftool is in the PATH. As you can see the
62 | rftool is pre-compiled. It is a statically linked executable, and it can run on any x86_64(AMD64) linux system. You can recompile it of course if you want, see [rftool README](../rftool/README.md)
63 |
64 | Now it is time to install mCC1101, a modified (and simplified) panStamp
65 | CC1101 library. The skeleton projects created with "rftool create ProjName"
66 | use this library. (You can modify the code to use another CC1101 library)
67 |
68 | Change "~/sketchbook/libraries" with your actual sketchbook folder.
69 |
70 | ```bash
71 | > cd ~/sketchbook/libraries
72 | > git clone https://github.com/pkarsy/mCC1101.git
73 | ```
74 |
75 | Linux by default does not give permission (to regular users) to access the Serial ports, neither the ISP programmers. To change this for Serial port:
76 |
77 | ```bash
78 | > sudo adduser myusername dialout
79 | ```
80 | You need to logout and login again for the changes to take effect.
81 | For ISP programmer:
82 | ```bash
83 | > sudo nano /etc/udev/rules.d/99-isp.rules
84 | ```
85 |
86 | and add the lines
87 | ```sh
88 | # USBasp
89 | SUBSYSTEM=="usb", ATTR{product}=="USBasp", ATTR{idProduct}=="05dc", ATTRS{idVendor}=="16c0", MODE="0666"
90 |
91 | # USBtiny
92 | SUBSYSTEM=="usb", ATTR{idVendor}=="1781", ATTR{idProduct}=="0c9f", MODE="0666"
93 | ```
94 |
95 | Now in the command line
96 | ```bash
97 | > sudo service udev restart
98 | ```
99 | You have to disconnect the module from the USB port (if connected), and reconnect for the changes to take effect.
100 |
101 | ***Now the Linux PC has all neccesary software components***
102 |
The steps above should be repeated on every PC you are going to use for development.
103 |
104 | ### usb2rf module
105 |
106 | ***WARNING: The red FTDI modules (USB-to-Serial, they probably have a fake FTDI chip) that can be found on many online shops, are very unreliable. A lot of failed uploads, and mysterious CRC errors, disappeared by using a CP2102 or Pl2303 USB-to-Serial module.
107 | I don't have a genuine FTDI module to test it.
Maybe the problem is power related as the FTDI regulator powers the ProMini and the CC1101 module directly. This means that if we resist the temptation to connect FTDI<-->ProMini directly with the 6-pin headers, and connect the 5V FTDI output to the RAW proMini pin, then they may work reliably.
108 | I didn't investigate further, as CP2102 is working perfectly.***
109 |
110 | To build the usb2rf module you need :
111 | - A CP2102 module ( A CP2104 or a PL2303 is also OK)
112 | - ProMini 3.3V. Do not use a 5V ProMini. CC1101 cannot tolerate 5V.
113 | - CC1101 module (I use D-SUN modules)
114 | - some female-female jumper wires (2.54mm spacing).
115 |
116 | ```
117 | +----------+
118 | | | +--------+ +----------+ +--------+
119 | | gtkterm | <---> | CP2102 | <---> | Pro mini | <---> | CC1101 |
120 | | rftool | USB +--------+ Serial +----------+ SPI +--------+
121 | +----------+
122 | PC | usb2rf module |
123 | +-------------------------------------------------+
124 | ```
125 |
126 | Here is a photo of the materials we need
127 | 
128 |
129 | ***Serial connection (CP2102<-->ProMini)***
130 |
131 | 4 cables are required :
132 |
133 | CP2102 | Cable COLOR | Pro Mini
134 | ---- | ----- | --------
135 | GND | Black |GND
136 | 5V | Red | RAW
137 | TX | Yellow | RX
138 | RX | Green |TX
139 |
140 | ProMini regulates the 5V from RAW pin to 3.3V. CP2102 has also an internal 3.3 regulator and the 2 modules
141 | can communicate without the need for logic level conversion.
142 | Notice: CP2102 has also a 3.3V output but I am not sure
143 | that the current is enough to power ProMini+CC1101 so we don't use it. Instead we feed the far more capable ProMini's regulator (The RAW pin is the regulator input) with 5V as you can see in the connections table
144 |
145 | ***SPI connection (ProMini<-->CC1101)***
146 |
147 | 7 cables are required :
148 |
149 | CC1101 PIN | Cable COLOR | ProMini pin
150 | ------------- | ----------- | -----------
151 | GND | Black | GND
152 | VCC | Red | VCC(3.3V)
153 | CSN | Yellow | 10
154 | SCK | Green | 13
155 | MOSI | Blue | 11
156 | MISO | Violet | 12
157 | GDO0 | Gray | 2
158 | GDO2 | | Not Connected
159 |
160 | CC1101 is working fine with 3.3V, so again no level conversion is needed.
161 |
162 | Now connect the proMini pins D3 and RST (Orange cable).
163 | See [Explanation](usb2rf-reset.md)
164 |
165 | 
166 |
167 | And here is the final module
168 |
169 | 
170 |
171 | ### Assign the USB-to-Serial module, a unique serial ID
172 | ***Notice: I am not the developer of these utilities, all credit goes to them.***
173 |
174 | This is mandatory if you are going to have more than one CP2102
175 | modules connected to your PC at the same time, even for completely different purposes.
176 | https://github.com/DiUS/cp210x-cfg.git
177 | compile the source (install libusb-1.0-0-dev first)
178 |
179 | ```sh
180 | # Be sure there is only one CP2102 module connected to the PC
181 | > sudo ./cp210x-cfg -S "random_serial"
182 | # disconnect the module from USB port and connect again after a few seconds
183 | ```
184 |
185 | - "random_serial" should be unique for every module ie 12F34, 25317, 1awd34fg etc.
186 | - The CP2104 chip seems to have already unique ID, so this procedure is not needed and maybe in
187 | fact do harm, as this chip is not tested by the developer.
188 | - The Pl2303 chip cannot programmed, so if you are going to use this chip, you
189 | have to use only one, and use other brands, if you need to connect other
190 | USB-to-Serial modules.
191 | - The FTDI modules also have unique serial IDs, if you manage to bypass the reliability problems as explained earlier.
192 | - There is another linux utility doing the same job, and seems to have more options
193 | http://cp210x-program.sourceforge.net/
194 | but some distros might have difficulties to install the dependencies (python-usb).
195 |
196 |
197 |
198 | ### Configure rftool to use the usb2rf module
199 | ```bash
200 | > rftool addport
201 | ```
202 | and insert the usb2rf module. rftool detects it and saves the Serial port device
203 | to "~/.usb2rf" file. Note that **if you omit this step, rftool will not be able to use this module, for code upload.**
204 |
205 | Note: Sometimes the module is detected as "/dev/ttyUSB0". Another time as "/dev/ttyUSB1", and so
206 | on. rftool instead searches the "/dev/serial/by-id" directory and always finds the correct usb2rf module.
207 | You can have more than one usb2rf devices and rftool will use the first one referenced in "~/.usb2rf"
208 |
209 | ### Burn the appropriate firmware to usb2rf
210 |
211 | The usb2rf module (The proMini) needs a firmware in order to do the job as a USB<-->RF bridge.
212 | **This step will work only if you already done the "rftool addport" step above.** And of course it
213 | needs to be done once. Ensure the module is the only one connected (if you happen to have more than one)
214 | To upload the pre-compiled .hex
215 | ```bash
216 | > cd usb2rf
217 | > make sendHex
218 | ```
219 | You may need to press proMini reset button as auto-reset does not work.
220 |
221 | As always, you can build the sketch yourself. (See [usb2rf/README.md](../usb2rf/README.md) )
222 |
223 | ***Hardware and software setup is done !***
224 |
225 | Continue with
226 | [The First Project](The-First-Project.md)
227 |
228 |
--------------------------------------------------------------------------------
/help/Notes-about-the-License.md:
--------------------------------------------------------------------------------
1 | Rfboot is Licensed under **GPLv3**.
2 |
3 | The following notes are not modifications to the rfboot license, but a summary of what I understand,
4 | with the hope that someone with more knowledge will help me correct any misunderstandings.
5 |
6 | - If you do any modifications to the code and you want to distribute them, you have
7 | to use the same license.
8 |
9 | - if you want to use rfboot in a commercial product, giving the customers
10 | the opportunity to upload code wirelesly, it is perfectly OK, but if you modified
11 | the bootloader, you need to give back under GPLv3 the modifications / improvements.
12 | This is the Right thing to do anyway.
13 | Probably this is a duplicate of the above.
14 |
15 | - If you want to use rfboot to upload a proprietary/closed source application,
16 | it should be OK, and i fact I will be happy if rfboot helps you in your job.
17 | This is because the application (no matter if it is AVR assembler or Arduino sketch) and the bootloader
18 | use different source code trees.
19 |
20 | - It should be obvious, but to be really sure: Channel, syncword, XTEA key are just numbers.
21 | They are not modifications to the code, and you don't publish them.
22 |
23 | Generally, I will be glad if you want to offer corrections or improvements to the code/documentation.
24 |
--------------------------------------------------------------------------------
/help/Reliability.md:
--------------------------------------------------------------------------------
1 | ### Reliability
2 |
3 | In the following section lets imagine a electronic project wich is problematic
4 | to attach wires such as a **weathering station on the roof** a **quadcopter**
5 | or a **model boat on a pool**. We use the cc1101 chip
6 | to communicate with our project, but we also want to update the code via the same RF link.
7 | And most importantly, whatever failure happens while uploading, we should be able to
8 | repeat the process until we succeed.
9 |
10 | Here is explained what rfboot does to accomplish this job.
11 |
12 | At first, a bootloader runs only at power on or after a MCU Reset. The aproach we take here is
13 | that the application must implement a mechanism to software reset the MCU, whenever
14 | we need to update the firmware. A simple solution is to listen for incoming RF packets.
15 | When an incoming packet contains exactly the string ie "Reset" then the application resets
16 | the device giving control to rfboot.
17 |
18 | The rftool utility, whenever creates a new empty project with **"rftool create ProjName"**
19 | includes this mechanism in the .ino file.
20 |
21 | As long as this mechanism works, we can upload code to the device literally thousands of
22 | times, without any need to even touch the device. if however the device for some reason
23 | (usually software bug)
24 | stops responding to the reset request, then it is impossible to reprogram it remotely.
25 | We need to access the reset button (we need to go to the roof for example).
26 |
27 | rfboot avoids (not always as we will see, but close) this type of failure with the following precautions :
28 |
29 | - If rfboot does not receive a packet for 20ms, then requests a retransmission, and of course
30 | rftool on PC side, resends the packet. This is the simplest defence but it is very
31 | effective. Almost all uploads complete, even if some (or even a lot) retransmissions occur.
32 |
33 | - If the upload process is interrupted (completly), rfboot detects it and waits for new firmware. Even
34 | after a power cycle, rfboot refuses to start the application, and waits indefinitely for
35 | new upload.
36 |
37 | - At the event of a power loss or MCU reset while programming, when the power comes back rfboot
38 | will detect the corrupted code and stays waiting for new firmware. When -eventually- the upload
39 | process finishes correctly, only then rfboot gives control to the application.
40 |
41 | - If the upload process is finished (seemingly) correctly but some packet arrived with some wrong bytes, rfboot
42 | will detect that the flashed firmware does not have the correct CRC, and of course it does not start the application.
43 | It is waiting for new firmware.
44 |
45 | - rfboot enables the watchdog timer before the application starts. If for some reason the
46 | application is malfunctioning, watchdog timer will eventually reset the device allowing to reprogram it.
47 | **Note: If the code resets the watchdog periodically, but fails to respond to the reset string, then you are locked out. You will need to access the reset or power button.**
48 |
49 | - Every time rftool creates a new empty project, gives unique channel, syncword, and XTEA
50 | key to the project. This is in turn makes it impossible to send the code to the wrong device (essentially "bricking" it).
51 | Even if we work in parallel with multiple modules, the code always go to the correct MCU.
52 |
53 | **As we see, it is unfortunatelly possible to "brick" the remote target, by sending buggy code.**
54 | Buggy code in this case means code who does not respond to a reset request (from the PC).
55 |
56 | **Always test the firmware at the lab before uploading at the field.**
57 |
58 | Generally it is a good idea to have the reset (or power) button somewhat accessible, for occasional use.
59 |
60 |
--------------------------------------------------------------------------------
/help/The-First-Project.md:
--------------------------------------------------------------------------------
1 | ### The First Project
2 |
3 | Before you proceed, it is required that you have completed the
4 | [Installation of rfboot](Installation.md)
5 |
6 | ### Bill of materials
7 | - atmega328p-pu
8 | - 2 ceramic caps 1uF (Optional, for voltage stability near MCU)
9 | - A momentary pushbutton (optional, for reset)
10 | - A cc1101 RF module with 2.54 pin spacing. The photos show a D-SUN module
11 | - A LED with a suitable resistor.
12 | - Male to female 2.54 jumper wires, and some simple striped wires
13 | - A 3.3V stabilized power source.
14 | For example A lithium-ion cell with a 3.3V regulator and
15 | 2 additional 1uF caps. LP2950-3.3 and HT7333 are very good for this purpose. See picture.
16 | Do not use LM7833 or L78L33 or other non LDO regulators unless your power source voltage is at least 5V. On the other hand some
17 | 3.3V regulators can handle voltages up to 6V only, so be careful.
18 | - ISP programmer with a 28pin ZIF socket. The ISP programmer is used only once
19 | for each project, to write rfboot to the target MCU.
20 | - A breadboard. Note that a breadboard with loose connections is a basic source of failures when prototyping.
21 |
22 |
23 | On the PC, prefferably in you sketchbook folder type :
24 | ```sh
25 | > rftool create myProject
26 | ```
27 |
28 | and you will get something like this:
29 | ```sh
30 |
31 | Application SyncWord = 28,120
32 | rfboot SyncWord = 167,224
33 | rfboot channel = 0
34 | Application channel = 3
35 |
36 | ```
37 |
38 | As you can see rftool generates random parameters (using /dev/urandom), and creates
39 | a "myProject" folder containing all information/data our project needs.
40 |
41 | ```sh
42 | > cd myProject
43 | ```
44 | Now it is time to burn the atmega with rfboot, using the ISP programmer.
45 |
46 | Here is a photo of the USBasp programmer together with a ZIF developer board. (search ebay)
47 | 
48 | If you have a USBtiny ISP programmer, edit the file "rfboot/hardware_settings.mk" and uncomment
49 | the USBtiny line. Put the atmega328p-pu chip on the ZIF socket and :
50 |
51 | ```sh
52 | > make isp
53 | ```
54 | To write the bootloader.
55 | If a project uses a crystal you can edit "rfboot/hardware_settings.mk" before burn.
56 |
57 |
58 | Do not do this (use a crystal) on this first project however, to keep things simple.
59 | Rfboot works perfectly with (uncalibrated up to 10% error) internal oscillator,
60 | because SPI is synchronous.
61 | UART Serial bootloaders on the other hand need a relatively accurate +-2% clock,
62 | otherwise they cannot communicate at all. This is the reason all arduino boards
63 | come with crystal/resonator.
64 |
65 | Here is how our project looks like. It is not connected with anything, and we are going to program it wirelessly.
66 | 
67 |
68 | Now put the atmega and the other components in the breadboard,
69 | and power the board.
70 | From now on, you need the usb2rf module (See [Installation](Installation.md)) connected.
71 |
72 | ```sh
73 | # Opens gtkterm with all apropriate options
74 | > make terminal
75 |
76 | # Sends the firmware via the RF link
77 | > make send
78 | ```
79 |
80 | The "myProject" folder contains a arduino .ino file, in this case "myProject.ino". As is, the program prints a "hello world", it waits for keypresses from the serial terminal, and after that it prints back what you pressed. The purpose of the program is to ensure that all components are correctly wired and working.
81 |
82 | If you were succesful, you can start playing with the code.
83 | All arduino code is working as expected, with the important exception of Serial.print() wich sends data to the hardware serial port but NOT to the RF link. The
84 | PRINT and PRINTLN macros can be used instead which use sprintf internally.
85 | ```C++
86 | i=2;
87 | PRINT("i=%d",i);
88 | j=7;
89 | k=8;
90 | PRINTLN("j=%d and k=%d",j,k);
91 | ```
92 | As you can see they look like the standard printf function. They send data via the RF link, the usb2rf module receives the data, and we can see them with a serial port terminal (we use gtkterm at 38400 bps)
93 |
94 | Now uncomment the lines related to the LED, inside setup()
95 | and loop() in order to have the LED blinking.
96 |
97 | A very importand feature of rfboot is that it does NOT use any EEPROM location to store RF
98 | channel etc. All parameters are stored in the compiled bootloader, and the application can
99 | use the whole EEPROM.
100 |
101 | ***The first rfboot based project is finished !***
102 |
103 | Spend 2 minitues to configure geany (or your editor) to execute
104 |
105 | "make terminal"
106 |
107 | "make clean"
108 |
109 | "make send"
110 |
111 | with a menu entry, or keyboard shortcut
112 |
113 | 
114 |
--------------------------------------------------------------------------------
/help/files/FirstRfbootProject.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pkarsy/rfboot/479c2bde7dda42a6d2efc1c06f510441e89a511c/help/files/FirstRfbootProject.fzz
--------------------------------------------------------------------------------
/help/files/FirstRfbootProject.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pkarsy/rfboot/479c2bde7dda42a6d2efc1c06f510441e89a511c/help/files/FirstRfbootProject.jpg
--------------------------------------------------------------------------------
/help/files/MenuEntry.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pkarsy/rfboot/479c2bde7dda42a6d2efc1c06f510441e89a511c/help/files/MenuEntry.png
--------------------------------------------------------------------------------
/help/files/ftdi.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pkarsy/rfboot/479c2bde7dda42a6d2efc1c06f510441e89a511c/help/files/ftdi.jpg
--------------------------------------------------------------------------------
/help/files/usb2rf1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pkarsy/rfboot/479c2bde7dda42a6d2efc1c06f510441e89a511c/help/files/usb2rf1.jpg
--------------------------------------------------------------------------------
/help/files/usb2rf2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pkarsy/rfboot/479c2bde7dda42a6d2efc1c06f510441e89a511c/help/files/usb2rf2.jpg
--------------------------------------------------------------------------------
/help/files/usb2rf3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pkarsy/rfboot/479c2bde7dda42a6d2efc1c06f510441e89a511c/help/files/usb2rf3.jpg
--------------------------------------------------------------------------------
/help/files/usbasp.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pkarsy/rfboot/479c2bde7dda42a6d2efc1c06f510441e89a511c/help/files/usbasp.jpg
--------------------------------------------------------------------------------
/help/usb2rf-reset.md:
--------------------------------------------------------------------------------
1 | ### What the D3 to RST cable does in ProMini (usb2rf module)
2 |
3 | This is only useful if you modify the usb2rf sketch frequently. In fact you probably want to program the module with the stock firmware and then forget it. This is explained in [Installation](help/Installation.md)
4 |
5 | D3-RST plays the same role as the DTR-RST connection, in arduinos, to support the autoreset feature. The difference is that the reset is triggered by the firmware and not by the Serial module. This is very importat because we do not want the module to reset every time the serial port is accessed by a program (gtkterm, rftool).
6 |
7 | However the usb2rf firmware asserts D3 LOW when we want to update (the firmware). The usb2rf/Makefile resets the module with this mechanism.
8 |
--------------------------------------------------------------------------------
/rfboot/Makefile:
--------------------------------------------------------------------------------
1 | # Makefile for the rfboot bootloader
2 |
3 | # program name. Should not be changed.
4 | PROGRAM = rfboot
5 |
6 | include hardware_settings.mk
7 |
8 | OBJ = $(PROGRAM).o
9 | OPTIMIZE = -Os -fno-inline-small-functions -fno-split-wide-types
10 | DEFS = -g
11 | LIBS = -Icc1101 -Ixtea
12 | CC = avr-gcc
13 |
14 | # Default frequency is 8Mhz, unless you set one in "complile_settings.mk"
15 | # This should be the normal for atmega328 @ 3.3V
16 | ifeq ($(F_CPU),)
17 | F_CPU := 8000000L
18 | endif
19 |
20 | # Default programmer is usbasp
21 | ifeq ($(PROGRAMMER),)
22 | PROGRAMMER := usbasp
23 | endif
24 |
25 |
26 |
27 | # Default is no crystal
28 | ifeq ($(CRYSTAL),1)
29 | LFUSE := 0xFF
30 | else
31 | LFUSE := 0xE2
32 | endif
33 |
34 | COMPILE_TIME := $(shell date '+%s')
35 |
36 | # Override is only needed by avr-lib build system.
37 | override CFLAGS = -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(F_CPU) $(DEFS)
38 | override LDFLAGS = -Wl,$(LDSECTION)
39 |
40 | OBJCOPY = avr-objcopy
41 | OBJDUMP = avr-objdump
42 |
43 | all: atmega328p
44 |
45 | atmega328p: check
46 | atmega328p: clean
47 | atmega328p: MCU_TARGET = atmega328p
48 | atmega328p: CFLAGS += -std=gnu99 -Wall -ffunction-sections -fdata-sections -fshort-enums -g -Os -w -fno-exceptions -Wl,--gc-sections -Ixtea -Icc1101
49 | atmega328p: CFLAGS += $(OSCCAL_FLAG)
50 | atmega328p: CFLAGS += -DCOMPILE_TIME=$(COMPILE_TIME)
51 | atmega328p: LDSECTION = --section-start=.text=0x7000
52 | atmega328p: $(PROGRAM)_atmega328p.elf
53 | atmega328p: size
54 |
55 | isp: getosccal atmega328p
56 | avrdude -qq -p atmega328p -c $(PROGRAMMER) -e -U lfuse:w:$(LFUSE):m -U hfuse:w:0xD8:m -U efuse:w:0xFD:m -U flash:w:rfboot_atmega328p.elf -U lock:w:0x0C:m
57 |
58 | %.elf:
59 | $(CC) $(CFLAGS) $(LDFLAGS) -c -o xtea.o xtea/xtea.c
60 | $(CC) $(CFLAGS) $(LDFLAGS) -c -o cc1101.o cc1101/cc1101.c
61 | $(CC) $(CFLAGS) $(LDFLAGS) -c -o spi.o cc1101/spi.c
62 | $(CC) $(CFLAGS) $(LDFLAGS) -c -o rfboot.o rfboot.c
63 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ rfboot.o xtea.o spi.o cc1101.o
64 |
65 | check:
66 | @test -s rfboot_settings.h || { echo "rfb_settings.h does not exist ! Exiting..."; exit 1; }
67 |
68 | clean:
69 | rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex
70 |
71 | %.lst: %.elf
72 | $(OBJDUMP) -h -S $< > $@
73 |
74 | %.hex: %.elf
75 | $(OBJCOPY) -j .text -j .data -O ihex $< $@
76 |
77 | size:
78 | avr-size --mcu=$(MCU_TARGET) -C $(PROGRAM)_$(MCU_TARGET).elf
79 |
80 | ifdef RC_CALIBRATOR
81 | getosccal:
82 | $(eval OPTIMAL_OSCCAL_VALUE := $(shell $(RC_CALIBRATOR) ) )
83 | $(eval OSCCAL_FLAG := -DOPTIMAL_OSCCAL_VALUE=$(OPTIMAL_OSCCAL_VALUE) )
84 | else
85 | getosccal:
86 |
87 | endif
88 |
--------------------------------------------------------------------------------
/rfboot/README.md:
--------------------------------------------------------------------------------
1 | This folder contains the bootloader part of the rfboot project
2 |
3 | WARNING: do not complile rfboot from the repository directory
4 | use "rftool create ProjName" in your projects directory
5 | See URL TODO 1rst project
6 |
--------------------------------------------------------------------------------
/rfboot/cc1101/COPYING:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/rfboot/cc1101/README.md:
--------------------------------------------------------------------------------
1 | This is the panStamp library converted from C++ to C. Also a lot of simplifications have been done.
2 |
3 | rfboot (the bootloader part) is written in C, so there is the need to have a C library for the CC1101 chip
4 |
5 | The file pin_macros.h contains code to replace pinMode, digitalRead, digitalWrite in a C environment. The code circulates in many places
6 | in the Internet, and should be Public Domain.
7 |
--------------------------------------------------------------------------------
/rfboot/cc1101/RELEASES.txt:
--------------------------------------------------------------------------------
1 | May 26 2013
2 | ---------------
3 | - Fixed bug in panstamp.cpp so that repeaters no longer respond to queries and commands not
4 | addressed to them.
5 | - Added "enabled" flag in repeater.cpp
6 | - enableRepeater(0) now stops the repeater mode
7 |
8 | May 14 2013
9 | ---------------
10 | - Fixed bug in wakeUp
11 |
12 | May 13 2013
13 | ---------------
14 | - Skip sleeping loop in goToSleep after running wakeUp
15 |
16 | May 8 2013
17 | ---------------
18 | - New implementation of getInternalTemp
19 |
20 | May 7 2013
21 | ---------------
22 | - Bug fixed in setRegValue from register.h
23 |
24 | May 1 2013
25 | ---------------
26 | - Changes in REPEATER class
27 | - New setRegValue method in class REGISTER to set register value from a 1-to-4 byte number
28 | - setSyncWord from CC1101 class now accepts the main argument to be passed as individual bytes
29 | (High byte and low byte of the sync word)
30 | - 433MHz band now supported from the CC1101 class
31 |
32 | Apr 13 2013
33 | ---------------
34 | - CCPACKET and SWPACKET objects become static in isrGDO0event()
35 |
36 | Mar 21 2013
37 | ---------------
38 | - Switched to LGPL license
39 |
40 | Mar 20 2013
41 | ---------------
42 | - Fixed problem with Timer 2 being disabled during SLEEP
43 |
44 | Feb 23 2013
45 | ---------------
46 | - Self-detection of 32.768 KHz crystal
47 | - Timer 1 reverted to its original settings after calibration
48 |
49 | Feb 10 2013
50 | ---------------
51 | - Fixed problem about Rx interrupts happening wjilst in Tx mode
52 | - Señf-detection of the external 32.768 KHz crystal. No more need to define (or comment)
53 | EXTERNAL_RTC_CRYSTAL in config.h
54 |
55 | Jan 17 2013
56 | ---------------
57 | - Check for RX_OVERFLOW in sendData whilst trying to enter Rx state
58 |
59 | Dec 10 2012
60 | ---------------
61 | - EXTERNAL_RTC_CRYSTAL now enabled by default from config.h. This option needs to be disabled
62 | for old versions of panStamp, without the external 32.768 KHz crystal
63 |
64 |
--------------------------------------------------------------------------------
/rfboot/cc1101/cc1101.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2017 Panagiotis Karagiannis
3 | Based on the panstamp library and modified to better suite the needs of
4 | rfboot. The licence remains the same LGPLv3 or later
5 | */
6 |
7 | /**
8 | * Copyright (c) 2011 panStamp
9 | *
10 | * This file is part of the panStamp project.
11 | *
12 | * panStamp is free software; you can redistribute it and/or modify
13 | * it under the terms of the GNU Lesser General Public License as published by
14 | * the Free Software Foundation; either version 3 of the License, or
15 | * any later version.
16 | *
17 | * panStamp is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Lesser General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Lesser General Public License
23 | * along with panStamp; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 | * USA
26 | *
27 | * Author: Daniel Berenguer
28 | * Creation date: 03/03/2011
29 | */
30 |
31 | #include "cc1101.h"
32 | #include
33 | //#include "nvolat.h"
34 |
35 | /**
36 | * Macros
37 | */
38 | // Select (SPI) CC1101
39 | //define cc1101_Select() bitClear(PORT_SPI_SS, BIT_SPI_SS)
40 | #define cc1101_Select() LOW(SPI_SS)
41 |
42 | // Deselect (SPI) CC1101
43 | //#define cc1101_Deselect() bitSet(PORT_SPI_SS, BIT_SPI_SS)
44 | #define cc1101_Deselect() HIGH(SPI_SS)
45 |
46 | // Wait until SPI MISO line goes low
47 | //#define wait_Miso() while(bitRead(PORT_SPI_MISO, BIT_SPI_MISO))
48 | #define wait_Miso() while(READ(SPI_MISO))
49 |
50 | // Get GDO0 pin state
51 | //#define getGDO0state() bitRead(PORT_GDO0, BIT_GDO0)
52 | #define getGDO0state() READ(GDO0)
53 |
54 | // Wait until GDO0 line goes high
55 | #define wait_GDO0_high() while(!getGDO0state())
56 |
57 | // Wait until GDO0 line goes low
58 | #define wait_GDO0_low() while(getGDO0state())
59 |
60 | /**
61 | * PATABLE
62 | */
63 | //const byte paTable[8] = {0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60};
64 |
65 | /**
66 | * CC1101
67 | *
68 | * Class constructor
69 | */
70 | //void CC1101(void)
71 | //{
72 | // cc1101_paTableByte = PA_LowPower; // Priority = Low power
73 | //}
74 |
75 | /**
76 | * cc1101_wakeUp
77 | *
78 | * Wake up CC1101 from Power Down state
79 | */
80 | void cc1101_wakeUp(void)
81 | {
82 | cc1101_Select(); // Select CC1101
83 | wait_Miso(); // Wait until MISO goes low
84 | cc1101_Deselect(); // Deselect CC1101
85 | }
86 |
87 | /**
88 | * cc1101_writeReg
89 | *
90 | * Write single register into the CC1101 IC via SPI
91 | *
92 | * 'regAddr' Register address
93 | * 'value' Value to be writen
94 | */
95 | void cc1101_writeReg(byte regAddr, byte value)
96 | {
97 | cc1101_Select(); // Select CC1101
98 | wait_Miso(); // Wait until MISO goes low
99 | spi_send(regAddr); // Send register address
100 | spi_send(value); // Send value
101 | cc1101_Deselect(); // Deselect CC1101
102 | }
103 |
104 | /**
105 | * cc1101_writeBurstReg
106 | *
107 | * Write multiple registers into the CC1101 IC via SPI
108 | *
109 | * 'regAddr' Register address
110 | * 'buffer' Data to be writen
111 | * 'len' Data length
112 | */
113 | void cc1101_writeBurstReg(byte regAddr, byte* buffer, byte len)
114 | {
115 | byte addr, i;
116 |
117 | addr = regAddr | WRITE_BURST; // Enable burst transfer
118 | cc1101_Select(); // Select CC1101
119 | wait_Miso(); // Wait unt0il MISO goes low
120 | spi_send(addr); // Send register address
121 |
122 | for(i=0 ; i 0)
442 | cc1101_setDevAddress(bVal, false); */
443 | //}
444 |
445 | /**
446 | * cc1101_setPowerDownState
447 | *
448 | * Put CC1101 into power-down state
449 | */
450 | void cc1101_setPowerDownState()
451 | {
452 | // Comming from RX state, we need to enter the IDLE state first
453 | cc1101_cmdStrobe(CC1101_SIDLE);
454 | // Enter Power-down state
455 | cc1101_cmdStrobe(CC1101_SPWD);
456 | }
457 |
458 | /**
459 | * cc1101_sendData
460 | *
461 | * Send data packet via RF
462 | *
463 | * 'packet' Packet to be transmitted. First byte is the destination address
464 | *
465 | * Return:
466 | * True if the transmission succeeds
467 | * False otherwise
468 | */
469 | bool cc1101_sendData(CCPACKET packet)
470 | {
471 | byte marcState;
472 | bool res = false;
473 |
474 | // Declare to be in Tx state. This will avoid receiving packets whilst
475 | // transmitting
476 | //cc1101_rfState = RFSTATE_TX;
477 |
478 | // Enter RX state
479 | setRxState();
480 |
481 | // Check that the RX state has been entered
482 | while (((marcState = readStatusReg(CC1101_MARCSTATE)) & 0x1F) != 0x0D)
483 | {
484 | if (marcState == 0x11) // RX_OVERFLOW
485 | flushRxFifo(); // flush receive queue
486 | }
487 |
488 | //delayMicroseconds(500);
489 | _delay_us(500);
490 |
491 | // Set data length at the first position of the TX FIFO
492 | cc1101_writeReg(CC1101_TXFIFO, packet.length);
493 | // Write data into the TX FIFO
494 | cc1101_writeBurstReg(CC1101_TXFIFO, packet.data, packet.length);
495 |
496 | // CCA enabled: will enter TX state only if the channel is clear
497 | setTxState();
498 |
499 | // Check that TX state is being entered (state = RXTX_SETTLING)
500 | marcState = readStatusReg(CC1101_MARCSTATE) & 0x1F;
501 | if((marcState != 0x13) && (marcState != 0x14) && (marcState != 0x15))
502 | {
503 | setIdleState(); // Enter IDLE state
504 | flushTxFifo(); // Flush Tx FIFO
505 | setRxState(); // Back to RX state
506 |
507 | // Declare to be in Rx state
508 | //cc1101_rfState = RFSTATE_RX;
509 | return false;
510 | }
511 |
512 | // Wait for the sync word to be transmitted
513 | wait_GDO0_high();
514 |
515 | // Wait until the end of the packet transmission
516 | wait_GDO0_low();
517 |
518 | // Check that the TX FIFO is empty
519 | if((readStatusReg(CC1101_TXBYTES) & 0x7F) == 0)
520 | res = true;
521 |
522 | setIdleState(); // Enter IDLE state
523 | flushTxFifo(); // Flush Tx FIFO
524 |
525 | // Enter back into RX state
526 | setRxState();
527 |
528 | // Declare to be in Rx state
529 | //cc1101_rfState = RFSTATE_RX;
530 |
531 | return res;
532 | }
533 |
534 | /**
535 | * cc1101_receiveData
536 | *
537 | * Read data packet from RX FIFO
538 | *
539 | * 'packet' Container for the packet received
540 | *
541 | * Return:
542 | * Amount of bytes received
543 | */
544 | byte cc1101_receiveData(CCPACKET * packet)
545 | {
546 | byte val;
547 | byte rxBytes = readStatusReg(CC1101_RXBYTES);
548 |
549 | // Any byte waiting to be read and no overflow?
550 | if (rxBytes & 0x7F && !(rxBytes & 0x80))
551 | {
552 | // Read data length
553 | packet->length = readConfigReg(CC1101_RXFIFO);
554 | // If packet is too long
555 | if (packet->length > CC1101_DATA_LEN)
556 | packet->length = 0; // Discard packet
557 | else
558 | {
559 | // Read data packet
560 | cc1101_readBurstReg(packet->data, CC1101_RXFIFO, packet->length);
561 | // Read RSSI
562 | packet->rssi = readConfigReg(CC1101_RXFIFO);
563 | // Read LQI and CRC_OK
564 | val = readConfigReg(CC1101_RXFIFO);
565 | packet->lqi = val & 0x7F;
566 | //packet->crc_ok = bitRead(val, 7);
567 | packet->crc_ok = (val>>7);
568 | }
569 | }
570 | else
571 | packet->length = 0;
572 |
573 | setIdleState(); // Enter IDLE state
574 | flushRxFifo(); // Flush Rx FIFO
575 | //cc1101_cmdStrobe(CC1101_SCAL);
576 |
577 | // Back to RX state
578 | setRxState();
579 |
580 | return packet->length;
581 | }
582 |
583 |
--------------------------------------------------------------------------------
/rfboot/cc1101/cc1101.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2017 Panagiotis Karagiannis
3 | Based on the panstamp library and modified to better suite the needs of
4 | rfboot. The licence remains the same LGPLv3 or later
5 | */
6 |
7 | /**
8 | * Copyright (c) 2011 panStamp
9 | *
10 | * This file is part of the panStamp project.
11 | *
12 | * panStamp is free software; you can redistribute it and/or modify
13 | * it under the terms of the GNU Lesser General Public License as published by
14 | * the Free Software Foundation; either version 3 of the License, or
15 | * any later version.
16 | *
17 | * panStamp is distributed in the hope that it will be useful,
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | * GNU Lesser General Public License for more details.
21 | *
22 | * You should have received a copy of the GNU Lesser General Public License
23 | * along with panStamp; if not, write to the Free Software
24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 | * USA
26 | *
27 | * Author: Daniel Berenguer
28 | * Creation date: 03/03/2011
29 | */
30 |
31 | #ifndef _CC1101_H
32 | #define _CC1101_H
33 |
34 | #include
35 |
36 | #include "spi.h"
37 | #include "ccpacket.h"
38 |
39 | /**
40 | * Carrier frequencies
41 | */
42 | enum CFREQ
43 | {
44 | CFREQ_868 = 0,
45 | CFREQ_915,
46 | CFREQ_433,
47 | CFREQ_LAST
48 | };
49 |
50 | /**
51 | * RF STATES
52 | */
53 | enum RFSTATE
54 | {
55 | RFSTATE_IDLE = 0,
56 | RFSTATE_RX,
57 | RFSTATE_TX
58 | };
59 |
60 |
61 | /**
62 | * Frequency channels
63 | */
64 | #define NUMBER_OF_FCHANNELS 10
65 |
66 | /**
67 | * Type of transfers
68 | */
69 | #define WRITE_BURST 0x40
70 | #define READ_SINGLE 0x80
71 | #define READ_BURST 0xC0
72 |
73 | /**
74 | * Type of register
75 | */
76 | #define CC1101_CONFIG_REGISTER READ_SINGLE
77 | #define CC1101_STATUS_REGISTER READ_BURST
78 |
79 | /**
80 | * PATABLE & FIFO's
81 | */
82 | #define CC1101_PATABLE 0x3E // PATABLE address
83 | #define CC1101_TXFIFO 0x3F // TX FIFO address
84 | #define CC1101_RXFIFO 0x3F // RX FIFO address
85 |
86 | /**
87 | * Command strobes
88 | */
89 | #define CC1101_SRES 0x30 // Reset CC1101 chip
90 | #define CC1101_SFSTXON 0x31 // Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL=1). If in RX (with CCA):
91 | // Go to a wait state where only the synthesizer is running (for quick RX / TX turnaround).
92 | #define CC1101_SXOFF 0x32 // Turn off crystal oscillator
93 | #define CC1101_SCAL 0x33 // Calibrate frequency synthesizer and turn it off. SCAL can be strobed from IDLE mode without
94 | // setting manual calibration mode (MCSM0.FS_AUTOCAL=0)
95 | #define CC1101_SRX 0x34 // Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL=1
96 | #define CC1101_STX 0x35 // In IDLE state: Enable TX. Perform calibration first if MCSM0.FS_AUTOCAL=1.
97 | // If in RX state and CCA is enabled: Only go to TX if channel is clear
98 | #define CC1101_SIDLE 0x36 // Exit RX / TX, turn off frequency synthesizer and exit Wake-On-Radio mode if applicable
99 | #define CC1101_SWOR 0x38 // Start automatic RX polling sequence (Wake-on-Radio) as described in Section 19.5 if
100 | // WORCTRL.RC_PD=0
101 | #define CC1101_SPWD 0x39 // Enter power down mode when CSn goes high
102 | #define CC1101_SFRX 0x3A // Flush the RX FIFO buffer. Only issue SFRX in IDLE or RXFIFO_OVERFLOW states
103 | #define CC1101_SFTX 0x3B // Flush the TX FIFO buffer. Only issue SFTX in IDLE or TXFIFO_UNDERFLOW states
104 | #define CC1101_SWORRST 0x3C // Reset real time clock to Event1 value
105 | #define CC1101_SNOP 0x3D // No operation. May be used to get access to the chip status byte
106 |
107 | /**
108 | * CC1101 configuration registers
109 | */
110 | #define CC1101_IOCFG2 0x00 // GDO2 Output Pin Configuration
111 | #define CC1101_IOCFG1 0x01 // GDO1 Output Pin Configuration
112 | #define CC1101_IOCFG0 0x02 // GDO0 Output Pin Configuration
113 | #define CC1101_FIFOTHR 0x03 // RX FIFO and TX FIFO Thresholds
114 | #define CC1101_SYNC1 0x04 // Sync Word, High Byte
115 | #define CC1101_SYNC0 0x05 // Sync Word, Low Byte
116 | #define CC1101_PKTLEN 0x06 // Packet Length
117 | #define CC1101_PKTCTRL1 0x07 // Packet Automation Control
118 | #define CC1101_PKTCTRL0 0x08 // Packet Automation Control
119 | #define CC1101_ADDR 0x09 // Device Address
120 | #define CC1101_CHANNR 0x0A // Channel Number
121 | #define CC1101_FSCTRL1 0x0B // Frequency Synthesizer Control
122 | #define CC1101_FSCTRL0 0x0C // Frequency Synthesizer Control
123 | #define CC1101_FREQ2 0x0D // Frequency Control Word, High Byte
124 | #define CC1101_FREQ1 0x0E // Frequency Control Word, Middle Byte
125 | #define CC1101_FREQ0 0x0F // Frequency Control Word, Low Byte
126 | #define CC1101_MDMCFG4 0x10 // Modem Configuration
127 | #define CC1101_MDMCFG3 0x11 // Modem Configuration
128 | #define CC1101_MDMCFG2 0x12 // Modem Configuration
129 | #define CC1101_MDMCFG1 0x13 // Modem Configuration
130 | #define CC1101_MDMCFG0 0x14 // Modem Configuration
131 | #define CC1101_DEVIATN 0x15 // Modem Deviation Setting
132 | #define CC1101_MCSM2 0x16 // Main Radio Control State Machine Configuration
133 | #define CC1101_MCSM1 0x17 // Main Radio Control State Machine Configuration
134 | #define CC1101_MCSM0 0x18 // Main Radio Control State Machine Configuration
135 | #define CC1101_FOCCFG 0x19 // Frequency Offset Compensation Configuration
136 | #define CC1101_BSCFG 0x1A // Bit Synchronization Configuration
137 | #define CC1101_AGCCTRL2 0x1B // AGC Control
138 | #define CC1101_AGCCTRL1 0x1C // AGC Control
139 | #define CC1101_AGCCTRL0 0x1D // AGC Control
140 | #define CC1101_WOREVT1 0x1E // High Byte Event0 Timeout
141 | #define CC1101_WOREVT0 0x1F // Low Byte Event0 Timeout
142 | #define CC1101_WORCTRL 0x20 // Wake On Radio Control
143 | #define CC1101_FREND1 0x21 // Front End RX Configuration
144 | #define CC1101_FREND0 0x22 // Front End TX Configuration
145 | #define CC1101_FSCAL3 0x23 // Frequency Synthesizer Calibration
146 | #define CC1101_FSCAL2 0x24 // Frequency Synthesizer Calibration
147 | #define CC1101_FSCAL1 0x25 // Frequency Synthesizer Calibration
148 | #define CC1101_FSCAL0 0x26 // Frequency Synthesizer Calibration
149 | #define CC1101_RCCTRL1 0x27 // RC Oscillator Configuration
150 | #define CC1101_RCCTRL0 0x28 // RC Oscillator Configuration
151 | #define CC1101_FSTEST 0x29 // Frequency Synthesizer Calibration Control
152 | #define CC1101_PTEST 0x2A // Production Test
153 | #define CC1101_AGCTEST 0x2B // AGC Test
154 | #define CC1101_TEST2 0x2C // Various Test Settings
155 | #define CC1101_TEST1 0x2D // Various Test Settings
156 | #define CC1101_TEST0 0x2E // Various Test Settings
157 |
158 | /**
159 | * Status registers
160 | */
161 | #define CC1101_PARTNUM 0x30 // Chip ID
162 | #define CC1101_VERSION 0x31 // Chip ID
163 | #define CC1101_FREQEST 0x32 // Frequency Offset Estimate from Demodulator
164 | #define CC1101_LQI 0x33 // Demodulator Estimate for Link Quality
165 | #define CC1101_RSSI 0x34 // Received Signal Strength Indication
166 | #define CC1101_MARCSTATE 0x35 // Main Radio Control State Machine State
167 | #define CC1101_WORTIME1 0x36 // High Byte of WOR Time
168 | #define CC1101_WORTIME0 0x37 // Low Byte of WOR Time
169 | #define CC1101_PKTSTATUS 0x38 // Current GDOx Status and Packet Status
170 | #define CC1101_VCO_VC_DAC 0x39 // Current Setting from PLL Calibration Module
171 | #define CC1101_TXBYTES 0x3A // Underflow and Number of Bytes
172 | #define CC1101_RXBYTES 0x3B // Overflow and Number of Bytes
173 | #define CC1101_RCCTRL1_STATUS 0x3C // Last RC Oscillator Calibration Result
174 | #define CC1101_RCCTRL0_STATUS 0x3D // Last RC Oscillator Calibration Result
175 |
176 | /**
177 | * CC1101 configuration registers - Default values extracted from SmartRF Studio
178 | *
179 | * Configuration:
180 | *
181 | * Deviation = 20.629883
182 | * Base frequency = 867.999939
183 | * Carrier frequency = 867.999939
184 | * Channel number = 0
185 | * Carrier frequency = 867.999939
186 | * Modulated = true
187 | * Modulation format = GFSK
188 | * Manchester enable = false
189 | * Data whitening = off
190 | * Sync word qualifier mode = 30/32 sync word bits detected
191 | * Preamble count = 4
192 | * Channel spacing = 199.951172
193 | * Carrier frequency = 867.999939
194 | * Data rate = 38.3835 Kbps
195 | * RX filter BW = 101.562500
196 | * Data format = Normal mode
197 | * Length config = Variable packet length mode. Packet length configured by the first byte after sync word
198 | * CRC enable = true
199 | * Packet length = 255
200 | * Device address = 1
201 | * Address config = Enable address check
202 | * Append status = Append two status bytes to the payload of the packet. The status bytes contain RSSI and
203 | * LQI values, as well as CRC OK
204 | * CRC autoflush = false
205 | * PA ramping = false
206 | * TX power = 12
207 | * GDO0 mode = Asserts when sync word has been sent / received, and de-asserts at the end of the packet.
208 | * In RX, the pin will also de-assert when a packet is discarded due to address or maximum length filtering
209 | * or when the radio enters RXFIFO_OVERFLOW state. In TX the pin will de-assert if the TX FIFO underflows
210 | * Settings optimized for low current consumption
211 | */
212 | //#define CC1101_DEFVAL_IOCFG2 0x29 // GDO2 Output Pin Configuration
213 | #define CC1101_DEFVAL_IOCFG2 0x2E // GDO2 Output Pin Configuration
214 | #define CC1101_DEFVAL_IOCFG1 0x2E // GDO1 Output Pin Configuration
215 | #define CC1101_DEFVAL_IOCFG0 0x06 // GDO0 Output Pin Configuration
216 | #define CC1101_DEFVAL_FIFOTHR 0x07 // RX FIFO and TX FIFO Thresholds
217 | #define CC1101_DEFVAL_SYNC1 0xB5 // Synchronization word, high byte
218 | #define CC1101_DEFVAL_SYNC0 0x47 // Synchronization word, low byte
219 | #define CC1101_DEFVAL_PKTLEN 0x3D // Packet Length
220 | #define CC1101_DEFVAL_PKTCTRL1 0x06 // Packet Automation Control
221 | #define CC1101_DEFVAL_PKTCTRL0 0x05 // Packet Automation Control
222 | #define CC1101_DEFVAL_ADDR 0xFF // Device Address
223 | #define CC1101_DEFVAL_CHANNR 0x00 // Channel Number
224 | #define CC1101_DEFVAL_FSCTRL1 0x08 // Frequency Synthesizer Control
225 | #define CC1101_DEFVAL_FSCTRL0 0x00 // Frequency Synthesizer Control
226 | // Carrier frequency = 868 MHz
227 | #define CC1101_DEFVAL_FREQ2_868 0x21 // Frequency Control Word, High Byte
228 | #define CC1101_DEFVAL_FREQ1_868 0x62 // Frequency Control Word, Middle Byte
229 | #define CC1101_DEFVAL_FREQ0_868 0x76 // Frequency Control Word, Low Byte
230 | // Carrier frequency = 902 MHz
231 | #define CC1101_DEFVAL_FREQ2_915 0x22 // Frequency Control Word, High Byte
232 | #define CC1101_DEFVAL_FREQ1_915 0xB1 // Frequency Control Word, Middle Byte
233 | #define CC1101_DEFVAL_FREQ0_915 0x3B // Frequency Control Word, Low Byte
234 | // Carrier frequency = 433 MHz
235 | #define CC1101_DEFVAL_FREQ2_433 0x10 // Frequency Control Word, High Byte
236 | #define CC1101_DEFVAL_FREQ1_433 0xA7 // Frequency Control Word, Middle Byte
237 | #define CC1101_DEFVAL_FREQ0_433 0x62 // Frequency Control Word, Low Byte
238 |
239 | #define CC1101_DEFVAL_MDMCFG4 0xCA // Modem Configuration
240 | #define CC1101_DEFVAL_MDMCFG3 0x83 // Modem Configuration
241 | #define CC1101_DEFVAL_MDMCFG2 0x93 // Modem Configuration
242 | #define CC1101_DEFVAL_MDMCFG1 0x22 // Modem Configuration
243 | #define CC1101_DEFVAL_MDMCFG0 0xF8 // Modem Configuration
244 | #define CC1101_DEFVAL_DEVIATN 0x35 // Modem Deviation Setting
245 | #define CC1101_DEFVAL_MCSM2 0x07 // Main Radio Control State Machine Configuration
246 | //#define CC1101_DEFVAL_MCSM1 0x30 // Main Radio Control State Machine Configuration
247 | #define CC1101_DEFVAL_MCSM1 0x20 // Main Radio Control State Machine Configuration
248 | #define CC1101_DEFVAL_MCSM0 0x18 // Main Radio Control State Machine Configuration
249 | #define CC1101_DEFVAL_FOCCFG 0x16 // Frequency Offset Compensation Configuration
250 | #define CC1101_DEFVAL_BSCFG 0x6C // Bit Synchronization Configuration
251 | #define CC1101_DEFVAL_AGCCTRL2 0x43 // AGC Control
252 | #define CC1101_DEFVAL_AGCCTRL1 0x40 // AGC Control
253 | #define CC1101_DEFVAL_AGCCTRL0 0x91 // AGC Control
254 | #define CC1101_DEFVAL_WOREVT1 0x87 // High Byte Event0 Timeout
255 | #define CC1101_DEFVAL_WOREVT0 0x6B // Low Byte Event0 Timeout
256 | #define CC1101_DEFVAL_WORCTRL 0xFB // Wake On Radio Control
257 | #define CC1101_DEFVAL_FREND1 0x56 // Front End RX Configuration
258 | #define CC1101_DEFVAL_FREND0 0x10 // Front End TX Configuration
259 | #define CC1101_DEFVAL_FSCAL3 0xE9 // Frequency Synthesizer Calibration
260 | #define CC1101_DEFVAL_FSCAL2 0x2A // Frequency Synthesizer Calibration
261 | #define CC1101_DEFVAL_FSCAL1 0x00 // Frequency Synthesizer Calibration
262 | #define CC1101_DEFVAL_FSCAL0 0x1F // Frequency Synthesizer Calibration
263 | #define CC1101_DEFVAL_RCCTRL1 0x41 // RC Oscillator Configuration
264 | #define CC1101_DEFVAL_RCCTRL0 0x00 // RC Oscillator Configuration
265 | #define CC1101_DEFVAL_FSTEST 0x59 // Frequency Synthesizer Calibration Control
266 | #define CC1101_DEFVAL_PTEST 0x7F // Production Test
267 | #define CC1101_DEFVAL_AGCTEST 0x3F // AGC Test
268 | #define CC1101_DEFVAL_TEST2 0x81 // Various Test Settings
269 | #define CC1101_DEFVAL_TEST1 0x35 // Various Test Settings
270 | #define CC1101_DEFVAL_TEST0 0x09 // Various Test Settings
271 |
272 | /**
273 | * Macros
274 | */
275 | // Read CC1101 Config register
276 | #define readConfigReg(regAddr) cc1101_readReg(regAddr, CC1101_CONFIG_REGISTER)
277 | // Read CC1101 Status register
278 | #define readStatusReg(regAddr) cc1101_readReg(regAddr, CC1101_STATUS_REGISTER)
279 | // Enter Rx state
280 | #define setRxState() cc1101_cmdStrobe(CC1101_SRX)
281 | // Enter Tx state
282 | #define setTxState() cc1101_cmdStrobe(CC1101_STX)
283 | // Enter IDLE state
284 | #define setIdleState() cc1101_cmdStrobe(CC1101_SIDLE)
285 | // Flush Rx FIFO
286 | #define flushRxFifo() cc1101_cmdStrobe(CC1101_SFRX)
287 | // Flush Tx FIFO
288 | #define flushTxFifo() cc1101_cmdStrobe(CC1101_SFTX)
289 | // Disable address check
290 | #define disableAddressCheck() cc1101_writeReg(CC1101_PKTCTRL1, 0x04)
291 | // Enable address check
292 | #define enableAddressCheck() cc1101_writeReg(CC1101_PKTCTRL1, 0x06)
293 | // Disable CCA
294 | #define disableCCA() cc1101_writeReg(CC1101_MCSM1, 0)
295 | // Enable CCA
296 | #define enableCCA() cc1101_writeReg(CC1101_MCSM1, CC1101_DEFVAL_MCSM1)
297 | // Set PATABLE single byte
298 | // #define setTxPowerAmp(setting) cc1101_paTableByte = setting
299 | // PATABLE values
300 | #define PA_LowPower 0x60
301 | #define PA_LongDistance 0xC0
302 |
303 | /**
304 | * Class: CC1101
305 | *
306 | * Description:
307 | * CC1101 interface
308 | */
309 | //class CC1101
310 | //{
311 | //private:
312 | /**
313 | * Atmega's SPI interface
314 | */
315 | //SPI spi;
316 |
317 | /**
318 | * cc1101_writeBurstReg
319 | *
320 | * Write multiple registers into the CC1101 IC via SPI
321 | *
322 | * 'regAddr' Register address
323 | * 'buffer' Data to be writen
324 | * 'len' Data length
325 | */
326 | //void cc1101_writeBurstReg(byte regAddr, byte* buffer, byte len);
327 |
328 | /**
329 | * cc1101_readBurstReg
330 | *
331 | * Read burst data from CC1101 via SPI
332 | *
333 | * 'buffer' Buffer where to copy the result to
334 | * 'regAddr' Register address
335 | * 'len' Data length
336 | */
337 | void cc1101_readBurstReg(byte * buffer, byte regAddr, byte len);
338 |
339 | /**
340 | * cc1101_setDefaultRegs
341 | *
342 | * Configure CC1101 registers
343 | */
344 | void cc1101_setDefaultRegs(void);
345 |
346 | /**
347 | * setRegsFromEeprom
348 | *
349 | * Set registers from EEPROM
350 | */
351 | //void setRegsFromEeprom(void);
352 |
353 | //public:
354 | /*
355 | * RF state
356 | */
357 | //byte cc1101_rfState;
358 |
359 | /**
360 | * Tx Power byte (single PATABLE config)
361 | */
362 | //byte cc1101_paTableByte;
363 |
364 | /**
365 | * Carrier frequency
366 | */
367 | //byte cc1101_carrierFreq;
368 |
369 | /**
370 | * Frequency channel
371 | */
372 | //byte cc1101_channel;
373 |
374 | /**
375 | * Synchronization word
376 | */
377 | //byte cc1101_syncWord[2];
378 |
379 | /**
380 | * Device address
381 | */
382 | //byte cc1101_devAddress;
383 |
384 | /**
385 | * CC1101
386 | *
387 | * Class constructor
388 | */
389 | //CC1101(void);
390 |
391 | void cc1101_writeBurstReg(byte regAddr, byte* buffer, byte len);
392 |
393 | /**
394 | * cc1101_cmdStrobe
395 | *
396 | * Send command strobe to the CC1101 IC via SPI
397 | *
398 | * 'cmd' Command strobe
399 | */
400 | void cc1101_cmdStrobe(byte cmd);
401 |
402 | /**
403 | * cc1101_wakeUp
404 | *
405 | * Wake up CC1101 from Power Down state
406 | */
407 | void cc1101_wakeUp(void);
408 |
409 | /**
410 | * cc1101_readReg
411 | *
412 | * Read CC1101 register via SPI
413 | *
414 | * 'regAddr' Register address
415 | * 'regType' Type of register: CC1101_CONFIG_REGISTER or CC1101_STATUS_REGISTER
416 | *
417 | * Return:
418 | * Data byte returned by the CC1101 IC
419 | */
420 | byte cc1101_readReg(byte regAddr, byte regType);
421 |
422 | /**
423 | * cc1101_writeReg
424 | *
425 | * Write single register into the CC1101 IC via SPI
426 | *
427 | * 'regAddr' Register address
428 | * 'value' Value to be writen
429 | */
430 | void cc1101_writeReg(byte regAddr, byte value);
431 |
432 | /**
433 | * cc1101_reset
434 | *
435 | * Reset CC1101
436 | */
437 | void cc1101_reset(void);
438 |
439 | /**
440 | * cc1101_init
441 | *
442 | * Initializa CC1101
443 | */
444 | void cc1101_init(void);
445 |
446 | /**
447 | * cc1101_setSyncWord
448 | *
449 | * Set synchronization word
450 | *
451 | * 'syncH' Synchronization word - High byte
452 | * 'syncL' Synchronization word - Low byte
453 |
454 | */
455 | void cc1101_setSyncWord(uint8_t syncH, uint8_t syncL);
456 |
457 | /**
458 | * cc1101_setSyncWord (overriding method)
459 | *
460 | * Set synchronization word
461 | *
462 | * 'syncH' Synchronization word - pointer to 2-byte array
463 |
464 | */
465 | //void cc1101_setSyncWord(byte *sync);
466 |
467 | /**
468 | * cc1101_setDevAddress
469 | *
470 | * Set device address
471 | *
472 | * 'addr' Device address
473 |
474 | */
475 | void cc1101_setDevAddress(byte addr);
476 |
477 | /**
478 | * cc1101_setCarrierFreq
479 | *
480 | * Set carrier frequency
481 | *
482 | * 'freq' New carrier frequency
483 | */
484 | void cc1101_setCarrierFreq(byte freq);
485 |
486 | /**
487 | * cc1101_setChannel
488 | *
489 | * Set frequency channel
490 | *
491 | * 'chnl' Frequency channel
492 |
493 | */
494 | void cc1101_setChannel(byte chnl);
495 |
496 | /**
497 | * cc1101_setPowerDownState
498 | *
499 | * Put CC1101 into power-down state
500 | */
501 | void cc1101_setPowerDownState();
502 |
503 | /**
504 | * cc1101_sendData
505 | *
506 | * Send data packet via RF
507 | *
508 | * 'packet' Packet to be transmitted. First byte is the destination address
509 | *
510 | * Return:
511 | * True if the transmission succeeds
512 | * False otherwise
513 | */
514 | bool cc1101_sendData(CCPACKET packet);
515 |
516 | /**
517 | * cc1101_receiveData
518 | *
519 | * Read data packet from RX FIFO
520 | *
521 | * Return:
522 | * Amount of bytes received
523 | */
524 | byte cc1101_receiveData(CCPACKET *packet);
525 | //};
526 |
527 | #endif
528 |
529 |
--------------------------------------------------------------------------------
/rfboot/cc1101/ccpacket.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011 panStamp
3 | *
4 | * This file is part of the panStamp project.
5 | *
6 | * panStamp is free software; you can redistribute it and/or modify
7 | * it under the terms of the GNU Lesser General Public License as published by
8 | * the Free Software Foundation; either version 3 of the License, or
9 | * any later version.
10 | *
11 | * panStamp is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with panStamp; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 | * USA
20 | *
21 | * Author: Daniel Berenguer
22 | * Creation date: 03/03/2011
23 | */
24 |
25 | #ifndef _CCPACKET_H
26 | #define _CCPACKET_H
27 |
28 | //#include "Arduino.h"
29 |
30 | /**
31 | * Buffer and data lengths
32 | */
33 | #define CC1101_BUFFER_LEN 64
34 | #define CC1101_DATA_LEN CC1101_BUFFER_LEN - 3
35 |
36 | /**
37 | * Class: CCPACKET
38 | *
39 | * Description:
40 | * CC1101 data packet class
41 | */
42 | typedef struct
43 | {
44 | //public:
45 | /**
46 | * Data length
47 | */
48 | byte length;
49 |
50 | /**
51 | * Data buffer
52 | */
53 | byte data[CC1101_DATA_LEN];
54 |
55 | /**
56 | * CRC OK flag
57 | */
58 | uint8_t crc_ok;
59 |
60 | /**
61 | * Received Strength Signal Indication
62 | */
63 | byte rssi;
64 |
65 | /**
66 | * Link Quality Index
67 | */
68 | byte lqi;
69 | } CCPACKET;
70 |
71 | #endif
72 |
73 |
--------------------------------------------------------------------------------
/rfboot/cc1101/keywords.txt:
--------------------------------------------------------------------------------
1 | #######################################
2 | # Syntax Coloring Map panStamp
3 | #######################################
4 |
5 | #######################################
6 | # Datatypes (KEYWORD1)
7 | #######################################
8 | CC1101 KEYWORD1
9 | CCPACKET KEYWORD1
10 | CARRIER_FREQ KEYWORD1
11 | SWPACKET KEYWORD1
12 | ENDPOINT KEYWORD1
13 | PANSTAMP KEYWORD1
14 |
15 | #######################################
16 | # Methods and Functions (KEYWORD2)
17 | #######################################
18 | init KEYWORD2
19 | reset KEYWORD2
20 | wakeUp KEYWORD2
21 | goToSleep KEYWORD2
22 | enterSystemState KEYWORD2
23 | setSyncWord KEYWORD2
24 | setDevAddress KEYWORD2
25 | setCarrierFreq KEYWORD2
26 | setChannel KEYWORD2
27 | setSecurity KEYWORD2
28 | setTxInterval KEYWORD2
29 | setSwapStatusCallBack KEYWORD2
30 | setRxState KEYWORD2
31 | setPowerDownState KEYWORD2
32 | sendData KEYWORD2
33 | receiveData KEYWORD2
34 | disableAddressCheck KEYWORD2
35 | sleepFor KEYWORD2
36 | getData KEYWORD2
37 | setData KEYWORD2
38 | sendSwapStatus KEYWORD2
39 | getRegister KEYWORD2
40 | rcOscCalibrate KEYWORD2
41 |
42 | #######################################
43 | # Atributes (KEYWORD2)
44 | #######################################
45 | carrierFreq KEYWORD2
46 | channel KEYWORD2
47 | syncWord KEYWORD2
48 | devAddress KEYWORD2
49 |
50 | #######################################
51 | # Constants (LITERAL1)
52 | #######################################
53 | CFREQ_868 LITERAL1
54 | CFREQ_915 LITERAL1
55 |
56 |
--------------------------------------------------------------------------------
/rfboot/cc1101/pin_macros.h:
--------------------------------------------------------------------------------
1 | // MACROS FOR EASY PIN HANDLING FOR ATMEL GCC-AVR
2 | //these macros are used indirectly by other macros , mainly for string concatination
3 |
4 | #ifndef PIN_MACROS_H
5 | #include
6 |
7 | #define _SET(type,name,bit) type ## name |= _BV(bit)
8 | #define _CLEAR(type,name,bit) type ## name &= ~ _BV(bit)
9 | #define _TOGGLE(type,name,bit) type ## name ^= _BV(bit)
10 | #define _GET(type,name,bit) ((type ## name >> bit) & 1)
11 | #define _PUT(type,name,bit,value) type ## name = ( type ## name & ( ~ _BV(bit)) ) | ( ( 1 & (unsigned char)value ) << bit )
12 |
13 | //these macros are used by end user
14 | #define OUTPUT(pin) _SET(DDR,pin)
15 | #define INPUT(pin) _CLEAR(DDR,pin)
16 | #define HIGH(pin) _SET(PORT,pin)
17 | #define LOW(pin) _CLEAR(PORT,pin)
18 | #define TOGGLE(pin) _TOGGLE(PORT,pin)
19 | #define READ(pin) _GET(PIN,pin)
20 |
21 | /*
22 | BASIC STAMPS STYLE COMMANDS FOR ATMEL GCC-AVR
23 |
24 | Usage Example:
25 | ———————————————–
26 | #define pinLed B,5 //define pins like this
27 |
28 | OUTPUT(pinLed); //type fixed
29 | //OUTPUT(pinLED); //compiles as DDRB |= (1<<5);
30 | HIGH(pinLed); //compiles as PORTB |= (1<<5);
31 | ———————————————–
32 | */
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/rfboot/cc1101/spi.c:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2011 panStamp
3 | *
4 | * This file is part of the panStamp project.
5 | *
6 | * panStamp is free software; you can redistribute it and/or modify
7 | * it under the terms of the GNU Lesser General Public License as published by
8 | * the Free Software Foundation; either version 3 of the License, or
9 | * any later version.
10 | *
11 | * panStamp is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public License
17 | * along with panStamp; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 | * USA
20 | *
21 | * Author: Daniel Berenguer
22 | * Creation date: 03/03/2011
23 | */
24 |
25 | #include "spi.h"
26 | #include "pin_macros.h"
27 | /**
28 | * init
29 | *
30 | * SPI initialization
31 | */
32 | void spi_init()
33 | {
34 | //digitalWrite(SPI_SS, HIGH);
35 | HIGH(SPI_SS);
36 |
37 | // Configure SPI pins
38 | //pinMode(SPI_SS, OUTPUT);
39 | //pinMode(SPI_MOSI, OUTPUT);
40 | //pinMode(SPI_MISO, INPUT);
41 | //pinMode(SPI_SCK, OUTPUT);
42 | OUTPUT(SPI_SS);
43 | OUTPUT(SPI_MOSI);
44 | INPUT(SPI_MISO);
45 | OUTPUT(SPI_SCK);
46 |
47 | //digitalWrite(SPI_SCK, HIGH);
48 | //digitalWrite(SPI_MOSI, LOW);
49 | HIGH(SPI_SCK);
50 | LOW(SPI_MOSI);
51 |
52 | // SPI speed = clk/4
53 | SPCR = _BV(SPE) | _BV(MSTR);
54 | }
55 |
56 | /**
57 | * send
58 | *
59 | * Send byte via SPI
60 | *
61 | * 'value' Value to be sent
62 | *
63 | * Return:
64 | * Response received from SPI slave
65 | */
66 | byte spi_send(byte value)
67 | {
68 | SPDR = value; // Transfer byte via SPI
69 | wait_Spi(); // Wait until SPI operation is terminated
70 |
71 | return SPDR;
72 | }
73 |
74 |
--------------------------------------------------------------------------------
/rfboot/cc1101/spi.h:
--------------------------------------------------------------------------------
1 | /**
2 | * The code converted from c++ to c in order to use it in the rfboot
3 | *
4 | *
5 | *
6 | **/
7 |
8 | /**
9 | * Copyright (c) 2011 panStamp
10 | *
11 | * This file is part of the panStamp project.
12 | *
13 | * panStamp is free software; you can redistribute it and/or modify
14 | * it under the terms of the GNU Lesser General Public License as published by
15 | * the Free Software Foundation; either version 3 of the License, or
16 | * any later version.
17 | *
18 | * panStamp is distributed in the hope that it will be useful,
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 | * GNU Lesser General Public License for more details.
22 | *
23 | * You should have received a copy of the GNU Lesser General Public License
24 | * along with panStamp; if not, write to the Free Software
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
26 | * USA
27 | *
28 | * Author: Daniel Berenguer
29 | * Creation date: 03/03/2011
30 | */
31 |
32 | #ifndef _SPI_H
33 | #define _SPI_H
34 |
35 | //#include "Arduino.h"
36 | #include
37 | #define byte uint8_t
38 | #include
39 |
40 | /**
41 | * SPI pins
42 | */
43 | //#define SPI_SS 10 // PB2 = SPI_SS
44 | //#define SPI_MOSI 11 // PB3 = MOSI
45 | //#define SPI_MISO 12 // PB4 = MISO
46 | //#define SPI_SCK 13 // PB5 = SCK
47 | //#define GDO0 2 // PD2 = INT0
48 | #define SPI_SS B,2 // PB2 = SPI_SS
49 | #define SPI_MOSI B,3 // PB3 = MOSI
50 | #define SPI_MISO B,4 // PB4 = MISO
51 | #define SPI_SCK B,5 // PB5 = SCK
52 | #define GDO0 D,2 // PD2 = INT0
53 |
54 | #define PORT_SPI_MISO PINB
55 | #define BIT_SPI_MISO 4
56 |
57 | #define PORT_SPI_SS PORTB
58 | #define BIT_SPI_SS 2
59 |
60 | #define PORT_GDO0 PIND
61 | #define BIT_GDO0 2
62 |
63 | /**
64 | * Macros
65 | */
66 | // Wait until SPI operation is terminated
67 | #define wait_Spi() while(!(SPSR & _BV(SPIF)))
68 |
69 | /**
70 | * Class: SPI
71 | *
72 | * Description:
73 | * Basic SPI class
74 | */
75 | //class SPI
76 | //{
77 | // public:
78 | /**
79 | * init
80 | *
81 | * SPI initialization
82 | */
83 | void spi_init();
84 |
85 | /**
86 | * send
87 | *
88 | * Send byte via SPI
89 | *
90 | * 'value' Value to be sent
91 | *
92 | * Return:
93 | * Response received from SPI slave
94 | */
95 | byte spi_send(byte value);
96 | //};
97 | #endif
98 |
--------------------------------------------------------------------------------
/rfboot/hardware_settings.mk:
--------------------------------------------------------------------------------
1 | # Uncomment to enable external crystal.
2 | # If you uncomment this setting you MUST include a crystal in your project.
3 | # Default is internal oscillator @ 8Mhz
4 | # Only "1" is accepted as true
5 | #CRYSTAL = 1
6 |
7 | # The default MCU clock rate is 8MHz
8 | # WARNING: Change this if you are using external crystal
9 | # with the apropriate freequency
10 | #F_CPU = 8000000L
11 |
12 | # only if CRYSTAL above is NOT set.
13 | # Uncomment to enable automatic calibration of the
14 | # internal RC oscillator (only 8Mhz without clock divider)
15 | # https://github.com/pkarsy/rcCalibrator
16 | # If this is enabled, rfboot will set the OSCCAL register, so application
17 | # will have CPU clock close to 8Mhz. The OSCCAL value will be
18 | # compiled in the rfboot code, so no worries about reserved EEPROM locations.
19 | # If the executable is in the PATH, "osccal" is enough.
20 | # To be extra sure, check if the compilation emits the message :
21 | # #pragma message "NOTICE: rfboot will set OSCCAL value"
22 | #RC_CALIBRATOR = osccal
23 |
24 | # Uncomment to set usbtiny as ISP programmer
25 | # Default is USBasp.
26 | # usbasp and usbtiny are supported.
27 | # "usbtiny" is in lower case
28 | #PROGRAMMER = usbtiny
29 |
--------------------------------------------------------------------------------
/rfboot/rfboot.c:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * 2015 (C) Panagiotis Karagiannis
4 | * This software is distributed with the GPLv3+ Licence
5 | *
6 | * rfboot wireless bootloader for atmega328p with the TI cc1101 chip
7 | * https://github.com/pkarsy/rfboot
8 | *
9 | * this file implements the bootloader part of rfboot
10 | *
11 | * It is not based on optiboot or other bootloasers but is
12 | * written from scrach.
13 | * Configurable settings can only be changed at compile time.
14 | * Cannot be used to send code with serial port. In fact does not even touch the Rx Tx pins wich can be used
15 | * for other purposes (as GPIO pins) or to connect to another serial device (GPS for example)
16 | *
17 | * if the mcu resets/powers up with rfboot will wait for code upload for about 0.25 sec.
18 | *
19 | * rfboot cannot initialize a reset by itself. The duty for this is in the application.
20 | *
21 | * WARNING if you burn this bootloader to a ProMini 3.3V for example, you will not be able to program it over serial any more. Only via cc1101 module.
22 | *
23 | * rfboot is designed to be used on bare atmega328p chips. Of course you can still develop Arduino applications, a bootloader is code agnostic.
24 | * The hardware for rfboot is typically an atmega328p 8Mhz@3.3V
25 | * because CC1101 chip does not tolerate 5V on any pin and atmega328
26 | * DOES NOT RUN at 16Mh @ 3.3V
27 | *
28 | * not compatible unfortunately with avrdude. rfboot uses "rftool" instead of avrdude.
29 | * Encrypts the packets on the air see
30 | * https://github.com/pkarsy/rfboot/blob/master/help/Encryption.md
31 | *
32 | * TODO cc1101 reset before app start
33 | * TODO if cc1101 is not detected proceed immediatelly to application code
34 | * */
35 |
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 |
44 | #include
45 | #include
46 | #include
47 |
48 | #include "xtea.h"
49 |
50 |
51 | #define byte uint8_t
52 |
53 |
54 | // Parameters that are different in every rfboot project
55 | // RF Channel , Syncword , XTEA key
56 | // The file is generated by "rftool create ProjName"
57 | #include "rfboot_settings.h"
58 |
59 |
60 | // CC1101 has 64 bytes buffer but we restrict it to 32 bytes. If the reception is not ideal
61 | // long packets have greater probability to be corrupted
62 | #define PAYLOAD 32
63 |
64 | // this is a random enough number contained in the first packet.
65 | // the programmer sends it and rfboot requires this number to be
66 | // in the start of the header in order to continue. This protects
67 | // the bootloader from using any random packet, if happens
68 | // to be in the air, as a header
69 | // Compatibility reasons, require this number not to be changed
70 | // It is crucial that rfboot and rftool (the flasher) agree
71 | #define START_SIGNATURE 0xd20f6cdf
72 |
73 | // The XTEA cipher uses blocks of 8 bytes
74 | #define XTEA_BLOCK_SIZE 8
75 |
76 | // rfboot is designed to be a little smaller than this size
77 | // AVR FUSES for this bootloader size are set from Makefile
78 | #define BOOTLOADER_SECTION_SIZE 4096
79 |
80 | // this is the structure of the first packet and contains the header.
81 | // Total is 11 bytes. the other 21 bytes are unused.
82 | // TODO require the 21 bytes to be 0
83 | struct start_packet {
84 | uint32_t start_signature1;
85 | uint16_t app_size;
86 | uint16_t app_crc;
87 | uint16_t app_crc2;
88 | uint16_t counter;
89 | uint32_t start_signature2;
90 | };
91 |
92 | struct flash_info_struct {
93 | //uint16_t signature;
94 | uint16_t app_size;
95 | uint16_t app_crc;
96 | uint16_t app_crc2;
97 | uint16_t counter;
98 | } data;
99 |
100 | byte last_page_buf[SPM_PAGESIZE];
101 | //memcpy_P( last_page_buf, FLASHEND+1-sizeof(last_page_buf), SPM_PAGESIZE );
102 | const uint16_t BOOTLOADER_ADDR = FLASHEND-BOOTLOADER_SECTION_SIZE+1;
103 |
104 | const uint16_t DATA_PAGE = FLASHEND - BOOTLOADER_SECTION_SIZE +1 - SPM_PAGESIZE;
105 |
106 | //const last_page_addr = FLASHEND-BOOTLOADER_SECTION_SIZE+1-SPM_PAGESIZE;
107 | //struct flash_info_struct *flash_info=FLASHEND+1-sizeof(struct flash_info_struct);
108 |
109 |
110 |
111 | // This is the status codes rfboot is sending back to the programmer
112 | const uint8_t RFB_NO_SIGNATURE = 1;
113 | const uint8_t RFB_INVALID_CODE_SIZE = 2;
114 | //
115 | const uint8_t RFB_IDENTICAL_CODE = 3;
116 | const uint8_t RFB_SEND_PKT = 4;
117 | const uint8_t RFB_WRONG_CRC=5;
118 | const uint8_t RFB_SUCCESS=6;
119 |
120 | // rfboot approach to start the application code is to trigger a Watchdog Reset
121 | // and after this the application
122 | // code starts. With this mechanism we can be sure that the state of the MCU is correct
123 | // This is also the method optiboot uses.
124 | // However unlike optiboot, rfboot must know who is triggered the watchdog reset.
125 | // If triggered from the app rfboot must wait for firmware update.
126 | // If triggered from rfboot itself then the application code should start
127 |
128 | // The solution is to use a uninitialized global variable
129 | // (witch basically means a specific location in the atmega RAM)
130 | // the contents of which will inform rfboot who is triggered the reset.
131 |
132 | // if this (".noinit" on purpose) variable has the value RESET_BY_RFBOOT
133 | // rfboot knows that ITSELF triggered a wdog reset with
134 | // the intention to start the application and not load itself again.
135 | // memory is preserved across resets so apart from EEPROM (witch
136 | // we want to use as little as possible) is the only way to send info from one instance
137 | // of rfboot to the next (after a reset)
138 | // this variable cannot be declared register !!!
139 | const uint32_t RESET_BY_RFBOOT=0xd8317bc2;
140 | volatile uint32_t reset_origin __attribute__ ((section (".noinit")));
141 |
142 | // the next variable is also preserved between 2 continuous rfboot executions
143 | // It is used to report correct reset causes EXTRF WDRF OWR BROWNOUT to the app
144 | // (via the "r2" register) like optiboot
145 | // Technically a watchdog reset is triggered from rfboot itself
146 | // before the app starts. But we don't of course want to report this to the
147 | // application code.
148 | volatile uint8_t previous_reset_cause __attribute__ ((section (".noinit")));
149 |
150 | // if we don't want "mcusr_mirror" to be a register then we MUST put a line
151 | // __asm__ __volatile__ ("mov r2, %0\n" :: "r" (mcusr_mirror));
152 | // inside function reset_mcu();
153 | // right before jmp
154 | register uint8_t mcusr_mirror asm("r2") __attribute__ ((section (".noinit")));
155 |
156 | // recommended code from avr-libc documentation
157 | // MCUSR manipulation is very tricky so better leave it as is
158 | void get_mcusr(void) __attribute__((naked)) __attribute__((section(".init3")));
159 | void get_mcusr(void) {
160 | mcusr_mirror = MCUSR;
161 | MCUSR = 0;
162 | }
163 |
164 | //#ifdef USE_ENTROPY
165 | // #include "entropy.h"
166 | //#endif
167 |
168 | #include "cc1101.h"
169 |
170 | // a flag that a wireless packet has been received
171 |
172 | register bool data_ready asm("r3") __attribute__ ((section (".noinit")));
173 |
174 | // in this packet we store data coming from RF
175 | CCPACKET ccpacket __attribute__ ((section (".noinit")));
176 | uint8_t* packet = ccpacket.data;
177 |
178 | // Generated by CC1101 when receives SyncWord (or sends a packet)
179 | ISR (INT0_vect)
180 | {
181 | /* interrupt code here */
182 | data_ready = true;
183 | }
184 |
185 | #define get_data() cc1101_receiveData(&ccpacket)
186 |
187 | void radio_init(void) {
188 | cc1101_init();
189 | // default is 433Mhz
190 | cc1101_setChannel(RFBOOT_CHANNEL);
191 | cc1101_setSyncWord(RFBOOT_SYNCWORD[0],RFBOOT_SYNCWORD[1]);
192 | disableAddressCheck();
193 | get_data();
194 |
195 | ATOMIC_BLOCK(ATOMIC_FORCEON) {
196 | EICRA |= (1 << ISC01); // set INT0 to trigger on falling edge
197 | EIMSK |= (1 << INT0); // Turns on INT0
198 | }
199 |
200 | __asm__("nop\n\t");
201 | __asm__("nop\n\t");
202 | data_ready = false;
203 |
204 | }
205 |
206 | // This is used to send packets. Probably no need for separate
207 | // in and out packets
208 | // TODO low priority
209 | CCPACKET outpkt;
210 | void send_pkt(uint8_t msg, uint16_t data) {
211 |
212 | outpkt.length=3;
213 | outpkt.data[0]= msg ;
214 | outpkt.data[1]= data & 0xff ;
215 | outpkt.data[2]= data >> 8 ;
216 | cc1101_sendData(outpkt);
217 | while (! data_ready);
218 | data_ready = false;
219 | }
220 |
221 | void send_iv(const uint32_t* iv) {
222 | outpkt.length=8;
223 | memcpy(outpkt.data,(byte*)iv,8);
224 | cc1101_sendData(outpkt);
225 | while (! data_ready);
226 | data_ready = false;
227 | }
228 |
229 | // Never returns, so "naked" and "noreturn" attributes don't hurt and reduce
230 | // code size
231 | void reset_mcu() __attribute__ ((naked)) __attribute__ ((__noreturn__));
232 | void reset_mcu() {
233 |
234 | // rfboot will boot in a while
235 | // without remembering anything
236 | // But reset_origin variable will
237 | // contain the magic value RESET_BY_RFBOOT
238 | // so rfboot will know it is time to start the app
239 | reset_origin = RESET_BY_RFBOOT;
240 |
241 | // We save mcusr_mirror. after 15ms rfboot will put this value
242 | // to the r2 register before it gives control to the application
243 | previous_reset_cause = mcusr_mirror;
244 |
245 | // we enable watchdog at 15ms
246 | wdt_enable(WDTO_15MS);
247 | // we stay here until watchdog resets MCU
248 | while(1);
249 | }
250 |
251 | // we did it a function as we call the same thing a lot of times
252 | void page_erase(uint16_t page) {
253 | ATOMIC_BLOCK(ATOMIC_FORCEON) {
254 | boot_spm_busy_wait();
255 | boot_page_erase(page);
256 | }
257 | }
258 |
259 | // the same
260 | void flash_read_enable() {
261 | ATOMIC_BLOCK(ATOMIC_FORCEON) {
262 | boot_spm_busy_wait();
263 | boot_rww_enable();
264 | }
265 | }
266 |
267 | int main(void) {
268 | // rfboot does always enables a 2 sec Watchdog timer.
269 | // The application at normal operation will
270 | // have the duty to reset the WDOG timer periodically, witch is a good
271 | // practice anyway.
272 | wdt_enable(WDTO_2S);
273 |
274 | // Set the freequency close to 8Mhz using the OsccalCalibrator
275 | // You need the OsccalCalibrator and to enable the setting from
276 | // hardware_settings.mk
277 | #ifdef OPTIMAL_OSCCAL_VALUE
278 | //#warning "####################################################"
279 | //#error "Hard coding OSCCAL=" CALIBRATED_OSCCAL_VALUE
280 | #pragma message "NOTICE: rfboot will set OSCCAL value"
281 | OSCCAL = OPTIMAL_OSCCAL_VALUE;
282 | //#warning "####################################################"
283 | #endif
284 |
285 | // Disable interrupts.
286 | cli();
287 |
288 | memcpy_P( &data, DATA_PAGE, sizeof(data) );
289 |
290 | /*
291 | // Only HW reset allowed (from settings)
292 | // This means in effect, that programming needs physical contact.
293 | // unless you wired RST to some GPIO pin.
294 | #ifdef UPLOAD_AT_HW_RESET_ONLY
295 |
296 | if ( mcusr_mirror & _BV(EXTRF) ) {
297 | // We load rfboot
298 | }
299 | else {
300 | if (pgm_read_word(0) == 0xffff) { // Flash has no application. See explanation below
301 | // We can't do anything. We just hang
302 | while(1) ;
303 | }
304 | else { // Reset cause was no HW reset, and flash seems to have application written
305 |
306 | // Althrough XTEA_KEY is read only, the RAM can be written
307 | // We erase XTEA_KEY
308 | memset((void*)XTEA_KEY,0,sizeof(XTEA_KEY));
309 |
310 | // Jump to the application
311 | asm("jmp 0");
312 | }
313 | }
314 |
315 | #else // Default mode, watchdog reset (and any other) loads rfboot
316 | */
317 |
318 | // if the first 2 bytes of flash are 0xff, rfboot consider the flash
319 | // empty and stays waiting for code indefinitely
320 | // I searched the Internet and as I understand it, there is no
321 | // 0xffff AVR documented opcode at least for atmega328. So there is no
322 | // possibility an application will start with 0xffff by chance.
323 |
324 | if ( (pgm_read_word(0) != 0xffff) && (mcusr_mirror & _BV(WDRF) ) && (reset_origin == RESET_BY_RFBOOT) )
325 | {
326 | ///////////////////////////////////
327 | // - We have an installed application as the first word differs from 0xffff
328 | // - We have watchdog reset
329 | // - reset_origin variable says that the reset triggered by the bootloader itself
330 | // As a consequence : It is time to start the application code
331 | ///////////////////////////////////
332 |
333 | // it is absolutely necessary to alter the reset_origin variable to something different
334 | // than RESET_BY_RFBOOT because there is a very high
335 | // probability that the app will not overwrite the memory
336 | // region referring to this variable. If the application
337 | // triggers a WDOG reset, rfboot will find that
338 | // reset_origin == RESET_BY_RFBOOT and believing it itself
339 | // is the cause of the reset will jump directly to the application,
340 | // causing firmware updates to fail (when triggered from the application)
341 | reset_origin = 0;
342 |
343 | // mcusr_mirror is the register "r2" which can be used by the
344 | // application to examine the cause of the reset. We set "r2" to
345 | // be the reset cause of the previous reset, otherwise the application
346 | // will see as reset cause always WDOG
347 | mcusr_mirror = previous_reset_cause;
348 |
349 | // Althrough XTEA_KEY is read only, the RAM can be written
350 | // As atmega does not enforce any RAM protection. Maybe on other
351 | // cpu/mcu this command fails.
352 | // We erase XTEA_KEY
353 | memset((void*)XTEA_KEY,0,sizeof(XTEA_KEY));
354 |
355 | // finally we start the application
356 | // note that we come from a WDOG reset
357 | // so the MCU registers I/O etc are in pristine state
358 | // The app has responsibility of initialize the rf module
359 | // the application must reset the watchdog every 2 secs at least
360 | // or to change watchdog settings
361 | asm("jmp 0");
362 | }
363 | //#endif
364 |
365 | // TODO comment
366 | reset_origin = RESET_BY_RFBOOT;
367 |
368 | ////////////////////////////////////////////////
369 | // rfboot bootloader needs interrupts for
370 | // use with CC1101 (GDO0 is interrupt)
371 | //
372 | // Enable change of interrupt vectors
373 | // Without this "unlock next command" instruction, next command will have no effect
374 | MCUCR = (1<start_signature1 == START_SIGNATURE) && (spacket->start_signature2 == START_SIGNATURE) ) {
452 | // sig1 and sig2 OK
453 | }
454 | else {
455 | // We were unable to find the signature so we give up.
456 | // Probably the programmer used encryption with the wrong key or IV
457 | send_pkt(RFB_NO_SIGNATURE,0xffff);
458 | reset_mcu();
459 | }
460 |
461 | // We store here the size of the incoming application
462 | // this info is in the first packet
463 | // now using spacket pointer we extract info from the packet
464 | uint16_t app_size = spacket->app_size;
465 |
466 | // Here some basic checks for a valid app size.
467 | // app_size is always a multiple
468 | // of PAYLOAD. Trailing bytes are padded with 0xff
469 | // This is ensured by the programmer (rftool+usb2rf)
470 | if ( (app_size > DATA_PAGE ) ||
471 | (app_size%PAYLOAD!=0) || (app_size==0) )
472 | {
473 | send_pkt(RFB_INVALID_CODE_SIZE,0xffff);
474 | reset_mcu();
475 | }
476 |
477 | // remote programmer sends 2 CRCs (16bit each)
478 | // witch rfboot uses after the flash, to check if the code is OK.
479 |
480 | // this is the CRC16 of the application's opcode
481 | uint16_t remote_crc = spacket->app_crc;
482 |
483 | // this is the CRC16 calculated with the bytes in reverse order
484 | // again this is probably an overkill but it is too
485 | // simple to implement and offers many orders of magnitude
486 | // better error detection
487 | uint16_t remote_crc2 = spacket->app_crc2;
488 |
489 | // This variable will point to the flash location to be written
490 | uint16_t app_idx=app_size;
491 |
492 |
493 | data.app_crc = spacket->app_crc;
494 | data.app_crc2 = spacket->app_crc2;
495 | data.app_size = spacket->app_size;
496 | //data.counter++;
497 |
498 | // Here we send the request for the first packet
499 | // the packets are transmitted and received in reverse order
500 | // from the last 32 byte packet to the first
501 | send_pkt(RFB_SEND_PKT, app_idx);
502 |
503 | //#ifndef USE_ENTROPY
504 | // eeprom_update_word(E2END-1, counter);
505 | // eeprom_busy_wait();
506 | //#endif
507 |
508 | // Time to write the info
509 | page_erase(DATA_PAGE);
510 | ATOMIC_BLOCK(ATOMIC_FORCEON) {
511 | boot_spm_busy_wait();
512 | uint16_t *j=&data;
513 | uint16_t flash_idx = DATA_PAGE;
514 | do {
515 | boot_page_fill(flash_idx, *j);
516 | flash_idx+=2;
517 | j++;
518 | } while( flash_idx< DATA_PAGE+sizeof(data) );
519 | boot_spm_busy_wait();
520 | boot_page_write(DATA_PAGE);
521 | }
522 |
523 | // Before any write, we erase the first SPM page. If for some reason
524 | // the upload process fails, the first page will contain
525 | // 0xff and rfboot will refuse to start the corrupted code.
526 | // see the start of main() how this is implemented
527 | page_erase(0);
528 |
529 | // one loop per SPM page (in reverse order). rftool sends the last bytes of code first
530 | do
531 | {
532 | wdt_reset();
533 | // if i.e. app_idx == 256 we are going to burn the flash from 128-255
534 | // if app_idx == 128 we are going to burn the flash from 0-127 etc
535 | // We erase this SPM page unless it is the 0-127 page
536 | // which is erased before this loop starts
537 | if (app_idx>SPM_PAGESIZE) { // this means _not_ the first page
538 | uint16_t spm_page=(app_idx-1)/SPM_PAGESIZE*SPM_PAGESIZE;
539 | page_erase(spm_page);
540 | }
541 | // one loop per network packet 32 bytes == 4 xtea blocks
542 | do
543 | {
544 | { // we send a request and expect a data packet
545 | uint16_t i=40*10-1;
546 |
547 | while (true) {
548 | // every 20ms we send a request
549 | if ( (i%40)==0) send_pkt(RFB_SEND_PKT, app_idx);
550 |
551 | if (data_ready) {
552 | data_ready = false;
553 | if ( (get_data()==PAYLOAD) && ccpacket.crc_ok) {
554 | break;
555 | }
556 | else i=40*10+1;
557 | wdt_reset();
558 | }
559 | i--;
560 | if (i==0) reset_mcu();
561 | _delay_us(500);
562 | }
563 | }
564 |
565 | // We send a request for the next packet (unless this was the last one)
566 | // before even consume this
567 | // one. This is for efficiency. The answer will take some time
568 | // to arrive, so is better to do some work in the meantime
569 | if (app_idx-PAYLOAD>0) send_pkt(RFB_SEND_PKT, app_idx-PAYLOAD);
570 |
571 | // We decrypt the packet. 4 XTEA blocks
572 | for (uint8_t i=0; i<=3; i++) {
573 | xtea_decipher_cbc( (uint32_t*)(packet+i*XTEA_BLOCK_SIZE) , XTEA_KEY ,iv );
574 | }
575 | // at this point the packet is in cleartext
576 |
577 | // next thing is to wtite it in flash
578 | // the following code is basically what avr-gcc documentation
579 | // suggests, it just doing it from high addresses to low.
580 | ATOMIC_BLOCK(ATOMIC_FORCEON) {
581 | boot_spm_busy_wait();
582 | uint8_t j=PAYLOAD;
583 | do {
584 | app_idx-=2;
585 | j-=2;
586 | boot_page_fill(app_idx, *(uint16_t*)(packet+j));
587 | } while(j);
588 | }
589 |
590 | // we repeat the above 4 times until an SPM (128 bytes) page fills
591 | } while (app_idx%SPM_PAGESIZE);
592 | //
593 | // Now we filled a full SPM page we have to burn it in flash
594 | //
595 | ATOMIC_BLOCK(ATOMIC_FORCEON) {
596 | boot_spm_busy_wait();
597 | boot_page_write(app_idx);
598 | }
599 | // We repeat writing SPM pages
600 | // if app_idx becomes 0 we have just written the SPM page 0-127
601 | // and the whole application is written to the flash
602 | } while (app_idx);
603 |
604 | // We got all RF packets
605 | // the upload process is finished
606 |
607 | // Now we are going to check if the CRC's of the written code are the same as
608 | // the CRC's sent from rftool. So we need to enable flash read
609 | flash_read_enable();
610 |
611 | // the crc's are initialized with zero (from avr-libc documentation)
612 | uint16_t local_crc=0;
613 | uint16_t local_crc2=0;
614 | for (uint16_t i = 0; i < app_size ; i++) {
615 |
616 | // the first crc calculated reading the flash from start to end.
617 | local_crc = _crc16_update(local_crc,pgm_read_byte(i));
618 |
619 | // the second crc is calculated reading the flash from end to start
620 | // The 2 crc's according to my (non scientific) tests seem independent
621 | // offering an effective 32bit CRC
622 | // so offer a ~100% probability that flash is correctly
623 | // written. I am including a C program to test my hypothesis. If anyone has a
624 | // formal mathematical proof, I am very interested to know so
625 | // send me a note to include a link here.
626 | // Note also that the use of 2 CRC16 is
627 | // probably an overkill but it costs only 40-50 bytes in flash
628 | // and minimal MCU time.
629 | local_crc2 = _crc16_update(local_crc2,pgm_read_byte(app_size-1-i));
630 | // Note: I tried a CRC32 once, but bloated the code badly
631 | }
632 |
633 | // Now both crc's are calculated, we do the test
634 |
635 | if ( (remote_crc != local_crc) || (remote_crc2 != local_crc2) ) {
636 | // if the crc's dont match, we erase the first SPM page again, so rfboot wont try
637 | // to start a corrupted code. Note that this should be rare, since
638 | // the network packets are already protected with CRC.
639 | page_erase(0);
640 | send_pkt(RFB_WRONG_CRC,0);
641 |
642 | //I am not sure if this is needed but it doesn't hurt either
643 | flash_read_enable();
644 | }
645 | else {
646 | // Success !
647 | send_pkt(RFB_SUCCESS,0);
648 | }
649 |
650 | // Reset MCU. If flash is correctly written the application can start, not
651 | // directly but by using a Watchdog reset. This ensures
652 | // that the loaded app will see I/O pins etc are in their default state
653 | //
654 | // Of course , if the process fails, which at
655 | // this point means the crc check failed, rfboot
656 | // will wait indefinitelly for new code
657 | reset_mcu();
658 | }
659 |
--------------------------------------------------------------------------------
/rfboot/xtea/README.md:
--------------------------------------------------------------------------------
1 | The **xtea_encipher** and **xtea_decipher** are copied from the [XTEA wikipedia article](https://en.wikipedia.org/wiki/XTEA)
2 | and they are in the Public Domain.
3 | **xtea_encipher_cbc** and **xtea_decipher_cbc** are writen by me and due the their simplicity I put them also in the Public Domain
4 |
--------------------------------------------------------------------------------
/rfboot/xtea/xtea.c:
--------------------------------------------------------------------------------
1 | #ifndef XTEA_H
2 | #define XTEA_H
3 |
4 |
5 | #include
6 | #include "xtea.h"
7 |
8 |
9 | void xtea_encipher( uint32_t v[2], const uint32_t key[4] ) {
10 | static const uint8_t num_rounds=32;
11 | uint32_t v0=v[0], v1=v[1], sum=0, delta=0x9E3779B9;
12 | uint8_t i;
13 | for (i=0; i < num_rounds; i++) {
14 | v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]);
15 | sum += delta;
16 | v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]);
17 | }
18 | v[0]=v0; v[1]=v1;
19 | }
20 |
21 | void xtea_encipher_cbc( uint32_t v[2], const uint32_t key[4], uint32_t iv[2] ) {
22 | v[0] ^= iv[0];
23 | v[1] ^= iv[1];
24 | xtea_encipher(v,key);
25 | iv[0]=v[0];
26 | iv[1]=v[1];
27 | }
28 |
29 | void xtea_decipher( uint32_t v[2], const uint32_t key[4] ) {
30 | static const uint8_t num_rounds=32;
31 | uint32_t v0=v[0], v1=v[1], delta=0x9E3779B9, sum=delta*num_rounds;
32 | uint8_t i;
33 | for (i=0; i < num_rounds; i++) {
34 | v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]);
35 | sum -= delta;
36 | v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]);
37 | }
38 | v[0]=v0; v[1]=v1;
39 | }
40 |
41 |
42 | void xtea_decipher_cbc( uint32_t v[2], const uint32_t key[4], uint32_t iv[2] ) {
43 | uint32_t c0=v[0];
44 | uint32_t c1=v[1];
45 | xtea_decipher(v,key);
46 | v[0] ^= iv[0];
47 | v[1] ^= iv[1];
48 | iv[0]=c0;
49 | iv[1]=c1;
50 | }
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/rfboot/xtea/xtea.h:
--------------------------------------------------------------------------------
1 | #ifndef XTEA_H
2 | #define XTEA_H
3 |
4 |
5 | #include
6 |
7 | void xtea_encipher(uint32_t v[2], const uint32_t key[4] ) ;
8 | void xtea_encipher_cbc( uint32_t v[2], const uint32_t key[4], uint32_t iv[2] );
9 | void xtea_decipher( uint32_t v[2], const uint32_t key[4] );
10 | void xtea_decipher_cbc( uint32_t v[2], const uint32_t key[4], uint32_t iv[2] );
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/rftool/Makefile:
--------------------------------------------------------------------------------
1 | #NIM := $(shell which nim)
2 |
3 | #ifeq ($(NIM),)
4 | #@$(error No "nim" compiler found. Install it from https://nim-lang.org )
5 | #endif
6 |
7 | help:
8 | @echo "Targets are:"
9 | @echo
10 | @echo "make bin # Creates a rftool binary of the current architecture. requires nim-lang: https://nim-lang.org"
11 | @echo
12 | @echo "make musl # Creates a statically linked binary, requires nim-lang and musl-dev"
13 | @echo
14 | @echo "make clean"
15 | @echo
16 | @echo "make vagga # Creates a i386 container with all dependencies and generates a i386 static rftool binary. Requires vagga and some disk space (1.4G last checked), but the process is fully automatic. The advandage of this binary is that it is running on EVERY i386 or amd64 linux box"
17 | @echo
18 |
19 | bin:
20 | rm -f rftool
21 | nim c -d:release --opt:size -x:on rftool.nim
22 | strip rftool
23 | ls -l rftool
24 |
25 | musl:
26 | nim -d:release --opt:size -x:on --passL:-static --gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc c rftool
27 | strip rftool
28 | ls -l rftool
29 |
30 | vagga:
31 | if [ ! -d serial.nim ]; then git clone https://github.com/euantorano/serial.nim.git --branch v1.1.0 ; fi
32 | vagga nim --path:./serial.nim/src -d:release --opt:size -x:on --passL:-static --gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc c rftool
33 | strip rftool
34 | ls -l rftool
35 |
36 | clean:
37 | rm -rf nimcache rftool
38 |
--------------------------------------------------------------------------------
/rftool/README.md:
--------------------------------------------------------------------------------
1 | ### rftool
2 |
3 | This is the tool to be used instead of avrdude when uploading code.
4 | It has also the duty to create new projects.
5 | It is writen in the excellent nim programming language
https://nim-lang.org/
6 | To compile the code type "make help" or just "make" to see the available options.
7 | A precompiled, statically linked x86_64 binary is provided, if you do not want to compile the code.
8 |
--------------------------------------------------------------------------------
/rftool/rftool:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pkarsy/rfboot/479c2bde7dda42a6d2efc1c06f510441e89a511c/rftool/rftool
--------------------------------------------------------------------------------
/rftool/vagga.yaml:
--------------------------------------------------------------------------------
1 | containers:
2 | c:
3 | setup:
4 | - !UbuntuRelease { codename: bionic, arch: i386 }
5 | - !UbuntuUniverse
6 | - !Install [build-essential,musl,musl-dev,musl-tools]
7 | nim:
8 | setup:
9 | - !Container c
10 | - !BuildDeps [git, ca-certificates]
11 | - !Env NIM: /opt/nim
12 | - !Sh |
13 | git clone https://github.com/nim-lang/Nim.git $NIM
14 | cd $NIM
15 | git checkout v0.18.0
16 | git clone --depth 1 https://github.com/nim-lang/csources
17 | cd csources
18 | sh build.sh --cpu i386
19 | cd ..
20 | bin/nim c koch
21 | ./koch boot -d:release -d:useGnuReadline
22 | ./koch tools
23 | environ:
24 | PATH: "/opt/nim/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
25 | commands:
26 | nim: !Command
27 | container: nim
28 | run: [nim]
29 | description: Runs Nim compiler
30 | nimble: !Command
31 | container: nim
32 | run: [nimble]
33 | description: Runs Nimble package manager
34 | sh: !Command
35 | container: nim
36 | run: bash
37 | description: Enter a shell with Nim and Nimble available
38 |
--------------------------------------------------------------------------------
/rftool/xtea.c:
--------------------------------------------------------------------------------
1 | #ifndef XTEA_H
2 | #define XTEA_H
3 |
4 |
5 | #include
6 | #include "xtea.h"
7 |
8 |
9 | void xtea_encipher( uint32_t v[2], const uint32_t key[4] ) {
10 | static const uint8_t num_rounds=32;
11 | uint32_t v0=v[0], v1=v[1], sum=0, delta=0x9E3779B9;
12 | uint8_t i;
13 | for (i=0; i < num_rounds; i++) {
14 | v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]);
15 | sum += delta;
16 | v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]);
17 | }
18 | v[0]=v0; v[1]=v1;
19 | }
20 |
21 | void xtea_encipher_cbc( uint32_t v[2], const uint32_t key[4], uint32_t iv[2] ) {
22 | v[0] ^= iv[0];
23 | v[1] ^= iv[1];
24 | xtea_encipher(v,key);
25 | iv[0]=v[0];
26 | iv[1]=v[1];
27 | }
28 |
29 | void xtea_decipher( uint32_t v[2], const uint32_t key[4] ) {
30 | static const uint8_t num_rounds=32;
31 | uint32_t v0=v[0], v1=v[1], delta=0x9E3779B9, sum=delta*num_rounds;
32 | uint8_t i;
33 | for (i=0; i < num_rounds; i++) {
34 | v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum>>11) & 3]);
35 | sum -= delta;
36 | v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]);
37 | }
38 | v[0]=v0; v[1]=v1;
39 | }
40 |
41 |
42 | void xtea_decipher_cbc( uint32_t v[2], const uint32_t key[4], uint32_t iv[2] ) {
43 | uint32_t c0=v[0];
44 | uint32_t c1=v[1];
45 | xtea_decipher(v,key);
46 | v[0] ^= iv[0];
47 | v[1] ^= iv[1];
48 | iv[0]=c0;
49 | iv[1]=c1;
50 | }
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/rftool/xtea.h:
--------------------------------------------------------------------------------
1 | #ifndef XTEA_H
2 | #define XTEA_H
3 |
4 |
5 | #include
6 |
7 | void xtea_encipher(uint32_t v[2], const uint32_t key[4] ) ;
8 | void xtea_encipher_cbc( uint32_t v[2], const uint32_t key[4], uint32_t iv[2] );
9 | void xtea_decipher( uint32_t v[2], const uint32_t key[4] );
10 | void xtea_decipher_cbc( uint32_t v[2], const uint32_t key[4], uint32_t iv[2] );
11 |
12 | #endif
13 |
--------------------------------------------------------------------------------
/skel/Makefile:
--------------------------------------------------------------------------------
1 | # This Makefile uses the arduino-makefile
2 | # In order to use another AVR build system you must take the necessary changes
3 | # for the build to work
4 |
5 | # probably the project is NOT based on a promini, but the following
6 | # setting keep the build system happy.
7 | # for 8MHz projects choose pro328, even if the board is not o pro mini 3.3V
8 | # for 16MHZ choose pro5v328.
9 | BOARD_TAG = pro328
10 |
11 | # It is ok, unless the enums are larger than 256 items
12 | EXTRA_FLAGS += -fshort-enums
13 |
14 | # We use arduino-makefile to compile the project
15 | include /usr/share/arduino/Arduino.mk
16 |
17 | send: all
18 | @# "rftool send" tries to reset the remote module by sending a reset string first
19 | @# The application code must support this however, otherwise you have to
20 | @# manually reset the module
21 | rftool send $(TARGET_ELF)
22 |
23 | terminal:
24 | @# rftool will append the actual serial port after "-p"
25 | rftool terminal gtkterm -s 38400 -p
26 |
27 | isp:
28 | @# This command writes the bootloader to the MCU
29 | make -C rfboot isp
30 |
31 |
--------------------------------------------------------------------------------
/skel/skel.ino:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of rfboot
3 | https://github.com/pkarsy/rfboot
4 | and it is given to the Public Domain. This means you can do
5 | anything with it, including removing this notice.
6 | */
7 |
8 | #include
9 | #include "app_settings.h"
10 | #include
11 | mCC1101 rf;
12 |
13 | // These macros enables us to "print" messages via the RF
14 | // link. They use the rf.print(..) which is implemented in mCC1101.cpp
15 | #define PRINT(format, ...) rf.print( F(format), ##__VA_ARGS__)
16 | #define PRINTLN(format, ...) rf.print( F(format "\r\n"), ##__VA_ARGS__)
17 |
18 | // Interrupt from CC1101 gdo0 on PIN2(INT0)
19 | void cc1101_interrupt(void) {
20 | // Becomes true when a packet is received
21 | // or after a packet is transmitted
22 | // "interrupt" variable is implemented inside mCC1101 class
23 | // getPacket and sendPacket can manipulate it if necessary
24 | rf.interrupt = true;
25 | }
26 |
27 | void setup() {
28 | // rfboot enables watchdog (2 sec timeout) automatically
29 | // we can disable it with wdt_disable(); but is not recommended
30 | // as a misbehaving code will lock the module and we will no be
31 | // able to resend code remotely, ie without resetting the module
32 |
33 | // Althrough not needed by rfboot itself, almost all rfboot projects
34 | // also use the CC1101 module for connectivity witho othe modules/PC
35 | rf.init();
36 | // CFREQ_433 is the default with mCC1101
37 | // note that this is different than PanStamp library
38 | // rf.setCarrierFreq(CFREQ_433);
39 | // APP_CHANNEL and APP_SYNCWORD are defined in "app_settings.h"
40 | // and generated randomly by "rftool create ....."
41 | rf.setChannel(APP_CHANNEL);
42 | rf.setSyncWord(APP_SYNCWORD[0], APP_SYNCWORD[1]);
43 | rf.disableAddressCheck();
44 |
45 | // with the default register settings of the library
46 | // CC1101 chip asserts gdo0 LOW when a packet received
47 | // or after a packet is sent.
48 | // gdo1 is not used.
49 | attachInterrupt(0, cc1101_interrupt, FALLING);
50 |
51 | // Uncomment to use a LED in A5
52 | // pinMode(A5,OUTPUT);
53 |
54 | PRINTLN("Hello world, press a key");
55 | }
56 |
57 | void loop() {
58 | // As we said, rfboot has already enabled the watchdog timer.
59 | // This means we must reset it periodically, to avoid a reset.
60 | // If an operation/function inside loop blocks for more than 2sec,
61 | // the module will reset by the watchdog automatically.
62 | // This is a desirable behavior, preventing halted/non-responding modules.
63 | wdt_reset();
64 |
65 | if (rf.interrupt) {
66 | byte packet[64];
67 | byte pkt_size = rf.getPacket(packet);
68 | rf.interrupt = false;
69 | if (pkt_size>0 and rf.crc_ok) { // We have a valid packet with some data
70 | // The following code resets the MCU when it gets the RESET_STRING (is defined in "app_settings.h")
71 | // This is for wireless firmware updates without physical contact
72 | const uint8_t RESET_LEN = strlen(RESET_STRING) ;
73 | if ( pkt_size==RESET_LEN and memcmp( (char*)packet, RESET_STRING, RESET_LEN)==0 ) {
74 | // rftool on PC side, requires echo back
75 | PRINT("%s",RESET_STRING);
76 | wdt_enable( WDTO_15MS );
77 | // After 15ms -> reset
78 | while (1) {};
79 | }
80 | // here you can put code to check for any input
81 | if (pkt_size==1) {
82 | byte c = packet[0];
83 | if (c>=32 and c<=126) {
84 | PRINTLN("You pressed \"%c\"", packet[0]);
85 | }
86 | else {
87 | PRINTLN("Non printable ascii char");
88 | }
89 | }
90 | else {
91 | PRINTLN("Got packet with size %d", pkt_size);
92 | }
93 | // if (pkt_size==4 ....
94 | // you will need strcmp/memcmp for this and VERY IMPORTAND
95 | // you cannot type 4 chars in the serial terminal. The fingers are
96 | // very slow and probably the 4 chars will arrive as 4 packets, 1
97 | // byte each. However you can paste text (up to 32 chars) and will
98 | // arrive as a single packet
99 | }
100 | }
101 |
102 | // Uncomment to make LED blink, Be sure to also uncomment the "pinMode" in setup()
103 | // We use a method that does not block the execution flow, we avoid delay(..) in
104 | // other words. Change the numbers to see what it happens. This is only an example
105 | // but all code you write must have this in mind: No delay(..) inside loop. If
106 | // the delay is small enough (some ms) to support some specific function/device,
107 | // then is OK i guess.
108 |
109 | // digitalWrite(A5, millis()%1000<500);
110 | }
111 |
112 |
--------------------------------------------------------------------------------
/usb2rf/Makefile:
--------------------------------------------------------------------------------
1 | BOARD_TAG = pro328
2 | EXTRA_FLAGS = -fshort-enums -g
3 | include /usr/share/arduino/Arduino.mk
4 |
5 | MONITOR_PORT := $(shell rftool getport)
6 |
7 | send: all
8 | send: portcheck
9 | rftool resetLocal
10 | fuser -s -v -k -STOP $(MONITOR_PORT) || true
11 | $(MAKE) do_upload
12 | fuser -s -v -k -CONT $(MONITOR_PORT) || true
13 |
14 | portcheck:
15 | ifeq ($(MONITOR_PORT),)
16 | @$(error No usb2rf device is connected )
17 | endif
18 |
19 | hex: all
20 | cp -v build-pro328/usb2rf.hex .
21 |
22 | sendHex:
23 | rftool resetLocal
24 | avrdude -q -V -D -p atmega328p -c arduino -b 57600 -P $(MONITOR_PORT) -U flash:w:usb2rf.hex:i
25 |
26 | debug: portcheck
27 | # WARNING ! You need to put here the correct serial port device, for debug monitoring
28 | gtkterm -s 19200 -p /dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_Z2CVM7J2-if00-port0
29 |
--------------------------------------------------------------------------------
/usb2rf/README.md:
--------------------------------------------------------------------------------
1 | ### usb2rf module
2 | Generally you need the following info only if you read/modify the usb2rf source code.
3 |
4 | This folder contains firmware for the usb2rf module.
5 | The usb2rf module is a bridge allowing data from the PC to be transmitted as RF packets, and in reverse
6 | direction, allows rf packets to be received from the PC.
7 |
8 | ### Upload the precompiled usb2rf.hex file
9 | Normally you dont need/want to do that independently, as this is part of the [Installation](../help/Installation.md).
10 | OK, If rftool knows the module (rftool addport), it is just a
11 | ```sh
12 | > make sendHex
13 | ```
14 |
15 | ### build instructions
16 | You need to install the Arduino libraries
17 | [AltSoftSerial](https://github.com/PaulStoffregen/AltSoftSerial)
18 | [digitalWriteFast](https://github.com/NicksonYap/digitalWriteFast)
19 | and then compile as usual.
20 | ```sh
21 | # To build the firmware
22 | > make
23 | # to upload the firmware
24 | > make send
25 | # to replace the precompiled usb2rf.hex
26 | > make hex
27 | ```
28 |
29 | ### Debug port (useful if you are modifying/debugging the usb2rf code)
30 | By using another USB to UART module you can have debug messages, as obviously the main
31 | port cannot be used for debug messages.
32 | You need 3 jumper cables:
33 |
34 | ProMini | Debug SerialModule
35 | ------ | -----
36 | D9 | RX
37 | D4 | DTR
38 | GND | GND
39 |
40 | If the "data serial module" and the "debug serial module" are powered from the same
41 | computer (most likely) then the GND cable can be omitted.
42 |
43 | Edit the Makefile and replace the debug serial port (Not the same with the main serial port!)
44 | with the correct one and then:
45 | ```sh
46 | > make debug
47 | ```
48 | This command opens a gtkterm with the appropriate parameters.
49 | You can use your favorite serial terminal as usual.
50 | Now press "**F7**" (with gtkterm) to toggle DTR and enable/disable debug output.
51 | You can also read the comments inside usb2rf.ino for more info.
52 |
53 | ### Assemble the module
54 | See [Installation](../help/Installation.md) for instructions.
55 |
--------------------------------------------------------------------------------
/usb2rf/hardware/README.md:
--------------------------------------------------------------------------------
1 | This folder contains
2 | breadboard schematic
3 | PCB fritzing
4 | some photos
5 | In order to build your usb2rf module
6 |
--------------------------------------------------------------------------------
/usb2rf/hardware/usb2rf.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pkarsy/rfboot/479c2bde7dda42a6d2efc1c06f510441e89a511c/usb2rf/hardware/usb2rf.fzz
--------------------------------------------------------------------------------
/usb2rf/usb2rf.hex:
--------------------------------------------------------------------------------
1 | :100000000C94AF010C941A060C9447060C94D7017B
2 | :100010000C94D7010C94D7010C94D7010C94D70100
3 | :100020000C94D7010C94D7010C94210D0C94810CE5
4 | :100030000C94CB0D0C94D7010C94D7010C94D701E0
5 | :100040000C9474060C94D7010C94700A0C94AA0AB0
6 | :100050000C94D7010C94D7010C94D7010C94D701C0
7 | :100060000C94D7010C94D70153656E64696E6720B8
8 | :100070007061636B6574206661696C6564006469B6
9 | :100080007361626C656400656E61626C65640064D6
10 | :1000900065627567206D65737361676573200055D0
11 | :1000A000534232524600284637206B6579207769E3
12 | :1000B00074682067746B7465726D2920746F206595
13 | :1000C0006E61626C652F64697361626C6520646542
14 | :1000D000627567206F757470757400557362327243
15 | :1000E0006620646562756720706F72742061742089
16 | :1000F0003139323030206270732E20417373657253
17 | :1001000074204454522000556E6B6E6F776E2063DE
18 | :100110006F6D6D616E642000536F667477617265F8
19 | :1001200020726573657420636F6D6D616E642C2041
20 | :10013000626164206C656E677468203A2000536FBA
21 | :1001400066747761726520726573657400446F6EC2
22 | :10015000650053656E64696E672057616B65557005
23 | :1001600020627572737420313035306D73005570B4
24 | :100170006C6F616420636F646520636F6D6D616E89
25 | :10018000642C20626164206C656E677468203A207C
26 | :100190000053776974636820746F2075706C6F61A9
27 | :1001A00064206D6F646500557362327266206D6FF6
28 | :1001B00064756C65206661696C656420746F20727B
29 | :1001C000657365740055534220746F205246205267
30 | :1001D00065736574004D43552072657365742063C3
31 | :1001E0006F6D6D616E642077726F6E672073697AD0
32 | :1001F00065203A200053696C656E7420636F6D6DE5
33 | :10020000616E642C20626164206C656E6774682086
34 | :100210003A200053696C656E7420666F7220353029
35 | :100220006D73006368616E6E656C3D004368616E5E
36 | :100230006E656C20636F6D6D616E642077726F6E9A
37 | :10024000672073697A65203A200063633131303169
38 | :100250002077726F6E6720636D642073697A652002
39 | :100260000053796E63776F7264203D20004375738D
40 | :10027000746F6D20636F6D6D616E642C20626164BC
41 | :10028000206C656E677468203A200043433131303A
42 | :1002900031207265676973746572203D2000206F9C
43 | :1002A0007220002C20627574206578706563746517
44 | :1002B0006420003A2050726F746F636F6C20657217
45 | :1002C000726F722E206170705F6964783D006F6B91
46 | :1002D000206E65787420706B7400526573656E646F
47 | :1002E00000706B74206F7574203A206964783D004B
48 | :1002F00053617661696C3D0075706C6F61643A2082
49 | :1003000054696D656F7574000000000700020100FC
50 | :1003100000030406000000000000000001020408C1
51 | :10032000102040800102040810200102040810205F
52 | :10033000040404040404040402020202020203038B
53 | :100340000303030300000000250028002B00000029
54 | :100350000000240027002A00F2016A0B0702112482
55 | :100360001FBECFEFD8E0DEBFCDBF11E0A0E0B1E00F
56 | :10037000ECE3F4E202C005900D92AC36B107D9F778
57 | :1003800022E0ACE6B1E001C01D92AE3DB207E1F75C
58 | :1003900011E0CEEAD1E004C02197FE010E94FC11D9
59 | :1003A000CC3AD107C9F70E9488040C94BF110C9471
60 | :1003B000000081E08093820108956115710579F054
61 | :1003C000FB0101900020E9F73197AF01461B570B65
62 | :1003D000DC01ED91FC910280F381E02D099480E035
63 | :1003E00090E008958EE791E00E942B0EE2E7F1E0A5
64 | :1003F0001382128288EE93E0A0E0B0E084839583BC
65 | :10040000A683B78380E691E091838083089580E698
66 | :1004100091E090937301809372010C94170E80E920
67 | :1004200091E00E94030A0196D1F708958F929F925E
68 | :10043000AF92BF92CF92DF92EF92FF920F931F93F2
69 | :10044000CF93DF93CDB7DEB7C058D1090FB6F8947C
70 | :10045000DEBF0FBECDBF6C010E94BE064B015C012A
71 | :1004600064E180E991E00E942E0AE12CFF24F394DC
72 | :100470000E94BE06DC01CB0188199909AA09BB09B3
73 | :1004800085369105A105B10570F04C9906C068EF5D
74 | :1004900072E082E791E00E94180866E180E991E04D
75 | :1004A0000E942E0AEFC0E110EAC080E991E00E94AC
76 | :1004B000D70980970CF441C040E250E0BE016F5B69
77 | :1004C0007F4F80E991E00E94B10981E2C816D10412
78 | :1004D00028F064E180E991E00E942E0A4C9911C055
79 | :1004E00060EF72E082E791E00E94180880E991E0F5
80 | :1004F0000E94D7094AE050E0BC0182E791E00E94E7
81 | :100500002309FF20B9F040E2BE016F5B7F4F8EE709
82 | :1005100091E00E941D104C990DC061EE72E082E7DF
83 | :1005200091E00E9418084AE050E0B60182E791E0AD
84 | :100530000E946B09EE24E394F12C809182018823C0
85 | :1005400009F496CFBE016F5F7F4F8EE791E00E9466
86 | :10055000461110928201833009F07FC080918101A1
87 | :10056000882309F47AC00E94BE064B015C01898190
88 | :10057000843009F061C08A810B8110E0102F0027C0
89 | :10058000080F111D0C151D05B1F440E2BE016F5B93
90 | :100590007F4F8EE791E00E941D1065E180E991E0B8
91 | :1005A0000E942E0A4C9962C06AED72E082E791E0E7
92 | :1005B0000E9458085BC0760180E2E81AF1080E1527
93 | :1005C0001F0549F44C9954C06EEC72E082E791E04B
94 | :1005D0000E9458084DC04C992FC04AE050E06CE88A
95 | :1005E00070E082E791E00E941C0963EB72E082E711
96 | :1005F00091E00E9418084AE050E0B80182E791E0DB
97 | :100600000E94650963EA72E082E791E00E9418089F
98 | :100610004AE050E0B70182E791E00E9465096EE987
99 | :1006200072E082E791E00E9418084AE050E0B601CB
100 | :1006300082E791E00E9465090E940F0266E180E96D
101 | :1006400091E00E942E0A43E050E0BE016F5F7F4FB1
102 | :1006500080E991E00E94F00715C04C990DC060E060
103 | :1006600071E082E791E00E943B0806C0F12C05C0D2
104 | :10067000E12CFF24F39401C086016801F9CEF1104A
105 | :1006800042CF5BCFC058DF4F0FB6F894DEBF0FBE2E
106 | :10069000CDBFDF91CF911F910F91FF90EF90DF9031
107 | :1006A000CF90BF90AF909F908F900895EF92FF9260
108 | :1006B0000F931F93CF93DF931F92CDB7DEB77C01CB
109 | :1006C000162FFC018081813509F479C048F481340A
110 | :1006D000D1F1833409F460C0803309F0FEC00FC04B
111 | :1006E000853509F4A0C020F4823509F482C0F5C034
112 | :1006F000873509F4B2C08A3509F4D2C0EEC0613042
113 | :1007000091F44C99FDC06BE872E082E791E00E94A1
114 | :10071000180840E862E18EE791E00E94800E40E117
115 | :1007200050E0682F0BC04C99EBC06DE672E082E799
116 | :1007300091E00E9418084AE050E0612F82E791E0C2
117 | :100740000E944E09DDC0633011F5F70142816181DD
118 | :100750008EE791E00E94C60E4C99D2C061E672E02D
119 | :1007600082E791E00E9418084AE050E0F7016181B9
120 | :1007700082E791E00E94470960E171E082E791E041
121 | :100780000E943B084AE050E0F7016281D7CF4C99C4
122 | :10079000B7C06AE472E0CBCF623029F04C99B0C0A8
123 | :1007A0006CE272E0C4CFF7011181612F8EE791E016
124 | :1007B0000E94DB0E4C99A4C063E272E0B8CF6130B6
125 | :1007C00099F44C997FC063E172E082E791E00E9466
126 | :1007D00058080E94BE0660936C0170936D0180936F
127 | :1007E0006E0190936F016EC04C998AC065EF71E005
128 | :1007F0009ECF613029F04C9983C065ED71E097CFB1
129 | :100800004C9906C065EC71E082E791E00E945808BF
130 | :1008100040E060E08EE791E00E94C60E5B98539A3C
131 | :1008200067EA71E038C0633099F44C9906C061E919
132 | :1008300071E082E791E00E945808F70121818281EE
133 | :1008400090E0982F8827820F911D0E94160258C0B1
134 | :100850004C9956C06EE671E06ACF623009F050C024
135 | :100860004C9906C062E571E082E791E00E94580869
136 | :10087000F701818189830AE114E020E030E041E062
137 | :10088000BE016F5F7F4F8EE791E00E9486104C990A
138 | :1008900037C06DE471E082E791E00E94580830C0F3
139 | :1008A0006130B1F44C9908C06EE371E082E791E0E9
140 | :1008B0000E9458080E941A0D40E060E08EE791E027
141 | :1008C0000E94C60EE0917001F0917101099518C067
142 | :1008D0004C9916C068E171E02ACF4C9911C067E0CD
143 | :1008E00071E082E791E00E941808412F50E0B701C3
144 | :1008F00082E791E00E94F00782E791E00E944408BD
145 | :100900000F90DF91CF911F910F91FF90EF9008957D
146 | :10091000CF93DF93CDB7DEB7C054D1090FB6F894AB
147 | :10092000DEBF0FBECDBF0E94200762E084E00E94C0
148 | :10093000840740E056E960E070E080E991E00E94C1
149 | :10094000E50A61EA71E080E090E00E94DD0B8EE74D
150 | :1009500091E00E940F1044E067E08EE791E00E9472
151 | :100960002C0E48EE69E38EE791E00E94C60E42E04D
152 | :1009700050E069ED71E080E00E94FA0547E962E12C
153 | :100980008EE791E00E942C0E6BED70E082E791E023
154 | :100990000E94580866EA70E082E791E00E945808D9
155 | :1009A0000E94CA066B017C0165E070E080E090E087
156 | :1009B0000E94EF066FE970E080E991E00E9458081C
157 | :1009C00000E0B12C10E09924939489B18295817054
158 | :1009D00089258017A9F009B10295017009256FE8F2
159 | :1009E00070E082E791E00E9418084C9903C067E824
160 | :1009F00070E002C06EE770E082E791E00E94580864
161 | :100A000080E991E0BB2081F10E94D709892B89F010
162 | :100A100080E991E00E94030AE1E0F0E0EC0FFD1FA5
163 | :100A2000E10FF11D80831F5F103209F065C0B12C0A
164 | :100A30005FC00E94CA06DC01CB018C199D09AE097A
165 | :100A4000BF09813D9740A105B10508F490C011236D
166 | :100A500029F0612FCE0101960E9456030E94CA061A
167 | :100A60006B017C01B12C82C00E94D709892B09F44B
168 | :100A700041C080E991E00E94030AE1E0F0E0EC0F60
169 | :100A8000FD1FE10FF11D80831F5F103219F54C9996
170 | :100A900006C062E171E082E791E00E94DD0140E280
171 | :100AA000BE016F5F7F4F8EE791E00E941D10182FEF
172 | :100AB0004C990BC0882319F06BE171E002C069E129
173 | :100AC00071E082E791E00E94DD014C9911C01111A3
174 | :100AD0000FC089C0153081F445E050E06EE171E04F
175 | :100AE000CE0101960E94C211892B31F4BB24B3942C
176 | :100AF00010E002C0111105C00E94CA066B017C0102
177 | :100B000036C00E94CA06DC01CB018C199D09AE09D2
178 | :100B1000BF09813D9740A105B10548F14C990DC031
179 | :100B200064E271E082E791E00E94DD014AE050E07A
180 | :100B3000612F82E791E00E944709412FBE016F5F5C
181 | :100B40007F4F8EE791E00E941D104C990BC08823C7
182 | :100B500019F06BE171E002C069E171E082E791E0B8
183 | :100B60000E94DD010E94CA066B017C0110E08091A9
184 | :100B70008201882309F429CFBE016F5F7F4F8EE782
185 | :100B800091E00E944611A82E10928201809181016D
186 | :100B90008823C9F0AA2071F04A2D50E0BE016F5F92
187 | :100BA0007F4F80E991E00E94F0074C990ECF69E2F7
188 | :100BB00071E00DC04C9909CF6DE271E082E791E0E0
189 | :100BC0000E946A0802CF4C9900CF64E371E082E78B
190 | :100BD00091E00E94DD014AE050E06A2D82E791E059
191 | :100BE0000E944E09F2CE68E670E082E791E00E9432
192 | :100BF00058087ECF8230E8F4E82FF0E0EE0FFF1FB8
193 | :100C0000ED57FE4F71836083813041F08091690020
194 | :100C10008C7F482B40936900E89A08958091690081
195 | :100C2000440F551F440F551F837F482B4093690085
196 | :100C3000E99A08951F920F920FB60F9211242F93E5
197 | :100C40003F934F935F936F937F938F939F93AF9354
198 | :100C5000BF93EF93FF938091830190918401892B3F
199 | :100C600029F0E0918301F09184010995FF91EF91C2
200 | :100C7000BF91AF919F918F917F916F915F914F91B4
201 | :100C80003F912F910F900FBE0F901F9018951F92BC
202 | :100C90000F920FB60F9211242F933F934F935F93B0
203 | :100CA0006F937F938F939F93AF93BF93EF93FF9334
204 | :100CB0008091850190918601892B29F0E091850131
205 | :100CC000F09186010995FF91EF91BF91AF919F91AE
206 | :100CD0008F917F916F915F914F913F912F910F90E5
207 | :100CE0000FBE0F901F9018951F920F920FB60F9284
208 | :100CF00011242F933F938F939F93AF93BF93809132
209 | :100D0000880190918901A0918A01B0918B01309165
210 | :100D1000870126E0230F2D3720F40296A11DB11D77
211 | :100D200005C029E8230F0396A11DB11D209387015B
212 | :100D30008093880190938901A0938A01B0938B01DD
213 | :100D400080918C0190918D01A0918E01B0918F01C5
214 | :100D50000196A11DB11D80938C0190938D01A093EC
215 | :100D60008E01B0938F01BF91AF919F918F913F9171
216 | :100D70002F910F900FBE0F901F9018952FB7F894DA
217 | :100D8000609188017091890180918A0190918B0115
218 | :100D90002FBF08953FB7F89480918C0190918D01F9
219 | :100DA000A0918E01B0918F0126B5A89B05C02F3F61
220 | :100DB00019F00196A11DB11D3FBFBA2FA92F982F81
221 | :100DC0008827820F911DA11DB11DBC01CD0143E0FB
222 | :100DD000660F771F881F991F4A95D1F70895CF9204
223 | :100DE000DF92EF92FF92CF93DF936B017C010E9421
224 | :100DF000CA06EB01C114D104E104F10479F00E94A8
225 | :100E0000CA066C1B7D0B683E7340A0F381E0C81AD4
226 | :100E1000D108E108F108C851DC4FECCFDF91CF9148
227 | :100E2000FF90EF90DF90CF9008958130910539F0D9
228 | :100E3000029729F0880F991F01970197F1F70895FC
229 | :100E4000789484B5826084BD84B5816084BD85B5A5
230 | :100E5000826085BD85B5816085BDEEE6F0E080816C
231 | :100E600081608083E1E8F0E010828081826080838D
232 | :100E7000808181608083E0E8F0E080818160808310
233 | :100E8000E1EBF0E0808184608083E0EBF0E0808142
234 | :100E900081608083EAE7F0E08081846080838081E4
235 | :100EA000826080838081816080838081806880838C
236 | :100EB0001092C1000895833081F028F4813099F0B8
237 | :100EC0008230A1F008958630A9F08730B9F08430DF
238 | :100ED000D1F4809180008F7D03C0809180008F7756
239 | :100EE00080938000089584B58F7702C084B58F7D8C
240 | :100EF00084BD08958091B0008F7703C08091B000C9
241 | :100F00008F7D8093B0000895CF93DF9390E0FC0134
242 | :100F1000E45EFC4F2491FC01E05DFC4F849188234A
243 | :100F200061F190E0880F991FFC01E25BFC4FC591D5
244 | :100F3000D491FC01EC5BFC4FA591B491611109C007
245 | :100F40009FB7F8948881209582238883EC912E2383
246 | :100F50000BC0623061F49FB7F8943881822F80957E
247 | :100F600083238883EC912E2B2C939FBF06C08FB7D1
248 | :100F7000F894E8812E2B28838FBFDF91CF910895BD
249 | :100F80001F93CF93DF93282F30E0F901E85FFC4FE8
250 | :100F90008491F901E45EFC4FD491F901E05DFC4FCE
251 | :100FA000C491CC23C9F0162F81110E945B07EC2F4E
252 | :100FB000F0E0EE0FFF1FEC5BFC4FA591B4918FB7F3
253 | :100FC000F894111105C09C91ED2FE095E92302C022
254 | :100FD000EC91ED2BEC938FBFDF91CF911F91089592
255 | :100FE000CF92DF92EF92FF920F931F93CF93DF93F5
256 | :100FF0006C01EB017B01E40EF51E00E010E0CE1564
257 | :10100000DF0561F06991D601ED91FC910190F081CD
258 | :10101000E02DC6010995080F191FF1CFC801DF9116
259 | :10102000CF911F910F91FF90EF90DF90CF90089597
260 | :10103000EF92FF920F931F93CF93DF937C01FB01FD
261 | :1010400000E010E06491EF012196662361F0D70182
262 | :10105000ED91FC910190F081E02DC7010995080FF9
263 | :10106000191FFE01EFCFC801DF91CF911F910F91A2
264 | :10107000FF90EF9008950C94DD01DC01ED91FC915F
265 | :101080000190F081E02D09940F931F93CF93DF938C
266 | :10109000EC016DE00E943D088C016AE0CE010E94E7
267 | :1010A0003D08800F911FDF91CF911F910F910895FF
268 | :1010B0000F931F93CF93DF93EC010E9418088C01CC
269 | :1010C000CE010E944408800F911FDF91CF911F91A4
270 | :1010D0000F9108950F931F93CF93DF93EC010E941C
271 | :1010E000DD018C01CE010E944408800F911FDF9129
272 | :1010F000CF911F910F9108958F929F92AF92BF92BF
273 | :10110000CF92DF92EF92FF920F931F93CF93DF93D3
274 | :10111000CDB7DEB7A1970FB6F894DEBF0FBECDBF37
275 | :101120006C01142FE52FCB01022F19A2223008F4F5
276 | :101130000AE07E0121E2E20EF11C802E912CA12C0E
277 | :10114000B12C612F7E2FA50194010E94CF11029F27
278 | :101150001019112481E0E81AF1081A3014F4105D16
279 | :1011600001C0195CF7011083122FE32FCA01232B52
280 | :10117000242B252B31F7B701C6010E94DD01A19672
281 | :101180000FB6F894DEBF0FBECDBFDF91CF911F9198
282 | :101190000F91FF90EF90DF90CF90BF90AF909F9016
283 | :1011A0008F900895CF92DF92EF92FF920F931F934B
284 | :1011B000CF93DF93EC016A017B012115310579F4AE
285 | :1011C000E881F9810190F081E02D642FDF91CF91CA
286 | :1011D0001F910F91FF90EF90DF90CF9009942A30EC
287 | :1011E0003105E9F477FF1AC06DE20E943D088C01D9
288 | :1011F00044275527BA014C195D096E097F092AE079
289 | :10120000CE010E947C08800F911FDF91CF911F912A
290 | :101210000F91FF90EF90DF90CF9008952AE0B701F3
291 | :10122000A601CE01DF91CF911F910F91FF90EF901A
292 | :10123000DF90CF900C947C089A01AB01770F660B7E
293 | :10124000770B0C94D2080F931F93CF93DF93EC018D
294 | :101250009A01AB01770F660B770B0E94D2088C01C5
295 | :10126000CE010E944408800F911FDF91CF911F9102
296 | :101270000F9108952115310541F4DC01ED91FC91A8
297 | :101280000190F081E02D642F09940C947C089A0160
298 | :10129000462F50E060E070E00C943A090F931F93E2
299 | :1012A000CF93DF93EC019A01462F50E060E070E0AD
300 | :1012B0000E943A098C01CE010E944408800F911FC0
301 | :1012C000DF91CF911F910F9108959A01AB0160E0DA
302 | :1012D00070E00C943A090F931F93CF93DF93EC01C6
303 | :1012E0009A01AB0160E070E00E943A098C01CE01E6
304 | :1012F0000E944408800F911FDF91CF911F910F91A1
305 | :1013000008950F931F93CF93DF93EC010E94BE06C5
306 | :10131000688779878A879B87E881F9810680F781CA
307 | :10132000E02DCE01099597FF17C00E94BE060885E3
308 | :1013300019852A853B85DC01CB01801B910BA20B13
309 | :10134000B30B0C811D812E813F8180179107A2076D
310 | :10135000B30710F38FEF9FEFDF91CF911F910F91A4
311 | :101360000895CF92DF92EF92FF920F931F93CF9346
312 | :10137000DF936C017A018B01C0E0D0E0CE15DF0570
313 | :1013800061F0C6010E94810997FF02C07E0105C07D
314 | :10139000F80181938F012196F1CFC701DF91CF91A1
315 | :1013A0001F910F91FF90EF90DF90CF900895FC0177
316 | :1013B00024853585F901E05CFF4F8081918132966B
317 | :1013C00020813181821B930B8F7399270895DC0153
318 | :1013D0001C96ED91FC911D97DF01A05CBF4F2D91F4
319 | :1013E0003C91119712968D919C911197281739076E
320 | :1013F00039F08D919C91E80FF91F808190E008955C
321 | :101400008FEF9FEF0895FC01A485B585FD01E05C99
322 | :10141000FF4F2081318132968081918128173907D1
323 | :1014200079F080819181A80FB91F8C912081318141
324 | :101430002F5F3F4F2F7333273183208390E0089530
325 | :101440008FEF9FEF0895FC0181A1882329F0A489E3
326 | :10145000B5898C9186FFFBCF11A208950F931F933E
327 | :10146000CF93DF93FC01A685B7858D01005C1F4FEC
328 | :10147000E8018881998101968F739927AD014E5BB0
329 | :101480005F4FEA012881398182179307D1F3E80180
330 | :1014900028813981A20FB31F6C93A685B785A05C04
331 | :1014A000BF4F11969C938E93A689B7892C9181E0AA
332 | :1014B00090E0078C02C0880F991F0A94E2F7822BF4
333 | :1014C0008C9381E081A30488F589E02D808180647C
334 | :1014D000808381E090E0DF91CF911F910F9108957B
335 | :1014E0001F920F920FB60F9211242F934F935F9379
336 | :1014F0008F939F93EF93FF938091C00082FD1CC058
337 | :101500002091C600809136029091370201968F7328
338 | :10151000992740913802509139028417950771F04C
339 | :10152000E0913602F0913702EA50FE4F208390930B
340 | :1015300037028093360202C08091C600FF91EF917E
341 | :101540009F918F915F914F912F910F900FBE0F90B0
342 | :101550001F9018951F920F920FB60F9211242F9380
343 | :101560003F938F939F93EF93FF932091F2013091DC
344 | :10157000F3018091F4019091F5012817390731F4B6
345 | :101580008091C1008F7D8093C10014C0E091F4016F
346 | :10159000F091F501EE54FE4F20818091F40190917D
347 | :1015A000F50101968F7399279093F5018093F401CB
348 | :1015B0002093C600FF91EF919F918F913F912F91C2
349 | :1015C0000F900FBE0F901F901895CF92DF92EF9261
350 | :1015D000FF920F931F93CF93DF93EC016A017B017E
351 | :1015E000EC89FD8981E090E008A002C0880F991F76
352 | :1015F0000A94E2F7808360E874E88EE190E0A70146
353 | :1016000096010E94CF1189019A0101501109210907
354 | :1016100031093695279517950795980101151041C1
355 | :1016200008F042C0E889F9893083EA89FB89208380
356 | :1016300019A2EE89FF89408181E090E09C010C8C29
357 | :1016400002C0220F331F0A94E2F7242B2083EE8975
358 | :10165000FF8940819C010D8C02C0220F331F0A9428
359 | :10166000E2F7242B2083EE89FF8940819C010E8CB8
360 | :1016700002C0220F331F0A94E2F7242B2083EE8945
361 | :10168000FF8920810F8C02C0880F991F0A94E2F70E
362 | :10169000809582238083DF91CF911F910F91FF90DE
363 | :1016A000EF90DF90CF900895EC89FD89108260E47F
364 | :1016B00072E48FE090E0A70196010E94CF11DA0159
365 | :1016C000C9010197A109B109B695A7959795879585
366 | :1016D0009C01A8CFE0E9F1E01382128288EE93E04A
367 | :1016E000A0E0B0E084839583A683B78380E591E092
368 | :1016F0009183808386EF91E09587848782EB91E0E8
369 | :101700009787868785EC90E0918B808B84EC90E0C6
370 | :10171000938B828B80EC90E0958B848B81EC90E0B6
371 | :10172000978B868B82EC90E0918F808F86EC90E097
372 | :10173000938F828F84E0848F83E0858F87E0868F0C
373 | :1017400085E0878F81E080A308958091D4029091F5
374 | :10175000D302891769F09F5F903508F090E0E92F78
375 | :10176000F0E0ED57FD4F80819093D30290E0089513
376 | :101770008FEF9FEF08958091D402E091D3028E17EE
377 | :1017800051F0EF5FE03508F0E0E0F0E0ED57FD4F9D
378 | :10179000808190E008958FEF9FEF08955091D402DB
379 | :1017A0004091D302852F90E0242F30E0541710F49D
380 | :1017B000805B9F4F821B930B08959B01AC012136E8
381 | :1017C00088E138074105510530F410926F001092FE
382 | :1017D000800081E825C073E0569547953795279599
383 | :1017E0007A95D1F7213688E138074105510530F463
384 | :1017F00010926F001092800082E812C065E056954A
385 | :101800004795379527956A95D1F7213688E13807AE
386 | :1018100041055105C0F510926F001092800084E8D8
387 | :10182000809381003093DD022093DC02A5E2B0E0DA
388 | :101830000E94F111DC01CB0122E0B695A7959795A6
389 | :1018400087952A95D1F79093D6028093D50262E0CE
390 | :1018500088E00E94840761E089E00E94C00761E09F
391 | :1018600089E00E9484071092DB021092D402109249
392 | :10187000D3021092820210927F0210927E0280E2C6
393 | :1018800086BB80936F00089590917F029F5F943490
394 | :1018900008F090E020917E022917E1F32FB7F89429
395 | :1018A00030918202332341F0E92FF0E0E65CFD4FF6
396 | :1018B000808390937F021DC091E090938202809379
397 | :1018C00081021092800282E086BB80916F0082606C
398 | :1018D00080936F00809180008F7380688093800078
399 | :1018E0008091840090918500409690938900809328
400 | :1018F00088002FBF0895862F0E94440C81E090E05D
401 | :1019000008951F920F920FB60F9211242F933F93B9
402 | :101910004F935F936F937F938F939F93EF93FF9377
403 | :10192000809182026091810220918800309189002B
404 | :101930004091DC025091DD02909180028A30F8F4EF
405 | :10194000240F351F893019F0762F717001C071E0B6
406 | :1019500066958F5F791791F390918000772311F04E
407 | :10196000906C02C09F7390689093800030938900C0
408 | :101970002093880070938002609381024AC0909106
409 | :101980007F02E0917E029E1319C08A3051F48BE0F1
410 | :1019900080938202240F351F3093890020938800A2
411 | :1019A0003AC010928202809180008F7380938000F1
412 | :1019B00080916F008D7F80936F002DC0EF5FE434C6
413 | :1019C00008F0E0E0E0937E02F0E0E65CFD4F9081FD
414 | :1019D0009093810210928002909180009F73906892
415 | :1019E000909380008A3059F48091DC029091DD025E
416 | :1019F000280F391F309389002093880009C08091F7
417 | :101A0000840090918500409690938900809388008F
418 | :101A100081E080938202FF91EF919F918F917F915E
419 | :101A20006F915F914F913F912F910F900FBE0F904B
420 | :101A30001F901895809182028111FCCF08950C941B
421 | :101A40001A0D1F920F920FB60F9211242F933F93EE
422 | :101A50004F935F936F937F938F939F93AF93BF93B6
423 | :101A6000EF93FF9380918600909187004091D90277
424 | :101A700020918100442331F02F7B2093810010922C
425 | :101A8000D90206C020642093810020E82093D90267
426 | :101A90003091DB02311125C041116CC02091D5027B
427 | :101AA0003091D602280F391F30938B0020938A0083
428 | :101AB00024E026BB20916F00246020936F002091CA
429 | :101AC000DC023091DD02820F931F36952795820F3D
430 | :101AD000931F9093D8028093D70281E08093DB021A
431 | :101AE00049C04091D7025091D8026091DC027091B8
432 | :101AF000DD02DB01A095B0952091DA02E091D902D8
433 | :101B0000841B950BA817B90768F126952E2B460F55
434 | :101B1000571F3F5F861B970B3930A0F32093DA02E3
435 | :101B200080916F008B7F80936F008091D4028F5FD4
436 | :101B3000803508F080E09091D302891749F0E82FB2
437 | :101B4000F0E09091DA02ED57FD4F90838093D4023C
438 | :101B5000809181008F7B809381001092D902109236
439 | :101B6000DB0208C02093DA025093D8024093D702D8
440 | :101B70003093DB02FF91EF91BF91AF919F918F91D5
441 | :101B80007F916F915F914F913F912F910F900FBE79
442 | :101B90000F901F9018951F920F920FB60F9211245D
443 | :101BA0002F938F939F93EF93FF9380916F008B7F81
444 | :101BB00080936F00809181008F7B80938100809162
445 | :101BC000DB022091D90220589091DA02893020F46A
446 | :101BD0009695922B8F5FFACF9093DA028091D40280
447 | :101BE0008F5F803508F080E02091D302821739F0B2
448 | :101BF000E82FF0E0ED57FD4F90838093D4021092D0
449 | :101C0000DB02809181008F7B809381001092D9024A
450 | :101C1000FF91EF919F918F912F910F900FBE0F9099
451 | :101C20001F9018958091D3028093D4020895CF938A
452 | :101C3000DF93CFE6D0E088818B7F888388818F7D9A
453 | :101C400088830E94120E0E941A0D88818D7F8883DE
454 | :101C5000DF91CF91089508950F931F93CF93DF9352
455 | :101C60001F92CDB7DEB78C012A981C99FECFC80110
456 | :101C700049830E94B9114981642FC8010E94B9119A
457 | :101C80002A9A0F90DF91CF911F910F910895CF92D3
458 | :101C9000DF92EF92FF920F931F93CF93DF9300D0C9
459 | :101CA000CDB7DEB78C01F22E60642A981C99FECF66
460 | :101CB000C80149835A830E94B9114981E42EC42E78
461 | :101CC0005A81D52E8C2D8E198F1538F4F60161911D
462 | :101CD0006F01C8010E94B911F5CF2A9A0F900F9099
463 | :101CE000DF91CF911F910F91FF90EF90DF90CF90F8
464 | :101CF00008952A981C99FECF0E94B9112A9A089536
465 | :101D0000CF93DF93EC01642B2A981C99FECFCE0170
466 | :101D10000E94B91160E0CE010E94B9112A9ADF91A8
467 | :101D2000CF910895AF92BF92DF92EF92FF920F93FF
468 | :101D30001F93CF93DF931F92CDB7DEB78C01F62EA2
469 | :101D4000E22E642F606C2A981C99FECFC80179831B
470 | :101D50000E94B911DF2CAF2C7981B72E8A2D8D19F5
471 | :101D60008E1540F460E0C8010E94B911F50181931D
472 | :101D70005F01F4CF2A9A0F90DF91CF911F910F91BD
473 | :101D8000FF90EF90DF90BF90AF9008951F93CF9397
474 | :101D9000DF93EC01142F462F64E00E942C0E412F9C
475 | :101DA00065E0CE01DF91CF911F910C942C0E462F50
476 | :101DB00069E00C942C0E462F6AE00C942C0ECF9305
477 | :101DC000DF93EC01613069F06230B1F440E16DE025
478 | :101DD0000E942C0E47EA6EE0CE010E942C0E42E6D5
479 | :101DE00015C042E26DE00E942C0E41EB6EE0CE0188
480 | :101DF0000E942C0E4BE30AC041E26DE00E942C0EC3
481 | :101E000042E66EE0CE010E942C0E46E76FE0CE0166
482 | :101E1000DF91CF910C942C0ECF93DF93EC014EE227
483 | :101E200060E00E942C0E4EE261E0CE010E942C0E7A
484 | :101E300046E062E0CE010E942C0E47E063E0CE0156
485 | :101E40000E942C0E4DE366E0CE010E942C0E44E071
486 | :101E500067E0CE010E942C0E45E068E0CE010E94B2
487 | :101E60002C0E47E465EBCE010E94C60E6FEFCE014B
488 | :101E70000E94D70E60E0CE010E94DB0E48E06BE0CE
489 | :101E8000CE010E942C0E40E06CE0CE010E942C0E90
490 | :101E900062E0CE010E94DF0E4AEC60E1CE010E94BA
491 | :101EA0002C0E43E861E1CE010E942C0E43E962E171
492 | :101EB000CE010E942C0E42E263E1CE010E942C0E64
493 | :101EC00048EF64E1CE010E942C0E45E365E1CE01AE
494 | :101ED0000E942C0E47E066E1CE010E942C0E40E2EB
495 | :101EE00067E1CE010E942C0E48E168E1CE010E941C
496 | :101EF0002C0E46E169E1CE010E942C0E4CE66AE10F
497 | :101F0000CE010E942C0E43E46BE1CE010E942C0E08
498 | :101F100040E46CE1CE010E942C0E41E96DE1CE015E
499 | :101F20000E942C0E47E86EE1CE010E942C0E4BE67B
500 | :101F30006FE1CE010E942C0E4BEF60E2CE010E94B9
501 | :101F40002C0E46E561E2CE010E942C0E40E162E2D9
502 | :101F5000CE010E942C0E49EE63E2CE010E942C0EAF
503 | :101F60004AE264E2CE010E942C0E40E065E2CE011E
504 | :101F70000E942C0E4FE166E2CE010E942C0E41E43D
505 | :101F800067E2CE010E942C0E40E068E2CE010E9482
506 | :101F90002C0E49E569E2CE010E942C0E4FE76AE261
507 | :101FA000CE010E942C0E4FE36BE2CE010E942C0E5C
508 | :101FB00041E86CE2CE010E942C0E45E36DE2CE01B9
509 | :101FC0000E942C0E49E06EE2CE010E942C0E40ECE5
510 | :101FD0006EE3CE01DF91CF910C942C0ECF93DF9363
511 | :101FE000EC012A9A85E090E00E9415072A988AE081
512 | :101FF00090E00E9415072A9A89E290E00E94150756
513 | :102000002A981C99FECF60E3CE010E94B9111C9959
514 | :10201000FECF2A9ACE01DF91CF910C940C0FCF9373
515 | :10202000DF93EC010E949A1160E082E00E94840735
516 | :10203000CE01DF91CF910C94EE0FEF92FF921F93A0
517 | :10204000CF93DF93EC017B01142F4E3308F01DE397
518 | :1020500064E3CE010E94790E40EC65E3CE010E945C
519 | :10206000800E982F9F719D3021F08131A9F76AE38E
520 | :10207000F0CF84EF91E00E941507412F6FE3CE016E
521 | :102080000E942C0E212FA7016FE3CE010E94470E64
522 | :1020900065E3CE010E94790E40EC65E3CE010E941B
523 | :1020A000800E8F718351833070F066E3CE010E9401
524 | :1020B000790E6BE3CE010E94790E64E3CE010E949B
525 | :1020C000790E80E01DC04A9BFECF4A99FECF0000EA
526 | :1020D0001C8240EC6AE3CE010E94800E8F7751F0A3
527 | :1020E0006BE3CE010E94790E66E3CE010E94790E69
528 | :1020F00010E001C011E064E3CE010E94790E812F4F
529 | :10210000DF91CF911F91FF90EF9008952F923F9212
530 | :102110004F925F926F927F928F929F92AF92BF92F7
531 | :10212000CF92DF92EF92FF920F931F93CF93DF93A3
532 | :1021300000D01F92CDB7DEB79B838A831B014983F2
533 | :102140002801390164E30E94790E40EC65E38A813D
534 | :102150009B810E94800E982F9F719D3031F08131BC
535 | :10216000A1F76AE38A819B81EECF84EF91E00E9420
536 | :1021700015076BE38A819B810E94790E65E38A8152
537 | :102180009B810E94790E40EC65E38A819B810E94CD
538 | :10219000800E8F71835166E3833070F08A819B815A
539 | :1021A0000E94790E64E38A819B810E94790E60E02F
540 | :1021B00070E080E090E054C08A819B810E94790E9B
541 | :1021C00042E267E18A819B810E942C0E65E38A814D
542 | :1021D0009B810E94790E0E94BE064B015C01C12CBE
543 | :1021E000D12C76010E94BE06DC01CB018819990929
544 | :1021F000AA09BB0984159505A605B705B8F48FEFA4
545 | :10220000C81AD80AE80AF80A49816FE38A819B81D3
546 | :102210000E942C0E2981A1016FE38A819B810E947B
547 | :10222000470E4A9BFECF4A99FECFDCCF0000EA81E1
548 | :10223000FB81148266E3CF010E94790E40E267E1E0
549 | :102240008A819B810E942C0E6BE38A819B810E9474
550 | :10225000790E64E38A819B810E94790EB601C701E1
551 | :102260000F900F900F90DF91CF911F910F91FF90E2
552 | :10227000EF90DF90CF90BF90AF909F908F907F9026
553 | :102280006F905F904F903F902F900895EF92FF9244
554 | :102290001F93CF93DF936115710509F444C07B014F
555 | :1022A000EC0140EC6BE30E94800E982F9F7711F4B5
556 | :1022B00010E02BC087FDFCCF40E86FE3CE010E9409
557 | :1022C000800E182F8FEF810F8D3390F7212F4FE362
558 | :1022D000B701CE010E94920E40E86FE3CE010E944A
559 | :1022E000800E87FD8095898389818695865B8983A9
560 | :1022F00040E86FE3CE010E94800E982F9F779A836B
561 | :10230000982F991F9927991F9B8366E3CE010E94FE
562 | :10231000790E6AE3CE010E94790E64E3CE010E9439
563 | :10232000790E812F01C080E0DF91CF911F91FF9046
564 | :10233000EF90089561E08AE00E94C00761E08AE0C2
565 | :102340000E94840761E08BE00E94840760E08CE0DB
566 | :102350000E94840761E08DE00E94840761E08DE0C7
567 | :102360000E94C00760E08BE00E94C00780E58CBD42
568 | :1023700008956EBD0DB407FEFDCF8EB50895F89497
569 | :102380000C941112FB01DC0104C08D9101908019A5
570 | :1023900021F441505040C8F7881B990B0895A1E2E1
571 | :1023A0001A2EAA1BBB1BFD010DC0AA1FBB1FEE1FCF
572 | :1023B000FF1FA217B307E407F50720F0A21BB30B1A
573 | :1023C000E40BF50B661F771F881F991F1A9469F796
574 | :1023D00060957095809590959B01AC01BD01CF01F2
575 | :1023E00008950E940212A59F900DB49F900DA49F86
576 | :1023F000800D911D11240895EE0FFF1F0590F4919B
577 | :10240000E02D0994A29FB001B39FC001A39F700D5E
578 | :10241000811D1124911DB29F700D811D1124911DEC
579 | :10242000089511E0CEEAD1E004C0FE010E94FC1143
580 | :0C2430002196CF3AD107C9F7F894FFCFEE
581 | :10243C00476F7420756E6B6E6F776E20706B7400C7
582 | :10244C002C006F75742033320020460D0A00434F68
583 | :10245C004D4D44006F75742000696E2000696E202C
584 | :10246C0030202100696E20435243206572726F72D6
585 | :10247C002E20706B745F73697A653D00000000005C
586 | :10248C002E0AF007D709030AE709230A0000000007
587 | :0C249C007B0CF007CE0BA50BBB0B1F0D3B
588 | :00000001FF
589 |
--------------------------------------------------------------------------------
/usb2rf/usb2rf.ino:
--------------------------------------------------------------------------------
1 | // WARNING: the USB-to-RF module does NOT have rfboot as bootloader
2 | // But the bootloader wich is preinstalled with the module
3 | // Normally this is a ProMini 3.3V with ATmegaBOOT
4 | // Again: Do not replace the bootloader of the USB-to-RF module
5 |
6 | // WARNING:
7 | // Some USB to serial adapters do not
8 | // have a unique serial ID. If we only have one such module then is OK
9 | // but if we have more than one connected to the PC at the same time
10 | // it will be hard to choose the correct one.
11 | // FTDI chips have unique serial IDs but at least the red 1-2$ modules (almost certainly fake chips)
12 | // have some reliability problems.
13 | // I prefet to use CP2102 which does not ship with unique ID, but you can program
14 | // one easily
15 | // http://cp210x-program.sourceforge.net/
16 | // I have a CP2104 module and seems to have a unique ID from the factory.
17 |
18 |
19 | #define PAYLOAD 32
20 |
21 | #include
22 | mCC1101 rf;
23 |
24 | // a flag that a wireless packet has been received
25 | // Handle interrupt from CC1101 GDO0 <--> D2(INT0)
26 | void cc1101signalsInterrupt(void) {
27 | rf.interrupt = true;
28 | }
29 |
30 | // Seems the AltSoftSerial does better than SoftSerial @ 8MHz
31 | // Anything more than 19200 baud @ 8MHz seems unreliable
32 | // Uses fixed pins
33 | // To enable debug output you need to attach a second USB serial dongle "debug serial module"
34 | // open with gtkterm 19200 baud. F7 enables/disables debug output
35 | // D8(RX) <---> Debug SerialModule TX (no need to connect)
36 | // D9(TX) <---> SerialModule2 RX
37 | // D10 pwm is unusable (no problem, we dont need it, and it is used by SPI anyway)
38 | // D4 <----> DTR (to enable disable debug with F7)
39 | // GND <----> GND no need if both usb2serial are connected to the same PC. All USB ports share
40 | // the same ground
41 | // https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
42 | // https://github.com/PaulStoffregen/AltSoftSerial
43 | #include
44 | AltSoftSerial debug_port;
45 |
46 | // The digitalRead, digitalWrite function is slow
47 | // and we use it extensivelly for the debug function
48 | // so we prefer digitalReadFast.
49 | // https://github.com/NicksonYap/digitalWriteFast
50 | #include
51 |
52 | #define RESET_TRIGGER_PIN 3
53 |
54 | #define DEBUG_PIN 4
55 |
56 | #define debug not digitalReadFast(DEBUG_PIN)
57 |
58 | void(* resetFunc) (void) = 0;
59 | uint32_t silence_timer ;
60 |
61 | void drain_serial() {
62 | while ( Serial.read()!=-1 ) {};
63 | }
64 |
65 | void upload(uint16_t app_idx) {
66 | // Upload mode
67 | // Offloads some of the work rftool does
68 | // to improve latency
69 | // These are the status codes rfboot is sending back to the programmer
70 | const uint8_t RFB_SEND_PKT = 4;
71 | const byte USB_SEND_PACKET = 20;
72 | const byte USB_INFO_RESEND = 21;
73 | const byte USB_INFO_END = 22;
74 | //const byte USB_INFO_ABORT = 21;
75 | uint32_t timer = millis();
76 |
77 | byte outpacket[64];
78 | bool rfboot_waiting = true;
79 | bool outpacket_ready = false;
80 | Serial.write(USB_SEND_PACKET); // want 1 packets
81 | while (1) { // and (millis()-timer<1000) TODO
82 |
83 | if (millis()-timer>100) {
84 | if (debug) debug_port.print(F("upload: Timeout"));
85 | Serial.write(USB_INFO_END);
86 | return;
87 | }
88 |
89 | if ( (not outpacket_ready) and (Serial.available()>=PAYLOAD) ) {
90 | outpacket_ready = true;
91 | Serial.readBytes((char*)outpacket, PAYLOAD);
92 | if (app_idx>PAYLOAD) Serial.write(USB_SEND_PACKET); // TODO
93 | if (debug) {
94 | debug_port.print(F("Savail="));
95 | debug_port.println(Serial.available());
96 | }
97 | }
98 |
99 | if (rfboot_waiting and outpacket_ready) {
100 | rf.sendPacket(outpacket,PAYLOAD);
101 | // outpacket is not market as ready yet
102 | // it will when rfboot asks for next packet
103 | rfboot_waiting=false;
104 | if (debug) {
105 | debug_port.print(F("pkt out : idx="));
106 | debug_port.println(app_idx);
107 | //if (sending_header) debug_port.println(F("This was the header"));
108 | }
109 | }
110 |
111 | if (rf.interrupt) {
112 | byte inpacket[64];
113 | byte pkt_size = rf.getPacket(inpacket);
114 | rf.interrupt = false;
115 | if (pkt_size==3 and rf.crc_ok) {
116 | timer = millis(); // reset the timer
117 | // we just got a 3 byte packet from rfboot
118 | byte cmd = inpacket[0];
119 |
120 | if (cmd==RFB_SEND_PKT) {
121 | uint16_t i=inpacket[1]+inpacket[2]*256;
122 | if (i==app_idx) {
123 | // rfboot needs the same packet
124 | rf.sendPacket(outpacket,PAYLOAD);
125 | rfboot_waiting = false;
126 | Serial.write(USB_INFO_RESEND); // inform the resent
127 | if (debug) {
128 | debug_port.println(F("Resend"));
129 | }
130 | }
131 | else if (i==app_idx-PAYLOAD) { // next packet
132 |
133 | if (debug) debug_port.println(F("ok next pkt"));
134 | rfboot_waiting = true;
135 | app_idx = i;
136 | outpacket_ready = false;
137 | }
138 | else {
139 | if (debug) {
140 | debug_port.print(__LINE__);
141 | debug_port.print(F(": Protocol error. app_idx="));
142 | debug_port.print(i);
143 | debug_port.print(F(", but expected "));
144 | debug_port.print(app_idx-PAYLOAD);
145 | debug_port.print(F(" or "));
146 | debug_port.print(app_idx);
147 | }
148 | drain_serial();
149 | Serial.write(USB_INFO_END);
150 | Serial.write(inpacket,3);
151 | return; // ABORT
152 | }
153 | }
154 | else {
155 |
156 | drain_serial();
157 | // Uncknown cmd
158 | Serial.write(USB_INFO_END);
159 | Serial.write(inpacket,3);
160 |
161 | return; // ABORT
162 | }
163 | //}
164 | }
165 | else {
166 | if (debug) debug_port.print("Got unknown pkt"); // TODO pkt_size crc_ok
167 |
168 | }
169 | }
170 | }
171 | if (debug) {
172 | debug_port.print("app_idx="); debug_port.println(app_idx);
173 | debug_port.print(F("Serial.available()="));
174 | debug_port.println(Serial.available());
175 | }
176 | }
177 |
178 | void execCmd(uint8_t* cmd , uint8_t cmd_len ) {
179 |
180 | switch (cmd[0]) {
181 |
182 | case '0':
183 | if (cmd_len==1) {
184 | if (debug) {
185 | debug_port.print(F("CC1101 register = "));
186 | debug_port.println(rf.readConfigReg(CC1101_MDMCFG2),HEX);
187 | }
188 | }
189 | else {
190 | if (debug) {
191 | debug_port.print(F("Custom command, bad length : "));
192 | debug_port.println(cmd_len);
193 | }
194 | }
195 | break;
196 |
197 | case 'A':
198 | if (cmd_len==3) {
199 | rf.setSyncWord(cmd[1],cmd[2]);
200 | if (debug) {
201 | debug_port.print(F("Syncword = "));
202 | debug_port.print(cmd[1]) ;
203 | debug_port.print(",");
204 | debug_port.println(cmd[2]);
205 | }
206 | }
207 | else {
208 | if (debug) {
209 | debug_port.print(F("cc1101 wrong cmd size "));
210 | debug_port.println(cmd_len);
211 | }
212 | }
213 | break;
214 |
215 | case 'C': // We set channel
216 | {
217 | if (cmd_len!=2) {
218 | if (debug) {
219 | debug_port.print(F("Channel command wrong size : "));
220 | debug_port.println(cmd_len);
221 | }
222 | }
223 | else {
224 | uint8_t channel = cmd[1];
225 |
226 | {
227 | rf.setChannel(channel);
228 | if (debug) {
229 | debug_port.print(F("channel="));
230 | debug_port.println(channel);
231 | }
232 | }
233 | }
234 | }
235 | break;
236 |
237 | case 'Q':
238 | if (cmd_len==1) {
239 | if (debug) {
240 | debug_port.println(F("Silent for 50ms"));
241 | silence_timer = millis();
242 | }
243 | resetFunc();
244 | }
245 | else {
246 | if (debug) {
247 | debug_port.print(F("Silent command, bad length : "));
248 | debug_port.println(cmd_len);
249 | }
250 | }
251 | break;
252 |
253 | case 'R': // MCU hardware reset
254 | {
255 | if (cmd_len!=1) {
256 | if (debug) {
257 | debug_port.print(F("MCU reset command wrong size : "));
258 | debug_port.println(cmd_len);
259 | }
260 | }
261 | else {
262 | if (debug) {
263 | debug_port.println(F("USB to RF Reset"));
264 | }
265 | rf.setSyncWord(0,0);
266 |
267 | digitalWriteFast(RESET_TRIGGER_PIN,LOW);
268 | pinModeFast(RESET_TRIGGER_PIN, OUTPUT); // reset the module because D4 is connected with RESET pin. See circuit diagram
269 | // the following command will be executed only if the module fails to reset
270 | debug_port.println(F("Usb2rf module failed to reset"));
271 | }
272 | }
273 | break;
274 |
275 |
276 | case 'U':
277 | if (cmd_len==3) {
278 | if (debug) {
279 | debug_port.println(F("Switch to upload mode"));
280 | //debug_port.flush();
281 | }
282 | // Perimeno size
283 | uint16_t app_idx=cmd[1]+cmd[2]*256;
284 | //debug_port.println( Serial.available() );
285 | upload(app_idx);
286 | }
287 | else {
288 | if (debug) {
289 | debug_port.print(F("Upload code command, bad length : "));
290 | debug_port.println(cmd_len);
291 | }
292 | }
293 |
294 | break;
295 |
296 | case 'W':
297 | // send wake up 1 sec pulse
298 | if (cmd_len==2) {
299 | if (debug) {
300 | debug_port.println(F("Sending WakeUp burst 1050ms"));
301 | }
302 | const byte w=cmd[1];
303 | rf.sendBurstPacket(&w,1,1050);
304 | if (debug) {
305 | debug_port.println(F("Done"));
306 | }
307 | }
308 | break;
309 |
310 | case 'Z':
311 | if (cmd_len==1) {
312 | if (debug) {
313 | debug_port.println(F("Software reset"));
314 | debug_port.flush();
315 | }
316 | rf.setSyncWord(0,0);
317 | resetFunc();
318 | }
319 | else {
320 | if (debug) {
321 | debug_port.print(F("Software reset command, bad length : "));
322 | debug_port.println(cmd_len);
323 | }
324 | }
325 | break;
326 |
327 | default:
328 | if (debug) {
329 | debug_port.print(F("Unknown command "));
330 | debug_port.write(cmd,cmd_len);
331 | debug_port.println();
332 | }
333 | break;
334 | }
335 | }
336 |
337 |
338 | int main() {
339 |
340 | init(); // mandatory, for arduino functions to work
341 |
342 | pinMode(DEBUG_PIN,INPUT_PULLUP);
343 | //Serial.begin(57600);
344 | Serial.begin(38400);
345 |
346 | debug_port.begin(19200);
347 | //delay(1);
348 |
349 | rf.init();
350 | //rf.setCarrierFreq(CFREQ_433);
351 | rf.disableAddressCheck();
352 | rf.setSyncWord(57,232);
353 | attachInterrupt(0, cc1101signalsInterrupt, FALLING);
354 |
355 | rf.writeReg(CC1101_MDMCFG2, 0x97);
356 |
357 | //if (debug)
358 | //delay(8);
359 | debug_port.println(F("Usb2rf debug port at 19200 bps. Assert DTR "));
360 | debug_port.println(F("(F7 key with gtkterm) to enable/disable debug output"));
361 |
362 | uint8_t idx = 0;
363 | uint32_t timer = micros();
364 | bool cmdmode = false;
365 | delay(5);
366 | Serial.println(F("USB2RF"));
367 |
368 | //bool last_debug = not debug;
369 | bool last_debug = false;
370 | uint8_t packet[64];
371 |
372 | while (1) {
373 | if (debug != last_debug) {
374 | last_debug = debug;
375 | debug_port.print(F("debug messages "));
376 | if (debug) debug_port.println(F("enabled"));
377 | else debug_port.println(F("disabled"));
378 | }
379 | if (cmdmode) {
380 | if (Serial.available()) {
381 |
382 | uint8_t msg = Serial.read();
383 | packet[idx]=msg;
384 | idx++;
385 | if (idx==32) {
386 | idx=0;
387 | cmdmode=false;
388 | }
389 | timer = micros();
390 | }
391 | else if (micros()-timer>2000) {
392 | if (idx>0) {
393 | execCmd(packet,idx);
394 | }
395 | cmdmode=false;
396 | idx=0;
397 | timer=micros();
398 | }
399 | }
400 | else {
401 | if (Serial.available()) {
402 |
403 | uint8_t msg = Serial.read();
404 |
405 | packet[idx]=msg;
406 | idx++;
407 | if (idx==32) {
408 |
409 |
410 | if (debug) debug_port.write("out 32");
411 |
412 | bool succ = rf.sendPacket(packet,32);
413 |
414 | if ( debug ) {
415 | if (succ) debug_port.write("\r\n");
416 | else debug_port.write(" F\r\n");
417 | }
418 | //while (! interrupt);
419 | //interrupt = false;
420 |
421 |
422 | if ( debug and (!succ) ) debug_port.println(F("Sending packet failed"));
423 |
424 | idx=0;
425 | }
426 | else if (idx==5 and memcmp(packet,"COMMD",5)==0 ) {
427 | cmdmode = true;
428 | idx=0;
429 | }
430 | timer = micros();
431 | }
432 |
433 | else if (idx==0) {
434 | timer=micros();
435 | }
436 |
437 | else if (micros() - timer > 2000) {
438 | {
439 |
440 | if (debug) {
441 | debug_port.write("out ");
442 | debug_port.print(idx);
443 | }
444 |
445 | bool succ;
446 |
447 | succ = rf.sendPacket(packet,idx);
448 |
449 | if ( debug ) {
450 | if (succ) debug_port.write("\r\n");
451 | else debug_port.write(" F\r\n");
452 | }
453 | }
454 | timer = micros();
455 | idx=0;
456 | }
457 | }
458 |
459 | if (rf.interrupt) {
460 | byte pkt_size = rf.getPacket(packet);
461 | rf.interrupt = false;
462 |
463 | if (rf.crc_ok) {
464 | if ( pkt_size > 0) {
465 | //else {
466 | // Afti i grammi diorthonei to 5088 bug pou akoma den kserw pou ofeiletai
467 | // pantos o bootloader stelnei olososto paketo kai o kwdikas to vlepei kanonika
468 | // wstoso to 4,224,19 stanei sto PC mono san 4,224
469 | // if (ccpacket.length==3 and ccpacket.data[0]==4 and ccpacket.data[2]<=19) ccpacket.data[2]+=128;
470 |
471 | /* if (pkt_size==8) {
472 | for (byte i=0;i<8;i++) {
473 | if (packet[i]<16) Serial.write('0');
474 | Serial.print(packet[i], HEX);
475 | Serial.write(' ');
476 | }
477 | Serial.println();
478 | }
479 | else {
480 | Serial.write(packet, pkt_size);
481 | } */
482 | Serial.write(packet, pkt_size);
483 |
484 | if (debug) {
485 | debug_port.write("in ");
486 | //if (pkt_size != 3)
487 | debug_port.println(pkt_size);
488 | }
489 | //}
490 | }
491 | else if (debug) {
492 | debug_port.println("in 0 !");
493 | }
494 | }
495 | else {
496 | if (debug) {
497 | debug_port.write("in CRC error. pkt_size=");
498 | debug_port.println(pkt_size);
499 | }
500 | }
501 | }
502 |
503 | }
504 | }
505 |
506 |
--------------------------------------------------------------------------------