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.
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>
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.
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 ).
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.
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.
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.
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.
...it has been removed in a0caf93e50ed ("Remove flash-as-eeprom
emulation for USER_ID").
Fixes: a0caf93e50ed ("Remove flash-as-eeprom emulation for USER_ID")
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%
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.
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.
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
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.
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)
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%
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%
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.