Skip to content

stm32/wb55: Add usb/bluetooth transparent mode to stm32wb55 via native module. #9046

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/library/stm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,14 @@ the second CPU, the RF core.
Execute a HCI command on the SYS channel. The execution is synchronous.

Returns a bytes object with the result of the SYS command.

.. function:: rfcore_ble_hci(command[, response_buf])

Execute a HCI command on the BLE channel. The execution is synchronous.

Takes a *command* byte/bytearray with pre-formatted HCI packet.

Optionally takes a pre-allocated bytearray buffer for the response packet.

Returns response length if *response_buf* is provided, else a bytes object with the
response HCI packet.
83 changes: 83 additions & 0 deletions examples/natmod/stm32wb55_transparent_vcp/LICENCE_ST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
> Originally from https://github.com/STMicroelectronics/STM32CubeWB/blob/83aacadecbd5136ad3194f39e002ff50a5439ad9/Projects/P-NUCLEO-WB55.USBDongle/Applications/LICENSE.md
> Applies only to stm32wb55_local_commands.c

SLA0044 Rev5/February 2018

## Software license agreement

### **ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT**

BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE
OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS
INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES
(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON
BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES
TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT.

Under STMicroelectronics’ intellectual property rights, the redistribution,
reproduction and use in source and binary forms of the software or any part
thereof, with or without modification, are permitted provided that the following
conditions are met:

1. Redistribution of source code (modified or not) must retain any copyright
notice, this list of conditions and the disclaimer set forth below as items 10
and 11.

2. Redistributions in binary form, except as embedded into microcontroller or
microprocessor device manufactured by or for STMicroelectronics or a software
update for such device, must reproduce any copyright notice provided with the
binary code, this list of conditions, and the disclaimer set forth below as
items 10 and 11, in documentation and/or other materials provided with the
distribution.

3. Neither the name of STMicroelectronics nor the names of other contributors to
this software may be used to endorse or promote products derived from this
software or part thereof without specific written permission.

4. This software or any part thereof, including modifications and/or derivative
works of this software, must be used and execute solely and exclusively on or in
combination with a microcontroller or microprocessor device manufactured by or
for STMicroelectronics.

5. No use, reproduction or redistribution of this software partially or totally
may be done in any manner that would subject this software to any Open Source
Terms. “Open Source Terms” shall mean any open source license which requires as
part of distribution of software that the source code of such software is
distributed therewith or otherwise made available, or open source license that
substantially complies with the Open Source definition specified at
www.opensource.org and any other comparable open source license such as for
example GNU General Public License (GPL), Eclipse Public License (EPL), Apache
Software License, BSD license or MIT license.

6. STMicroelectronics has no obligation to provide any maintenance, support or
updates for the software.

7. The software is and will remain the exclusive property of STMicroelectronics
and its licensors. The recipient will not take any action that jeopardizes
STMicroelectronics and its licensors' proprietary rights or acquire any rights
in the software, except the limited rights specified hereunder.

8. The recipient shall comply with all applicable laws and regulations affecting
the use of the software or any part thereof including any applicable export
control law or regulation.

9. Redistribution and use of this software or any part thereof other than as
permitted under this license is void and will automatically terminate your
rights under this license.

10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE
DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL
STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER
EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY
RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY.
34 changes: 34 additions & 0 deletions examples/natmod/stm32wb55_transparent_vcp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This module is intended for use on stm32wb55 microcontrollers
# and shows how a native module can be used to extend hardware
# functionality.

# Note: `pip install pyelftools` is required to build native modules.

# Location of top-level MicroPython directory
MPY_DIR = ../../..

# Name of module
MOD = rfcore_transparent

# Architecture to build for (x86, x64, armv7m, xtensa, xtensawin)
ARCH = armv7m

# Source files (.c or .py)
SRC = \
stm32wb55_transparent.c \
stm32wb55_local_commands.c \
rfcore_transparent.py

MCU_SERIES = wb
CMSIS_MCU = STM32WB55xx

CFLAGS += -Os
CFLAGS += -D$(CMSIS_MCU) -DUSE_FULL_LL_DRIVER $(CFLAGS_MCU_$(MCU_SERIES))

CFLAGS += -I$(MPY_DIR)/ports/stm32
CFLAGS += -I$(MPY_DIR)/ports/stm32/boards/NUCLEO_WB55
CFLAGS += -I$(MPY_DIR)/lib/cmsis/inc
CFLAGS += -I$(MPY_DIR)/lib/stm32lib/STM32WBxx_HAL_Driver/Inc
CFLAGS += -I$(MPY_DIR)/lib/stm32lib/CMSIS/STM32WBxx/Include

include $(MPY_DIR)/py/dynruntime.mk
50 changes: 50 additions & 0 deletions examples/natmod/stm32wb55_transparent_vcp/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# STM32WB55 BLE HCI Transparent Mode

This module allows the usage of a stm32wb55 board (eg. nucleo or dongle) as a USB/UART Bluetooth HCI Dongle.

This allows it to be used to provide bluetooth functionality with the unix micropython port.

It also has full support for use with STM32CubeMonitor-Rf app.

The native module can be compiled and deployed with:

```
cd examples/natmod/stm32wb55_transparent_vcp
make
mpremote cp rfcore_transparent.mpy :
```

Minimal usage:

```
import rfcore_transparent
rfcore_transparent.start()
```

By default stdio (repl) will be used / taken over by this
transparent mode.

Example `main.py`

```
import os
from pyb import Pin, LED

sw = Pin("SW3", Pin.IN, Pin.PULL_UP)

def activity(status):
if status:
LED(3).on()
else:
LED(3).off()

if sw.value():
LED(2).on()
import rfcore_transparent

# Disconnect USB VCP from repl to use here
usb = os.dupterm(None, 1) # startup default is usb (repl) on slot 1

rfcore_transparent.start(usb, activity)

```
25 changes: 25 additions & 0 deletions examples/natmod/stm32wb55_transparent_vcp/rfcore_transparent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This will be built into the native mpy module.
# Functions here will be available in the rfcore_transparent module along with
# the native C functions.


def start(stream=None, callback=None):
import sys
import micropython
from bluetooth import BLE

# Ensure rfcore has been started at least once, then turn off bluetooth.
BLE().active(1)
BLE().active(0)

in_stream = out_stream = stream

if not in_stream:
# Disable the ctrl-c interrupt when using repl stream.
micropython.kbd_intr(-1)

in_stream = sys.stdin
out_stream = sys.stdout

# Start transparant mode C function (never exits).
_rfcore_transparent_start(in_stream, out_stream, callback)
Loading