florisla / stm32loader

Flash firmware to STM32 microcontrollers using Python.
GNU General Public License v3.0
111 stars 55 forks source link

Fix incorrect checksum in write_memory when byte count != 255 #9

Closed NINI1988 closed 5 years ago

NINI1988 commented 5 years ago

The checksum in write_memory must be set to nr_of_bytes and not 0xFF.

https://github.com/florisla/stm32loader/blob/1ec166ce22675f263a26df6a5faf1406f5b35ec5/stm32loader/stm32loader.py#L274

Then it's possible to send multiple of 4 bytes and we are not required to send mutliple of 256 bytes.

The following code can be added to the write_memory function to add the padding:

if nr_of_bytes % 4 != 0:
    data.extend(([0xFF] * (4 - (nr_of_bytes % 4))))
    nr_of_bytes = len(data)-1
florisla commented 5 years ago

Thanks for reporting this.

AN3155 confirms it; section 3.6 says 'XOR of N and of all data bytes' -- where N is the byte count -1.

I'll support this in a next release, but it may take a while until I resurrect my STM32.

Note: this is an XOR checksum, not a CRC.

N0ury commented 5 years ago

@NINI1988 can you please put here a diff ?

florisla commented 5 years ago

@nbenm See this new branch. Beware, this is untested.

N0ury commented 5 years ago

@florisla Thanks. I have cloned 9-write-memory-smaller-byte-count branch. I'll try it in nearly two weeks after receiving my new devices. I'll close then the issue if it works fine.

florisla commented 5 years ago

This is released in v0.4.0.

@nbenm If you're going to test it, could you try the latest version from PyPI?

N0ury commented 5 years ago

Hi @florisla I have downloaded v0.4.0 Successfully installed progress-1.5 stm32loader-0.4.0 But I'm still waiting for the devices. The seller told me it will take 2 weeks.

N0ury commented 5 years ago

I tried the new version. I didn't have any problems. That doesn't mean there's none.

florisla commented 5 years ago

Thanks for reporting!

If anything else is broken I'm sure someone will create an issue soon enough ;-)