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
#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);
}
}