There is a pair of USB requests ( GS_USB_BREQ_GET_USER_ID and
_SET_USER_ID) that is not supported by the linux driver, and not used by
any known software :
https://github.com/candle-usb/candleLight_fw/issues/91
Since the firmware returns a unique serial #, there doesn't appear to be
any use case for assigning a user ID. Using a whole flash page for that
purpose can be wasteful on bigger targets .
This removes all the relevant code and adjusts the linker scripts
accordingly.
Looking at the queue code it turns out, a lot of the functions are not
used. Remove the unused queue functionality. Not sure why the compiler
hasn't removed the malloc() and free() functions entirely, but this
saves some bytes:
| add/remove: 0/3 grow/shrink: 0/0 up/down: 0/-232 (-232)
| Function old new delta
| malloc 20 - -20
| free 20 - -20
| _free_r 192 - -192
| Total: Before=17370, After=17138, chg -1.34%
Move CAN_INTERFACE and CAN_CLOCK_SPEED to the config file as the CAN
clock can vary based on HW implementation.
Better to add it here than to keep adding defines into the
usbd_gs_can.h file.
CAN_INTERFACE can vary based on the number of channels you are using
so also makes sense to add here even though most chips use the same
interface ID.
In commit
40e1997d45
[1] GS_CAN_FEATURE_GET_STATE has been added to the Linux driver.
Document this bit here accordingly.
The new feature ("GS_CAN_FEATURE_GET_STATE") indicates that the state
of the CAN controller can be queried with the new
GS_USB_BREQ_GET_STATE control message.
[1] https://git.kernel.org/torvalds/c/40e1997d4551e6053fc2f61959628da474775dc5
In commit
1f1835264d
[1] Bus Error Reporting has been added to the Linux driver. Document
this bit here accordingly.
The new feature ("GS_CAN_FEATURE_BERR_REPORTING") indicates that the
bus error reporting in the CAN controller can switched on and off with
the GS_CAN_MODE_BERR_REPORTING mode bit in the GS_USB_BREQ_MODE
control message.
[1] https://git.kernel.org/torvalds/c/1f1835264d81da03fcd05646542a622678b379d6
Since all bit errors already trigger sending a error msg,
remove the code triggering on counters going upwards, since they
are send anyway. See [1] "This if statement doesn't normally do
anything", get rid of it.
[1] https://github.com/candle-usb/candleLight_fw/pull/61
Add a USB message which controls a GPIO for a specified CAN bus.
The GPIO activates a SSR to connect a 120Ohm terminating resistor
to the specified CAN bus.
Signed-off-by: Daniel Trevitz <daniel.trevitz@wika.com>
with help from include-what-you-use (iwyu-tool). It's not quite clever
enough to understand our intent of including "hal_include.h" but still
offers good suggestions.
This saves a few bytes:
before:
| create and sign dfu bin file: candleLight_fw
| text data bss dec hex filename
| 15708 192 1976 17876 45d4 candleLight_fw
after:
| create and sign dfu bin file: candleLight_fw
| text data bss dec hex filename
| 15712 184 1976 17872 45d0 candleLight_fw
Signed-off-by: Marc Kleine-Budde <mkl@blackshift.org>
Use tabs for leading whitespace and spaces for continuation lines.
Besides that inconsistent whitespace looks odd, it causes unnecessary
merge conflicts.
commit 46b01339f5eeab1157d "Add new mode to pad output usb packets
to max packet size for better ..." introduced an unused function
USBD_GS_CAN_GetPadPacketsToMaxPacketSize, get rid of it.
Functions in c which are declared as f() accept any argument. Declare
them as f(void) instead to declare that no arguments are allowed and
add uint32_t sysmem_base to dfu_jump_to_bootloader.
Since commit b5cc61b3317e "fix critical section handling", there are two
versions of enable_irq, enable_irq(void) as used by queue.c and
enable_irq(int primask) as used by usbd_gs_can.c. As a consequence
interrupts might be re-enabled too early in case of nested disable calls.
To prevent this, declared enable_irq as void, since it doesn't accept an
argument and add restore_irq which requires an argument and adjust users
of it.
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.
The documents a workaround for a NXP chip errata on LPC546xx
controllers (Errata sheet LPC546xx / USB.15).
According to the document corruption can occur when the following
conditions are met:
* A TX (IN) transfer happens after a RX (OUT) transfer.
* The RX (OUT) transfer length is 4 + N * 16 (N >= 0) bytes.
Even though the struct gs_host_frame has a size of 76 bytes for a FD
frame, which does not apply to the above rule, corruption could be
seen.
Adding a dummy byte to break the second condition also on transfer
lengths with 4 + N * 8 bytes reliably circumvents USB transfer data
corruption.
The firmware can now request this quirk by setting
GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX.
The CANtact FD and other devices implement a gs-usb compatible USB
protocol. The protocol has been extended to support CAN-FD and the
changes on the Linux gs_usb driver will be mainlined soon.
This patch adds the new GS_CAN_MODE_*, GS_CAN_FEATURE_*,
GS_USB_BREQ_DATA_BITTIMING, and GS_CAN_FLAG_* bits as well as struct
gs_host_frame_canfd to the candlelight driver.
This is mainly for documentation purpose, as the STM32F042 and
STM32F072 don't support CAN-FD. But there are some ports to CAN-FD
capable STM32 µC that can make use of these definitions.
[1] https://github.com/linklayer/gs_usb_fd/issues/2
The bits in GS_CAN_MODE_ correspond to the bits in GS_CAN_FEATURE_*.
This means the bits 5 and 6 of GS_CAN_MODE_ are not "free", document
this by adding a comment to the corresponding GS_CAN_FEATURE_*.
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.