Loading...
 
Skip to main content

System Workbench for STM32


Programming in pure assembler

Hi all, I want to port my existing toolchain over to the STM32 platform (bluepill board with F103C8) and need to be able to code in pure assembler. I believe that the easiest way to do that is using Eclipse with the OpenSTM32 plugins. However, I do not want to use the C compiler, because I need to implement a virtual machine to support my own compiler. So far I have set up the eclipse environment and can assemble *.asm files already, but the build process keeps trying to link crt0.o and libc.a, which results in linker errors. How can I modify the build process to avoid linking any C related libraries?

(edit: added linker output)

Invoking: MCU GCC Linker
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -Wl,-Map=output.map -Wl,----gc-sections -lm -o "mycode.elf" @"objects.list"
c:/users/me/.p2/pool/plugins/fr.ac6.mcu.externaltools.arm-none.win32_1.13.2.201703061525/tools/compiler/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7-m\libc.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x16): undefined reference to `_exit'
c:/users/me/.p2/pool/plugins/fr.ac6.mcu.externaltools.arm-none.win32_1.13.2.201703061525/tools/compiler/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7-m/crt0.o: In function `_start':
(.text+0x4a): undefined reference to `main'
collect2.exe: error: ld returned 1 exit status
make: *** mycode.elf Error 1

France

Hi,

For this you should pass options to the linker (in the linker options miscellaneous tab):

  • -nostdlib will avoid linking standard libraries and startup files; it combines two options:
    • -nostartfiles which avoids the startup files
    • -nodefaultlibs which bypasses the standard libraries (including the C library)
  • However, if ever you link compiled C code, you may need to explicitly add the following option:
    • -lgcc to link the libgcc.a compiler helper library


Note that not using the default startup files mean you will have to replace them by suitable code and, at least, provide the vector table. Note you may have also to edit or replace the link editor script file (the .ld file placed at the root of your project).

Anyway, as you will be tweaking the compiler toolchain, I advise you look at the GCC, AS and LD documentation (there are links to these in the "Documentation " section fo the wb site).

Hope this helps,

Bernard (Ac6)


Thank you so much Bernard for your quick reply. This did the trick. The linker ignores the libraries I do not need now. I had to add a ".global _start" to my source and then it built as expected. No worries about the vector tables, I am used to that kind of stuff from the last microcontroller I ported my virtual machine for. Next step is to try the debugger.

Hello, I need a bit of help again please. I have successfully assembled and linked my first code for the bluepill board. I have flashed the latest software into ST-LINK V2 adapter. Then I connected the 3.3V, GND, SWDIO, SWCLK and RESET pins from the ST_LINK to the board. The ST-LINK can program the chip and I can view the memory. The code is started and I can single-step through it. However, when I try to program the board using the Eclipse Project context menu->Target->Program chip I get the following messages:

Open On-Chip Debugger 0.10.0-dev-00275-gd486ac2-dirty (2017-03-06-15:22)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
srst_only separate srst_nogate srst_open_drain connect_assert_srst
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v27 API v2 SWIM v6 VID 0x0483 PID 0x3748
Info : vid/pid are not identical: 0x0483/0x374B 0x0483/0x3748
Info : using stlink api v2
Info : Target voltage: 3.256233
Info : STM32F103C8Tx.cpu: hardware has 6 breakpoints, 4 watchpoints
Error: timed out while waiting for target halted
TARGET: STM32F103C8Tx.cpu - Not halted
in procedure 'program'
in procedure 'reset' called at file "embedded:startup.tcl", line 478
in procedure 'ocd_bouncer'

    • Unable to reset target **

shutdown command invoked

Do I need to worry about the message: vid/pid are not identical?
How can I program and debug the chip?

Hi,

The vid/pid message is only a warning.
It means you have selected a STLink v2-1 as debug interface instead of a STLINK V2 but that's not an issue.

In the "debug configurations", debugger tab, which mode do you have ?
Did you choose an st board like a nucleo F103 or other F1 st board ?
Or you're using "use local script" and you have a custom board ?
Or you're using the "Manual spec" mode ?

I don't see the command that is issued to openocd when you try to Program the chip.
When using menu Target => "Program chip" , you should see the first line with the command text with all arguments given to openocd.exe.

I thought these "blue pills" boards didn't have a Reset line connected ?
Are you sure it is a Reset line output of stlink for the STM32 reset pin ?
If you had no issue debugging, it means that it's surely a good reset line.

You can try to use the "Manual Spec" mode (choose stlink V2 and swd) and add just above in openocd options :-c "reset_config none".
But i am not sure it will be used in menu Target => "Program chip".

Rgds,
Laurent


Hi Laurent,

In the "debug configurations", debugger tab, which mode do you have ? manual spec, device: ST-LinkV2, interface: SWD
Did you choose an st board like a nucleo F103 or other F1 st board ? no other board to try at hand
Or you're using "use local script" and you have a custom board ? no local script
Or you're using the "Manual spec" mode ? yes

I tried this with and without the RESET line connected. Checked the connection on the board and there is connectivity between the board external header pin4 and pin7 NRST of the chip.

I added the command line option you suggested. Programming doesn't work yet:
-------
Programing project Ninja32 on chip ****
(a few lines deleted)
Error: libusb_open() failed with LIBUSB_ERROR_ACCESS
Error: open failed (no matching adapter found)
in procedure 'program'
in procedure 'init' called at file "embedded:startup.tcl", line 473
in procedure 'ocd_bouncer'
-------
Nevertheless, the command line option helped a bit.
The debugger can halt the chip now, but it runs into another issue.
-------
Open On-Chip Debugger 0.10.0-dev-00275-gd486ac2-dirty (2017-03-06-15:22)
(a few lines deleted)
Error: BUG: can't assert SRST
Info : STM32F103C8Tx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'gdb' connection on tcp/3333
Error: TRST/SRST error
STM32F103C8Tx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 00000000 pc: 0x080001ac msp: 0x20004ffc
Info : device id = 0x20036410
Info : flash size = 64kbytes
STM32F103C8Tx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 00000000 pc: 0x080001ac msp: 0x20004ffc
STM32F103C8Tx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 00000000 pc: 0x080001ac msp: 0x20004ffc
-------
...and then after a few seconds a popup with the following message appears:
-------
Error in final launch sequence
Failed to execute MI command:
load C:\\Data\\workspace\\Ninja32\\Debug\\Ninja32.elf
Error message from debugger back end:
Error finishing flash operation
Error finishing flash operation
-------
A second attempt gives me different messages:
-------
Open On-Chip Debugger 0.10.0-dev-00275-gd486ac2-dirty (2017-03-06-15:22)
(a few lines deleted)
Error: BUG: can't assert SRST
Info : STM32F103C8Tx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : accepting 'gdb' connection on tcp/3333
Error: TRST/SRST error
STM32F103C8Tx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
Info : device id = 0x20036410
Info : flash size = 64kbytes
Error: address + size wrapped(0xfffffffe, 0x00000004)
STM32F103C8Tx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
STM32F103C8Tx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
STM32F103C8Tx.cpu: target state: halted
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000003a msp: 0xfffffffc
STM32F103C8Tx.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 00000000 pc: 0x080001ac msp: 0x20004ffc
-------
No popup appears this time.
I can click Suspend and the debug actions (step into/over/return) become selectable.
When clicking on Step Into I get:
-------
Info : halted: PC: 0x0800018c
Info : halted: PC: 0x0800018c
(repeated until I click Suspend again)
Info : halted: PC: 0x0800018c
Info : The target is not running when halt was requested, stopping GDB.
Info : The target is not running when halt was requested, stopping GDB.
Info : The target is not running when halt was requested, stopping GDB.
Info : halted: PC: 0x0800018c
-------
Those two results repeat for all following attempts.
A look into my code shows me that the chip had a Hard Fault (HardFault_Handler() at 0x800018c)
Again, the same code runs fine and can be single-stepped using ST-LINK alone (STSW-LINK007 Version 2.28.18)

Thanks for your help.
- Klaus


After a lot of reading I wonder if the following might help:
Maybe I can avoid the error message "Error finishing flash operation " if I can skip the flash load operation as a workaround?
At least the code loads and runs fine when I use the ST-LINK utility only. However, I cannot find the load step in any of the *.cfg files.
I believe that I can ignore the "Error: address + size wrapped(0xfffffffe, 0x00000004) " message.
Not sure if the "Error: TRST/SRST error" is an issue. Eventually GDB seems to be able to halt the CPU.
Any help is much appreciated.
- Klaus


Hello,

Check the schematic of your appli board, if you can connect the Reset ouput of STLink to the Reset input pin of your STM32F1 device, you don't need to modify the debug config and manual spec like you did is ok.

Just terminate any debug session or you will have error with LIBUSB...that is still connected to the STLink.

Rgds,
Laurent


It works!! 😀 Thanks for your help Laurent and Bernard.
I am in business now, finishing the port to STM32.
Looking forward to explore this exciting new platform.