31 Commits

Author SHA1 Message Date
Marc Kleine-Budde
f83fdd8371 usbd_gs_can: import struct gs_host_frame from kernel and adopt code 2024-01-30 11:48:52 +01:00
Marc Kleine-Budde
3d98b33f15 usbd_gs_can: USBD_GS_CAN_Config_Request(): check size 2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
3bbb594467 gs_usb.h: fix typo in GS_CAN_FEATURE_BERR_REPORTING
Fixes: ad2f13ace724 ("gs_usb.h: document GS_CAN_MODE_BERR_REPORTING")
2023-05-10 16:19:50 +02:00
Marc Kleine-Budde
1155a608e0 gs_usb: mark all structures as aligned to 4 bytes
Marking structures as packed as the following 2 results:
- the compiler doesn't insert any holes in the structures
  e.g. if variables are not naturally aligned
- the compiler doesn't assume the base address of the struct to be
  naturally aligned

The 2nd effect results in the compiler (depending on the target
architecture) to generate bad code, as unaligned access is not
possible on all archs.

Mark the structs as aligned to 4 bytes, using the not-so-beautiful
__ALIGN_BEGIN and __ALIGN_END macros.

This saves some bytes and generates probably faster code.

| add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-468 (-468)
| Function                                     old     new   delta
| USBD_GS_CAN_EP0_RxReady                      684     568    -116
| main                                        2712    2360    -352
| Total: Before=17138, After=16670, chg -2.73%
2022-11-14 17:04:56 +01:00
Marc Kleine-Budde
f5e5a6e16b gs_usb: remove unused struct gs_tx_context 2022-11-14 17:04:56 +01:00
Marc Kleine-Budde
048288042f gs_usb: update comment about struct gs_device_config::byte_order
Fixes: bbe39cad2ea8 ("usbd_gs_can: remove unused USBD_GS_CAN_HandleTypeDef::host_config")
2022-11-14 17:04:56 +01:00
fenugrec
a0caf93e50 Remove flash-as-eeprom emulation for USER_ID
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.
2022-11-14 10:40:27 -05:00
Marc Kleine-Budde
2bba52ffc9 gs_usb.h: document GS_CAN_FEATURE_GET_STATE, GS_USB_BREQ_GET_STATE
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
2022-10-31 14:06:28 +01:00
Marc Kleine-Budde
ad2f13ace7 gs_usb.h: document GS_CAN_MODE_BERR_REPORTING
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
2022-10-31 14:06:08 +01:00
fenugrec
12cc477412 some misc whitespace leftovers uncrustified
closes gh #118
2022-10-15 10:01:51 -04:00
Daniel Trevitz
0a1d6dc920 Add switchable terminating resistor support
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>
2022-10-12 17:39:21 -04:00
fenugrec
f45060be53 rework some #include lines
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.
2022-10-12 17:28:50 -04:00
Daniel Trevitz
cfca364c2a Uncrustify the code 2022-10-11 19:27:57 -04:00
Marc Kleine-Budde
151ec30d78 gs_usb: document switchable termination support 2022-09-29 10:10:53 +02:00
Jeroen Hofstee
9f07a4b223 use consistent whitespace
Use tabs for leading whitespace and spaces for continuation lines.
Besides that inconsistent whitespace looks odd, it causes unnecessary
merge conflicts.
2022-08-26 21:51:33 -04:00
Marc Kleine-Budde
b549cb768b gs_usb.h: document GS_CAN_FEATURE_BT_CONST_EXT and GS_USB_BREQ_BT_CONST_EXT
Some CAN-FD capable controllers have different bittiming constants for
arbitration phase and data phase to reach maximum performance at
higher speeds.
2022-01-12 09:21:30 -05:00
Marc Kleine-Budde
fea8b8603f gs_usb.h: document GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX
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.
2022-01-12 09:21:30 -05:00
Marc Kleine-Budde
41f9e7d64f gs_usb.h: introduce CAN-FD support
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
2022-01-12 09:21:30 -05:00
Marc Kleine-Budde
335dc50cd6 gs_usb.h: document used GS_CAN_MODE_* bits
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_*.
2022-01-12 09:21:30 -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
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
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
Hubert Denkmair
38512d1a11 implement timestamp usb control requests 2016-05-04 20:52:12 +02:00
Hubert Denkmair
990c08cd2d add license info 2016-04-16 22:13:47 +02:00
Hubert Denkmair
01a40f66a1 generate linux error frames 2016-04-16 21:49:46 +02:00
Hubert Denkmair
e4011dec05 implement can tx/rx 2016-04-10 11:19:10 +02:00
Hubert Denkmair
70c41d0296 usb communication seems to work 2016-04-08 19:34:59 +02:00