Exemple #1
0
//=========================================================================
//-------------------------------------------------------------------------
__myevic__ void InitUSB()
{
	USBD_SwReset();

	if ( dfStatus.vcom )
	{
		USBD_Open( &usbdVCOMDescriptors, usbdClassRequest+1, 0 );
	}
	else if ( dfStatus.storage )
	{
		USBD_Open( &usbdMSCDescriptors, usbdClassRequest+1, 0 );
		USBD_SetConfigCallback( MSC_SetConfig );
		MSC_Init();
	}
	else
	{
		USBD_Open( &usbdDescriptors, usbdClassRequest+1, 0 );
	}

	SetupEndpoints();
	USBD_Start();
	NVIC_EnableIRQ( USBD_IRQn );

	if ( dfStatus.vcom )
	{
		myputc = VCOM_Putc;
	}

}
msc_Return_TypeDef Serialnum_write (uint32_t number)
{
	msc_Return_TypeDef ret;
	uint32_t *addr = (uint32_t *)USER_PAGE_ADDR;
	MSC_Init();
	ret = MSC_WriteWord(addr, &number, sizeof(number));
	MSC_Deinit();
	return ret;
}
Exemple #3
0
void ANIM_prerenderFrames(void)
{
  uint32_t i;
  uint32_t magicWord = 0xef32;
  
  /* Get the starting address of the prerendered frames */
  uint32_t *addr = (uint32_t *)FRAMES_START;
  
  /* Get the end of the prerendered frames */
  uint32_t *lastAddr = addr + FRAME_BUFFER_SIZE_WORDS * NUM_FRAMES;
  
  /* Get the address of the current frame buffer */
  uint16_t *frameBuffer = FB_getActiveBuffer();
  
  /* Check the last address for the magic word. 
   * If this has been written the frames are already in flash 
   * and we can skip the entire prerendering step */
  if ( *lastAddr == magicWord ) {
    return;
  }
  
  MSC_Init();
  
  /* Make emWin draw to the frame buffer */
  FB_activateFrameBuffer();
  
  /* Add meta data to frame buffer */
  FB_writeControlSignals((uint8_t*)frameBuffer);
  
  /* Erase all the pages we are going to write to */
  while ( addr < lastAddr ) {
    MSC_ErasePage(addr);
    addr += FRAME_BUFFER_SIZE_WORDS;
  }
  
  addr = (uint32_t *)FRAMES_START;
    
  for ( i=0; i<NUM_FRAMES; i++ ) {
    
    /* Render a frame */
    GUI_DrawBitmap(frames[i], 0, 0);
    
    /* Copy entire frame buffer to flash */
    MSC_WriteWord(addr, frameBuffer, FRAME_BUFFER_SIZE_BYTES);
    addr += FRAME_BUFFER_SIZE_WORDS;
  }
  
  /* Write magic word to indicate that the frames are ready in Flash */
  MSC_WriteWord(lastAddr, &magicWord, 4);
  
  MSC_Deinit();
}
Exemple #4
0
/**************************************************************************//**
 * @brief GPIO Interrupt handler (PB11)
 *        Saves the number to the userpage
 *****************************************************************************/
void GPIO_ODD_IRQHandler(void)
{
  msc_Return_TypeDef ret;

  /* Acknowledge interrupt */
  GPIO_IntClear(1 << 11);

  /* Initialize the MSC for writing */
  MSC_Init();

  /* Erase the page */
  //ret = MSC_ErasePage((uint32_t *) (USERPAGE + userData.numWrites * 256 ) );

  /* Check for errors. If there are errors, set the global error variable and
   * deinitialize the MSC */
  /*if (ret != mscReturnOk)
  {
    currentError = ret;
    MSC_Deinit();
    return;
  }*/



  /* Write data to the userpage */
  memset(userData.payload, userData.numWrites, 256);
  ret = MSC_WriteWord((uint32_t *) (USERPAGE + userData.numWrites * 256 ),
					  (void *) &userData.payload,
                      sizeof(UserData_TypeDef));

  /* Increase the number of saves */
  userData.numWrites++;

  /* Check for errors. If there are errors, set the global error variable and
   * deinitialize the MSC */
  if (ret != mscReturnOk)
  {
    currentError = ret;
    MSC_Deinit();
    return;
  }
  /* Deinitialize the MSC. This disables writing and locks the MSC */
  MSC_Deinit();

  /* Signal completion of save. The number of saves will be displayed */
  recentlySaved = true;
}
Exemple #5
0
/**************************************************************************//**
 * @brief
 *   Initialize the storage media interface.
 *****************************************************************************/
