stm32/powerctrl: Disable WB55 BLE before entering deepsleep.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
pull/8337/head
Andrew Leech 2022-02-23 13:06:44 +11:00 zatwierdzone przez Damien George
rodzic 2eca86e8fa
commit c551723914
4 zmienionych plików z 32 dodań i 6 usunięć

Wyświetl plik

@ -116,7 +116,7 @@ int mp_bluetooth_hci_uart_init(uint32_t port, uint32_t baudrate) {
int mp_bluetooth_hci_uart_deinit(void) {
DEBUG_printf("mp_bluetooth_hci_uart_deinit (stm32 rfcore)\n");
rfcore_ble_reset();
return 0;
}

Wyświetl plik

@ -29,6 +29,7 @@
#include "powerctrl.h"
#include "rtc.h"
#include "genhdr/pllfreqtable.h"
#include "extmod/modbluetooth.h"
#if defined(STM32H7)
#define RCC_SR RSR
@ -947,6 +948,10 @@ void powerctrl_enter_standby_mode(void) {
}
#endif
#if defined(STM32WB) && MICROPY_PY_BLUETOOTH
mp_bluetooth_deinit();
#endif
// We need to clear the PWR wake-up-flag before entering standby, since
// the flag may have been set by a previous wake-up event. Furthermore,
// we need to disable the wake-up sources while clearing this flag, so

Wyświetl plik

@ -600,18 +600,38 @@ static const struct {
void rfcore_ble_init(void) {
DEBUG_printf("rfcore_ble_init\n");
// Clear any outstanding messages from ipcc_init.
tl_check_msg(&ipcc_mem_sys_queue, IPCC_CH_SYS, NULL);
// Configure and reset the BLE controller.
tl_sys_hci_cmd_resp(HCI_OPCODE(OGF_VENDOR, OCF_BLE_INIT), (const uint8_t *)&ble_init_params, sizeof(ble_init_params), 0);
tl_ble_hci_cmd_resp(HCI_OPCODE(0x03, 0x0003), NULL, 0);
if (!rfcore_ble_reset()) {
// ble init can fail if core2 has previously locked up. Reset HSI & rfcore to retry.
LL_RCC_HSI_Disable();
mp_hal_delay_ms(100);
LL_RCC_HSI_Enable();
rfcore_init();
rfcore_ble_reset();
}
// Enable PES rather than SEM7 to moderate flash access between the cores.
uint8_t buf = 0; // FLASH_ACTIVITY_CONTROL_PES
tl_sys_hci_cmd_resp(HCI_OPCODE(OGF_VENDOR, OCF_C2_SET_FLASH_ACTIVITY_CONTROL), &buf, 1, 0);
}
bool rfcore_ble_reset(void) {
DEBUG_printf("rfcore_ble_reset\n");
// Clear any outstanding messages from ipcc_init.
tl_check_msg(&ipcc_mem_sys_queue, IPCC_CH_SYS, NULL);
// Configure and reset the BLE controller.
int ret = tl_sys_hci_cmd_resp(HCI_OPCODE(OGF_VENDOR, OCF_BLE_INIT), (const uint8_t *)&ble_init_params, sizeof(ble_init_params), 500);
if (ret == -MP_ETIMEDOUT) {
return false;
}
tl_ble_hci_cmd_resp(HCI_OPCODE(0x03, 0x0003), NULL, 0);
return true;
}
void rfcore_ble_hci_cmd(size_t len, const uint8_t *src) {
DEBUG_printf("rfcore_ble_hci_cmd\n");

Wyświetl plik

@ -33,6 +33,7 @@ typedef void (*rfcore_ble_msg_callback_t)(void *, const uint8_t *, size_t);
void rfcore_init(void);
void rfcore_ble_init(void);
bool rfcore_ble_reset(void);
void rfcore_ble_hci_cmd(size_t len, const uint8_t *src);
size_t rfcore_ble_check_msg(rfcore_ble_msg_callback_t cb, void *env);
void rfcore_ble_set_txpower(uint8_t level);