コード例 #1
44
ファイル: leds.c プロジェクト: drmetal/lollyjar
void clear_led(uint8_t led)
{
    HAL_GPIO_WritePin(leds[led].port, leds[led].pin, GPIO_PIN_RESET);
}
コード例 #2
12
ファイル: leds.c プロジェクト: drmetal/lollyjar
void switch_led(uint8_t led, bool state)
{
    HAL_GPIO_WritePin(leds[led].port, leds[led].pin, state ? GPIO_PIN_SET : GPIO_PIN_RESET);
}
コード例 #3
5
void HAL_LedSet(ST_LedInit_t *pstLedInit, EN_Led_Value_t enLedValue)
{
  HAL_GPIO_WritePin(pstLedInit->pvGPIOPort, pstLedInit->pvInitStruct.Pin, (GPIO_PinState)enLedValue);
}
コード例 #4
1
ファイル: Tumbler3BSP.c プロジェクト: glocklueng/myLib
void StatusLED_Off_T3B(StatusLED_T3B_TypeDef Led) {
	HAL_GPIO_WritePin(STATUSLED_GPIO_PORT[Led], STATUSLED_GPIO_PIN[Led],
			GPIO_PIN_RESET);
}
コード例 #5
0
ファイル: lsm303d.c プロジェクト: fhtthg/my_pix4
void LSM303D_CS_ENABLE(void)
{
    HAL_GPIO_WritePin(LSM303D_CS_PORT, LSM303D_CS_PIN, GPIO_PIN_RESET);
}
コード例 #6
0
ファイル: main.c プロジェクト: eleciawhite/STM32Cube
/**
  * @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;

    }
}
コード例 #7
0
/**
  * @brief  Turns selected LED Off.
  * @param  Led: Specifies the Led to be set off. 
  *   This parameter can be one of following parameters:
  *     @arg LED4
  *     @arg LED3
  *     @arg LED5
  *     @arg LED6 
  */
void BSP_LED_Off(Led_TypeDef Led)
{
  HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET); 
}
コード例 #8
0
ファイル: st7789.c プロジェクト: wosayttn/aos
/********************************************************************
*
*       LcdWriteDataMultiple
*
* Function description:
*   Writes multiple values to a display register.
*/
void LcdWriteDataMultiple(uint8_t * pData, int NumItems) 
{
  HAL_GPIO_WritePin(LCD_DCX_GPIO_Port, LCD_DCX_Pin, GPIO_PIN_SET);
  HAL_SPI_Transmit(&hspi1, pData, NumItems, 10);
}
コード例 #9
0
ファイル: max1301.c プロジェクト: hampussandberg/HexConnect
/**
 * @brief	Pull the CS pin HIGH
 * @param	None
 * @retval	None
 */
static inline void prvADC_CS_HIGH()
{
	HAL_GPIO_WritePin(ADC_PORT, ADC_CS_PIN, GPIO_PIN_SET);
}
コード例 #10
0
ファイル: leds.c プロジェクト: drmetal/lollyjar
void set_led(uint8_t led)
{
    HAL_GPIO_WritePin(leds[led].port, leds[led].pin, GPIO_PIN_SET);
}
コード例 #11
0
// 输出比较 回调函数
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
{
  uint16_t delay_new = 0;
  // TIM4
  if (htim->Instance == TIM4) {
    // 1
    // 排烟风机 通道
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
      // 排烟风机 delay_on, 打开输出
      // 输出:On
      HAL_GPIO_WritePin(PORT_SCR, SCR0_smoke, GPIO_PIN_RESET);
      HAL_TIM_OC_Stop_IT( &htim4, TIM_CHANNEL_1);

      // 启动波峰
      if (is_lower_blow) {
        is_lower_blow = false;
        delay_new = __HAL_TIM_GET_COMPARE(&htim4, TIM_CHANNEL_1);
        __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, delay_new + 10000 - 1);
        HAL_TIM_OC_Start_IT( &htim4, TIM_CHANNEL_1); 
      }
      
      //设置停止时间
      delay_new = __HAL_TIM_GET_COMPARE(&htim1, TIM_CHANNEL_1);
      __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, delay_new + uS_DELAY_OFF);
      
      // 启动定时器
      HAL_TIM_OC_Start_IT( &htim1, TIM_CHANNEL_1); 
    }
    
    // 2
    // 循环风机通道
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) {      
      // 循环风机 delay_on, 打开输出
      // 输出:On
      HAL_GPIO_WritePin(PORT_SCR, SCR1_exchange, GPIO_PIN_RESET);
      HAL_TIM_OC_Stop_IT( &htim4, TIM_CHANNEL_2);
      
      // 启动波峰
      if (is_lower_exchange) {
        is_lower_exchange = false;
        delay_new = __HAL_TIM_GET_COMPARE(&htim4, TIM_CHANNEL_2);
        __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, delay_new + 10000 - 1);
        HAL_TIM_OC_Start_IT( &htim4, TIM_CHANNEL_2); 
        
      }
      //设置停止时间
      uint16_t delay_new = __HAL_TIM_GET_COMPARE(&htim1, TIM_CHANNEL_2);
      __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, delay_new + uS_DELAY_OFF);
      // 启动定时器
      HAL_TIM_OC_Start_IT( &htim1, TIM_CHANNEL_2);      
    }
    
    // 3
    // 送料电机 通道
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3) {
      HAL_GPIO_WritePin(PORT_SCR, SCR2_feed, GPIO_PIN_RESET);      
      HAL_TIM_OC_Stop_IT( &htim4, TIM_CHANNEL_3);
      
      // 启动波峰
      if (is_lower_feed) {
        is_lower_feed = false;
        uint16_t delay_new = __HAL_TIM_GET_COMPARE(&htim4, TIM_CHANNEL_3);
        __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, delay_new + 10000 - 1);
        HAL_TIM_OC_Start_IT( &htim4, TIM_CHANNEL_3); 
        
      }
      //设置停止时间
      uint16_t delay_new = __HAL_TIM_GET_COMPARE(&htim1, TIM_CHANNEL_3);
      __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_3, delay_new + uS_DELAY_OFF);
      
    }
    
  }  
  // TIM1  
  // 延时1ms关闭触发
  if (htim->Instance == TIM1) {
    // 1
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
      HAL_GPIO_WritePin(PORT_SCR, SCR0_smoke, GPIO_PIN_SET);
      HAL_TIM_OC_Stop_IT( &htim1, TIM_CHANNEL_1);
    }
    
    // 2
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) {
      // 输出 循环:Off
      HAL_GPIO_WritePin(PORT_SCR, SCR1_exchange, GPIO_PIN_SET);
      HAL_TIM_OC_Stop_IT( &htim1, TIM_CHANNEL_2);
    }
    
    // 3
    if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3) {
      // 输出 送料: Off
      HAL_GPIO_WritePin(PORT_SCR, SCR2_feed, GPIO_PIN_SET);
      HAL_TIM_OC_Stop_IT( &htim1, TIM_CHANNEL_3);
    }
    
  }  // TIM1
 //
  
}
コード例 #12
0
ファイル: main.c プロジェクト: MrZANE42/verisure1512
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  GPIO_InitTypeDef  GPIO_InitStruct;

  /* Enable the CPU Cache */
  CPU_CACHE_Enable();
  
  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator on ITCM interface
       - 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.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 216 MHz */
  SystemClock_Config();

  /* Enable GPIO Clock */
  __HAL_RCC_GPIOB_CLK_ENABLE();
  
  /* Configure the GPIO pins: used to display the 4 wave forms */
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  
  /* Configure PB.00 to display wave form of channel1 */
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  
  /* Configure PB.01 to display wave form of channel2 */
  GPIO_InitStruct.Pin = GPIO_PIN_1;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  
  /* Configure PB.02 to display wave form of channel3 */  
  GPIO_InitStruct.Pin = GPIO_PIN_2;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  
  /* Configure PB.03 to display wave form of channel4 */
  GPIO_InitStruct.Pin = GPIO_PIN_3;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /* Compute the prescaler value to have TIMx counter clock equal to 10 kHz */
  uwPrescalerValue = ((SystemCoreClock) / 10000) - 1;

  /*##-1- Configure the TIM peripheral #######################################*/ 
  /* Initialize TIMx peripheral as follow:
       + Prescaler = (SystemCoreClock)/10000 - 1;
       + Period = 65535
       + ClockDivision = 0
       + Counter direction = Up
  */
  TimHandle.Instance = TIM1;
  
  TimHandle.Init.Period        = 65535;
  TimHandle.Init.Prescaler     = uwPrescalerValue;
  TimHandle.Init.ClockDivision = 0;
  TimHandle.Init.CounterMode   = TIM_COUNTERMODE_UP;
  if(HAL_TIM_OC_Init(&TimHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
  
  /*##-2- Configure the Output Compare channels #########################################*/ 
  /* Common configuration for all channels */
  sConfig.OCMode     = TIM_OCMODE_INACTIVE;
  sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;

  /* Set the pulse (delay1)  value for channel 1 */
  sConfig.Pulse = PULSE1_VALUE;  
  if(HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1) != HAL_OK)
  {
    /* Configuration Error */
    Error_Handler();
  }
  
  /* Set the pulse (delay2) value for channel 2 */
  sConfig.Pulse = PULSE2_VALUE;
  if(HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2) != HAL_OK)
  {
    /* Configuration Error */
    Error_Handler();
  }
  
  /* Set the pulse (delay3) value for channel 3 */
  sConfig.Pulse = PULSE3_VALUE;
  if(HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_3) != HAL_OK)
  {
    /* Configuration Error */
    Error_Handler();
  }
  
  /* Set the pulse (delay4) value for channel 4 */
  sConfig.Pulse = PULSE4_VALUE;
  if(HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_4) != HAL_OK)
  {
    /* Configuration Error */
    Error_Handler();
  }
  
  /*##-3- Set GPIO Pins PB.00, PB.01, PB.02 and PB.03 as reference ###################*/ 
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_2, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);
    
  /*##-4- Start signals generation #######################################*/ 
  /* Start channel 1 in Output compare mode */
  if(HAL_TIM_OC_Start_IT(&TimHandle, TIM_CHANNEL_1) != HAL_OK)
  {
    /* Starting Error */
    Error_Handler();
  }
  /* Start channel 2 in Output compare mode */
  if(HAL_TIM_OC_Start_IT(&TimHandle, TIM_CHANNEL_2) != HAL_OK)
  {
    /* Starting Error */
    Error_Handler();
  }
  /* Start channel 3 in Output compare mode */
  if(HAL_TIM_OC_Start_IT(&TimHandle, TIM_CHANNEL_3) != HAL_OK)
  {
    /* Starting Error */
    Error_Handler();
  }
  /* Start channel 4 in Output compare mode */
  if(HAL_TIM_OC_Start_IT(&TimHandle, TIM_CHANNEL_4) != HAL_OK)
  {
    /* Starting Error */
    Error_Handler();
  }

  while (1)
  {
  }
}
コード例 #13
0
/** Configure pins as 
        * Analog 
        * Input 
        * Output
        * EVENT_OUT
        * EXTI
     PA10   ------> USB_OTG_FS_ID
     PA11   ------> USB_OTG_FS_DM
     PA12   ------> USB_OTG_FS_DP
*/
void MX_GPIO_Init(void)
{

    GPIO_InitTypeDef GPIO_InitStruct;

    /* GPIO Ports Clock Enable */
    __GPIOC_CLK_ENABLE();
    __GPIOH_CLK_ENABLE();
    __GPIOA_CLK_ENABLE();
    __GPIOB_CLK_ENABLE();
    __GPIOD_CLK_ENABLE();


    HAL_GPIO_WritePin(GPIO_BOARD_KILL_PORT, GPIO_BOARD_KILL_PIN, GPIO_PIN_SET);

    GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15|GPIO_PIN_6|GPIO_PIN_7 
                          |GPIO_PIN_8|GPIO_PIN_14;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_15;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_1;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    //---------------------------------------------------------------------------------
    // Initialize Power Kill Pin
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
    GPIO_InitStruct.Pin = GPIO_PIN_9;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    //---------------------------------------------------------------------------------
    // Initialize LED GPIOs
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

    // Port A LED GPIOs
    GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    // Port B LED GPIOs
    GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    // Port C LED GPIOs
    GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_7|GPIO_PIN_8;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    // Port D LED GPIOs
    GPIO_InitStruct.Pin = GPIO_PIN_2;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

    // THIS ONE DOESNT SEEM TO WORK
    // Port H LED GPIOs
    GPIO_InitStruct.Pin = GPIO_PIN_1;
    HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);

    //---------------------------------------------------------------------------------

    GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_2;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_12;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

}
コード例 #14
0
ファイル: main.c プロジェクト: li3p/F4-DiscoverFree
int main(void) {

	/* USER CODE BEGIN 1 */

	/* USER CODE END 1 */

	/* MCU Configuration----------------------------------------------------------*/

	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
	HAL_Init();

	/* Configure the system clock */
	SystemClock_Config();

	/* Initialize all configured peripherals */
	MX_GPIO_Init();
	MX_USART3_UART_Init();
	MX_SPI1_Init();
	MX_SPI2_Init();

	/* USER CODE BEGIN 2 */

	uint8_t init_bytes[] = { 0x07, 0x40, 0xC0, 0x01, 0x00, 0x8C, 0x8E, 0x00 };

	for (int i = 0; i < 2; i++) {
		HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET);
		HAL_SPI_Transmit(&hspi1, (uint8_t*) (&init_bytes[i]), 1, 1000);
		HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET);
	}

	for (int i = 0; i < 0x16; i++) {
		HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET);
		HAL_SPI_Transmit(&hspi1, (uint8_t*) (&init_bytes[2]), 1, 1000);
		HAL_SPI_Transmit(&hspi1, (uint8_t*) (&init_bytes[4]), 1, 1000);
		init_bytes[2]++;
		HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET);
	}

	HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET);
	HAL_SPI_Transmit(&hspi1, (uint8_t*) (&init_bytes[5]), 1, 1000);
	HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET);

