Example #1
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_I2C3_Init();
	MX_TIM1_Init();
	MX_TIM2_Init();
	MX_TIM3_Init();
	MX_TIM4_Init();
	MX_TIM5_Init();
	MX_USART1_UART_Init();
	MX_USART2_UART_Init();
	MX_TIM11_Init();

	/* USER CODE BEGIN 2 */
	HAL_TIM_Base_Start_IT(&htim11); // 100 msec timer
	initSonar( MAX_SONAR);
	initSerOutput();
	/* USER CODE END 2 */

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

		/* USER CODE BEGIN 3 */
		// >>>>> Sonar reading
		triggerSonar( COUPLE_0_2);
		HAL_Delay(49);
		triggerSonar( COUPLE_1_3);
		HAL_Delay(49);
		// <<<<< Sonar reading

		// >>>>> Serial Output
		convertMeasures();
		sendMeasures();
		// <<<<< Serial Output

	}
	/* USER CODE END 3 */

}
Example #2
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_ADC1_Init();
  MX_I2C1_Init();
  MX_RTC_Init();
  MX_SPI2_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_USART3_UART_Init();

  /* USER CODE BEGIN 2 */
	encoderInit();
	pwmInit();
//	adcInit();
	uartInit();
	timInterruptInit();
	gyroInit(GYROHIGH);
	calibrateGyro();

//	rotaryRight(800);
//	HAL_Delay(500);
//	rotaryLeft(800);
	drive(VEL);

  /* USER CODE END 2 */

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

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #3
0
int main(void) {
  HAL_Init();

  Nucleo_BSP_Init();
  MX_TIM2_Init();

  HAL_TIM_Base_Start_IT(&htim2);

  while (1);
}
Example #4
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 */

}
Example #5
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_SPI1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM7_Init();
  MX_TIM10_Init();
  MX_TIM11_Init();
  MX_TIM13_Init();
  MX_TIM14_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */
	
	HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);      //Motor1
	HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4);      //Motor2
	HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);      //Motor3
	HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);      //Motor4

  /* USER CODE END 2 */

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

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #6
0
/**
  * @brief  The application entry point.
  * @retval int
  */
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();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

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

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_I2C1_Init();
  MX_TIM2_Init();
  /* USER CODE BEGIN 2 */

  Display_Init();
  CircularBuff_Init();
  DisplayUpdater_Init();

  HAL_TIM_Base_Start_IT(&htim2);      //start timer2 in interrupt mode.

  /* USER CODE END 2 */

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

    /* USER CODE BEGIN 3 */

	__WFI(); // CPU sleep
  }
  /* USER CODE END 3 */
}
Example #7
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_ADC1_Init();
  MX_I2C1_Init();
  MX_IWDG_Init();
  MX_SDADC1_Init();
  MX_SDADC2_Init();
  MX_TSC_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_SDADC3_Init();
  MX_USB_DEVICE_Init();
  MX_RTC_Init();
  MX_TIM6_Init();
  MX_TIM7_Init();

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

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

  /* USER CODE BEGIN 3 */
	  loop();
  }
  /* USER CODE END 3 */

}
Example #8
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_ADC1_Init();
  MX_ADC2_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  HAL_TIM_Base_Start_IT(&htim1);
  HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);
  HAL_TIMEx_PWMN_Start(&htim1,TIM_CHANNEL_1);
  HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_2);
  HAL_TIMEx_PWMN_Start(&htim1,TIM_CHANNEL_2);
  HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_3);
  HAL_TIMEx_PWMN_Start(&htim1,TIM_CHANNEL_3);
  HAL_TIM_Base_Start_IT(&htim2);
  while (1)
  {
  /* USER CODE END WHILE */
  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #9
0
int main(void) {
  uint32_t IV[200];
  float angle;

  HAL_Init();

  Nucleo_BSP_Init();
  MX_TIM2_Init();

  for (uint8_t i = 0; i < 200; i++) {
    angle = ASR*(float)i;
    IV[i] = (uint16_t) rint(100 + 99*sinf(angle*(PI/180)));
  }

  HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_1, (uint32_t *)IV, 200);

  while (1);
}
Example #10
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_TIM2_Init();
  MX_USART2_UART_Init();
  MX_USART6_UART_Init();
  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */
	HAL_TIM_Base_Start_IT(&htim2);

#ifdef DEBUG_TO_CONSOLE
	initialise_monitor_handles();
	printf("start\n");
