aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 76b77f789c5ac352b9710166f1463e6a84fbab7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Altimeter thingo

## Getting Started

### Submoule checkout

This repo uses the [Unity](http://www.throwtheswitch.org/unity) unit testing
library, as well as Bosch's BMP3 Sensor API, which are included as submodules.
You must therefore do a recursive clone when cloning this repo initially, e.g.:

	git clone --recursive https://git.nah.nz/altimeter/

or later come along and check out the submodules if you didn't perform a
recursive clone initially:

	git submodule init && git submodule update


### Dependencies

Bare minimum, you will need:

* make
* avr-gcc
* avr-libc

If you want to flash to a real board, you will need:

* avrdude

If you want to simulate a mock/fake version of the software on a virtual AVR
before flashing, you will need:

* qemu-avr

### Test

In order to build and run the unit tests without building ELFs or HEXs:

	$ make test

Otherwise, unit tests are always run as the final part of the `make all` recipe
below and will fail the build if they do not pass.

### Build

	$ make all
	...
	$ file build/altimeter*.elf
	build/altimeter.elf:     ELF 32-bit LSB executable, Atmel AVR 8-bit, version 1 (SYSV), statically linked, with debug_info, not stripped
	build/altimeter_sim.elf: ELF 32-bit LSB executable, Atmel AVR 8-bit, version 1 (SYSV), statically linked, with debug_info, not stripped

### Run mock/sim build of software in QEMU

The sim build of the software has peripherals mocked out so that the software
can run in QEMU, where the only peripherals available on the AVR are timers and
the USART controller.

Thus, the sim build isn't very useful for hacking on I/O driver code, but is
perfectly fine for higher level logic, such as UI and business logic.

A simulated barometer is provided, which cycles through some preset pressure
values each time it is asked for pressure. The HD44780 LCD is replaced with a
thin UART driver instead, which QEMU puts on stdout.

	$ make emu

and from a separate terminal, attach GDB. Optionally set breakpoints before
unpausing qemu:

	$ make gdb
	(gdb) cont

You should see some activity in the emulated serial output back on the first
terminal. Use GDB as normal to play/pause/debug the software. Ctrl+C and k to
end QEMU.

### Flash good software to chip

With the board reset into programming mode, run avrdude through the makefile
recipe:

	$ make flash PORT=/dev/ttyACMx

...replacing `/dev/ttyACMx` with the right tty device that shows up when you
put your microcontroller into programming mode.