Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Add a prototype DFU firmware based on the ColorHug2 firmware
Browse files Browse the repository at this point in the history
To use this, you'll also need my m-stack fork, for details see:
signal11/m-stack#9
  • Loading branch information
hughsie committed Nov 12, 2015
1 parent 40e8ff4 commit 87cd748
Show file tree
Hide file tree
Showing 19 changed files with 2,116 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.as
*.cab
*.cmf
*.cof
*.d
*.dfu
*.hex
*.hxl
*.lst
*.obj
*.p1
*.pre
*.rlf
*.sdb
*.sym
m-stack
144 changes: 144 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Copyright (C) 2012 t-lo <[email protected]>
# Copyright (C) 2012-2015 Richard Hughes <[email protected]>
#
# Licensed under the GNU General Public License Version 2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#


VENDOR = hughski
PROJECT_NAME = colorhug+
VERSION = 1.0

PK2CMD_DIR = ../../pk2cmd/pk2cmd
CC = /opt/microchip/xc8/v1.34/bin/xc8
DFU_TOOL = /home/hughsie/Code/fwupd/libdfu/dfu-tool

.DEFAULT_GOAL := all

all: bootloader.hex $(VENDOR)-$(PROJECT_NAME)-$(VERSION).cab

# common to bootloader and firmware
CFLAGS += \
-I. \
-Im-stack/usb/include \
--chip=18F46J50 \
--asmlist \
--opt=+speed \
-w3 \
-nw=3004

# This is in _BYTES_ not words
#
# 0000
# | <--- Bootloader (crossing 2 pages)
# 7bff
# 7c00
# | <--- Config space
# 7fff
# 8000
# | <--- Runtime program
# fff8

# get from the device
verify.hex: Makefile bootloader.hex firmware.hex
${PK2CMD_DIR}/pk2cmd -pPIC18F46J50 -GF $@ -b ${PK2CMD_DIR}/ -r
verify.dfu: verify.hex Makefile
${DFU_TOOL} convert $< $@ 273f 1004 ffff 8000

# bootloader
SRC_BOOTLOADER_H = \
ch-config.h \
ch-errno.h \
ch-flash.h \
ch-sram.c \
usb_config_bootloader.h
SRC_BOOTLOADER_C = \
bootloader.c \
ch-config.c \
ch-errno.c \
ch-flash.c \
ch-sram.c \
m-stack/usb/src/usb.c \
m-stack/usb/src/usb_dfu.c \
usb_descriptors_bootloader.c
bootloader_CFLAGS = \
${CFLAGS} \
--rom=0x0000-0x3dff \
-DCOLORHUG_BOOTLOADER
bootloader.hex: Makefile ${SRC_BOOTLOADER_C} ${SRC_BOOTLOADER_H}
$(CC) $(bootloader_CFLAGS) ${SRC_BOOTLOADER_C} -o$@
bootloader.dfu: bootloader.hex
${DFU_TOOL} convert $< $@ 273f 1004 ffff 8000
install-bootloader: bootloader.hex
${PK2CMD_DIR}/pk2cmd -pPIC18F46J50 -f $< -b ${PK2CMD_DIR}/ -m -r

# runtime firmware
SRC_FIRMWARE_H = \
ch-config.h \
ch-errno.h \
ch-flash.h \
ch-sram.c \
usb_config_firmware.h
SRC_FIRMWARE_C = \
ch-config.c \
ch-errno.c \
ch-flash.c \
ch-sram.c \
firmware.c \
m-stack/usb/src/usb.c \
m-stack/usb/src/usb_dfu.c \
m-stack/usb/src/usb_hid.c \
usb_descriptors_firmware.c
firmware_CFLAGS = \
--codeoffset=0x4000 \
--rom=0x4000-0x8000 \
${CFLAGS}
firmware.hex: Makefile ${SRC_FIRMWARE_C} ${SRC_FIRMWARE_H}
$(CC) $(firmware_CFLAGS) ${SRC_FIRMWARE_C} -o$@
firmware.dfu: firmware.hex Makefile
${DFU_TOOL} convert $< $@ 273f 1004 ffff 8000
install: firmware.dfu Makefile
${DFU_TOOL} -R --alt 0 --download $< --verbose

# LVFS package
CAB_FILES= \
firmware.dfu \
firmware.metainfo.xml
check: firmware.metainfo.xml
appstream-util validate-relax $<
%.cab: $(CAB_FILES)
gcab --create --nopath $@ $(CAB_FILES)

clean:
rm -f *.as
rm -f *.bin
rm -f *.cab
rm -f *.cmf
rm -f *.cof
rm -f *.d
rm -f funclist
rm -f *.hex
rm -f *.hxl
rm -f *.mum
rm -f *.o
rm -f *.obj
rm -f *.p1
rm -f *.pre
rm -f *.lst
rm -f *.rlf
rm -f *.sdb
rm -f *.sym
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ColorHug Firmware README

Right, you're probably reading this file as you want to make a driver
for the ColorHug hardware.

If you came here for modifying, building and flashing the firmware
please have a look at the Makefiles.

== General Device Information ==

The device is a small USB peripheral that connects to the host computer
and takes XYZ measurements of a specified accuracy. Longer measurements
lead to a more accurate result, but take more time.

The device has two LEDs that can either be switched on or off, or be
programmed to do a repeated flashing with specified on and off durations.

== Firmware Design ==

The device will enter a bootloader if programming the device failed or was
interrupted, or if the device is detached and then reset at runtime.

When the device is in bootloader mode the LEDs will flash in an
alternate pattern to advise the user that it is not fully functional.

== Building and flashing the firmware ==

Before compiling you need to have:

* A checkout of https://github.com/hughsie/m-stack/tree/usb_dfu
* The xc8 compiler installed from Microchip

Then just issue 'make' and then you flash the `bootloader.hex` file to the
device using a hardware programmer, which will also remove the firmware image.

If you just want to flash the firmware do `make install` if you have fwupd
or `dfu-util -D firmware.dfu` will do the same thing.
Loading

0 comments on commit 87cd748

Please sign in to comment.