cancel
Showing results for 
Search instead for 
Did you mean: 

STSAFE-A110 STSAFEA_COMMUNICATION_ERROR on all reads

Teedoubleyuh
Associate II

Hi,

I ported example projects from en.x-cube-safea1\project\NUCLEO-L476RG for MbedTLS cryptolib for use on my B-U585I-IOT02A Discovery Kit. The STSAFE-A110 is powered correctly and NRESET is pulled high. It never errors on writes to the device, but all reads that execute the StSafeA_Receive function in stsafea_service.c return STSAFEA_COMMUNICATION_ERROR. In fact, it's very specifically always happening here (code snippet below) where after calling StSafeA_ReceiveBytes and getting STSAFE_BUS_OK, it is masking the header value with the inverse of STSAFEA_CMD_HEADER_RMACEN which always turns STSAFE_BUS_OK (0x00) to 0x01 which is STSAFEA_COMMUNICATION_ERROR. Any idea what I could be doing so that I can get past this?
Thanks!

if (status_code != STSAFEA_BUFFER_LENGTH_EXCEEDED)

{

if (status_code == (StSafeA_ResponseCode_t)STSAFEA_BUS_OK)

{

status_code = (StSafeA_ResponseCode_t)(uint8_t)((uint8_t)pTLV_Buffer->Header &

~(uint8_t)STSAFEA_CMD_HEADER_RMACEN); <---- *** this is changing the STSAFEA_BUS_OK (0x00)

to 0x01 which is STSAFEA_COMMUNICATION_ERROR

}

 

1 ACCEPTED SOLUTION

Accepted Solutions
Teedoubleyuh
Associate II

I believe the issue was my CRC_Compute function mapped to StSafeA_HW_Probe. Rather than use the software CRC function produced by x-cube-safea1, I initially tried to map it to the hardware CRC of the STM32U585 I'm using. This wasn't properly handling the header tag that is also included in CRC calculations.

I am still curious though if you can tell me why the CRC_Compute function does a byteswap on the CRC. Is it related to the byte order the payload is transmitted to the STSAFE-A110? I only ask because I compared the CRC results to an online calculator that uses the CRC-16/x-25 algorithm and the online results do not swap the bytes, so for example, the CRC_Compute may give result 0x73CD but the online calculator gives result 0xCD73.

	uint32_t CRC_Compute(uint8_t *pData1, uint16_t Length1, uint8_t *pData2, uint16_t Length2)
	{
	  (void)Length1;
	  uint16_t crc16 = 0;
	  if ((pData1 != NULL) && (pData2 != NULL))
	  {
	    crc16 = StSafeA_Crc16_ccitt(pData1[0], pData2, Length2);
	
	    crc16 = (uint16_t)SWAP2BYTES(crc16);
	    crc16 ^= 0xFFFFU;
	  }
	  return (uint32_t)crc16;
}

 

View solution in original post

4 REPLIES 4
Jacob WOODRUFF
ST Employee

Hi All,

 

This post has been escalated to the ST Online Support Team for additional assistance. We'll contact you directly.


Regards,
Jake

ST Support

Teedoubleyuh
Associate II

I believe the issue was my CRC_Compute function mapped to StSafeA_HW_Probe. Rather than use the software CRC function produced by x-cube-safea1, I initially tried to map it to the hardware CRC of the STM32U585 I'm using. This wasn't properly handling the header tag that is also included in CRC calculations.

I am still curious though if you can tell me why the CRC_Compute function does a byteswap on the CRC. Is it related to the byte order the payload is transmitted to the STSAFE-A110? I only ask because I compared the CRC results to an online calculator that uses the CRC-16/x-25 algorithm and the online results do not swap the bytes, so for example, the CRC_Compute may give result 0x73CD but the online calculator gives result 0xCD73.

	uint32_t CRC_Compute(uint8_t *pData1, uint16_t Length1, uint8_t *pData2, uint16_t Length2)
	{
	  (void)Length1;
	  uint16_t crc16 = 0;
	  if ((pData1 != NULL) && (pData2 != NULL))
	  {
	    crc16 = StSafeA_Crc16_ccitt(pData1[0], pData2, Length2);
	
	    crc16 = (uint16_t)SWAP2BYTES(crc16);
	    crc16 ^= 0xFFFFU;
	  }
	  return (uint32_t)crc16;
}

 

Pavel A.
Evangelist III

I am still curious though if you can tell me why the CRC_Compute function does a byteswap on the CRC.

Hmm. I don't have STSAFE-A110 but it's kind of tradition for I2C devices to use big endian data format. The MCU itself (and most of the world) is little endian.

 

 

Ok, I think I'll just continue to use the CRC_Compute functions generated byte x-cube and not dare to try the hardware CRC. :)
Thanks!