fenugrec 2c4d046df5 LED : handle 32-bit tick overflow properly
32-bit milliseconds gives a 49.7-day wrap period which would break the
blinking patterns.

Fix GH #78, and hopefully makes the code cleaner / less error-prone.

Currently the sequence is specified with a uint8 but we still clamp
deltas to INT32_MAX in case the tick resolution ever changes.

Clamping the interval to INT32_MAX should ensure that for the
next (UINT32_MAX - 1) ticks, the macro SEQ_ISPASSED(now, wait_until)
produces the correct logic. Example :

now = 0
delta = INT32_MAX (7FFF....)
wait_until = now + delta = INT32_MAX (7FFF...

// 0 ticks later
(now - wait_until) == -7FFF FFFF ; SEQ_ISPASSED = false

// 1 tick later
(new_now - wait_until) == -7FFF FFFE  ; SEQ_ISPASSED = false

// 7FFF... ticks later
(new_now - wait_until) == 0; ok, now SEQ_ISPASSED is true

// new_now == UINT32_MAX - 1 == FFFF FFFE, almost rollover
(new_now - wait_until) == 7FFF FFFF ; ok, SEQ_ISPASSED is still true

// new_now == UINT32_MAX == FFFF FFFF,
(new_now - wait_until) == 8000 0000 == -7FFF FFFF; this fails because
the sign changed !
2022-01-06 12:54:41 -05:00
2022-01-06 12:31:05 -05:00
2022-01-06 12:31:05 -05:00
2022-01-06 12:31:05 -05:00
2022-01-06 12:31:05 -05:00
2022-01-06 12:31:05 -05:00
2021-02-16 11:11:32 -05:00

candleLight_gsusb

Build Status

This is firmware for certain STM32F042x/STM32F072xB-based USB-CAN adapters, notably:

Of important note is that the common STM32F103 will NOT work with this firmware because its hardware cannot use both USB and CAN simultaneously. Beware also the smaller packages in the F042 series which map a USB and CAN_TX signal on the same pin and are therefore unusable !

This implements the interface of the mainline linux gs_usb kernel module and works out-of-the-box with linux distros packaging this module, e.g. Ubuntu.

Known issues

Be aware that there is a bug in the gs_usb module in linux<4.5 that can crash the kernel on device removal.

Here is a fixed version that should also work for older kernels: https://github.com/HubertD/socketcan_gs_usb

The Firmware also implements WCID USB descriptors and thus can be used on recent Windows versions without installing a driver.

Building

Building requires arm-none-eabi-gcc toolchain.

sudo apt-get install gcc-arm-none-eabi

mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/gcc-arm-none-eabi-8-2019-q3-update.cmake

# or,
# cmake-gui ..
# don't forget to specify the cmake toolchain file before configuring.
#
# compile all targets :

make

# OR, each board target is a cmake option and can be disabled before running 'make';
# OR, compile a single target , e.g.
make cantact_fw

#
# to list possible targets :
make help

Flashing

Flashing candleLight on linux: (source: https://wiki.linklayer.com/index.php/CandleLightFirmware)

  • Flashing requires the dfu-util tool. On Ubuntu, this can be installed with sudo apt install dfu-util.
  • compile as above, or download the current binary release: gsusb_cantact_8b2b2b4.bin
  • If dfu-util fails due to permission issues on Linux, you may need additional udev rules. Consult your distro's documentation and see 70-candle-usb.rules provided here.
  • If compiling with cmake, make flash-<targetname_fw>, e.g. make flash-canable_fw, to invoke dfu-util.

method for reflashing a specific device by serial

  • when multiple devices are connected, dfu-util may be unable to choose which one to flash.
  • Obtain device's serial # by looking at dfu-util -l
  • adapt the following command accordingly : dfu-util -D CORRECT_FIRMWARE.bin -S "serial_number_here", -a 0 -s 0x08000000:leave
  • note, the :leave suffix above may not be supported by older builds of dfu-util and is simply a convenient way to reboot into the normal firmware.

fail-safe method (or if flashing a blank device)

  • Disconnect the USB connector from the CANtact, short the BOOT pins, then reconnect the USB connector. The device should enumerate as "STM32 BOOTLOADER".

  • invoke dfu-util manually with: sudo dfu-util --dfuse-address -d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D CORRECT_FIRWARE.bin where CORRECT_FIRWARE is the name of the desired .bin.

  • Disconnect the USB connector, un-short the BOOT pins, and reconnect.

  • Cangaroo open source can bus analyzer software
  • Candle.NET .NET wrapper for the candle API
Description
gs_usb compatible firmware for candleLight, cantact and canable
Readme 2.8 MiB
Languages
C 99.8%
CMake 0.2%