Example #1
0
int main(void)
{

  int i;

  HAL_Init();
  SystemClock_Config();

  __GPIOC_CLK_ENABLE();

  // LEDs on Discovery F0
  GPIO_InitTypeDef GPIO_InitTypeDefStruct;
  GPIO_InitTypeDefStruct.Pin = GPIO_PIN_9 | GPIO_PIN_8;
  GPIO_InitTypeDefStruct.Mode= GPIO_MODE_OUTPUT_PP;
  GPIO_InitTypeDef* GPIO_Init= & GPIO_InitTypeDefStruct;
  HAL_GPIO_Init(GPIOC,GPIO_Init);



    while (1) {
	for (i = 1000000; i > 0; i--);
        HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_9);
        HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_8);
    }



  /* Infinite loop */
  exit (1);
}
Example #2
0
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */


  /* USER CODE BEGIN 2 */
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
      HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_2);
      HAL_Delay(100);
      HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_8);
      HAL_Delay(100);

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #3
0
int main(void)
{
  uint32_t bootStatus;
  
  /* 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();
  
  /* Turn on led Init */
  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_12|GPIO_PIN_13, GPIO_PIN_RESET);
  
  /* Wait for timeout */
  bootStatus = bootWait(5000);
  
  /* Turn off led */
  HAL_GPIO_WritePin(GPIOE, GPIO_PIN_12|GPIO_PIN_13, GPIO_PIN_SET);
  
  /* Check for Result */
  if(bootStatus == 0)
  {
    /* Test if user code is programmed starting from address USBD_DFU_APP_DEFAULT_ADD */
    if(((*(__IO uint32_t*)USBD_DFU_APP_DEFAULT_ADD) & 0x2FFE0000 ) == 0x20000000)
    {
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (USBD_DFU_APP_DEFAULT_ADD + 4);
      JumpToApplication = (pFunction) JumpAddress;
      
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) USBD_DFU_APP_DEFAULT_ADD);
      JumpToApplication();
    }
    
    /* load application failed */
    while (1)
    {
      HAL_Delay(50);
      HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_12|GPIO_PIN_13);
    }
  }
  
  /* Init Device Library,Add Supported Class and Start the library*/
  USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
  USBD_RegisterClass(&hUsbDeviceFS, &USBD_DFU);
  USBD_DFU_RegisterMedia(&hUsbDeviceFS, &USBD_DFU_fops_FS);
  USBD_Start(&hUsbDeviceFS);
  
  /* Infinite loop */
  while (1)
  {
    HAL_Delay(500);
    HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_13);
  }
}
Example #4
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* This sample code shows how to use GPIO HAL API to toggle LED1, LED2, LED3 and LED4 IOs
    in an infinite loop. */

  /* STM32F3xx HAL library initialization:
       - Configure the Flash prefetch
       - 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 72 MHz */
  SystemClock_Config();
  
  /* -1- Enable each GPIO Clock (to be able to program the configuration registers) */
  LED1_GPIO_CLK_ENABLE();
  LED2_GPIO_CLK_ENABLE();
  LED3_GPIO_CLK_ENABLE();
  LED4_GPIO_CLK_ENABLE();

  /* -2- Configure IOs in output push-pull mode to drive external LEDs */
  GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull  = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

  GPIO_InitStruct.Pin = LED1_PIN;
  HAL_GPIO_Init(LED1_GPIO_PORT, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = LED2_PIN;
  HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = LED3_PIN;
  HAL_GPIO_Init(LED3_GPIO_PORT, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = LED4_PIN;
  HAL_GPIO_Init(LED4_GPIO_PORT, &GPIO_InitStruct);

  /* -3- Toggle IOs in an infinite loop */
  while (1)
  {
    HAL_GPIO_TogglePin(LED1_GPIO_PORT, LED1_PIN);
    /* Insert delay 100 ms */
    HAL_Delay(100);
    HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);
    /* Insert delay 100 ms */
    HAL_Delay(100);
    HAL_GPIO_TogglePin(LED3_GPIO_PORT, LED3_PIN);
    /* Insert delay 100 ms */
    HAL_Delay(100);
    HAL_GPIO_TogglePin(LED4_GPIO_PORT, LED4_PIN);
    /* Insert delay 100 ms */
    HAL_Delay(100);
  }
}
Example #5
0
void send(uint8_t status, uint8_t* buffer, uint8_t buffer_length) {
  uint8_t transmitBuffer[UART_command_length + 1];
  transmitBuffer[0] = MORE_DATA;
  uint8_t total_transmitted = 0;
  while (total_transmitted < buffer_length) {
    if (buffer_length - total_transmitted <= UART_command_length) {
      transmitBuffer[0] = status;
    }
    for (int i = 0; i < UART_command_length; i++) {
      if (total_transmitted < buffer_length) {
        transmitBuffer[i+1] = buffer[total_transmitted];
      } else {
        transmitBuffer[i+1] = 0;
      }
      total_transmitted++;
    }
    if (HAL_UART_Transmit(&hUART, (unsigned char*) transmitBuffer, UART_command_length + 1, 1000) != HAL_OK) {
      Output_High(FAIL_LED_GPIOx, FAIL_LED_Pin);
      Output_High(BUSY_LED_GPIOx, BUSY_LED_Pin);
      for (int i = 0; i < 10; i++) {
        HAL_GPIO_TogglePin(FAIL_LED_GPIOx, FAIL_LED_Pin);
        HAL_GPIO_TogglePin(BUSY_LED_GPIOx, BUSY_LED_Pin);
        HAL_Delay(50);
      }
    }
    HAL_Delay(100);
  }
}
Example #6
0
/**
  * @brief  Rx Transfer completed callback
  * @param  None
  * @retval None
  */
