312 Commits

Author SHA1 Message Date
Marc Kleine-Budde
ea53735f4d usbd_gs_can: shrink CAN_CMD_PACKET_SIZE to minimal size
Since commit "usbd_gs_can: USBD_GS_CAN_Config_Request(): pass data
buffer to USBD_CtlSendData() directly" control frames from Device ->
Host are not copied to hcan->ep0_buf anymore. Shrink
CAN_CMD_PACKET_SIZE to minimal size.
2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
35fb74228b compiler.h: add some min() and max() macros 2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
7d23053caa usbd_gs_can: USBD_GS_CAN_Config_Request(): pass data buffer to USBD_CtlSendData() directly
Do not copy the control data to the intermediate buffer hcan->ep0_buf,
but directly pass the pointer to the data to USBD_CtlSendData().

Some data is located in the ROM (USBD_GS_CAN_btconst,
USBD_GS_CAN_dconf) while other is located in BSS or stack.

Tested on STM32F072.
2023-10-15 19:03:14 +02: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
d678d47915 usbd_gs_can: USBD_GS_CAN_EP0_RxReady(): make use of USBD_GS_CAN_GetChannel() 2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
61d366e7a4 usbd_gs_can: USBD_GS_CAN_Config_Request(): introduce USBD_GS_CAN_GetChannel() and make use of it 2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
4dcd1c7319 usbd_gs_can: USBD_GS_CAN_EP0_RxReady(): limit scope of timing and mode 2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
548bb6de6f usbd_gs_can: USBD_GS_CAN_Config_Request(): make use of fallthrough 2023-10-15 19:03:14 +02:00
Marc Kleine-Budde
66aa53873f usbd_gs_can: USBD_GS_CAN_Config_Request(), USBD_GS_CAN_Config_Request(): sort switch statements
In USBD_GS_CAN_Config_Request(), sort the switch statement by
GS_USB_BREQ vlaue as much as possible, but don't duplicate code.

First place the "Host -> Device" calls which use USBD_CtlPrepareRx().
Followed by the "Device -> Host" calls which are using
USBD_CtlSendData().

For USBD_GS_CAN_EP0_RxReady(), simply sort by GS_USB_BREQ value.
2023-10-15 19:02:44 +02:00
Marc Kleine-Budde
1c1cd11ac0 usbd_gs_can: bring callback functions into same order as assigned in USBD_ClassTypeDef USBD_GS_CAN
No functional change intended.
2023-10-13 08:24:14 +02:00
Marc Kleine-Budde
6fa452a310 usbd_gs_can: move init of USBD_ClassTypeDef USBD_GS_CAN to end
This avoids the forward declarations. No functional change intended.
2023-10-13 08:24:14 +02:00
Marc Kleine-Budde
fa7b91bcc5 usbd_gs_can: USBD_GS_CAN_Transmit(): mark as static 2023-10-13 08:24:14 +02:00
Marc Kleine-Budde
5b9c788ac6 main: can_parse_error_status(): move last_err into can_data_t
This is a preparation patch to support more then 1 channel.
2023-10-13 08:24:14 +02:00
Marc Kleine-Budde
226afd795d usbd_gs_can: USBD_GS_CAN_SuspendCallback(): use ARRAY_SIZE(hcan->channels) instead of NUM_CAN_CHANNEL 2023-10-13 08:24:14 +02:00
Marc Kleine-Budde
85c92ee306 usbd_gs_can: USBD_GS_CAN_SuspendCallback(): remove not needed null pointer check for hcan
In main() the USBD_GS_CAN_Init() is called (which assigns
pdev->pClassData), before the USB is started. Remove not needed null
pointer check in USBD_GS_CAN_SuspendCallback().
2023-10-13 08:24:14 +02:00
Marc Kleine-Budde
1c386e89ce compiler.h: add fallthrough
Import from FreeBSD.
2023-10-13 08:21:26 +02:00
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
Venelin Efremov
7a4fcc16e8 usbd_gs_can: use NUM_CAN_CHANNEL to set USBD_GS_CAN_dconf::icount
...instead of hard coding 1 channel.
2023-05-10 17:29:19 +02:00
Marc Kleine-Budde
23f43f17e3 usbd_gs_can: use C99 initializers for USBD_GS_CAN_dconf and USBD_GS_CAN_btconst 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
3b04c3f9e6 usbd_desc: remove unused and unreferenced USBD_FS_USRStringDesc 2023-05-10 17:29:18 +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
cee17f3d0d gcc-arm-none-eabi-8-2019-q3-update: remove trailing whitespace 2023-05-10 16:19:50 +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
Andras Gemes
ac71cb4126
CI: replace set-output 2023-04-25 22:06:14 +02:00
Andras Gemes
8d531f4afc README: fix some typos 2023-04-22 10:58:24 -04:00
Andras Gemes
49eb5da92a gitignore: add .idea/ to ignored files 2023-04-22 10:57:49 -04:00
Andras Gemes
ff6eb19b10
README: fix broken CANtact links 2023-04-22 16:18:25 +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
Jonas Martin
dffacdeafa stm32g0xx: usb: fix stall on high load USB endpoints
Having two writes to clean and set COUNTn_RX and NUM_BLOCK results in
a small windows in which COUNTn_RX and NUM_BLOCK are zero.

