/*******************************************************************************
* Function Name  : Write_Memory
* Description    : Handle the Write operation to the microSD card.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void Write_Memory(void)
{
  u32 temp =  Counter + 64;
	NAND_ADDRESS Nand_Addr;
	static u16 Last_Erased_Block = -1;

  i = 0;
  for (; Counter < temp; Counter++)
  {
    Data1_Buffer[Counter] = Bulk_Data_Buff[i];
    i++;
  }

  Memory_Offset += Data_Len;
  Transfer_Length -= Data_Len;

  if (!(Transfer_Length % 2048))
	//if (!(Transfer_Length % 64))
  {
    Counter = 0;
		NAND_ConvertOffsetToAddress(Memory_Offset - 2048, 2048, &Nand_Addr);
		/*if (Last_Erased_Block != Nand_Addr.Block) {
			NAND_EraseBlock(Nand_Addr);
			//i=1;
			Last_Erased_Block = Nand_Addr.Block;
		}*/
		//NAND_ConvertOffsetToAddress(Memory_Offset - 64, 64, &Nand_Addr);
		NAND_WriteSmallPage(Data1_Buffer, Nand_Addr, 1);
		//NAND_WriteSpareArea(Data1_Buffer, Nand_Addr, 1);
  }

  CSW.dDataResidue -= Data_Len;
  SetEPRxStatus(ENDP2, EP_RX_VALID); /* enable the next transaction*/

  //Led_RW_ON();

  if ((Transfer_Length == 0) || (Bot_State == BOT_CSW_Send))
  {
    Counter = 0;
    Set_CSW (CSW_CMD_PASSED, SEND_CSW_ENABLE);
    //Led_RW_OFF();
  }
}
Пример #2
0
/**
  * @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)
  {
  }
}