What's the difference - stm32duino makes st-link inoperrable?

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
mkr
Posts: 7
Joined: Fri Jan 19, 2018 10:33 pm

What's the difference - stm32duino makes st-link inoperrable?

Post by mkr » Sat Jan 20, 2018 3:42 pm

Hi all,

Some time ago I've moved from arduino ide to Eclipse (on linux). My project (small game for my nephew) used ST SPL for "blue pill", u8g library (graphics primitives, screen buffer handling), Nokia 5110 LCD with my own drivers and rotary encoder (handled by my code) - nothing special.
In fact I've used eclipse for code navigation and as good source browser for ST and u8g staff. Build process was driven by my own self-made makefile and the only linked in things were SPL distribution rooted startup files (no libgcc nor libc nor libstdc++).
I've used Chinese st-link clone for uploads with st-flash utility (exec bundled with Arduino IDE for Linux). Everything worked fine and development was very smooth - every code change was recompiled and re-linked by makefile and finally uploaded to stm32 board with reset and program started.

For next project i'd like to give the chance to other tools - Arduino API (stm32duino) built via PlatformIO IDE (VSCode on linux). In terms of usability this is way better than Arduino IDE - VSCode is decent IDE with powerful Sublime like editor, code completion and navigation. Unfortunately, on first sketch (LED blink) problems appeared. Build process is smooth but firmware upload is very unstable:

First upload (board had my game fw) was smooth:

Code: Select all

st-flash write .pioenvs/genericSTM32F103CB/firmware.bin 0x08000000
2018-01-20T15:56:03 INFO src/usb.c: -- exit_dfu_mode
2018-01-20T15:56:03 INFO src/common.c: Loading device parameters....
2018-01-20T15:56:03 INFO src/common.c: Device connected is: F1 Medium-density device, id 0x20036410
2018-01-20T15:56:03 INFO src/common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes
2018-01-20T15:56:03 INFO src/common.c: Attempting to write 8436 (0x20f4) bytes to stm32 address: 134217728 (0x8000000)
...
2018-01-20T15:56:04 INFO src/common.c: Starting verification of write complete
2018-01-20T15:56:04 INFO src/common.c: Flash written and verified! jolly good!
  8/8 pages written
but every next upload gave:

Code: Select all

rm-none-eabi-objcopy -O binary .pioenvs/genericSTM32F103CB/firmware.elf .pioenvs/genericSTM32F103CB/firmware.bin
st-flash write .pioenvs/genericSTM32F103CB/firmware.bin 0x08000000
2018-01-19T23:03:55 INFO src/common.c: Loading device parameters....
2018-01-19T23:03:55 WARN src/common.c: unknown chip id! 0xa05f0000
st-flash 1.3.1
As a workaround I've googled that shorting Boot0 and reset of the board (builtin serial bootloader is activated then) makes st-flash possible again but it's VERY annoying to do it every time... Restart of the board (reset or re-plug) is not enough..

Then I've tried to re-flash my previous FW (done with makefile) It's uploaded with the same method (st-flash write fw 0x8000000) and first time I've to activate serial bootloader, but, after first flash every re-flashing was smooth again - this proves that HW (board and st-link) is still operable and stm32duinow firmware is probably the root of the problem. I've also tried to upgrade fw on st-link (now its newest) and try most recent texane/stlink, but it did change nothing...

I wonder if someone else had similar problems and why stm32duino based firmware (just simple blink) makes the board not flashable via st-link...
Maybe my board is somehow broken, but using old staff with it still works fine. It looks like stm32duino init part or some gcc related staff makes re-flashing so hard. I've tried 3 different toolchains (Arduino gcc, PlatformIO gcc and bleeding-edge gcc) but it also changed nothing..

Please help...

victor_pv
Posts: 1871
Joined: Mon Apr 27, 2015 12:12 pm

Re: What's the difference - stm32duino makes st-link inoperrable?

