/**
* @brief  Main program.
* @param  None
* @retval None
*/
int main(void)
{
  /* MCU Configuration----------------------------------------------------------*/
  
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  
  /* Configure the system clock */
  SystemClock_Config();
    
  HAL_EnableDBGStopMode();

  /* Initialize LEDs*/
  RadioShieldLedInit(RADIO_SHIELD_LED);
  BSP_LED_Init(LED2);
  
  Radio_HAL_Init();
  
  Radio_WMBus_Init();
  
  /* Initialize Buttons*/
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);

#if defined(LPM_ENABLE)
  SystemPower_Config();  
  Enter_LP_mode();
#endif
  while (1)
  {
    Radio_WMBus_On(); 
  } 
}
/**
* @brief  Main program.
* @param  None
* @retval None
*/
int main(void)
{
  /* MCU Configuration----------------------------------------------------------*/
  
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  
  /* Configure the system clock */
  SystemClock_Config();
  
  HAL_EnableDBGStopMode();

  /* Initialize LEDs*/
  RadioShieldLedInit(RADIO_SHIELD_LED);
  //BSP_LED_Init(LED2);
  
  HAL_Spirit1_Init();
    
  /* Initialize Buttons*/
  //BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
  
  P2P_Init();

#if defined(LPM_ENABLE)
  /* Configure the system Power */
  SystemPower_Config();
  Enter_LP_mode();
#endif

  while (1)
  { 
    /* Data communication start */   
    Data_Comm_On(aTransmitBuffer, TxLength, aReceiveBuffer, RxLength);
  } 
}
Пример #3
0
/**
  * @brief  stm32cube_hal_init()
  * @param  None
  * @retval None
  */
void stm32cube_hal_init()
{
    HAL_Init();
    /* Configure the system clock */
    SystemClock_Config();

    HAL_EnableDBGStopMode();
    
    MX_GPIO_Init();
    USARTConfig();
    HAL_Spirit1_Init();
    SPIRIT1_Init();
    
   /* Initialize RTC */
   
   RTC_Config();
   RTC_TimeStampConfig();
}
Пример #4
0
/**
 * @brief  Main function to show how to use BlueNRG Bluetooth Low Energy
 *         stack.
 *         To test this application you need:
 *         - an STM32 Nucleo board with its BlueNRG STM32 expansion board
 *         - a Smartphone with Bluetooth Low Energy (BLE) chip and Android
 *           OS >= v4.3.
 *         On the Android smartphone the STM32_BLE_Toolbox App must be installed
 *         and running.
 *         The STM32_BLE_Toolbox App can be found in this package at:
 *         $PATH_TO_THIS_PACKAGE$\Utilities\Android_Software\Profiles_Central
 *         This sample application configures the board as Server-Peripheral,
 *         while the smartphone plays the Client-Central role.
 *         To set/change the BLE Profile to test, change the value of the macro
 *         BLE_CURRENT_PROFILE_ROLES (in the "active profile" section) in file:
 *         $PATH_TO_THIS_PACKAGE$\Middlewares\ST\STM32_BlueNRG\Profile_Framework
 *         \includes\host_config.h
 *         For example, if the HEART_RATE profile is set, after the connection
 *         between the board and the smartphone has been established, the
 *         STM32_BLE_Toolbox App will show the Heart Rate values in bpm (beats
 *         per minute) coming from the STM32 Nucleo board.
 *         The communication is done using a vendor specific profile.
 *
 * @param  None
 * @retval None
 */
