florisla / stm32loader

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

Activating read protection #21

Closed N0ury closed 5 years ago

N0ury commented 5 years ago

Hi,

Is it possible to activate read protection using stm32loader? I have seen an existing "readout_protect" function in the code. How to use it if possible? I don't need it to protect any code. I'm doing some tests, and I need to read protect and then unprotect the flash, to see it being erased. If there's another way to do that, it's ok for me.

florisla commented 5 years ago

There is no command-line argument to configure read protection currently.

I'm planning to add this, but it will be some weeks before I get to it.

Alternatively, you could write a short Python script and use stm32loader as a library to call readout_protect. I can provide an example script if you want.

N0ury commented 5 years ago

That would be very nice if you can provide such a script.

N0ury commented 5 years ago

I have tried this, but I'm not sure it works

#!/usr/bin/env python3

from stm32loader.main import Stm32Loader
loader = Stm32Loader()
loader.configuration["port"]="/dev/cu.usbserial-A5XK3RJT"
loader.connect()
loader.stm32.readout_unprotect()
N0ury commented 5 years ago

It works fine switching from readout_unprotect() to readout_protect() stm32loader "-r" option gives an error using readout_unprotect() after that makes it possible to read the flash, but it has been erased. That's exactly what I want. It would make stm32loader much better if you can add a protect option.

Thanks for this idea you gave me.

florisla commented 5 years ago

Thanks for reporting and trying this!