# Zubax babel schematic and hardware init for libcanard

**URL:** <https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252>\
**Category:** Cyphal & DroneCAN\
**Created:** [March 7, 2019, 4:56am UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252 "2019-03-07T04:56:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kent\_Martin](https://forum.zubax.com/letter_avatar_proxy/v4/letter/k/a698b9/32.png) [@Kent\_Martin](https://forum.zubax.com/u/Kent_Martin)\
**Post date:** [March 7, 2019, 4:56am UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/1 "2019-03-07T04:56:30Z")

</div>

Hi,  
I am trying to run libcanard on the zubax babel board.  
I couldn’t find a schematic anywhere to show what the crystal is and pin connections to the stm32.  
I am trying to use cubemx to set up a project so I need to know what the xtal frequency is and pins connceted. I also need to know what the HSE\_VALUE define refers to? Is it External crystal frequency or is it the system clock, or pll clk frequency?

Thanks.

---

<div class="post-metadata">

**Author:** ![alexander.sysoev](https://forum.zubax.com/letter_avatar_proxy/v4/letter/a/da6949/32.png) [@alexander.sysoev](https://forum.zubax.com/u/alexander.sysoev)\
**Post date:** [March 10, 2019, 7:46am UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/2 "2019-03-10T07:46:43Z")

</div>

Greetings! Please find babel schemaitc attached to this post  
[babel.pdf](https://forum.zubax.com/uploads/default/original/1X/2c6a1ace93bd65406e6bc9354e0c3f4881d0cf50.pdf) (58.2 KB)  
HSE\_VALUE is indeed frequency of the external crystal. System clock is obtained from it using PLL with its prescalers and dividers. UAVCAN may work with different system clock settings, it just has to know these settings. For that there is a function `canardSTM32ComputeCANTimings`.

---

<div class="post-metadata">

**Author:** ![Kent\_Martin](https://forum.zubax.com/letter_avatar_proxy/v4/letter/k/a698b9/32.png) [@Kent\_Martin](https://forum.zubax.com/u/Kent_Martin)\
**Post date:** [March 14, 2019, 1:59am UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/3 "2019-03-14T01:59:34Z")

</div>

Hi,  
Thanks, I did manage to create a startup project and got it to build and run, but it did not work. It got stuck in a tx function somewhere.  
Is there any chance i can get the original .ioc (cubemx ) file used to generate the project?  
I’m using SW4STM(ac6) not ewarm that appears was used in the sample code.  
There is something wrong. Most code should be the same but the startup (.s) file is not.  
I couldn’t see one there that was for sw4stm that would build on it, so I need to generate from cubemx.  
Having the original cubemx file would help greatly in narrowing down what the problem is.  
It might help to see where there are differences in generated source.

Thanks.

---

<div class="post-metadata">

**Author:** ![alexander.sysoev](https://forum.zubax.com/letter_avatar_proxy/v4/letter/a/da6949/32.png) [@alexander.sysoev](https://forum.zubax.com/u/alexander.sysoev)\
**Post date:** [March 17, 2019, 4:17pm UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/4 "2019-03-17T16:17:06Z")

</div>

> [@Kent\_Martin](#):
>
> 4STM(ac6) not ewarm that appears was used in the sample code.  
> There is something wrong. Most code should be the same but the startup (.s) file is not.  
> I couldn’t see one there that was for sw4stm that would build on it, so I need to generate from cubemx.  
> Having the original cubemx file would help greatly in narrowing down what the problem is.  
> It might help to see wh

I’m sorry but there is no \*.ioc file for this project as iCubeMX was not used to generate any code here.  
Stm32CubeMX is well known for the low quality code it generates so I try to avoid it if I can.  
If you’d like to use any kind of library for hardware init, I’d recommend you go on with SPL.  
Also, do you have step by step debug available? It would be useful to know on what step exactly everything stops.  
Best regards, Alex

---

<div class="post-metadata">

**Author:** ![Kent\_Martin](https://forum.zubax.com/letter_avatar_proxy/v4/letter/k/a698b9/32.png) [@Kent\_Martin](https://forum.zubax.com/u/Kent_Martin)\
**Post date:** [May 10, 2019, 2:00am UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/5 "2019-05-10T02:00:54Z")

</div>

Hi,  
I’m back on this again after a break.  
I created another project in ac6 with SPL drivers, then copied over the drivers from the zubax source, and left cmsis from the created project. The startup file calls SystemInit from “system\_stm32f37x.c” supplied in the source. hwInit is called from the supplied main.h, then swInit. The can timings computed are bit\_rate\_prescalar = 2, bit\_segment\_1 = 7, bit\_segment\_2=1,max\_rescynchronization\_width=1.  
It does not transmit or recive anyhting.  
When attempting to transmit it gets stuck in sendCanard() while (txf) loop.  
canardSTM32Transmit() always returns 0 , meaning it didn;t transmit anything and keep it stuck in the while loop.  
For first call we get result 1, then after always 0 for canardSTM32Transmit  
Inside the function tme[3] = false,true,true  
isFramePriorityHigher returns 0 and then the function exits wuth return code 0.  
There is a mailbox whose priority is higher or equal priority of the new frame.  
This is always returned.  
I have a zubax babel connected to the other end running uavcangui which of course doesn’t show any messages incoming. I have checked the termination resistor is on for the uavcan gui babel device.  
Is there anymore info on how to get this project to run?  
Any clues or more debug required to find the problem?

Thanks,  
Kent

---

<div class="post-metadata">

**Author:** ![Kent\_Martin](https://forum.zubax.com/letter_avatar_proxy/v4/letter/k/a698b9/32.png) [@Kent\_Martin](https://forum.zubax.com/u/Kent_Martin)\
**Post date:** [May 13, 2019, 11:38pm UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/6 "2019-05-13T23:38:27Z")

</div>

Hi ,  
I’m still at a loss to get this going after a lof of effort.  
Can anyone help to get this project running?  
I thought this should be relatively easy, but it just won’t work.  
Is there any other things to try or test to find the problem?  
The only thing I am doing differently is using SW4STM.  
I am not sure what else I can try to get this to work.  
I tried disabling sendCanard, so it doesn’t get stuck in a loop, but still nothing is recieved.  
Please Help!!

---

<div class="post-metadata">

**Author:** ![alexander.sysoev](https://forum.zubax.com/letter_avatar_proxy/v4/letter/a/da6949/32.png) [@alexander.sysoev](https://forum.zubax.com/u/alexander.sysoev)\
**Post date:** [May 25, 2019, 3:36pm UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/7 "2019-05-25T15:36:27Z")

</div>

> [@Kent\_Martin](#):
>
> after a break.  
> I created another project

Hi Kent Martin! Sorry for the delay.  
Let me try to help you. Can you please describe your setup a bit more detailed? How many UAVCAN devices do you have on the bus and what are these devices? Could you also share your source code? I may want to reproduce your issues precisely.  
Best regards, Alex

---

<div class="post-metadata">

**Author:** ![Kent\_Martin](https://forum.zubax.com/letter_avatar_proxy/v4/letter/k/a698b9/32.png) [@Kent\_Martin](https://forum.zubax.com/u/Kent_Martin)\
**Post date:** [May 27, 2019, 11:40pm UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/8 "2019-05-27T23:40:33Z")

</div>

Hi, Thanks you can see the source here for 2 projects I did on the babel.

> **[share](https://www.dropbox.com/sh/cv3f0c1fcaa2cfs/AAD5D8W_gq6uDVFVEmXrvXkja?dl=0)**
>
> Shared with Dropbox

I have 2 zubax babels connected to each other. One with uavcangui running at 1Mbps , the other running the code in the link.  
Thanks,  
Kent

---

<div class="post-metadata">

**Author:** ![Kent\_Martin](https://forum.zubax.com/letter_avatar_proxy/v4/letter/k/a698b9/32.png) [@Kent\_Martin](https://forum.zubax.com/u/Kent_Martin)\
**Post date:** [May 27, 2019, 11:43pm UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/9 "2019-05-27T23:43:12Z")

</div>

BTW,  
I now have made a standard CAN setup using cubemx and I can see messages coming out.  
It’s not uavcan but I can at least get the hardware to do something. Although after the 1st transmit it fails as no one is responding to it I presume, and you have to stop it and restart it before sending another packet. I’ll try put libcanard on top of this and see if it can work then.

Kent

---

<div class="post-metadata">

**Author:** ![lohits7](https://forum.zubax.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@lohits7](https://forum.zubax.com/u/lohits7)\
**Post date:** [February 22, 2020, 8:15pm UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/10 "2020-02-22T20:15:41Z")

</div>

Hi Kent. I am facing same problem with this. Are you able to over come this problem. when i am debugging i came to know once the spincanard happens next time the return inside sendcanard will go into while loop tx\_ref will always be zero. If any one can help please looking forward.

---

<div class="post-metadata">

**Author:** ![Kent\_Martin](https://forum.zubax.com/letter_avatar_proxy/v4/letter/k/a698b9/32.png) [@Kent\_Martin](https://forum.zubax.com/u/Kent_Martin)\
**Post date:** [February 23, 2020, 3:52am UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/11 "2020-02-23T03:52:45Z")

</div>

Hi,  
I’m not sure what problem you have but I have noticed that if the can bus is not powered the code will not start. You can fix this by changing some code so it will ignore this failure and the bus will work once power is applied. See the code below where I have commented out the error return when the inak does not occur after initialization. Ignore the extra code I put in to use interrupts, that is not necessary for it to work.

```nohighlight
    /*
     * Hardware initialization (the hardware has already confirmed initialization mode, see above)
     */
    BXCAN->MCR = CANARD_STM32_CAN_MCR_ABOM | CANARD_STM32_CAN_MCR_AWUM | CANARD_STM32_CAN_MCR_INRQ; // RM page 648

    BXCAN->BTR = (((timings->max_resynchronization_jump_width - 1) & 3U) << 24) |
                 (((timings->bit_segment_1 - 1) & 15U) << 16) |
                 (((timings->bit_segment_2 - 1) & 7U) << 20) |
                 ((timings->bit_rate_prescaler - 1) & 1023U) |
                 ((iface_mode == CanardSTM32IfaceModeSilent) ? CANARD_STM32_CAN_BTR_SILM : 0);
    CANARD_ASSERT(0 == BXCAN->IER); // Making sure the iterrupts are indeed disabled
#if USERXINT
    BXCAN->IER = CANARD_STM32_CAN_IER_FMPIE0|CANARD_STM32_CAN_IER_FMPIE1;//|CANARD_STM32_CAN_IER_TMEIE;
#endif
    BXCAN->MCR &= ~CANARD_STM32_CAN_MCR_INRQ; // Leave init mode
    if (!waitMSRINAKBitStateChange(BXCAN, false))
    {
        //BXCAN->MCR = CANARD_STM32_CAN_MCR_RESET;
        //return -CANARD_STM32_ERROR_MSR_INAK_NOT_CLEARED;
    }

```

---

<div class="post-metadata">

**Author:** ![lohits7](https://forum.zubax.com/letter_avatar_proxy/v4/letter/l/dbc845/32.png) [@lohits7](https://forum.zubax.com/u/lohits7)\
**Post date:** [February 24, 2020, 5:48am UTC](https://forum.zubax.com/t/zubax-babel-schematic-and-hardware-init-for-libcanard/1252/12 "2020-02-24T05:48:42Z")

</div>

Hi,  
I figured out the problem. The software waits for the ACK from the other device side which is to notify the message being received. Thank you for replying for the message.