void can2RxCpltCallback()
{
//	if ((CAN_Handle.pRxMsg->StdId == 0x321) && (CAN_Handle.pRxMsg->IDE == CAN_ID_STD) && (CAN_Handle.pRxMsg->DLC == 2))
//	{
//		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
//		volatile uint8_t test1 = CAN_Handle.pRxMsg->Data[0];
//		volatile uint8_t test2 = CAN_Handle.pRxMsg->Data[1];
//	}

	if (prvRxBuffer1State != CANBufferState_Reading && prvRxBuffer1Count < RX_BUFFER_SIZE)
	{
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
		prvRxBuffer1State = CANBufferState_Writing;
		/* Save the message */
		prvRxBuffer1[prvRxBuffer1CurrentIndex].id = CAN_Handle.pRxMsg->StdId;
		prvRxBuffer1[prvRxBuffer1CurrentIndex].dlc = CAN_Handle.pRxMsg->DLC;
		for (uint32_t i = 0; i < CAN_Handle.pRxMsg->DLC; i++)
			prvRxBuffer1[prvRxBuffer1CurrentIndex].data[i] = CAN_Handle.pRxMsg->Data[i];

		/* Increment the counters */
		prvRxBuffer1CurrentIndex++;
		prvRxBuffer1Count++;

		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer1ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer1ClearTimer, NULL);
	}
	else if (prvRxBuffer2State != CANBufferState_Reading && prvRxBuffer2Count < RX_BUFFER_SIZE)
	{
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
		prvRxBuffer2State = CANBufferState_Writing;
		/* Save the message */
		prvRxBuffer2[prvRxBuffer1CurrentIndex].id = CAN_Handle.pRxMsg->StdId;
		prvRxBuffer2[prvRxBuffer1CurrentIndex].dlc = CAN_Handle.pRxMsg->DLC;
		for (uint32_t i = 0; i < CAN_Handle.pRxMsg->DLC; i++)
			prvRxBuffer2[prvRxBuffer1CurrentIndex].data[i] = CAN_Handle.pRxMsg->Data[i];

		/* Increment the counters */
		prvRxBuffer2CurrentIndex++;
		prvRxBuffer2Count++;

		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer2ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer2ClearTimer, NULL);
	}
	else
	{
		/* No buffer available, something has gone wrong */
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
	}


	/* Receive */
	if (HAL_CAN_Receive_IT(&CAN_Handle, CAN_FIFO1) != HAL_OK)
	{
		/* Reception Error */
//		Error_Handler();
	}
}
Example #7
0
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* AdcHandle)
{	
	HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_9);
	HAL_ADC_Stop_DMA(&g_AdcHandle);
	osSignalSet(tid_TH_GUI,DMA_ConvCpltSig);
	HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_9);
	//GPIOB->ODR ^= GPIO_PIN_9; // this is just for test of DMA speed
}
Example #8
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
    /* STM32F2xx HAL library initialization:
         - Configure the Flash prefetch, instruction and Data caches
         - 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 120 MHz */
    SystemClock_Config();

    /* -1- Enable GPIOG, GPIOC and GPIOI Clock (to be able to program the configuration registers) */
    __HAL_RCC_GPIOG_CLK_ENABLE();
    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOI_CLK_ENABLE();

    /* -2- Configure PG.6, PG.8, PI.9 and PC.7 IOs in output push-pull mode to
           drive external LEDs */
    GPIO_InitStruct.Pin = (GPIO_PIN_6 | GPIO_PIN_8);
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FAST;

    HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_9;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FAST;

    HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FAST;

    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    /* -3- Toggle PG.6, PG.8, PI.9 and PC.7 IOs in an infinite loop */
    while (1)
    {
        HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_6);
        /* Insert delay 100 ms */
        HAL_Delay(100);
        HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_8);
        /* Insert delay 100 ms */
        HAL_Delay(100);
        HAL_GPIO_TogglePin(GPIOI, GPIO_PIN_9);
        /* Insert delay 100 ms */
        HAL_Delay(100);
        HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_7);
        /* Insert delay 100 ms */
        HAL_Delay(100);
    }
}
Example #9
0
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_DMA_Init();
    MX_USART3_UART_Init();
    MX_TIM2_Init();

    /* USER CODE BEGIN 2 */
    nec.timerHandle = &htim2;

    nec.timerChannel = TIM_CHANNEL_1;
    nec.timerChannelActive = HAL_TIM_ACTIVE_CHANNEL_1;

    nec.timingBitBoundary = 1680;
    nec.timingAgcBoundary = 12500;
    nec.type = NEC_NOT_EXTENDED;

    nec.NEC_DecodedCallback = myNecDecodedCallback;
    nec.NEC_ErrorCallback = myNecErrorCallback;
    nec.NEC_RepeatCallback = myNecRepeatCallback;

    NEC_Read(&nec);
    /* USER CODE END 2 */

    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    while (1) {
        /* USER CODE END WHILE */

        /* USER CODE BEGIN 3 */
        HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
        HAL_Delay(100);
        HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);
        HAL_Delay(100);
    }
    /* USER CODE END 3 */

}
// The following is never bing called:
void  HAL_TIM_PWM_PulseFinishedCallback (TIM_HandleTypeDef *htim)
{
  if ((htim->Instance == easySPIN_TIMER_PWM1) && (htim->Channel == easySPIN_HAL_ACT_CHAN_TIMER_PWM1))
    {
      if (EasySpin_GetDeviceState(0) != INACTIVE)
         {
           EasySpin_StepClockHandler(0);
         }
    }

  if ((htim->Instance == easySPIN_TIMER_PWM2) && (htim->Channel == easySPIN_HAL_ACT_CHAN_TIMER_PWM2))
    {
      if (EasySpin_GetDeviceState(1) != INACTIVE)
         {
           EasySpin_StepClockHandler(1);
         }
   }

  if ((htim->Instance == easySPIN_TIMER_PWM3) && (htim->Channel == easySPIN_HAL_ACT_CHAN_TIMER_PWM3))
    {
      HAL_GPIO_TogglePin(easySPIN_PWM_3_PORT, easySPIN_PWM_3_PIN);
      if (EasySpin_GetDeviceState(2) != INACTIVE)
         {
           EasySpin_StepClockHandler(2);
         }
    }
}
Example #11
0
/**
  * @brief  Rx Transfer completed callback
  * @param  None
  * @retval None
  */
