Node Initialization STM32

95 views
Skip to first unread message

7553...@qq.com

unread,
Mar 15, 2018, 9:04:35 PM3/15/18
to UAVCAN
Hi, I used UAVCAN on stm32f103ZE for gcc at keil4 ,but I can not node.start();, error -5 ,I debug ,just konw    problem at const List* list = selectList(kind);      Entry* p = list->get();   is null 

const DataTypeDescriptor* GlobalDataTypeRegistry::find(DataTypeKind kind, const char* name) const
{
    if (!name)
    {
        UAVCAN_ASSERT(0);
        return NULL;
    }
    const List* list = selectList(kind);
    if (!list)
    {
        UAVCAN_ASSERT(0);
        return NULL;
    }
    Entry* p = list->get();
    while (p)
    {
        if (p->descriptor.match(kind, name))
        {
            return &p->descriptor; ////
        }
        p = p->getNextListNode();
    }
    return NULL;
}

and my main.cpp

#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"  
#include "can.h" 
// #include "ds18b20.h" 
// #include "ms5611.h"
// #include "myiic.h"
// #include "systime.h" 
// #include "ms4525.h"
// #include "filter.h"
// #include "airspeed.h"
// #include "adc.h"
// #include "filter.h"

// #include <iostream>
// #include <cstdlib>
// #include <unistd.h>

#include <uavcan/uavcan.hpp>
#include <uavcan_stm32/uavcan_stm32.hpp>
#include <chip.h>

#include <uavcan/protocol/debug/KeyValue.hpp> // uavcan.protocol.debug.KeyValue

static constexpr int RxQueueSize = 64;
static constexpr std::uint32_t BitRate = 1000000;

// extern uavcan::ICanDriver& getCanDriver();
// extern uavcan::ISystemClock& getSystemClock();

uavcan::ISystemClock& getSystemClock()
{
    return uavcan_stm32::SystemClock::instance();
}

uavcan::ICanDriver& getCanDriver()
{
    static uavcan_stm32::CanInitHelper<RxQueueSize> can;
    static bool initialized = false;
    if (!initialized)
    {
        initialized = true;
        int res = can.init(BitRate);
        if (res < 0)
        {
            // Handle the error
        }
    }
    return can.driver;
}

constexpr unsigned NodeMemoryPoolSize = 16384;  //16384;
typedef uavcan::Node<NodeMemoryPoolSize> Node;

static Node& getNode()
{
    static Node node(getCanDriver(), getSystemClock());
    return node;
}


int main()
{
SystemInit();
NVIC_Configuration();  

  LED1_Init();
  delay_init();
uart_init(9600);
    CAN_Mode_Init();     //CAN IO
  auto& node = getNode();

node.setNodeID(5);  ///wangzw ID 5

    node.setName("org.uavcan.tutorial.init");

//     uavcan::protocol::SoftwareVersion sw_version;  // Standard type uavcan.protocol.SoftwareVersion
//     sw_version.major = 1;
//     node.setSoftwareVersion(sw_version);

//     uavcan::protocol::HardwareVersion hw_version;  // Standard type uavcan.protocol.HardwareVersion
//     hw_version.major = 1;
//     node.setHardwareVersion(hw_version);
    /*
     * Start the node.
     * All returnable error codes are listed in the header file uavcan/error.hpp.
     */
    const int node_start_res = node.start();
    if (node_start_res < 0)
    {
       throw std::runtime_error("Failed to start the node; error: " + std::to_string(node_start_res));
    }
    uavcan::Publisher<uavcan::protocol::debug::KeyValue> kv_pub(node);
    const int kv_pub_init_res = kv_pub.init();
    if (kv_pub_init_res < 0)
    {
       throw std::runtime_error("Failed to start the publisher; error: " + std::to_string(kv_pub_init_res));
    }


    kv_pub.setTxTimeout(uavcan::MonotonicDuration::fromMSec(1000));

    /*
     * Priority of outgoing tranfers can be changed as follows.
     * Default priority is 16 (medium).
     */
    kv_pub.setPriority(uavcan::TransferPriority::MiddleLower);

    /*
     * Running the node.
     */
    node.setModeOperational();

    while (true)
    {
        /*
         * Spinning for 1 second.
         * The method spin() may return earlier if an error occurs (e.g. driver failure).
         * All error codes are listed in the header uavcan/error.hpp.
         */
        const int spin_res = node.spin(uavcan::MonotonicDuration::fromMSec(1000));
        if (spin_res < 0)
        {
//            std::cerr << "Transient failure: " << spin_res << std::endl;
        }

        /*
         * Publishing a random value using the publisher created above.
         * All message types have zero-initializing default constructors.
         * Relevant usage info for every data type is provided in its DSDL definition.
         */
        uavcan::protocol::debug::KeyValue kv_msg;  // Always zero initialized
        kv_msg.value = std::rand() / float(RAND_MAX);

        /*
         * Arrays in DSDL types are quite extensive in the sense that they can be static,
         * or dynamic (no heap needed - all memory is pre-allocated), or they can emulate std::string.
         * The last one is called string-like arrays.
         * ASCII strings can be directly assigned or appended to string-like arrays.
         * For more info, please read the documentation for the class uavcan::Array<>.
         */
        kv_msg.key = "a";   // "a"
        kv_msg.key += "b";  // "ab"
        kv_msg.key += "c";  // "abc"

        /*
         * Publishing the message.
         */
        const int pub_res = kv_pub.broadcast(kv_msg);
        if (pub_res < 0)
        {
//            std::cerr << "KV publication failure: " << pub_res << std::endl;
        }
GPIO_ResetBits(GPIOG,GPIO_Pin_15);
    delay_ms(1000);
GPIO_SetBits(GPIOG,GPIO_Pin_15);
delay_ms(1000);
    }
  while(1)
  {
    GPIO_ResetBits(GPIOG,GPIO_Pin_15);
    delay_ms(1000);
GPIO_SetBits(GPIOG,GPIO_Pin_15);
delay_ms(1000);
  }
}