This results in a stall as the buffer is empty (ready to receive) but
also has no space to receive the package into.

Signed-off-by: Jonas Martin <j.martin@pengutronix.de>
2023-02-13 09:20:32 +01:00
Eya
b6d102871e stm32g0xx: usb: Use correct macro to clear RXBD register block numbers
Cherry-picked from upstream commit Fixes: e289146768cf ("[LL][USB] Use
correct macro to clear RXBD register block numbers")

https://github.com/STMicroelectronics/stm32g0xx_hal_driver.git
2023-02-13 09:20:32 +01:00
Marc Kleine-Budde
4a1e646cdb bxcan: can_enable(): fix disabling of standby pin
The binary inverse of 0x1 is 0xfe not 0x0. Fix this by using a logic
negation instead.

Fixes: f4f1586dbf56 ("can.c: use GPIO_INIT_STATE to set CANSTBY pin")
2023-01-16 16:58:41 +01:00
Marc Kleine-Budde
e2b2ef93c1 gdb_oocd.cmds, openocd.cfg: remove executable flag
Fixes: 99a8eac354b5 ("add "make debug" target for openocd"
2022-12-15 11:23:12 +01:00
fenugrec
f07aed4a5b device: add basic (incomplete) G0 file
leftover from last commit. Target doesn't build by default, assuming
broken
2022-12-12 11:27:18 -05: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
fenugrec
0c23387317 cmake : remove some duplication in add_XYZ_target 2022-12-12 11:09:54 -05:00
ConvertDevice
537c0860c3 feat: change xCAN01 to xCAN 2022-12-11 11:56:15 +08:00
fenugrec
dfdcb38336 ldscripts : move init/fini_array sections to flash
startup files generated by stm32cubeIDE do this. Mostly useless since
none of our code uses that; the linking step gets rid of those sections
anyway.

objdump before:
200000a8 l       .data	00000000 __fini_array_end
200000a4 l       .data	00000000 __fini_array_start
200000a4 l       .data	00000000 __init_array_end
200000a0 l       .data	00000000 __preinit_array_end
200000a0 l       .data	00000000 __init_array_start
200000a0 l       .data	00000000 __preinit_array_start

after:
0800419c l       .fini_array	00000000 __fini_array_end
08004198 l       .fini_array	00000000 __fini_array_start
08004198 l       .init_array	00000000 __init_array_end
08004194 l       .preinit_array	00000000 __preinit_array_end
08004194 l       .init_array	00000000 __init_array_start
08004194 l       .preinit_array	00000000 __preinit_array_start
2022-12-05 13:47:01 -05:00
fenugrec
bef47ab1bc gpio : make DCDC_EN and nSI86EN pins generic
other boards may eventually have similar functions.
2022-12-05 13:34:39 -05:00
fenugrec
2e2e09c122 override __register_exitproc()
atexit() is meaningless on this kind of embedded fw. Overriding this
symbol saves a bunch of memory (384 B flash on cannette).

Ref:
https://sourceware.org/git/?p=newlib-cygwin.git;a=blob_plain;f=newlib/libc/stdlib/__atexit.c;hb=HEAD
2022-11-28 12:24:38 -05:00
fenugrec
83c7df7451 led_update_normal_mode() : pass 'now' as argument 2022-11-28 11:40:29 -05: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