Skip to content

Commit

Permalink
Added erase flash to Platformio projecs tasks to restore motor to unc…
Browse files Browse the repository at this point in the history
…alibrated state
  • Loading branch information
dzid26 committed Aug 4, 2024
1 parent 77a59cd commit e318d18
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
- A4950 current drivers (integrated mosfets) - **IMPORTANT** - do not back drive the motor without the [board modification](https://github.com/dzid26/RetroPilot-SERVO42B/wiki/Board-BEMF-protection-mod)

## Firmware
- It uses Platformio build system, to configure, upload and debug the program
- Uses ST's (old) Standard Peripheral Library (src/lib) for registers configuration
- CAN handling c-code is generated from dbc file using cantools. See `generate_Msg.sh`
- It uses Platformio to build, upload and debug the program
- User can interract with Function buttons (F1 and F2) and Reset button (Rst) or via debug virtual serial, aka semihosting
- CAN handling c-code is generated from dbc file using cantools. See `generate_Msg.sh`
- User can interact with the program using Function buttons (F1 and F2) and Reset button (Rst)

### Build and upload
- Specify your programming dongle in `firmware/platformio.ini` - default is stlink
Expand All @@ -27,7 +27,8 @@
platformio run
```
- Upload firmware to the board by pressing Upload arrow at the status bar in VScode
- Eeprom is not erased when flashing the firmware - any future calibration will not be lost.
- Eeprom is not erased when flashing the firmware - any future calibration will not be lost
- Eeprom can be erased to factory state using ST-Link tool or in Platformio activity bar ServoCAN_dev -> Custom -> Erase Flash

### Configuration
- In `firmware/src/BSP/actuator_config.c` set:
Expand Down
38 changes: 38 additions & 0 deletions firmware/erase_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from SCons.Script import ARGUMENTS
from os.path import join
Import("env")

def do_erase(*args, **kwargs):
board = env.BoardConfig()
platform = env.PioPlatform()
upload_protocol = env.subst("$UPLOAD_PROTOCOL")
debug_tools = board.get("debug.tools", {})
openocd_args = [
join(platform.get_package_dir("tool-openocd"), "bin", "openocd"),
"-d%d" % (2 if int(ARGUMENTS.get("PIOVERBOSE", 0)) else 1)
]
# openocd_args.extend([
# "-c", "set CPUTAPID 0x2ba01477",
# ])
openocd_args.extend(
debug_tools.get(upload_protocol).get("server").get("arguments", []))
# actual erase command: erase bank 0, first sector to last sector.
# assumes it's a 1-bank device. some STM32s have dual bank.
openocd_args.extend([
"-c",
"init; halt; flash probe 0; flash erase_sector 0 0 last; reset; shutdown;"
])
# print("OpenOCD args", openocd_args)
# string escape every argument
openocd_args = ['"' + arg + '"' for arg in openocd_args]
env.Execute(" ".join(openocd_args))

env.AddCustomTarget(
name="erase",
dependencies=None,
actions=[
do_erase
],
title="Erase Flash",
description="Erase eeprom (calibrations) and flash (program). Flash new program after this and perform motor calibration"
)
4 changes: 3 additions & 1 deletion firmware/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ build_flags =

board_build.ldscript = ./src/APP/STM32F103C8_DEFAULT.ld
board_upload.maximum_size = 63488
extra_scripts = pre:linker_options_pio.py
extra_scripts =
pre:erase_task.py
pre:linker_options_pio.py

check_tool = cppcheck, clangtidy
check_skip_packages = yes ;don't inlcude compiler package inludes
Expand Down

0 comments on commit e318d18

Please sign in to comment.