diff --git a/core/SConscript.firmware b/core/SConscript.firmware index 6336329b84..9fb27f4b69 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -590,7 +590,11 @@ env.Ignore(hdr_moduledefs, qstr_generated) if FROZEN: SOURCE_PY_DIR = 'src/' - SOURCE_PY = Glob(SOURCE_PY_DIR + '*.py') + SOURCE_PY = Glob(SOURCE_PY_DIR + '*.py', + exclude=[ + SOURCE_PY_DIR + 'ble.py', + ] if "ble" not in FEATURES_AVAILABLE else [] + ) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py', exclude=[ SOURCE_PY_DIR + 'trezor/sdcard.py', diff --git a/core/SConscript.unix b/core/SConscript.unix index fe26db8663..7ee1f0316f 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -645,7 +645,11 @@ env.Ignore(micropy_defines, qstr_generated) if FROZEN: SOURCE_PY_DIR = 'src/' - SOURCE_PY = Glob(SOURCE_PY_DIR + '*.py') + SOURCE_PY = Glob(SOURCE_PY_DIR + '*.py', + exclude=[ + SOURCE_PY_DIR + 'ble.py', + ] if "ble" not in FEATURES_AVAILABLE else [] + ) SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/*.py', exclude=[ SOURCE_PY_DIR + 'trezor/sdcard.py', diff --git a/core/src/ble.py b/core/src/ble.py new file mode 100644 index 0000000000..3d48729124 --- /dev/null +++ b/core/src/ble.py @@ -0,0 +1,12 @@ +import storage.device +import trezorble as ble +from trezor import log + +try: + ble.start_comm() + + # allow connections from bonded peers if any + if ble.peer_count() > 0: + ble.start_advertising(True, storage.device.get_label()) +except Exception as e: + log.exception(__name__, e) diff --git a/core/src/main.py b/core/src/main.py index 5c33ef32e6..727d32d8ca 100644 --- a/core/src/main.py +++ b/core/src/main.py @@ -49,14 +49,9 @@ usb.bus.open(storage.device.get_device_id()) # enable BLE, allow connections if utils.USE_BLE: - import trezorble as ble - ble.start_comm() - - # allow connections from bonded peers if any - if ble.peer_count() > 0: - ble.start_advertising(True, storage.device.get_label()) - - del ble + with utils.unimport(): + import ble # noqa: F401 + del ble # run the endless loop