Bootloader refuses Send Data and Program Row packets

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello, 

   

I'm writing an Bootloader Host (that is, which sends a new Bootloadable to the PSoC bootloader via an UART link), running on another STM32 chip. I can't use the AN68272.zip code due to major architecture differences, so I wrote my own.

   

I can send most packets without any sort of issue,  in that order : 

   

- Enter Bootloader (0x38)

   

- Verify Application Checksum (0x31)

   

- Flash Array ID (0x32, two times, for both flash chips)

   

- Send Data (0x37). That's where the problem arises, as I can only send one byte of data at a time. More than one byte of data (size in packet > 1), and the Bootloader answers with a BOOTLOADER_ERR_LENGTH (0x03) error. I'm pretty sure the packet is well formed, that the checksum is valid, and that everything is in place. 

   

"Flash Array ID" packet also contains more than one byte, and the Bootloader accepts it without issue. 

   

"Program Row" (0x39) exposes the exact same problem. No matter what I do, it'll answer a 0x03 error.

   

I've tracked down the error in the Bootloader at the test  if (((pktSize + Bootloader_1_MIN_PKT_SIZE) > numberRead)) in Bootloader_1.c around line 1744.

   

If someone could point me to the obvious mistake I'm making, I'd be very thankful.  

   

Thanks a lot !

   

 

   

Here is the full code of my packet generator : 

   

// Sends a command to the bootloader containing a command ID and optionnal data
uint8_t send_bootloader_packet(uint8_t cmd, uint8_t *data, uint16_t size) {
    uint8_t packet[140]; // FIXME
    uint16_t crc = 0x00;

   

    packet[0] = 0x01;                                  // Start byte
    packet[1] = cmd;                                   // Command ID
    packet[2] = (uint8_t) (size&0xFF);                 // data length, LSB
    packet[3] = (uint8_t) (size>>8);                   // data length, MSB
    if(size && data) memcpy(&packet[4], data, size);   // Copy data
    crc = bl_basic_summation(packet, size+4);          // Compute CRC on the first 4 bytes and the data
    packet[size+4] = (uint8_t) (crc&0xFF);             // CRC LSB
    packet[size+5] = (uint8_t) (crc>>8);               // CRC MSB
    packet[size+6] = 0x17;                             // End byte

   

    ​    return send_UART(packet, size+7);
}

   

EDIT: Packet sent and received : 

   

Get Flash Size for array 1, works flawlessly

   

>>> 01 32 01 00 01 CB FF 17                     // Packet 0x32, 1 byte of data, summation checksum
<<< 01 00 04 00 00 00 FF 01 FB FE 17      // Valid answer, usable flash in range 0000-01FF

   

 

   

Send Data,doesn't work

   

>>> 01 37 08 00 00 40 00 20 91 24 00 00 AB FE 17    // Packet 0x37, 8 bytes of data, summation checksum
<<< 01 03 00 00 FC FF 17                                            // Answer, error 0x03

0 Likes
2 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum, Jean.

   

Can it be a problem of little & big endianess? Change the target for a test. Replace the 0xff with a 0xffu!

   

or is the copy better done with

   

if(size && data) memcpy(&packet[7], data, size);   // Copy data

   

Bob

0 Likes
Anonymous
Not applicable
    

Can it be a problem of little & big endianess?

   
   

Nope, as it would affect the checksum (and other parts of the code) as well. The checksum has also been tested on a known message (sent from the bootloader) and works as intended. And it would also affect packets with 1 byte of data (becoming 256 bytes of data if the endianess was wrong). Packets with only 1 byte of data are generate no error from the bootloader.

   
    

or is the copy better done with

    

if(size && data) memcpy(&packet[7], data, size);   // Copy data

   
   

The data wouldn't be copied at the right place. I am missing something here ?

   

Thanks for your answer !

   

 

   


 

0 Likes