Esempio n. 1
0
static int acc_init(void) {
	int res;

	res = BSP_ACCELERO_Init();
    if (res != HAL_OK) {
        printk("BSP_ACCLEERO_Init failed, returned %d\n", res);
        return -1;
    }

    acc_calculate_offset();

	return res;
}
Esempio n. 2
0
/**
  * @brief  Test ACCELERATOR MEMS Hardware.
  *         The main objective of this test is to check acceleration on 2 axes X and Y
  * @param  None
  * @retval None
  */
void ACCELERO_MEMS_Test(void)
{
  /* Init Accelerometer MEMS */
  if(BSP_ACCELERO_Init() != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler(); 
  }
  
  UserPressButton = 0;
  while(!UserPressButton)
  {
    ACCELERO_ReadAcc();
  }
}  
Esempio n. 3
0
/**
  * @brief  Test Gyroscope MEMS Hardware.
  *         The main objectif of this test is to check the hardware connection of the 
  *         MEMS peripheral.
  * @param  None
  * @retval None
  */
void GYRO_MEMS_Test(void)
{
  /* Init Gyroscope MEMS */
  if(BSP_ACCELERO_Init() != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler(); 
  }
  
  UserPressButton = 0;
  while(!UserPressButton)
  {
    GYRO_ReadAng();
  }
}  
Esempio n. 4
0
int main(int argc, char **argv)
{

	uint32_t i;
	uint8_t accelRc, gyroRc;
	/* Configure the system clock */
	SystemClock_Config();

	HAL_Init();
	TerminalInit();  /* Initialize UART and USB */
	/* Configure the LEDs... */
	for(i=0; i<numLEDs; i++) {
		BSP_LED_Init(LEDs[i]);
	}

	/* Initialize the pushbutton */
	BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);

	/* Initialize the Accelerometer */
	accelRc = BSP_ACCELERO_Init();
	if(accelRc != ACCELERO_OK) {
		printf("Failed to initialize acceleromter\n");
		Error_Handler();
	}

	/* Initialize the Gyroscope */
	gyroRc = BSP_GYRO_Init();
	if(gyroRc != GYRO_OK) {
		printf("Failed to initialize Gyroscope\n");
		Error_Handler();
	}

	HD44780_Init();                       // lcd init 
	HD44780_PutStr("Hello World!");       
	hd44780_wr_cmd(0xC0); // to change curser to next line
	HD44780_PutStr("Hello Test !");       //print text


	while(1) {
		TaskInput();
	}

	return 0;
}
int main(int argc, char **argv)
{
  uint32_t i;
  uint8_t accelRc, gyroRc;
  /* Configure the system clock */
  SystemClock_Config();

  HAL_Init();
  TerminalInit();  /* Initialize UART and USB */
  /* Configure the LEDs... */
  for(i=0; i<numLEDs; i++) {
    BSP_LED_Init(LEDs[i]);
  }

  /* Initialize the pushbutton */
  BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);

  /* Initialize the Accelerometer */
  accelRc = BSP_ACCELERO_Init();
  if(accelRc != ACCELERO_OK) {
    printf("Failed to initialize acceleromter\n");
    Error_Handler();
  }

  /* Initialize the Gyroscope */
  gyroRc = BSP_GYRO_Init();
  if(gyroRc != GYRO_OK) {
    printf("Failed to initialize Gyroscope\n");
    Error_Handler();
  }



  while(1) {
    TaskInput();
     taskcounter();
  }

  return 0;
}
Esempio n. 6
0
int main(void) {
	HAL_Init();

	led_all_init();
	SystemClock_Config();

	if (BSP_ACCELERO_Init() != ACCELERO_OK) {
		Error_Handler();
	}
	BSP_ACCELERO_Click_ITConfig();
	TIM_LED_Config();

	isLooping = 1;
	ledState = LEDS_OFF;

	BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);

	// Link the USB Host disk I/O driver
	if (FATFS_LinkDriver(&USBH_Driver, usbDrivePath) == 0) {
		USBH_Init(&hUSBHost, usbUserProcess, 0);
		USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS);
		USBH_Start(&hUSBHost);

		while (1) {
			switch (appState) {
			case APP_START:
				startApp();
				break;
			case APP_IDLE:
			default:
				break;
			}
			USBH_Process(&hUSBHost);
		}
	}

	while (1) {
	}
}
Esempio n. 7
0
/**
  * @brief Test ACCELERATOR MEMS Hardware.
  *   The main objective of this test is to check acceleration on 2 axis X and Y
  * @param None
  * @retval None
  */
