Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
drmpf opened this issue Jan 11, 2022 · 13 comments

Comments

@drmpf
Copy link

drmpf commented Jan 11, 2022

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.

@jeanthom
Copy link
Owner

Have you tried installing libusb using msys2 package manager?

pacman -S mingw-w64-x86_64-libusb

@drmpf
Copy link
Author

drmpf commented Jan 11, 2022

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 drmpf changed the title Package libusb-1.0 Missing <sys/mman.h> on MSYS MinGW x64, Windows 7 (was missing Package libusb-1.0) Jan 11, 2022
@jeanthom
Copy link
Owner

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.

@drmpf
Copy link
Author

drmpf commented Jan 12, 2022

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
Copy link
Author

drmpf commented Jan 13, 2022

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)

@jeanthom
Copy link
Owner

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

@drmpf
Copy link
Author

drmpf commented Jan 13, 2022

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

@jeanthom
Copy link
Owner

jeanthom commented Jan 14, 2022

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?

@drmpf
Copy link
Author

drmpf commented Jan 14, 2022

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.

@jeanthom
Copy link
Owner

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.

@drmpf
Copy link
Author

drmpf commented Jan 14, 2022

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?

@jeanthom
Copy link
Owner

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

@jeanthom
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants