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); } }
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; }
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_SPI_Begin_Ext(HAL_SPI_Interface spi, SPI_Mode mode, uint16_t pin, void* reserved) { if (pin == SPI_DEFAULT_SS) pin = spiMap[spi].SPI_SS_Pin; spiState[spi].SPI_SS_Pin = pin; STM32_Pin_Info* PIN_MAP = HAL_Pin_Map(); spiState[spi].mode = mode; /* Enable SPI Clock */ *spiMap[spi].SPI_RCC_APBRegister |= spiMap[spi].SPI_RCC_APBClockEnable; *spiMap[spi].SPI_RCC_AHBRegister |= spiMap[spi].SPI_RCC_AHBClockEnable; /* Connect SPI pins to AF */ GPIO_PinAFConfig(PIN_MAP[spiMap[spi].SPI_SCK_Pin].gpio_peripheral, PIN_MAP[spiMap[spi].SPI_SCK_Pin].gpio_pin_source, spiMap[spi].SPI_AF_Mapping); GPIO_PinAFConfig(PIN_MAP[spiMap[spi].SPI_MISO_Pin].gpio_peripheral, PIN_MAP[spiMap[spi].SPI_MISO_Pin].gpio_pin_source, spiMap[spi].SPI_AF_Mapping); GPIO_PinAFConfig(PIN_MAP[spiMap[spi].SPI_MOSI_Pin].gpio_peripheral, PIN_MAP[spiMap[spi].SPI_MOSI_Pin].gpio_pin_source, spiMap[spi].SPI_AF_Mapping); HAL_Pin_Mode(spiMap[spi].SPI_SCK_Pin, AF_OUTPUT_PUSHPULL); HAL_Pin_Mode(spiMap[spi].SPI_MISO_Pin, AF_OUTPUT_PUSHPULL); HAL_Pin_Mode(spiMap[spi].SPI_MOSI_Pin, AF_OUTPUT_PUSHPULL); if (mode == SPI_MODE_MASTER) { HAL_Pin_Mode(pin, OUTPUT); HAL_GPIO_Write(pin, Bit_SET);//HIGH } else { HAL_Pin_Mode(pin, INPUT); } /* SPI configuration */ spiState[spi].SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; spiState[spi].SPI_InitStructure.SPI_Mode = SPI_Mode_Master; spiState[spi].SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; if(spiState[spi].SPI_Data_Mode_Set != true) { //Default: SPI_MODE3 spiState[spi].SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; spiState[spi].SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; } spiState[spi].SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; if(spiState[spi].SPI_Clock_Divider_Set != true) { /* Defaults to 15Mbit/s on SPI1, SPI2 and SPI3 */ if(spi == HAL_SPI_INTERFACE1) { spiState[spi].SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;//60/4=15 } else { spiState[spi].SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;//30/2=15 } } if(spiState[spi].SPI_Bit_Order_Set != true) { //Default: MSBFIRST spiState[spi].SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; } spiState[spi].SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(spiMap[spi].SPI_Peripheral, &spiState[spi].SPI_InitStructure); if (mode == SPI_MODE_SLAVE) { /* Attach interrupt to slave select pin */ HAL_InterruptExtraConfiguration irqConf = {0}; irqConf.size = sizeof(irqConf); irqConf.IRQChannelPreemptionPriority = 1; irqConf.IRQChannelSubPriority = 0; HAL_Interrupts_Attach(pin, &HAL_SPI_SS_Handler, (void*)(spi), CHANGE, &irqConf); /* Switch to slave mode */ spiState[spi].SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; SPI_Init(spiMap[spi].SPI_Peripheral, &spiState[spi].SPI_InitStructure); } if (mode == SPI_MODE_MASTER) { /* SPI peripheral should not be enabled in Slave mode until the device is selected */ SPI_Cmd(spiMap[spi].SPI_Peripheral, ENABLE); } spiState[spi].SPI_Enabled = true; }
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); }