void ACCELERO_MEMS_Test(void)
{
  MEMS_SetHint();

  /* Init Accelerometer Mems */
  if(BSP_ACCELERO_Init() != HAL_OK)
  {
    BSP_LCD_SetTextColor(LCD_COLOR_RED);    
    BSP_LCD_DisplayStringAt(0, 115, (uint8_t*)"Initialization problem", CENTER_MODE); 
    BSP_LCD_DisplayStringAt(0, 130, (uint8_t*)"MEMS cannot be initialized", CENTER_MODE); 
    return;
  }

  while (1)
  {
    ACCELERO_ReadAcc();
    
    if(CheckForUserInput() > 0)
    {
      return;
    }
  }
}
Esempio n. 8
0
File: main.c Progetto: kmos/janusb
/* Setup Function --------------------------*/
void setup(){
	HAL_Init();
	//Initializze board's led
	BSP_LED_Init(0);
	BSP_LED_Init(1);
	BSP_LED_Init(2);
	BSP_LED_Init(3);
	//Initializze board's accelerometer
    BSP_ACCELERO_Init();
	//Initializze USB device
	BSP_LED_On(LED3);
	USBD_Init(&USBD_Device, &VCP_Desc, 0);
	USBD_RegisterClass(&USBD_Device, &USBD_CDC);
	USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_Template_fops);
	USBD_Start(&USBD_Device);
	HAL_Delay(4000);
	BSP_LED_Off(LED3);
	//Initializze ADC conv
	MX_ADC1_Init();

	//Initializze logical variable and memory areas
	memset(request, '\0',256);
	memset(response,'\0',256);
}
Esempio n. 9
0
/**
  * @brief  Execute the demo application.
  * @param  None
  * @retval None
  */
static void Demo_Exec(void)
{
    uint8_t togglecounter = 0x00;

    /* Initialize Accelerometer MEMS*/
    if(BSP_ACCELERO_Init() != HAL_OK)
    {
        /* Initialization Error */
        Error_Handler();
    }

    while(1)
    {
        DemoEnterCondition = 0x00;

        /* Reset UserButton_Pressed variable */
        UserButtonPressed = 0x00;

        /* Configure LEDs to be managed by GPIO */
        BSP_LED_Init(LED3);
        BSP_LED_Init(LED4);
        BSP_LED_Init(LED5);
        BSP_LED_Init(LED6);

        /* SysTick end of count event each 10ms */
        SystemCoreClock = HAL_RCC_GetHCLKFreq();
        SysTick_Config(SystemCoreClock / 100);

        /* Turn OFF all LEDs */
        BSP_LED_Off(LED4);
        BSP_LED_Off(LED3);
        BSP_LED_Off(LED5);
        BSP_LED_Off(LED6);

        /* Waiting User Button is pressed */
        while (UserButtonPressed == 0x00)
        {
            /* Toggle LED4 */
            BSP_LED_Toggle(LED4);
            HAL_Delay(10);
            /* Toggle LED4 */
            BSP_LED_Toggle(LED3);
            HAL_Delay(10);
            /* Toggle LED4 */
            BSP_LED_Toggle(LED5);
            HAL_Delay(10);
            /* Toggle LED4 */
            BSP_LED_Toggle(LED6);
            HAL_Delay(10);
            togglecounter ++;
            if (togglecounter == 0x10)
            {
                togglecounter = 0x00;
                while (togglecounter < 0x10)
                {
                    BSP_LED_Toggle(LED4);
                    BSP_LED_Toggle(LED3);
                    BSP_LED_Toggle(LED5);
                    BSP_LED_Toggle(LED6);
                    HAL_Delay(10);
                    togglecounter ++;
                }
                togglecounter = 0x00;
            }
        }

        /* Waiting User Button is Released */
        while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED)
        {}
        UserButtonPressed = 0x00;

        /* TIM4 channels configuration */
        TIM4_Config();

        DemoEnterCondition = 0x01;

        /* USB configuration */
        Demo_USBConfig();

        /* Waiting User Button is pressed */
        while (UserButtonPressed == 0x00)
        {}

        /* Waiting User Button is Released */
        while (BSP_PB_GetState(BUTTON_KEY) != KEY_NOT_PRESSED)
        {}

        /* Disconnect the USB device */
        USBD_Stop(&hUSBDDevice);
        USBD_DeInit(&hUSBDDevice);
        if(HAL_TIM_PWM_DeInit(&htim4) != HAL_OK)
        {
            /* Initialization Error */
            Error_Handler();
        }
    }
}
Esempio n. 10
0
/**
  * @brief Test Audio Hardware.
  *   The main objective of this test is to check the hardware connection of the 
  *   Audio peripheral.
  * @param  None
  * @retval None
  */