#endif
	UARTInit();

  /* USER CODE END 2 */

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

  /* USER CODE BEGIN 3 */
		UARTLoopDemo();
	}
  /* USER CODE END 3 */

}
Example #11
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_I2C1_Init();
  MX_TIM1_Init();
  MX_TIM3_Init();
  MX_ADC1_Init();
  MX_TIM2_Init();

  /* USER CODE BEGIN 2 */
  
  //Start PWM
  HAL_TIM_Base_Start(&htim1);
  HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_ALL);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);     
	HAL_Delay(100);
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
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_DMA_Init();
  MX_ADC1_Init();
  MX_ADC2_Init();
  MX_DAC_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();

  /* USER CODE BEGIN 2 */
  configure_modem();
  acquisition_init();
  acquisition_start();
  /* USER CODE END 2 */

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

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #13
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();

  /* System interrupt init*/
  /* Sets the priority grouping field */
  HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  MX_DAC_Init();
  MX_TIM2_Init();

  /* USER CODE BEGIN 2 */
  HAL_ADC_Start(&hadc1);
  HAL_DAC_Start(&hdac, DAC_CHANNEL_1);

  /* USER CODE END 2 */

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

  }
  /* USER CODE END 3 */

}
Example #14
0
File: main.c Project: fominok/znp
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_RTC_Init();
  //if(!(*(volatile uint32_t *) (BDCR_RTCEN_BB)))__HAL_RCC_RTC_ENABLE();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

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

  /* USER CODE BEGIN 3 */
    HAL_RTC_GetTime(&hrtc, &myTime, FORMAT_BIN);
    HAL_RTC_GetDate(&hrtc, &myDate, FORMAT_BIN);
  }
  /* USER CODE END 3 */

}
Example #15
0
File: aos.c Project: OUWECAD/MOWE
/* --- AOS Initialization --- */
void AOS_init(void)
{		
	/* MCU Configuration */

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

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

	/* Unlock the Flash Program Erase controller */
	//HAL_FLASH_Unlock();

	/* Initialize all configured peripherals */
	MX_GPIO_Init();	
	MX_UART_Init();
	MX_TIM2_Init();
	MX_TIM7_Init();
	/* PWM Timers will override P1, P3 & P4 */
	MX_TIM3_Init();
  MX_TIM15_Init();
	
	#ifndef TX
		MX_ADC_Init();
	#endif

	/* AOS Initialization */
	
	/* Startup indicator sequence */
	blink(500);
	HAL_Delay(100);
	blink(100);
	HAL_Delay(100);
	blink(100);	

	/* Initialize random seed for PRNG */
	srand(atoi(_firmTime));
	
}
Example #16
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_CRC_Init();
  MX_I2C1_Init();
  MX_SPI2_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);

  // reinitialize uart with speed from config
  huart2.Init.BaudRate = USART_DEBUG_SPEED;
  HAL_UART_Init(&huart2);

  DEBUG_PRINTF("Hello, Lepton!\n\r");
  fflush(stdout);

  lepton_init();

  HAL_Delay(1000);

  init_lepton_command_interface();
#ifdef ENABLE_LEPTON_AGC
  enable_lepton_agc();
#endif

#ifdef Y16
  enable_telemetry();
#else
  enable_rgb888(PSUEDOCOLOR_LUT);
#endif

  DEBUG_PRINTF("reading_tmp007_regs...\n\r");

  read_tmp007_regs();

  DEBUG_PRINTF("Initialized...\n\r");

  HAL_Delay(250);

  MX_USB_DEVICE_Init();

  PT_INIT(&lepton_task_pt);
  PT_INIT(&usb_task_pt);
  PT_INIT(&uart_task_pt);

  /* USER CODE END 2 */

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

  /* USER CODE BEGIN 3 */

	  PT_SCHEDULE(lepton_task(&lepton_task_pt));
	  PT_SCHEDULE(usb_task(&usb_task_pt));
	  PT_SCHEDULE(uart_task(&uart_task_pt));
	  PT_SCHEDULE(button_task(&button_task_pt));

  }
  /* USER CODE END 3 */

}
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_I2C3_Init();
  MX_SPI3_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_TIM5_Init();
  MX_USART1_UART_Init();

  /* USER CODE BEGIN 2 */

  /* 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, osPriorityNormal, 0, 128);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

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

  /* Create the queue(s) */
  /* definition and creation of xQueueUARTReceive */
  osMessageQDef(xQueueUARTReceive, 3, char);
  xQueueUARTReceiveHandle = osMessageCreate(osMessageQ(xQueueUARTReceive), NULL);

  /* 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 */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
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_SPI1_Init();
  MX_TIM2_Init();
  MX_WWDG_Init();

  /* USER CODE BEGIN 2 */
	//HAL_TIM_Base_Start_IT(&htim3);
	
  /* 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 */
	HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
	HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the thread(s) */
  /* definition and creation of defaultTask */
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 96);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), 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 */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #19
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_ADC1_Init();
  MX_ADC3_Init();
  MX_I2C1_Init();
  MX_SPI1_Init();
  MX_SPI2_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();
  MX_USB_OTG_FS_PCD_Init();

  /* USER CODE BEGIN 2 */
  TIM1->CCR1 = 0x300;
  TIM1->CCR2 = 0x300;
  TIM2->CCR2 = 0x60;
  
  // Настройка deathTime
  pwm.init();
/* bugfix */   pwmDeathTime.setValue(10);
  htim1.Instance->BDTR &= ~TIM_BDTR_DTG;
  htim1.Instance->BDTR |= pwm.computeDeathTime(pwmDeathTime.getValueFlt());
  
  HAL_TIM_Base_Start(&htim1);
  // Выходной сигнал для ацп
  HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_2);
  // Выходной сигнал для ацп
  HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_3);
  
//  HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);
//  HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_2);
//  pwm.start();

//  HAL_TIMEx_PWMN_Start(&htim1,TIM_CHANNEL_1);
//  HAL_TIMEx_PWMN_Start(&htim1,TIM_CHANNEL_2);

  __HAL_RCC_DMA2_CLK_ENABLE();
  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc1.getBufer(), adc1.getBuferSize());
  HAL_ADC_Start_DMA(&hadc3, (uint32_t*)adc3.getBufer(), adc3.getBuferSize());
  


//------------------------------------------------------------------------------
  //  Низкоуровневая инициализация
//------------------------------------------------------------------------------
  //  Разрешение выходов буферов
  GPIOC->BSRR = BIT_14;

  //  Инициализация SPI портов
  

//------------------------------------------------------------------------------
//  Агрегация объектов
//  Определяется только при инициализации программы
//------------------------------------------------------------------------------
  
  mainMenu.addObserver( &menuEngine );  //  Объект menuEngine подписался на рассылку событий, объявленных в IControlCommands
  
//------------------------------------------------------------------------------
//  Начальные условия
//------------------------------------------------------------------------------
  menuEngine.setMenuValue("");
 