void rs232RxCpltCallback()
{
	if (prvRxBuffer1State != BUFFERState_Reading && prvRxBuffer1Count < RX_BUFFER_SIZE)
	{
		prvRxBuffer1State = BUFFERState_Writing;
		prvRxBuffer1[prvRxBuffer1CurrentIndex++] = prvReceivedByte;
		prvRxBuffer1Count++;
		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer1ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer1ClearTimer, NULL);
	}
	else if (prvRxBuffer2State != BUFFERState_Reading && prvRxBuffer2Count < RX_BUFFER_SIZE)
	{
		prvRxBuffer2State = BUFFERState_Writing;
		prvRxBuffer2[prvRxBuffer2CurrentIndex++] = prvReceivedByte;
		prvRxBuffer2Count++;
		/* Start the timer which will clear the buffer if it's not already started */
		if (xTimerIsTimerActive(prvBuffer2ClearTimer) == pdFALSE)
			xTimerStartFromISR(prvBuffer2ClearTimer, NULL);
	}
	else
	{
		/* No buffer available, something has gone wrong */
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
	}

	/* Continue receiving data */
	HAL_UART_Receive_IT(&UART_Handle, &prvReceivedByte, 1);
	/* Give back the semaphore now that we are done */
	xSemaphoreGiveFromISR(xSemaphore, NULL);
}
Example #12
0
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_TIM3_Init();
  //MX_TIM4_Init();

  //HAL_TIM_Base_Start(&htim3);
  //HAL_TIM_Base_Start(&htim4);
  //HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
  //HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);
  //HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2);

  HAL_GPIO_WritePin(Led_gpio,Led_pin,GPIO_PIN_SET);
  HAL_Delay(1000);
  HAL_GPIO_WritePin(Led_gpio,Led_pin,GPIO_PIN_RESET);

  HAL_GPIO_WritePin(DcCal_gpio,DcCal_pin,GPIO_PIN_RESET);
  

  char state;
  int cnt;
  cnt = HAL_GetTick();
  while (1)
  {
    state = HAL_GPIO_ReadPin(sens_gpio,sens_ph1_pin);
    state = state << 1;
    state |= HAL_GPIO_ReadPin(sens_gpio,sens_ph2_pin);
    state = state << 1;
    state |= HAL_GPIO_ReadPin(sens_gpio,sens_ph3_pin);

    ApplyPhaseSolid(state);
    if(HAL_GetTick()>1000+cnt) {
      HAL_GPIO_TogglePin(EnGate_gpio,EnGate_pin);
      cnt = HAL_GetTick();
    }

//      if(TIM3->CCR3<200)
//        TIM3->CCR3++;
//      else
//        TIM3->CCR3=0;
//
//      HAL_Delay(20);
  }
  /* USER CODE END 3 */

}
Example #13
0
static void LED_Thread1(void const *argument)
{
	GPIO_InitTypeDef GPIO_InitStruct_LED, GPIO_InitStruct_BUTTON;

	/* GPIO Ports Clock Enable */
	__GPIOI_CLK_ENABLE();

	/*Configure GPIO pin : PI1 */
	GPIO_InitStruct_LED.Pin = GPIO_PIN_1;
	GPIO_InitStruct_LED.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStruct_LED.Pull = GPIO_NOPULL;
	GPIO_InitStruct_LED.Speed = GPIO_SPEED_LOW;
	HAL_GPIO_Init(GPIOI, &GPIO_InitStruct_LED);

	GPIO_InitStruct_BUTTON.Pin = GPIO_PIN_11;
	GPIO_InitStruct_BUTTON.Mode = GPIO_MODE_INPUT;
	GPIO_InitStruct_BUTTON.Pull = GPIO_PULLUP;
	HAL_GPIO_Init(GPIOI, &GPIO_InitStruct_BUTTON);

	while(1)
	{
		if(HAL_GPIO_ReadPin(GPIOI, GPIO_PIN_11)){
			HAL_GPIO_TogglePin(GPIOI, GPIO_PIN_1);
			HAL_Delay(500);
			printf("Pintando \n");
		}
		HAL_GPIO_WritePin(GPIOI, GPIO_PIN_1, 0);

	}
}
Example #14
0
void digitalToggle( uint32_t ulPin )
{
    if ( digitalPinToPort(ulPin) == NULL ) {
        return ;
    }
    HAL_GPIO_TogglePin(digitalPinToPort(ulPin), digitalPinToBitMask(ulPin));
}
Example #15
0
static void vLEDFlashTask( void *pvParameters )
{

	for(;;)
	{
		/* Delay for half the flash period then turn the LED on. */
		//vTaskDelayUntil( &xLastFlashTime, xFlashRate );
		vTaskDelay(500/portTICK_RATE_MS);
		HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);

		/* Delay for half the flash period then turn the LED off. */
		//vTaskDelayUntil( &xLastFlashTime, xFlashRate );
		vTaskDelay(500/portTICK_RATE_MS);
		HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);
	}
}
 /*----------------------------------------------------------------------------
*      Thread  'LED_Thread': Toggles LED
 *---------------------------------------------------------------------------*/
	void Thread_LED (void const *argument) {
		while(1){
				osDelay(200);
				//printf("LED");
				HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);
		}
	}
