Esempio n. 1
0
/**
  * @brief  IAP Write Flash memory.
  * @param  None
  * @retval None
  */
void COMMAND_Download(void)
{
  /* Open the binary file to be downloaded */
  if(f_open(&MyFileR, DOWNLOAD_FILENAME, FA_READ) == FR_OK)
  {
    if(MyFileR.fsize > USER_FLASH_SIZE)
    {
      /* No available Flash memory size for the binary file: Turn LED4 On and 
         Toggle LED3 in infinite loop */
      BSP_LED_On(LED4); 
      Fail_Handler();
    }
    else
    {
      /* Download On Going: Turn LED4 On */
      BSP_LED_On(LED4); 
      
      /* Erase FLASH sectors to download image */
      if(FLASH_If_EraseSectors(APPLICATION_ADDRESS) != 0x00)
      {
        /* Flash erase error: Turn LED4 On and Toggle LED2 and LED3 in 
           infinite loop */
        BSP_LED_Off(LED4); 
        Erase_Fail_Handler();
      }
      
      /* Program flash memory */
      COMMAND_ProgramFlashMemory();
      
      /* Download Done: Turn LED4 Off and LED2 On */
      BSP_LED_Off(LED4); 
      BSP_LED_On(LED2); 
      
      /* Close file */
      f_close(&MyFileR);
    }
  }
  else
  {
    /* The binary file is not available: Turn LED1, LED2 and LED4 On and Toggle 
       LED3 in infinite loop */
    BSP_LED_On(LED1);
    BSP_LED_On(LED2);
    BSP_LED_On(LED4);
    Fail_Handler();
    
  }
}
Esempio n. 2
0
/**
  * @brief  USBH_USR_DeviceSpeedDetected
  *         Displays the message on LCD for device speed
  * @param  Device speed:
  * @retval None
  */
void USBH_USR_DeviceSpeedDetected(uint8_t DeviceSpeed)
{
  if ((DeviceSpeed != HPRT0_PRTSPD_FULL_SPEED)&&(DeviceSpeed != HPRT0_PRTSPD_LOW_SPEED))
  {
    /* Toggle Red LED in infinite loop: USB device disconnected */
    Fail_Handler();
  }
}
Esempio n. 3
0
/**
  * @brief  USBH_USR_DeviceSpeedDetected
  *         Displays the message on LCD for device speed
  * @param  Device speed:
  * @retval None
  */
void USBH_USR_DeviceSpeedDetected(uint8_t DeviceSpeed)
{
	if ((DeviceSpeed != HPRT0_PRTSPD_FULL_SPEED)
	&&  (DeviceSpeed != HPRT0_PRTSPD_LOW_SPEED)
		)
	{
		USBH_USR_ApplicationState = USH_USR_BADSPEED;
		Fail_Handler();
	}
}
Esempio n. 4
0
/**
  * @brief  IAP write memory.
  * @param  None
  * @retval None
  */
void COMMAND_DOWNLOAD(void)
{
  /* Open the binary file to be downloaded */
  if (f_open(&fileR, DOWNLOAD_FILENAME, FA_READ) == FR_OK)
  {
    if (fileR.fsize > USER_FLASH_SIZE)
    {
      /* Toggle Red LED in infinite loop: No available Flash memory size for 
         the binary file */
      Fail_Handler();
    }
    else
    {  
      /* Erase FLASH sectors to download image */
      if (FLASH_If_EraseSectors(APPLICATION_ADDRESS) != 0x00)
      {
        /* Toggle Red LED in infinite loop: Flash erase error */
        Fail_Handler();
      }
      
      STM_EVAL_LEDOff(LED3);
      /* Program flash memory */
      COMMAND_ProgramFlashMemory();
      
      /* Set Green LED ON: Download Done */
      STM_EVAL_LEDOn(LED3); 

      /* Close file and filesystem */
      f_close (&fileR);
    }
  }
  else
  {
    /* Toggle Red LED in infinite loop: the binary file is not available */
    Fail_Handler();
  }
}
Esempio n. 5
0
/**
  * @brief  MEMS accelerometre management of the timeout situation.
  * @param  None.
  * @retval None.
  */
