====== Elbow ======
{{template>:project:infobox|
name=Elbow|
image=elbow.jpg?200|
founder=[[user:b00lean]]|
interested=[[user:niekt0]]\\ [[user:harvie]]|
hw=|
sw=|
status=done}}
~~META:
status = done
&relation firstimage = :project:elbow.jpg
~~
General purpose open-source ARM based MCU peripheral controled via USB.\\
Allows cheap and easy way to control input/outputs of arm7 based device from host computer via USB.\\
Price for building such device should not exceed 500 CZK (25 USD).\\
===== Motivation =====
- To learn and play with ARM processor
- To create an usefull peripheral as a possible platform for future USB based toys.
===== Specification =====
* API which Elbow device offers to host computer:
* Read/Write input values from/to GPIO
* Read/Write from/to device FLASH/RAM
* Generate pulse of specified length in milliseconds on GPIO
* Check connection with elbow device
* Read device serial number
* Write once device serial number
* Read 1-wire Dallas chip information
* Read device firmware version
* Selected technologies:
* Elbow Device Hardware:
* MCU: AT91SAM7S [[http://www.atmel.com/dyn/products/product_card.asp?part_id=3524|AT91SAM7S256 or AT91SAM7S512]]
* Board: [[http://www.kramara.com/?q=node/16|AT91SAM7S256-KIT]]/[[http://www.kramara.com/?q=node/27|AT91SAM7X512_KIT]]/[[http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3784|AT91SAM7S256-EK]]
* Connection to host: USB
* Elbow Device Software:
* Compiler: [[http://www.gnuarm.com/|gnuarm(GCC)]]
* OS: [[http://www.freertos.org/|FreeRTOS]]
* Elbow Host Software:
* Supported OS: Linux
* IDE: [[http://www.eclipse.org|Eclipse]] (C+Java)
* Driver model: ttyACM (serial communication via USB)
* Software library: [[http://www.java.com|Java]] [[http://www.rxtx.org/|RxTx]]
===== Phases of project =====
==== Preparation ====
- Buy module board - **DONE AT91SAM7S256-KIT**
- Buy JTAG adapter - **DONE**
- Try compiling and running tutorials with GCC - **DONE**
- Try compiling and running FreeRTOS tutorial - **DONE**
- Write USB communication example - **DONE**
- Find out how to connect to JTAG with OpenOCD - **DONE**
- Try to debug with JTAG+OpenOCD+GDB - **DONE**
- Find out how to flash program via JTAG. - **DONE**
- Setup IDE(Eclipse CDP) for project with armGCC. - **DONE**
- Configure Eclipse IDE with GDB+OpenOCD - **DONE**
- Write and test firmware that sends and receives commands to host via USB - **DONE**
- Buy prototyping board+wires+LEDs+resistors+buttons - **DONE**
- Try writing and reading inputs/outputs **DONE**
{{:project:elbow_prototype_alpha.jpg?200}}
{{:project:elbow_prototype_beta.jpg?354}}
==== HW implementation ====
- Device should be powered via USB (needs to be stabilized to 3.3V) - **DONE**
- Add power loss aware circuit - **DONE**
- LEDs/Buttons should be connected to GPIO using 12V. **DONE**
- Connect DS2401 connector **DONE**
- Connect relays **DONE**
- Make my own board
==== SW implementation ====
- Implement 1st set of basic commands:
* Check connection with elbow device - **DONE** Command: PING
* Read device firmware version - **DONE** Command: VERSION
- Implement 2nd set of commands:
* Write once device serial number - **DONE** Command: SETSERIAL 12345678
* Read device serial number - **DONE** Command: GETSERIAL
* Read/Write input values on/to GPIO. - **DONE** Commands: CFGIO, SETIO, CLRIO
- Implement 3rd set of commands:
* Read 1-wire Dallas chip information (serial/temperature) - **DONE** Commands: GETSERIAL x, GETTEMP x
* Generate pulse by specified length in milliseconds on GPIO - **DONE** Commands: PULSE x m
- Implement 4th set of commands:
* Read/Write to device FLASH/RAM - **DONE** Commands: FLASHWRITE, FLASHREAD, RAMREAD, RAMWRITE
* Reporting of input values change on a pin - **DONE** Commands: EIOIRQ, DIOIRQ
- Add power loss detection and RAM persistence. - **DONE**
- Implement Java library that communicates with elbow
* Implement direct connection via ttyACM support - **DONE**
* Write and run functionality tests. - **DONE** (some bugs fixed)
* Write and run stress tests (concurrency+fast queries). - **DONE**
* Implement tests for interrupt messages IOIRQ, SAFERAM
* Implement TCP connection support
====== COMMUNICATION PROTOCOL ======
How to talk to ELBOW:
b00lean@hcooh:~$ echo "PING" > /dev/ttyACM0
How to listen to ELBOW:
b00lean@hcooh:~$ cat /dev/ttyACM0
Interactive mode:
harvie@insomnia ~ $ minicom -D /dev/ttyACM0
===== Commands =====
Legend: \\
C = Computer \\
E = ELBOW \\
How to check that elbow is alive:
C> PING
E> PONG
Get Elbow version:
C> VERSION
E> VERSION ELBOW 1.0.2
Get Elbow serial number:
C> GETSERIAL
E> SERIAL 12345678
Set Elbow serial number:
C> SETSERIAL 12345678
E> SERIAL 12345678
Read Elbow's current GPIO configuration: \\
This command returns configuration of every IO pin output (32) \\
Legend: \\
O = output
I = input
F = input with glitch filter
P = input with pull-up resistor(10kOhm)
A = input with pull-up resistor and glitch filter
Letter in uppercase means that pin is permitted.
Letter in lowercase means pin is not permitted.
C> CFGIO
E> CFGIO FOOOPPPPPPPPPPPPOPfPPPPPPIIioAOP
Configure Elbow's GPIO: \\
C> CFGIO iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
E> CFGIO OK
Reading all Elbow's inputs: \\
C> GETIO
E> GETIO 10011111111111110111111111111101
Setting all Elbow's outputs to logical 1: \\
C> SETIO 11111111111111111111111111111111
E> SETIO OK
Setting all Elbow's outputs to logical 0: \\
C> CLRIO 11111111111111111111111111111111
E> CLRIO OK
Sending pulse on pin 8 of specified duration 100ms(sending oposite state than is current for specified duration): \\
C> PULSE 8 100
E> PULSE OK
Enable input value change on input pin number 3 reporting and report value after 100 continuous reads. \\
In example elbow is reporting that on pin 3 level changed to logical 1
C> EIOIRQ 3 100
E> EIOIRQ OK
E> IOIRQ 3 1
Disable input value change on input pin number 3 reporting
C> DIOIRQ 3
E> DIOIRQ OK
Get 1-wire chip serial number connected to pin 8 (PA08):
C> GETSERIAL 8
E> SERIAL 000002950dcd
if chip is not found:
E> SERIAL EMPTY
Get 1-wire chip temperature connected to pin 8 (PA08):
C> GETTEMP 8
E> TEMP 22.6
if chip is not found:
E> TEMP EMPTY
How to read 10 bytes from device user reserved RAM(20kB) from offset 0
C> RAMREAD 0 10
E> RAMREAD OK
E> datadatadata
E> EOF
How to read 10 bytes from device user reserved FLASH(64kB) from offset 0
C> FLASHREAD 0 10
E> FLASHREAD OK
E> datadatadata
E> EOF
How to write 10 bytes to device user reserved RAM(20kB) to offset 0
C> RAMWRITE 0 10
E> RAMWRITE READY
C> datadatadata
E> RAMWRITE OK
How to write 10 bytes to device user reserved RAM(64kB) to offset 0
C> FLASHWRITE 0 10
E> FLASHWRITE READY
C> datadatadata
E> FLASHWRITE OK
How to make sure that if power is lost on pin 4(turns to logical 0) first 256 bytes of RAM will be stored in internal flash memory before the device dies on power loss:
C> ESAFERAM 4
E> ESAFERAM OK
When power loss occurs elbow will try to send message on usb:
E> SAFERAM SAVED
How to restore saved 256 bytes of data from flash to RAM:
C> RSAFERAM
E> RSAFERAM OK
====== PINOUTS ======
1. ADVref44. Vcc
2. AD4 43. Vcc
3. AD5 42. DDP
4. AD6 41. DDM
5. AD7 40. PA31?
6. PA17 39. PA0
7. PA18 38. PA1
8. PA21 37. PA2
9. PA19 36. PA3
10. PA22 35. PA30
11. PA23 34. PA29
12. PA20 33. RESET
13. PA16! 32. PA28
14. PA15 31. PA27
15. PA14 30. PA4
16. PA13 29. PA5
17. PA24 28. PA6
18. PA25 27. PA7
19. PA26 26. PA8
20. PA12 25. PA9*
21. GND 24. PA10*
22. GND 23. PA11!
! - reserved for USB detection
* - used also for JTAG
? - used for alive signalization (blinking diode - output)