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 !
Also remove some useless math/DSP headers.
The USB code really needed updating, considering the following entries from ST's
release notes (
https://raw.github.com/STMicroelectronics/STM32CubeF0/master/Release_Notes.html
) :
-Bug fix: USB_ReadPMA() and USB_WritePMA() by ensuring 16-bits access to
USB PMA memory
-Bug fix: correct USB RX count calculation
-Fix USB Bulk transfer double buffer mode
Avoid using <assert.h> because the standard assert() pulls in
fprintf and its of dependencies, as well as including __FILE__:__LINE__
strings for each assert() call. All this has an unacceptable memory
cost, as well as being useless since there is nothing to printf *to*.
Currently assert_basic() was added to check calloc() return values;
in case of failure we simply halt the core with BKPT(0). This could be
improved and refined.
This had probably been accidentally reverted in
2ebc665109887bfe95a4ad63ebe5e1d7d13c0fef ? flash_data_rom ended up on the same flash page as other unrelated data, which meant flash_flush() would've erased too much.
Also reduce nvm area to 1k and use variables to calculate area. (F042
devices only have 1kB pages vs 2k for the F072)
The other logic could sometimes send frames out of order. See comments
on GH issue 27,
https://github.com/candle-usb/candleLight_fw/pull/27#issuecomment-549633588
where running "canfdtest" sometimes fails after a few seconds.
I don't see why the logic was different in the first place either. The
main loop executes pretty fast, so always putting the frame in the queue
makes all the logic simpler.
dfu-util warns when flashing a .bin file that has no "dfu suffix". Now
we use dfu-suffix, if available, to add the dfu suffix; otherwise keep
the original dfu-util command line as a reflash target; fixes#56 GH.
Also add .bin files as BYPRODUCTS so that 'make clean' picks them up
too.