koendv / STM32duino-Semihosting

Arduino arm semihosting library
7 stars 2 forks source link

Semihosting on STM32 BluePill Chinese clone issues #2

Open Wire7 opened 3 years ago

Wire7 commented 3 years ago

I am trying to get semihosting to work on my bluepill. I followed this thread's guides here step by step but I am getting the following error when running the task "OpenOCD (semihosting output)" and when trying to debug as well.

When debugging, the Consol's output is:

Processing bluepill_f103c8 (platform: ststm32; board: bluepill_f103c8; framework: cmsis)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/bluepill_f103c8.html
PLATFORM: ST STM32 (12.1.1) > BluePill F103C8
HARDWARE: STM32F103C8T6 72MHz, 20KB RAM, 64KB Flash
DEBUG: Current (custom) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES:
 - framework-cmsis 2.50501.200527 (5.5.1)
 - framework-cmsis-stm32f1 4.3.1
 - tool-ldscripts-ststm32 0.1.0
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
Warning! Cannot find a linker script for the required board! An auto-generated script will be used to link firmware!
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in debug mode
Checking size .pio/build/bluepill_f103c8/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   1.6% (used 328 bytes from 20480 bytes)
Flash: [=         ]   6.6% (used 4320 bytes from 65536 bytes)
========================= [SUCCESS] Took 1.76 seconds =========================
Reading symbols from /Users/engmoh/Embedded/PlatformIO_Projects/STM32_Projects/0-SemiHosting_Configurations/.pio/build/bluepill_f103c8/firmware.elf...
done.
PlatformIO Unified Debugger -> http://bit.ly/pio-debug
PlatformIO: debug_tool = custom
PlatformIO: Initializing remote target...
.pioinit:13: Error in sourced command file:
:3333: Operation timed out.

When running the task, Terminal's output is:

> Executing task in folder 0-SemiHosting_Configurations: cd ~/.platformio/packages/tool-openocd && bin/openocd -f scripts/interface/stlink.cfg -f target/stm32f1x.cfg <

xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-12:31)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J37S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 1.436903
Error: target voltage may be too low for reliable debugging
Warn : UNEXPECTED idcode: 0x2ba01477
Error: expected 1 of 1: 0x1ba01477

The terminal process "/bin/zsh '-c', 'cd ~/.platformio/packages/tool-openocd && bin/openocd -f scripts/interface/stlink.cfg -f target/stm32f1x.cfg'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

My platformio.ini

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = cmsis
upload_protocol = stlink

; ============ Enable Arm Semihosting in debugger to show logs =============
extra_scripts = extra_script.py ; Must be located in the main project folder
build_unflags =
    --specs=nosys.specs 
    -lnosys
debug_extra_cmds =
    monitor arm semihosting enable
debug_tool = custom
debug_port = :3333
; ===========================================================================

; Enable Chinese clones STM32 MCUs recognition (Fixing "Warn : UNEXPECTED idcode: 0x2ba01477" Error)
upload_flags = -c set CPUTAPID 0    ;This will allow Originals and Clones to debug 

my Tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "command": "cd ~/.platformio/packages/tool-openocd && bin/openocd -f scripts/interface/stlink.cfg -f target/stm32f1x.cfg",
            "args": [
            ],
            "problemMatcher": [
                "$platformio"
            ],
            "label": "OpenOCD (semihosting output)"
        }
    ]
}

and my main.c

#include <stm32f1xx.h>
#include <stdio.h>

/* semihosting Initializing */
extern void initialise_monitor_handles(void);

int main(void)
{
    initialise_monitor_handles();
    printf("Hello .. Echo .. Echo\n");
}

I think I should use "-c set CPUTAPID 0" somewhere in the tasks.json probably but I don't know were! but what about debugging? why It's not working?

koendv commented 3 years ago

On Mon, 26 Apr 2021 21:28:53 -0700 Wire7 @.***> wrote:

Info : STLINK V2J37S7 (API v2) VID:PID 0483:3748 Info : Target voltage: 1.436903 Error: target voltage may be too low for reliable debugging

For a blue pill target, I'd expect 3.3 volt target voltage. Check and double check connections between stlink and target.

koen