uint32_t LIS302DL_TIMEOUT_UserCallback(void)
{
  /* MEMS Accelerometer Timeout error occured during Test program execution */
  if (DemoEnterCondition == 0x00)
  {
    /* Timeout error occured for SPI TXE/RXNE flags waiting loops.*/
    Fail_Handler();
  }
  /* MEMS Accelerometer Timeout error occured during Demo execution */
  else
  {
    while (1)
    {
    }
  }
  return 0;
}
Esempio n. 6
0
/**
  * @brief  Programs the internal Flash memory. 
  * @param  None
  * @retval None
  */
static void COMMAND_ProgramFlashMemory(void)
{
  uint32_t programcounter = 0x00;
  uint8_t readflag = TRUE;
  uint16_t bytesread;
  
  /* RAM Address Initialization */
  RamAddress = (uint32_t) &RAM_Buf;
  
  /* Erase address init */
  LastPGAddress = APPLICATION_ADDRESS;
  
  /* While file still contain data */
  while ((readflag == TRUE))
  {
    /* Read maximum 512 Kbyte from the selected file */
    f_read (&MyFileR, RAM_Buf, BUFFER_SIZE, (void *)&bytesread);
    
    /* Temp variable */
    TmpReadSize = bytesread;
    
    /* The read data < "BUFFER_SIZE" Kbyte */
    if(TmpReadSize < BUFFER_SIZE)
    {
      readflag = FALSE;
    }
    
    /* Program flash memory */
    for(programcounter = TmpReadSize; programcounter != 0; programcounter -= 4)
    {
      TmpProgramCounter = programcounter;
      /* Write word into flash memory */
      if( FLASH_If_Write((LastPGAddress- TmpProgramCounter + TmpReadSize), \
        *(uint32_t *)(RamAddress - programcounter + TmpReadSize )) != 0x00)
      {
        /* Flash programming error: Turn LED3 On and Toggle LED3 in infinite loop */
        BSP_LED_On(LED3);
        Fail_Handler();
      }
    }
    /* Update last programmed address value */
    LastPGAddress = LastPGAddress + TmpReadSize;
  }  
} 
Esempio n. 7
0
/**
  * @brief  Programs the internal Flash memory. 
  * @param  None
  * @retval None
  */
void COMMAND_ProgramFlashMemory(void)
{
  __IO uint32_t programcounter = 0x00;
  uint8_t readflag = TRUE;
  uint16_t BytesRead;
  
  /* RAM Address Initialization */
  RamAddress = (uint32_t) & RAM_Buf;
  
  /* Erase address init */
  LastPGAddress = APPLICATION_ADDRESS;
  
  /* While file still contain data */
  while ((readflag == TRUE) && (HCD_IsDeviceConnected(&USB_OTG_Core) == 1))
  {
    /* Read maximum 512 Kbyte from the selected file */
    f_read (&fileR, RAM_Buf, BUFFER_SIZE, (void *)&BytesRead);
    
    /* Temp variable */
    TmpReadSize = BytesRead;
    
    /* The read data < "BUFFER_SIZE" Kbyte */
    if (TmpReadSize < BUFFER_SIZE)
    {
      readflag = FALSE;
    }
    
    /* Program flash memory */
    for (programcounter = TmpReadSize; programcounter != 0; programcounter -= 4)
    {
      TmpProgramCounter = programcounter;
      /* Write word into flash memory */
      if (FLASH_If_ProgramWord((LastPGAddress - TmpProgramCounter + TmpReadSize), \
        *(__IO uint32_t *)(RamAddress - programcounter + TmpReadSize)) != FLASH_COMPLETE)
      {
        /* Toggle Red LED in infinite loop: Flash programming error */
        Fail_Handler();
      }
    }
    /* Update last programmed address value */
    LastPGAddress = LastPGAddress + TmpReadSize;
  }
}
Esempio n. 8
0
/**
  * @brief  IAP Read all flash memory.
  * @param  None
  * @retval None
  */
