351 Commits

Author SHA1 Message Date
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
fenugrec
b4ff7497aa led_update : assert on invalid mode 2022-11-25 08:36:40 -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
57d9900f5b queue: don't use global q_from_host, use the one from hGS_CAN instead
The next patch will replace the queue by a list and embed the list
head into the hGS_CAN. This is a preparation patch to make the diff
smaller.
2022-11-24 10:24:36 +01:00
Marc Kleine-Budde
0a864a3cbc main: replace send_to_host_or_enqueue() by queue_push_back()
Since 8b3a7b4565a3 ("Always queue frames to the host in order")
send_to_host_or_enqueue() always enqueues the frame to the q_to_host.

In order to make the patch that converts to Linux compatible lists
smaller, replace send_to_host_or_enqueue(...) by
queue_push_back(q_to_host, ...).

Suggested-by: fenugrec <fenugrec@users.sourceforge.net>
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
0612b5017f cmake: switch from -Os to -O2 optimization
This increases the code size, but even on a STMF042x6 fits into the
flash:

-Os:
| Memory region         Used Size  Region Size  %age Used
|            FLASH:       14180 B        32 KB     43.27%
|              RAM:        3744 B         6 KB     60.94%

-O2:
| Memory region         Used Size  Region Size  %age Used
|            FLASH:       17284 B        32 KB     52.75%
|              RAM:        3744 B         6 KB     60.94%

This optimization increases the max TX CAN bus load on a STM32F072
(1 MBit/s, DLC=1) from 77% to 84%.

For completeness:

-O3:
| Memory region         Used Size  Region Size  %age Used
|            FLASH:       22568 B        32 KB     68.87%
|              RAM:        3744 B         6 KB     60.94%

The max TX CAN bus load is 88%.

This also removes the -fno-move-loop-invariants option which was probably for
some gcc pre-4.9 behaviour (see
https://bugs.launchpad.net/gcc-arm-embedded/+bug/1395077 ).
2022-11-23 18:20:09 -05:00
fenugrec
e521e31665 README : add notes on contributing, and profiling v2.1 2022-11-23 10:45:40 -05:00
fenugrec
049e806d7b editorconfig : add info to configure git as well
Not sure where else to consign that info. Bundling a .gitconfig is not
appropriate in this case since we can't assume all platforms provide
"less" as a pager.
2022-11-23 10:28:32 -05:00
fenugrec
b3814f5f12 ldscripts : unmark RAM section as executable
It has no business being marked "rwx". Related to #106 on GH, but
doesn't fix the "LOAD segment with RWX permissions" warning.
2022-11-23 10:23:19 -05:00