void AudioPlay_Test(void)
{  
  /* Initial volume level (from 0 (Mute) to 100 (Max)) */
  __IO uint8_t volume = 70;

  /* Initialize MEMS Accelerometer mounted on STM32F4-Discovery board */
  if(BSP_ACCELERO_Init() != ACCELERO_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
  
  /* MEMS Accelerometer configure to manage PAUSE, RESUME operations */
  BSP_ACCELERO_Click_ITConfig();
  
  /* Turn ON LED6: start of Audio file play */
  BSP_LED_On(LED6);
  
  /* Retrieve Wave Sample rate*/
  waveformat = (WAVE_FormatTypeDef*) AUDIO_FILE_ADDRESS;
  
  /* Initialize Audio Device */
  if(BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_AUTO, volume, waveformat->SampleRate) != 0)
  {
    Error_Handler();
  }
  
  /*Set variable used to stop player before starting */
  UserPressButton = 0;
  AudioTest = 0;
  
  /* Set the total number of data to be played */
  AudioTotalSize = AUDIO_FILE_SIZE;  
  /* Set the current audio pointer position */
  CurrentPos = (uint16_t *)(AUDIO_FILE_ADDRESS);
  /* Start the audio player */
  BSP_AUDIO_OUT_Play(CurrentPos, AudioTotalSize);  
  /* Update the remaining number of data to be played */
  AudioRemSize = AudioTotalSize - AUDIODATA_SIZE * DMA_MAX(AudioTotalSize);   
  /* Update the current audio pointer position */
  CurrentPos += DMA_MAX(AudioTotalSize);
  
  /* Infinite loop */
  while(!UserPressButton)
  { 
    if (PauseResumeStatus == PAUSE_STATUS)
    {
      /* Turn ON LED4: Audio play in pause */
      BSP_LED_On(LED4);
      
      /* Pause playing */
      BSP_AUDIO_OUT_Pause();
      PauseResumeStatus = IDLE_STATUS;
    }
    else if (PauseResumeStatus == RESUME_STATUS)
    {
      /* Turn OFF LED4: Audio play running */
      BSP_LED_Off(LED4);
      
      /* Resume playing */
      BSP_AUDIO_OUT_Resume();
      PauseResumeStatus = IDLE_STATUS;
    }
  }
  
  /* Stop Player before close Test */
  if (BSP_AUDIO_OUT_Stop(CODEC_PDWN_HW) != AUDIO_OK)
  {
    /* Audio Stop error */
    Error_Handler();
  }
}
Esempio n. 11
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 LED3, LED4, LED5 and LED6 */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  BSP_LED_Init(LED5);
  BSP_LED_Init(LED6);
 
  /* Configure the system clock to 84 MHz */
  SystemClock_Config(); 
   
  /* Initialize MEMS Accelerometer mounted on STM32F4-Discovery board */
  if(BSP_ACCELERO_Init() != ACCELERO_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
  
  /* Enable click config for pause/play */
  BSP_ACCELERO_Click_ITConfig();
  
  /* Turn ON LED4: start of application */
  BSP_LED_On(LED4);
  
  /* Configure TIM4 Peripheral to manage LEDs lighting */
  TIM_LED_Config();
  
  /* Turn OFF all LEDs */
  LEDsState = LEDS_OFF;
  
  /* Initialize User Button */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
  
  /*##-1- Link the USB Host disk I/O driver ##################################*/
  application_init();
  
  /*##-2- Init Host Library ################################################*/
  USBH_Init(&hUSBHost, USBH_UserProcess, 0);
  
  /*##-3- Add Supported Class ##############################################*/
  USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS);
  
  /*##-4- Start Host Process ###############################################*/
  USBH_Start(&hUSBHost);  
  
  /* Run Application (Blocking mode)*/
  while (1)
  {
    application_task();
    
    /* USBH_Background Process */
    USBH_Process(&hUSBHost);
  }
}
Esempio n. 12
0
static void HW_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStruct;

  /* Init STM32F401 discovery LEDs */
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  BSP_LED_Init(LED5);
  BSP_LED_Init(LED6);

  /* Init SPI and I2C */
  GYRO_IO_Init();
  COMPASSACCELERO_IO_Init();

  /* Init on-board AccelMag */
  BSP_ACCELERO_Init();

  /* Init BlueNRG CS, Reset, and IRQ pin */
  BLUENRG_CS_GPIO_CLK_ENABLE();
  GPIO_InitStruct.Pin   = BLUENRG_CS_PIN;
  GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull  = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  HAL_GPIO_Init(BLUENRG_CS_GPIO_PORT, &GPIO_InitStruct);
  HAL_GPIO_WritePin(BLUENRG_CS_GPIO_PORT, BLUENRG_CS_PIN, GPIO_PIN_SET);

  BLUENRG_RESET_GPIO_CLK_ENABLE();
  GPIO_InitStruct.Pin   = BLUENRG_RESET_PIN;
  GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull  = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(BLUENRG_RESET_GPIO_PORT, &GPIO_InitStruct);

  BLUENRG_IRQ_GPIO_CLK_ENABLE();
  GPIO_InitStruct.Pin   = BLUENRG_IRQ_PIN;
  GPIO_InitStruct.Mode  = GPIO_MODE_IT_RISING;
  GPIO_InitStruct.Pull  = GPIO_NOPULL;
  HAL_GPIO_Init(BLUENRG_IRQ_GPIO_PORT, &GPIO_InitStruct);

#ifdef WITH_USART
  /* Init USART port */
  UsartHandle.Instance        = USART2;
  UsartHandle.Init.BaudRate   = 9600;
  UsartHandle.Init.WordLength = USART_WORDLENGTH_8B;
  UsartHandle.Init.StopBits   = USART_STOPBITS_1;
  UsartHandle.Init.Parity     = USART_PARITY_NONE;
  UsartHandle.Init.Mode       = USART_MODE_TX_RX;
  if (HAL_USART_Init(&UsartHandle) != HAL_OK)
  {
    ColorfulRingOfDeath();
  }
#endif

#ifdef WITH_VCP
  /* Init Device Library */
  USBD_Init(&hUSBDDevice, &VCP_Desc, 0);

  /* Add Supported Class */
  USBD_RegisterClass(&hUSBDDevice, &USBD_CDC);

  /* Add CDC Interface Class */
  USBD_CDC_RegisterInterface(&hUSBDDevice, &USBD_CDC_fops);

  /* Start Device Process */
  USBD_Start(&hUSBDDevice);
#endif
}