Skip to content

Commit

Permalink
Merge pull request micropython#8021 from SiliconLabs/dev
Browse files Browse the repository at this point in the history
Silabs fixes, BLE bonding and peripheral changes
  • Loading branch information
dhalbert committed May 24, 2023
2 parents bb74be3 + 8ca87a5 commit 713d86f
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 85 deletions.
2 changes: 1 addition & 1 deletion ports/silabs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ requires:
recommends:
- id: sensor_rht
- id: sensor_lux
- id: bt_rail_compatibility_fix
5 changes: 3 additions & 2 deletions ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions ports/silabs/boards/devkit_xg24_brd2601b/pins.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@ provides:
- name: custom_brd2703a_cp_support
requires:
- name: efr32mg24b210f1536im48
recommends:
- id: bt_rail_compatibility_fix
4 changes: 2 additions & 2 deletions ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ MCU_SERIES = MG24
MCU_VARIANT = EFR32MG24B210F1536IM48

CIRCUITPY_USB = 0
CIRCUITPY_SDCARDIO = 1

CIRCUITPY_CREATOR_ID = 0x19960000
CIRCUITPY_CREATION_ID = 0x00242703
Expand Down
1 change: 0 additions & 1 deletion ports/silabs/circuitpython_efr32.slcp
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
7 changes: 4 additions & 3 deletions ports/silabs/common-hal/_bleio/Adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down
54 changes: 15 additions & 39 deletions ports/silabs/common-hal/_bleio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;

Expand All @@ -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:
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions ports/silabs/common-hal/analogio/AnalogIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
28 changes: 0 additions & 28 deletions ports/silabs/silabs.pintool

This file was deleted.

0 comments on commit 713d86f

Please sign in to comment.