// Затычка на время отсутствия FRAM. Инициализация float данных

  vICalibrating.setValue(vICalibrating.getValue());
  vUDcBusCodeUCal.setValue(vUDcBusCodeUCal.getValue());
  vUDcBusCodeZero.setValue(vUDcBusCodeZero.getValue());
  vIChargeCodeICal.setValue(vIChargeCodeICal.getValue());
  vUChargeCodeUCal.setValue(vUChargeCodeUCal.getValue());
  vIChargeCodeZero.setValue(vIChargeCodeZero.getValue());
  vUChargeCodeZero.setValue(vUChargeCodeZero.getValue());
  vDcBusLoadVoltageDifferent.setValue(vDcBusLoadVoltageDifferent.getValue());

  /* USER CODE END 2 */

  /* Call init function for freertos objects (in freertos.c) */
  MX_FREERTOS_Init();
  
  /* Start scheduler */
  osKernelStart();
  
  /* We should never get here as control is now taken by the scheduler */

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

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #20
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  /* Data initialization */
  int_T i;

  /* 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_ADC1_Init();
  MX_ADC2_Init();
  MX_CAN1_Init();
  MX_CAN2_Init();
  MX_DAC_Init();
  MX_I2C1_Init();
  MX_SPI2_Init();
  MX_SPI3_Init();
  MX_SPI4_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM5_Init();
  MX_TIM8_Init();
  MX_TIM9_Init();
  MX_TIM13_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_USART6_UART_Init();

  /* USER CODE BEGIN 2 */
  /* Systick configuration and enable SysTickHandler interrupt */
  if (SysTick_Config((uint32_t)(SystemCoreClock * 0.5))) {
    autoReloadTimerLoopVal_S = 1;
    do {
      autoReloadTimerLoopVal_S++;
    } while ((uint32_t)(SystemCoreClock * 0.5)/autoReloadTimerLoopVal_S >
             SysTick_LOAD_RELOAD_Msk);

    SysTick_Config((uint32_t)(SystemCoreClock * 0.5)/autoReloadTimerLoopVal_S);
  }

  remainAutoReloadTimerLoopVal_S = autoReloadTimerLoopVal_S;//Set nb of loop to do

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  for (i=0;i<1;i++) {
    OverrunFlags[i] = 0;
  }

  /* Model initialization call */
  Test_Stateflow_initialize();

  /* Infinite loop */
  /* Real time from systickHandler */
  while (1) {
    /*Process tasks every solver time*/
    if (remainAutoReloadTimerLoopVal_S == 0) {
      remainAutoReloadTimerLoopVal_S = autoReloadTimerLoopVal_S;

      /* Check base rate for overrun */
      if (OverrunFlags[0]) {
        rtmSetErrorStatus(Test_Stateflow_M, "Overrun");
      }

      OverrunFlags[0] = true;

      /* Step the model for base rate */
      Test_Stateflow_step();

      /* Get model outputs here */

      /* Indicate task for base rate complete */
      OverrunFlags[0] = false;
    }
  }

  /* USER CODE END WHILE */

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

}
Example #21
0
File: main.c Project: sincoon/injex
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_SPI2_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();

  /* USER CODE BEGIN 2 */
	InitMotor();
	HAL_TIM_Encoder_Start(&htim1,TIM_CHANNEL_ALL);


  /* USER CODE END 2 */

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

  /* Create the semaphores(s) */
  /* definition and creation of stopMoveByTime */
  osSemaphoreDef(stopMoveByTime);
  stopMoveByTimeHandle = osSemaphoreCreate(osSemaphore(stopMoveByTime), 1);

  /* definition and creation of suspendMoveByTime */
  osSemaphoreDef(suspendMoveByTime);
  suspendMoveByTimeHandle = osSemaphoreCreate(osSemaphore(suspendMoveByTime), 1);

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  xSemaphoreTake(stopMoveByTimeHandle, 0);
  xSemaphoreTake(suspendMoveByTimeHandle, 0);
	/* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* Create the timer(s) */
  /* definition and creation of elapsedTimer */
  osTimerDef(elapsedTimer, elapsedTimerCallback);
  elapsedTimerHandle = osTimerCreate(osTimer(elapsedTimer), osTimerPeriodic, NULL);

  /* definition and creation of moveTimer */
  osTimerDef(moveTimer, moveTimerCallback);
  moveTimerHandle = osTimerCreate(osTimer(moveTimer), osTimerPeriodic, NULL);

  /* 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, osPriorityNormal, 0, 64);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

  /* definition and creation of buttonScanTask */
  osThreadDef(buttonScanTask, buttonScanFunc, osPriorityLow, 0, 128);
  buttonScanTaskHandle = osThreadCreate(osThread(buttonScanTask), NULL);

  /* definition and creation of guiTask */
  osThreadDef(guiTask, guiFunc, osPriorityNormal, 0, 128);
  guiTaskHandle = osThreadCreate(osThread(guiTask), NULL);

  /* definition and creation of motorTask */
  osThreadDef(motorTask, motorFunc, osPriorityAboveNormal, 0, 64);
  motorTaskHandle = osThreadCreate(osThread(motorTask), NULL);

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

  /* Create the queue(s) */
  /* definition and creation of buttonEvents */
  osMessageQDef(buttonEvents, 16, uint16_t);
  buttonEventsHandle = osMessageCreate(osMessageQ(buttonEvents), NULL);

  /* definition and creation of encoderEvents */
  osMessageQDef(encoderEvents, 16, uint16_t);
  encoderEventsHandle = osMessageCreate(osMessageQ(encoderEvents), NULL);

  /* USER CODE BEGIN RTOS_QUEUES */
	/* add queues, ... */
  xInputEvents = xQueueCreate( 8, sizeof( struct Event ) );
  xMotorEvents = xQueueCreate( 4, sizeof( struct MotorEvent ) );
  /* 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 */
	while (1)
	{
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */


	}
  /* USER CODE END 3 */

}
Example #22
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_CAN2_Init();
  MX_DMA2D_Init();
  MX_FMC_Init();
