diff --git a/cpu/stm32/include/can_params.h b/cpu/stm32/include/can_params.h index e0f2408f14..b6294e599a 100644 --- a/cpu/stm32/include/can_params.h +++ b/cpu/stm32/include/can_params.h @@ -65,6 +65,7 @@ static const can_conf_t candev_conf[] = { .rx1_irqn = CAN1_RX1_IRQn, .sce_irqn = CAN1_SCE_IRQn, #endif + .en_deep_sleep_wake_up = true, .ttcm = 0, .abom = 1, .awum = 1, @@ -85,6 +86,7 @@ static const can_conf_t candev_conf[] = { #ifndef CPU_FAM_STM32F1 .af = GPIO_AF9, #endif + .en_deep_sleep_wake_up = true, .tx_irqn = CAN2_TX_IRQn, .rx0_irqn = CAN2_RX0_IRQn, .rx1_irqn = CAN2_RX1_IRQn, @@ -108,6 +110,7 @@ static const can_conf_t candev_conf[] = { .rx_pin = GPIO_PIN(PORT_B, 3), .tx_pin = GPIO_PIN(PORT_B, 4), .af = GPIO_AF11, + .en_deep_sleep_wake_up = true, .tx_irqn = CAN3_TX_IRQn, .rx0_irqn = CAN3_RX0_IRQn, .rx1_irqn = CAN3_RX1_IRQn, diff --git a/cpu/stm32/include/candev_stm32.h b/cpu/stm32/include/candev_stm32.h index 0d5afe5a7a..9a8925d380 100644 --- a/cpu/stm32/include/candev_stm32.h +++ b/cpu/stm32/include/candev_stm32.h @@ -100,6 +100,7 @@ typedef struct { #ifndef CPU_FAM_STM32F1 gpio_af_t af; /**< Alternate pin function to use */ #endif + bool en_deep_sleep_wake_up; /**< Enable deep-sleep wake-up interrupt */ #if CANDEV_STM32_CHAN_NUMOF > 1 || defined(DOXYGEN) CAN_TypeDef *can_master; /**< Master CAN device */ uint32_t master_rcc_mask; /**< Master device RCC mask */ diff --git a/cpu/stm32/periph/can.c b/cpu/stm32/periph/can.c index 032abb6ae5..9862cdb3c8 100644 --- a/cpu/stm32/periph/can.c +++ b/cpu/stm32/periph/can.c @@ -644,8 +644,10 @@ static void turn_off(can_t *dev) #endif } _status[chan] = STATUS_SLEEP; - periph_clk_dis(APB1, dev->conf->rcc_mask); - enable_int(dev, 0); + if (dev->conf->en_deep_sleep_wake_up) { + periph_clk_dis(APB1, dev->conf->rcc_mask); + enable_int(dev, 0); + } } } else { @@ -658,20 +660,26 @@ static void turn_off(can_t *dev) #endif /* Fall through */ case STATUS_NOT_USED: - periph_clk_dis(APB1, dev->conf->master_rcc_mask); + if (dev->conf->en_deep_sleep_wake_up) { + periph_clk_dis(APB1, dev->conf->master_rcc_mask); + } break; } - periph_clk_dis(APB1, dev->conf->rcc_mask); + if (dev->conf->en_deep_sleep_wake_up) { + periph_clk_dis(APB1, dev->conf->rcc_mask); + } if (_status[get_channel(dev->conf->can)] != STATUS_SLEEP) { #ifdef STM32_PM_STOP pm_unblock(STM32_PM_STOP); #endif } _status[get_channel(dev->conf->can)] = STATUS_SLEEP; - if (_status[master_chan] == STATUS_SLEEP) { - enable_int(dev, 1); + if (dev->conf->en_deep_sleep_wake_up) { + if (_status[master_chan] == STATUS_SLEEP) { + enable_int(dev, 1); + } + enable_int(dev, 0); } - enable_int(dev, 0); } #else if (_status[get_channel(dev->conf->can)] != STATUS_SLEEP) { @@ -680,8 +688,10 @@ static void turn_off(can_t *dev) #endif } _status[get_channel(dev->conf->can)] = STATUS_SLEEP; - periph_clk_dis(APB1, dev->conf->rcc_mask); - gpio_init_int(dev->rx_pin, GPIO_IN, GPIO_FALLING, _wkup_cb, dev); + if (dev->conf->en_deep_sleep_wake_up) { + periph_clk_dis(APB1, dev->conf->rcc_mask); + gpio_init_int(dev->rx_pin, GPIO_IN, GPIO_FALLING, _wkup_cb, dev); + } #endif irq_restore(irq); } @@ -697,7 +707,9 @@ static void turn_on(can_t *dev) switch (_status[master_chan]) { case STATUS_SLEEP: _status[master_chan] = STATUS_READY_FOR_SLEEP; - disable_int(dev, 1); + if (dev->conf->en_deep_sleep_wake_up) { + disable_int(dev, 1); + } #ifdef STM32_PM_STOP pm_block(STM32_PM_STOP); #endif @@ -712,7 +724,9 @@ static void turn_on(can_t *dev) #ifdef STM32_PM_STOP pm_block(STM32_PM_STOP); #endif - disable_int(dev, 0); + if (dev->conf->en_deep_sleep_wake_up) { + disable_int(dev, 0); + } periph_clk_en(APB1, dev->conf->rcc_mask); } _status[get_channel(dev->conf->can)] = STATUS_ON;