void COMMAND_Upload(void)
{
  __IO uint32_t address = APPLICATION_ADDRESS;
  __IO uint32_t counterread = 0x00;
  uint32_t tmpcounter = 0x00, indexoffset = 0x00;
  FlagStatus readoutstatus = SET;
  uint16_t byteswritten;
  
  /* Get the read out protection status */
  readoutstatus = FLASH_If_ReadOutProtectionStatus();
  if(readoutstatus == RESET)
  {
    /* Remove UPLOAD file if it exists on flash disk */
    f_unlink(UPLOAD_FILENAME);
    
    /* Init written byte counter */
    indexoffset = (APPLICATION_ADDRESS - USER_FLASH_STARTADDRESS);
    
    /* Open binary file to write on it */
    if(( Appli_state == APPLICATION_READY) && (f_open(&MyFile, UPLOAD_FILENAME, FA_CREATE_ALWAYS | FA_WRITE) == FR_OK))
    {
      /* Upload On Going: Turn LED4 On and LED3 Off */
      BSP_LED_On(LED4); 
      BSP_LED_Off(LED3);
      
      /* Read flash memory */
      while ((indexoffset < USER_FLASH_SIZE) && ( Appli_state == APPLICATION_READY))
      {
        for(counterread = 0; counterread < BUFFER_SIZE; counterread++)
        {
          /* Check the read bytes versus the end of flash */
          if(indexoffset + counterread < USER_FLASH_SIZE)
          {
            tmpcounter = counterread;
            RAM_Buf[tmpcounter] = (*(uint8_t*)(address++));
          }
          /* In this case all flash was read */
          else
          {
            break;
          }
        }
        
        /* Write buffer to file */
        f_write (&MyFile, RAM_Buf, BUFFER_SIZE, (void *)&byteswritten);

        /* Number of byte written  */
        indexoffset = indexoffset + counterread;
      }
      
      /* Turn LED3 On: Upload Done */
      BSP_LED_On(LED3); 
      
      /* Close file and filesystem */
      f_close(&MyFile);
      f_mount(0, 0, 0);   
    }
    /* Keep LED4 OFF when Device connected */
    BSP_LED_Off(LED4); 
  }
  else
  {
    /* Message ROP active: Turn LED3 On and 
       Toggle LED4 in infinite loop */
    BSP_LED_On(LED3);
    Fail_Handler();
  }
}
Esempio n. 9
0
/**
  * @brief  IAP Read all flash memory.
  * @param  None
  * @retval None
  */
void COMMAND_UPLOAD(void)
{
  __IO uint32_t address = APPLICATION_ADDRESS;
  __IO uint32_t counterread = 0x00;
  
  uint32_t tmpcounter = 0x00, indexoffset = 0x00;
  FlagStatus readoutstatus = SET;
  uint16_t bytesWritten;
  
  /* Get the read out protection status */
  readoutstatus = FLASH_If_ReadOutProtectionStatus();
  if (readoutstatus == RESET)
  {
    /* Remove UPLOAD file if exist on flash disk */
    f_unlink (UPLOAD_FILENAME);
    
    /* Init written byte counter */
    indexoffset = (APPLICATION_ADDRESS - USER_FLASH_STARTADDRESS);
    
    /* Open binary file to write on it */
    if ((HCD_IsDeviceConnected(&USB_OTG_Core) == 1) && (f_open(&file, UPLOAD_FILENAME, FA_CREATE_ALWAYS | FA_WRITE) == FR_OK))
    {  
      /* Read flash memory */
      while ((indexoffset != USER_FLASH_SIZE) && (HCD_IsDeviceConnected(&USB_OTG_Core) == 1))
      {
        for (counterread = 0; counterread < BUFFER_SIZE; counterread++)
        {
          /* Check the read bytes versus the end of flash */
          if (indexoffset + counterread != USER_FLASH_SIZE)
          {
            tmpcounter = counterread;
            RAM_Buf[tmpcounter] = (*(uint8_t*)(address++));
          }
          /* In this case all flash was read */
          else
          {
            break;
          }
        }

        /* Write buffer to file */
        f_write (&file, RAM_Buf, BUFFER_SIZE, (void *)&bytesWritten);
        
        /* Number of byte written  */
        indexoffset = indexoffset + counterread;
      }
      
      /* Set Green LED ON: Upload Done */ 
      STM_EVAL_LEDOn(LED3); 
      
      /* Close file and filesystem */
      f_close (&file);
      f_mount(0, NULL);
    }
  }
  else
  {
    /* Message ROP active: Toggle Red LED in infinite loop */
    Fail_Handler();
  }
}
Esempio n. 10
0
/**
  * @brief  USBH_USR_MSC_Application
  *         Demo application for IAP thru USB mass storage
  * @param  None
  * @retval Staus
  */