//  MX_SPI1_Init();
//  MX_SPI5_Init();
  MX_TIM2_Init();
  MX_I2C3_Init();

//  SET RESET HIGH ~~ TURN ON


  ILI9341Init();
//  ili9341_Init();
  volatile uint16_t lcd_id =  ili9341_ReadID();

  MX_LTDC_Init();

//  lcd_id++;

  /* USER CODE BEGIN 2 */
  UserInitCan2();

//  HAL_GPIO_WritePin(BMS_ERR_GPIO_Port, BMS_ERR_Pin, GPIO_PIN_RESET);
//  HAL_GPIO_WritePin(BMS_ERR_GPIO_Port, BMS_ERR_Pin, GPIO_PIN_SET);

//  char recv_string[10] = "";
//  HAL_SDRAM_Write_8b(&hsdram1, 0, "hi", 3);
//  HAL_SDRAM_Read_8b(&hsdram1, 0, recv_string, 3);

  /* 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, osPriorityNormal, 0, 128);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

  /* USER CODE BEGIN RTOS_THREADS */
  	  /* Button polling task. 100Hz. */
	  osThreadDef(buttonTask, vPollButtonsTask, osPriorityHigh, 1, 1024);
	  buttonTaskHandle = osThreadCreate(osThread(buttonTask), NULL);

	  osThreadDef(canTask, vCanTask, osPriorityHigh, 1, 1024);
	  canTaskHandle = osThreadCreate(osThread(canTask), NULL);

	  osThreadDef(ledTask, vLedUpdateTask, osPriorityLow, 1, 1024);
	  ledTaskHandle = osThreadCreate(osThread(ledTask), NULL);



  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_QUEUES */
	  osMessageQDef(ibutton_queue, 12, ButtonObject); // Declare a message queue
	  interfaceButtonQueue = osMessageCreate(osMessageQ(ibutton_queue), NULL);

	  osMessageQDef(sbutton_queue, 12, ButtonObject); // Declare a message queue
	  stateButtonQueue = osMessageCreate(osMessageQ(sbutton_queue), NULL);

  /* 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 */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
Example #23
0
int main(void)
{

    /* USER CODE BEGIN 1 */
    CMDLINE_CONTEXT cmd_context;
    const char *zhonx_info = (char *)CONFIG_ZHONX_INFO_ADDR;
    /* 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_ADC2_Init();
    MX_ADC3_Init();
    MX_I2C1_Init();
    MX_RNG_Init();
    MX_TIM1_Init();
    MX_TIM2_Init();
    MX_TIM3_Init();
    MX_TIM4_Init();
    MX_TIM5_Init();
    MX_TIM6_Init();
    MX_TIM7_Init();
    MX_TIM8_Init();
    MX_TIM11_Init();
    MX_USART3_UART_Init();

    /* USER CODE BEGIN 2 */
    expanderInit();
    HAL_Delay(100);
    mainControlInit();
    ssd1306Init(0);
    timesBaseInit();
    ledPowerBlink(990, 10);
    settingsInit();
    mulimeterInit();
    bluetoothInit();
    toneInit();
    spyPostInit();

    positionControlSetPositionType(GYRO);
    mainControlSetFollowType(NO_FOLLOW);

    toneSetVolulme(100);
    tone(F4, 50);
    toneItMode(A4, 50);

    // Register Output callback
    cmd_context.out = blockingPrintf;
    // Initialize Command Line module
    cmdline_init(&cmd_context);

    // Check if robot name is populated in Flash
    memset(zhonxName, 0, sizeof(zhonxName));
    // Retrieve ZHONX information from flash if any
    if (zhonx_info[0] == 'Z')
    {
        strcpy(zhonxName, zhonx_info);
    }

    while (zhonxName[0] == 0)
    {
        menu(zhonxNameMenu);
    }

    while (1)
    {
        menu(mainMenu);
        powerOffConfirmation();
    }

    /* USER CODE END 2 */

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

    /* USER CODE BEGIN 3 */

    /* USER CODE END 3 */

}
Example #24
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  my_usb_init();
  /* 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_TIM1_Init();
  MX_USB_DEVICE_Init();
  MX_USART3_UART_Init();
  MX_TIM2_Init();

  /* USER CODE BEGIN 2 */
  HAL_TIM_Base_Start(&htim2);
  delay_us_init(&htim2);
  softserial_init(SOFTSERIAL_TX_GPIO_Port, SOFTSERIAL_TX_Pin);
  hmi_lcd_init(&huart3);
  cpu_ctrl_init(&htim1);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  HAL_Delay(100);
  hsc_stop();
  cpu_reset();
  lcd_clear();
  addr_input();
  data_input();
  build_ui();
  HAL_Delay(100);

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

  /* USER CODE BEGIN 3 */
    if(is_running == 0)
      addr_data_display_update();

    // z80 reset button
    if(is_button_1_pressed)
    {
      hsc_stop();
      cpu_reset();
      lcd_print_width(130, 110, 180, 45, "CYAN", "RESET");
      is_button_1_pressed = 0;
      HAL_Delay(500);
      build_ui();
    }

    // clk step button
    if(is_button_3_pressed)
    {
      hsc_stop();
      cycle_clock(1);
      lcd_print_width(130, 110, 180, 45, "RED", "CLK STEP");
      is_button_3_pressed = 0;
      HAL_Delay(100);
      build_ui();
    }

    // ins step button
    if(is_button_4_pressed)
    {
      hsc_stop();
      lcd_print_width(130, 110, 180, 45, "GREEN", "INS STEP");
      // cycle clock until we're at next M1 cycle
      while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, M1_Pin) == LOW)
        cycle_clock(1);
      while(HAL_GPIO_ReadPin(CPU_CTRL_PORT, M1_Pin) == HIGH)
        cycle_clock(1);
      is_button_4_pressed = 0;
      HAL_Delay(100);
      build_ui();
    }

    // run/stop button
    if(is_button_5_pressed)
    {
      is_running = (is_running + 1) % 2;
      if(is_running)
      {
        lcd_print_width(130, 110, 180, 45, "GREEN", "RUNNING");
        hsc_start();
      }
      else
      {
        hsc_stop();
        build_ui();
      }
      is_button_5_pressed = 0;
    }

    usb_data = my_usb_readline();
    if(usb_data != NULL && strstr(usb_data, "epm") != NULL)
    {
      hsc_stop();
      program_mode();
      build_ui();
    }
  }
  /* USER CODE END 3 */

}
Example #25
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();

	HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
