Skip to content

Commit

Permalink
docs: Describe the various ways to start stm32loader
Browse files Browse the repository at this point in the history
  • Loading branch information
florisla committed Feb 28, 2022
1 parent 5247d3d commit ad8957a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
52 changes: 52 additions & 0 deletions RUN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

# Running stm32loader


## Execute as a module

After installing stm32loader with `pip`, it's available as a Python module.

You can execute this with `python -m [modulename]`.

```shell
python3 -m stm32loader
```


## Execute as a module without installing

You can also run `stm32loader` without installing it. You do need `pyserial` though.

Make sure you are in the root of the repository, or the repository is in `PYTHONPATH`.

```shell
python3 -m pip install pyserial --user
python3 -m stm32loader
```


## Execute main.py directly

The file `main.py` also runs the `stm32loader` program when executed.
Make sure the module can be found; add the folder of the repository to `PYTHONPATH`.

```shell
PYTHONPATH=. python3 stm32loader/main.py
```


## Use from Python

You can use the classes of `stm32loader` from a Python script.

Example:

```python
from stm32loader.main import Stm32Loader

loader = Stm32Loader()
loader.configuration.port = "/dev/cu.usbserial-A5XK3RJT"
loader.connect()
loader.stm32.readout_unprotect()
loader.disconnect()
```
3 changes: 2 additions & 1 deletion stm32loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import copy
import os
import sys
from types import SimpleNamespace

try:
from progress.bar import ChargingBar as progress_bar
Expand Down Expand Up @@ -71,7 +72,7 @@ class Stm32Loader:
def __init__(self):
"""Construct Stm32Loader object with default settings."""
self.stm32 = None
self.configuration = None
self.configuration = SimpleNamespace()

def debug(self, level, message):
"""Log a message to stderror if its level is low enough."""
Expand Down
7 changes: 7 additions & 0 deletions stm32loader/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ def connect(self):
timeout=self._timeout,
)

def disconnect(self):
if not self.serial_connection:
return

self.serial_connection.close()
self.serial_connection = None

def write(self, *args, **kwargs):
"""Write the given data to the serial connection."""
return self.serial_connection.write(*args, **kwargs)
Expand Down

0 comments on commit ad8957a

Please sign in to comment.