@@ -135,7 +135,8 @@ extern const struct device __device_dts_ord_0;
135135#define CONFIG_NET_BUF_ALIGNMENT 0
136136#define CONFIG_NET_BUF_WARN_ALLOC_INTERVAL 0
137137#define CONFIG_NET_BUF_LOG_LEVEL 0
138- #define CONFIG_NET_BUF_POOL_USAGE 0
138+ // CONFIG_NET_BUF_POOL_USAGE must be undefined, not 0, because Zephyr checks with #if defined()
139+ #undef CONFIG_NET_BUF_POOL_USAGE
139140
140141// =============================================================================
141142// PART 2: Macro Conflict Prevention
@@ -413,9 +414,10 @@ extern const struct device __device_dts_ord_0;
413414#define CONFIG_BT_PASSKEY_MAX 999999
414415#define CONFIG_BT_SMP_MIN_ENC_KEY_SIZE 7 // Minimum encryption key size (7-16 bytes)
415416#define BT_SMP_MIN_ENC_KEY_SIZE CONFIG_BT_SMP_MIN_ENC_KEY_SIZE
416- #define CONFIG_BT_PRIVACY 1
417- #define CONFIG_BT_RPA 1
417+ #define CONFIG_BT_PRIVACY 0 // Disabled to fix scanning EPERM error
418+ #define CONFIG_BT_RPA 0 // Disabled to fix scanning EPERM error
418419#define CONFIG_BT_CTLR_PRIVACY 0 // No controller privacy (host-only)
420+ #define CONFIG_BT_SCAN_WITH_IDENTITY 1 // Use identity address for scanning instead of random address
419421
420422// --- L2CAP ---
421423#define CONFIG_BT_L2CAP_TX_BUF_COUNT 4
@@ -532,8 +534,9 @@ extern const struct device __device_dts_ord_0;
532534
533535// --- RX Work Queue Configuration ---
534536// Use system work queue for receiving BLE events
537+ // CONFIG_BT_RECV_WORKQ_BT must be undefined, not 0, because Zephyr checks with #if defined()
535538#define CONFIG_BT_RECV_WORKQ_SYS 1
536- #define CONFIG_BT_RECV_WORKQ_BT 0
539+ #undef CONFIG_BT_RECV_WORKQ_BT
537540
538541// RX thread configuration (not used in MicroPython, but needed for compilation)
539542#define CONFIG_BT_RX_STACK_SIZE 1024
@@ -581,16 +584,17 @@ extern const struct device __device_dts_ord_0;
581584#ifdef NDEBUG
582585#define CONFIG_ASSERT 0
583586#else
584- #define CONFIG_ASSERT 1
587+ #define CONFIG_ASSERT 1 // Re-enable to capture assertion location
585588#endif
589+ #define CONFIG_ASSERT_LEVEL 2 // Maximum verbosity
586590
587591// Bluetooth-specific assert macros (from subsys/bluetooth/common/assert.h)
588- // These are defined here to ensure they're always available when BLE code is compiled
589- #define CONFIG_BT_ASSERT 0 // Use simple __ASSERT fallback, not verbose BT_ASSERT
590- #define CONFIG_BT_ASSERT_VERBOSE 0
591- #define CONFIG_BT_ASSERT_PANIC 0
592+ // These must be undefined (not 0) because Zephyr checks with #if defined()
593+ #undef CONFIG_BT_ASSERT // Use simple __ASSERT fallback, not verbose BT_ASSERT
594+ #undef CONFIG_BT_ASSERT_VERBOSE
595+ #undef CONFIG_BT_ASSERT_PANIC
592596
593- // When CONFIG_BT_ASSERT=0 , BT_ASSERT falls back to __ASSERT macros (defined in kernel.h)
597+ // When CONFIG_BT_ASSERT is undefined , BT_ASSERT falls back to __ASSERT macros (defined in kernel.h)
594598#ifndef BT_ASSERT
595599#define BT_ASSERT (cond ) __ASSERT_NO_MSG(cond)
596600#endif
@@ -748,4 +752,43 @@ int lll_csrand_get(void *buf, size_t len); // Controller crypto stub
748752// (bt_buf_get_evt, bt_buf_get_rx, bt_buf_get_tx, bt_buf_get_type) are defined
749753// in zephyr/bluetooth/buf.h. Include that header in files that need them.
750754
755+ // ===== Endian Conversion Macros =====
756+ // Required for HCI parameter encoding in scan.c and other Zephyr BLE host code
757+ #include <stdint.h>
758+
759+ // Byte swap functions
760+ static inline uint16_t __bswap_16 (uint16_t x ) {
761+ return (uint16_t )((x << 8 ) | (x >> 8 ));
762+ }
763+
764+ static inline uint32_t __bswap_32 (uint32_t x ) {
765+ return ((x << 24 ) & 0xFF000000 ) |
766+ ((x << 8 ) & 0x00FF0000 ) |
767+ ((x >> 8 ) & 0x0000FF00 ) |
768+ ((x >> 24 ) & 0x000000FF );
769+ }
770+
771+ // ARM Cortex-M is little-endian, so CPU-to-LE is a no-op
772+ #define __LITTLE_ENDIAN__
773+
774+ #ifdef __LITTLE_ENDIAN__
775+ #define sys_cpu_to_le16 (x ) (x)
776+ #define sys_cpu_to_le32 (x ) (x)
777+ #define sys_le16_to_cpu (x ) (x)
778+ #define sys_le32_to_cpu (x ) (x)
779+ #define sys_cpu_to_be16 (x ) __bswap_16(x)
780+ #define sys_cpu_to_be32 (x ) __bswap_32(x)
781+ #define sys_be16_to_cpu (x ) __bswap_16(x)
782+ #define sys_be32_to_cpu (x ) __bswap_32(x)
783+ #else
784+ #define sys_cpu_to_le16 (x ) __bswap_16(x)
785+ #define sys_cpu_to_le32 (x ) __bswap_32(x)
786+ #define sys_le16_to_cpu (x ) __bswap_16(x)
787+ #define sys_le32_to_cpu (x ) __bswap_32(x)
788+ #define sys_cpu_to_be16 (x ) (x)
789+ #define sys_cpu_to_be32 (x ) (x)
790+ #define sys_be16_to_cpu (x ) (x)
791+ #define sys_be32_to_cpu (x ) (x)
792+ #endif
793+
751794#endif // MICROPY_INCLUDED_EXTMOD_ZEPHYR_BLE_ZEPHYR_BLE_CONFIG_H
0 commit comments