#ifdef DEBUG_MODE
	usb_init();
	setbuf(stdout, NULL);
#endif 
	HAL_Delay(200); 
  /* Initialize all configured peripherals */
	
  MX_GPIO_Init();
  MX_TIM2_Init();
  MX_USART1_UART_Init();
  MX_USART3_UART_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */


 uint8_t push_button_cmd[] = {NOTF_VOICE_RECORD, 0x00, 0x00}; 


// enable encoders
// HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6, GPIO_PIN_RESET);
uint16_t c = 0; 
uint8_t current_state = 0, old_state = 0; 
 
 while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
    

     current_state = (HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_2) == GPIO_PIN_SET)? 1 : 0; 
      if(( current_state == 1) && ( old_state == 0) ){
     //          LOG("push button ... \r\n"); 
     //          HAL_UART_Transmit(&huart1, push_button_cmd, 3, 1000);

        }
      old_state = current_state; 

    stateMachine();
    controller(); 
    driveMotors(u);
    HAL_Delay(20);
	

}
  /* USER CODE END 3 */

}
Example #26
0
/**
  * @brief  Resume callback.
  * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
  * @param  hpcd: PCD handle
  * @retval None
  */
void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
{
  U8 i,y;
  uint32_t wInterrupt_Mask = 0;
//  USBD_HID_HandleTypeDef *ptr;
//  ptr = (USBD_HID_HandleTypeDef *)(hUsbDeviceFS.pClassData);
  GPIO_InitTypeDef GPIO_InitStruct;
//__GPIOC_CLK_ENABLE();
//__GPIOA_CLK_ENABLE();
//__GPIOB_CLK_ENABLE();
   if (hpcd->Init.low_power_enable) {
//    SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));   
//    SystemClockConfig_Resume();      
     if (remotewakeupon == 0)
//  if ((hpcd->Init.low_power_enable)&&(remotewakeupon == 0))
  {    
    /* Reset SLEEPDEEP bit of Cortex System Control Register */
    SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));   
    SystemClockConfig_Resume(); 
   USBD_LL_Resume(hpcd->pData); 
   HAL_Delay(10);    
    for (i=0;i<3;i++) {
    ((USBD_HID_HandleTypeDef *)&hUsbDeviceFS.pClassData)->state[i] = HID_IDLE;
//      ptr->state[i] = HID_IDLE;
    }
     for (y = 0; y < COLS; y++) {   
         gpio_setDirvalue(matrix[y].port, matrix[y].pin, 0, 1);
//         for (i = 0; i < 10; i++);
     }
        /* Handle Resume state machine */  
     HAL_GPIO_WritePin(LED_RESET_GPIO_Port, LED_RESET_Pin, GPIO_PIN_SET);                    // Low to shut down led controller
//     EXTI->FTSR = 0;
////     for (i = 0; i < 10; i++);
//        __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_All); 
    HAL_NVIC_DisableIRQ(EXTI0_1_IRQn);
    HAL_NVIC_DisableIRQ(EXTI2_3_IRQn);
    HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_1);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_2); 
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_3);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_4);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_5);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_6);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_7);  
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_15);    
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_All);  
//    
//    HAL_NVIC_EnableIRQ(I2C2_IRQn);
      GPIO_InitStruct.Pin = R0_Pin|R1_Pin|R2_Pin|R3_Pin 
                          |R4_Pin|R5_Pin|R6_Pin|R7_Pin 
                          |LED_INT_Pin|SCROLL_UP_Pin|SCROLL_DOWN_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
//  MX_GPIO_Init();
//  MX_CRC_Init();
////  MX_IWDG_Init();
////  MX_TIM6_Init();
////  MX_TIM7_Init();
////  MX_WWDG_Init();
////  MX_USB_DEVICE_Init();
  MX_I2C2_Init();
  MX_TIM2_Init();
