1

I wrote following Windows batch script that copies given file to Nucleo STM32 virtual drive:

@echo off
for /f %%D in ('%SystemRoot%\System32\wbem\WMIC.exe volume get DriveLetter^, Label ^| find "NODE_F446RE"') do set nucleo_drive=%%D
rem echo Nucleo drive: %nucleo_drive%

IF EXIST %nucleo_drive%\DETAILS.TXT (
  IF EXIST %1 (
    @echo on
    xcopy %1 %nucleo_drive%
    @echo off
    echo Copied %1 on nucleo
  ) ELSE (
    echo Binary %1 not found. Run `mingw32-make` in this directory to compile the project.
  )
) ELSE (
  echo Nucleo drive not found. If needed, edit the `find "NODE_F446RE"` part of this script to refference your nucleo volume name.
)

Nucleo's drive is virtual file drive. When you copy compatible binary on it, it flashes the binary on the actual Nucleo processor and restarts it. I'd like to do the same for Linux using a bash script - particularly Ubuntu, but the more compatible the better.

I can see that the Nucleo appeared on path /media/MY_USERNAME/NODE_F446RE. But I have little experience with linux, is that path standard? Can I rely on copying the file to /media/%username%/NODE_F446RE?

Or is there a better way to get removable device path (say, first volume if it has more volumes, which nucleo won't)?

  • try lsblk -rno label,mountpoint | awk '$1=="NODE_F446RE"{print $2}' – don_crissti Feb 14 '17 at 15:15
  • Is this in the linux subsystem for Windows environment? – Jeff Schaller Feb 14 '17 at 19:47
0

You can rely on this particular removable device appearing as /media/$username/NODE_F446RE on your machine. This isn't universal in the Linux world, but it's the way it is in (recent enough) Ubuntu and most other distributions these days: /media, username, filesystem label.

There are other ways to ensure a fixed path, but you'd only be re-creating the same mechanisms that the default setup already uses (udisks2). And there are ways to find where a particular device is mounted (look for the device under /dev/disks using known characteristics, then use /proc/mounts or df or findmnt to find where that device is mounted), but you don't need them on your machine. So there's no point in investigating other approaches unless you need to make something that works for other people's environments.

  • label and/or UUID. May also depend if a desktop environment is running, etc. – ivanivan Feb 15 '17 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.