# Libcanard not working on stm32f4discovery

**URL:** <https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060>\
**Category:** Cyphal & DroneCAN\
**Created:** [August 21, 2018, 4:26pm UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060 "2018-08-21T16:26:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albert\_martinez](https://forum.zubax.com/user_avatar/forum.zubax.com/albert_martinez/32/210_2.png) [@Albert\_martinez](https://forum.zubax.com/u/Albert_martinez)\
**Post date:** [August 21, 2018, 4:26pm UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/1 "2018-08-21T16:26:48Z")

</div>

Hi,

I have 2 Babel boards. I wanted to follow the tutorial on knowledge base, but I am stuck on the first one…

I wanted to compile the code into a stm32f4discovery board, this has an external crystal HSE=8KHz. I used CAN 1 in port PD0 and PD1 (Rx,Tx). The code i compiling and I am able to load into the board , but It is not transmitting. Actually the code returns with **CANARD\_STM32\_ERROR\_UNSUPPORTED\_BIT\_RATE**. Is this a timing issue? What else could it be?

Gui Tool and Babel are working find, as I tried to communicate with a Pixhawk 2.

Code is the same as in you basic example.

I will appreciate any help, as I would like to get libcanard running on the discovey before touching a babel hardware.

Sincerely,

Albert

---

<div class="post-metadata">

**Author:** ![pavel-kirienko](https://forum.zubax.com/user_avatar/forum.zubax.com/pavel-kirienko/32/180_2.png) [@pavel-kirienko](https://forum.zubax.com/u/pavel-kirienko)\
**Post date:** [August 22, 2018, 7:28am UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/2 "2018-08-22T07:28:21Z")

</div>

Hi Albert,

Have you updated the HSE configuration in the source? What bit rate are you trying to use?

---

<div class="post-metadata">

**Author:** ![Albert\_martinez](https://forum.zubax.com/user_avatar/forum.zubax.com/albert_martinez/32/210_2.png) [@Albert\_martinez](https://forum.zubax.com/u/Albert_martinez)\
**Post date:** [August 22, 2018, 8:45am UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/3 "2018-08-22T08:45:22Z")

</div>

Hi Pavel,

thanks for the fast answer. I set it to HSE\_VALUE=8000000. Taget\_bitrate is set to 1000000, as in your example.  
you can look here: [GitHub - kuiskas/libcanard\_test](https://github.com/kuiskas/libcanard_test)  
I also had problems under linux(System Workbench) with usleep(). That is why I am trying under windows (IAR). Is there any other function I can use in order to make a standard delay? Maybe with Systicks?

thanks in advance

---

<div class="post-metadata">

**Author:** ![pavel-kirienko](https://forum.zubax.com/user_avatar/forum.zubax.com/pavel-kirienko/32/180_2.png) [@pavel-kirienko](https://forum.zubax.com/u/pavel-kirienko)\
**Post date:** [August 22, 2018, 9:14am UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/4 "2018-08-22T09:14:11Z")

</div>

You should determine which exact part of the CAN timing settings computation fails with that error. Put some breakpoints.

> I also had problems under linux(System Workbench) with usleep(). That is why I am trying under windows (IAR). Is there any other function I can use in order to make a standard delay? Maybe with Systicks?

You should implement it yourself; yes, you can use the SysTick timer for that.

---

<div class="post-metadata">

**Author:** ![Albert\_martinez](https://forum.zubax.com/user_avatar/forum.zubax.com/albert_martinez/32/210_2.png) [@Albert\_martinez](https://forum.zubax.com/u/Albert_martinez)\
**Post date:** [August 27, 2018, 4:25pm UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/5 "2018-08-27T16:25:39Z")

</div>

Thanks for the answer. At the end it was a timing issue, somehow the stm32f4 discovery did init at a wrong frequency.  
I went trough your tutorial and now I would like to test some of the libuavcan functionalities before jumping into nuttx. Do you have any bare example somewhere in github which I could follow. This will be really usefull.

---

<div class="post-metadata">

**Author:** ![pavel-kirienko](https://forum.zubax.com/user_avatar/forum.zubax.com/pavel-kirienko/32/180_2.png) [@pavel-kirienko](https://forum.zubax.com/u/pavel-kirienko)\
**Post date:** [August 27, 2018, 4:41pm UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/6 "2018-08-27T16:41:54Z")

</div>

I think the best starting point are the official libuavcan tutorials: [Open technology for real-time intravehicular distributed computing and communication based on modern networking standards](https://uavcan.org/Implementations/Libuavcan/Tutorials/)

Libuavcan is a bit hard to set up initially, but once it builds, further development is a breeze.

---

<div class="post-metadata">

**Author:** ![Albert\_martinez](https://forum.zubax.com/user_avatar/forum.zubax.com/albert_martinez/32/210_2.png) [@Albert\_martinez](https://forum.zubax.com/u/Albert_martinez)\
**Post date:** [August 28, 2018, 4:29pm UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/7 "2018-08-28T16:29:52Z")

</div>

Hi again Pavel,  
well I’ve been reading the documentation you pointed at. I wasn’t able to setup the enviroment. Libuavcan theory can I understand, but I just find too complicated the setup for stm32 (system workbench) without any example.  
In the tutorial:

> **[Open technology for real-time communications in cyber-physical systems](https://opencyphal.org/)**
>
> Cyphal is an open technology for real-time intravehicular distributed computing and communication
> based on modern networking standards (Ethernet, CAN FD, etc.).
> It is created to address the challenge of on-board deterministic computing and...

under Running on stm32 you refer to a STM32 test application. Does this exists?

---

<div class="post-metadata">

**Author:** ![pavel-kirienko](https://forum.zubax.com/user_avatar/forum.zubax.com/pavel-kirienko/32/180_2.png) [@pavel-kirienko](https://forum.zubax.com/u/pavel-kirienko)\
**Post date:** [August 29, 2018, 3:53pm UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/8 "2018-08-29T15:53:00Z")

</div>

We [used to have it, it got removed](https://github.com/UAVCAN/libuavcan/pull/125) because at this point there are plenty of open source projects that leverage libuavcan on STM32. E.g. [https://github.com/PX4/sapog](https://github.com/PX4/sapog) or [GitHub - Zubax/zubax\_gnss: Zubax GNSS module](https://github.com/Zubax/zubax_gnss)

---

<div class="post-metadata">

**Author:** ![Albert\_martinez](https://forum.zubax.com/user_avatar/forum.zubax.com/albert_martinez/32/210_2.png) [@Albert\_martinez](https://forum.zubax.com/u/Albert_martinez)\
**Post date:** [September 4, 2018, 7:25am UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/9 "2018-09-04T07:25:13Z")

</div>

Hi Pavel,  
yes I saw the projects. I tought it would be good to get it running baremetal as I do not know how to use ChibiOS and Nuttx does not implement it anymore. Anyway I manage to use it with PX4 firmware.  
Just one question. In case of 2 CAN buses, how could I chose which one I am sending to. Do I have to create 2 task or there is other easier workaround?

---

<div class="post-metadata">

**Author:** ![pavel-kirienko](https://forum.zubax.com/user_avatar/forum.zubax.com/pavel-kirienko/32/180_2.png) [@pavel-kirienko](https://forum.zubax.com/u/pavel-kirienko)\
**Post date:** [September 9, 2018, 11:07am UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/10 "2018-09-09T11:07:47Z")

</div>

> In case of 2 CAN buses, how could I chose which one I am sending to. Do I have to create 2 task or there is other easier workaround?

If you have more than one CAN interface, two configurations are possible:

- Redundant transport configuration. In this case, you create only one CAN node, and it uses all available interfaces simultaneously. You don’t get to choose which one to use when – they are always used at the same time in the same manner. That’s the purpose of modular redundancy – if one interface fails anywhere on the bus, the whole redundant transport will continue functioning unaffected.
- Two independent interfaces (this case is extremely rare and I am nearly certain this is not what you need). In this case, you create an independent node per interface, and handle each one separately. This architecture may be useful, for example, if you’re building a bridge between several different UAVCAN networks.

---

<div class="post-metadata">

**Author:** ![Albert\_martinez](https://forum.zubax.com/user_avatar/forum.zubax.com/albert_martinez/32/210_2.png) [@Albert\_martinez](https://forum.zubax.com/u/Albert_martinez)\
**Post date:** [February 5, 2019, 6:22pm UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/11 "2019-02-05T18:22:26Z")

</div>

Hi Pavel,

I am actually looking for two independent interfaces for PX4. I was looking at your code and trying to use CanInitHelper in order to separate the two interface and use each one in a different instance, but I am not sure if it is the best option. In your code is also described, that CanInitHelper has to be instantiated only once, does that mean I can not use it twice in order to start two instances with different interfaces?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![pavel-kirienko](https://forum.zubax.com/user_avatar/forum.zubax.com/pavel-kirienko/32/180_2.png) [@pavel-kirienko](https://forum.zubax.com/u/pavel-kirienko)\
**Post date:** [February 8, 2019, 1:10pm UTC](https://forum.zubax.com/t/libcanard-not-working-on-stm32f4discovery/1060/12 "2019-02-08T13:10:52Z")

</div>

> [@Albert\_martinez](#):
>
> In your code is also described, that CanInitHelper has to be instantiated only once, does that mean I can not use it twice in order to start two instances with different interfaces?

You can’t use the stock driver at all then, because it does not support the use case you’re describing (as I said, it’s an extremely uncommon one). Write your own driver.