//  initLedModule(0);  // initialize LED  
  } else {
      HAL_PCD_ActivateRemoteWakeup((&hpcd_USB_FS));

      /* remote wakeup delay */
      HAL_Delay(10);
      
      /* Disable Remote wakeup */
      HAL_PCD_DeActivateRemoteWakeup((&hpcd_USB_FS));
      USBD_LL_Resume(hpcd->pData);
      HAL_Delay(10);
 //     }
      /* change remote_wakeup feature to 0*/
//      hUsbDeviceFS.dev_remote_wakeup = 0;
       for (y = 0; y < COLS; y++) {   
         gpio_setDirvalue(matrix[y].port, matrix[y].pin, 0, 1);
//         for (i = 0; i < 10; i++);
  }
      HAL_GPIO_WritePin(LED_RESET_GPIO_Port, LED_RESET_Pin, GPIO_PIN_SET);                    // Low to shut down led controller
//      EXTI->FTSR = 0;
// //   __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_All);    
    HAL_NVIC_DisableIRQ(EXTI0_1_IRQn);
    HAL_NVIC_DisableIRQ(EXTI2_3_IRQn);
    HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_1);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_2); 
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_3);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_4);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_5);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_6);
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_7);  
//    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_15);    
////    __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_All);
//    HAL_NVIC_EnableIRQ(I2C2_IRQn); 
      GPIO_InitStruct.Pin = R0_Pin|R1_Pin|R2_Pin|R3_Pin 
                          |R4_Pin|R5_Pin|R6_Pin|R7_Pin 
                          |LED_INT_Pin|SCROLL_UP_Pin|SCROLL_DOWN_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);  
  MX_I2C2_Init();
  MX_TIM2_Init();  
    for (i=0;i<3;i++) {
    ((USBD_HID_HandleTypeDef *)&hUsbDeviceFS.pClassData)->state[i] = HID_IDLE;
//      ptr->state[i] = HID_IDLE;
    }  
    wInterrupt_Mask = USB_CNTR_CTRM  | USB_CNTR_WKUPM | USB_CNTR_SUSPM | USB_CNTR_ERRM \
      | USB_CNTR_ESOFM | USB_CNTR_RESETM;
    
    /*Set interrupt mask*/
    hpcd_USB_FS.Instance->CNTR = wInterrupt_Mask;
    switchModeDetect(); 
        
  }
}
//  MX_GPIO_Init();  
//  MX_I2C2_Init();
//  MX_TIM2_Init(); 
//  initLedModule(0); 
  /* USER CODE END 3 */
//  USBD_LL_Resume(hpcd->pData);
  remotewakeupon=0;
}
Example #27
0
int main(void) {
  HAL_Init();

  Nucleo_BSP_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();

  HAL_TIM_Encoder_Start(&hTIM2, TIM_CHANNEL_ALL);
  HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_1);
  HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_2);

  cnt1 = __HAL_TIM_GET_COUNTER(&hTIM2);
  tick = HAL_GetTick();

  while (1) {
    if (HAL_GetTick() - tick > 1000L) {
      cnt2 = __HAL_TIM_GET_COUNTER(&hTIM2);
      if (__HAL_TIM_IS_TIM_COUNTING_DOWN(&hTIM2)) {
        if (cnt2 < cnt1) /* Check for counter underflow */
          diff = cnt1 - cnt2;
        else
          diff = (65535 - cnt2) + cnt1;
      } else {
        if (cnt2 > cnt1) /* Check for counter overflow */
          diff = cnt2 - cnt1;
        else
          diff = (65535 - cnt1) + cnt2;
      }

      sprintf(msg, "Difference: %d\r\n", diff);
      HAL_UART_Transmit(&huart2, (uint8_t*) msg, strlen(msg), HAL_MAX_DELAY);

      speed = ((diff / PULSES_PER_REVOLUTION) / 60);

      /* If the first three bits of SMCR register are set to 0x3
       * then the timer is set in X4 mode (TIM_ENCODERMODE_TI12)
       * and we need to divide the pulses counter by two, because
       * they include the pulses for both the channels */
      if ((TIM2->SMCR & 0x3) == 0x3)
        speed /= 2;

      sprintf(msg, "Speed: %d RPM\r\n", speed);
      HAL_UART_Transmit(&huart2, (uint8_t*) msg, strlen(msg), HAL_MAX_DELAY);

      dir = __HAL_TIM_IS_TIM_COUNTING_DOWN(&hTIM2);
      sprintf(msg, "Direction: %d\r\n", dir);
      HAL_UART_Transmit(&huart2, (uint8_t*) msg, strlen(msg), HAL_MAX_DELAY);

      tick = HAL_GetTick();
      cnt1 = __HAL_TIM_GET_COUNTER(&hTIM2);
    }

    if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_RESET) {
      /* Invert rotation by swapping CH1 and CH2 CCR value */
      tim1_ch1_pulse = __HAL_TIM_GET_COMPARE(&htim1, TIM_CHANNEL_1);
      tim1_ch2_pulse = __HAL_TIM_GET_COMPARE(&htim1, TIM_CHANNEL_2);

      __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, tim1_ch2_pulse);
      __HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_2, tim1_ch1_pulse);
    }
  }
}
Example #28
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  osKernelInitialize();
  /* 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_TIM2_Init();
  MX_USART2_UART_Init();
  MX_TIM4_Init();
  MX_TIM3_Init();
  MX_ADC1_Init();

  /* USER CODE BEGIN 2 */
//#ifdef  USE_FULL_ASSERT
#ifndef MAC_COORDINATOR
  // Board - Serial identification
  sprintf(Buf, "\x0cNUCLEO-F446 Debug Terminal\r\nVisible Light Communication "
      "Project\r\n---\r\nDEV_CONFIG=%d\r\n\r\n", DEV_CONFIG);
  HAL_UART_Transmit(&huart2, (uint8_t *) Buf, strlen(Buf), 0xffff);
#endif
//#endif
  // Initialize Optical Driver
  DRV_Init();
  // Initialize PHY layer
  PHY_Init();
  // Initialize MAC APP layer
  MAC_AppInit();
  
  // Create threads
#ifdef MAC_COORDINATOR
  tid_blinkLED = osThreadCreate (osThread(blinkLED), NULL);
