259 Commits

Author SHA1 Message Date
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
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
d719705e93 Update flash.c to support the G0 programming
The STM32G0 uses double word programming for flash.  Update the routine to handle this new architecture.
2022-11-14 10:34:00 -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
Ryan Edwards
5645f93365 Fix RAM size in linker
I never updated the RAM size in the linker when creating it from the template.  If I ever use 144K I'm writing very poor code!
2022-11-14 10:02:30 -05:00
Ryan Edwards
051006b4e3 Changes to the USB configuration file to support the USB controller on the STM32G0xx
Minor changes required to support new configuration flags used with the "USB_DRD_FS" implementation on the STM32G0xx. No changes needed to be made to the STM32 HAL USB Device Library to support.
2022-11-14 10:01:42 -05:00
Ryan Edwards
ef416f8d6a Add the interrupt table to support the STM32G0xx microcontroller
This interrupt table implements the minimal number of function calls to support candleLight.  This table was converted and imported from the CubeMX file startup_stm32g0b1ketx.s

Add the changes to support the RCC clock init for the STM32G0xx

Code copied from the autogenerated code from the STM32 CubeMX software
2022-11-14 09:57:31 -05:00
Ryan Edwards
e8d82ef7ae Add the CMake files to support the STM32G0
Add the STM32G0 to the CMake setup.  This CMake is specific to the STM32G0B1xK device.  Also included the linker file that is required for the make.

Currently G0 targets are disabled by default to keep project buildable
as-is.
2022-11-14 09:15:58 -05:00
Ryan Edwards
d0cd8cf0d9 Add STM HAL libraries for the STM32G0xx
Add the STM32 library files to support the STM32G0 products. The chipset files included support the STM32G0B1xK which supports 1 Full Speed USB and 2 CANFD channels.

This also includes a version bump for some of the common files (CMSIS,
etc)
2022-11-14 09:15:57 -05:00
Marc Kleine-Budde
32fc94118e editorconfig: add minimal editorconfig
GH parses the .editorconfig for displaying code. Add minimal
editorconfig to display our code, the STM code looks good at first
glance, too.
2022-11-14 14:13:32 +00: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
Marc Kleine-Budde
439d122d52 cmake: add_link_options(): add LINKER:--print-memory-usage
This gives a nice memory usage overview during linking:

| Memory region         Used Size  Region Size  %age Used
|            FLASH:       15476 B       127 KB     11.90%
|              RAM:        4304 B        16 KB     26.27%
|             DATA:           4 B         1 KB      0.39%
2022-11-11 00:08:56 +01:00
Marc Kleine-Budde
dcdf5564a4 cmake: add_link_options(): use LINKER: instead of -Xlinker
Using "LINKER:" is a portable way to pass options to the linker tool.

Link: https://cmake.org/cmake/help/v3.25/command/add_link_options.html#handling-compiler-driver-differences
2022-11-11 00:05:26 +01:00
Marc Kleine-Budde
2d11092425 cmake: add_compile_options(), add_link_options(): only 1 option per line and sort them
Only cleanups, no functional change intended.
2022-11-11 00:04:59 +01: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
Ryan Edwards
8f9fa7788c cmake: add µC series letter to TGT*_LIST variables
This is a preparation patch to add support for the STM32G0 series.
2022-11-08 21:26:24 +01:00
Ryan Edwards
beaa9bdecf gitignore: add ignores for files created by the STM32 IDE
The additions to the ignore are to prevent files generated by the
STM32 IDE from being tracked by git.
2022-11-08 21:24:36 +01:00
Marc Kleine-Budde
b44d9cf8bd gitignore: sort 2022-11-08 21:22:55 +01:00