Added a new flashing parameter for generic cheap St-link and bluepill(-128kib) boards.#13809
Added a new flashing parameter for generic cheap St-link and bluepill(-128kib) boards.#13809benpicco merged 1 commit intoRIOT-OS:masterfrom
Conversation
|
Thank you for the patch! |
Vinggui
left a comment
There was a problem hiding this comment.
I have no idea how my original commit had files that I didn`t change if I cloned this repo and then added my modification, just for the fork!
Well, I removed those files now. Let's see if it is accepted.
thanks @benpicco
|
Thank you much better now :) |
|
@benpicco I am recently working with these stm32fx "bluepill" boards, and I read that there are clone versions (very cheap) and the original ones. Besides, the blackpill board also shares "common/blxxxpil" folder and its files. So, I believe that who implemented these configurations and who is currently using RiotOS with these boards probably have everything working well. Changing some configuration here could slightly change their system. Meanwhile, adding a new config for these generic boards will keep the old behavior for original boards while adding portability. Configuration differences will impact only new projects using the new clone boards. I tried to optimize code to my best and avoid creating new files, but by my observation, it would just make code harder to read and little improvement to it. Thank you! |
Please read the documentation regarding flashing. It seems that you didn't connect the SRST signal. The change to Btw: Did you try flashing with the lasted OpenOCD (that is compiling it from source)? Maybe a separate config is no longer needed when a new release of OpenOCD is published? |
|
@maribu Thanks for your reply. I have the lastest compiled Openocd version. For me, it did not automatically work with a cloned version of bluepill. The CPUTAPID is not correct for it, the clone has 0x2ba01477. Also, I think this short answer you gave us over this topic will already help many in the community, connecting this "error" to the solution. |
The documentation page of the Bluepill (128 KiB version) contains only a single sentence, referring to the common documentation of the Bluepill / Blackpill boards. (Same for the other Bl*pill flavors.) And that is where the flashing info is. To me, this counts as properly documented 😉
That is a pitty. Citing the OpenOCD doc on
So, it would be possible to just list both IDs here and it would work for both flavors, without having the user to worry which chip the bluepill contains. From the user experience point of view, that would be the best solution. For now, this would require having our own So: I'd say this would be the route to go. @Vinggui, @benpicco: What do you think? |
|
I have been playing around with options the whole day and using my St-link v2 (clone version), and I still haven't been able to flash my stm32fx using the This leads me to think that other people might be having the same issue. So, making an option for generic boards/programmers could make their life easier. @maribu I really appreciate your input, please keep helping me finding common ground and a better solution. However, I don't think that having a full version of this openocd config
We could do that in our config and keep the append If you agree, I can work on it right now. Meanwhile I'm trying to make my St-link reset with the pin.... |
Maybe setting
I can confirm this. In the worst case, you could just manually press the reset button. Keep it pressed until OpenOCD starts, then release the button. This issue is however completely unrelated to whether your bluepill has a genuine STM32F103 or a clone MCU; it is only related to your debugger. A global solution like Btw: If you have a cheap ST-Link clone, you can convert it to a black magic probe. RIOT supports the Black Magic Probe for many boards by passing the |
|
First, thank you for sharing this bmp info. I'll look into it.
I think that so copying the entire cfg could indeed work. I found some better ways to work this around, but we needed more flexibility from the The way it is now, it requires many duplicated versions of .cfg files for each case. I think it's bad, but its the "only" way. I could do some work around this, but it would not be elegant. |
|
Ok... FirstI fixed the SecondIf you have a clone St-link debugger without the reset function, you can now make ThirdI renamed the |
7971b11 to
1ffd095
Compare
maribu
left a comment
There was a problem hiding this comment.
I have some minor remarks inline, but in general t his looks good to me. I'm not sure about the bootloader; I have the feeling that this might not be the best option to get DFU updates. I think @benpicco has more expertise on this.
If there is indeed a better option for DFU updates, I think it would be better to just recommend using that bootloader instead.
|
|
||
| # If using STM32duino bootloader, this change is necessary. | ||
| # Bootloader available at | ||
| # github.com/rogerclarkmelbourne/STM32duino-bootloader/tree/master/binaries | ||
| ifeq (stm32duino,$(BOOTLOADER)) | ||
| FFLAGS_OPTS ?= -R | ||
| FFLAGS ?= --device $(DFU_USB_ID) \ | ||
| --alt $(DFU_ALT) \ | ||
| --download $(FLASHFILE) \ | ||
| $(FFLAGS_OPTS) | ||
|
|
||
| # Flashing may be easier when uncommenting the "RESET_STM" line and | ||
| # using the binary "upload-reset" from rogerclarkmelbourne/Arduino_STM32. | ||
| # github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/tools/linux/upload-reset | ||
| # RESET_STM := $(shell $(RIOTBOARD)/common/blxxxpill/bin/upload-reset /dev/ttyACM0 750) | ||
| endif | ||
|
|
There was a problem hiding this comment.
This should be documented in boards/common/blxxxpill/doc.txt. (@benpicco: The other dfu bootloader doc is btw also missing. Care to add this?)
Also: The README of the stm32duino bootloader says this:
Also Note: Use GCC 4.8 (not 4.9 or newer, as those versions have more aggressive optimisation which cause hardware registers to be read incorrectly and consequently the bootloader does not work)
This is a highly significant indicator of code quality problems of the bootloader. (If your code breaks by updating GCC, in 999 out of 1000 cases the problem is your code, not GCC. I bet they forgot to add the volatile qualifier for accessing memory mapped I/O or similar.) Maybe it is just better to use a different bootloader instead?
There was a problem hiding this comment.
I think you did put a very pertinent question.
I got to know Riot a few years ago, but haven`t worked on it so far. Now I got some cheap boards (bluepills) to experience this system as an alternative or my projects. In my short experience working on STM32, I went through a lot of options to flash it, and one of the most cited/documented in the community was this stm32duino bootloarder.
During my attempts to flash using dfu provided in Arduino and Riot, I found this difference that made it actually possible to use their bootloader into Riot. With Riot`s default configuration for dfu, it did not work at all.
So, in general, I think you made a very good point, @benpicco indeed could give us some insight, but I think that leaving this BOOTLOADER=stm32duino option might be very useful for newcomers like me, especially if they have lesser knowledge about these things.
There was a problem hiding this comment.
Sorry I've bee busy the last couple of days - I'm not sure why you assume I have much knowledge about DFU bootloaders though 😆
You added the config for dfu-util(#12697), I just happened to use it. So I'm also not sure what doc you mean.
If using upload-reset makes flashing easier, why not always use it and download that tool on-demand? I wouldn't download the binary though, just the source and compile it like it's done with other tools.
upload-reset would then be added to FLASHDEPS.
There was a problem hiding this comment.
Is the RESET_STM variable anywhere referenced? It seems to neither be referenced in code introduced by this PR nor by existing code in RIOT. Thus, I don't see how this should have an impact.
There was a problem hiding this comment.
# Flashing may be easier when uncommenting the "RESET_STM" line and
# using the binary "upload-reset" from rogerclarkmelbourne/Arduino_STM32.
# github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/tools/linux/upload-reset
# RESET_STM := $(shell $(RIOTBOARD)/common/blxxxpill/bin/upload-reset /dev/ttyACM0 750)
RESET_STM is commented as one possible solution/improvement for someone trying stm32duino bootloader.
There was a problem hiding this comment.
Oh ok. I did not see this PREFLASHER option before. Nice!
Ok, it could be changed to that, IF your first USB reset does not work instead since we already have that.
But in any case, this is only useful if USB is on, which is not yet. I dont know if its worth changing this right now. I gotta check the USB first.
There was a problem hiding this comment.
Yea so better remove it for now, maybe add a comment that upload-reset can be used in the future.
There was a problem hiding this comment.
I still think that a comment would still be helpful for some people and still not affect code anyhow. But, in this case, it's your call.
There was a problem hiding this comment.
A comment that upload-reset /dev/ttyACM0 750 should be used as PREFLASHER once we have USB support for stm32f1 is good, but let's not get people to think this implicit reset at Makefile evaluation would be a good idea 😉
There was a problem hiding this comment.
Doing it now. But, important to remember that the bootloader has USB support, and that is why the reset command can improve this procedure.
So I'm going to test this PREFLASHER option now.
| # Flashing may be easier when uncommenting the "RESET_STM" line and | ||
| # using the binary "upload-reset" from rogerclarkmelbourne/Arduino_STM32. | ||
| # github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/tools/linux/upload-reset | ||
| # RESET_STM := $(shell $(RIOTBOARD)/common/blxxxpill/bin/upload-reset /dev/ttyACM0 750) |
There was a problem hiding this comment.
Btw: How does this affect flashing?
There was a problem hiding this comment.
That's is why I did not incorporate this code into the commit, just mentioned the possibility.
Indeed, there are some caveats:
1- Arduino's structure uses USB for its stdio (which should be one of my priorities soon). Hence, this RESET_STM works great (if CPU is not in delay()). But in Riot, USB is not active after bootloading, so the reset won't kick in after that, reset must be pressed manually.
2- During the flash of the Riot's default dfu configuration, it does not wait the device to be reset, then it makes very hard to synchronize both actions manually. With this RESET_STM, stm32duino receives a command to wait for flash and makes dfu synchronization easier (that was my impression). So I decided to leave this suggestion commented.
I wouldn't mind removing this, but what is the problem of some more information/help?
There was a problem hiding this comment.
btw.: this seems very similar to what is done on sam0 with the Arduino bootloader (#12304), so the RIOT USB stack already has a baudrate hack in place to trigger a bootloader reset.
Unfortunately the USB peripheral is not the same across all stm32, so currently stm32f1 has no USB support in RIOT.
There was a problem hiding this comment.
In any case, this reset is not absolutely necessary, and it may not always work, because of USB peripheral not available.
I wonder how easy would it be to port the code from Arduino, they use USB as STDIO.
There was a problem hiding this comment.
You can use USB as STDIO too in RIOT, just not on stm32f1 (yet) - you'd have to implement/adopt stm32_common/periph/usbdev.c.
On stm32f4 (e.g. #12778) stdio over USB works just fine.
There was a problem hiding this comment.
I'm sorry, I meant that I agree with you.
My point is that in Arduino stm32f1 is already working with USB as STDIO too, so maybe just observing their code and adapting into RIOT could be possible/faster.
There was a problem hiding this comment.
I don't think there is any technical reason for why it's not done for stm32f1 yet - it's just that nobody has done it yet/is actively working on it.
If you want to work on this, that would be great!
There was a problem hiding this comment.
I should. I would like to use it too, but first I wanna get this one done.
|
Sorry that we dropped this here.
|
|
@benpicco Done. |
Contribution description
It is now possible to use a new flashing parameter BOOTLOADER=stm32duino for those cheap generic bluepill(-128kib) boards (stm32F1x) while keeping backward compatibility.
It fixes the 'make flash' using clone stlink-v2 (use SRST=none). It also fixes flashing when using "PROGRAMMER=dfu-util", if your device already has the bootloader (stm32duino) installed somehow (like using Serial connection).
This PR changes:
Bugs fixed when flashing generic STM32 bluepill boards with stlink-v2
Solution: Added new .cfg for generic board with
set CPUTAPID 0x2ba01477Solution: Changed reset_config line in the new .cfg for generic board
from
reset_config srst_only srst_nogate connect_assert_srstto
reset_config none srst_nogate connect_assert_srstBugs fixed when flashing generic STM32 bluepill boards with stm32duino bootloader
Solution: Changed blxxxpil makefile for generic board
Testing procedure
If you are trying to flash for it, just add "BOOTLOADER=stm32duino" or "SRST=none" before "make flash".
BOARD=bluepill SRST=none make clean all flashBOARD=bluepill PROGRAMMER=dfu-util BOOTLOADER=stm32duino make clean all flashIn case of dfu-util programmer, you need to synchronize pushing the reset button before flashing it.
Issues/PRs references
Maybe solves issue #11030