355 Commits

Author SHA1 Message Date
Marc Kleine-Budde
1a36d8de55 usbd_gs_can: USBD_GS_CAN: make use of C99 initializers 2022-10-19 16:51:19 -04:00
Marc Kleine-Budde
bbe39cad2e usbd_gs_can: remove unused USBD_GS_CAN_HandleTypeDef::host_config
The GS_USB_BREQ_HOST_FORMAT has never been supported by the
candleLight firmware, and since Linux v5.10 the gs_usb driver works on
Big Endian Linux systems, too.

So remove host_config handling from the firmware. This saves some
bytes:

| add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-16 (-16)
| Function                                     old     new   delta
| USBD_GS_CAN_EP0_RxReady                      640     624     -16
| Total: Before=17382, After=17366, chg -0.09%
2022-10-19 16:51:19 -04:00
Daniel Trevitz
17a7fe8445 Check code formatting on PR
Check the code formatting of a PR by looking up the files in git diff HEAD^
If the uncrustify config sees a change, yell about it.

Signed-off-by: Daniel Trevitz <daniel.trevitz@wika.com>
2022-10-15 22:48:05 -04:00
fenugrec
12cc477412 some misc whitespace leftovers uncrustified
closes gh #118
2022-10-15 10:01:51 -04:00
Jeroen Hofstee
c25f4ce480 remove odd err-frames
The gusb-interface can report completely weird error-frames,
like being in error-ative (based on counters), and error-warning,
and bus-off at the same time.

To fix this:
  - only send state changes once.
  - don't send LEC / err counters in bus-off (invalid anyway).
  - don't send empty error frames.
2022-10-15 10:00:52 -04:00
Jeroen Hofstee
9a663007f5 remove triggering error message based on counter values
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
2022-10-15 10:00:52 -04:00
Daniel Trevitz
d991308d63 Help the compiler optimize out the terminating resistor
Use get_term to make sure the compiler can identify that the branch will always fail.

Signed-off-by: Daniel Trevitz <daniel.trevitz@wika.com>
2022-10-12 19:16:41 -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
Daniel Trevitz
4540120e94 Use consistent whitespace
Use tabs in cmake to match c file formatting

Signed-off-by: Daniel Trevitz <daniel.trevitz@wika.com>
2022-10-05 22:30:06 -04:00
Daniel Trevitz
0e53857656 Generalize the gpio configuration
Move the nCANSTBY_Pin to be avaliable for other boards. Make the
  LED Rx and Tx pins optional.

Signed-off-by: Daniel Trevitz <daniel.trevitz@wika.com>
2022-10-05 21:43:08 -04:00
Marc Kleine-Budde
151ec30d78 gs_usb: document switchable termination support 2022-09-29 10:10:53 +02:00
Marc Kleine-Budde
c19f3a17e1 cmake: add -Wstrict-prototypes
Suggested-by: fenugrec <fenugrec@users.sourceforge.net>
Link: https://github.com/candle-usb/candleLight_fw/issues/103
Signed-off-by: Marc Kleine-Budde <mkl@blackshift.org>
2022-08-28 21:47:36 +02:00
Marc Kleine-Budde
c7547b0dcd interrupts: fix function declaration
Reported-by: https://github.com/ReXT3D
Signed-off-by: Marc Kleine-Budde <mkl@blackshift.org>
2022-08-28 21:47:36 +02:00
Marc Kleine-Budde
e6766934aa leds: mark led_identify_seq as const
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>
2022-08-28 00:31:22 +02:00
Marc Kleine-Budde
7860fef8fd USBD_GS_CAN_GetProtocolVersion(): remove unused function
Signed-off-by: Marc Kleine-Budde <mkl@blackshift.org>
2022-08-28 00:27:52 +02:00
Jeroen Hofstee
c105ca4847 completely reset the CAN peripheral
Make sure the CAN-bus state and associated error counters are
also reset in can_enable.

Writing to the ESR won't help, only the LEC field is writable, the rest
is read-only. The only reported way to make that work is by issuing an
RCC reset.

In addition, socketcan requires the CAN interface to be in active-error
state after open.
2022-08-26 22:09:47 -04:00
fenugrec
65cd7d76c9 reduce the scope of function / vars where possible
Originally by johfstee , but without modifying the
interrupt handler decls in src/interrupts.c
2022-08-26 22:00:50 -04: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
Jeroen Hofstee
8049e7d8af remove unused received_count
commit 46b01339f5eeab1157d "Add new mode to pad output usb packets
to max packet size for better ..." introduced the never used global
variable received_count, so get rid of it again.
2022-08-25 09:36:41 +02:00
Jeroen Hofstee
f1be957992 remove unused USBD_GS_CAN_GetPadPacketsToMaxPacketSize
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.
2022-08-25 09:36:41 +02:00
Jeroen Hofstee
4668b03c7d add stricter prototype checking
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.
2022-08-25 09:36:41 +02:00
Jeroen Hofstee
4f51b8e964 use restore_irq to restore irq state
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.
2022-08-25 09:36:36 +02:00
fenugrec
7d59b2f063 Rename silly LED_1/LED_2 to LED_RX/TX 2022-07-29 10:34:29 -04:00
ReXT3D
2878e4656d Update README.md
Included CANable-MKS GitHUb link
2022-07-29 10:23:12 -04:00
ReXT3D
3337447233 Add Makerbase CANable-MKS board support
Configuration for Makerbase CANable-MKS and CANable-MKS Pro boards
2022-07-29 10:23:12 -04:00
ReXT3D
df5c35815b Fix whitespace consistency in config.h 2022-07-29 10:23:12 -04:00
fenugrec
241e4994c4 try to fix CI action upload, again
- use upload-artifact v3 which should support wildcards in path
- remove reference to matrix_target since we're not using a build matrix
  anymore
2022-06-10 21:43:17 -04:00
fenugrec
51637c9bf6 README : add info on assigning unique device names
from GH issue #76
v2.0
2022-04-16 21:20:43 -04:00
fenugrec
4c142b974d CI : Build targets together and rename artifact
The "install toolchain" step is very slow, and needed to run for each
target part of the build matrix. There is no obvious way to "cache" the
runner environment just before running cmake. Uploading artifacts
separately may be possible but I couldn't find how to do that with a
build matrix or arrays/maps.

Weekly builds, or push/ pullrequest triggered builds, now generate different
names.
2022-04-16 20:55:52 -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
fenugrec
0e1638b446 fix CI. Accidentally dropped a commit during merge 2022-03-09 11:44:41 -05:00
fenugrec
7f6418fe91 CI : build weekly instead of daily
Also rename artifact to contain build date
2022-03-09 10:30:56 -05:00
vondraussen
1149642d7f add binary download instr. to readme 2022-01-13 10:54:04 -05:00
vondraussen
0d77312544 CI: change make jobs to automatic
The github runner VM currently provides 2 cores with 7GB RAM, so we
should be fine with make -j to run unlimited parallel builds.
2022-01-13 10:54:04 -05:00
vondraussen
c03d01a2cb add matrix build for separate artifacts 2022-01-13 10:54:04 -05:00
Marc Kleine-Budde
2a1e2943d9 README: add link to Linux Automation candleLight 2022-01-13 09:28:02 +01: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
fenugrec
6ac7632522 update README with github-actions build status 2022-01-08 19:55:58 -05: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
vondraussen
8c5a7d08e5 add github actions CI #84
remove travis ci, since Travis-CI is not a good place for opensource
projects anymore.
2022-01-08 09:22:04 -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
f58de5e678 config.h : document CAN_S_PIN for silent mode
fix GH #81
2022-01-06 17:48:15 -05:00
fenugrec
1b1c3bb8ff usb RX_FIFO size: remove nonapplicable PMA comment
on F4 with the USB_OTG peripheral, the RX FIFO must be sized according
to different rules vs the USB_FS peripheral of the F0.
2022-01-06 17:42:50 -05:00