Cryptoauthlib-匿名联合只能有非静态数据成员-分段错误 我试图用CudioAuthLIB编译一个C++程序,在ATCAIIFACE中得到这个(匿名联盟只能有非静态数据成员)错误。我认为这是c11特性,与c++不兼容:
未命名联合中的所有命名结构都会引发错误。我删除了以下结构的名称:Cryptoauthlib-匿名联合只能有非静态数据成员-分段错误 我试图用CudioAuthLIB编译一个C++程序,在ATCAIIFACE中得到这个(匿名联盟只能有非静态数据成员)错误。我认为这是c11特性,与c++不兼容:,c++,encryption,microchip,C++,Encryption,Microchip,未命名联合中的所有命名结构都会引发错误。我删除了以下结构的名称: typedef struct { ATCAIfaceType iface_type; // active iface - how to interpret the union below ATCADeviceType devtype; // explicit device type union // each instanc
typedef struct
{
ATCAIfaceType iface_type; // active iface - how to interpret the union below
ATCADeviceType devtype; // explicit device type
union // each instance of an iface cfg defines a single type of interface
{
struct //ATCAI2C
{
uint8_t slave_address; // 8-bit slave address
uint8_t bus; // logical i2c bus number, 0-based - HAL will map this to a pin pair for SDA SCL
uint32_t baud; // typically 400000
} atcai2c;
struct //ATCASWI
{
uint8_t bus; // logical SWI bus - HAL will map this to a pin or uart port
} atcaswi;
struct //ATCAUART
{
int port; // logic port number
uint32_t baud; // typically 115200
uint8_t wordsize; // usually 8
uint8_t parity; // 0 == even, 1 == odd, 2 == none
uint8_t stopbits; // 0,1,2
} atcauart;
struct //ATCAHID
{
int idx; // HID enumeration index
uint32_t vid; // Vendor ID of kit (0x03EB for CK101)
uint32_t pid; // Product ID of kit (0x2312 for CK101)
uint32_t packetsize; // Size of the USB packet
uint8_t guid[16]; // The GUID for this HID device
} atcahid;
struct //ATCACUSTOM
{
ATCA_STATUS (*halinit)(void *hal, void *cfg);
ATCA_STATUS (*halpostinit)(void *iface);
ATCA_STATUS (*halsend)(void *iface, uint8_t *txdata, int txlength);
ATCA_STATUS (*halreceive)(void *iface, uint8_t* rxdata, uint16_t* rxlength);
ATCA_STATUS (*halwake)(void *iface);
ATCA_STATUS (*halidle)(void *iface);
ATCA_STATUS (*halsleep)(void *iface);
ATCA_STATUS (*halrelease)(void* hal_data);
} atcacustom;
};
uint16_t wake_delay; // microseconds of tWHI + tWLO which varies based on chip type
int rx_retries; // the number of retries to attempt for receiving bytes
void * cfg_data; // opaque data used by HAL in device discovery
} ATCAIfaceCfg;
#include <iostream>
#include "cryptoauthlib.h"
int main(int argc, char *argv[])
{
ATCAIfaceCfg *atca_cfg;
atca_cfg = &cfg_ateccx08a_i2c_default;
ATCA_STATUS status = atcab_init(atca_cfg);
std::cout << "status: " << (int)status << std::endl;
uint8_t revision[4];
status = atcab_info(revision);
if (status != ATCA_SUCCESS)
{
return -1;
}
std::cout << "revision: " << (int)revision << std::endl;
uint8_t serial[ATCA_SERIAL_NUM_SIZE];
status = atcab_read_serial_number(serial);
if (status != ATCA_SUCCESS)
{
return - 1;
}
std::cout << "serial: " << (int)serial << std::endl;
uint8_t num[32];
status = atcab_random(num);
if (status != ATCA_SUCCESS)
{
return - 1;
}
std::cout << "random: " << (int)num << std::endl;
return 0;
}
我将这些结构更改为未命名结构并进行编译,但不幸的是,在调用init函数ATCA_STATUS atinit(ATCAIface)时,我遇到了一个分段错误代码>。。。我不直接调用这个函数。我调用atcab_init(&cfg_ateccx08a_i2c_default)代码>
有没有一种方法可以在不修改界面的情况下使用它?为什么会出现分段错误
我的硬件设置是一个CM3,ATEC608A连接到I2C 1。界面已打开,我可以查询它。是否需要将默认接口修改为正确的设备类型和正确的I2C接口?当我这样做的时候,我得到了同样的分割错误
编辑:
示例代码
#include <iostream>
#include "cryptoauthlib.h"
int main(int argc, char *argv[])
{
uint8_t random_number;
atcab_init(&cfg_ateccx08a_i2c_default);
ATCA_STATUS status = atcab_random(&random_number);
std::cout << "status: " << (int)status << std::endl;
return 0;
}
建造
编辑5:
发现我必须在我的CMAKE项目中明确地执行设置(ATCA_HAL_I2C TRUE)
。。。不幸的是,作为一种选择,它对我不起作用
现在我在这里又遇到了一个分段错误:
ATCA_STATUS atcab_random(uint8_t *rand_out)
{
...
ATCACommand ca_cmd = _gDevice->mCommands;
...
}
我在github上打开了它。我发现了错误。硬件抽象层无法连接,因为i2c总线.atcai2c.bus
的默认总线设置被设置为2,它需要为1,否则它将找不到i2c设备
ATCAIfaceCfg cfg_ateccx08a_i2c_default = {
.iface_type = ATCA_I2C_IFACE,
.devtype = ATECC608A,
.atcai2c.slave_address = 0xC0,
.atcai2c.bus = 1,
.atcai2c.baud = 400000,
//.atcai2c.baud = 100000,
.wake_delay = 1500,
.rx_retries = 20
};
现在,我可以通过以下方式从芯片中获取修订版、序列号和随机数:
typedef struct
{
ATCAIfaceType iface_type; // active iface - how to interpret the union below
ATCADeviceType devtype; // explicit device type
union // each instance of an iface cfg defines a single type of interface
{
struct //ATCAI2C
{
uint8_t slave_address; // 8-bit slave address
uint8_t bus; // logical i2c bus number, 0-based - HAL will map this to a pin pair for SDA SCL
uint32_t baud; // typically 400000
} atcai2c;
struct //ATCASWI
{
uint8_t bus; // logical SWI bus - HAL will map this to a pin or uart port
} atcaswi;
struct //ATCAUART
{
int port; // logic port number
uint32_t baud; // typically 115200
uint8_t wordsize; // usually 8
uint8_t parity; // 0 == even, 1 == odd, 2 == none
uint8_t stopbits; // 0,1,2
} atcauart;
struct //ATCAHID
{
int idx; // HID enumeration index
uint32_t vid; // Vendor ID of kit (0x03EB for CK101)
uint32_t pid; // Product ID of kit (0x2312 for CK101)
uint32_t packetsize; // Size of the USB packet
uint8_t guid[16]; // The GUID for this HID device
} atcahid;
struct //ATCACUSTOM
{
ATCA_STATUS (*halinit)(void *hal, void *cfg);
ATCA_STATUS (*halpostinit)(void *iface);
ATCA_STATUS (*halsend)(void *iface, uint8_t *txdata, int txlength);
ATCA_STATUS (*halreceive)(void *iface, uint8_t* rxdata, uint16_t* rxlength);
ATCA_STATUS (*halwake)(void *iface);
ATCA_STATUS (*halidle)(void *iface);
ATCA_STATUS (*halsleep)(void *iface);
ATCA_STATUS (*halrelease)(void* hal_data);
} atcacustom;
};
uint16_t wake_delay; // microseconds of tWHI + tWLO which varies based on chip type
int rx_retries; // the number of retries to attempt for receiving bytes
void * cfg_data; // opaque data used by HAL in device discovery
} ATCAIfaceCfg;
#include <iostream>
#include "cryptoauthlib.h"
int main(int argc, char *argv[])
{
ATCAIfaceCfg *atca_cfg;
atca_cfg = &cfg_ateccx08a_i2c_default;
ATCA_STATUS status = atcab_init(atca_cfg);
std::cout << "status: " << (int)status << std::endl;
uint8_t revision[4];
status = atcab_info(revision);
if (status != ATCA_SUCCESS)
{
return -1;
}
std::cout << "revision: " << (int)revision << std::endl;
uint8_t serial[ATCA_SERIAL_NUM_SIZE];
status = atcab_read_serial_number(serial);
if (status != ATCA_SUCCESS)
{
return - 1;
}
std::cout << "serial: " << (int)serial << std::endl;
uint8_t num[32];
status = atcab_random(num);
if (status != ATCA_SUCCESS)
{
return - 1;
}
std::cout << "random: " << (int)num << std::endl;
return 0;
}
#包括
#包括“cryptoauthlib.h”
int main(int argc,char*argv[])
{
ATCAIFACFG*atca_cfg;
atca_cfg=&cfg_ATECX08A_i2c_默认值;
ATCA_状态状态=atcab_初始(ATCA_cfg);
std::cout在我的机器上工作。但是我必须弥补很多缺失的部分。你能确保你的示例代码完整并编译(产生编译器错误)吗?我没有将联合更改为struct@john,我删除了未命名联合中的结构名称。@Eljay我添加的示例代码仍然没有按照给定的方式编译。我的调整版本必须定义ATCAIfaceType、ATCADeviceType和ATCA_状态。我遇到了另一个错误,我通过给匿名联合一个名称修复了该错误(不再匿名)。但是默认接口定义不起作用。因为编译器找不到联盟的成员。我正在使用gcc 7.3.1…github上有人告诉我必须使用-DATCA_halu_I2C作为C编译器标志。但是我现在得到了对HAL_I2C_init的未定义引用