231 Commits

Author SHA1 Message Date
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
Marc Kleine-Budde
2bba52ffc9 gs_usb.h: document GS_CAN_FEATURE_GET_STATE, GS_USB_BREQ_GET_STATE
In commit
40e1997d45
[1] GS_CAN_FEATURE_GET_STATE has been added to the Linux driver.
Document this bit here accordingly.

The new feature ("GS_CAN_FEATURE_GET_STATE") indicates that the state
of the CAN controller can be queried with the new
GS_USB_BREQ_GET_STATE control message.

[1] https://git.kernel.org/torvalds/c/40e1997d4551e6053fc2f61959628da474775dc5
2022-10-31 14:06:28 +01:00
Marc Kleine-Budde
ad2f13ace7 gs_usb.h: document GS_CAN_MODE_BERR_REPORTING
In commit
1f1835264d
[1] Bus Error Reporting has been added to the Linux driver. Document
this bit here accordingly.

The new feature ("GS_CAN_FEATURE_BERR_REPORTING") indicates that the
bus error reporting in the CAN controller can switched on and off with
the GS_CAN_MODE_BERR_REPORTING mode bit in the GS_USB_BREQ_MODE
control message.

[1] https://git.kernel.org/torvalds/c/1f1835264d81da03fcd05646542a622678b379d6
2022-10-31 14:06:08 +01:00
fenugrec
e4b7a7a1fb github action : bump actions/checkout to v3 2022-10-20 19:38:07 -04:00
Marc Kleine-Budde
a9b6414cc0 usbd_gs_can: USBD_GS_CAN: remove not needed comments 2022-10-19 16:51:19 -04:00
Marc Kleine-Budde
1a36d8de55 usbd_gs_can: USBD_GS_CAN: make use of C99 initializers 2022-10-19 16:51:19 -04:00
Marc Kleine-Budde
bbe39cad2e usbd_gs_can: remove unused USBD_GS_CAN_HandleTypeDef::host_config
The GS_USB_BREQ_HOST_FORMAT has never been supported by the
candleLight firmware, and since Linux v5.10 the gs_usb driver works on
Big Endian Linux systems, too.

So remove host_config handling from the firmware. This saves some
bytes:

| add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-16 (-16)
| Function                                     old     new   delta
| USBD_GS_CAN_EP0_RxReady                      640     624     -16
| Total: Before=17382, After=17366, chg -0.09%
2022-10-19 16:51:19 -04:00
Daniel Trevitz
17a7fe8445 Check code formatting on PR
Check the code formatting of a PR by looking up the files in git diff HEAD^
If the uncrustify config sees a change, yell about it.

Signed-off-by: Daniel Trevitz <daniel.trevitz@wika.com>
2022-10-15 22:48:05 -04:00
fenugrec
12cc477412 some misc whitespace leftovers uncrustified
closes gh #118
2022-10-15 10:01:51 -04:00
Jeroen Hofstee
c25f4ce480 remove odd err-frames
The gusb-interface can report completely weird error-frames,
like being in error-ative (based on counters), and error-warning,
and bus-off at the same time.

To fix this:
  - only send state changes once.
  - don't send LEC / err counters in bus-off (invalid anyway).
  - don't send empty error frames.
2022-10-15 10:00:52 -04:00
Jeroen Hofstee
9a663007f5 remove triggering error message based on counter values
Since all bit errors already trigger sending a error msg,
remove the code triggering on counters going upwards, since they
are send anyway. See [1] "This if statement doesn't normally do
anything", get rid of it.

[1] https://github.com/candle-usb/candleLight_fw/pull/61
2022-10-15 10:00:52 -04:00
Daniel Trevitz
d991308d63 Help the compiler optimize out the terminating resistor
Use get_term to make sure the compiler can identify that the branch will always fail.

Signed-off-by: Daniel Trevitz <daniel.trevitz@wika.com>
2022-10-12 19:16:41 -04:00
Daniel Trevitz
0a1d6dc920 Add switchable terminating resistor support
Add a USB message which controls a GPIO for a specified CAN bus.
The GPIO activates a SSR to connect a 120Ohm terminating resistor
  to the specified CAN bus.

Signed-off-by: Daniel Trevitz <daniel.trevitz@wika.com>
2022-10-12 17:39:21 -04:00
fenugrec
f45060be53 rework some #include lines
with help from include-what-you-use (iwyu-tool). It's not quite clever
enough to understand our intent of including "hal_include.h" but still
offers good suggestions.
2022-10-12 17:28:50 -04:00
Daniel Trevitz
cfca364c2a Uncrustify the code 2022-10-11 19:27:57 -04:00
Daniel Trevitz
4540120e94 Use consistent whitespace
Use tabs in cmake to match c file formatting

