130 Commits

Author SHA1 Message Date
Marc Kleine-Budde
26134e6a7e compiler.h: add IS_ENABLED
Import from zephyr
2023-07-19 10:39:37 +02:00
Marc Kleine-Budde
0207095915 compiler.h: add DECLARE_FLEX_ARRAY and struct_size
Import from FreeBSD.
2023-05-10 17:29:19 +02:00
Marc Kleine-Budde
6af7be218a treewide: sort includes 2023-05-10 17:29:19 +02:00
Marc Kleine-Budde
881f430c55 config: make NUM_CAN_CHANNEL a per board macro 2023-05-10 17:29:19 +02:00
Marc Kleine-Budde
5109196811 config: make CAN_QUEUE_SIZE depend on number of CAN channels 2023-05-10 17:29:19 +02:00
Marc Kleine-Budde
ab292f22e7 gpio: GPIO_INIT_STATE: use lower case for macro argument 2023-05-10 17:29:18 +02:00
Marc Kleine-Budde
dc1664779f config: convertdevice xCANFD: remove unused CANFDIF_GPIO_Port, CANFDIFRX_Pin, CANFDIFTX_Pin 2023-05-10 17:29:18 +02:00
Marc Kleine-Budde
4cd86590d6 timer: run at 1 MHz for all clock speeds
The TIM2 timer is expected to run at 1 MHz, but it's clocked by the
CPU clock. The current code expects the CPU runs with 48 MHz.

Introduce TIM2_CLOCK_SPEED and calculate a proper divider.
2023-05-10 17:29:18 +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
ConvertDevice
4dc288d174 feat: add convertdevice xCANFD config info 2023-04-22 09:27:07 -04:00
Chris Wilson
4d7abdf9fd
Add support for additional F072 boards
- DSD TECH SH-C30A: https://www.deshide.com/product-details.html?pid=384242&_t=1671089557
- FYSETC UCAN: https://www.fysetc.com/products/fysetc-ucan-board-based-on-stm32f072-usb-to-can-adapter-support-with-canable-candlelight-klipper-firmware
2023-04-19 22:16:22 -07:00
fenugrec
41e0388273 move system clock config to device_XX.c 2022-12-12 11:27:18 -05:00
fenugrec
2d9d1b302c split device-specific can_init() to separate files 2022-12-12 11:27:18 -05:00
ConvertDevice
537c0860c3 feat: change xCAN01 to xCAN 2022-12-11 11:56:15 +08:00
fenugrec
edc684609b led.c : removed unused last_mode 2022-11-28 11:39:45 -05:00
fenugrec
361ab73ddb led : move tx/rx blinking logic to led_update()
This allows a much lighter implementation of led_indicate_trx(), which
is called for every frame !

Test with 'cangen -L0 -g0 -p10 can0'
After : 13174 frames/sec
2022-11-28 11:39:42 -05:00
fenugrec
c2bb46f18f led_update() only every 10ms
Not necessary to spam it every mainloop. Currently throughputs of 17-18k
frames per second is realistic, which means function calls from mainloop
are very frequent and must be "short" compared to the processing time
for each frame.
2022-11-25 08:36:40 -05:00
Marc Kleine-Budde
0b52b4eaf9 queue: remove no longer used queue implementation 2022-11-24 10:24:36 +01:00
Marc Kleine-Budde
35d6cb8941 queue: convert to Linux compatible list implementation
Convert from the queue implementation to a Linux compatible list
implementation. Get rid of This way we can avoid dynamic memory
allocation altogether.