bool MSDDMEDIA_Init( void )
{
  #if ( MSD_MEDIA != MSD_SDCARD_MEDIA ) && ( MSD_MEDIA != MSD_NORFLASH_MEDIA )
  numSectors = MEDIA_SIZE / 512;
  #endif

  #if ( MSD_MEDIA == MSD_PSRAM_MEDIA )
  storage = (uint8_t*)EBI_BankAddress( EBI_BANK2 );
  storage[0] = 0;   /* To force new "format disk" when host detects disk. */
  #endif

  #if ( MSD_MEDIA == MSD_SDCARD_MEDIA )
  /* Enable SPI access to MicroSD card */
  BSP_PeripheralAccess( BSP_MICROSD, true );
  MICROSD_Init();

  if ( disk_initialize( 0 ) != 0 )
    return false;

  /* Get numSectors from media. */
  if ( disk_ioctl( 0, GET_SECTOR_COUNT, &numSectors ) != RES_OK )
    return false;
  #endif

  #if ( MSD_MEDIA == MSD_FLASH_MEDIA )
  flashStatus.pendingWrite = false;
  MSC_Init();                         /* Unlock and calibrate flash timing  */
  MSC_Deinit();                       /* Lock flash                         */
  #endif

  #if ( MSD_MEDIA == MSD_NORFLASH_MEDIA )
  flashStatus.pendingWrite = false;
  NORFLASH_Init();                    /* Initialize NORFLASH interface      */

  storage       = (uint8_t*)NORFLASH_DeviceInfo()->baseAddress;
  flashPageSize = NORFLASH_DeviceInfo()->sectorSize;
  /* Use external PSRAM as page (flash sector) buffer */
  flashPageBuf  = (uint8_t*)EBI_BankAddress( EBI_BANK2 );
  numSectors    = NORFLASH_DeviceInfo()->deviceSize / 512;
  #endif

  return true;
}
Exemple #6
0
/*---------------------------------------------------------------------------------------------------------*/
int32_t main (void)
{
    SYS_Init();
    UART0_Init();

    printf("+-------------------------------------------------------+\n");
    printf("|          NuMicro USB MassStorage Sample Code          |\n");
    printf("+-------------------------------------------------------+\n");

    printf("NnMicro USB MassStorage Start!\n");

    USBD_Open(&gsInfo, MSC_ClassRequest, NULL);
    /* Endpoint configuration */
    MSC_Init();
    NVIC_EnableIRQ(USBD_IRQn);
    USBD_Start();

    while(1)
    {
        if (g_usbd_UsbConfig)
            MSC_ProcessCmd();
    }
}
/***************************************************************************//**
 * @brief
 *   Initialize NVM driver.
 *
 * @details
 *   This function is run upon initialization, at least once before any other
 *   functions. It can be used to call necessary startup routines before the
 *   hardware can be accessed.
 ******************************************************************************/
void NVMHAL_Init(void)
{
  MSC_Init();
}
Exemple #8
0
otError utilsFlashInit(void)
{
    MSC_Init();
    return OT_ERROR_NONE;
}
Exemple #9
0
rt_err_t fvs_begin_write(void *addr)
{
	MSC_Init();
	return RT_EOK;
}