//	ds3234_set_time();
	vfd_display();

	ds3234_set_reg(DS3234_REG_CONTROL, 0x00);

//	vfd_write_display_flag(0x03, 0x04);
//	vfd_write_display_flag(0x0F, 0x03);

	while (1) {
	};

	/* USER CODE END 2 */

	/* USER CODE BEGIN RTOS_MUTEX */
	/* add mutexes, ... */
	/* USER CODE END RTOS_MUTEX */

	/* USER CODE BEGIN RTOS_SEMAPHORES */
	/* add semaphores, ... */
	/* USER CODE END RTOS_SEMAPHORES */

	/* USER CODE BEGIN RTOS_TIMERS */
	/* start timers, add new ones, ... */
	/* USER CODE END RTOS_TIMERS */

	/* Create the thread(s) */
	/* definition and creation of defaultTask */
	osThreadDef(defaultTask, StartDefaultTask, osPriorityIdle, 0, 128);
	defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

	/* definition and creation of myTask02 */
	osThreadDef(myTask02, StartTask02, osPriorityNormal, 0, 128);
	myTask02Handle = osThreadCreate(osThread(myTask02), NULL);

	/* definition and creation of myTask03 */
	osThreadDef(myTask03, StartTask03, osPriorityNormal, 0, 128);
	myTask03Handle = osThreadCreate(osThread(myTask03), NULL);

	/* definition and creation of myTask01 */
	osThreadDef(myTask01, StartTask01, osPriorityNormal, 0, 128);
	myTask01Handle = osThreadCreate(osThread(myTask01), NULL);

	/* definition and creation of myTask04 */
	osThreadDef(myTask04, StartTask04, osPriorityNormal, 0, 128);
	myTask04Handle = osThreadCreate(osThread(myTask04), NULL);

	/* USER CODE BEGIN RTOS_THREADS */
	/* add threads, ... */
	/* USER CODE END RTOS_THREADS */

	/* USER CODE BEGIN RTOS_QUEUES */
	/* add queues, ... */
	/* USER CODE END RTOS_QUEUES */

	/* Start scheduler */
	osKernelStart();

	/* We should never get here as control is now taken by the scheduler */

	/* Infinite loop */
	/* USER CODE BEGIN WHILE */
	char i = 0;

	while (1) {
		/* USER CODE END WHILE */

		/* USER CODE BEGIN 3 */

		HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
		HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);
		HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin);
		HAL_GPIO_TogglePin(LED4_GPIO_Port, LED4_Pin);

		aTxBuffer[30] = ((i++) % 10) + '0';
		HAL_UART_Transmit(&huart3, aTxBuffer, RXBUFFERSIZE, 5000);
		HAL_Delay(1000);
	}
	/* USER CODE END 3 */

}
コード例 #15
0
/** Configure pins as 
        * Analog 
        * Input 
        * Output
        * EVENT_OUT
        * EXTI
*/
static void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  GPIO_InitStruct.Pin = GPIO_PIN_All;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_INPUT;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  // Clear the B8,B9 lines
  GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOC, LCD_A0_Pin|MOD4_GPIO2_Pin|MOD3_GPIO2_Pin|MOD2_GPIO2_Pin 
                          |WIFI_EN_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, MOD1_GPIO2_Pin|LCD_BL_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, MOD2_GPIO1_Pin|MOD4_GPIO1_Pin|LCD_RST_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pins : LCD_A0_Pin MOD4_GPIO2_Pin MOD3_GPIO2_Pin MOD2_GPIO2_Pin 
                           WIFI_EN_Pin */
  GPIO_InitStruct.Pin = LCD_A0_Pin|MOD4_GPIO2_Pin|MOD3_GPIO2_Pin|MOD2_GPIO2_Pin 
                          |WIFI_EN_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pins : MOD1_GPIO2_Pin LCD_BL_Pin */
  GPIO_InitStruct.Pin = MOD1_GPIO2_Pin|LCD_BL_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : MOD2_GPIO1_Pin MOD4_GPIO1_Pin LCD_RST_Pin */
  GPIO_InitStruct.Pin = MOD2_GPIO1_Pin|MOD4_GPIO1_Pin|LCD_RST_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pins : SW_D_Pin SW_E_Pin */
  GPIO_InitStruct.Pin = SW_D_Pin|SW_E_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  // Configure pins for I2C
  GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin : VCAP1_Pin */
  GPIO_InitStruct.Pin = VCAP1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  HAL_GPIO_Init(VCAP1_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : BATT_STAT_Pin */
  GPIO_InitStruct.Pin = BATT_STAT_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(BATT_STAT_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : SW_A_Pin */
  GPIO_InitStruct.Pin = SW_A_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(SW_A_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : SW_B_Pin */
  GPIO_InitStruct.Pin = SW_B_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(SW_B_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : SW_C_Pin */
  GPIO_InitStruct.Pin = SW_C_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(SW_C_GPIO_Port, &GPIO_InitStruct);

}
コード例 #16
0
ファイル: main.c プロジェクト: mrengineer/KaijaSensor
/** Configure pins as 
        * Analog 
        * Input 
        * Output
        * EVENT_OUT
        * EXTI
*/
void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __GPIOC_CLK_ENABLE();
  __GPIOA_CLK_ENABLE();
  __GPIOB_CLK_ENABLE();
  __GPIOD_CLK_ENABLE();

  /*Configure GPIO pin : ACC_INT2_Pin */
  GPIO_InitStruct.Pin = ACC_INT2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(ACC_INT2_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : nDISCHARGE_Pin */
  GPIO_InitStruct.Pin = nDISCHARGE_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_VERY_LOW;
  HAL_GPIO_Init(nDISCHARGE_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : PWR_TO_2_8V_Pin ENABLE_2_5V_Pin INDICATOR2_Pin WIFI_PWR_Pin */
  GPIO_InitStruct.Pin = PWR_TO_2_8V_Pin|ENABLE_2_5V_Pin|INDICATOR2_Pin|WIFI_PWR_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_VERY_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pin : ACC_INT1_Pin */
  GPIO_InitStruct.Pin = ACC_INT1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(ACC_INT1_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : STATUS_Pin ACC_CS_Pin HALL_CLAMP_PWR_Pin INDICATOR3_Pin */
  GPIO_InitStruct.Pin = STATUS_Pin|ACC_CS_Pin|HALL_CLAMP_PWR_Pin|INDICATOR3_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_VERY_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : SENS_CLAMP_A_Pin SENS_TAKEOFF_Pin */
  GPIO_InitStruct.Pin = SENS_CLAMP_A_Pin|SENS_TAKEOFF_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pins : SHUNT_0_06_DISABLE_Pin RF_CE_Pin */
  GPIO_InitStruct.Pin = SHUNT_0_06_DISABLE_Pin|RF_CE_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
  GPIO_InitStruct.Speed = GPIO_SPEED_VERY_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin : HALL_SENS_PWR_Pin */
  GPIO_InitStruct.Pin = HALL_SENS_PWR_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_VERY_LOW;
  HAL_GPIO_Init(HALL_SENS_PWR_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : RF_PWR_Pin SD_PWR_Pin */
  GPIO_InitStruct.Pin = RF_PWR_Pin|SD_PWR_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_VERY_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PWR_TO2_8AND2_9V_Pin INDICATOR1_Pin */
  GPIO_InitStruct.Pin = PWR_TO2_8AND2_9V_Pin|INDICATOR1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_VERY_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pins : SENS_CLAMP_B_Pin RF_IRQ_Pin SENS_OPEN_Pin */
  GPIO_InitStruct.Pin = SENS_CLAMP_B_Pin|RF_IRQ_Pin|SENS_OPEN_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOC, nDISCHARGE_Pin|WIFI_PWR_Pin, GPIO_PIN_SET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOC, PWR_TO_2_8V_Pin|ENABLE_2_5V_Pin|INDICATOR2_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, STATUS_Pin|ACC_CS_Pin|HALL_CLAMP_PWR_Pin|INDICATOR3_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, SHUNT_0_06_DISABLE_Pin|HALL_SENS_PWR_Pin|RF_CE_Pin|PWR_TO2_8AND2_9V_Pin 
                          |INDICATOR1_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, RF_PWR_Pin|SD_PWR_Pin, GPIO_PIN_SET);

}
コード例 #17
0
ファイル: gpio.c プロジェクト: Vadim-Stupakov/ProjectX
/** Configure pins as 
        * Analog 
        * Input 
        * Output
        * EVENT_OUT
        * EXTI
     PC3   ------> I2S2_SD
     PA4   ------> I2S3_WS
     PA5   ------> SPI1_SCK
     PA6   ------> SPI1_MISO
     PA7   ------> SPI1_MOSI
     PB10   ------> I2S2_CK
     PC7   ------> I2S3_MCK
     PC10   ------> I2S3_CK
     PC12   ------> I2S3_SD
     PB6   ------> I2C1_SCL
     PB9   ------> I2C1_SDA
*/
void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __GPIOE_CLK_ENABLE();
  __GPIOC_CLK_ENABLE();
  __GPIOH_CLK_ENABLE();
  __GPIOA_CLK_ENABLE();
  __GPIOB_CLK_ENABLE();
  __GPIOD_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(CS_I2C_SPI_GPIO_Port, CS_I2C_SPI_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin 
                          |Audio_RST_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = CS_I2C_SPI_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(CS_I2C_SPI_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = PDM_OUT_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  HAL_GPIO_Init(PDM_OUT_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PA4 */
  GPIO_InitStruct.Pin = GPIO_PIN_4;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PA5 PA6 PA7 */
  GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = BOOT1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(BOOT1_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = CLK_IN_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  HAL_GPIO_Init(CLK_IN_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : PDPin PDPin PDPin PDPin 
                           PDPin */
  GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin 
                          |Audio_RST_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /*Configure GPIO pins : PC7 PCPin PC12 */
  GPIO_InitStruct.Pin = GPIO_PIN_7|I2S3_SCK_Pin|GPIO_PIN_12;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : PBPin PBPin */
  GPIO_InitStruct.Pin = Audio_SCL_Pin|Audio_SDA_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = MEMS_INT1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(MEMS_INT1_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PtPin */
  GPIO_InitStruct.Pin = MEMS_INT2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(MEMS_INT2_GPIO_Port, &GPIO_InitStruct);

}
コード例 #18
0
ファイル: main-ex2.c プロジェクト: Shreeyak/mastering-stm32
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
  if(GPIO_Pin == GPIO_PIN_13)
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, SET);
  else
    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, RESET);
}
コード例 #19
0
ファイル: max1301.c プロジェクト: hampussandberg/HexConnect
/**
 * @brief	Pull the CS pin LOW
 * @param	None
 * @retval	None
 */
static inline void prvADC_CS_LOW()
{
	HAL_GPIO_WritePin(ADC_PORT, ADC_CS_PIN, GPIO_PIN_RESET);
}
コード例 #20
0
/**
   * @brief A function used to compare user input angle with the actual angle, and blink LEDs accordingly
	 * @param none
	 * @retval 
   */
void compare_user_actual_angle(void)
{
	float neg_roll = roll*(-1);
	float neg_threshold = threshold*(-1);
	//check if the threshold has been set
	if(threshold_set_flag) {
		
		//if less than the threshold, blink LD3(orange) to tell user to lower the board in that direction
		if((roll > 0 && roll < (threshold-THRESHOLD_TOLERANCE)) || (roll < 0 && roll < (neg_threshold-THRESHOLD_TOLERANCE))) {
			
			if(count_for_animation>=700 && count_for_animation<1000) {
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
			} else {
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
			}
			
			HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_RESET);
			
			
		//if less than the threshold, blink LD6(blue) to tell user to lower the board in that direction
		} else if((roll > 0 && roll > (threshold+THRESHOLD_TOLERANCE)) || (roll < 0 && roll > (neg_threshold+THRESHOLD_TOLERANCE))) {
			if(count_for_animation>=700 && count_for_animation<1000) {
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);
			} else {
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
			}
			HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_12, GPIO_PIN_RESET);
			
			
			
		//if within range, blink all LEDs to tell user that the board pitch/roll angle is within defined range
		} else {
			if(count_for_animation>=700 && count_for_animation<1000) {
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15, GPIO_PIN_RESET);
			} else {
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
				HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
			}
		}
		count_for_animation++;
		
		//reset the counter to 0
		if(count_for_animation==1000) count_for_animation = 0;
	}
}
コード例 #21
0
ファイル: keyboard.c プロジェクト: WeSpeakEnglish/STM32PLC
void SetLineKbd(uint8_t Number){
  switch(Number){
    case 0: 
      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10,GPIO_PIN_SET);
      break;
    case 1: 
      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7,GPIO_PIN_SET);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9|GPIO_PIN_10,GPIO_PIN_SET);   
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8,GPIO_PIN_RESET);        
      break;  
    case 2: 
      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7,GPIO_PIN_SET);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8|GPIO_PIN_10,GPIO_PIN_SET);   
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9,GPIO_PIN_RESET); 
      break;
    case 3: 
      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7,GPIO_PIN_SET);
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8|GPIO_PIN_9,GPIO_PIN_SET);   
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10,GPIO_PIN_RESET);
  }
return;
}
コード例 #22
0
ファイル: main1.c プロジェクト: dongkc/cleaner
__task void power (void)
 {
   unsigned int count =0;
   unsigned int temp;
	 static GPIO_InitTypeDef  GPIO_InitStruct;
	 GPIO_PinState bitstatus;
  
   while(1)
     {
	      GPIO_InitStruct.Pin = GPIO_PIN_2;
        GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
        GPIO_InitStruct.Pull = GPIO_PULLUP;
        GPIO_InitStruct.Speed = GPIO_SPEED_FAST;  
        HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 	  
	      bitstatus   =   HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_2);	      
        if(bitstatus==GPIO_PIN_RESET)
				{			
             os_dly_wait (200);
             bitstatus   =   HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_2);
					   if(bitstatus==GPIO_PIN_RESET)
						 {	 
							 
							   if(HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR6)==0)
								 {
												count =0;
											 do{
															 bitstatus   =   HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_2);
															 count++;
															 if(count>5000000)
															 {       
																			 Time3Disable();
																			 GUI_Clear();                                 												 
																			 HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET);  
																			 HAL_GPIO_WritePin(GPIOE,GPIO_PIN_2,GPIO_PIN_RESET);  
																			 if(zhuantskid  !=NULL)  os_tsk_delete(zhuantskid);   
																			 if(maintskid   !=NULL)  os_tsk_delete(maintskid);   
																			 if(keytskid    !=NULL)  os_tsk_delete(keytskid);  
																			 if(servertskid !=NULL)  os_tsk_delete(servertskid);  
																			 if(meuntskid !=NULL)  os_tsk_delete(meuntskid);  
																			 if(setsystemtimetskid !=NULL)  os_tsk_delete(setsystemtimetskid);  
																			 if(setledlighttskid !=NULL)  os_tsk_delete(setledlighttskid);  
																			 if(setledtimetskid !=NULL)  os_tsk_delete(setledtimetskid);  
																			 if(setsoundtskid !=NULL)  os_tsk_delete(setsoundtskid);   													 
																			 if(setworkmodetskid !=NULL)  os_tsk_delete(setworkmodetskid);  
																			 if(yushentskid !=NULL)  os_tsk_delete(yushentskid);

                                       HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR6,1);  		// 说明是正常关机状态;

                                       														 
                                       HAL_GPIO_WritePin(GPIOG,GPIO_PIN_3,GPIO_PIN_RESET);  
																			 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_2,GPIO_PIN_SET);  
                                     											 
																	 
															 } 	 
													 
												 }while(bitstatus==GPIO_PIN_RESET); 	
									}else
                  {
                         os_mut_init(mut_GLCD);
	 
												 os_mut_init(mut_Gclock);
												
												 GUI_UC_SetEncodeUTF8();   
												 
												 zhuantskid = os_tsk_create (zhuan1, 0);
												 maintskid  = os_tsk_create (Main_Task, 0);  
												 keytskid   = os_tsk_create (phase_KEY, 0);    
												 servertskid = os_tsk_create (Server_Task, 0);   
                         Time3Enable(HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR1));
                        
										     HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_RESET);  
												 HAL_GPIO_WritePin(GPIOE,GPIO_PIN_2,GPIO_PIN_SET);  
										
                         HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR6,0);  // 清楚掉关机状态 	
                  }										
					
	           }
	  
	      }
     
	    }    
   
 }
コード例 #23
0
/**************************************************************************
*                           BlueNRG_GPIO_Init
*
* @brief  This function is used for low level initialization of the SPI
*         communication support with the BlueNRG Expansion Board.
*
* @param  Pointer to the handle of the STM32Cube HAL SPI interface.
* @retval None
*************************************************************************/
void  BlueNRG_GPIO_Init (SPI_HandleTypeDef* hspi)
{
  GPIO_InitTypeDef  GPIO_InitStruct;


//  09/13/15        ---- NO ONE CALLS THIS LOGIC ANYMORE !!! ----
//                   is now handled in mnet_connect_network()

         //---------------------------------------------------
         // Configure GPIOs for control of BLE NRG module
         //---------------------------------------------------

         //---------------------------------------------------
         // Configure RESET pin:  PA8 - Arduino D7 on Nucleo.
         //---------------------------------------------------
    pin_Config (BLE_BLUENRG_RESET, GPIO_OUTPUT, PIN_USE_PULLUP);
    pin_Low (BLE_BLUENRG_RESET);    // and set it LOW, to prevent spurius interrupts during config

         //-------------------------------------------------------------------
         // Configure SPI CS pin:  PA1 - Arduino A1 on Nucleo.
         //
         // Rest of SPI pins will be auto-configured on spi_Init call (below)
         //-------------------------------------------------------------------
    pin_Config (BLE_BLUENRG_SPI_CS, GPIO_OUTPUT, PIN_USE_PULLUP);
    pin_High (BLE_BLUENRG_SPI_CS);  // and set it HIGH, to De-Assert CS during config

         //---------------------------------------------------
         // Configure IRQ pin:  PA0 - Arduino A0 on Nucleo
         //---------------------------------------------------
    pin_Config_IRQ_Pin (BLE_BLUENRG_IRQ_PIN, GPIO_RUPT_MODE_RISING, 0, BLE_BLUENRG_IRQn, 4);

         // and setup associated NVIC EXTI entries
    HAL_NVIC_SetPriority (BLE_BLUENRG_IRQn, 4, 0);
    HAL_NVIC_EnableIRQ (BLE_BLUENRG_IRQn);


#if WVD_SHUTOFF                              // 06/20/15 - debug L0 issues
  if (hspi->Instance == BNRG_SPI_INSTANCE)   // 0620/15 - L0 is skipping this ==> wrong instance ???
    {
        /* Enable GPIO Ports Clock */
    BNRG_SPI_RESET_CLK_ENABLE();
    BNRG_SPI_SCLK_CLK_ENABLE();
    BNRG_SPI_MISO_CLK_ENABLE();
    BNRG_SPI_MOSI_CLK_ENABLE();
    BNRG_SPI_CS_CLK_ENABLE();
    BNRG_SPI_IRQ_CLK_ENABLE();

        /* Enable SPI clock */
    BNRG_SPI_CLK_ENABLE();

        /* Reset */
    GPIO_InitStruct.Pin       = BNRG_SPI_RESET_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_RESET_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_RESET_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_RESET_SPEED;
    GPIO_InitStruct.Alternate = BNRG_SPI_RESET_ALTERNATE;
    HAL_GPIO_Init (BNRG_SPI_RESET_PORT, &GPIO_InitStruct);
    HAL_GPIO_WritePin (BNRG_SPI_RESET_PORT, BNRG_SPI_RESET_PIN, GPIO_PIN_RESET); // force RESET
	/* Added to avoid spurious interrupt from the BlueNRG */
#endif

        /* SCLK */
    GPIO_InitStruct.Pin       = BNRG_SPI_SCLK_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_SCLK_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_SCLK_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_SCLK_SPEED;
    GPIO_InitStruct.Alternate = BNRG_SPI_SCLK_ALTERNATE;
    HAL_GPIO_Init(BNRG_SPI_SCLK_PORT, &GPIO_InitStruct);

        /* MISO */
    GPIO_InitStruct.Pin       = BNRG_SPI_MISO_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_MISO_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_MISO_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_MISO_SPEED;
    GPIO_InitStruct.Alternate = BNRG_SPI_MISO_ALTERNATE;
    HAL_GPIO_Init(BNRG_SPI_MISO_PORT, &GPIO_InitStruct);

        /* MOSI */
    GPIO_InitStruct.Pin       = BNRG_SPI_MOSI_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_MOSI_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_MOSI_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_MOSI_SPEED;
    GPIO_InitStruct.Alternate = BNRG_SPI_MOSI_ALTERNATE;
    HAL_GPIO_Init(BNRG_SPI_MOSI_PORT, &GPIO_InitStruct);

#if WVD_SHUTOFF                              // 06/20/15 - debug L0 issues
        /* NSS/CSN/CS */
    GPIO_InitStruct.Pin       = BNRG_SPI_CS_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_CS_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_CS_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_CS_SPEED;
    GPIO_InitStruct.Alternate = BNRG_SPI_CS_ALTERNATE;
    HAL_GPIO_Init (BNRG_SPI_CS_PORT, &GPIO_InitStruct);
    HAL_GPIO_WritePin (BNRG_SPI_CS_PORT, BNRG_SPI_CS_PIN, GPIO_PIN_SET);  // De-Assert BLE CS

        /* IRQ -- INPUT */
    GPIO_InitStruct.Pin       = BNRG_SPI_IRQ_PIN;
    GPIO_InitStruct.Mode      = BNRG_SPI_IRQ_MODE;
    GPIO_InitStruct.Pull      = BNRG_SPI_IRQ_PULL;
    GPIO_InitStruct.Speed     = BNRG_SPI_IRQ_SPEED;
#if defined(STM32F103xB)
#else
    GPIO_InitStruct.Alternate = BNRG_SPI_IRQ_ALTERNATE;
#endif
    HAL_GPIO_Init (BNRG_SPI_IRQ_PORT, &GPIO_InitStruct);

 #if L0_TESTING_MOVED     // 06/20/15
        /* Configure the NVIC for SPI */
    HAL_NVIC_SetPriority (BNRG_SPI_EXTI_IRQn, 4, 0);
    HAL_NVIC_EnableIRQ (BNRG_SPI_EXTI_IRQn);
 #endif
   }
#endif                              // WVD_SHUTOFF

}
コード例 #24
0
/**
* @brief  Sets the level of a specified GPIO.
* @param  xGpio Specifies the GPIO to be set.
*         This parameter can be one of following parameters:
*         @arg GPIO_0
*         @arg GPIO_1
*         @arg GPIO_2
*         @arg GPIO_3
* @param  GPIO_PinState Level of the GPIO. This parameter can be:
*         GPIO_PIN_SET or GPIO_PIN_RESET.
* @retval None.
*/
void RadioGpioSetLevel(RadioGpioPin xGpio, GPIO_PinState xState)
{
  /* Sets the GPIO level */
  HAL_GPIO_WritePin(aRADIO_GPIO_PORT[xGpio], aRADIO_GPIO_PIN[xGpio], xState); 
}
コード例 #25
0
ファイル: main.c プロジェクト: pengphei/STM32Cube_L0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  GPIO_InitTypeDef  GPIO_InitStruct;
  
 /* This sample code shows how to use STM32L0xx TIM HAL API to generate 4 PWM
  signals */
  
  /* STM32L0xx 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();
  
  /* Enable GPIO Clock */
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
  
  /* Configure the GPIO pins: used to display the 4 wave forms */
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH  ;
  
  /* Configure PC4 to display wave form of channel1 */
  GPIO_InitStruct.Pin = GPIO_PIN_4;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  
  /* Configure PA5 to display wave form of channel2 */
  GPIO_InitStruct.Pin = GPIO_PIN_5;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
  /* Configure PC5 to display wave form of channel3 */  
  GPIO_InitStruct.Pin = GPIO_PIN_5;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  
  /* Configure PB0 to display wave form of channel4 */
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  
  /* Compute the prescaler value to have TIM2 counter clock equal to 1 KHz */
  uwPrescalerValue = ((SystemCoreClock) / 1000) - 1;

  
  /*##-1- Configure the TIM peripheral #######################################*/ 
  /* Initialize TIM2 peripheral as follow:
       + Prescaler = (SystemCoreClock)/1000
       + Period = 65535
       + ClockDivision = 0
       + Counter direction = Up
  */
  TimHandle.Instance = TIM2;
  
  TimHandle.Init.Period        = 65535;
  TimHandle.Init.Prescaler     = uwPrescalerValue;
  TimHandle.Init.ClockDivision = 0;
  TimHandle.Init.CounterMode   = TIM_COUNTERMODE_UP;
  if(HAL_TIM_OC_Init(&TimHandle) != HAL_OK)
  {
    /* Initialization Error */
    ErrorHandler();
  }
  
  /*##-2- Configure the Output Compare channels ##############################*/ 
  /* Common configuration for all channels */
  sConfig.OCMode     = TIM_OCMODE_INACTIVE;
  sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;

  /* Set the pulse (delay1)  value for channel 1 */
  sConfig.Pulse = PULSE1_VALUE;  
  if(HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1) != HAL_OK)
  {
    /* Configuration Error */
    ErrorHandler();
  }
  
  /* Set the pulse (delay2) value for channel 2 */
  sConfig.Pulse = PULSE2_VALUE;
  if(HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2) != HAL_OK)
  {
    /* Configuration Error */
    ErrorHandler();
  }
  
  /* Set the pulse (delay3) value for channel 3 */
  sConfig.Pulse = PULSE3_VALUE;
  if(HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_3) != HAL_OK)
  {
    /* Configuration Error */
    ErrorHandler();
  }
  
  /* Set the pulse (delay4) value for channel 4 */
  sConfig.Pulse = PULSE4_VALUE;
  if(HAL_TIM_OC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_4) != HAL_OK)
  {
    /* Configuration Error */
    ErrorHandler();
  }
  
  /*##-3- Set GPIO Pins PC4, PA5, PC5 and PB0 as reference ###################*/ 
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_5, GPIO_PIN_SET);
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
  
  /*##-4- Start signals generation ###########################################*/ 
  /* Start channel 1 in Output compare mode */
  if(HAL_TIM_OC_Start_IT(&TimHandle, TIM_CHANNEL_1) != HAL_OK)
  {
    /* Starting Error */
    ErrorHandler();
  }
  /* Start channel 2 in Output compare mode */
  if(HAL_TIM_OC_Start_IT(&TimHandle, TIM_CHANNEL_2) != HAL_OK)
  {
    /* Starting Error */
    ErrorHandler();
  }
  /* Start channel 3 in Output compare mode */
  if(HAL_TIM_OC_Start_IT(&TimHandle, TIM_CHANNEL_3) != HAL_OK)
  {
    /* Starting Error */
    ErrorHandler();
  }
  /* Start channel 4 in Output compare mode */
  if(HAL_TIM_OC_Start_IT(&TimHandle, TIM_CHANNEL_4) != HAL_OK)
  {
    /* Starting Error */
    ErrorHandler();
  }

  while (1)
  {}
}
コード例 #26
0
ファイル: cHal_init.cpp プロジェクト: klaus-liebler/sensact
void cHAL::Init(void) {

	__HAL_RCC_GPIOA_CLK_ENABLE();
	__HAL_RCC_GPIOB_CLK_ENABLE();
	__HAL_RCC_GPIOC_CLK_ENABLE();
	__HAL_RCC_CAN2_CLK_ENABLE();
	__HAL_RCC_CAN1_CLK_ENABLE();
	__HAL_RCC_USART3_CLK_ENABLE();
	__HAL_RCC_UART4_CLK_ENABLE();

	GPIO_InitTypeDef gi;
	HAL_StatusTypeDef status;

	//Enable UART
	gi.Pin = GPIO_PIN_10 | GPIO_PIN_11; //C10=TX, C11=RX
	gi.Mode = GPIO_MODE_AF_PP;
	gi.Pull = GPIO_PULLUP;
	gi.Speed = GPIO_SPEED_LOW;
	gi.Alternate = GPIO_AF7_USART3;
	HAL_GPIO_Init(GPIOC, &gi);
	InitAndTestUSART();

	//Onboard LEDs
	gi.Mode = GPIO_MODE_OUTPUT_PP;
	gi.Alternate = 0;
	gi.Pull = GPIO_NOPULL;
	gi.Speed = GPIO_SPEED_LOW;
	gi.Pin = GPIO_PIN_7;
	HAL_GPIO_Init(GPIOB, &gi);
	LOGI(BSP::SUCCESSFUL_STRING, "GPIO for LED");

	if(InitDWTCounter())
	{
		LOGI(BSP::SUCCESSFUL_STRING, "DWTCounter");
	}
	else
	{
		LOGE(NOT_SUCCESSFUL_STRING, "DWTCounter");
	}

	//MP3-Player
	gi.Pin = GPIO_PIN_0 | GPIO_PIN_1; //A0=USART4_TX, A1=USART4_RX, Kerbe nach oben; ansicht von Pinseite, rechts von oben
	//VCC, RX, TX, DACR, DACL, SPK1, GND, SPK2
	//Also: PA0 --> RX
	gi.Mode = GPIO_MODE_AF_PP;
	gi.Pull = GPIO_PULLUP;
	gi.Speed = GPIO_SPEED_LOW;
	gi.Alternate = GPIO_AF8_UART4;
	HAL_GPIO_Init(GPIOA, &gi);
	BELL.Instance = UART4;
	BELL.Init.BaudRate = 9600;
	BELL.Init.WordLength = UART_WORDLENGTH_8B;
	BELL.Init.StopBits = UART_STOPBITS_1;
	BELL.Init.Parity = UART_PARITY_NONE;
	BELL.Init.Mode = UART_MODE_TX_RX;
	BELL.Init.HwFlowCtl = UART_HWCONTROL_NONE;
	BELL.Init.OverSampling = UART_OVERSAMPLING_16;
	HAL_UART_Init(&BSP::BELL);
	LOGI(SUCCESSFUL_STRING, "UART4 for MP3-Module");

	__I2C1_CLK_ENABLE();
	__I2C2_CLK_ENABLE();
	/*
	 PB08     ------> I2C1_SCL
	 PB09     ------> I2C1_SDA
	 */
	gi.Pin = GPIO_PIN_8 | GPIO_PIN_9;
	gi.Mode = GPIO_MODE_AF_OD;
	gi.Pull = GPIO_PULLUP;
	gi.Speed = GPIO_SPEED_MEDIUM;
	gi.Alternate = GPIO_AF4_I2C1;
	HAL_GPIO_Init(GPIOB, &gi);
	/*
	 PB10     ------> I2C2_SCL
	 PB11     ------> I2C2_SDA
	 */
	gi.Pin = GPIO_PIN_10 | GPIO_PIN_11;
	gi.Mode = GPIO_MODE_AF_OD;
	gi.Pull = GPIO_PULLUP;
	gi.Speed = GPIO_SPEED_MEDIUM;
	gi.Alternate = GPIO_AF4_I2C2;
	HAL_GPIO_Init(GPIOB, &gi);

	i2cbus[0].Instance = I2C1;
	i2cbus[0].Init.ClockSpeed = 100000;
	i2cbus[0].Init.DutyCycle = I2C_DUTYCYCLE_2;
	i2cbus[0].Init.OwnAddress1 = 0;
	i2cbus[0].Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
	i2cbus[0].Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
	i2cbus[0].Init.OwnAddress2 = 0;
	i2cbus[0].Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
	i2cbus[0].Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
	HAL_I2C_Init(&i2cbus[0]);
	LOGI("I2C1 configured for onboard digital io");

	i2cbus[1].Instance = I2C2;
	i2cbus[1].Init.ClockSpeed = 100000;
	i2cbus[1].Init.DutyCycle = I2C_DUTYCYCLE_2;
	i2cbus[1].Init.OwnAddress1 = 0;
	i2cbus[1].Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
	i2cbus[1].Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
	i2cbus[1].Init.OwnAddress2 = 0;
	i2cbus[1].Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
	i2cbus[1].Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
	HAL_I2C_Init(&BSP::i2c2);
	LOGI(BSP::SUCCESSFUL_STRING, "I2C2 for 1wire and external");


	if(drivers::cPCA9685::SoftwareReset(&BSP::i2c1))
	{
		LOGI(SUCCESSFUL_STRING, "i2c1 reset");
	}
	else
	{
		LOGE(NOT_SUCCESSFUL_STRING, "i2c1 reset");
	}


	if(pca9685_U7.Setup())//next to CPU, all A-Pins @ GND b01
	{
		LOGI(SUCCESSFUL_STRING, "pca9685_U7");
	}
	else
	{
		LOGE(NOT_SUCCESSFUL_STRING, "pca9685_U7");
	}
	if(pca9685_U9.Setup())
	{
		LOGI(SUCCESSFUL_STRING, "pca9685_U9");
	}
	else
	{
		LOGE(NOT_SUCCESSFUL_STRING, "pca9685_U9");
	}

	//Interrupt-Pins for PCA9555
	gi.Pin = GPIO_PIN_0|GPIO_PIN_1;
	gi.Mode = GPIO_MODE_INPUT;
	gi.Pull = GPIO_PULLUP;
	HAL_GPIO_Init(GPIOC, &gi);

	if(pca9555_U19.Setup())
	{
		LOGI(BSP::SUCCESSFUL_STRING, "pca9555_U19");
	}
	else
	{
		LOGE(BSP::NOT_SUCCESSFUL_STRING, "pca9555_U19");
	}
	if(pca9555_U18.Setup())
	{
		LOGI(BSP::SUCCESSFUL_STRING, "pca9555_U18");
	}
	else
	{
		LOGE(BSP::NOT_SUCCESSFUL_STRING, "pca9555_U18");
	}

	uint16_t tmp = pca9555_U18.GetInput();
	inputState[WORD_I2C] = (inputState[WORD_I2C] & 0xFFFF0000) + tmp;
	tmp = pca9555_U19.GetInput();
	inputState[WORD_I2C] = (inputState[WORD_I2C] & 0x0000FFFF) + (tmp << 16);

	rcSwitch.enableReceive();






	if(drivers::cPCA9685::SoftwareReset(&BSP::i2c2))
	{
		LOGI(SUCCESSFUL_STRING, "i2c2 reset");
	}
	else
	{
		LOGE(NOT_SUCCESSFUL_STRING, "i2c2 reset");
	}

	SearchI2C("I2C2", &i2c2);
	Init1wire();

	//Enable Rotary Encoder Switch Input
	gi.Mode = GPIO_MODE_INPUT;
	gi.Alternate = 0;
	gi.Pull = GPIO_PULLUP;
	gi.Speed = GPIO_SPEED_LOW;
	gi.Pin = GPIO_PIN_13;
	HAL_GPIO_Init(GPIOC, &gi);
	LOGI(SUCCESSFUL_STRING, "GPIO for Rotary Encoder");
#ifdef DCF77
	//DCF77
	gi.Mode = GPIO_MODE_INPUT;
	gi.Alternate=0;
	gi.Pull=GPIO_PULLUP;
	gi.Speed=GPIO_SPEED_FREQ_LOW;
	gi.Pin=DCF77_PIN;
	HAL_GPIO_Init(DCF77_PORT, &gi);
#endif


#endif
	//=====PWM-Timers
	//===============

	//Overall GPIO-Settings
	//All gpios enabled!
	gi.Mode = GPIO_MODE_AF_PP;
	gi.Pull = GPIO_NOPULL;
	gi.Speed = GPIO_SPEED_HIGH;

	//Overall base timer settings
	TIM_HandleTypeDef TimHandle;
	TimHandle.Init.Prescaler = 0;
	TimHandle.Init.Period = UINT16_MAX;
	TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
	TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;

	//Overall OC-settings
	TIM_OC_InitTypeDef sConfig;
	sConfig.OCMode = TIM_OCMODE_PWM1;
	sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
	sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
	sConfig.OCFastMode = TIM_OCFAST_DISABLE;
	sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
	sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
	sConfig.Pulse = 0;

	//===Slow Timers (84MHz) TIM4 and TIM12
	//TIM1, TIM8		SystemCoreClock/1
	//Others			SystemCoreClock/2
	//Prescaler (uint16_t) ((SystemCoreClock / 1 bzw 2) / TimerTickFrq) - 1;
	//Einstellungen führen zu PWM-Frequenz von 116,5Hz (rechnerisch ermittelt, per LogicAnalyzer bestätigt)



#ifdef SENSACTHS07
	TimHandle.Init.Prescaler = 10; //for 84MHz-Timers
	__TIM12_CLK_ENABLE()
	;
	gi.Pin = GPIO_PIN_14 | GPIO_PIN_15;
	gi.Alternate = GPIO_AF9_TIM12;
	HAL_GPIO_Init(GPIOB, &gi);
	TimHandle.Instance = TIM12;
	HAL_TIM_PWM_Init(&TimHandle);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1); //PB14 O1.1
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2); ///PB15 O1.2
	CLEAR_BIT(TIM12->CCMR1, TIM_CCMR1_OC1PE);
	CLEAR_BIT(TIM12->CCMR1, TIM_CCMR1_OC2PE);
	LOGI(BSP::SUCCESSFUL_STRING, "TIM12");

	//===Fast Timers (168MHz) TIM1 and TIM8
	TimHandle.Init.Prescaler = 20;

	__TIM8_CLK_ENABLE()
	;
	gi.Pin = GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_9;
	gi.Alternate = GPIO_AF3_TIM8;
	HAL_GPIO_Init(GPIOC, &gi);
	TimHandle.Instance = TIM8;
	HAL_TIM_PWM_Init(&TimHandle);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_4);
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1); //C6 O1.3
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2); //C7 O1.4
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_4); //C9 O1.5
	CLEAR_BIT(TIM8->CCMR1, TIM_CCMR1_OC1PE);
	CLEAR_BIT(TIM8->CCMR1, TIM_CCMR1_OC2PE);
	CLEAR_BIT(TIM8->CCMR2, TIM_CCMR2_OC4PE);
	LOGI(SUCCESSFUL_STRING, "TIM8");

	__TIM1_CLK_ENABLE()
	;
	gi.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10;
	gi.Alternate = GPIO_AF1_TIM1;
	HAL_GPIO_Init(GPIOA, &gi);
	TimHandle.Instance = TIM1;
	TIM_ClockConfigTypeDef sClockSourceConfig;
	TIM_MasterConfigTypeDef sMasterConfig;
	TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;


	HAL_TIM_Base_Init(&TimHandle);
	sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
	HAL_TIM_ConfigClockSource(&TimHandle, &sClockSourceConfig);
	HAL_TIM_PWM_Init(&TimHandle);

	sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
	sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
	HAL_TIMEx_MasterConfigSynchronization(&TimHandle, &sMasterConfig);

	sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
	sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
	sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
	sBreakDeadTimeConfig.DeadTime = 0;
	sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
	sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
	sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
	HAL_TIMEx_ConfigBreakDeadTime(&TimHandle, &sBreakDeadTimeConfig);



	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_3);
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1); //A8 O1.6
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2); //A9 O1.7
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_3); //A10 O1.8
	CLEAR_BIT(TIM1->CCMR1, TIM_CCMR1_OC1PE);
	CLEAR_BIT(TIM1->CCMR1, TIM_CCMR1_OC2PE);
	CLEAR_BIT(TIM1->CCMR2, TIM_CCMR2_OC3PE);
	LOGI(SUCCESSFUL_STRING, "TIM1");


#endif
#ifdef SENSACTHS04
	TimHandle.Init.Prescaler = 10; //for 84MHz-Timers

	__TIM4_CLK_ENABLE();
	gi.Pin = GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9;
	gi.Alternate = GPIO_AF2_TIM4;
	HAL_GPIO_Init(GPIOB, &gi);
	TimHandle.Instance = TIM4;
	HAL_TIM_PWM_Init(&TimHandle);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_3);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_4);
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1); //PB6 o2.1
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2); //PB7 o2.2
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_3); //PB8 o1.1
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_4); //PB9 o1.2
	TIM4->CCMR1 &= ~TIM_CCMR1_OC1PE;
	TIM4->CCMR1 &= ~TIM_CCMR1_OC2PE;
	TIM4->CCMR2 &= ~TIM_CCMR2_OC3PE;
	TIM4->CCMR2 &= ~TIM_CCMR2_OC4PE;
	LOGI(SUCCESSFUL_STRING, "TIM4");


	__TIM12_CLK_ENABLE();

	gi.Pin = GPIO_PIN_14 | GPIO_PIN_15;
	gi.Alternate = GPIO_AF9_TIM12;
	HAL_GPIO_Init(GPIOB, &gi);
	TimHandle.Instance = TIM12;
	HAL_TIM_PWM_Init(&TimHandle);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1); //PB14 O7.2
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2); ///PB15 O4.1
	TIM12->CCMR1 &= ~TIM_CCMR1_OC1PE;
	TIM12->CCMR1 &= ~TIM_CCMR1_OC2PE;
	LOGI(SUCCESSFUL_STRING, "TIM12");

	//===Fast Timers (168MHz) TIM1 and TIM8
	TimHandle.Init.Prescaler = 20;

	__TIM1_CLK_ENABLE();

	gi.Pin = GPIO_PIN_8;
	gi.Alternate = GPIO_AF1_TIM1;
	HAL_GPIO_Init(GPIOA, &gi);
	TimHandle.Instance = TIM1;
	HAL_TIM_PWM_Init(&TimHandle);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);

	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_3);
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1);
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_3);

	TIM1->CCMR1 &= ~TIM_CCMR1_OC1PE;

	TIM1->CCMR2 &= ~TIM_CCMR2_OC3PE;
	LOGI(SUCCESSFUL_STRING, "TIM1");

	__TIM8_CLK_ENABLE();

	gi.Pin = GPIO_PIN_6 | GPIO_PIN_7  | GPIO_PIN_9;
	gi.Alternate = GPIO_AF3_TIM8;
	HAL_GPIO_Init(GPIOC, &gi);
	TimHandle.Instance = TIM8;
	HAL_TIM_PWM_Init(&TimHandle);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2);
	HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_4);
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_1);
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_2);
	HAL_TIM_PWM_Start(&TimHandle, TIM_CHANNEL_4);
	TIM8->CCMR1 &= ~TIM_CCMR1_OC1PE;
	TIM8->CCMR1 &= ~TIM_CCMR1_OC2PE;
	TIM8->CCMR2 &= ~TIM_CCMR2_OC4PE;
	LOGI(SUCCESSFUL_STRING, "TIM8");
#endif
	//===SPI for Relais
	//PA15=LATCH,PB3=CLK PB4=MISO, PB5=MOSI
	//DRV8066 DIN=2, CLK([email protected])=3, [email protected] edge=4
	__SPI3_CLK_ENABLE()
	;
	gi.Pin = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5;
	gi.Mode = GPIO_MODE_AF_PP;
	gi.Pull = GPIO_NOPULL;
	gi.Speed = GPIO_SPEED_HIGH;
	gi.Alternate = GPIO_AF6_SPI3;
	HAL_GPIO_Init(GPIOB, &gi);

#ifdef SENSACTHS07
	BSP::spi.Init.DataSize = SPI_DATASIZE_8BIT;
	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET);
	gi.Pin = GPIO_PIN_14;
	gi.Mode = GPIO_MODE_OUTPUT_PP;
	gi.Pull = GPIO_NOPULL;
	gi.Speed = GPIO_SPEED_MEDIUM;
	HAL_GPIO_Init(GPIOC, &gi);
#endif
#ifdef SENSACTHS04
	BSP::spi.Init.DataSize = SPI_DATASIZE_16BIT;
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
	gi.Pin = GPIO_PIN_15;
	gi.Mode = GPIO_MODE_OUTPUT_PP;
	gi.Pull = GPIO_NOPULL;
	gi.Speed = GPIO_SPEED_MEDIUM;
	HAL_GPIO_Init(GPIOA, &gi);
#endif



	BSP::spi.Instance = SPI3;
	BSP::spi.Init.Mode = SPI_MODE_MASTER;
	BSP::spi.Init.Direction = SPI_DIRECTION_2LINES;

	BSP::spi.Init.CLKPolarity = SPI_POLARITY_LOW;
	BSP::spi.Init.CLKPhase = SPI_PHASE_1EDGE;
	BSP::spi.Init.NSS = SPI_NSS_SOFT;
	BSP::spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
	BSP::spi.Init.FirstBit = SPI_FIRSTBIT_MSB;
	BSP::spi.Init.TIMode = SPI_TIMODE_DISABLED;
	BSP::spi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
	BSP::spi.Init.CRCPolynomial = 1;
	status = HAL_SPI_Init(&BSP::spi);
	if (status != HAL_OK) {
		LOGE("Unable to configure SPI for Relays");
		while(1) {};
	}
	uint8_t tx[] = {0, 0, 0};
#ifdef SENSACTHS07
	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET);
	HAL_SPI_Transmit(&BSP::spi, tx, 3, 100);
	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET);
	LOGI(SUCCESSFUL_STRING, "SPI for DRV8860");
#endif
#ifdef SENSACTHS04
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
	if (HAL_SPI_Transmit(&BSP::spi, tx, 1, 100) == HAL_OK) {
		LOGI(SUCCESSFUL_STRING, "SPI for DRV8860");
	}
	else
	{
		LOGE(NOT_SUCCESSFUL_STRING, "SPI for DRV8860");
	}
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
#endif





	/**CAN2 GPIO Configuration
	 PB12     ------> CAN2_RX
	 PB13     ------> CAN2_TX
	 */
	gi.Pin = GPIO_PIN_12 | GPIO_PIN_13;
	gi.Mode = GPIO_MODE_AF_PP;
	gi.Pull = GPIO_NOPULL;
	gi.Speed = GPIO_SPEED_LOW;
	gi.Alternate = GPIO_AF9_CAN2;
	HAL_GPIO_Init(GPIOB, &gi);
	InitCAN();
	return;
}
コード例 #27
0
ファイル: main.c プロジェクト: sinaaghli/STM32DT
void ApplyPhase(char sens) {
  switch(sens) {
    case 5:   
      HAL_GPIO_WritePin(GPIOE,ph_u_l,GPIO_PIN_RESET);
      GPIO_pwm(ph_v_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(Phase_gpio,ph_w_l,GPIO_PIN_RESET);
      GPIO_pwm(ph_w_h,GPIO_PIN_RESET);

      GPIO_pwm(ph_u_h,GPIO_PIN_SET);
      HAL_GPIO_WritePin(Phase_gpio,ph_v_l,GPIO_PIN_SET);
      break;
    case 4:   
      GPIO_pwm(ph_u_h,GPIO_PIN_SET);
      HAL_GPIO_WritePin(GPIOE,ph_u_l,GPIO_PIN_RESET);
      GPIO_pwm(ph_v_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(Phase_gpio,ph_v_l,GPIO_PIN_RESET);
      GPIO_pwm(ph_w_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(Phase_gpio,ph_w_l,GPIO_PIN_SET);
      break;
    case 6:   
      GPIO_pwm(ph_u_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(GPIOE,ph_u_l,GPIO_PIN_RESET);
      GPIO_pwm(ph_v_h,GPIO_PIN_SET);
      HAL_GPIO_WritePin(Phase_gpio,ph_v_l,GPIO_PIN_RESET);
      GPIO_pwm(ph_w_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(Phase_gpio,ph_w_l,GPIO_PIN_SET);
      break;
    case 2:   
      GPIO_pwm(ph_u_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(GPIOE,ph_u_l,GPIO_PIN_SET);
      GPIO_pwm(ph_v_h,GPIO_PIN_SET);
      HAL_GPIO_WritePin(Phase_gpio,ph_v_l,GPIO_PIN_RESET);
      GPIO_pwm(ph_w_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(Phase_gpio,ph_w_l,GPIO_PIN_RESET);
      break;
    case 3:   
      GPIO_pwm(ph_u_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(GPIOE,ph_u_l,GPIO_PIN_SET);
      GPIO_pwm(ph_v_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(Phase_gpio,ph_v_l,GPIO_PIN_RESET);
      GPIO_pwm(ph_w_h,GPIO_PIN_SET);
      HAL_GPIO_WritePin(Phase_gpio,ph_w_l,GPIO_PIN_RESET);
      break;
    case 1: 
      GPIO_pwm(ph_u_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(GPIOE,ph_u_l,GPIO_PIN_RESET);
      GPIO_pwm(ph_v_h,GPIO_PIN_RESET);
      HAL_GPIO_WritePin(Phase_gpio,ph_v_l,GPIO_PIN_SET);
      GPIO_pwm(ph_w_h,GPIO_PIN_SET);
      HAL_GPIO_WritePin(Phase_gpio,ph_w_l,GPIO_PIN_RESET);
      break;
    default:
      while(1);
    }
}
コード例 #28
0
ファイル: cHal_init.cpp プロジェクト: klaus-liebler/sensact
void BSP::DoEachCycle(Time_t now) {
#if (defined(SENSACTHS07))
	//modus: convert-command, nur inputs abfragen, wechselweise inputs und temp abfragen
	static Time_t last_CONVERT_T_COMMAND=0;
	static uint8_t mode = MODE_CONV_COMMAND;
	static uint8_t inpId=0;
	static uint8_t tempId=0;
	static bool flipflop=false;
	//das Durchschalten der Relais hat Priorität beim 1wire

	if(lastCommittedPoweredOutputState[WORD_1WI]!=poweredOutputState[WORD_1WI])
	{
		//es gibt mal grundsätzlich Unterschiede...doch wo genau?
		int i;
		for(i=0;i<MODEL::sensactWi_RelayAddressesCnt;i++)
		{
			uint32_t mask = (0x3 << (i*2));
			if((lastCommittedPoweredOutputState[WORD_1WI] & mask) != (poweredOutputState[WORD_1WI] & mask))
			{
				ds2482.OWWriteDS2413(drivers::e1WireFamilyCode::_3A2100H, MODEL::sensactWi_RelayAddresses[i], RBN(poweredOutputState[WORD_1WI], i*2), RBN(poweredOutputState[WORD_1WI], 2*i+1));
				//clear both
				lastCommittedPoweredOutputState[WORD_1WI] &= ~mask;
				//set both
				lastCommittedPoweredOutputState[WORD_1WI] |= (poweredOutputState[WORD_1WI] & mask);
			}
		}
	}
	else
	{
		switch(mode)
		{
		case MODE_CONV_COMMAND:
			//issue Convert-Command;
			ds2482.BeginTransactionForAll(drivers::e1WireCommand::CONVERT_T);
			mode=MODE_QUERY_INPUTS;
			last_CONVERT_T_COMMAND=now;
			LOGD("MODE_CONV_COMMAND");
			break;
		case MODE_QUERY_INPUTS:
			//fetch input data
			if(MODEL::sensactWi_InputAddressesCnt>inpId)
			{
				ds2482.OWReadDS2413(drivers::e1WireFamilyCode::_3A2100H, MODEL::sensactWi_InputAddresses[inpId], inpId*2, &inputState[WORD_1WI]);
				LOGD("MODE_QUERY_INPUTS %d", inpId);
				inpId++;
				if(inpId==MODEL::sensactWi_InputAddressesCnt)
				{
					inpId=0;
				}
			}
			if(now-last_CONVERT_T_COMMAND>1000)
			{
				mode=MODE_MIX;
			}
			break;
		case MODE_MIX:
			if(flipflop)
			{
				if(MODEL::sensactWi_InputAddressesCnt>inpId)
				{
					//fetch input data
					ds2482.OWReadDS2413(drivers::e1WireFamilyCode::_3A2100H, MODEL::sensactWi_InputAddresses[inpId], inpId*2, &inputState[WORD_1WI]);
					LOGD("MODE_MIX inp %d", inpId);
					inpId++;
					if(inpId==MODEL::sensactWi_InputAddressesCnt)
					{
						inpId=0;
					}
				}
			}
			else
			{
				if(MODEL::ds18b20_AddressesCnt>tempId)
				{
					//fetch temperature data
					ds2482.OWReadDS18B20Temp(MODEL::ds18b20_Addresses[tempId], &temperatures[tempId]);
					LOGD("MODE_MIX temp %d", tempId);
					tempId++;
					if(tempId==MODEL::ds18b20_AddressesCnt)
					{
	/*
						#if LOGLEVEL == LEVEL_INFO
						LOGI("Got the following temperatures");
						uint8_t tc=0;
						for(tc=0;tc<16;tc++)
						{
							Console::Writeln("Sensor %d: %d and %d/16", tc, temperatures[tc]/16, temperatures[tc]%16);
						}
	#endif
	*/
						tempId=0;
						mode=MODE_CONV_COMMAND;
					}
				}
				else
				{
					tempId=0;
					mode=MODE_CONV_COMMAND;
				}
			}
			flipflop =!flipflop;
			break;
		}
	}

	//StartConversion und 1 sek später reihum einsammeln
	if (now > nextLedToggle) {
		for(uint8_t i=0;i<COUNTOF(BSP::ErrorCounters);i++)
		{
			if(BSP::ErrorCounters[i]!=0)
			{
				LOGW("ErrorCounters[%i] = %i", i, BSP::ErrorCounters[i]);
			}
		}
		nextLedToggle += 1000;
	}
#endif
#ifdef SENSACTHS07

	if (pca9555_U18.HasChanged()) {
		uint16_t tmp = pca9555_U18.GetInput();
		inputState[WORD_I2C] = (inputState[WORD_I2C] & 0xFFFF0000) + tmp;
	}
	if (pca9555_U19.HasChanged()) {
		uint16_t tmp = pca9555_U19.GetInput();
		inputState[WORD_I2C] = (inputState[WORD_I2C] & 0x0000FFFF) + (tmp << 16);
	}
	uint8_t *tx = ((uint8_t*) &(poweredOutputState[WORD_SPI]));
	if (lastCommittedPoweredOutputState[WORD_SPI] != poweredOutputState[WORD_SPI]) {
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET);
		if (HAL_SPI_Transmit(&BSP::spi, tx, 3, 100) == HAL_OK) {
			lastCommittedPoweredOutputState[WORD_SPI] = poweredOutputState[WORD_SPI];
		}
		HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET);
	}
	if(rcSwitch.available())
	{
		uint32_t val=rcSwitch.getReceivedValue();
		rcSwitchQueue=val;
		rcSwitch.resetAvailable();
	}
#endif
#ifdef SENSACTHS04

	uint8_t *tx = ((uint8_t*) &poweredOutputState);
	if (lastCommittedPoweredOutputState != poweredOutputState) {
		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
		if (HAL_SPI_Transmit(&BSP::spi, tx, 1, 100) == HAL_OK) {
			lastCommittedPoweredOutputState = poweredOutputState;
		}
		HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
	}
#endif
	(void)now;
}
コード例 #29
0
ファイル: lsm303d.c プロジェクト: fhtthg/my_pix4
void LSM303D_CS_DISABLE(void)
{
    HAL_GPIO_WritePin(LSM303D_CS_PORT, LSM303D_CS_PIN, GPIO_PIN_SET);
}
コード例 #30
0
/** Configure pins as 
        * Analog 
        * Input 
        * Output
        * EVENT_OUT
        * EXTI
     PC3   ------> I2S2_SD
     PA4   ------> I2S3_WS
     PA5   ------> SPI1_SCK
     PA6   ------> SPI1_MISO
     PA7   ------> SPI1_MOSI
     PB10   ------> I2S2_CK
     PB12   ------> I2S2_WS
     PA9   ------> USB_OTG_FS_VBUS
     PA10   ------> USB_OTG_FS_ID
     PA11   ------> USB_OTG_FS_DM
     PA12   ------> USB_OTG_FS_DP
     PC10   ------> I2S3_CK
     PC12   ------> I2S3_SD
     PB6   ------> I2C1_SCL
     PB9   ------> I2C1_SDA
*/
void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __GPIOE_CLK_ENABLE();
  __GPIOC_CLK_ENABLE();
  __GPIOH_CLK_ENABLE();
  __GPIOA_CLK_ENABLE();
  __GPIOB_CLK_ENABLE();
  __GPIOD_CLK_ENABLE();

  /*Configure GPIO pin : PE2 */
  GPIO_InitStruct.Pin = GPIO_PIN_2;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /*Configure GPIO pin : CS_I2C_SPI_Pin */
  GPIO_InitStruct.Pin = CS_I2C_SPI_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(CS_I2C_SPI_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : PE4 PE5 MEMS_INT2_Pin */
  GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|MEMS_INT2_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */
  GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PDM_OUT_Pin */
  GPIO_InitStruct.Pin = PDM_OUT_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  HAL_GPIO_Init(PDM_OUT_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pin : PA0 */
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : PA4 */
  GPIO_InitStruct.Pin = GPIO_PIN_4;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PA5 PA6 PA7 */
  GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : CLK_IN_Pin PB12 */
  GPIO_InitStruct.Pin = CLK_IN_Pin|GPIO_PIN_12;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin 
                           Audio_RST_Pin */
  GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin 
                          |Audio_RST_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /*Configure GPIO pin : VBUS_FS_Pin */
  GPIO_InitStruct.Pin = VBUS_FS_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(VBUS_FS_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : OTG_FS_ID_Pin OTG_FS_DM_Pin OTG_FS_DP_Pin */
  GPIO_InitStruct.Pin = OTG_FS_ID_Pin|OTG_FS_DM_Pin|OTG_FS_DP_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : I2S3_SCK_Pin PC12 */
  GPIO_InitStruct.Pin = I2S3_SCK_Pin|GPIO_PIN_12;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */
  GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct);

  /*Configure GPIO pins : Audio_SCL_Pin Audio_SDA_Pin */
  GPIO_InitStruct.Pin = Audio_SCL_Pin|Audio_SDA_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(CS_I2C_SPI_GPIO_Port, CS_I2C_SPI_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_RESET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin 
                          |Audio_RST_Pin, GPIO_PIN_RESET);

}