Getting Started with STM32F103 under Linux

VK3TY
Fri Oct 07, 2016 3:26 am
It has been an interesting journey – trying to get my STM32 to talk to my J-Link. After endless days of “Googling” and segments of this forum – I’m no wiser. By way of background;-
Hardware:

  • HP EliteBook 8440P
    • Architecture: x86_64
    • CPU op-mode(s): 32-bit, 64-bit
    • Byte Order: Little Endian
    • CPU(s): 4
    • On-line CPU(s) list: 0-3
    • Thread(s) per core: 2
    • Core(s) per socket: 2
    • Socket(s): 1
    • NUMA node(s) 1
    • Vendor ID: GenuineIntel
    • CPU family: 6
    • Model: 37
    • Stepping: 2
    • CPU MHz: 2534.000
    • BogoMIPS: 5054.20
    • Virtualisation: VT-x
    • L1d cache: 32K
    • L1i cache: 32K
    • L2 cache: 256K
    • L3 cache: 3072K
    • NUMA node0 CPU(s): 0-3

    STM32F103:

Software:

  • OS: LinuxMint 17.3
  • Arduino Ver 1.6.10
    • STM32 Lib (ex GitHub)
    • Arduino_STM32-master.zip

One consolation I do have is that, when I produce a list of USBs;-

  • $ lsusb
    Bus 002 Device 003: ID 046d:c52f Logitech, Inc. Unifying Receiver
    Bus 002 Device 008: ID 12f7:1d23 Memorex Products, Inc.
    Bus 002 Device 006: ID 1366:0101 SEGGER J-Link PLUS
    Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
    Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 005: ID 04f2:b15e Chicony Electronics Co., Ltd
    Bus 001 Device 004: ID 138a:0007 Validity Sensors, Inc. VFS451 Fingerprint Reader
    Bus 001 Device 003: ID 03f0:231d Hewlett-Packard Broadcom 2070 Bluetooth Combo
    Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    $

So, why is it when the device can be seen using lsusb, Arduino can’t see it?

So, back to my problem. Although I have been able to load the STM32 libraries but I cannot get my J-Link talk to my mini-STM32 board through the Arduino IDE?

There are many ways to skin a cat. I assume that there are many ways to program the SMT32 using an Arduino IDE environment on a LinuxMint platform.

Just like skinning a cat (the easiest way is to ensure the cat is dead). The analogy to the cat is to suggest that there must be preparatory activities that must be done to ensure success.

Surely there is a script, or documented sequence of tasks to be performed to enable me to program the STM32 on a Linux platform.

One last item: When I compile something like the ubiquitous “blink” sketch, I get the following message;-

  • Failed to open serial device.
    dfu-util: Invalid DFU suffix signature
    dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
    dfu-util: No DFU capable USB device available
    An error occurred while uploading the sketch

    dfu-util 0.8

    Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
    Copyright 2010-2014 Tormod Volden and Stefan Schmidt
    This program is Free Software and has ABSOLUTELY NO WARRANTY
    Please report bugs to [email protected]

    Deducing device DFU version from functional descriptor length

Could it be a simple matter of an incorrect dfu-util setup? If so, how does one set it up within Linux?

Are there any members who have achieved this goal. Most references I have found are based on a Windows or Mac platforms.

Anyone having the same challenges I am?

Regards,
Nick


RogerClark
Fri Oct 07, 2016 6:41 am
Nick

I use a JLink clone with another Arduino core (for the nRF51822), but its on Windows

Does your JLink have a command line to upload the file ? I presume so

In theory you could just port my windows code here

https://github.com/rogerclarkmelbourne/ … upload.bat

to make jlink_upload script file and put it in the tools linux folder.

(basically all it does is write a temporary command file, with jlink commands in it (in the temporary build folder that the Arduino IDE creates), and then calls the JLink command line, passing in the path to the script etc

You’d also need to make 2 more changes

Firstly, change platform.txt include JLInk upload

See the bottom of this file https://github.com/rogerclarkmelbourne/ … atform.txt

# jlink upload
tools.jlink_upload.cmd=jlink_upload
tools.jlink_upload.cmd.windows=jlink_upload.bat
tools.jlink_upload.path.windows={runtime.hardware.path}/tools/win
tools.jlink_upload.path.macosx={runtime.hardware.path}/tools/macosx
tools.jlink_upload.path.linux={runtime.hardware.path}/tools/linux

tools.jlink_upload.upload.params.verbose=-d
tools.jlink_upload.upload.params.quiet=
tools.jlink_upload.upload.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.bin"


mrburnette
Fri Oct 07, 2016 1:28 pm
I’m running Linux 17.3 on an old Acer without issues. Did you give yourself rights to the serial port?
I am not using Jlink, however … just serial even on the blue pill.

Ray


RogerClark
Fri Oct 07, 2016 7:58 pm
I also crossed my mind, to simply use the JLink to flash the bootloader onto that board, then you no longer need to use JLink.

i.e as you are simply using it to upload, the bootloader performs the same task.


VK3TY
Sat Oct 08, 2016 11:36 am
Roger,

Thanks for the reply. Like me, I see you rely on clones ;) .

Sadly, Windows .bat files don’t work on Linux. Not sure that I can simply “So. All you need to do is port my windows.bat file

The problems that are overcome through the use of the batch-file (as I see it);-

  • Overcoming incorrect slashes (Windows idiosyncrasy).
    Creating a Commander script file from the Arduino for the tmp .bin file (Not sure of the need for the Commander script – expressed in my own ignorance).

You have made a specific reference to using the generic nRF51822 as the device type and not STM32F103C8 as a device type. How would this tie-in with the Arduino IDE?

I have managed to download a program form the Segger site that is setup for a Linux platform. JLINKEXE appears to have many features/options.

The programs I have installed for Segger are;-

  • ~/jlink/usr/bin $ ll
    total 8
    drwxr-xr-x 2 nick nick 4096 Oct 7 23:10 ./
    drwxr-xr-x 3 nick nick 4096 Oct 7 07:13 ../
    lrwxrwxrwx 1 nick nick 36 Oct 7 07:13 JFlashSPI_CL -> /opt/SEGGER/JLink_V610d/JFlashSPI_CL*
    lrwxrwxrwx 1 nick nick 32 Oct 7 07:13 JLinkExe -> /opt/SEGGER/JLink_V610d/JLinkExe*
    lrwxrwxrwx 1 nick nick 38 Oct 7 07:13 JLinkGDBServer -> /opt/SEGGER/JLink_V610d/JLinkGDBServer*
    lrwxrwxrwx 1 nick nick 43 Oct 7 07:13 JLinkLicenseManager -> /opt/SEGGER/JLink_V610d/JLinkLicenseManager*
    lrwxrwxrwx 1 nick nick 41 Oct 7 07:13 JLinkRegistration -> /opt/SEGGER/JLink_V610d/JLinkRegistration*
    lrwxrwxrwx 1 nick nick 41 Oct 7 07:13 JLinkRemoteServer -> /opt/SEGGER/JLink_V610d/JLinkRemoteServer*
    lrwxrwxrwx 1 nick nick 38 Oct 7 07:13 JLinkRTTClient -> /opt/SEGGER/JLink_V610d/JLinkRTTClient*
    lrwxrwxrwx 1 nick nick 38 Oct 7 07:13 JLinkRTTLogger -> /opt/SEGGER/JLink_V610d/JLinkRTTLogger*
    lrwxrwxrwx 1 nick nick 34 Oct 7 07:13 JLinkSTM32 -> /opt/SEGGER/JLink_V610d/JLinkSTM32*
    lrwxrwxrwx 1 nick nick 38 Oct 7 07:13 JLinkSWOViewer -> /opt/SEGGER/JLink_V610d/JLinkSWOViewer*
    ~/jlink/usr/bin $

The most useful program (until I can find more information) is JLinkExe. This provides me with a variety of commands which will allow me to load the files suggested.

I’m currently trying to find a definitive article in the (correct) use of JLINKEXE.

I might add that, at this stage I have not found

Regards,
Nick


VK3TY
Sat Oct 08, 2016 12:13 pm
Ray,

Thanks for the quick response.
mrburnette wrote:I’m running Linux 17.3 on an old Acer without issues. Did you give yourself rights to the serial port?
I am not using Jlink, however … just serial even on the blue pill.
Ray


VK3TY
Sat Oct 08, 2016 12:17 pm
Roger,
RogerClark wrote:I also crossed my mind, to simply use the JLink to flash the bootloader onto that board, then you no longer need to use JLink.

i.e as you are simply using it to upload, the bootloader performs the same task.


mrburnette
Sat Oct 08, 2016 1:58 pm
in this post
viewtopic.php?f=45&t=1441
I am using a very similar board to your Blue Pill board.
I am using a Chinese $1 clone USB serial adapter with Vout set to 3.3V

A9 and A10 are the serial pins. Then just follow the WiKi instructions… https://github.com/rogerclarkmelbourne/ … /Uploading

I do seem to remember that if you ever load the bootloader, reverting to this proprietary serial method does not work… but I’m fuzzy on details here… something about the bootloader leaving the pins configured as analog.

Ray


RogerClark
Sat Oct 08, 2016 7:58 pm
Ray

I dont know what you mean about not going back to Serial.

The only thing I can guess at, is that on the Maple mini, boot1 is floating ( this is a design mistake) as it sometimes prevents Serial uploads working.

If you pull boot1 low, and use the button to pull Boot0 high, you will still be able to upload via serial.

Upload via SDW after running a bootloader sketch, may be what you are thinking up.
The SWD pins are reassigned as GPIO, so either you need to pull Boot0 high, or you need to use connect under reset, to gain access again via SWD.

But you never totally loose the ability to upload via SWD or internal Serial bootloader


RogerClark
Sat Oct 08, 2016 7:59 pm
Nick

check out my youtube videos

I did one on upload via serial, and there are other people who did better ones, explaining how to flash the bootloader using usb to serial


VK3TY
Sun Oct 16, 2016 1:28 pm
Folks,

  • I think we can close this one as I have moved it to “General”. Not entirely “solved” but moved into a a more descriptive subject.

    Most of my knowledge (so far) has been gained through perseverance and a pretty steep learning curve in understanding the nuances of using a J-Link in a Linux environment.

Regards,
Nick


VK3TY
Wed Nov 02, 2016 1:21 am
SOLVED

Folks,

  • Roger has posted a new Arduino_STM32-master on GitHub – I suggest you download the latest and replace all files.

    I can confirm that it has been test and works.

Regards,
Nick


VK3TY
Wed Nov 02, 2016 1:26 am
:D :D :D :D :D . . . to say subject has been resolved. Thank you to all that read and responded.

Leave a Reply

Your email address will not be published. Required fields are marked *