Add CAN support for STM32L4KC
Summary
Nucleo-L432KC provides a CAN1 interface, but the current NuttX configuration misses both the PINs declaration and the setup definition.
Impact
This PR aims to add CAN support to the nucleo-l432kc board and a dedicated configuration where CAN is enabled, so it is available out of the box for testing.
Testing
Trying to compile with the following configuration: CAN1 enabled, CAN Driver enabled, CAN example enabled.
Before PR:
After PR:
Hello @LightDestory and thank you for your first PR welcome to The NuttX Club :-)
We have automated CI verification for each PR, including build and code formatting, all checks must pass to unblock merge.
I can see formatting needs some update. Please take a look at:
Please update git commit message:
- topic
boards/nucleo-l432kc: add can support and configuration.- please add some short description to the commit so people reading the
git logwill know what/why happened here :-)All three sections of the PR are mandatory (Summary, Impact, Testing). Please update :-)
- Impact - adds CAN support to nucleo-l432kc board and dedicated configuration where CAN is enabled so it is available out of the box for testing.
- Testing - this is very important to show the patch that you provide works and was tested, you can provide build log essentials + testing logs (text preferred).
Thanks for your review. I tried to meet all the requirements.
I have converted the PR to draft, I will provide text logs of the CAN as soon as I get my hands on the board itself.
Regarding the warnings, I just took as reference the can implementation for the l476rg.
@LightDestory: I have converted the PR to draft, I will provide text logs of the CAN as soon as I get my hands on the board itself.
Thank you :-) In a perfect situation we want to include code that is already verified on a real world hardware. I know this is copy-paste from similar MCU but there may be slight differences that will not allow exact same code to work on different MCU (happened to me recently with stm32) :-)
Regarding the warnings, I just took as reference the can implementation for the l476rg.
It would be nice to update the existing code as well when you know it already and there are known issues :-) This fix updates may come already in this PR as part of L432 but then you will have copy-paste for L476 :-)
Thanks again @LightDestory :-)
I can confirm that CAN works on my L4 board :)
@LightDestory same issue that @cederom pointed early. The issue was not caused by you, but the CI detected that stm32l4_can.c in arch/ has some printing error. Replace %d from those variables that are unsigned int with %u or %" PRIu32 ".
chip/stm32l4_can.c: In function 'stm32l4can_ioctl':
Error: chip/stm32l4_can.c:880:19: error: format '%d' expects argument of type 'int', but argument 5 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
880 | caninfo("TS1: %d TS2: %d BRP: %d\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
881 | bt->bt_tseg1, bt->bt_tseg2, brp);
| ~~~
| |
| uint32_t {aka long unsigned int}
chip/stm32l4_can.c:880:42: note: format string is defined here
880 | caninfo("TS1: %d TS2: %d BRP: %d\n",
| ~^
| |
| int
| %ld
chip/stm32l4_can.c: In function 'stm32l4can_txready':
Error: chip/stm32l4_can.c:1335:11: error: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
1335 | caninfo("CAN%d TSR: %08x\n", priv->port, regval);
| ^~~~~~~~~~~~~~~~~~~ ~~~~~~
| |
| uint32_t {aka long unsigned int}
chip/stm32l4_can.c:1335:26: note: format string is defined here
1335 | caninfo("CAN%d TSR: %08x\n", priv->port, regval);
| ~~~^
| |
| unsigned int
| %08lx
chip/stm32l4_can.c: In function 'stm32l4can_txempty':
Error: chip/stm32l4_can.c:1366:11: error: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
1366 | caninfo("CAN%d TSR: %08x\n", priv->port, regval);
| ^~~~~~~~~~~~~~~~~~~ ~~~~~~
| |
| uint32_t {aka long unsigned int}
chip/stm32l4_can.c:1366:26: note: format string is defined here
1366 | caninfo("CAN%d TSR: %08x\n", priv->port, regval);
| ~~~^
| |
| unsigned int
| %08lx
chip/stm32l4_can.c: In function 'stm32l4can_bittiming':
Error: chip/stm32l4_can.c:1685:11: error: format '%d' expects argument of type 'int', but argument 4 has type 'long unsigned int' [-Werror=format=]
1685 | caninfo("CAN%d PCLK1: %d baud: %d\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
chip/stm32l4_can.c:1685:26: note: format string is defined here
1685 | caninfo("CAN%d PCLK1: %d baud: %d\n",
| ~^
| |
| int
| %ld
Error: chip/stm32l4_can.c:1685:11: error: format '%d' expects argument of type 'int', but argument 5 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
1685 | caninfo("CAN%d PCLK1: %d baud: %d\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1686 | priv->port, STM32L4_PCLK1_FREQUENCY, priv->baud);
| ~~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
chip/stm32l4_can.c:1685:35: note: format string is defined here
1685 | caninfo("CAN%d PCLK1: %d baud: %d\n",
| ~^
| |
| int
| %ld
Error: chip/stm32l4_can.c:1738:11: error: format '%d' expects argument of type 'int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
1738 | caninfo("TS1: %d TS2: %d BRP: %d\n", ts1, ts2, brp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| uint32_t {aka long unsigned int}
chip/stm32l4_can.c:1738:18: note: format string is defined here
1738 | caninfo("TS1: %d TS2: %d BRP: %d\n", ts1, ts2, brp);
| ~^
| |
| int
| %ld
Error: chip/stm32l4_can.c:1738:11: error: format '%d' expects argument of type 'int', but argument 4 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
1738 | caninfo("TS1: %d TS2: %d BRP: %d\n", ts1, ts2, brp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| uint32_t {aka long unsigned int}
chip/stm32l4_can.c:1738:26: note: format string is defined here
1738 | caninfo("TS1: %d TS2: %d BRP: %d\n", ts1, ts2, brp);
| ~^
| |
| int
| %ld
Error: chip/stm32l4_can.c:1738:11: error: format '%d' expects argument of type 'int', but argument 5 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
1738 | caninfo("TS1: %d TS2: %d BRP: %d\n", ts1, ts2, brp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~
| |
| uint32_t {aka long unsigned int}
chip/stm32l4_can.c:1738:34: note: format string is defined here
1738 | caninfo("TS1: %d TS2: %d BRP: %d\n", ts1, ts2, brp);
| ~^
| |
| int
| %ld
chip/stm32l4_can.c: In function 'stm32l4can_exitinitmode':
Error: chip/stm32l4_can.c:1857:14: error: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'uint32_t' {aka 'long unsigned int'} [-Werror=format=]
1857 | canerr("ERROR: Timed out waiting to exit initialization mode: %08x\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1858 | regval);
| ~~~~~~
| |
| uint32_t {aka long unsigned int}
chip/stm32l4_can.c:1857:72: note: format string is defined here
1857 | canerr("ERROR: Timed out waiting to exit initialization mode: %08x\n",
| ~~~^
| |
| unsigned int
| %08lx
ping @LightDestory