Post by victor_pv » Sat Jan 20, 2018 4:42 pm

May have something to do witht he debug pins. Not sure what's the default not, but look around the init() function, or wherever is called from, the find the one that sets the debug pins to alternate mode. A search in the forum will possibly give you some pointers.
Search for debug pins, or jtag or something in those lines.

mkr
Posts: 7
Joined: Fri Jan 19, 2018 10:33 pm

Re: What's the difference - stm32duino makes st-link inoperrable?

Post by mkr » Sat Jan 20, 2018 6:30 pm

Yeah...that's the simplest explanation...but for me was quite clear that such a mature soft as duino is, should not do such a things... Thought that my config is quite common and someone would notice such a thing... But, alright I'll try to investigate that.

zmemw16
Posts: 1687
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: What's the difference - stm32duino makes st-link inoperrable?

Post by zmemw16 » Sat Jan 20, 2018 6:34 pm

what pins are you using ? anything on the low side of PB is problematical pb0-pb5 !
stephen

User avatar
mrburnette
Posts: 2236
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: What's the difference - stm32duino makes st-link inoperrable?

Post by mrburnette » Sat Jan 20, 2018 7:07 pm

mkr wrote:
Sat Jan 20, 2018 6:30 pm
Yeah...that's the simplest explanation...but for me was quite clear that such a mature soft as duino is, should not do such a things... Thought that my config is quite common and someone would notice such a thing... But, alright I'll try to investigate that.
... a misconception.
The "core" has nothing to do with uploading. Uploading is done via 3rd party tools under ArduinoIDE. Outside the ArduinoIDE, we have no responsibility for failures; that is, you have a clone board, a clone ST_Link, and are using a make file to compile (or other environment.) The forum's baseline environment is Windows or Linux running a recent version of the ArduinoIDE and the Maple Mini with bootloader (2K or 4K.)

I do appreciate your situation, but the "duino" in STM32duino is a reference to the ArduinoIDE. We have many members using other tools for code development and broadly two classes of users: those that use Roger's github_hosted bootloaders and those that use no bootloaders. When outside the IDE, you are welcome to post and ask for assistance but just remember you are ultimately in self-supported territory.

Even using the ArduinoIDE, uploading can be very problematic, rarely 100% success.

Ray

mkr
Posts: 7
Joined: Fri Jan 19, 2018 10:33 pm

Re: What's the difference - stm32duino makes st-link inoperrable?

Post by mkr » Sat Jan 20, 2018 7:16 pm

Bingo!

Adding

Code: Select all

void setup() {
    // AFIO_BASE - expansion from SPL
    uint32_t *AFIO = ((uint32_t *)((((uint32_t)0x40000000) + 0x10000) + 0x0000));
    // AFIO_MAPR->SWJ_CFG = 0x0 // no remap, both JTAG and SWD active
    AFIO[1] &= ~(0x07000000);
    
    pinMode(LED, OUTPUT);
}
And board is easily re-flashable with st-link connected to blue pill shorter edge's pins (PA13 / PA14).
I'm really surprised that noone was bothered by that...

My wiring is like that
Image

Maybe this should be default config for duino, what you think.

mkr
Posts: 7
Joined: Fri Jan 19, 2018 10:33 pm

Re: What's the difference - stm32duino makes st-link inoperrable?

Post by mkr » Sat Jan 20, 2018 7:33 pm

mrburnette wrote:
Sat Jan 20, 2018 7:07 pm

The "core" has nothing to do with uploading. Uploading is done via 3rd party tools under ArduinoIDE. Outside the ArduinoIDE, we have no responsibility for failures; that is, you have a clone board, a clone ST_Link, and are using a make file to compile (or other environment.) The forum's baseline environment is Windows or Linux running a recent version of the ArduinoIDE and the Maple Mini with bootloader (2K or 4K.)