#endif
  //tid_sendSerial = osThreadCreate (osThread(sendSerial), NULL);
  //tid_checkButton = osThreadCreate (osThread(checkButton), NULL);
  // Start thread execution
  osKernelStart();

  // Run codes
  DRV_RX_Start();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1) {
    osDelay(1000);
#ifdef MAC_COORDINATOR
    osSignalSet(tid_blinkLED, 0x0001);
#endif
  }
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  /* USER CODE END 3 */

}
Example #29
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_DMA_Init();
  MX_ADC_Init();
  MX_TIM2_Init();
  MX_TIM21_Init();

  batpins battery3;
  batpins battery4;
  pwm_timers b3_tims;
  pwm_timers b4_tims;
  batprops props_bat3;
  batprops props_bat4;

  /* Battery 3 */
  b3_tims.conv_timer = htim2;
  b3_tims.dchg_timer = htim21;

  battery3.v_adc_chan = ADC_CHANNEL_4;
  battery3.i_adc_chan = ADC_CHANNEL_8;
  battery3.chg_port = chg_onoff_3_GPIO_Port;
  battery3.chg_pin = chg_onoff_3_Pin;
  battery3.dchg_pin = TIM_CHANNEL_1;
  battery3.conv_chg_pin = TIM_CHANNEL_1;
  battery3.conv_dchg_pin = TIM_CHANNEL_2;
  battery3.pwm_tims = b3_tims;

  props_bat3.i_adc_val = 0;
  props_bat3.v_adc_val = 0;
  props_bat3.adc_val_old = adc_read(battery3.i_adc_chan);
  props_bat3.id_adc_stpt = 400 + props_bat3.adc_val_old;
  props_bat3.ic_adc_stpt = props_bat3.adc_val_old - 600;
  props_bat3.conv_bst_stpt = 200; // Need to calibrate this to boost to desired voltage
  props_bat3.pwm_chg_stpt = 0; 	  // Initialized to 0. Program will change as needed.
  props_bat3.pwm_dchg_stpt = 720; // Initialize near where discharge FET turns on
  props_bat3.pi = 0;

  /* Battery 4 */
  b4_tims.conv_timer = htim2;
  b4_tims.dchg_timer = htim21;

  battery4.v_adc_chan = ADC_CHANNEL_11;
  battery4.i_adc_chan = ADC_CHANNEL_10;
  battery4.chg_port = chg_onoff_4_GPIO_Port;
  battery4.chg_pin = chg_onoff_4_Pin;
  battery4.dchg_pin = TIM_CHANNEL_2;
  battery4.conv_chg_pin = B4_CHG_CHAN; // Change in h file (used in multiple locations, dma_offset func)
  battery4.conv_dchg_pin = TIM_CHANNEL_4;
  battery4.pwm_tims = b4_tims;

  props_bat4.i_adc_val = 0;
  props_bat4.v_adc_val = 0;
  props_bat4.adc_val_old = adc_read(battery4.i_adc_chan);
  props_bat4.id_adc_stpt = 500 + props_bat4.adc_val_old;
  props_bat4.ic_adc_stpt = props_bat4.adc_val_old - 200;
  props_bat4.conv_bst_stpt = 200; // Need to calibrate this to boost to desired voltage
  props_bat4.pwm_chg_stpt = 0; 	  // Initialized to 0. Program will change as needed.
  props_bat4.pwm_dchg_stpt = 720; // Initialize near where discharge FET turns on
  props_bat4.pi = 0;

  /* Initialize global variables */
#ifdef BAT1
  TimeCounter3 = 0;
  TimeCounter4 = 0;
  uint32_t restStartms3 = 0;
  uint32_t i3 = 0;
  uint32_t voltage3 = 0;
  uint32_t current3 = 720;
  status bat_stat3 = OK;
  i3_origin = props_bat3.adc_val_old;
#endif

#ifdef BAT2
  uint32_t restStartms4 = 0;
  uint32_t i4 = 0;
  uint32_t voltage4 = 0;
  uint32_t current4 = 720;
  status bat_stat4 = OK;
  i4_origin = props_bat4.adc_val_old;
