277 Commits

Author SHA1 Message Date
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
fenugrec
a0a333ae13 ldscripts: remove .jcr sections 2022-11-17 14:06:23 -05: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
f4f1586dbf can.c: use GPIO_INIT_STATE to set CANSTBY pin 2022-11-17 13:05:48 -05:00
fenugrec
718882b354 move GPIO_INIT_STATE macro to gpio.h 2022-11-17 13:01:58 -05:00
Marc Kleine-Budde
59896b65fd startup: get rid of zero table and fix copy_table 2022-11-17 12:50:07 -05:00
fenugrec
ac24146664 cmake : generate ldscripts automatically
99% of the ldscripts is identical, which makes it a pain to maintain.

Now we use cmake 'configure_file()' with a handful of variables to
produce each ldscript from a common template.
2022-11-17 12:40:26 -05:00
gerryqd
3e3358943f
Fix the issue that device cannot be recognized correctly
The kernel reports error message as below,

    Couldn't send data format (err=-32)

Seems caused by issue introduce in commit below,

    a0caf93e50edd081
2022-11-16 13:59:31 +08:00
Marc Kleine-Budde
88bf7f567c usbd_gs_can: don't announce that we support GS_CAN_FEATURE_USER_ID
...it has been removed in a0caf93e50ed ("Remove flash-as-eeprom
emulation for USER_ID").

Fixes: a0caf93e50ed ("Remove flash-as-eeprom emulation for USER_ID")
2022-11-14 11:30:54 -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