This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

calculate crc of Serial (HCI) packet format DFU

Working on a project i want to update the nordic application (firmware) from other MCU, i am having some problem to compute the crc.

  • How to we calculate the crc of sample packet : HCI start packet

  • Used the function in components/libraries/crc16/crc16.c

  • as per the document Bluetooth Core Specification (Volume 4, Part D, Chapter 4) , CRC-CCITT is computed using : Each octet of the Packet Header and Packet Payload is used to com- pute the Data Integrity Check.

  • Snippet used to find the crc of start packet for my application

     typedef struct {
     	//uint8_t slip_start;
     	uint32_t packet_header;
     	uint32_t dfu_packet_type;
     	uint32_t dfu_udpate_type;
     	uint32_t sizeof_sd;
     	uint32_t sizeof_bl;
     	uint32_t sizeof_app;
     	uint16_t crc_value;
     	//uint8_t slip_end;
     } __attribute__((__packed__)) dfu_startpacket_t;
    
    	//dfu_start_packet.slip_start      = 0xc0;
     dfu_start_packet.packet_header   = (*(uint32_t *)(&hci_packet_header)); // 0xE0014ED1
     dfu_start_packet.dfu_packet_type = 0x03; // DFU start packet
     dfu_start_packet.dfu_udpate_type = 0x04; // application image
     dfu_start_packet.sizeof_sd       = 0x00; // no SoftDevice image is transferred
     dfu_start_packet.sizeof_bl       = 0x00; // no bootloader image is transferred
     dfu_start_packet.sizeof_app      = 0x5d0c; // size of application
     //dfu_start_packet.slip_end	= 0xc0;
     }
    
  • To compute the crc below code is used

      dfu_start_packet.crc_value       = 0x0000;
     /** 
     crc_value computed : 0xCA0E , once expected  as reported in example :0xFCC6 
     memcpy(temp_buffer, &dfu_start_packet, sizeof(dfu_start_packet));
     crc_value       = crc16_compute(temp_buffer,sizeof(temp_buffer),0);
     **/
      crc_value       = crc16_compute((uint8_t*)(&dfu_start_packet),sizeof(dfu_start_packet),0);
    
  • May i know what i am doing wrong here.

Parents Reply Children
No Data
Related