thanks 

Pavel Kirienko

unread,
Mar 18, 2018, 5:55:11 PM3/18/18
to 7553...@qq.com, UAVCAN
Error code 5 means that one of the data types used by the Node class have not been registered with the library. This could happen if your runtime environment did not perform static object initialization correctly. Please check your C runtime initialization code to ensure that constructors of static C++ objects are invoked properly. This could also happen if you were using the UAVCAN_NO_GLOBAL_DATA_TYPE_REGISTRY config option, but I assume you aren't.

As a quick test, you could try registering the required data types manually, as shown here http://uavcan.org/Implementations/Libuavcan/Tutorials/8._Custom_data_types/.

Pavel.

--
You received this message because you are subscribed to the Google Groups "UAVCAN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+unsubscribe@googlegroups.com.
To post to this group, send email to uav...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/uavcan/ae0c8d23-fefe-42e3-b0e7-62ca48039a08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

7553...@qq.com

unread,
Mar 20, 2018, 11:44:04 PM3/20/18
to UAVCAN
thanks  very much  Pavel

As you say ,I registering the required data types manually ,it OK

wang

在 2018年3月19日星期一 UTC+8上午5:55:11,Pavel Kirienko写道:
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+un...@googlegroups.com.

7553...@qq.com

unread,
Mar 21, 2018, 9:30:06 PM3/21/18
to UAVCAN
Hi  Pavel 

I  try registering the required data types auto,but I don not know how to do ,in this IDE  I can not add DSDL compiler, so i  just add    DSDl  compiler  build finish file (.h) ,I don not konw  I just do this is ok. 

 please  ,sorry  my english is bad 

wang

在 2018年3月19日星期一 UTC+8上午5:55:11,Pavel Kirienko写道:
Error code 5 means that one of the data types used by the Node class have not been registered with the library. This could happen if your runtime environment did not perform static object initialization correctly. Please check your C runtime initialization code to ensure that constructors of static C++ objects are invoked properly. This could also happen if you were using the UAVCAN_NO_GLOBAL_DATA_TYPE_REGISTRY config option, but I assume you aren't.
To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+un...@googlegroups.com.

Pavel Kirienko

unread,
Mar 23, 2018, 5:19:09 AM3/23/18
to 7553...@qq.com, UAVCAN
Decent IDEs usually provide an option to invoke an arbitrary command before or after the application is built. Examples:


That said, you can always pre-compile message definitions ahead of time and then simply store them with your sources. Generally, this is not a good practice because it complicates versioning, but it's your call.

Pavel

To unsubscribe from this group and stop receiving emails from it, send an email to uavcan+unsubscribe@googlegroups.com.

To post to this group, send email to uav...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages