Ejemplo n.º 1
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{

  /* STM32F3xx HAL library initialization:
       - Configure the Flash prefetch
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();

  /* Configure the system clock to have a system clock = 72 MHz */
  SystemClock_Config();

  /* Initialize STM32F3348-DISCO LEDs */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  BSP_LED_Init(LED6);

  /* Initialize User_Button on STM32F3348-DISCO */
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);   

  /* Initialize ADC to be triggered by the HRTIMER */
  ADC_Config();
  
  /* Initialize HRTIM and related inputs */
  HRTIM_Config();
  /* Initialize HRTIM outputs (it has to be done after HRTIM init) */
  GPIO_HRTIM_outputs_Config();
  
  /* Infinite loop */
  while (1)
  {
    
    /* ---------------- */
    /* Fault management */
    /* ---------------- */
    while(__HAL_HRTIM_GET_FLAG(&hhrtim, HRTIM_FLAG_FLT1) == SET)
    {
      /* LED3 is flashing in case of fault */
      BSP_LED_On(LED3);
      HAL_Delay(20);
      BSP_LED_Off(LED3);
      HAL_Delay(80);
      
      /* Re-arm HRTIM TD1 output if "User" push button is pressed*/
      if((BSP_PB_GetState(BUTTON_USER) == SET))
      {
          __HAL_HRTIM_CLEAR_IT(&hhrtim, HRTIM_IT_FLT1);
          HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TD1);
      }
    }

    /* ---------------- */
    /* Normal operation */
    /* ---------------- */
    /* LED6 toggling to show MCU activity */
    BSP_LED_On(LED6);
    HAL_Delay(100);
    BSP_LED_Off(LED6);
    HAL_Delay(400);
    
    /* -------------------------------------------------------------------- */
    /* ADC monitoring (to be viewed with watch)                             */
    /* PA4 can be connected to the RC filter or any voltage to be monitored */
    /* -------------------------------------------------------------------- */
    ADCReadout = HAL_ADCEx_InjectedGetValue(&AdcHandle, ADC_INJECTED_RANK_1);
    
  }
}
Ejemplo n.º 2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{

    /* STM32F3xx HAL library initialization:
         - Configure the Flash prefetch
         - Configure the Systick to generate an interrupt each 1 msec
         - Set NVIC Group Priority to 4
         - Global MSP (MCU Support Package) initialization
       */
    HAL_Init();

    /* Configure the system clock to have a system clock = 72 MHz */
    SystemClock_Config();

    /* Initialize STM32F3348-DISCO LEDs */
    BSP_LED_Init(LED3);
    BSP_LED_Init(LED4);
    BSP_LED_Init(LED6);

    /* Initialize User_Button on STM32F3348-DISCO */
    BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);

    /* Initialize ADC to be triggered by the HRTIMER */
    ADC_Config();

    /* Initialize HRTIM and related inputs */
#ifdef SNIPPET
    HRTIM_Config_NoHAL();
#else
    HRTIM_Config();
#endif

    /* Initialize BUCK outputs (it has to be done after HRTIM init) */
    GPIO_BUCK_outputs_Config();

    /* Turn ON T6 MOSFET on discovery board */
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_SET);

    /* Infinite loop */
    while (1)
    {

        /* ---------------- */
        /* Fault management */
        /* ---------------- */
#ifdef SNIPPET
        /* If Fault occured */
        while(HRTIM1->sCommonRegs.ISR & HRTIM_ICR_FLT1C)
        {
            /* LED3 is flashing in case of fault */
            BSP_LED_On(LED3);
            HAL_Delay(20);
            BSP_LED_Off(LED3);
            HAL_Delay(80);

            /* Re-arm HRTIM TD1 output if "User" push button is pressed*/
            if((BSP_PB_GetState(BUTTON_USER) == SET))
            {
                /* Clear interrupt flag */
                HRTIM1->sCommonRegs.ICR = HRTIM_ICR_FLT1C;
                /* Re-enable TA1 and TA2 */
                HRTIM1->sCommonRegs.OENR = HRTIM_OENR_TA1OEN + HRTIM_OENR_TA2OEN;
            }
        }
#else
        while(__HAL_HRTIM_GET_FLAG(&hhrtim, HRTIM_FLAG_FLT1) == SET)
        {
            /* LED3 is flashing in case of fault */
            BSP_LED_On(LED3);
            HAL_Delay(20);
            BSP_LED_Off(LED3);
            HAL_Delay(80);

            /* Re-arm HRTIM TD1 output if "User" push button is pressed*/
            if((BSP_PB_GetState(BUTTON_USER) == SET))
            {
                __HAL_HRTIM_CLEAR_IT(&hhrtim, HRTIM_IT_FLT1);
                HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TA1 | HRTIM_OUTPUT_TA2);
            }
        }
#endif

        /* ---------------- */
        /* Normal operation */
        /* ---------------- */
        /* LED6 toggling to show MCU activity */
        BSP_LED_On(LED6);
        HAL_Delay(100);
        BSP_LED_Off(LED6);
        HAL_Delay(400);

        /* -----------------------------------------------------------------------*/
        /* Input and output voltages can be displayed real-time in a watch window */
        /* -----------------------------------------------------------------------*/
        Vin = (HAL_ADCEx_InjectedGetValue(&AdcHandle, ADC_INJECTED_RANK_1) * ADC_VREF)/0x1000;
        /* VIN bridge conversion is 4.97 (6.8K / 6.8K + 27K) */
        Vin = (497 * Vin )/100;

        Vout = (HAL_ADCEx_InjectedGetValue(&AdcHandle, ADC_INJECTED_RANK_2) * ADC_VREF)/0x1000;
        /* VOUT bridge conversion is 5.03 (3.3K / 3.3K + 13.3K) */
        Vout = (503 * Vout)/100;

    }
}