STM32H7 CAN (port device for STM32H7)

820 views
Skip to first unread message

Clancys74

unread,
Jul 11, 2019, 11:57:58 AM7/11/19
to NuttX
Hello everyone,

I started trying NuttX some times ago and i think it is really good !

I used and try what was already implemented for the STM32H743 (also known as nucleo-h743 in some places in the code),
mainly the U(S)ART and the correct OS start.

After all that, i wanted to try to use the CAN.
I've used it with my board with bare-metal code from STM32CubeMX and it was working great.
However, i couldn't find a CAN port for my board in NuttX.
So i have tried to do my own port by using and adapting code from the "stm32" port.

After some times, everything compiled well and the RTOS was starting with the CAN example in Read/Write mode.
BUT an error occured immediately everytime i turned on my micro-controller :
ERROR: open /dev/can0 failed : 2 --> Happening on the line 300 of the can_main.c file.

If i understand correctly, my device is not initialized as error 2 means "No such file or directory".

Does someone have the idea of what i should check and where to finally make it work?
If needed, i would not be bothered to delete my actual nuttx project and restart it from scratch if i can get a complete tuto (what to modify, check and where) on how to correctly add a device from another nuttx port (stm32, stm32f7, ...).

Don't forget and hesitate to correct me if i've said something wrong in my message.

Sincerely,
Clancys.

Alan Carvalho de Assis

unread,
Jul 11, 2019, 12:23:56 PM7/11/19
to nu...@googlegroups.com
Hi Clancys,

Did you create a stm32_can.c inside your board configs/ to setup/init the CAN?

After compiling NuttX you can open the System.map and double check if the CAN functions are there. The fact the it is compiled doesn't mean it will be included in the final firmware.

BR,

Alan
--
You received this message because you are subscribed to the Google Groups "NuttX" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nuttx+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nuttx/f871a5c1-f566-4b1a-ad64-928133d7b15d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gregory Nutt

unread,
Jul 11, 2019, 12:33:06 PM7/11/19
to nu...@googlegroups.com

> I used and try what was already implemented for the STM32H743 (also
> known as nucleo-h743 in some places in the code),
> mainly the U(S)ART and the correct OS start.

STM32F7 would be a better place to port from.  The Cortex-M7 data cache
changes how drivers must be implemented.  In general (particularly if
the driver uses DMA), STM32 drivers will not be compatible with
STM32H7.  See
http://www.nuttx.org/doku.php?id=wiki:howtos:port-drivers_stm32f7 . That
Wiki page applies to the F7, but it also applies to the H7.



Clancys74

unread,
Jul 15, 2019, 9:54:21 AM7/15/19
to NuttX
Thanks for your responses and sorry for the delay, i was trying things out.

I got a stm32_can.c from another stm32 device and arrange it for my need and a ".o" file is created.
I checked the System.map and can_main is present but no other functions are so i don't know to be honest.
On a device with a working CAN module, what is present in the System.map ?

I try to understand the tutorial but to be honest i'm not sure if i understood everything correctly.
Based on what i understood, if i took the stm32_can.c/h files from the stm32f7 directory, i should be fine.
Am i right ?

Sincerely,
Clancys.

Clancys74

unread,
Jul 15, 2019, 10:43:05 AM7/15/19
to NuttX
Little remarks that i just found on the stm32f7 port of the CAN :

- The stm_can.c and stm_can.h are almost (some spaces are there or not) exactly the same as the stm32 port
- There is no stm32_can.c file in the configs/ for the stm32f7*

Does that mean that the port from stm32f4 to stm32f7 has never been done ?

Sincerely,
Clancys.

Gregory Nutt

unread,
Jul 15, 2019, 12:51:09 PM7/15/19
to nu...@googlegroups.com

 

 

- The stm_can.c and stm_can.h are almost (some spaces are there or not) exactly the same as the stm32 port

- There is no stm32_can.c file in the configs/ for the stm32f7*

 

Does that mean that the port from stm32f4 to stm32f7 has never been done ?

 

 

