コード例 #1
0
/*******************************************************************************
* Function Name  : Read_Memory
* Description    : Handle the Read operation from the microSD card. 
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Read_Memory(void)
{ //unsigned int a=0,b=0;	 
	NAND_ADDRESS Nand_Addr;
 // GPIO_SetBits(GPIOB, GPIO_Pin_5);
  if (!Block_Read_count)
  {	
		//NAND_ConvertOffsetToAddress(Memory_Offset, 64, &Nand_Addr);
		NAND_ConvertOffsetToAddress(Memory_Offset, 2048, &Nand_Addr);
		NAND_ReadSmallPage(Data1_Buffer, Nand_Addr, 1);
		//NAND_ReadSpareArea(Data1_Buffer, Nand_Addr, 1);
    UserToPMABufferCopy(Data1_Buffer, ENDP1_TXADDR, BULK_MAX_PACKET_SIZE);
    Block_Read_count = 2048 - BULK_MAX_PACKET_SIZE;
		//Block_Read_count = 64 - BULK_MAX_PACKET_SIZE;
    Block_offset = BULK_MAX_PACKET_SIZE;	 
  }
  else
  {
    UserToPMABufferCopy(Data1_Buffer + Block_offset, ENDP1_TXADDR, BULK_MAX_PACKET_SIZE);
    Block_Read_count -= BULK_MAX_PACKET_SIZE;
    Block_offset += BULK_MAX_PACKET_SIZE;
  }

  SetEPTxCount(ENDP1, BULK_MAX_PACKET_SIZE);
  SetEPTxStatus(ENDP1, EP_TX_VALID);

  Memory_Offset += BULK_MAX_PACKET_SIZE;
  Transfer_Length -= BULK_MAX_PACKET_SIZE;

  CSW.dDataResidue -= BULK_MAX_PACKET_SIZE;
  //Led_RW_ON();

  if (Transfer_Length == 0)
  {
    Block_Read_count = 0;
    Block_offset = 0;
    Memory_Offset = 0;
    Bot_State = BOT_DATA_IN_LAST;
    //Led_RW_OFF();
  }
}
コード例 #2
0
ファイル: main.c プロジェクト: Dzenik/QuadVolucer
/**
  * @brief   Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     

  /* Initialize Leds mounted on STM3210X-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  
  /* Enable the FSMC Clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  
  /* FSMC Initialization */
  NAND_Init();

  /* NAND read ID command */
  NAND_ReadID(&NAND_ID);

  /* Verify the NAND ID */
  if((NAND_ID.Maker_ID == NAND_ST_MakerID) && (NAND_ID.Device_ID == NAND_ST_DeviceID))
  {

    /* NAND memory address to write to */
    WriteReadAddr.Zone = 0x00;
    WriteReadAddr.Block = 0x00;
    WriteReadAddr.Page = 0x00;

    /* Erase the NAND first Block */
    status = NAND_EraseBlock(WriteReadAddr);

    /* Write data to FSMC NAND memory */
    /* Fill the buffer to send */
    Fill_Buffer(TxBuffer, BUFFER_SIZE , 0x66);

    status = NAND_WriteSmallPage(TxBuffer, WriteReadAddr, PageNumber);

    /* Read back the written data */
    status = NAND_ReadSmallPage (RxBuffer, WriteReadAddr, PageNumber);
   
    /* Verify the written data */
    for(j = 0; j < BUFFER_SIZE; j++)
    {
      if(TxBuffer[j] != RxBuffer[j])
      {
        WriteReadStatus++;
      }
    }

    if (WriteReadStatus == 0)
    { 
      /* OK */
      /* Turn on LED1 */
      STM_EVAL_LEDOn(LED1);
    }
    else
    { 
      /* KO */
      /* Turn on LED2 */
      STM_EVAL_LEDOn(LED2);
    }
  }
  else
  {
    /* Turn on LED3 */
    STM_EVAL_LEDOn(LED3);
  }

  while(1)
  {
  }
}