gps-watch.git
4 years agocommon: Add the i2c module.
Tilman Sauerbeck [Mon, 18 Nov 2019 06:38:24 +0000 (07:38 +0100)]
common: Add the i2c module.

4 years agobootloader: Call clock::reset() before jumping to the application.
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.

4 years agocommon: Implement clock::reset().
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.

4 years agocommon: Combine writes to SIM_CLKDIV1 in clock::configure_clkdiv().
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.

4 years agobootloader: Disable the watchdog.
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.

4 years agocommon: Add the watchdog module.
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.

4 years agoapplication: Explicitly enable global interrupts.
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.

4 years agobootloader: Sanitize global interrupt handling.
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.

4 years agocommon: Implement enable_interrupts() and disable_interrupts().
Tilman Sauerbeck [Sat, 16 Nov 2019 10:32:26 +0000 (11:32 +0100)]
common: Implement enable_interrupts() and disable_interrupts().

4 years agocommon: Disable the USB interrupt in usb_serial::shutdown().
Tilman Sauerbeck [Sat, 16 Nov 2019 10:11:54 +0000 (11:11 +0100)]
common: Disable the USB interrupt in usb_serial::shutdown().

4 years agobootloader: Use the same maximum size for both bootloaders.
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.

4 years agobootloader: Reimplement flash::run_command() in C.
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.

4 years agobootloader: Use distinct USB PIDs depending on location in flash.
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.

4 years agobootloader: Explicitly initialize the port module.
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.

4 years agocommon: Implement port::init().
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.

4 years agoapplication: Add humble beginnings of the application code.
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.

4 years agocommon: Fix two -Wold-style-declaration warnings.
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;
 ^~~~~~~~

4 years agocommon: Remove unused variable s_sendSize from virtual_com.c.
Tilman Sauerbeck [Tue, 9 Jul 2019 18:20:34 +0000 (20:20 +0200)]
common: Remove unused variable s_sendSize from virtual_com.c.

4 years agobootloader: Stop USB serial device before entering the application.
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.

4 years agocommon: Wrap USB_VcomDeinit() in usb_serial::shutdown().
Tilman Sauerbeck [Mon, 8 Jul 2019 19:06:01 +0000 (21:06 +0200)]
common: Wrap USB_VcomDeinit() in usb_serial::shutdown().

4 years agocommon: USB_VcomDeinit() always shuts down the singleton CDC device.
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.

4 years agocommon: Don't attempt to stop the USB clock in USB_VcomDeinit().
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.

4 years agobootloader: Only attempt to jump to application if there is any.
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.

4 years agobootloader: Import bootloader-final.ld.
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.

4 years agobootloader: Rename bootloader.ld to bootloader-intermediate.ld.
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.

4 years agotools: Don't try to erase and program the second flash sector.
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.

4 years agobootloader: Refuse to erase the second flash 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.

4 years agobootloader: Only begin serial communication if PTE24 is held down.
Tilman Sauerbeck [Sun, 7 Jul 2019 18:29:48 +0000 (20:29 +0200)]
bootloader: Only begin serial communication if PTE24 is held down.

4 years agobootloader: configure PTE24 for push button use.
Tilman Sauerbeck [Sun, 7 Jul 2019 18:29:05 +0000 (20:29 +0200)]
bootloader: configure PTE24 for push button use.

4 years agocommon: Add the gpio module.
Tilman Sauerbeck [Sat, 6 Jul 2019 16:17:43 +0000 (18:17 +0200)]
common: Add the gpio module.

4 years agocommon: Add the port module.
Tilman Sauerbeck [Sat, 6 Jul 2019 16:16:11 +0000 (18:16 +0200)]
common: Add the port module.

4 years agobootloader: Initialize systick on startup.
Tilman Sauerbeck [Sun, 7 Jul 2019 16:48:43 +0000 (18:48 +0200)]
bootloader: Initialize systick on startup.

4 years agocommon: Add the systick module.
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.

4 years agotools: Add support for COMMAND_START_APP.
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.

4 years agobootloader: Use USB VID 0xf055 and PID 0x635c.
Tilman Sauerbeck [Sun, 7 Jul 2019 10:37:23 +0000 (12:37 +0200)]
bootloader: Use USB VID 0xf055 and PID 0x635c.

4 years agocommon: Make USB_VcomInit() take VID/PID and pass them on.
Tilman Sauerbeck [Sun, 7 Jul 2019 10:15:14 +0000 (12:15 +0200)]
common: Make USB_VcomInit() take VID/PID and pass them on.

4 years agocommon: Add USB_DeviceSetVendorId() and USB_DeviceSetProductId().
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.

4 years agocommon: Initialize the usb_serial module with an USB VID and PID pair.
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.

