void HAL_Core_Enter_Stop_Mode(uint16_t wakeUpPin, uint16_t edgeTriggerMode) { if ((wakeUpPin < TOTAL_PINS) && (edgeTriggerMode <= FALLING)) { PinMode wakeUpPinMode = INPUT; /* Set required pinMode based on edgeTriggerMode */ switch(edgeTriggerMode) { case CHANGE: wakeUpPinMode = INPUT; break; case RISING: wakeUpPinMode = INPUT_PULLDOWN; break; case FALLING: wakeUpPinMode = INPUT_PULLUP; break; } HAL_Pin_Mode(wakeUpPin, wakeUpPinMode); /* Configure EXTI Interrupt : wake-up from stop mode using pin interrupt */ HAL_Interrupts_Attach(wakeUpPin, NULL, NULL, edgeTriggerMode, NULL); HAL_Core_Execute_Stop_Mode(); /* Detach the Interrupt pin */ HAL_Interrupts_Detach(wakeUpPin); } }
/******************************************************************************* * Function Name : detachInterrupt * Description : Arduino compatible function to detach hardware interrupts that were asssigned previously using attachInterrupt * Input : pin number to which the interrupt was attached * Output : None. * Return : None. *******************************************************************************/ void detachInterrupt(uint16_t pin) { #if Wiring_Cellular == 1 /* safety check that prevents users from detaching an interrupt from * BATT_INT_PC13 for power management which is shared with D7 */ if (pin == D7) return; #endif HAL_Interrupts_Detach(pin); delete handlers[pin]; handlers[pin] = NULL; }
bool attachInterrupt(uint16_t pin, raw_interrupt_handler_t handler, InterruptMode mode, int8_t priority, uint8_t subpriority) { #if Wiring_Cellular == 1 /* safety check that prevents users from attaching an interrupt to D7 * which is shared with BATT_INT_PC13 for power management */ if (pin == D7) return false; #endif HAL_Interrupts_Detach(pin); HAL_InterruptExtraConfiguration extra = {0}; HAL_Interrupts_Attach(pin, call_raw_interrupt_handler, (void*)handler, mode, configure_interrupt(extra, priority, subpriority)); return true; }
void HAL_SPI_End(HAL_SPI_Interface spi) { if(spiState[spi].SPI_Enabled != false) { if (spiState[spi].mode == SPI_MODE_SLAVE) { HAL_Interrupts_Detach(spiState[spi].SPI_SS_Pin); } SPI_Cmd(spiMap[spi].SPI_Peripheral, DISABLE); HAL_SPI_DMA_Transfer_Cancel(spi); SPI_DeInit(spiMap[spi].SPI_Peripheral); spiState[spi].SPI_Enabled = false; } }
bool attachInterrupt(uint16_t pin, wiring_interrupt_handler_t fn, InterruptMode mode, int8_t priority, uint8_t subpriority) { #if Wiring_Cellular == 1 /* safety check that prevents users from attaching an interrupt to D7 * which is shared with BATT_INT_PC13 for power management */ if (pin == D7) return false; #endif HAL_Interrupts_Detach(pin); wiring_interrupt_handler_t* handler = allocate_handler(pin, fn); if (handler) { HAL_InterruptExtraConfiguration extra = {0}; HAL_Interrupts_Attach(pin, call_wiring_interrupt_handler, handler, mode, configure_interrupt(extra, priority, subpriority)); } return handler!=NULL; }
void BUTTON_EXTI_Config(Button_TypeDef button, FunctionalState NewState) { HAL_InterruptExtraConfiguration config = {0}; config.version = HAL_INTERRUPT_EXTRA_CONFIGURATION_VERSION; config.keepHandler = false; config.flags = HAL_DIRECT_INTERRUPT_FLAG_NONE; if (NewState == ENABLE) { HAL_Interrupts_Attach(HAL_Buttons[button].pin, BUTTON_Interrupt_Handler, (void *)((int)button), HAL_Buttons[button].interrupt_mode, &config); } else { HAL_Interrupts_Detach(HAL_Buttons[button].pin); } }
void HAL_Core_Execute_Stop_Mode(void) { int32_t state = HAL_disable_irq(); if((BKP_ReadBackupRegister(BKP_DR9) >> 12) == 0xA) { uint16_t wakeUpPin = BKP_ReadBackupRegister(BKP_DR9) & 0xFF; InterruptMode edgeTriggerMode = (InterruptMode)((BKP_ReadBackupRegister(BKP_DR9) >> 8) & 0x0F); /* Clear Stop mode system flag */ BKP_WriteBackupRegister(BKP_DR9, 0xFFFF); if ((wakeUpPin < TOTAL_PINS) && (edgeTriggerMode <= FALLING)) { PinMode wakeUpPinMode = INPUT; /* Set required pinMode based on edgeTriggerMode */ switch(edgeTriggerMode) { case CHANGE: wakeUpPinMode = INPUT; break; case RISING: wakeUpPinMode = INPUT_PULLDOWN; break; case FALLING: wakeUpPinMode = INPUT_PULLUP; break; } HAL_Pin_Mode(wakeUpPin, wakeUpPinMode); /* Configure EXTI Interrupt : wake-up from stop mode using pin interrupt */ HAL_Interrupts_Attach(wakeUpPin, NULL, NULL, edgeTriggerMode, NULL); /* Request to enter STOP mode with regulator in low power mode */ PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); /* Detach the Interrupt pin */ HAL_Interrupts_Detach(wakeUpPin); /* Disable RTC Alarm */ HAL_RTC_Cancel_UnixAlarm(); /* At this stage the system has resumed from STOP mode */ /* Enable HSE, PLL and select PLL as system clock source after wake-up from STOP */ /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ if(RCC_WaitForHSEStartUp() != SUCCESS) { /* If HSE startup fails try to recover by system reset */ NVIC_SystemReset(); } /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08); } } HAL_enable_irq(state); }