void BoardInitMcu( void ) { if( McuInitialized == false ) { // We use IRQ priority group 4 for the entire project // When setting the IRQ, only the preemption priority is used NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); // Disable Systick SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; // Systick IRQ off SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk; // Clear SysTick Exception pending flag AdcInit( &Adc, POTI ); SpiInit( &SX1272.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC ); SX1272IoInit( ); #if( LOW_POWER_MODE_ENABLE ) TimerSetLowPowerEnable( true ); #else TimerSetLowPowerEnable( false ); #endif BoardUnusedIoInit( ); if( TimerGetLowPowerEnable( ) == true ) { RtcInit( ); } else { TimerHwInit( ); } McuInitialized = true; } }
void EXTI9_5_IRQHandler( void ) { #if !defined( USE_NO_TIMER ) if( TimerGetLowPowerEnable( ) == true ) { RtcRecoverMcuStatus( ); } #endif if( EXTI_GetITStatus( EXTI_Line5 ) != RESET ) { if( GpioIrq[5] != NULL ) { GpioIrq[5]( ); } EXTI_ClearITPendingBit( EXTI_Line5 ); } if( EXTI_GetITStatus( EXTI_Line6 ) != RESET ) { if( GpioIrq[6] != NULL ) { GpioIrq[6]( ); } EXTI_ClearITPendingBit( EXTI_Line6 ); } if( EXTI_GetITStatus( EXTI_Line7 ) != RESET ) { if( GpioIrq[7] != NULL ) { GpioIrq[7]( ); } EXTI_ClearITPendingBit( EXTI_Line7 ); } if( EXTI_GetITStatus( EXTI_Line8 ) != RESET ) { if( GpioIrq[8] != NULL ) { GpioIrq[8]( ); } EXTI_ClearITPendingBit( EXTI_Line8 ); } if( EXTI_GetITStatus( EXTI_Line9 ) != RESET ) { if( GpioIrq[9] != NULL ) { GpioIrq[9]( ); } EXTI_ClearITPendingBit( EXTI_Line9 ); } }
void EXTI4_IRQHandler( void ) { #if !defined( USE_NO_TIMER ) if ( TimerGetLowPowerEnable( ) == true ) RtcRecoverMcuStatus( ); #endif if ( EXTI_GetITStatus( EXTI_Line4 ) != RESET ) { if ( GpioIrq[4] != NULL ) GpioIrq[4]( ); EXTI_ClearITPendingBit( EXTI_Line4 ); } }
void BoardInitMcu( void ) { if( McuInitialized == false ) { // We use IRQ priority group 4 for the entire project // When setting the IRQ, only the preemption priority is used NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); // Disable Systick // SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; // Systick IRQ off // SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk; // Clear SysTick Exception pending flag /* Setup SysTick Timer for 1 ms interrupts (not too often to save power) */ if (SysTick_Config(SystemCoreClock / 1000)) { /* Capture error */ while (1); } I2cInit( &I2c, I2C_SCL, I2C_SDA ); SpiInit( &SX1276.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC ); SX1276IoInit( ); #if defined( USE_DEBUG_PINS ) GpioInit( &DbgPin1, J1_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); GpioInit( &DbgPin2, J1_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); GpioInit( &DbgPin3, J1_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); GpioInit( &DbgPin4, J1_4, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); #endif BoardInitPeriph( ); #if( LOW_POWER_MODE_ENABLE ) TimerSetLowPowerEnable( true ); #else TimerSetLowPowerEnable( false ); #endif BoardUnusedIoInit( ); if( TimerGetLowPowerEnable( ) == true ) { RtcInit( ); } else { TimerHwInit( ); } McuInitialized = true; } }
void BoardInitMcu( void ) { if ( McuInitialized == false ) { /* Initialize low level components */ low_level_init(); /*! SPI channel to be used by Semtech SX1276 */ #if defined(SX1276_BOARD_EMBED) SpiInit(&SX1276.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC); SX1276IoInit(); #endif #if defined (USE_USB_CDC) UartInit( &UartUsb, UART_USB_CDC, NC, NC ); UartConfig( &UartUsb, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL ); TimerSetLowPowerEnable(false); #elif defined(DEBUG) #if defined(USE_SHELL) Shell_Init(); #else #if !defined(USE_CUSTOM_UART_HAL) FifoInit(&Uart1.FifoRx, DbgRxBuffer, DBG_FIFO_RX_SIZE); FifoInit(&Uart1.FifoTx, DbgTxBuffer, DBG_FIFO_TX_SIZE); #endif UartInit(&Uart1, UART_1, UART1_TX, UART1_RX); UartConfig(&Uart1, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL); #endif DbgConsole_Init(&Uart1); TimerSetLowPowerEnable(false); #elif( LOW_POWER_MODE_ENABLE ) TimerSetLowPowerEnable(true); #else TimerSetLowPowerEnable(false); #endif BoardUnusedIoInit(); #if !defined(USE_FREE_RTOS) if ( TimerGetLowPowerEnable() == true ) { RtcInit(); } else { TimerHwInit(); } #endif /* USE_FREE_RTOS */ McuInitialized = true; } }
void EXTI15_10_IRQHandler( void ) { #if !defined( USE_NO_TIMER ) if ( TimerGetLowPowerEnable( ) == true ) RtcRecoverMcuStatus( ); #endif if ( EXTI_GetITStatus( EXTI_Line10 ) != RESET ) { if ( GpioIrq[10] != NULL ) GpioIrq[10]( ); EXTI_ClearITPendingBit( EXTI_Line10 ); } if ( EXTI_GetITStatus( EXTI_Line11 ) != RESET ) { if ( GpioIrq[11] != NULL ) GpioIrq[11]( ); EXTI_ClearITPendingBit( EXTI_Line11 ); } if ( EXTI_GetITStatus( EXTI_Line12 ) != RESET ) { if ( GpioIrq[12] != NULL ) GpioIrq[12]( ); EXTI_ClearITPendingBit( EXTI_Line12 ); } if ( EXTI_GetITStatus( EXTI_Line13 ) != RESET ) { if ( GpioIrq[13] != NULL ) GpioIrq[13]( ); EXTI_ClearITPendingBit( EXTI_Line13 ); } if ( EXTI_GetITStatus( EXTI_Line14 ) != RESET ) { if ( GpioIrq[14] != NULL ) GpioIrq[14]( ); EXTI_ClearITPendingBit( EXTI_Line14 ); } if ( EXTI_GetITStatus( EXTI_Line15 ) != RESET ) { if ( GpioIrq[15] != NULL ) GpioIrq[15]( ); EXTI_ClearITPendingBit( EXTI_Line15 ); } }
void BoardInitMcu( void ) { if( McuInitialized == false ) { // We use IRQ priority group 4 for the entire project // When setting the IRQ, only the preemption priority is used NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); // Disable Systick SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; // Systick IRQ off SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk; // Clear SysTick Exception pending flag I2cInit( &I2c, I2C_SCL, I2C_SDA ); SpiInit( &SX1272.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC ); SX1272IoInit( ); #if defined( USE_DEBUG_PINS ) GpioInit( &DbgPin1, J5_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); GpioInit( &DbgPin2, J5_2, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); GpioInit( &DbgPin3, J5_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); GpioInit( &DbgPin4, J5_4, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); #endif BoardInitPeriph( ); #if( LOW_POWER_MODE_ENABLE ) TimerSetLowPowerEnable( true ); #else TimerSetLowPowerEnable( false ); #endif BoardUnusedIoInit( ); if( TimerGetLowPowerEnable( ) == true ) { RtcInit( ); } else { TimerHwInit( ); } McuInitialized = true; } }
void RtcRecoverMcuStatus( void ) { if( TimerGetLowPowerEnable( ) == true ) { if( ( LowPowerDisableDuringTask == false ) && ( RtcTimerEventAllowsLowPower == true ) ) { // Disable IRQ while the MCU is not running on HSI __disable_irq( ); /* After wake-up from STOP reconfigure the system clock */ /* Enable HSI */ RCC_HSICmd( ENABLE ); /* Wait till HSI is ready */ while( RCC_GetFlagStatus( RCC_FLAG_HSIRDY ) == RESET ) {} /* 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( ) != 0x0C ) {} /* Set MCU in ULP (Ultra Low Power) */ PWR_UltraLowPowerCmd( DISABLE ); // add up to 3ms wakeup time /* Enable the Power Voltage Detector */ PWR_PVDCmd( ENABLE ); BoardInitMcu( ); __enable_irq( ); } } }
void BoardInitMcu( void ) { if( McuInitialized == false ) { #if defined( USE_BOOTLOADER ) // Set the Vector Table base location at 0x3000 NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x3000 ); #endif // We use IRQ priority group 4 for the entire project // When setting the IRQ, only the preemption priority is used NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); // Disable Systick SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; // Systick IRQ off SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk; // Clear SysTick Exception pending flag I2cInit( &I2c, I2C_SCL, I2C_SDA ); AdcInit( &Adc, BAT_LEVEL ); SpiInit( &SX1272.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC ); SX1272IoInit( ); #if defined( USE_DEBUG_PINS ) GpioInit( &DbgPin1, CON_EXT_1, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); GpioInit( &DbgPin2, CON_EXT_3, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); GpioInit( &DbgPin3, CON_EXT_7, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); GpioInit( &DbgPin4, CON_EXT_9, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); #endif #if defined( USE_USB_CDC ) { Gpio_t usbDM; GpioInit( &usbDM, USB_DM, PIN_INPUT, PIN_PUSH_PULL, PIN_PULL_UP, 0 ); if( GpioRead( &usbDM ) == 0 ) { TimerSetLowPowerEnable( false ); UsbMcuInit( ); UartInit( &UartUsb, UART_USB_CDC, NC, NC ); UartConfig( &UartUsb, RX_TX, 115200, UART_8_BIT, UART_1_STOP_BIT, NO_PARITY, NO_FLOW_CTRL ); } else { TimerSetLowPowerEnable( true ); GpioInit( &usbDM, USB_DM, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0 ); } } #elif defined( LOW_POWER_MODE_ENABLE ) TimerSetLowPowerEnable( true ); #else TimerSetLowPowerEnable( false ); #endif BoardUnusedIoInit( ); if( TimerGetLowPowerEnable( ) == true ) { RtcInit( ); } else { TimerHwInit( ); } McuInitialized = true; } }