Exemple #1
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_stm32l1xx_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32l1xx.c file
     */      

  /* Initialize Leds mounted on STM3210X-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  
  /* Write/read to/from FSMC SRAM memory  *************************************/
  /* Enable the FSMC Clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

  /* Configure FSMC Bank1 NOR/SRAM2 */
  NOR_Init();
 
  /* Read NOR memory ID */
  NOR_ReadID(&NOR_ID);

  NOR_ReturnToReadMode();

  /* Erase the NOR memory block to write on */
  NOR_EraseBlock(WRITE_READ_ADDR);

  /* Write data to FSMC NOR memory */
  /* Fill the buffer to send */
  Fill_Buffer(TxBuffer, BUFFER_SIZE, 0x3210);
  NOR_WriteBuffer(TxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);

  /* Read data from FSMC NOR memory */
  NOR_ReadBuffer(RxBuffer, WRITE_READ_ADDR, BUFFER_SIZE);  

  /* Read back NOR memory and check content correctness */   
  for (Index = 0x00; (Index < BUFFER_SIZE) && (WriteReadStatus == 0); Index++)
  {
    if (RxBuffer[Index] != TxBuffer[Index])
    {
      WriteReadStatus = Index + 1;
    }
  }

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

  while (1)
  {
  }
}
Exemple #2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
    /* Periph clock enable */
    RCC_Configuration();

    /* Config the LED GPIO */
    LED_Configuration();

    /* Config the USART1 */
    USART1_Configuration();

    printf("NOR Flash Init!\n\r");

    /* EXMC nor flash init */
    EXMC_NorFlash_Init();

    /* Read Nor Flash ID and printf */
    NOR_ReadID(&NOR_ID);
    printf("\n\rNor Flash ID:0x%X 0x%X 0x%X 0x%X\n\r",NOR_ID.Manufacturer_Code,NOR_ID.Device_Code,
                                                      NOR_ID.Block_Protection_Indicator,NOR_ID.Block_Protection_Status);

    NOR_ReturnToReadMode();

    /* Erase the nor flash block to be written data */
    Status = NOR_EraseBlock(WRITE_READ_ADDR);
    if(NOR_SUCCESS == Status)
    {
        printf("\n\rErase nor flash block successfully!\n\r");
    }
    else
    {
        printf("\n\rErase nor flash block failure!\n\r");
    }

    /* Whether address cross-border */
    if((WRITE_READ_ADDR + BUFFER_SIZE ) > NOR_MAX_ADDRESS)
    {
        printf("\n\rAddress cross-border\n\r");
        GPIO_SetBits(LED_GPIO, LED4_PIN | LED5_PIN);
        while(1)
        {

        }
    }

    /* Fill WriteBuffer with the specified value */
    Fill_Buffer(WriteBuffer, BUFFER_SIZE, 0x1234);

    /* Write data to nor flash, WRITE_READ_ADDR: the starting address of the write data */
    Status = NOR_WriteBuffer(WriteBuffer, WRITE_READ_ADDR, BUFFER_SIZE);
    if(NOR_SUCCESS == Status)
    {
        printf("\n\rWrite data to nor flash block successfully!\n\r");
    }
    else
    {
        printf("\n\rWrite data to nor flash block failure!\n\r");
    }

    /* Read data from nor flash, WRITE_READ_ADDR: the starting address of the read data*/
    NOR_ReadBuffer(ReadBuffer, WRITE_READ_ADDR, BUFFER_SIZE);

    /* Read and write data comparison for equality */
    WriteReadStatus = 0;
    for (Index = 0x00; Index < BUFFER_SIZE; Index++)
    {
        if (ReadBuffer[Index] != WriteBuffer[Index])
        {
            WriteReadStatus++;
            break;
        }
    }

    printf("\n\rThe result to access the nor flash:\n\r");
    if (WriteReadStatus == 0)
    {
         printf("\n\rAccess nor flash successfully!\n\r");
         GPIO_SetBits(LED_GPIO, LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN);
    }
    else
    { 
         printf("\n\rAccess nor flash failure!\n\r"); 
         GPIO_SetBits(LED_GPIO, LED2_PIN | LED3_PIN);
    }

    printf("\n\rPrintf data to be read: \n\r");
    printf("\n\r");
    for(Index = 0; Index < BUFFER_SIZE; Index++)
    {
        printf("%X ",ReadBuffer[Index]);
    }

    while(1)
    {

    }
}