#endif

  //uint32_t dc_pwm[1] = {800};//, 500, 200, 300, 400, 500, 600, 700, 250, 750};
  //uint32_t test2[2] = {100, 900};
  //uint32_t sine = 0;

  /* Initialize converter and charge / discharge pins   */
  conv_init(battery3);
  conv_init(battery4);

  //HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_3, &dc_pwm, (uint16_t)1);
  //HAL_Delay(10);
  //HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_4, &dc_pwm[8], (uint16_t)2);
  //HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_1, 200, (uint16_t)SINE_RES_500HZ);
  //HAL_TIM_PWM_Start_DMA(&htim2, TIM_CHANNEL_4, 800, (uint16_t)SINE_RES_500HZ); //Bat2 conv dchg
  //pwm_sine_Start(battery3.pwm_tims.conv_timer, battery3.conv_dchg_pin, dc_pwm, sine); // Boost (discharge)
  //pwm_sine_Start(battery3.pwm_tims.conv_timer, battery3.conv_chg_pin,  dc_pwm, sine); // Buck (charge)
  //pwm_sine_Start(battery4.pwm_tims.conv_timer, battery4.conv_dchg_pin, test2, sine); // Boost (discharge)
  //pwm_sine_Start(battery4.pwm_tims.conv_timer, battery4.conv_chg_pin, 400, sine); // Buck (charge)
  //pwm_Set(battery3.pwm_tims.dchg_timer, battery3.dchg_pin, 750);
 // pwm_Set(battery4.pwm_tims.dchg_timer, battery4.dchg_pin, 760);
  //pwm_sine_Start(battery3.pwm_tims.conv_timer, battery3.conv_chg_pin, dc_pwm, sine); // Buck (charge)
  //HAL_GPIO_WritePin(battery3.chg_port, battery3.chg_pin, GPIO_PIN_SET); // Charging On
  //HAL_GPIO_WritePin(battery4.chg_port, battery4.chg_pin, GPIO_PIN_SET); // Charging On
  //pwm_sine_Start(battery4.pwm_tims.conv_timer, battery4.conv_chg_pin, dc_pwm, sine); // Buck (charge)
  //HAL_TIM_PWM_Start(battery4.pwm_tims.conv_timer, battery4.conv_dchg_pin);
  //HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2); // Bat1 conv dchg

  uint8_t u8_oc3 = 0;
  uint8_t u8_oc4 = 0;

  // Wait for batteries to be connected
  //while(adc_read(battery3.v_adc_chan) < 500 || adc_read(battery4.v_adc_chan) < 500) {}

  /* Infinite loop */
  while (1)
  {

#ifdef BAT1
	  /* First battery */
	  if(TimeCounter3>=5) // 4ms, ie 2 periods of 500Hz sine wave
	  	  {
	  		  switch(bat_stat3) {
	  		  case DISCHARGE:
	  			  bat_stat3 = discharge_main(battery3, &props_bat3, &restStartms3, i3, bat_stat3);
	  			  break;
	  		  case CC:
	  			  bat_stat3 = chg_ctrl(battery3, &props_bat3, i3, i3_origin);
	  			  //HAL_Delay(1);
	  			  break;
	  		  case CV:
	  			  bat_stat3 = cv_main(battery3, &props_bat3, &restStartms3, i3, i3_origin, bat_stat3);
	  			  break;
	  		  case FULL:
	  			  if(HAL_GetTick() - restStartms3 >= REST)
	  			  {
						props_bat3.i_adc_val = 0;
						props_bat3.v_adc_val = 0;
						props_bat3.adc_val_old = adc_read(battery3.i_adc_chan);
						bat_stat3 = DISCHARGE;
	  			  }
	  			  break;
	  		  case LVDC:
	  			if(HAL_GetTick() - restStartms3 >= REST)
	  			  {
					  props_bat3.i_adc_val = 0;
					  props_bat3.v_adc_val = 0;
					  props_bat3.adc_val_old = adc_read(battery3.i_adc_chan);
					  bat_stat3 = CC;
	  			  }
	  			  break;
	  		  case OK:
	  			  props_bat3.i_adc_val = 0; // normally reset in d/chg func, but not used so reset here
	  			  props_bat3.v_adc_val = 0; // normally reset in d/chg func, but not used so reset here
	  			  bat_stat3 = CC;
	  			  break;
	  		  case OVERCURRENT:
	  			  bat_stat3 = OVERCURRENT;
	  			  break;
	  		  default:
	  			  bat_stat3 = OK;
	  			  break;
	  		  }
	  		  TimeCounter3 = 0;
	  		  i3 = 0;
	  	  }

  	  /* Update ADC readings */
  	  current3 = adc_read(battery3.i_adc_chan);
  	  voltage3 = adc_read(battery3.v_adc_chan);
  	  props_bat3.i_adc_val = props_bat3.i_adc_val + current3;
  	  props_bat3.v_adc_val = props_bat3.v_adc_val + voltage3;

  	  /* Over-current protection */
  	  if(current3>3950 || current3<100)
  	  {
  		  u8_oc3++;
  		  if(u8_oc3 > 15)
  		  {
  			conv_init(battery3);
  			bat_stat3 = OVERCURRENT;
  		  }
  	  }
  	  else
  	  {
  		  u8_oc3 = 0;
  	  }
  	  i3++;
#endif

#ifdef BAT2
	  /* Second battery */
	  if(TimeCounter4>=5) // 4ms, ie 2 periods of 500Hz sine wave
		  {
			  switch(bat_stat4) {
			  case DISCHARGE:
				  bat_stat4 = discharge_main(battery4, &props_bat4, &restStartms4, i4, bat_stat4);
				  break;
			  case CC:
				  bat_stat4 = chg_ctrl(battery4, &props_bat4, i4, i4_origin);
				  break;
			  case CV:
				  bat_stat4 = cv_main(battery4, &props_bat4, &restStartms4, i4, i4_origin, bat_stat4);
				  break;
			  case FULL:
				  if(HAL_GetTick() - restStartms4 >= REST)
				  {
						props_bat4.i_adc_val = 0;
						props_bat4.v_adc_val = 0;
						props_bat4.adc_val_old = adc_read(battery4.i_adc_chan);
						bat_stat4 = DISCHARGE;
				  }
				  break;
			  case LVDC:
				if(HAL_GetTick() - restStartms4 >= REST)
				  {
					  props_bat4.i_adc_val = 0;
					  props_bat4.v_adc_val = 0;
					  props_bat4.adc_val_old = adc_read(battery4.i_adc_chan);
					  bat_stat4 = CC;
				  }
				  break;
			  case OK:
				  props_bat4.i_adc_val = 0; // normally reset in d/chg func, but not used so reset here
				  props_bat4.v_adc_val = 0; // normally reset in d/chg func, but not used so reset here
				  bat_stat4 = CC;
				  break;
			  case OVERCURRENT:
				  bat_stat4 = OVERCURRENT;
				  break;
			  default:
				  bat_stat4 = OK;
				  break;
			  }
			  TimeCounter4 = 0;
			  i4 = 0;
		  }

	  /* Update ADC readings */
  	  current4 = adc_read(battery4.i_adc_chan);
  	  voltage4 = adc_read(battery4.v_adc_chan);
  	  props_bat4.i_adc_val = props_bat4.i_adc_val + current4;
  	  props_bat4.v_adc_val = props_bat4.v_adc_val + voltage4;

  	  /* Over-current protection */
  	  if(current4>3950 || current4<100)
  	  {
  		  u8_oc4++;
  		  if(u8_oc4 > 15)
  		  {
  			conv_init(battery4);
  			bat_stat4 = OVERCURRENT;
  		  }
  	  }
  	  else
  	  {
  		  u8_oc4 = 0;
  	  }
  	  i4++;

#endif

	  HAL_SYSTICK_IRQHandler();

  }


}