As the struct gs_host_frame is not placed into the data segment,
requirements for the static memory grows. On the low end processors
the heap reserved in the linker file is too big, resulting in a linker
error. On STM32F042 and STM32F072 set a HEAP size of 0 bytes.
2022-11-24 10:24:36 +01:00
Marc Kleine-Budde
67b15c19f1 list.h: add new locked variants, remove old ones
It turned out, that the locked functions added in
61baf8ce9039 ("list.h: add locked variants") are not needed. Remove
these and replace them by locked variants of functions needed in the
upcoming patches.
2022-11-24 10:24:36 +01:00
Marc Kleine-Budde
61baf8ce90 list.h: add locked variants 2022-11-17 13:41:33 -05:00
Marc Kleine-Budde
9ea65a1d98 list.h: remove BSD specific STANDALONE support and include compiler.h 2022-11-17 13:41:33 -05:00
Marc Kleine-Budde
e2173dc60b list.h: uncrustify 2022-11-17 13:41:33 -05:00
Marc Kleine-Budde
d67381bce3 list.h: import from freebsd 2022-11-17 13:41:33 -05:00
Marc Kleine-Budde
9e98f4b49a usbd_gs_can: move struct gs_host_frame msgbuf into USBD_GS_CAN_HandleTypeDef
Place the struct gs_host_frame msgbuf directly into
USBD_GS_CAN_HandleTypeDef. Get rid of another calloc().

This also requires a tweak to heap size in order to fit on the smaller
targets.
2022-11-17 13:41:13 -05:00
Marc Kleine-Budde
6123dbd115 usbd_gs_can: embed can_data_t in USBD_GS_CAN_HandleTypeDef
As USBD_GS_CAN_HandleTypeDef describes the whole device, place the
data structure describing the channels directly into it.
2022-11-17 13:20:19 -05:00
Marc Kleine-Budde
1c9f2e7384 usbd_gs_can: place USBD_GS_CAN_HandleTypeDef in BSS
Get rid of the first calloc().
2022-11-17 13:20:19 -05:00
Marc Kleine-Budde
e739f60960 usbd_gs_can: move USBD_GS_CAN_HandleTypeDef to header
Move USBD_GS_CAN_HandleTypeDef definition to header as a preparation
to place the USBD_GS_CAN_HandleTypeDef into the BSS in main.c
2022-11-17 13:20:19 -05:00
Marc Kleine-Budde
859b7e3717 usbd_gs_can: USBD_GS_CAN_PrepareReceive(): mark as static
USBD_GS_CAN_PrepareReceive() is only used in usbd_gs_can.c, remove
function prototype from usbd_gs_can.h, mark as static, and move in
front to avoid forward declaration.
2022-11-17 13:20:19 -05:00
Marc Kleine-Budde
e27abfe173 treewide: sort includes 2022-11-17 13:20:19 -05:00
fenugrec
718882b354 move GPIO_INIT_STATE macro to gpio.h 2022-11-17 13:01:58 -05: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
Marc Kleine-Budde
84a397731b compiler.h: add more helper macros
Add:
- __aligned
- __packed
- container_of
- ARRAY_SIZE
2022-11-14 17:04:56 +01:00
Marc Kleine-Budde
8ab58a41f7 compiler.h: uncrustify 2022-11-14 17:04:56 +01:00
Marc Kleine-Budde
ae59fae696 compiler.h: remove unused defines 2022-11-14 17:04:56 +01:00
Marc Kleine-Budde
eab812d07a compiler.h: import from freebsd 2022-11-14 17:04:56 +01:00
ConvertDevice
e0e04ea938 ci: add convertdevice-xcan01 hardware support 2022-11-14 10:46:19 -05: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
Ryan Edwards
b24cba3a55 Add config for budgetcan
Update the config.h and CMake to support the budgetcan device which contains the STM32G0B1xK microcontroller.
2022-11-14 10:03:53 -05:00
Marc Kleine-Budde
7f97321149 queue: remove unused functionality
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%
2022-11-10 19:46:08 -05:00
Ryan Edwards
8a9cdf1076 config.h: move the CAN_INTERFACE and CAN_CLOCK_SPEED to the config.h
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.
2022-11-09 08:59:21 +01: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
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
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