Reply
Posts: 3
Registered: ‎03-24-2017
Accepted Solution

cp2102n Setconfig

Hello,

i want do config a cp2102n with my written delphi program by using the manufactoring.dll. For example the product string should be changed. Therefor a 768 byte buffer have to transmit. The last to bytes in this buffer contain the check sum. But I don't know how to calculate this check sum.

Only if I send the buffer with the right check sum I can modify the configuration of the cp2102n.

 

Can anybody help me?

Thanks

Posts: 451
Registered: ‎02-21-2014

Re: cp2102n Setconfig

The checksum is a 16-bit 'fletcher' checksum of the rest of the configuration array.

 

Here is the C implementation:

// Taken from Wikipedia https://en.wikipedia.org/wiki/Fletcher%27s_checksum
// Must use generic pointer since function is called on XDATA and CODE spaces.
uint16_t fletcher16(uint8_t *dataIn, uint16_t bytes)
{
        uint16_t sum1 = 0xff, sum2 = 0xff;
        uint16_t tlen;
 
        while (bytes) {
                tlen = bytes >= 20 ? 20 : bytes;
                bytes -= tlen;
                do {
                        sum2 += sum1 += *dataIn++;
                } while (--tlen);
                sum1 = (sum1 & 0xff) + (sum1 >> 8);
                sum2 = (sum2 & 0xff) + (sum2 >> 8);
        }
        /* Second reduction step to reduce sums to 8 bits */
        sum1 = (sum1 & 0xff) + (sum1 >> 8);
        sum2 = (sum2 & 0xff) + (sum2 >> 8);
        return sum2 << 8 | sum1;
}

And here's an implementation in python (note all of the gross masking to force python integers to a particular bit-length. There's probably a better way to do this, but it works!)

 

def generateFletcherChecksum(byteArray):
    sum1 = 0xFF
    sum2 = 0xFF
    tlen = 0

    numBytes = len(byteArray)

    index = 0
    while(numBytes):
        tlen = 20 if numBytes >= 20 else numBytes
        numBytes -= tlen
        
        while(tlen):
            sum1 += (byteArray[index] & 0xFF)
            sum1 &= 0xFFFF
            sum2 += sum1
            sum2 &= 0xFFFF
            index += 1
            tlen -= 1
            
        sum1 = ((sum1 & 0xFF) + (sum1 >> 8)) & 0xFFFF
        sum2 = ((sum2 & 0xFF) + (sum2 >> 8)) & 0xFFFF
        
    sum1 = ((sum1 & 0xFF) + (sum1 >> 8)) & 0xFFFF
    sum2 = ((sum2 & 0xFF) + (sum2 >> 8)) & 0xFFFF

    checksum = ((sum2 << 8) | sum1) & 0xFFFF

    return checksum

 

 

 

Posts: 3
Registered: ‎03-24-2017

Re: cp2102n Setconfig

Thanks,

that are the infos I need.

 

But could you tell me the data structure of the configuration arry also?

Posts: 2,079
Registered: ‎10-14-2014

Re: cp2102n Setconfig

Very interesting,

Though SS xpress configurator could generate a configuration file, but I never see any document that expose the format of this file.

 

My views are my own and do not necessarily represent the views of Silicon Labs

WeiguoLu
Posts: 451
Registered: ‎02-21-2014

Re: cp2102n Setconfig

[ Edited ]

I think this is something that we should document, so I'll put in a ticket to have it added to the CP210x API application note.

 

I can give you some information, though. Studio uses an xml file to generate this byte array called cp2102n.hexProvision. It's located under the Studio install directory under offline/ffd/xpress_configurator/cp2102n/cp2102n.hexProvision. This isn't the most easy to read file, but it should be self explanatory. Each bytefield is described by a propertyId, which is also used to generate the UI. So, to find the propertyId for a particular setting, you'll need to look at the XML that describes the UI. That's located in two places - offline/ffd/xpress_configurator/cp2102n/cp2102n.viewLayout, then one file for each of the devices for the port config UI, for example offline/ffd/xpress_configurator/cp2102n/cp2102n_a01_gqfn20/cp2102n_a01_gqfn20_portConfig.viewLayout

 

I'll also attach a spreadsheet that describes these fields as well. Note that not all of the fields in the byte array are intended to be changed by the user, as some of them are part of the USB descriptor that must be particular values.

 

MCUAPPS-7829

Posts: 451
Registered: ‎02-21-2014

Re: cp2102n Setconfig

[ Edited ]

I generated a more user-friendly version of the spreadsheet, which I've attached to this post.

 

Properties that are labeled "USER" are editable. The other properties should be left at their defaults.

Highlighted
Posts: 3
Registered: ‎03-24-2017

Re: cp2102n Setconfig

Thank you very much BrianL..

 

That's I am looking for.