Example #17
0
static void main_loop(void){
	static uint32_t loopCounter = 0;
	static uint32_t divider100ms = 100;
	uint32_t i = 0;
	if(!(loopCounter%divider100ms)){
		HAL_GPIO_TogglePin(GPIOD,GPIO_PIN_15);
		kommuHandler();
	}
	
	if(!(loopCounter)){

	}
	power[3] = 100+pidY_X;
	if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0) == GPIO_PIN_SET){
		if(!bursting_start && !bursting_end){
			//bursting_start = 1;
		}
	}else{
		if(bursting_end){
			i = 0;
			while(i <= currentburst ){
				stdout_putchar(burst[i++]);
			}
			currentburst = 0;
			bursting_end = 0;
		}
	}

	loopCounter++;
}
Example #18
0
int main(void)
{
    HAL_Init();

    led_gpio_init();

    SystemClock_Config();

    mima_init();

    usbKB_init();

    USBD_Init(&USBD_Device, &HID_Desc, 0);

    USBD_RegisterClass(&USBD_Device, USBD_HID_CLASS);

    USBD_CUSTOM_HID_RegisterInterface(&USBD_Device, &USBD_CustomHID_fops);

    USBD_Start(&USBD_Device);

    HAL_Delay(1000);
    USB_KB_type("Hello world", 11);

    while(1) {
        HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7);
        mima_loop();
    }
}
Example #19
0
int main(void)
{

  /* 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_TIM6_Init();

  /* USER CODE BEGIN 2 */
	interrupt_set_up();
  /* USER CODE END 2 */

	
  while (1)
  {
//			GPIOA->BSRR	= (1<<0);
//			HAL_Delay(blink_period);
//			GPIOA->BRR = (1<<0);
//			HAL_Delay(blink_period);
			
			HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
			HAL_Delay(blink_period);
				
  }
  /* USER CODE END 3 */

}
Example #20
0
void myNecRepeatCallback() {
    char* msg = "Repeat!\n";
    HAL_UART_Transmit_DMA(&huart3, (uint8_t*) msg, strlen(msg));
    HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_15);
    HAL_Delay(10);
    NEC_Read(&nec);
}
Example #21
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - 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 100 MHz */
  SystemClock_Config();
  
  /*##-1- Enable GPIOA Clock (to be able to program the configuration registers) */
  __HAL_RCC_GPIOA_CLK_ENABLE();
  
  /*##-2- Configure PA05 IO in output push-pull mode to drive external LED ###*/  
  GPIO_InitStruct.Pin = GPIO_PIN_5;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 
   
  /*##-3- Toggle PA05 IO in an infinite loop #################################*/  
  while (1)
  {
    HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
    
    /* Insert a 100ms delay */
    HAL_Delay(100);
  }
}
Example #22
0
int main(void)
{
	HAL_Init();
	
	SystemClock_Config();
	__GPIOA_CLK_ENABLE();
	
	gpio.Pin = GPIO_PIN_5;
	gpio.Mode = GPIO_MODE_OUTPUT_PP;
	gpio.Pull = GPIO_NOPULL;
	gpio.Speed = GPIO_SPEED_LOW;
	
	HAL_GPIO_Init(GPIOA, &gpio);

	while(1)
	{
		
		HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
		HAL_Delay(100);
	
	}
	
	
	
}
Example #23
0
int main(void)
{

  HAL_Init();
  SystemClock_Config();

  MX_GPIO_Init();
  MX_CAN_Init();
  MX_I2C1_Init();
  MX_USART3_UART_Init();
  MX_USART2_UART_Init();
  MX_USART1_UART_Init();
  MX_TIM1_Init();
  USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
  USBD_RegisterClass(&hUsbDeviceFS, &USBD_CUSTOM_HID);
  USBD_CUSTOM_HID_RegisterInterface(&hUsbDeviceFS, &USBD_CustomHID_fops_FS);
  USBD_Start(&hUsbDeviceFS);

  while (1)
  {

  /* USER CODE END WHILE */


  /* USER CODE BEGIN 3 */
	  HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_1);
	  HAL_Delay(blinkingDelay);
  }
  /* USER CODE END 3 */

}
Example #24
0
int main(void)
{

  /* USER CODE BEGIN 1 */
	uint8_t damogranlabs_logo[]={
		0x0F,
		0x13,
		0x11,
		0x11,
		0x0e,
		0x00,
		0x00		
	};
  /* 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_USART1_UART_Init();

  /* USER CODE BEGIN 2 */
	LCD_Init(2, 20);
	LCD_CreateChar(0, damogranlabs_logo); 
	
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
	LCD_PrintString(2, 1, "n: ");
	LCD_PrintNumber(2, 4, -10);
	
	LCD_PrintString(2, 10, "f: ");
	LCD_PrintFloat(2, 13, -326.5635, 5);
	
	while (1)
  {
		LCD_PrintStringWindow(1, 3, 14, 350, "Find us on github and www.damogranlabs.com");
		LCD_Clear();
		LCD_PrintString(1, 1, "www.damogranlabs.com");
		LCD_PutCustom(2, 10, 0);
		LCD_ClearArea(1, 5, 12); 
		HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
		HAL_Delay(2000);
		
		
		
				/* USER CODE END WHILE */

		/* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */

}
Example #25
0
uint8_t processUserInput(int8_t opt) {
  char msg[30];

  if(!(opt >=1 && opt <= 3))
    return 0;

  sprintf(msg, "%d", opt);
  UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg));

  switch(opt) {
  case 1:
    HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
    break;
  case 2:
    sprintf(msg, "\r\nUSER BUTTON status: %s",
        HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_RESET ? "PRESSED" : "RELEASED");
    UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg));
    break;
  case 3:
    return 2;
  };

  UART_Transmit(&huart2, (uint8_t*)PROMPT, strlen(PROMPT));
  return 1;
}
Example #26
0
static uint8_t  USBD_RAW_Setup (USBD_HandleTypeDef *pdev,
                                USBD_SetupReqTypedef *req)
{

  switch (req->bmRequest & USB_REQ_TYPE_MASK)
  {
  case USB_REQ_TYPE_CLASS :
    switch (req->bRequest)
    {

    default:
      USBD_CtlError (pdev, req);
      return USBD_FAIL;
    }
    break;

  case USB_REQ_TYPE_STANDARD:
    switch (req->bRequest)
    {HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_10);

    default:
      USBD_CtlError (pdev, req);
      return USBD_FAIL;
    }
  }
  return USBD_OK;
}
Example #27
0
void timer_irq_handler(void) {
    // Channel 1 for mbed timeout
    if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
        if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) {
            __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
            us_ticker_irq_handler();
        }
    }

    // Channel 2 for HAL tick
    if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) {
        if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) {
            __HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2);
            uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle);
            if ((val - PreviousVal) >= HAL_TICK_DELAY) {
                // Increment HAL variable
                HAL_IncTick();
                // Prepare next interrupt
                __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY);
                PreviousVal = val;
