示例#1
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 */

}
示例#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_CAN_Init();
  MX_I2C1_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

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

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
示例#3
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_CAN_Init();
  MX_USART1_UART_Init();

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

  for (int i = 0; i < 10; ++i)
  {
	  led_blink();
	  HAL_Delay(100);
  }

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  CanRxMsgTypeDef rx_msg;
  uint8_t prebuf[12];
  uint8_t uart_msg[18];

  while (1)
  {
	  //

	  while (__HAL_CAN_MSG_PENDING(&hcan, CAN_FIFO0) <= 0) ;

	  hcan.pRxMsg = &rx_msg;
	  if (HAL_OK != HAL_CAN_Receive(&hcan, CAN_FIFO0, 3))
		  continue;

	  //

	  uint8_t flags = rx_msg.DLC & 0xf;

	  if (rx_msg.RTR == CAN_RTR_REMOTE)
		  flags |= 0x10;

	  if (rx_msg.IDE == CAN_ID_EXT)
		  flags |= 0x20;

	  uint32_t id = (rx_msg.IDE == CAN_ID_EXT ? rx_msg.ExtId : rx_msg.StdId);

	  for (int i = 3; i >= 0; --i)
	  {
		  prebuf[i] = (id & 0xff);
		  id >>= 8;
	  }

	  for (int i = 4; i < 12; ++i)
		  prebuf[i] = 0;

	  for (int i = 0; i < 8 && i < rx_msg.DLC; ++i)
		  prebuf[4+i] = rx_msg.Data[i];

	  //

	  int j = 0;
	  for (int i = 0; i < 12; i += 3, j += 4)
	  {
		  uint32_t triple = 0;
		  for (int k = 0; k < 3; ++k)
		  {
			  triple <<= 8;
			  triple += prebuf[i+k];
		  }

		  for (int k = 0; k < 4; ++k)
		  {
			  uart_msg[j+3-k] = basis_64[triple & 63];
			  triple >>= 6;
		  }

	  }

	  uart_msg[16] = basis_64[flags];
	  uart_msg[17] = '\n';

	  //

	  HAL_UART_Transmit(&huart1, uart_msg, 18, 1000);

	  //

	  led_blink();

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
示例#4
0
文件: main.c 项目: uavosky/STM32Cube
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_CAN_Init();
  MX_IWDG_Init();
  MX_USART1_UART_Init();
  MX_USART2_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 */

  /* 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 */

}
示例#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_CAN_Init();
  MX_I2C1_Init();
  MX_SPI1_Init();
  MX_USART1_UART_Init();
  MX_USART3_UART_Init();

  /* USER CODE BEGIN 2 */
  /* these calls are from arduino main */

	init();

	initVariant();
	
	HAL_Delay(3000); 	/* Wait 3 seconds to enable a serial coms channel */
	
	/* 
		Usart6 is linked to printf for diagnostic use It is also mapped to
		alternate function pins 12 and 14.  This code is adapted from
		the prinf demo in the STM32F401 Nucleo examples folder
	*/
	
	//printf("Serial backchannel enabled.\r\n");
  
  	/* Arduino optionally sets up USB callback stream here 
#if defined(USBCON)
	USBDevice.attach();
#endif
	*/
	
	setup();

  /* USER CODE END 2 */

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

  /* USER CODE BEGIN 3 */
	loop();
	/* Arduino callback	if (serialEventRun) serialEventRun(); */

  }
  /* USER CODE END 3 */

}