Signed-off-by: Daniel Trevitz <daniel.trevitz@wika.com>
2022-10-05 22:30:06 -04:00
Daniel Trevitz
0e53857656 Generalize the gpio configuration
Move the nCANSTBY_Pin to be avaliable for other boards. Make the
  LED Rx and Tx pins optional.

Signed-off-by: Daniel Trevitz <daniel.trevitz@wika.com>
2022-10-05 21:43:08 -04:00
Marc Kleine-Budde
151ec30d78 gs_usb: document switchable termination support 2022-09-29 10:10:53 +02:00
Marc Kleine-Budde
c19f3a17e1 cmake: add -Wstrict-prototypes
Suggested-by: fenugrec <fenugrec@users.sourceforge.net>
Link: https://github.com/candle-usb/candleLight_fw/issues/103
Signed-off-by: Marc Kleine-Budde <mkl@blackshift.org>
2022-08-28 21:47:36 +02:00
Marc Kleine-Budde
c7547b0dcd interrupts: fix function declaration
Reported-by: https://github.com/ReXT3D
Signed-off-by: Marc Kleine-Budde <mkl@blackshift.org>
2022-08-28 21:47:36 +02:00
Marc Kleine-Budde
e6766934aa leds: mark led_identify_seq as const
This saves a few bytes:

before:
| create and sign dfu bin file: candleLight_fw
|    text	  data	   bss	   dec	   hex	filename
|   15708	   192	  1976	 17876	  45d4	candleLight_fw

after:
| create and sign dfu bin file: candleLight_fw
|    text	  data	   bss	   dec	   hex	filename
|   15712	   184	  1976	 17872	  45d0	candleLight_fw

Signed-off-by: Marc Kleine-Budde <mkl@blackshift.org>
2022-08-28 00:31:22 +02:00
Marc Kleine-Budde
7860fef8fd USBD_GS_CAN_GetProtocolVersion(): remove unused function
Signed-off-by: Marc Kleine-Budde <mkl@blackshift.org>
2022-08-28 00:27:52 +02:00
Jeroen Hofstee
c105ca4847 completely reset the CAN peripheral
Make sure the CAN-bus state and associated error counters are
also reset in can_enable.

Writing to the ESR won't help, only the LEC field is writable, the rest
is read-only. The only reported way to make that work is by issuing an
RCC reset.

In addition, socketcan requires the CAN interface to be in active-error
state after open.
2022-08-26 22:09:47 -04:00
fenugrec
65cd7d76c9 reduce the scope of function / vars where possible
Originally by johfstee , but without modifying the
interrupt handler decls in src/interrupts.c
2022-08-26 22:00:50 -04:00
Jeroen Hofstee
9f07a4b223 use consistent whitespace
Use tabs for leading whitespace and spaces for continuation lines.
Besides that inconsistent whitespace looks odd, it causes unnecessary
merge conflicts.
2022-08-26 21:51:33 -04:00
Jeroen Hofstee
8049e7d8af remove unused received_count
commit 46b01339f5eeab1157d "Add new mode to pad output usb packets
to max packet size for better ..." introduced the never used global
variable received_count, so get rid of it again.
2022-08-25 09:36:41 +02:00
Jeroen Hofstee
f1be957992 remove unused USBD_GS_CAN_GetPadPacketsToMaxPacketSize
commit 46b01339f5eeab1157d "Add new mode to pad output usb packets
to max packet size for better ..." introduced an unused function
USBD_GS_CAN_GetPadPacketsToMaxPacketSize, get rid of it.
2022-08-25 09:36:41 +02:00
Jeroen Hofstee
4668b03c7d add stricter prototype checking
Functions in c which are declared as f() accept any argument. Declare
them as f(void) instead to declare that no arguments are allowed and
add uint32_t sysmem_base to dfu_jump_to_bootloader.
2022-08-25 09:36:41 +02:00
Jeroen Hofstee
4f51b8e964 use restore_irq to restore irq state
Since commit b5cc61b3317e "fix critical section handling", there are two
versions of enable_irq, enable_irq(void) as used by queue.c and
enable_irq(int primask) as used by usbd_gs_can.c. As a consequence
interrupts might be re-enabled too early in case of nested disable calls.

To prevent this, declared enable_irq as void, since it doesn't accept an
argument and add restore_irq which requires an argument and adjust users
of it.
2022-08-25 09:36:36 +02:00