Yes. So you would have to start with STM3 F4.

Clancys74

unread,
Jul 16, 2019, 9:06:27 AM7/16/19
to NuttX
Oh... okay, it will take way longer than i expected then ^^

If we forget the potential memory error (because of the DMA) or a problem in the driver,
I still got the "can't open /dev/can0" error,
-- > the function "stm32_can_setup" (which should start the can pseudo-file) is not in System.map, is this normal ?
-- > If it is normal, what can be the reason for the pseudo-file to not be created ?

Clancys.

Gregory Nutt

unread,
Jul 16, 2019, 1:18:36 PM7/16/19
to nu...@googlegroups.com

 

If we forget the potential memory error (because of the DMA) or a problem in the driver,

I still got the "can't open /dev/can0" error,

-- > the function "stm32_can_setup" (which should start the can pseudo-file) is not in System.map, is this normal ?

 

Yes…IF you don’t all it.  You are probably not calling it because you are missing the configuration settings in the .config file.

 

Two choices:

 

(1) Initialize from NSH.  Needs

 

CONFIG_LIB_BOARDCTL=y and

CONFIG_NSH_ARCHINIT=y

 

Or

(2)  Initialized with a custom initialization thread:

 

CONFIG_LATE_INITIALIZE=y

 

-- > If it is normal, what can be the reason for the pseudo-file to not be created ?

 

Same answer

 

Greg

 

 

 

Gregory Nutt

unread,
Jul 16, 2019, 11:55:03 PM7/16/19
to nu...@googlegroups.com

 

 

Oh... okay, it will take way longer than i expected then ^^

 

You should compare the STM32H7 CAN register with the definitions in arch/arm/src/stm32/hardware/stm32_can.h.  I thik that the H7 CAN may be different from any other can driver.  It is not a CANFD peripheral?  I think that would require an all new, original CAN driver.  But what do I know, I am not an H7 export.

 

Clancys74

unread,
Jul 18, 2019, 3:33:07 AM7/18/19
to NuttX
I've compared it and it is a lot different, i am starting fresh from the STM32CubeMX fdcan functions to create a new driver.
Yes, it is FDCAN on the STM32H7 but the interrupt and the register have been modified (probably for speed or simplicity purposes i guess).

And last question (i hope ^^) :
- There is a lot of function in the stm32_can.c file, which ones are actually called during the process (for example from the can example) ?

Alan Carvalho de Assis

unread,
Jul 18, 2019, 9:01:57 AM7/18/19
to nu...@googlegroups.com
You need to call the function stm32_can_setup() during the initialization.

BR,

Alan
> --
> You received this message because you are subscribed to the Google Groups
> "NuttX" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nuttx+un...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nuttx/15215f45-ba8c-4b7d-8f31-37e2fd51a4ac%40googlegroups.com.

Hal Glenn

unread,
Jul 19, 2019, 10:41:18 AM7/19/19
to NuttX
As a side note when doing CAN debugging on the H7's,  those early H7 chips have a CAN bus errata that makes running two can buses at the same time impossible. (Spent a lot of time trying to solve that one). I think they fixed it on the newer die though. (they also have some pretty gnarly Ethernet errata)

Good luck, thanks all, looking forward to one day using the H7 port!
Hal


On Thursday, July 18, 2019 at 8:01:57 AM UTC-5, Alan Carvalho de Assis wrote:
You need to call the function stm32_can_setup() during the initialization.

BR,

Alan

On 7/18/19, Clancys74 <menoui...@gmail.com> wrote:
> I've compared it and it is a lot different, i am starting fresh from the
> STM32CubeMX fdcan functions to create a new driver.
> Yes, it is FDCAN on the STM32H7 but the interrupt and the register have
> been modified (probably for speed or simplicity purposes i guess).
>
> And last question (i hope ^^) :
> - There is a lot of function in the stm32_can.c file, which ones are
> actually called during the process (for example from the can example) ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "NuttX" group.
> To unsubscribe from this group and stop receiving emails from it, send an
Reply all
Reply to author
Forward
0 new messages