How to invoke a python upload script correctly?
Posted: Mon Jun 03, 2024 12:44 pm
I started playing with some WeAct CH32X035 boards and came across wagiminator / MCU-Flash-Tools which contains Python flash scripts for various MCUs including stm32isp
I want to add support for the chprog flash tool to arduino_core_ch32. For testing purposes, I have done the following:
1. Download and copy chprog.py to: `/Users/ZZZ/Library/Arduino15/packages/WCH/tools/openocd/1.0.0/bin`
2. Add the following to platform.txt:
3. Add the following to boards.txt:
I then select Wagiminator chprog as the upload method and hit upload. The correct upload command is generated:
But the command fails with:
When I run the generated upload command from the command line, it works as expected, thus it seems as if my environment is set up correctly.
Running which python3 gives:
From Arduino, the following version of python3 is executed:
I hardcoded the path to the non-xcode python3 executable in platform.txt with the same error described above. I do not know enough about the python environment to fix this.
I downloaded pyinstaller and bundle chprog.py to a "One File" executable using:
I then modified platform.txt to reference this executable, and it is working as expected.
I was hoping someone can help me understand what I need to do to get the original chprog.py python script working
My setup:
I want to add support for the chprog flash tool to arduino_core_ch32. For testing purposes, I have done the following:
1. Download and copy chprog.py to: `/Users/ZZZ/Library/Arduino15/packages/WCH/tools/openocd/1.0.0/bin`
2. Add the following to platform.txt:
Code: Select all
## CHPROG
tools.CHPROG.path={runtime.tools.openocd-1.0.0.path}/bin/
tools.CHPROG.cmd=chprog.py
tools.CHPROG.upload.params.verbose=
tools.CHPROG.upload.params.quiet=
tools.CHPROG.upload.pattern=python3 "{path}{cmd}" "{build.path}/{build.project_name}.bin"
Code: Select all
CH32X035_EVT.menu.upload_method.chprogMethod=Wagiminator chprog
CH32X035_EVT.menu.upload_method.chprogMethod.upload.protocol=chprog
CH32X035_EVT.menu.upload_method.chprogMethod.upload.options=
CH32X035_EVT.menu.upload_method.chprogMethod.upload.tool=CHPROG
Code: Select all
python3 /Users/ZZZ/Library/Arduino15/packages/WCH/tools/openocd/1.0.0/bin/chprog.py /var/folders/tq/dqrghm993td49tz1pvg8psxm0000gn/T/arduino_build_807950/Blink.ino.bin
Code: Select all
Traceback (most recent call last):
File "/Users/ZZZ/Library/Arduino15/packages/WCH/tools/openocd/1.0.0/bin/chprog.py", line 45, in <module>
import usb.core
ModuleNotFoundError: No module named 'usb'
Running which python3 gives:
Code: Select all
/Library/Frameworks/Python.framework/Versions/3.12/bin/python3
Code: Select all
/Applications/Xcode.app/Contents/Developer/usr/bin/python3
I downloaded pyinstaller and bundle chprog.py to a "One File" executable using:
Code: Select all
pyinstaller --onefile chprog.py
I was hoping someone can help me understand what I need to do to get the original chprog.py python script working
My setup:
- macOS Sonoma 14.5 M1
arduino_core_ch32 1.0.4
Arduino 1.8.19