Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial upload with custom reset methods #257

Open
JarrettR opened this issue Jul 3, 2019 · 3 comments · May be fixed by #664
Open

Serial upload with custom reset methods #257

JarrettR opened this issue Jul 3, 2019 · 3 comments · May be fixed by #664

Comments

@JarrettR
Copy link

JarrettR commented Jul 3, 2019

This is possibly more of a discussion than any kind of bug report.Also documenting this method for anyone searching for a similar solution in the future.

Using the upload_protocol = serial requires manually setting jumpers and hitting reset buttons, generally. The RTS/DTR pins on most USB-UART dongles are used to trigger proper reset states on the ESP8266/32 boards, so it seems reasonable to support doing that for STM32 boards as well.

For reference, the serial upload method calls this code path:
https://github.com/platformio/platform-ststm32/blob/develop/builder/main.py#L174

This, in turns calls (I believe) this bat file, on Windows:
https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/master/tools/win/serial_upload.bat

The bat file calls stm32flash, PDF manual located here:
http://stm32flash.sourceforge.net/stm32flash-manual.pdf

The manual provides an example of how to use RTS/DTR in the way I propose:

• entry sequence: RTS=low, DTR=low, DTR=high
• exit sequence: RTS=high, DTR=low, DTR=high
stm32flash −R −i −rts,−dtr,dtr:rts,−dtr,dtr /dev/ttyS0

In this case, the DTR pins needs to be connected to the STM32's nRST / RESET pin, and the RTS needs to be connected to BOOT0.

Because of the weird argument format given to stm32flash, there doesn't appear to be any way to pass the arguments via PlatformIO. Any combination of the arguments in platformio.ini's upload_flags breaks the .bat file, in part due to the positional command %1 in line 11 of the .bat file.

This can be manually hacked around by changing line 11 of .platformio\packages\tool-stm32duino\serial_upload.bat to:
stm32flash -g 0x8000000 -R -i -rts,-dtr,dtr:rts,-dtr,dtr -b 115200 -w %str% %1

This works great for flashing over serial! Very happy with it.

But you know, not having to do a dirty hack would be nice. I'm really not sure the best approach for cleanly implementing it into the framework.

@rwalli
Copy link

rwalli commented Jul 12, 2019

why not use extra_scripts?

@yulong88888
Copy link

@JarrettR Hello, I also encountered the same problem recently, I don’t want to change the bat file, can it be achieved using extra_scripts.py configuration? looking forward to your reply

Miceuz added a commit to Miceuz/platform-ststm32 that referenced this issue Dec 15, 2022
This config can be used to specify a custom reset method during serial upload.

Example:
```
  "upload": {
    "maximum_ram_size": 65536,
    "maximum_size": 262144,
    "protocol": "serial",
    "protocols": [
      "dfu",
      "serial",
      "jlink",
      "stlink",
      "blackmagic"
    ],
    "gpiostring": "-dtr,-rts,"
```

Fix platformio#257

Also fix a small bug where 'False' would be inserted in case when
tool-stm32duino package is not available.
@Miceuz Miceuz linked a pull request Dec 15, 2022 that will close this issue
@Miceuz
Copy link

Miceuz commented Dec 16, 2022

Since this is board dependent, I think we can add a board level config parameter that would allow to specify gpio manipulation necessary - I have created a PR implementing this. Let me know your thoughts.

Miceuz added a commit to Miceuz/platform-ststm32 that referenced this issue Dec 21, 2022
This config can be used to specify a custom reset method during serial upload.

Example:
```
  "upload": {
    "maximum_ram_size": 65536,
    "maximum_size": 262144,
    "protocol": "serial",
    "protocols": [
      "dfu",
      "serial",
      "jlink",
      "stlink",
      "blackmagic"
    ],
    "gpiostring": "-dtr,-rts,"
```

Fix platformio#257

Also fix a small bug where 'False' would be inserted in case when
tool-stm32duino package is not available.

--amend
Miceuz added a commit to Miceuz/platform-ststm32 that referenced this issue Dec 21, 2022
This config can be used to specify a custom reset method during serial upload.

Example:
```
  "upload": {
    "maximum_ram_size": 65536,
    "maximum_size": 262144,
    "protocol": "serial",
    "protocols": [
      "dfu",
      "serial",
      "jlink",
      "stlink",
      "blackmagic"
    ],
    "gpiostring": "-dtr,-rts,"
```

Fix platformio#257
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants