Getting Started with STM32F103 under Linux

Any other STM32 based boards
User avatar
VK3TY
Posts: 16
Joined: Wed Oct 05, 2016 9:45 am
Location: Geelong, Victoria, Australia
Contact:

Getting Started with STM32F103 under Linux

Postby 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 dfu-util@lists.gnumonks.org

    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
Rgds,
Nick - VK3TY

User avatar
RogerClark
Posts: 5465
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Getting Started with STM32F103 under Linux

Postby 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

Code: Select all

# 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"


Then in boards.txt

for the board you have (which is Generic STM32F103C)

Add an entry to the upload menu list for that board

Which would look like this

Code: Select all

genericSTM32F103C.menu.upload_method.JLnkMethod=STLink
genericSTM32F103C.menu.upload_method.JLnkMethod.upload.protocol=jlink
genericSTM32F103C.menu.upload_method.JLnkMethod.upload.tool=jlink_upload
genericSTM32F103C.menu.upload_method.JLnkMethod.build.upload_flags=-DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER



So. All you need to do is port my windows.bat file ;-)

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

Re: Getting Started with STM32F103 under Linux

Postby 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

User avatar
RogerClark
Posts: 5465
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Getting Started with STM32F103 under Linux

Postby 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.

User avatar
VK3TY
Posts: 16
Joined: Wed Oct 05, 2016 9:45 am
Location: Geelong, Victoria, Australia
Contact:

Re: Getting Started with STM32F103 under Linux

Postby 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
Rgds,
Nick - VK3TY

User avatar
VK3TY
Posts: 16
Joined: Wed Oct 05, 2016 9:45 am
Location: Geelong, Victoria, Australia
Contact:

Re: Getting Started with STM32F103 under Linux

Postby 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

To answer your question - "yes". "dialout" as been set.

The Tools>Port is greyed out. This suggests that no serial communications device is attached. That's fine as I want it to see my JLink.

Using STLink, I get the following log;-

Code: Select all

Sketch uses 12,868 bytes (9%) of program storage space. Maximum is 131,072 bytes.
Global variables use 2,800 bytes of dynamic memory.
/home/nick/arduino-1.6.10/hardware/Arduino_STM32/tools/linux/stlink_upload ttyUSB0 {upload.altID} {upload.usbID} /tmp/build642595c231e601b4058c76a98d1ba4d8.tmp/BlinkWithoutDelay.ino.bin
2016-10-08T23:04:05 WARN src/stlink-usb.c: Couldn't find any ST-Link/V2 devices

. . and yet, listing USBs results in;-

Code: Select all

 ~/jlink/usr/bin $ lsusb
Bus 002 Device 028: ID 12f7:1d23 Memorex Products, Inc.
Bus 002 Device 003: ID 046d:c52f Logitech, Inc. Unifying Receiver
Bus 002 Device 027: 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
nick@nick-HP-EliteBook ~/jlink/usr/bin $

be damned as to what is going on and how to overcome it. Obviously (third line down) the J-Link is identified.

I'm totally new to STM32. Although I have coded a lot of Arduino AVR boards, the use of STM32 boards is a new venture into the unknown.

I bought the JLink interface on recommendations I had read and felt it was the the way to go. A friend of mine has also gone the way of STM32 using the same generic STM32F103C board.

Although we are both able to compile the ubiquitous "Blink" program, neither of us has been able to upload. His is via a serial port whilst I have opted to use the JLink module. Despite using similar boards but using different paths to load, neither of us is having much luck.

Regards,
Nick
Rgds,
Nick - VK3TY

User avatar
VK3TY
Posts: 16
Joined: Wed Oct 05, 2016 9:45 am
Location: Geelong, Victoria, Australia
Contact:

Re: Getting Started with STM32F103 under Linux

Postby 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.

If only I could flash the bootloader (which I tried to do). I don't appear to be able to do anything via the JLink :oops:

Regards,
Nick
Rgds,
Nick - VK3TY

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

Re: Getting Started with STM32F103 under Linux

Postby mrburnette » Sat Oct 08, 2016 1:58 pm

in this post
http://stm32duino.com/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/Arduino_STM32/wiki/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

User avatar
RogerClark
Posts: 5465
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Getting Started with STM32F103 under Linux

Postby 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

User avatar
RogerClark
Posts: 5465
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Getting Started with STM32F103 under Linux

Postby 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


Return to “All other boards”

Who is online

Users browsing this forum: acronis, Bing [Bot] and 1 guest