int USBH_USR_MSC_Application(void)
{
  EXTI_InitTypeDef EXTI_InitStructure;

  switch (USBH_USR_ApplicationState)
  {
  case USH_USR_FS_INIT:

    /* Initialises the File System*/
    if (f_mount( 0, &fatfs ) != FR_OK )
    {
      /* Fatfs initialisation fails */
      /* Toggle Red LED in infinite loop */
      Fail_Handler();
      return(-1);
    }

    /* Flash Disk is write protected: Set ON Blue LED and Toggle Red LED in infinite loop */
    if (USBH_MSC_Param.MSWriteProtect == DISK_WRITE_PROTECTED)
    {
      /* Set ON Blue LED */
      STM_EVAL_LEDOn(LED6);
      /* Toggle Red LED in infinite loop */
      Fail_Handler();
    }

    /* Go to IAP menu */
    USBH_USR_ApplicationState = USH_USR_IAP;
    break;

  case USH_USR_IAP:

    TimingDelay = 300;
    UploadCondition = 0x01;

    /* Initialize User_Button on STM32F4-Discovery in the EXTI Mode ----------*/
    STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);

    /* Configure Button EXTI line */
    EXTI_InitStructure.EXTI_Line = USER_BUTTON_EXTI_LINE;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);

    /* Writes Flash memory */
    COMMAND_DOWNLOAD();

    /* Initialize User_Button on STM32F4-Discovery in the GPIO Mode ----------*/
    STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);

    /* Check if User Button is already pressed */
    if ((TimingDelay == 0x00) && (UploadCondition == 0x01))
    {
      /* Reads all flash memory */
      COMMAND_UPLOAD();

    }
    else
    {
      /* Set Off Orange LED : Download Done */
      STM_EVAL_LEDOff(LED3);
      /* Set ON Green LED: Waiting User button pressed */
      STM_EVAL_LEDOn(LED4);
    }

    UploadCondition = 0x00;

    /* Waiting User Button Released */
    while ((STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET) && (HCD_IsDeviceConnected(&USB_OTG_Core) == 1))
    {}

    /* Waiting User Button Pressed */
    while ((STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET) && (HCD_IsDeviceConnected(&USB_OTG_Core) == 1))
    {}

    /* Waiting User Button Released */
    while ((STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET) && (HCD_IsDeviceConnected(&USB_OTG_Core) == 1))
    {}

    /* Jumps to user application code located in the internal Flash memory */
    COMMAND_JUMP();
    break;

  default:
    break;
  }
  return(0);
}
Esempio n. 11
0
/**
  * @brief  USBH_USR_DeviceNotSupported
  *         Device is not supported
  * @param  None
  * @retval None
  */
void USBH_USR_DeviceNotSupported(void)
{
  /* Toggle Red LED in infinite loop */
  Fail_Handler();
}
Esempio n. 12
0
/**
  * @brief  USBH_DisconnectEvent
  *         Device disconnect event
  * @param  None
  * @retval Staus
  */
void USBH_USR_DeviceDisconnected (void)
{
  /* Toggle Red LED in infinite loop: USB device disconnected */
  Fail_Handler();
}
Esempio n. 13
0
/**
  * @brief  USBH_USR_UnrecoveredError
  * @param  None
  * @retval None
  */
void USBH_USR_UnrecoveredError (void)
{
  /* Toggle Red LED in infinite loop */
  Fail_Handler();
}
Esempio n. 14
0
/**
  * @brief  USBH_DisconnectEvent
  *         Device disconnect event
  * @param  None
  * @retval Staus
  */
void USBH_USR_DeviceDisconnected (void)
{
	USBH_USR_ApplicationState = USH_USR_DISCONNECTED;
	Fail_Handler();
}
Esempio n. 15
0
/**
  * @brief  USBH_USR_UnrecoveredError
  * @param  None
  * @retval None
  */
void USBH_USR_UnrecoveredError (void)
{
	USBH_USR_ApplicationState = USH_USR_UNRECOVERED;
	Fail_Handler();
}
Esempio n. 16
0
/**
  * @brief  USBH_USR_DeviceNotSupported
  *         Device is not supported
  * @param  None
  * @retval None
  */
void USBH_USR_DeviceNotSupported(void)
{
	USBH_USR_ApplicationState = USH_USR_NOTSUPPORED;
	Fail_Handler();
}