4 years agobootloader: Jump to application code after serial communication is done.
Tilman Sauerbeck [Sun, 7 Jul 2019 07:57:47 +0000 (09:57 +0200)]
bootloader: Jump to application code after serial communication is done.

4 years agobootloader: Define application offset.
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.

4 years agocommon: Implement jump_to_application().
Tilman Sauerbeck [Sun, 7 Jul 2019 07:49:05 +0000 (09:49 +0200)]
common: Implement jump_to_application().

4 years agobootloader: Make run() function return a bool.
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.

4 years agobootloader: Prepare implementation of COMMAND_START_APP.
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.

4 years agocommon: Remove unused function USB_VcomWriteBlocking().
Tilman Sauerbeck [Thu, 4 Jul 2019 04:53:24 +0000 (06:53 +0200)]
common: Remove unused function USB_VcomWriteBlocking().

4 years agocommon: Remove unused function USB_VcomReadBlocking().
Tilman Sauerbeck [Thu, 4 Jul 2019 04:52:42 +0000 (06:52 +0200)]
common: Remove unused function USB_VcomReadBlocking().

4 years agocommon: Remove prototype for undefined function USB_VcomReadPolling().
Tilman Sauerbeck [Thu, 4 Jul 2019 04:52:00 +0000 (06:52 +0200)]
common: Remove prototype for undefined function USB_VcomReadPolling().

4 years agotools: Add firmware updater.
Tilman Sauerbeck [Fri, 28 Jun 2019 15:53:54 +0000 (17:53 +0200)]
tools: Add firmware updater.

4 years agobootloader: Call into the bootloader module from main().
Tilman Sauerbeck [Mon, 1 Jul 2019 18:01:43 +0000 (20:01 +0200)]
bootloader: Call into the bootloader module from main().

4 years agobootloader: Add the bootloader module.
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.

4 years agocommon: Implement the transmit path for the USB serial module.
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.

4 years agocommon: Implement the receive path for the USB serial module.
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.

4 years agocommon: Add the ringbuf module.
Tilman Sauerbeck [Tue, 25 Jun 2019 04:35:12 +0000 (06:35 +0200)]
common: Add the ringbuf module.

4 years agocommon: Add the buffer 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.

4 years agobootloader: Add the flash module.
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.

4 years agocommon: Add the crc32 module.
Tilman Sauerbeck [Mon, 24 Jun 2019 04:55:23 +0000 (06:55 +0200)]
common: Add the crc32 module.

5 years agocommon: Define panic handler using the #[panic_handler] attribute.
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.

5 years agocommon: Implement USB0 interrupt handler.
Tilman Sauerbeck [Tue, 18 Jun 2019 05:02:01 +0000 (07:02 +0200)]
common: Implement USB0 interrupt handler.

With this change, the device successfully registers as a USB ACM device
and doesn't hard fault if it's disconnected from USB.

5 years agocommon: Implement USB_DeviceIsrEnable() and USB_DeviceClockInit().
Tilman Sauerbeck [Mon, 17 Jun 2019 19:51:36 +0000 (21:51 +0200)]
common: Implement USB_DeviceIsrEnable() and USB_DeviceClockInit().

These functions are required by the C implementation.

5 years agobootloader: Initialize the usb_serial module on startup.
Tilman Sauerbeck [Mon, 17 Jun 2019 19:51:08 +0000 (21:51 +0200)]
bootloader: Initialize the usb_serial module on startup.

5 years agocommon: Add the usb_serial module.
Tilman Sauerbeck [Mon, 17 Jun 2019 19:49:15 +0000 (21:49 +0200)]
common: Add the usb_serial module.

Its init() function calls into the USB serial C code.

5 years agobootloader: Put the binary at offset 0x8000 in flash.
Tilman Sauerbeck [Mon, 17 Jun 2019 19:45:34 +0000 (21:45 +0200)]
bootloader: Put the binary at offset 0x8000 in flash.

This generates a binary that can be loaded as an application,
which allows for easy testing of the code.

5 years agocommon: Implement clock::configure_usb().
Tilman Sauerbeck [Mon, 17 Jun 2019 06:11:37 +0000 (08:11 +0200)]
common: Implement clock::configure_usb().

5 years agocommon: Set SIM_SOPT2.PLLFLLSEL by default.
Tilman Sauerbeck [Mon, 17 Jun 2019 06:05:55 +0000 (08:05 +0200)]
common: Set SIM_SOPT2.PLLFLLSEL by default.

At least the USB peripheral needs this, but probably others do, too.

5 years agobootloader: Configure system and peripheral clocks.
Tilman Sauerbeck [Mon, 17 Jun 2019 05:35:47 +0000 (07:35 +0200)]
bootloader: Configure system and peripheral clocks.

