STM32 BlinkLed setup fails on svd2swift generated files

I spend some time to compile blinkLed example on STM32F7.. and I have hit a wall at files generated by svd2swift:

 4 | 
 5 | /// General-purpose I/Os
 6 | public let gpioa = GPIOA(unsafeAddress: 0x40020000)
   |            |- error: let 'gpioa' is not concurrency-safe because non-'Sendable' type 'GPIOA' may have shared mutable state [#MutableGlobalVariable]
   |            `- note: disable concurrency-safety checks if accesses are protected by an external synchronization mechanism
 7 | 
 8 | /// General-purpose I/Os

 5 | /// General-purpose I/Os
   6 | @RegisterBlock
   7 | public struct GPIOA {
     |               `- note: consider making struct 'GPIOA' conform to the 'Sendable' protocol
   8 |     /// GPIO port mode register
   9 |     @RegisterBlock(offset: 0x0)
......

Every constant defined in generated files throws those errors, so there is a lot of them, all the same.

swift --version
Apple Swift version 6.2-dev (LLVM d266fd9f80a7945, Swift 665515c781999a8)
Target: arm64-apple-macosx15.0
Build config: +assertions

Is some way to disable concurrency-safety checks for terminal or another way to make step forward?

Right now the generated code does not support Swift 6 language mode / strict concurrency, though it really should.

You can avoid this by switching back to the Swift 5 language mode. See: swiftLanguageModes | Apple Developer Documentation

I tried many toolchains installed by Swiftly — and It does not work too. Every version below 6.1.2 throws. And it's out of my brain, where to search possible solutions.

swift build --configuration release --triple armv7em-none-none-eabi --toolset toolset.json
Building for production...
<unknown>:0: error: unknown argument: '-mergeable-symbols'

or

% swift build --configuration release --triple armv7em-none-none-eabi --toolset toolset.json
error: Unknown option '--toolset'
Usage: swift build <options>
  See 'build -help' for more information.

I did not found in swiftly documentation how to get 5.x.x development snapshot? Hard stuff!

You dont need to use a Swift 5 compiler instead you need to set the Package.swift to use the Swift 5 language mode.

See: swift-embedded-examples/stm32-lcd-logo/Package.swift at 622fd0a41dc883d40c1d101a73f678b1fe31b0d5 · swiftlang/swift-embedded-examples · GitHub for an example.

There is something wrong, with me or my setup. Some time ago I successfully compiled code for ESP32, I tried to play with STM32 with Documentation, after upgrade to newest tools everything stoped. Simplest example blinkLed from Apple examples could not be compiled because... surprise!

unable to load standard library for target 'armv7em-apple-none-macho'

I feel lost. To many mistakes, blind spots, nothing learned just frustration.

Installed by swiftly:

% swiftly list
Installed release toolchains
----------------------------
Swift 6.1.2 (default)
Swift 6.1.0
Swift 6.0.3
Swift 5.10.1

Installed snapshot toolchains
-----------------------------
main-snapshot-2025-06-12 (in use)
main-snapshot-2025-06-01
main-snapshot-2025-03-25

Swift version:

 % swift --version
Apple Swift version 6.2-dev (LLVM d266fd9f80a7945, Swift 665515c781999a8)
Target: arm64-apple-macosx15.0
Build config: +assertions

Where I have to dig?

On another hand: when I tried to compile another example, STM32-lcd-logo, much more happened (few minutes) ended with message:

...
Build complete! (227.16s)
demangling linker map...
cat /Users/lukasz/Documents/STM32/swift-embedded-examples/stm32-lcd-logo/.build/armv7em-apple-none-macho/release/Application.mangled.map \
		| c++filt | swift demangle > /Users/lukasz/Documents/STM32/swift-embedded-examples/stm32-lcd-logo/.build/armv7em-apple-none-macho/release/Application.map
disassembling...
otool \
		-arch armv7em -v -V -d -t \
		/Users/lukasz/Documents/STM32/swift-embedded-examples/stm32-lcd-logo/.build/armv7em-apple-none-macho/release/Application \
		| c++filt | swift demangle > /Users/lukasz/Documents/STM32/swift-embedded-examples/stm32-lcd-logo/.build/armv7em-apple-none-macho/release/Application.disassembly
extracting binary...
/Users/lukasz/Documents/STM32/swift-embedded-examples/Tools/macho2bin.py \
		/Users/lukasz/Documents/STM32/swift-embedded-examples/stm32-lcd-logo/.build/armv7em-apple-none-macho/release/Application \
		/Users/lukasz/Documents/STM32/swift-embedded-examples/stm32-lcd-logo/.build/armv7em-apple-none-macho/release/Application.bin \
		--base-address 0x00200000 \
		--segments '__TEXT,__DATA,__VECTORS'
env: uv: No such file or directory
make: *** [build] Error 127

uv? What's uv? Why uv?

I feel too stupid to play this game :slight_smile:

@kubamracek might be able to help here as he's the original author of that guide.

A couple notes tho:

This error

Implies whatever version of swift was run did not include the embedded standard library. This can happen if you don't have a nightly installed (though based on your swiftly output you do) or if your shell environment is not configured correctly. e.g. the swift installed by swiftly isn't the first version found on your PATH.

I have had this issue running in the vscode terminal for example.


UV is a python venv manager written in rust and is used to handle the dependencies needed for macho2bin.py and similar scripts in the repo.

There are installation instructions in the repo root, but the documentation should also be updated.

Here's an install guide: Installation | uv

1 Like

I feel stupid like a pack of nails without heads (foreign idiom).
Trying to build stm32-blink I have an error:

unable to load standard library for target 'armv7em-apple-none-macho'

but there is no problem if I try to compile stm32-lcd-logo. Script ends with

Writing segment __VECTORS size 456 (0x1c8) at vmaddr 0x00200000
Writing gap of size 56 (0x38) at vmaddr 0x002001c8
Writing segment __TEXT size 12768 (0x31e0) at vmaddr 0x00200200
Writing segment __DATA size 4 (0x4) at vmaddr 0x002033e0
Produced /Users/lukasz/Documents/STM32/swift-embedded-examples/stm32-lcd-logo/.build/armv7em-apple-none-macho/release/Application.bin with 13284 bytes

what looks promising.
But.

% st-flash --reset write .build/lcd-logo.bin 0x08000000
st-flash 1.8.0
2025-06-22T14:07:14 INFO common.c: STM32F74x_F75x: 320 KiB SRAM, 1024 KiB flash in at least 2 KiB pages.
open(.build/lcd-logo.bin) == -1
2025-06-22T14:07:14 ERROR common_flash.c: map_file() == -1
stlink_fwrite_flash() == -1
lukasz@ukaszs-Mac-Studio stm32-lcd-logo % st-flash --reset write .build/lcd-logo.bin 0x08000000
st-flash 1.8.0
2025-06-22T14:07:57 INFO common.c: STM32F74x_F75x: 320 KiB SRAM, 1024 KiB flash in at least 2 KiB pages.
open(.build/lcd-logo.bin) == -1
2025-06-22T14:07:57 ERROR common_flash.c: map_file() == -1
stlink_fwrite_flash() == -1

I tried to use STM32CubeProgrammer to upload Application.bin to board via USB ST-Link, but it did not work too:
In debug tab I found:

CPU Halted
Hard Fault detected
- Fault that is escalated to a hard fault (FORCED)
- Faulty instruction address [ 0x4000000B ]
Usage Faults:
- Attempt to enter an invalid set state (INVSTATE)

If I upload previously saved original firmware.bin everything works.
What a wonderful adventure!
...
Next morning uploading Application.bin via STM32Cube worked. No problem. Strange. 0_0

uv works!