SR is "write 0 to clear". Using `.modify()` is wrong since it will accidentally
clear interrupts that happened between the read and write.
Correct way is to write all ones except zero in the bit we want to clear. It's also faster.
If we attempt to read the OsTimer prior to it being initialized, some
kind of fault will occur.
https://github.com/embassy-rs/embassy/pull/5179 introduced a regression by
enabling the `defmt-timestamp-uptime` feature, which caused prints in the
SPLL setup to get the timestamp, causing a crash.
As a mitigation, we just return a time of zero until the OsTimer has actually
been initialized.
This commit implements Phase 1 of the BLE stack for STM32WBA, providing basic BLE peripheral functionality with advertising support.
- Complete HCI command interface with direct C function calls
- Command implementations: reset, read version, set event masks, BD address
- LE controller commands: advertising parameters, data, enable/disable
- Event parsing with support for CommandComplete, CommandStatus, ConnectionComplete, etc.
- Event channel for async event delivery
- Status code mapping and error handling
- Advertiser implementation with configurable parameters
- Advertising data builder with AD type formatting
- Support for flags, device name, and service UUIDs
- Scan response data support
- Start/stop advertising control
- Basic GATT server using ST's C implementation
- Service and characteristic creation
- Support for 16-bit and 128-bit UUIDs
- Characteristic properties: READ, WRITE, NOTIFY
- Characteristic value updates
- Event mask configuration
- High-level Ble struct with initialization
- Automatic controller reset and configuration
- Version info reading and validation
- Feature detection (buffer sizes, supported features)
- Integration with existing link layer and platform code
- Added BLEPLAT_Init() and BLEPLAT_RngGet() for BLE stack requirements
- RNG integration for random number generation
- Proper integration with existing hardware abstraction
- Added Cargo features for BLE stack library selection (basic, basic_plus, full, etc.)
- Added link layer library features (ble-basic, ble-full, peripheral-only, etc.)
- Fixed function name mismatches using #[link_name] attributes (uppercase C symbols)
- Proper unsafe extern block declarations
- Manual defmt::Format implementations for types with heapless::Vec
- Proper pointer type casting for array pointers
- Fixed all HCI function signatures to match C library
- Custom BleError enum with HCI status code mapping
- Result-based API throughout
- Proper validation of parameters (advertising data length, etc.)
Added :
- Complete BLE peripheral example
- Initializes BLE controller
- Creates GATT service with characteristics
- Starts advertising as "Embassy-WBA"
- Ready for testing with BLE scanner apps
- Added BLE stack library features
- Added link layer library features for WBA5x chips
- Enabled ble-stack-basic and linklayer-ble-basic features
- Changed default to BLE-only (removed MAC to avoid conflicts)
Successfully builds for thumbv8m.main-none-eabihf target.
Binary size: ~4.6MB (with debug info).
Unlike WB55 which uses IPCC for dual-core communication, WBA is single-core and uses direct C function calls to the BLE stack. This simplifies the implementation but requires careful linking of the ST BLE stack libraries.
- Full GATT server implementation
- Connection management
- BLE Central role (scanner, initiator)
- Security Manager (pairing/bonding)
- L2CAP connection-oriented channels
- Extended advertising (BLE 5.0+)
Implements Phase 1 of the plan outlined in feat/wpan-continued-work branch.
Estimated completion: 40% of full BLE stack.