99 Commits

Author SHA1 Message Date
fenugrec
7d59b2f063 Rename silly LED_1/LED_2 to LED_RX/TX 2022-07-29 10:34:29 -04:00
mosu_195
a01c508c86 stop transmission when usb is suspended 2022-04-16 20:49:48 -04:00
mosu_195
5a90a192a1 Release resource on USB Resume callback
Needed for hcan->TxState to reset. In some cases when the host reboots, the TxState get locked forever and there's no way to recover other than resetting the controller.
2022-04-16 20:48:53 -04:00
mosu_195
d3c8d66aa5 Fix memory leak every time host restart
After the host reboots, the USBD_GS_CAN_Start function is called, In that
we take a pointer out of frame pool and never pushes it back, So every
time the host reboot, we leak a pointer one by one
2022-04-16 20:47:49 -04:00
Marc Kleine-Budde
d89d414a3d main: clear frame->{flags,reserved} of Echo Frames before sending back to host
The Linux driver doesn't clear the flags (and reserved) value of the
struct gs_host_frame send to the device.

With the Echo Frame this value gets send back to Linux und might be
interpreted as a GS_CAN_FLAG_OVERFLOW Error Frame. Clear the flags
value before echoing back. While there clear the reserved value, too.

Since the following patch, Linux clears the flags value before sending it:

| https://lore.kernel.org/all/20220106002952.25883-1-brian.silverman@bluerivertech.com