I do appreciate your situation, but the "duino" in STM32duino is a reference to the ArduinoIDE. We have many members using other tools for code development and broadly two classes of users: those that use Roger's github_hosted bootloaders and those that use no bootloaders. When outside the IDE, you are welcome to post and ask for assistance but just remember you are ultimately in self-supported territory.

Even using the ArduinoIDE, uploading can be very problematic, rarely 100% success.
But the "core" setups microcontroller and st-link is officially supported way of uploading (appears in AIDE menu). And st-link is most probably blocked by this initialization... This seems to be AIDE problem. Preventing of SWD remapping should address most of AIDE issues with uploading via st-link... Most probably OCD is also disabled by "duino" which is rather bad news.

User avatar
mrburnette
Posts: 2236
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: What's the difference - stm32duino makes st-link inoperrable?

Post by mrburnette » Sat Jan 20, 2018 8:16 pm

mkr wrote:
Sat Jan 20, 2018 7:33 pm
<...>
But the "core" setups microcontroller and st-link is officially supported way of uploading (appears in AIDE menu). And st-link is most probably blocked by this initialization... This seems to be AIDE problem. Preventing of SWD remapping should address most of AIDE issues with uploading via st-link... Most probably OCD is also disabled by "duino" which is rather bad news.
There are two (2) cores both unfortunately called STM32duino:
https://github.com/rogerclarkmelbourne/Arduino_STM32
and
https://github.com/stm32duino/Arduino_C ... sed-boards

Both cores are intended to be used with the ArduinoIDE, in a base_line configuration. If you deviate the IDE or build process, you put a strain on "duino" resources. Do what you want but be prepared to take the risks.

Only the last link above is considered "supported" and to what level beyond "best effort" only fpiSTM can advise. Questions are answered in this section of the forum...
http://stm32duino.com/viewforum.php?f=48

As this specific section of STM32DUINO has no "official" support, technically nothing is Officially supported. Even the core files are marked"Experimental"...
Notice
This software is experimental and a work in progress. Under no circumstances should these files be used in relation to any critical system(s). Use of these files is at your own risk.
But, if you drop over to the ST core section for Nucleo boards, then there is some support.
https://github.com/stm32duino For core and other efforts.
And
https://github.com/stm32duino/Arduino_C ... sed-boards
Boards available
Current release
STM32F0

Nucleo F030R8
Nucleo F091RC
STM32F1

Nucleo F103RB
STM32VLDISCOVERY
STM32F2

Nucleo F207ZG
STM32F3

Nucleo F302R8
Nucleo F303K8
Nucleo F303RE
STM32F4

Nucleo F401RE
Nucleo F411RE
Nucleo F429ZI
Nucleo F446RE
STM32F407G-DISC1
STM32F7

STM32F746G-DISCOVERY
STM32L0

Nucleo L031K6
Nucleo L053R8
B-L072Z-LRWAN1
STM32L1

Nucleo L152RE
STM32L4

Nucleo L432KC
Nucleo L476RG
B-L475E-IOT01A
Next release
STM32F1
BluePill F103C8 (on going)
MapleMini F103CB (on going)

User avatar
Rick Kimball
Posts: 1079
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: What's the difference - stm32duino makes st-link inoperrable?

Post by Rick Kimball » Sat Jan 20, 2018 8:28 pm

mkr wrote:
Sat Jan 20, 2018 7:16 pm
Maybe this should be default config for duino, what you think.
Assuming you are using the libmaple core and the stlink upload option it is

viewtopic.php?t=27
-rick

User avatar
mrburnette
Posts: 2236
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: What's the difference - stm32duino makes st-link inoperrable?

Post by mrburnette » Sat Jan 20, 2018 8:44 pm

mkr wrote:
Sat Jan 20, 2018 7:16 pm
Bingo!
<...>
Maybe this should be default config for duino, what you think.
mkr:

This is the kind of knowledge that the user community wants to capture. It would make an excellent WiKi topic after some discussion with other advanced members who use ST_Link... hopefully they will chime in and continue this discussion.

Ray

Post Reply