int main(void)
{
#if (JTAG_SUPPORTED == 1) 
  /*
  * Keep debugger enabled while in any low power mode
  */
#ifdef STM32L053xx
  __DBGMCU_CLK_ENABLE();
  HAL_DBG_LowPowerConfig(DBGMCU_SLEEP | DBGMCU_STOP | DBGMCU_STANDBY, ENABLE);
#endif /* STM32L053xx */
  
#ifdef STM32L476xx
  HAL_DBGMCU_EnableDBGSleepMode();
  HAL_DBGMCU_EnableDBGStopMode();
  HAL_DBGMCU_EnableDBGStandbyMode();
#endif /* STM32L476xx */

#ifdef STM32F401xE 
  HAL_EnableDBGSleepMode();
  HAL_EnableDBGStopMode();
  HAL_EnableDBGStandbyMode();
#endif /* STM32F401xE */

#endif /* (JTAG_SUPPORTED == 1) */
 
  /* STM32Cube HAL library initialization:
   *  - Configure the Flash prefetch, Flash preread and Buffer caches
   *  - Systick timer is configured by default as source of time base, but user 
   *    can eventually implement his proper time base source (a general purpose 
   *    timer for example or other time source), keeping in mind that Time base 
   *    duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
   *    handled in milliseconds basis.
   *  - Low Level Initialization
   */
  HAL_Init();
  
  /* Configure the system clock */
  SystemClock_Config();
  
  /* Configure the system Power */
  SystemPower_Config();
    
  /* Initialize the Profile Application Context's Data Structures */
  Osal_MemSet(&profileApplContext,0,sizeof(tProfileApplContext));
  
  /* Configure the RTC */
  Init_RTC();
  TIMER_Init(&hrtc);
  TIMER_Create(eTimerModuleID_BlueNRG_Profile_App, &(profileApplContext.profileTimer_Id), eTimerMode_Repeated, 0);
  
  LPM_Mode_Request(eLPM_MAIN_LOOP_PROCESSES, eLPM_Mode_LP_Stop);  
  
  /* Initialize the BlueNRG SPI driver */
  BNRG_SPI_Init();
  
  /* Set current BlueNRG profile (HRM, HTM, GS, ...) */
  BNRG_Set_Current_profile();
  
  /* Initialize the BlueNRG Profile */
  /* set tx power and security parameters (common to all profiles) */
  BNRG_Profiles_Init();  
  /* low level profile initialization (profile specific) */
  profileApplContext.initProfileFunc();
  
  /* Start the main processes */
  while(1)
  {
    Background();
    
  } /* end while(1) */  
}
Пример #5
0
int main( void )
{
    HAL_EnableDBGStopMode();
    LowPowerConfiguration();
    pc.baud(115200);
    // print banner
    pc.printf("\r\n============== DEBUG STARTED ==============\r\n");
    
    /** User button triggers the ultrasonic sensor */ 
    //PinDetect button(PC_13,PullUp);
    //button.attach_asserted(&sensor, &UltraSonic::triggerSample); // callback routine to trigger usonic
    //button.setSampleFrequency();

    LoRaMacPrimitives_t LoRaMacPrimitives;
    LoRaMacCallback_t LoRaMacCallbacks;
    MibRequestConfirm_t mibReq;

    //BoardInitMcu( );
    //BoardInitPeriph( );
    BoardInit( );

    TimerInit( &mainLoopTimeout, onMainLoopTimeoutEvent );
    

    DeviceState = DEVICE_STATE_INIT;

    while( 1 )
    {
       wait(0.5);
        // This is a kind of watchdog on the main loop, if the timer isn't cancelled in x seconds then loop will enter INIT state
       TimerSetValue( &mainLoopTimeout, 3000000 );
       TimerStart( &mainLoopTimeout );


        switch( DeviceState )
        {
            case DEVICE_STATE_INIT:
            {
                  pc.printf("DEVICE_STATE_INIT\r\n");

                LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm;
                LoRaMacPrimitives.MacMcpsIndication = McpsIndication;
                LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm;
                LoRaMacCallbacks.GetBatteryLevel = BoardGetBatteryLevel;
                LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks );

                TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent );
                TimerInit( &ultrasonicTimer, OnUltrasonicTimeout );

                mibReq.Type = MIB_ADR;
                mibReq.Param.AdrEnable = LORAWAN_ADR_ON;
                LoRaMacMibSetRequestConfirm( &mibReq ); // MAC information base service to set attributes of LoRaMac layer

                mibReq.Type = MIB_PUBLIC_NETWORK;
                mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK;
                LoRaMacMibSetRequestConfirm( &mibReq );
                
                sensor.distanceAvailable = false; // Ensure initialised to false after power up

                DeviceState = DEVICE_STATE_JOIN;
                break;
            }
            case DEVICE_STATE_JOIN:
            {
                  pc.printf("DEVICE_STATE_JOIN\r\n");

#if( OVER_THE_AIR_ACTIVATION != 0 )
                pc.printf("OTA\r\n");
                MlmeReq_t mlmeReq;

                // Initialize LoRaMac device unique ID
                //BoardGetUniqueId( DevEui );
                mlmeReq.Type = MLME_JOIN; // MAC management service types are MLME_JOIN or MLME_LINK_CHECK

                mlmeReq.Req.Join.DevEui = DevEui;
                mlmeReq.Req.Join.AppEui = AppEui;
                mlmeReq.Req.Join.AppKey = AppKey;

                if( NextTx == true )
                {
                    LoRaMacMlmeRequest( &mlmeReq );  // Sends a join request
                }
                // Schedule next packet transmission
                //TxDutyCycleTime = OVER_THE_AIR_ACTIVATION_DUTYCYCLE;
                //DeviceState = DEVICE_STATE_CYCLE;

                DeviceState = DEVICE_STATE_CYCLE;
#else
                pc.printf("ABP\r\n");
                // Choose a random device address if not already defined in Comissioning.h
                if( DevAddr == 0 )
                {
                    // Random seed initialization
                   // srand1( BoardGetRandomSeed( ) );
                    // Choose a random device address
                    DevAddr = randr( 0, 0x01FFFFFF );
                }
                mibReq.Type = MIB_NET_ID;
                mibReq.Param.NetID = LORAWAN_NETWORK_ID;
                LoRaMacMibSetRequestConfirm( &mibReq );

                mibReq.Type = MIB_DEV_ADDR;
                mibReq.Param.DevAddr = DevAddr;
                LoRaMacMibSetRequestConfirm( &mibReq );

                mibReq.Type = MIB_NWK_SKEY;
                mibReq.Param.NwkSKey = NwkSKey;
                LoRaMacMibSetRequestConfirm( &mibReq );

                mibReq.Type = MIB_APP_SKEY;
                mibReq.Param.AppSKey = AppSKey;
                LoRaMacMibSetRequestConfirm( &mibReq );

                mibReq.Type = MIB_NETWORK_JOINED;
                mibReq.Param.IsNetworkJoined = true;
                LoRaMacMibSetRequestConfirm( &mibReq );

                DeviceState = DEVICE_STATE_SEND;
#endif
                break;
            }
            case DEVICE_STATE_SEND:
            {
                  pc.printf("DEVICE_STATE_SEND\r\n");

                if( NextTx == true )
                {
                    pc.printf("Sending\r\n");
                    PrepareTxFrame( AppPort );
                    NextTx = SendFrame( );
                }
            }   
            case DEVICE_STATE_CYCLE:
            {
                 pc.printf("DEVICE_STATE_CYCLE\r\n");
          
                 pc.printf("SensorState = %d, distanceAvailable = ",SensorState);
                if (sensor.distanceAvailable)
                   pc.printf("true\r\n");
                else
                      pc.printf("false\r\n");

                pc.printf("LoRaMacState = %d\r\n",GetMacStatus());      
                      
                if ((SensorState == SENT) || (SensorState == INIT)) { /** Range and Temperature readings have been sent so we can sleep */
                    TimerStop( &TxNextPacketTimer );
                    // Wait for MAC state to become idle before deep sleeping
                    if (GetMacStatus() == 0) { // Ensure MAC state is idle before sleeping
                        pc.printf("DeepSleep ..zzz.\r\n");
                        TimerStop(&mainLoopTimeout); // cancel main loop guard timeout
                        WakeUp::set(DEEPSLEEP_SECONDS); // Set RTC alarm to wake up from deep sleep
                        LowPowerPrep();
                        deepsleep(); // Deep sleep until wake up alarm from RTC 
                        LowPowerRestore();
                        SensorState = TRIGGERED;
                        /* Trigger ultrasonic sensor and start sensor read failure timer */
                        sensor.triggerSample(); // Get Ultrasonic reading
                        TimerSetValue( &ultrasonicTimer, 2000000 ); // 2s timeout
                        TimerStart( &ultrasonicTimer );
                        DeviceState = DEVICE_STATE_SLEEP; // Cycle in sleep until sensor readings ready
                    }
                    else { // Cycle around until MAC state is idle
                        DeviceState = DEVICE_STATE_CYCLE;
                    }
                }
                else {
                    // Error shouldn't get here
                      pc.printf("Error State!!\r\n");
                    //TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime );
                    //TimerStart( &TxNextPacketTimer );
                    SensorState = INIT;
                    DeviceState = DEVICE_STATE_SLEEP;
                }        

                break;
            }
            case DEVICE_STATE_SLEEP:
            {
                 pc.printf("DEVICE_STATE_SLEEP\r\n");

                // Loop until sensor ready
                if ((SensorState == TRIGGERED) && (sensor.distanceAvailable)) {
                    pc.printf("Xmit Reading..!\r\n");
                    TimerStop( &ultrasonicTimer ); // stop the sensor failure timer
                    SensorState = SENDING;
                    TimerSetValue( &TxNextPacketTimer, 10 ); // Schedule immediate transmission
                    TimerStart( &TxNextPacketTimer );
                }
        
                break;
            }
            default:
            {
                DeviceState = DEVICE_STATE_INIT;
                break;
            }
        }
    }
}