diff --git a/ports/silabs/Makefile b/ports/silabs/Makefile index 06ddf3a57d..39f493287a 100644 --- a/ports/silabs/Makefile +++ b/ports/silabs/Makefile @@ -88,7 +88,7 @@ SRC_C += \ mphalport.c \ $(SILABS_BUILD)/pins.c\ -ifeq ('$(BOARD)','brd2601b') +ifneq (,$(wildcard boards/$(BOARD)/sensor.c)) SRC_C += boards/$(BOARD)/sensor.c endif diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/custom_brd2601b_cp_support.slcc b/ports/silabs/boards/devkit_xg24_brd2601b/custom_brd2601b_cp_support.slcc index b1731a306f..f0a7d66c47 100644 --- a/ports/silabs/boards/devkit_xg24_brd2601b/custom_brd2601b_cp_support.slcc +++ b/ports/silabs/boards/devkit_xg24_brd2601b/custom_brd2601b_cp_support.slcc @@ -24,4 +24,3 @@ requires: recommends: - id: sensor_rht - id: sensor_lux - - id: bt_rail_compatibility_fix diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk b/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk index 9c40c6fe7c..58c6d15ba6 100644 --- a/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk +++ b/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk @@ -1,14 +1,15 @@ BOARD_BRD = brd2601b -INTERNAL_FLASH_FILESYSTEM = 0 +INTERNAL_FLASH_FILESYSTEM = 1 QSPI_FLASH_FILESYSTEM = 0 -SPI_FLASH_FILESYSTEM = 1 +SPI_FLASH_FILESYSTEM = 0 EXTERNAL_FLASH_DEVICES = MX25R3235F MCU_SERIES = MG24 MCU_VARIANT = EFR32MG24B310F1536IM48 CIRCUITPY_USB = 0 +CIRCUITPY_SDCARDIO = 1 CIRCUITPY_CREATOR_ID = 0x19960000 CIRCUITPY_CREATION_ID = 0x00242601 diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/pins.csv b/ports/silabs/boards/devkit_xg24_brd2601b/pins.csv index c1d9a5a252..47ab01ab3f 100644 --- a/ports/silabs/boards/devkit_xg24_brd2601b/pins.csv +++ b/ports/silabs/boards/devkit_xg24_brd2601b/pins.csv @@ -10,8 +10,8 @@ PB2,BTN0,1,2 PB3,BTN1,1,3 PC0,FLASH_CS,2,0 PC1,SCLK,2,1 -PC2,CIPO,2,2 -PC3,COPI,2,3 +PC2,MISO,2,2 +PC3,MOSI,2,3 PC4,SCL,2,4 PC5,SDA,2,5 PC9,SENSOR_CS,2,9 diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/custom_brd2703a_cp_support.slcc b/ports/silabs/boards/explorerkit_xg24_brd2703a/custom_brd2703a_cp_support.slcc index b78d83ce51..872897c4fb 100644 --- a/ports/silabs/boards/explorerkit_xg24_brd2703a/custom_brd2703a_cp_support.slcc +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/custom_brd2703a_cp_support.slcc @@ -16,5 +16,3 @@ provides: - name: custom_brd2703a_cp_support requires: - name: efr32mg24b210f1536im48 -recommends: - - id: bt_rail_compatibility_fix diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.h b/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.h index 87da017fb7..eb1efca12d 100644 --- a/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.h +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.h @@ -37,8 +37,8 @@ #define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) #define BOARD_HAS_LOW_SPEED_CRYSTAL (0) -#define DEFAULT_I2C_BUS_SDA (&pin_PB5) -#define DEFAULT_I2C_BUS_SCL (&pin_PB4) +#define DEFAULT_I2C_BUS_SDA (&pin_PC5) +#define DEFAULT_I2C_BUS_SCL (&pin_PC4) #define DEFAULT_I2C_PERIPHERAL I2C0 #define DEFAULT_SPI_BUS_SCK (&pin_PC1) diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk b/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk index dd63b4da17..849f11ffeb 100644 --- a/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk @@ -7,6 +7,7 @@ MCU_SERIES = MG24 MCU_VARIANT = EFR32MG24B210F1536IM48 CIRCUITPY_USB = 0 +CIRCUITPY_SDCARDIO = 1 CIRCUITPY_CREATOR_ID = 0x19960000 CIRCUITPY_CREATION_ID = 0x00242703 diff --git a/ports/silabs/circuitpython_efr32.slcp b/ports/silabs/circuitpython_efr32.slcp index e7010b08cd..d645f2b1ed 100644 --- a/ports/silabs/circuitpython_efr32.slcp +++ b/ports/silabs/circuitpython_efr32.slcp @@ -42,7 +42,6 @@ component: - {id: sleeptimer} - {id: emlib_wdog} - {id: bluetooth_feature_connection} -- {id: rail_lib_multiprotocol} - {id: bluetooth_feature_dynamic_gattdb} - {id: bluetooth_feature_system} - {id: bluetooth_feature_scanner} diff --git a/ports/silabs/common-hal/_bleio/Adapter.c b/ports/silabs/common-hal/_bleio/Adapter.c index cbfdcbce55..ec2e6632ec 100644 --- a/ports/silabs/common-hal/_bleio/Adapter.c +++ b/ports/silabs/common-hal/_bleio/Adapter.c @@ -280,9 +280,10 @@ uint32_t _common_hal_bleio_adapter_start_advertising( const bleio_address_obj_t *directed_to) { sl_status_t sc = SL_STATUS_FAIL; + int16_t power = tx_power * 10; // TX power in 0.1 dBm steps int16_t set_power; - uint32_t interval_min = 160; - uint32_t interval_max = 160; + uint32_t interval_min = (uint32_t)(interval * 1600); // (milliseconds * 1.6) + uint32_t interval_max = (uint32_t)(interval * 1600); // (milliseconds * 1.6) bd_addr address; uint8_t address_type; uint8_t system_id[8]; @@ -328,7 +329,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising( } sc = sl_bt_advertiser_set_tx_power(self->advertising_handle, - tx_power, + power, &set_power); if (SL_STATUS_OK != sc) { return sc; diff --git a/ports/silabs/common-hal/_bleio/__init__.c b/ports/silabs/common-hal/_bleio/__init__.c index e7323c7793..79a0b764e9 100644 --- a/ports/silabs/common-hal/_bleio/__init__.c +++ b/ports/silabs/common-hal/_bleio/__init__.c @@ -41,6 +41,7 @@ STATIC conn_state_t conn_state; osMutexId_t bluetooth_connection_mutex_id; bleio_adapter_obj_t common_hal_bleio_adapter_obj; +uint8_t ble_bonding_handle = 0xFF; __ALIGNED(4) static uint8_t bluetooth_connection_mutex_cb[osMutexCbSize]; const osMutexAttr_t bluetooth_connection_mutex_attr = { @@ -106,7 +107,6 @@ void common_hal_bleio_check_connected(uint16_t conn_handle) { // Bluetooth stack event handler. void sl_bt_on_event(sl_bt_msg_t *evt) { - sl_status_t sc = SL_STATUS_OK; bd_addr address; uint8_t address_type = 0; STATIC uint8_t serv_idx = 0; @@ -122,23 +122,18 @@ void sl_bt_on_event(sl_bt_msg_t *evt) { case sl_bt_evt_system_boot_id: - sc = sl_bt_system_get_identity_address(&address, &address_type); + sl_bt_system_get_identity_address(&address, &address_type); snprintf((char *)device_name, 14 + 1, "CIRCUITPY-%X%X",address.addr[1], address.addr[0]); sl_bt_gatt_server_write_attribute_value(gattdb_device_name, 0,14,device_name); - sc = sl_bt_sm_configure(0x00,sl_bt_sm_io_capability_noinputnooutput); - if (SL_STATUS_OK != sc) { - mp_raise_bleio_BluetoothError(translate("Sm configure fail")); - } + sl_bt_sm_store_bonding_configuration(5,2); - sc = sl_bt_sm_set_bondable_mode(1); - if (SL_STATUS_OK != sc) { - mp_raise_bleio_BluetoothError(translate("Set bondable mode fail")); - } - sl_bt_sm_delete_bondings(); + sl_bt_sm_configure(0x00,sl_bt_sm_io_capability_noinputnooutput); + + sl_bt_sm_set_bondable_mode(1); break; // This event indicates that a new connection was opened. @@ -154,14 +149,7 @@ void sl_bt_on_event(sl_bt_msg_t *evt) { bleio_connections[0].is_central = false; bleio_connections[0].mtu = 0; } - - sc = sl_bt_sm_increase_security( - evt->data.evt_connection_opened.connection); - - if (SL_STATUS_OK != sc) { - mp_raise_bleio_BluetoothError( - translate("Increase security fail.")); - } + ble_bonding_handle = evt->data.evt_connection_opened.bonding; osMutexRelease(bluetooth_connection_mutex_id); break; @@ -181,6 +169,8 @@ void sl_bt_on_event(sl_bt_msg_t *evt) { case sl_bt_evt_connection_closed_id: common_hal_bleio_adapter_remove_connection( evt->data.evt_connection_closed.connection); + // reset bonding handle variable to avoid deleting wrong bonding info + ble_bonding_handle = 0xFF; break; case sl_bt_evt_system_external_signal_id: @@ -306,7 +296,7 @@ void sl_bt_on_event(sl_bt_msg_t *evt) { && serv_idx < connection->remote_service_list->len) { service = connection->remote_service_list->items[serv_idx]; - sc = sl_bt_gatt_discover_characteristics( + sl_bt_gatt_discover_characteristics( evt->data.evt_gatt_procedure_completed.connection, service->handle); @@ -366,34 +356,20 @@ void sl_bt_on_event(sl_bt_msg_t *evt) { break; case sl_bt_evt_sm_confirm_bonding_id: - sc = sl_bt_sm_bonding_confirm( - evt->data.evt_sm_confirm_bonding.connection,1); - if (SL_STATUS_OK != sc) { - mp_raise_bleio_BluetoothError( - translate("Bonding confirm fail")); - } + sl_bt_sm_bonding_confirm(evt->data.evt_sm_confirm_bonding.connection,1); break; case sl_bt_evt_sm_bonded_id: break; case sl_bt_evt_sm_bonding_failed_id: + if (ble_bonding_handle != 0xFF) { + sl_bt_sm_delete_bonding(ble_bonding_handle); + ble_bonding_handle = 0xFF; + } break; case sl_bt_evt_connection_parameters_id: - switch (evt->data.evt_connection_parameters.security_mode) - { - case connection_mode1_level1: - break; - case connection_mode1_level2: - break; - case connection_mode1_level3: - break; - case connection_mode1_level4: - break; - default: - break; - } break; default: diff --git a/ports/silabs/common-hal/analogio/AnalogIn.c b/ports/silabs/common-hal/analogio/AnalogIn.c index ecf61ca268..e22c5b3493 100644 --- a/ports/silabs/common-hal/analogio/AnalogIn.c +++ b/ports/silabs/common-hal/analogio/AnalogIn.c @@ -91,10 +91,10 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, // Resolution is not configurable directly but is based on the // selected oversampling ratio (osrHighSpeed), which defaults to // 2x and generates 12-bit results. - initAllConfigs.configs[0].reference = iadcCfgReferenceInt1V2; - initAllConfigs.configs[0].vRef = 1210; + initAllConfigs.configs[0].reference = iadcCfgReferenceVddx; + initAllConfigs.configs[0].vRef = 3300; initAllConfigs.configs[0].osrHighSpeed = iadcCfgOsrHighSpeed2x; - initAllConfigs.configs[0].analogGain = iadcCfgAnalogGain0P5x; + initAllConfigs.configs[0].analogGain = iadcCfgAnalogGain1x; // Divide CLK_SRC_ADC to set the CLK_ADC frequency initAllConfigs.configs[0].adcClkPrescale @@ -212,5 +212,5 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { // Get adc ref value float common_hal_analogio_analogin_get_reference_voltage (analogio_analogin_obj_t *self) { - return 2.42f; + return 3.3f; } diff --git a/ports/silabs/silabs.pintool b/ports/silabs/silabs.pintool deleted file mode 100644 index 1121cb391d..0000000000 --- a/ports/silabs/silabs.pintool +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -