Tilman Sauerbeck [Sun, 5 Jan 2020 18:48:54 +0000 (19:48 +0100)]
application: Make system reset less likely do be run by accident.
System reset is now triggered by holding the upper left and the
lower right push button at the same time.
Tilman Sauerbeck [Sun, 5 Jan 2020 18:46:08 +0000 (19:46 +0100)]
application: Configure the remaining push buttons.
Tilman Sauerbeck [Sun, 5 Jan 2020 18:33:32 +0000 (19:33 +0100)]
application: Factor out the configure_push_buttons() function.
Tilman Sauerbeck [Sun, 5 Jan 2020 18:23:39 +0000 (19:23 +0100)]
application: Factor out the reset_requested() function.
No change in behavior.
Tilman Sauerbeck [Sun, 5 Jan 2020 18:18:26 +0000 (19:18 +0100)]
application: Set up pins for the MX25L flash memory.
This configures SPI0 as well as the GPIO used as the flash's
chip select line.
Tilman Sauerbeck [Sun, 5 Jan 2020 17:53:58 +0000 (18:53 +0100)]
common: Implement Storage::read() in Mx25l.
Tilman Sauerbeck [Mon, 6 Jan 2020 09:44:21 +0000 (10:44 +0100)]
common: Add the storage module.
Tilman Sauerbeck [Sat, 4 Jan 2020 18:29:57 +0000 (19:29 +0100)]
application: Perform system reset from panic handler if requested.
This is untested; I'm not sure if it would work at all.
Tilman Sauerbeck [Sat, 4 Jan 2020 18:19:02 +0000 (19:19 +0100)]
common: Add the mx25l module.
Provides access to the status register and device ID only for now.
Tilman Sauerbeck [Sat, 4 Jan 2020 18:15:08 +0000 (19:15 +0100)]
common: Accept DGPS fix information.
We used to reject differential GPS (DGPS) fixes as invalid, but they
are actually more accurate than standard GPS fixes.
Tilman Sauerbeck [Sat, 4 Jan 2020 17:24:44 +0000 (18:24 +0100)]
common: Increase size of the UART receive ringbuffer.
The GPS module sends about ~380 bytes per second, which led to
overflows of our 256 byte sized ringbuffer.
Tilman Sauerbeck [Sat, 4 Jan 2020 11:00:25 +0000 (12:00 +0100)]
common: Add the spi module.
Tilman Sauerbeck [Fri, 3 Jan 2020 20:42:24 +0000 (21:42 +0100)]
common: Restart NMEA message parsing when a '$' character is seen.
The GPS module sometimes sends incomplete NMEA messages such as this:
$GP$GGA...*
This changeset makes it so we'd only parse the second, complete message
in that example.
Tilman Sauerbeck [Fri, 3 Jan 2020 15:33:15 +0000 (16:33 +0100)]
tools: Pad final chunks with 0xff if necessary.
The bootloader only accepts chunks whose size is a multiple of four.
Tilman Sauerbeck [Fri, 3 Jan 2020 15:09:53 +0000 (16:09 +0100)]
common: Move panic handler out of libcommon.
This allows us to do a native build of libcommon which is useful for
unit testing.
Tilman Sauerbeck [Tue, 31 Dec 2019 12:32:48 +0000 (13:32 +0100)]
application: Show current time on the display if we have a GPS fix.
Tilman Sauerbeck [Thu, 2 Jan 2020 12:32:26 +0000 (13:32 +0100)]
common: Implement Time::fmt_time().
Formats time as HH:MM:SS.
Tilman Sauerbeck [Thu, 2 Jan 2020 12:28:59 +0000 (13:28 +0100)]
common: Add the time module.
This currently only contains the equivalent of gmtime(), which was
adapted from Rich Felker's musl.
Tilman Sauerbeck [Tue, 31 Dec 2019 12:35:35 +0000 (13:35 +0100)]
common: Add the fmt module.
Tilman Sauerbeck [Mon, 30 Dec 2019 18:51:46 +0000 (19:51 +0100)]
common: Implement screen::clear() and screen::draw_text().
This also imports (a subset of) Frederic Cambus' spleen font,
used by screen::draw_text().
Tilman Sauerbeck [Mon, 30 Dec 2019 17:18:08 +0000 (18:18 +0100)]
common: Tweak bit order of screen data.
The left-most pixel is now defined by the most significant bit.
This is a more intuitive representation than what we had before.
Tilman Sauerbeck [Tue, 31 Dec 2019 11:03:50 +0000 (12:03 +0100)]
application: Visualize GPS fix state using the satellite icons.
As long as we are waiting for a GPS fix, we animate the satellite
icons.
Tilman Sauerbeck [Tue, 31 Dec 2019 10:28:58 +0000 (11:28 +0100)]
application: Manage whether or not we have valid GPS fix information.
Expire such information after about 1.5s.
Tilman Sauerbeck [Tue, 31 Dec 2019 09:51:45 +0000 (10:51 +0100)]
application: Blink heart icon to indicate liveness.
Tilman Sauerbeck [Tue, 31 Dec 2019 08:17:08 +0000 (09:17 +0100)]
common: Implement display::show_icon() and display::hide_icon().
This only supports the alarm, heart and satellite icons for now,
but not the battery meter icon.
Tilman Sauerbeck [Mon, 30 Dec 2019 10:39:26 +0000 (11:39 +0100)]
application: Extract time and position from GPS NMEA messages.
Tilman Sauerbeck [Mon, 30 Dec 2019 09:41:00 +0000 (10:41 +0100)]
common: Add the gps module.
Tilman Sauerbeck [Mon, 30 Dec 2019 10:42:42 +0000 (11:42 +0100)]
application: Set up pins for the GPS.
This configures UART0 as well as the GPS' reset line.
Tilman Sauerbeck [Sun, 29 Dec 2019 00:31:08 +0000 (01:31 +0100)]
application: Define UART0_IRQHandler().
Writes received data to the global uart0_rx_buf ringbuffer.
Tilman Sauerbeck [Sat, 28 Dec 2019 22:11:09 +0000 (23:11 +0100)]
common: Add Rust glue for the ringbuf module.
For now this only allows us to access a ringbuffer from Rust
after it has been defined in C code.
Tilman Sauerbeck [Sat, 28 Dec 2019 18:54:46 +0000 (19:54 +0100)]
common: Add the uart module.
Tilman Sauerbeck [Mon, 30 Dec 2019 10:42:18 +0000 (11:42 +0100)]
application: Enable OSC0.
Needed for UART0.
Tilman Sauerbeck [Sat, 28 Dec 2019 18:49:02 +0000 (19:49 +0100)]
common: Implement clock::enable_osc0().
Tilman Sauerbeck [Sun, 29 Dec 2019 11:55:24 +0000 (12:55 +0100)]
build: Use rustc to link the binaries instead of gcc.
This simplifies the build system by removing the need for
libapplication.a, libbootloader.a and the two start.c copies.
Tilman Sauerbeck [Sun, 29 Dec 2019 11:51:25 +0000 (12:51 +0100)]
bootloader: Mark jump_to_application() as noreturn.
Tilman Sauerbeck [Sun, 29 Dec 2019 11:16:49 +0000 (12:16 +0100)]
build: Link libgcc from the command line instead of the linker script.
Pulling it in via the linker script will only work if we use our
C toolchain's linker and would fail if we used the Rust linker.
Tilman Sauerbeck [Sun, 29 Dec 2019 09:56:06 +0000 (10:56 +0100)]
build: Don't link libraries we don't need.
Tilman Sauerbeck [Fri, 20 Dec 2019 20:10:18 +0000 (21:10 +0100)]
application: Initialize and clear the display on startup.
Tilman Sauerbeck [Fri, 20 Dec 2019 20:09:42 +0000 (21:09 +0100)]
application: Set up pins for the display.
This configures I2C0 as well as the GPIO used to control the display's
reset line.
Tilman Sauerbeck [Wed, 18 Dec 2019 08:01:56 +0000 (09:01 +0100)]
common: Add the display module.
It currently can initialize, clear and draw the main area
of the display. Drawing or clearing the icon area is not yet
supported.
Tilman Sauerbeck [Wed, 18 Dec 2019 09:00:22 +0000 (10:00 +0100)]
application: Perform a system reset if PTA12 is pressed.
Tilman Sauerbeck [Wed, 18 Dec 2019 08:59:12 +0000 (09:59 +0100)]
application: Configure PTA12 for push button use.
Tilman Sauerbeck [Wed, 18 Dec 2019 07:46:46 +0000 (08:46 +0100)]
common: Implement nvic::system_reset().
Performs a system reset.
Tilman Sauerbeck [Sun, 8 Dec 2019 17:20:04 +0000 (18:20 +0100)]
bootloader: Never auto-start the application in the intermediate bootloader.
Instead, we now always enter bootloader operation. I think this has
less potential of bricking a device in case you don't press PTE24
fast enough after installing the intermediate bootloader.
Tilman Sauerbeck [Mon, 18 Nov 2019 06:38:24 +0000 (07:38 +0100)]
common: Add the i2c module.
Tilman Sauerbeck [Sun, 17 Nov 2019 20:42:01 +0000 (21:42 +0100)]
bootloader: Call clock::reset() before jumping to the application.
By switching back to FBE clock mode there, we can unconditionally
do the switches to FBE, PBE and PEE in any of our programs.
Tilman Sauerbeck [Sun, 17 Nov 2019 20:34:38 +0000 (21:34 +0100)]
common: Implement clock::reset().
This puts the MCG back into FBE mode.
Tilman Sauerbeck [Sat, 16 Nov 2019 20:54:50 +0000 (21:54 +0100)]
common: Combine writes to SIM_CLKDIV1 in clock::configure_clkdiv().
By setting both CLKDIV1 and CLKDIV4 at the same time we avoid
running the flash at twice the intended clock rate for a couple
of cycles which has been observed to make it read bad data.
Tilman Sauerbeck [Sun, 17 Nov 2019 18:05:39 +0000 (19:05 +0100)]
bootloader: Disable the watchdog.
The watchdog gets enabled with a 1s timeout on POR, and I don't
want to deal with that.
Tilman Sauerbeck [Sat, 16 Nov 2019 18:15:51 +0000 (19:15 +0100)]
common: Add the watchdog module.
For now this only lets us disable the COP watchdog.
Tilman Sauerbeck [Sat, 16 Nov 2019 15:05:11 +0000 (16:05 +0100)]
application: Explicitly enable global interrupts.
The bootloader now longer leaves them enabled before it jumps
to the application, so we need to enable them explicitly.
Tilman Sauerbeck [Sat, 16 Nov 2019 12:16:39 +0000 (13:16 +0100)]
bootloader: Sanitize global interrupt handling.
We now disable interrupts before jumping to application,
as overwriting the VTOR with interrupts enabled is rather risky.
Also don't assume that interrupts are enabled when the bootloader
is run -- enable them explicitly when we need them.
Tilman Sauerbeck [Sat, 16 Nov 2019 10:32:26 +0000 (11:32 +0100)]
common: Implement enable_interrupts() and disable_interrupts().
Tilman Sauerbeck [Sat, 16 Nov 2019 10:11:54 +0000 (11:11 +0100)]
common: Disable the USB interrupt in usb_serial::shutdown().
Tilman Sauerbeck [Sat, 16 Nov 2019 07:42:46 +0000 (08:42 +0100)]
bootloader: Use the same maximum size for both bootloaders.
This sets the maximum size of the intermediate bootloader to the
one that we (have to) use for the final bootloader, too.
I don't see the point in allowing more code in the intermediate
bootloader anymore.
Tilman Sauerbeck [Sun, 10 Nov 2019 17:58:44 +0000 (18:58 +0100)]
bootloader: Reimplement flash::run_command() in C.
While running a flash command that operates on a given flash block,
executing code from that same flash block will cause read-while-write
errors that lock up the core.
Thus we need to ensure that no interrupt handler will execute
during that time, and we also need to relocate the respective
flash code to RAM.
Tilman Sauerbeck [Thu, 7 Nov 2019 21:05:49 +0000 (22:05 +0100)]
bootloader: Use distinct USB PIDs depending on location in flash.
The intermediate bootloader binary (located at 0x8000) now uses
USB PID 0x635b and the final bootloader binary (located at 0x0)
uses USB PID 0x635c.
This lets us find out what binary we're talking to depending on
how it registers on the USB.
Tilman Sauerbeck [Wed, 6 Nov 2019 19:43:52 +0000 (20:43 +0100)]
bootloader: Explicitly initialize the port module.
Don't assume another component does it for us.
Tilman Sauerbeck [Wed, 6 Nov 2019 19:42:54 +0000 (20:42 +0100)]
common: Implement port::init().
This function powers up ports A, B, C, D and E.
Tilman Sauerbeck [Thu, 11 Jul 2019 17:43:02 +0000 (19:43 +0200)]
application: Add humble beginnings of the application code.
This is just a USB serial hello world right now.
Tilman Sauerbeck [Tue, 9 Jul 2019 18:22:23 +0000 (20:22 +0200)]
common: Fix two -Wold-style-declaration warnings.
This fixes the following warnings:
virtual_com.c:105:1: warning: 'static' is not at beginning of declaration
volatile static uint32_t s_recvSize = 0;
^~~~~~~~
virtual_com.c:106:1: warning: 'static' is not at beginning of declaration
volatile static uint8_t s_sendComplete = 0;
^~~~~~~~
Tilman Sauerbeck [Tue, 9 Jul 2019 18:20:34 +0000 (20:20 +0200)]
common: Remove unused variable s_sendSize from virtual_com.c.
Tilman Sauerbeck [Tue, 9 Jul 2019 17:44:36 +0000 (19:44 +0200)]
bootloader: Stop USB serial device before entering the application.
Try to provide a clean slate to the application.
Tilman Sauerbeck [Mon, 8 Jul 2019 19:06:01 +0000 (21:06 +0200)]
common: Wrap USB_VcomDeinit() in usb_serial::shutdown().
Tilman Sauerbeck [Mon, 8 Jul 2019 19:04:37 +0000 (21:04 +0200)]
common: USB_VcomDeinit() always shuts down the singleton CDC device.
This removes the function's argument.
Tilman Sauerbeck [Mon, 8 Jul 2019 19:00:56 +0000 (21:00 +0200)]
common: Don't attempt to stop the USB clock in USB_VcomDeinit().
We don't implement that functionality yet.
Tilman Sauerbeck [Tue, 9 Jul 2019 04:43:39 +0000 (06:43 +0200)]
bootloader: Only attempt to jump to application if there is any.
We now read the first word from flash where the application is
installed and compare against 0xffffffff to see if programming
succeeded.
Tilman Sauerbeck [Mon, 8 Jul 2019 18:38:16 +0000 (20:38 +0200)]
bootloader: Import bootloader-final.ld.
This is used to link the final bootloader described in the
previous commit.
Tilman Sauerbeck [Mon, 8 Jul 2019 17:22:13 +0000 (19:22 +0200)]
bootloader: Rename bootloader.ld to bootloader-intermediate.ld.
We will need two bootloader binaries eventually: an intermediate one
that we can install to 0x8000 using the vendor bootloader, and a
final one that is installed to 0x0 and will thus replace the vendor
bootloader.
Tilman Sauerbeck [Sun, 7 Jul 2019 20:07:56 +0000 (22:07 +0200)]
tools: Don't try to erase and program the second flash sector.
The bootloader refuses to erase that sector anyway. Consequences are
that we may not put any code in the second sector and that we
will get verification errors for that sector.
Tilman Sauerbeck [Sun, 7 Jul 2019 20:05:03 +0000 (22:05 +0200)]
bootloader: Refuse to erase the second flash sector.
The second flash sector (address 0x400) stores the flash configuration
field -- resetting the MCU with 0xff stored in there bricks the device.
Tilman Sauerbeck [Sun, 7 Jul 2019 18:29:48 +0000 (20:29 +0200)]
bootloader: Only begin serial communication if PTE24 is held down.
Tilman Sauerbeck [Sun, 7 Jul 2019 18:29:05 +0000 (20:29 +0200)]
bootloader: configure PTE24 for push button use.
Tilman Sauerbeck [Sat, 6 Jul 2019 16:17:43 +0000 (18:17 +0200)]
common: Add the gpio module.
Tilman Sauerbeck [Sat, 6 Jul 2019 16:16:11 +0000 (18:16 +0200)]
common: Add the port module.
Tilman Sauerbeck [Sun, 7 Jul 2019 16:48:43 +0000 (18:48 +0200)]
bootloader: Initialize systick on startup.
Tilman Sauerbeck [Sun, 7 Jul 2019 16:45:19 +0000 (18:45 +0200)]
common: Add the systick module.
This implements various timer functions using the systick peripheral.
Tilman Sauerbeck [Sun, 7 Jul 2019 12:21:37 +0000 (14:21 +0200)]
tools: Add support for COMMAND_START_APP.
May be combined with the write or verify commands, but it can also
be used on its own.
Tilman Sauerbeck [Sun, 7 Jul 2019 10:37:23 +0000 (12:37 +0200)]
bootloader: Use USB VID 0xf055 and PID 0x635c.
Tilman Sauerbeck [Sun, 7 Jul 2019 10:15:14 +0000 (12:15 +0200)]
common: Make USB_VcomInit() take VID/PID and pass them on.
Tilman Sauerbeck [Sun, 7 Jul 2019 10:08:35 +0000 (12:08 +0200)]
common: Add USB_DeviceSetVendorId() and USB_DeviceSetProductId().
These configure the VID/PID pair to use.
Tilman Sauerbeck [Sun, 7 Jul 2019 10:12:13 +0000 (12:12 +0200)]
common: Initialize the usb_serial module with an USB VID and PID pair.
No change in behaviour yet, as the IDs are not yet forwarded to
the USB system proper.
Tilman Sauerbeck [Sun, 7 Jul 2019 07:57:47 +0000 (09:57 +0200)]
bootloader: Jump to application code after serial communication is done.
Tilman Sauerbeck [Sun, 7 Jul 2019 08:06:12 +0000 (10:06 +0200)]
bootloader: Define application offset.
This defines the APPLICATION_ADDR constant and sets it to the
offset of the vector table to jump to after the bootloader is done.
Tilman Sauerbeck [Sun, 7 Jul 2019 07:49:05 +0000 (09:49 +0200)]
common: Implement jump_to_application().
Tilman Sauerbeck [Sun, 7 Jul 2019 07:57:33 +0000 (09:57 +0200)]
bootloader: Make run() function return a bool.
The return value indicates if the caller should continue to call
the function. It only returns false once COMMAND_START_APP is seen.
The idea is that after run() returns false, the we can jump to the
application code.
Tilman Sauerbeck [Sun, 7 Jul 2019 07:35:51 +0000 (09:35 +0200)]
bootloader: Prepare implementation of COMMAND_START_APP.
This command is to instruct the bootloader to jump to the application.
It doesn't do anything yet.
Tilman Sauerbeck [Thu, 4 Jul 2019 04:53:24 +0000 (06:53 +0200)]
common: Remove unused function USB_VcomWriteBlocking().
Tilman Sauerbeck [Thu, 4 Jul 2019 04:52:42 +0000 (06:52 +0200)]
common: Remove unused function USB_VcomReadBlocking().
Tilman Sauerbeck [Thu, 4 Jul 2019 04:52:00 +0000 (06:52 +0200)]
common: Remove prototype for undefined function USB_VcomReadPolling().
Tilman Sauerbeck [Fri, 28 Jun 2019 15:53:54 +0000 (17:53 +0200)]
tools: Add firmware updater.
Tilman Sauerbeck [Mon, 1 Jul 2019 18:01:43 +0000 (20:01 +0200)]
bootloader: Call into the bootloader module from main().
Tilman Sauerbeck [Fri, 28 Jun 2019 15:53:20 +0000 (17:53 +0200)]
bootloader: Add the bootloader module.
This implements a simple serial protocol that offers access to the
capabilities of the flash module, i.e. erase, program and verify
flash contents.
Tilman Sauerbeck [Wed, 3 Jul 2019 05:17:16 +0000 (07:17 +0200)]
common: Implement the transmit path for the USB serial module.
This adds the global variable cdc_tx_buf, which buffers data
to be written to USB.
Tilman Sauerbeck [Wed, 3 Jul 2019 04:04:02 +0000 (06:04 +0200)]
common: Implement the receive path for the USB serial module.
This sets up a ringbuffer for data received from the USB host.
When we try to read from the empty ringbuffer, another receive-data
request is sent.
Other modules can read from this ringbuffer via the new
usb_serial_read() function.
Tilman Sauerbeck [Tue, 25 Jun 2019 04:35:12 +0000 (06:35 +0200)]
common: Add the ringbuf module.
Tilman Sauerbeck [Tue, 25 Jun 2019 04:23:40 +0000 (06:23 +0200)]
common: Add the buffer module.
This comes with a C API, so it can be used by the USB serial code.
Tilman Sauerbeck [Tue, 25 Jun 2019 04:06:30 +0000 (06:06 +0200)]
bootloader: Add the flash module.
Offers functions to erase a flash sector, program a flash sector and
verify a flash sector's contents.
Note that we don't clear the flash controller's cache by writing to
MCM_PLACR after erasing or programming sectors since it doesn't seem
to be required.
Tilman Sauerbeck [Mon, 24 Jun 2019 04:55:23 +0000 (06:55 +0200)]
common: Add the crc32 module.
Tilman Sauerbeck [Mon, 24 Jun 2019 04:23:00 +0000 (06:23 +0200)]
common: Define panic handler using the #[panic_handler] attribute.
This means we now require rust 1.30 for the build.