stlink-tool icon indicating copy to clipboard operation
stlink-tool copied to clipboard

Missing <sys/mman.h> on MSYS MinGW x64, Windows 7 (was missing Package libusb-1.0)

Open drmpf opened this issue 4 years ago • 13 comments

I am getting this error in msys2 when trying to compile stlink-tool

Package libusb-1.0 was not found in the pkg-config search path. Perhaps you should add the directory containing `libusb-1.0.pc' to the PKG_CONFIG_PATH environment variable No package 'libusb-1.0' found

git clone https://github.com/jeanthom/stlink-tool did not bring down the libusb folder

pkg-config was installed by pacman msys/pkg-config 0.29.2-4

I downloaded libusb-1.0.23.tar.bz2 from https://github.com/libusb/libusb/releases/tag/v1.0.23 but not clear to me what to do next to resolve this error.

drmpf avatar Jan 11 '22 07:01 drmpf

Have you tried installing libusb using msys2 package manager?

pacman -S mingw-w64-x86_64-libusb

jeanthom avatar Jan 11 '22 08:01 jeanthom

Ok that worked but later I get (after installing mingw-w64-x86_64-gcc) on MSYS MinGW x64 on Windows 7

$ make cc -Wall -Wextra -Werror -I/mingw64/include/libusb-1.0 -o src/main.o -c src/main.c cc -Wall -Wextra -Werror -I/mingw64/include/libusb-1.0 -o src/stlink.o -c src/stlink.c src/stlink.c:27:10: fatal error: sys/mman.h: No such file or directory 27 | #include <sys/mman.h> | ^~~~~~~~~~~~ compilation terminated. make: *** [Makefile:7: src/stlink.o] Error 1

drmpf avatar Jan 11 '22 13:01 drmpf

Oh right, there's no mmap on Windows with msys2.

There was a work of my project which offered better Windows support: https://github.com/sakana280/stlink-tool I never tried it (I don't use Windows nowadays), let met know how it goes.

jeanthom avatar Jan 12 '22 20:01 jeanthom

Thanks for that pointer.

After working, unsuccessfully, on blackmagic and associated builds for the last week “It's not the despair, .... I can take the despair. It's the hope I can't stand." (John Cleese as Brian Stimpson in Clockwise)

drmpf avatar Jan 12 '22 21:01 drmpf

Actually I started on that page and carefully followed the instructions which say git clone https://github.com/jeanthom/stlink-tool hence the problem. replacing that line with git clone https://github.com/sakana280/stlink-tool did the trick.

Then used the stlink-tool to load blackmagic built with make PROBE_HOST=stlink ST_BOOTLOADER=1 stlink-tool blackmagic.bin (as per https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/flashing-and-debugging-nrf5152-with-a-cheap-blackm) but when I plug the blue-pill in (via USB connector) I get USB device not recognized so stumped (again)

drmpf avatar Jan 13 '22 02:01 drmpf

Uh... Bluepill? This is meant to reprogram one of those aluminium ST-Link, not a Blue Pill dev board?

jeanthom avatar Jan 13 '22 13:01 jeanthom

The link above definitely targets the blue pill "Now open ST-Link utility and erase the target chip (blue pill)." Not that I have managed to get that working However circling back around to an ESP8266 based black magic probe I think I have made some progress using https://github.com/J-Wrobel/blackmagic-espidf/tree/master/bins No_OTA on and ESP-01 (1Meg board) (could not get the build for that to run either :-( ) Now if I can just stop the ESP-01 and the target from getting stinking hot . . . . .

drmpf avatar Jan 13 '22 13:01 drmpf

I'm not sure to understand what you're trying to achieve? Are you trying to program a Blue Pill with an ST-Link programmer?

jeanthom avatar Jan 14 '22 11:01 jeanthom

what you're trying to achieve? Some background. Some 3years ago I did a project on very low power BLE based on programing nrf52 modules. Coming back to that again I find the supporting flashing hardware no longer available so I am trying to reproduce it using currently available devices. Modules like the ESP-01, ST-Link V2 and the STM32 "Blue Pill" seem to have stood the test of time and are still cheaply available. So I am trying to use those (or similar ubiquitous boards)

Are you trying to program a Blue Pill with an ST-Link programmer? That's what I thought was happening from the title "Black Magic Probe on STM32F103 "Blue Pill" That link used the ST-Link utility which did not seem to work for me, so I started to look for alternatives and arrived at your github. But thinking about it more, I now see that your tool is actually flashing the ST-Link V2 module itself, so not what is needed for Black Magic Probe on STM32F103 "Blue Pill"

For a black magic programming module, I have now had some success with using the ESP-01 approach.

Removing nRF52 chip protection Currently trying to find a means to remove the chip protection. I can do this with a CMISS-DAP module and OpenOCD, Half way down https://www.forward.com.au/pfod/BLE/LowPower/NanoReplacement/index.html shows how to do it using a CMISS-DAP module and OpenOCD. But have not found a way to do it with gdb and TCP connected blackmagic. If you have any suggestions on how to achieve this, they would be appreciated.

In lieu of those, my problem now is building a CMISS-DAP module. This repository, https://github.com/devanlai/dap42, bins to load onto and ST-Link V2 module to turn it into a CMISS-DAP module. I tried using your stlink-tool to do that stlink-tool -p found the ST-Link V2 and stlink-tool DAP103-stlink.bin seemed to upload but there after still no COM port the CMISS-DAP That repository uses dfu-util utility so I will try that next, unless you have other suggestions.

drmpf avatar Jan 14 '22 14:01 drmpf

But thinking about it more, I now see that your tool is actually flashing the ST-Link V2 module itself, so not what is needed for Black Magic Probe on STM32F103 "Blue Pill" Yep that's exactly what's happening. I'm afraid you have programmed your ST-Link dongle rather than your Blue Pill. You should be able to revert back to its origin firmware using ST's firmware update utility.

Otherwise if you want to use your ST-Link as a Blackmagic probe (or any other firmware basically), you have to use a special utility to exit its DFU mode (it "boots" into DFU by default). You can use https://github.com/stlink-org/stlink for that purpose.

https://github.com/stlink-org/stlink is actually the software you need to use if you want to program your Blue Pill using your ST-Link.

I hope your ST-Link is still in a recoverable state.

jeanthom avatar Jan 14 '22 19:01 jeanthom

No does not seem to be running. I have STM's ST-Link Utility and it can no longer find the ST-Link V2. I note there are SWD points on the ST-Link board.
Do you know how to re-install the ST-Link code?

drmpf avatar Jan 14 '22 22:01 drmpf

You'll need STLinkUpgrade.jar You might have to unplug/replug the ST-Link to get into its DFU bootloader

jeanthom avatar Jan 14 '22 22:01 jeanthom

https://github.com/jeanthom/DirtyJTAG/blob/master/docs/install-stlinkv2-swd.md (SWD pinout for ST-Link v2 dongles)

jeanthom avatar Jan 14 '22 22:01 jeanthom