Cannot upload code

I am sorry if my frustration shows through, but each time I return to PIO to amend my code and upload it, it’s become an almost certain bet that it won’t upload, and that’s what’s happened again today.

So I have a avr4809 40 pin variant which uses UPDI for programming. I have pyupdi set up in my pio.ini and it fails to work. I appreciate it is deprecated and pymcuprog is now advised. I can only use pymcuprog from the cli as trying to set it up in PIO.ini failed, but that’s an issue for another post perhaps.

So anyway,

here’s what I get from pymcuprog:


PS C:\Users\Paul\Documents\PlatformIO\Projects\Live\Stepper> pymcuprog write -d atmega4809 -t uart -u COM3 -c 250k -f .pio\build\ATmega4809\firmware.hex -erase
usage: pymcuprog [-h] [-d DEVICE] [-p PACKPATH] [-t TOOL] [-s SERIALNUMBER] [-m MEMORY] [-o OFFSET] [-b BYTES] [-l LITERAL [LITERAL ...]] [-f FILENAME] [-c CLK] [-u UART] [-i INTERFACE]
                 [-v {debug,info,warning,error,critical}] [-V] [-R] [--erase] [--verify] [-x] [-H {tool-toggle-power,user-toggle-power,simple-unsafe-pulse}] [-U] [-C]
                 {ping,erase,read,write,verify,getvoltage,getsupplyvoltage,reboot-debugger,setsupplyvoltage,getusbvoltage,reset}
pymcuprog: error: unrecognized arguments: –erase
PS C:\Users\Paul\Documents\PlatformIO\Projects\Live\Stepper> 

and as you can see it doesn’t recognise the --erase parameter which is essential for correct upload.

I posted at pymcuprog a while back and a reinstall of pymcuprog resolved the problem. I guess it will again, but why should I have to reinstall pymcuprog each time I use PIO???

here’s what pyupdi says:

C:\Users\Paul\.platformio\penv\Scripts\platformio.exe run --target upload 

Processing ATmega4809 (board: ATmega4809; platform: atmelmegaavr; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/ATmega4809.html
PLATFORM: Atmel megaAVR (1.4.0) > ATmega4809
HARDWARE: ATMEGA4809 20MHz, 6KB RAM, 48KB Flash
PACKAGES:
 - framework-arduino-megaavr-megacorex @ 1.0.9
 - tool-avrdude-megaavr @ 2.60300.210128 (6.3.0)
 - toolchain-atmelavr @ 2.70300.201015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 24 compatible libraries
Scanning dependencies...
Dependency Graph
|-- AccelStepper @ 1.61.0
|-- SoftwareReset @ 3.0.0
|-- Circular-Linked-List
|-- SPI @ 1.0
Building in release mode
Checking size .pio\build\ATmega4809\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  22.8% (used 1398 bytes from 6144 bytes)
Flash: [===       ]  31.8% (used 15627 bytes from 49152 bytes)
Configuring upload protocol...
AVAILABLE: custom
CURRENT: upload_protocol = custom
Uploading .pio\build\ATmega4809\firmware.hex
Traceback (most recent call last):
  File "C:\Users\Paul\.platformio\python3\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Paul\.platformio\python3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\Paul\.platformio\penv\Scripts\pyupdi.exe\__main__.py", line 7, in <module>
  File "C:\Users\Paul\.platformio\penv\lib\site-packages\updi\pyupdi.py", line 111, in _main
    if not _process(nvm, args):
  File "C:\Users\Paul\.platformio\penv\lib\site-packages\updi\pyupdi.py", line 136, in _process
    return _flash_file(nvm, args.flash)
  File "C:\Users\Paul\.platformio\penv\lib\site-packages\updi\pyupdi.py", line 151, in _flash_file
    nvm.write_flash(start_address, data)
  File "C:\Users\Paul\.platformio\penv\lib\site-packages\updi\nvm.py", line 111, in write_flash
    return self._write_mem(address, data, self.device.flash_pagesize, use_word_access=True)
  File "C:\Users\Paul\.platformio\penv\lib\site-packages\updi\nvm.py", line 133, in _write_mem
    self.application.write_nvm(address, page, use_word_access=use_word_access)
  File "C:\Users\Paul\.platformio\penv\lib\site-packages\updi\application.py", line 346, in write_nvm_v0
    self.execute_nvm_command(constants.UPDI_V0_NVMCTRL_CTRLA_PAGE_BUFFER_CLR)
  File "C:\Users\Paul\.platformio\penv\lib\site-packages\updi\application.py", line 228, in execute_nvm_command
    return self.datalink.st(self.device.nvmctrl_address + constants.UPDI_NVMCTRL_CTRLA, command)
  File "C:\Users\Paul\.platformio\penv\lib\site-packages\updi\link.py", line 124, in st
Device info: {'family': 'megaAVR', 'nvm': 'P:0', 'ocd': 'D:1', 'osc': '3', 'device_id': '1E9651', 'device_rev': '0.1'}
    raise Exception("Error with st")
Exception: Error with st
*** [upload] Error 1
===================================================================================== [FAILED] Took 14.68 seconds =====================================================================================
 *  The terminal process "C:\Users\Paul\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

So I can’t upload code at present, any help much appreciated.

But the program help text shows

Where is -erase coming from?

thanks for spotting that. Where it’s coming from is as follows:

because I can’t get pymcuprog to work from the pio.ini i use it from the CLI as I mentioned. Also because I tend to use it fairly infrequently, I copied the pymcuprog command into a google doc so that I can remember it. So google docs has ‘converted’ the two ‘-’ chars into one. I then cut and pasted that back to the pio cli and of course the error occurred.

Is there any way I can set pymcuprog up in the pio.ini ? it would save the cut and paste.

thanks for help