This patch fixes https://github.com/candle-usb/candleLight_fw/issues/87
2022-01-08 19:47:28 -05:00
fenugrec
2df0d420e9 Simplify BOARD_XYZ macros (no more numeric values)
There is currently no reason to assign a numeric value to each BOARD_*
macro.
Fix #83 GH
2022-01-06 17:54:49 -05:00
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
Ricky Lopez
d306798923 Add STM32F4 support
Specifically, the STM32F407VE.
Even more specifically, [this](https://stm32-base.org/boards/STM32F407VET6-STM32-F4VE-V2.0.html) dev board
2022-01-06 12:31:05 -05:00
fenugrec
e6b972441b Update USB stack to 1.11.2 (HAL + middleware)
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
2021-04-25 19:43:55 -04:00
Brian Silverman
2225fc0290 Clean up the USB interrupt interactions
This might fix candle-usb/candleLight_fw#58. It definitely makes it
so I no longer observe similar behavior with multiple hosts running
gs_usb.
2021-04-25 19:11:29 -04:00
fenugrec
d66fda39f8 Add git version string to USB config descriptor
There was already provisions for this in the code. Tweaked CMake to
generate version.h automatically every build.
2021-04-06 12:03:13 -04:00
fenugrec
138e6cb433 Add basic assert checks
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.
2021-02-17 16:00:09 -05:00
Hubert Denkmair
b796282765 move USB descriptor callback table to ROM 2020-12-06 12:51:46 -05:00
Hubert Denkmair
b94a26f016 move all usb descriptors to ROM
copy to USBD_DescBuf when requested
(serving from ROM seemingly not supported?)
2020-12-06 12:51:46 -05:00
Hubert Denkmair
f380b5eafd rename USBD_StrDesc to USBD_DescBuf
(will reuse not only for strings)
2020-12-06 12:51:46 -05:00
Hubert Denkmair
643d64a9df fix uninitialized variable warning 2020-12-06 12:51:46 -05:00
Hubert Denkmair
b5cc61b331 fix critical section handling
thanks to @ndushman for pointing this out
2020-12-06 12:51:46 -05:00
Hubert Denkmair
c88dc27653 call __initialize_hardware_early from reset handler for USB DFU handling 2020-12-06 12:51:46 -05:00
Hubert Denkmair
c6d180edaa add interrupt vetor table 2020-12-06 12:51:46 -05:00
Hubert Denkmair
fef1d397b5 use startup files and linker scripts from LibreUCpp 2020-12-06 12:51:46 -05:00
Hubert Denkmair
ed6152f1a2 upgrade HAL to STM32CubeF0-1.11.0 2020-12-06 12:51:46 -05:00
fenugrec
7f9a0ea331 CAN errors : comment some funcs + defines 2020-12-06 11:58:45 -05:00
Brian Silverman
ceeac236c4 Better bit error reporting
It reports more information with more accurate ordering with respect to
other frames sent and received.

Fixes candle-usb/candleLight_fw#59
2020-12-06 11:41:53 -05:00
Brian Silverman
8b3a7b4565 Always queue frames to the host in order
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.
2020-12-02 17:30:07 -05:00
fenugrec
9cf7eccf3d Add new boardtype : cannette
F042-based, galvanically isolated.
2020-10-30 21:55:27 -04:00
fenugrec
2416f260bb enable power-on LED blinkage on all boards
what's not to like ?
2020-10-30 21:55:12 -04:00
Ethan Zonca
465e957db9 Update CANable-specific LED initialization 2020-10-30 21:50:08 -04:00
fenugrec
4dac861b8c Set explicit LED polarity and invert canalyze
the canalyze has active-high LED signals
2019-11-11 16:21:15 -05:00
nexulm
89c44fe3f1 correct LED initialization for canable interfaces 2019-11-04 19:14:58 -05:00
Jeroen Hofstee
7618128cf6 fix whitespace
The project uses tabs with a length of 4 spaces, and spaces for
continuation, so lets use that for the whole project. There are
many trailing whitespaces and empty lines here and there; get
rid of them as well.
2019-11-04 19:04:54 -05:00
Jeroen Hofstee
cd31acce28 use unix line endings
Some files have Windows line endings which is annoying, since pathes
won't apply, diffs looks ugly etc. So do convert the few files which
have Windows line endings to use Unix line endings as well.
2019-11-04 19:04:45 -05:00
fenugrec
0434e8eeec LED functions : support GPIO pins >= 8
this requires a uint16 to save the pin #
2019-11-04 18:56:35 -05:00
Hubert Denkmair
7a11cf4897
Merge pull request #25 from candle-usb/cmake
re-organize everything to a cmake project structure
2019-11-02 20:43:40 +01:00
Hubert Denkmair
73dfc741c8 port fix for issue #15 2019-10-29 20:53:19 +01:00
Hubert Denkmair
29e8d65cdd fix whitespaces 2019-10-29 20:45:45 +01:00
Hubert Denkmair
797e15acfa return frame to pool if can_receive fails 2019-10-29 20:44:36 +01:00
Hubert Denkmair
9872639faf Merge branch 'master' of github.com:HubertD/candleLight_fw 2019-10-29 19:55:32 +01:00
Hubert Denkmair
ba1e4cce65 fix issue #15
thanks to @willtoth
2019-10-29 19:54:48 +01:00
Hubert Denkmair
23ebdb8a78 convert to cmake 2019-10-26 16:53:43 +02:00
Nathan Dushman
35b409bf1e
Fix enable_irq interpretation of primask
The logic for enable_irq is backwards; it should enable interrupts when primask is 0, not 1.
2019-06-03 11:30:13 -07:00
Max Behensky
46b01339f5 Add new mode to pad output usb packets to max packet size for better WinUSB performance 2017-11-22 13:00:01 -08:00
Florian Larysch
ea462f7251 usbd_desc: use device unique ID as serial number
Instead of hardcoding the serial number in the firmware, use the
device's manufacturer-provided UID as the serial number.

This makes it easier to distinguish between multiple adaptors plugged
into the same host without having to build a separate firmware for each
one.
2017-08-28 01:27:34 +02:00
Florian Larysch
7a011f5f0d util: add integer to hex formatting 2017-08-28 01:27:34 +02:00
Hubert Denkmair
2ebc665109 adapt to stm32f042 for candleZero 2017-05-12 23:31:39 +02:00
Hubert Denkmair
1453d70dc9 really implement write user_id to flash 2016-06-11 18:36:59 +02:00
Hubert Denkmair
37980fb2eb dummy implement user_id feature 2016-06-11 10:21:29 +02:00
Hubert Denkmair
6450f08b22 implement identify command 2016-06-03 15:02:24 +02:00
Hubert Denkmair
44431f4a43 use new feature bit and control request numbers for hardware timestamps 2016-05-14 21:49:56 +02:00
Hubert Denkmair
f4f47116cd hardware timestamp support via mode 2016-05-13 21:59:31 +02:00
Hubert Denkmair
56192e76f6 implement hardware timestamps on bulk pipes 2016-05-04 21:14:33 +02:00