#if 0 // For DEBUG only
                HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6);
#endif
            }
        }
    }
}
Example #28
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
    /* This sample code shows how to use STM32F4xx GPIO HAL API to toggle PG6, PG7,
       PG10, and PG12 IOs (connected to LED1, LED2, LED3 and LED4 on STM324x9I-EVAL board)
       in an infinite loop.
       To proceed, 3 steps are required: */

    /* STM32F4xx HAL library initialization:
         - Configure the Flash prefetch, instruction and Data caches
         - 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 180 MHz */
    SystemClock_Config();

    /* -1- Enable GPIOG Clock (to be able to program the configuration registers) */
    __HAL_RCC_GPIOG_CLK_ENABLE();

    /* -2- Configure PG.6, PG.7, PG10 and PG.12 IOs in output push-pull mode to
           drive external LEDs */
    GPIO_InitStruct.Pin = (GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_10 | GPIO_PIN_12);
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FAST;

    HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

    /* -3- Toggle PG.6, PG.7, PG10 and PG.12 IOs in an infinite loop */
    while (1)
    {
        HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_6);
        /* Insert delay 100 ms */
        HAL_Delay(100);
        HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_7);
        /* Insert delay 100 ms */
        HAL_Delay(100);
        HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_10);
        /* Insert delay 100 ms */
        HAL_Delay(100);
        HAL_GPIO_TogglePin(GPIOG, GPIO_PIN_12);
        /* Insert delay 100 ms */
        HAL_Delay(100);
    }
}
Example #29
0
/* USER CODE BEGIN 0 */
void myNecDecodedCallback(uint16_t address, uint8_t cmd) {
    char buff[100];
    snprintf(buff, 100, "A:%d\tC:%d\n", address, cmd);
    HAL_UART_Transmit_DMA(&huart3, (uint8_t*) buff, strlen(buff));
    HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_14);
    HAL_Delay(10);
    NEC_Read(&nec);
}
Example #30
-8
int main(void)
{

  /* USER CODE BEGIN 1 */
	char ADC_Tx_Data[70];
  /* 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_DMA_Init();
  MX_ADC1_Init();
  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */
	
	HAL_UART_Receive_IT(&huart1, (uint8_t *)Rx_Data, 1);
	HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&ADC_Value, 6);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		HAL_Delay(15);
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_4);
		HAL_Delay(15);
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_0);	
		HAL_Delay(15);
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_1);	
		HAL_Delay(15);
		HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_2);	
		HAL_Delay(15);		
	  sprintf(ADC_Tx_Data,"ADC1:%4d\tADC2:%4d\tADC3:%4d\tADC4:%4d\tADC5:%4d\tADC6:%4d\n\r", ADC_Value[0], ADC_Value[1], ADC_Value[2], ADC_Value[3], ADC_Value[4], ADC_Value[5]);
		HAL_UART_Transmit_IT(&huart1, (uint8_t *)ADC_Tx_Data, 70);
			
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}