5 years agocommon: Add the clock module.
Tilman Sauerbeck [Mon, 17 Jun 2019 05:34:52 +0000 (07:34 +0200)]
common: Add the clock module.

So far this module only knows how to bring the system to PEE mode.

5 years agocommon: Remove unused code from usb_osa_bm.c.
Tilman Sauerbeck [Mon, 17 Jun 2019 04:48:43 +0000 (06:48 +0200)]
common: Remove unused code from usb_osa_bm.c.

5 years agocommon: Use asm instead of __ASM in USB_OsaEnterCritical().
Tilman Sauerbeck [Mon, 17 Jun 2019 04:44:40 +0000 (06:44 +0200)]
common: Use asm instead of __ASM in USB_OsaEnterCritical().

5 years agocommon: Implement __disable_irq() from CMSIS.
Tilman Sauerbeck [Mon, 17 Jun 2019 04:42:48 +0000 (06:42 +0200)]
common: Implement __disable_irq() from CMSIS.

5 years agocommon: Remove EnableIRQ() and DisableIRQ() from fsl_common.h.
Tilman Sauerbeck [Mon, 17 Jun 2019 04:41:47 +0000 (06:41 +0200)]
common: Remove EnableIRQ() and DisableIRQ() from fsl_common.h.

5 years agocommon: Remove useless calls to __NOP() in busy wait loops.
Tilman Sauerbeck [Mon, 17 Jun 2019 04:30:42 +0000 (06:30 +0200)]
common: Remove useless calls to __NOP() in busy wait loops.

5 years agocommon: Avoid including fsl_clock.h, clock_config.h and board.h.
Tilman Sauerbeck [Mon, 17 Jun 2019 04:24:44 +0000 (06:24 +0200)]
common: Avoid including fsl_clock.h, clock_config.h and board.h.

We won't need them.

5 years agocommon: Hardcode use of NXP's USB baremetal stack in usb_osa.h.
Tilman Sauerbeck [Sun, 16 Jun 2019 19:55:40 +0000 (21:55 +0200)]
common: Hardcode use of NXP's USB baremetal stack in usb_osa.h.

5 years agocommon: Avoid including core_cm0plus.h and system_MKL26Z4.h.
Tilman Sauerbeck [Sun, 16 Jun 2019 19:50:38 +0000 (21:50 +0200)]
common: Avoid including core_cm0plus.h and system_MKL26Z4.h.

Manually add the required functions and macros instead.

5 years agocommon: Hardcode our target's CPU type in fsl_device_registers.h.
Tilman Sauerbeck [Sun, 16 Jun 2019 19:46:40 +0000 (21:46 +0200)]
common: Hardcode our target's CPU type in fsl_device_registers.h.

5 years agocommon: Add NXP's USB serial code.
Tilman Sauerbeck [Sun, 16 Jun 2019 19:44:12 +0000 (21:44 +0200)]
common: Add NXP's USB serial code.

This does not yet build.

5 years agocommon: Add the nvic module.
Tilman Sauerbeck [Sun, 16 Jun 2019 19:10:48 +0000 (21:10 +0200)]
common: Add the nvic module.

Allows enabling and disabling of interrupts as well as configuring
their priority.

5 years agocommon: Add the register module.
Tilman Sauerbeck [Sun, 16 Jun 2019 19:05:58 +0000 (21:05 +0200)]
common: Add the register module.

Allows 8, 16 or 32 bit access to peripheral registers.

5 years agobootloader: Fix address of SRAM in the target.
Tilman Sauerbeck [Sun, 16 Jun 2019 18:31:44 +0000 (20:31 +0200)]
bootloader: Fix address of SRAM in the target.

5 years agobootloader: Remove linker symbols __Vectors_Size and __Vectors_End.
Tilman Sauerbeck [Sun, 16 Jun 2019 18:11:02 +0000 (20:11 +0200)]
bootloader: Remove linker symbols __Vectors_Size and __Vectors_End.

They aren't used.

5 years agobootloader: Remove commented support for multiple .data/.bss sections.
Tilman Sauerbeck [Sun, 16 Jun 2019 17:46:17 +0000 (19:46 +0200)]
bootloader: Remove commented support for multiple .data/.bss sections.

5 years agobuild: Add infrastructure for the bootloader program and libcommon.
Tilman Sauerbeck [Sun, 16 Jun 2019 17:18:09 +0000 (19:18 +0200)]
build: Add infrastructure for the bootloader program and libcommon.

This builds, but does not produce a useful binary.

5 years agoInitial commit.
Tilman Sauerbeck [Sun, 26 May 2019 18:35:02 +0000 (20:35 +0200)]
Initial commit.