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().
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.
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>
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")
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
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
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.
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.