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