Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey any one tell me how to write buffer in NOR FLASH ((JS28F128J3F75) , i also attach my code for writtng buffer in Nor Flash






C#
#include "socDefs.h"
#include "APB_Interrupt.h"
#include "APB_UART.h"
#include "platform.h"
#include "externals.h"
#include "APB_GPIO.h"


#define BR_57600_40MHZ  42
#define nbytes  0x2000

void SDRAM_write(unsigned int baseaddr ,unsigned int offset, unsigned short data);
unsigned SDRAM_Verify(unsigned int baseaddr, unsigned int offset);

void IRQ_Handler (void)
{
}

void Flash_write(unsigned int baseaddr ,unsigned int offset, unsigned short data)
{
    *((volatile unsigned int *)(baseaddr + offset)) = (unsigned short)data;
}

unsigned Flash_Verify(unsigned int baseaddr, unsigned int offset)
{
    unsigned short read_data;
    read_data= *((volatile unsigned int *)(baseaddr + offset)) ;
    return (read_data & 0xFFFF);
}

int main( void)
{
    unsigned read, read1, read2, read3, i, j;
    unsigned short data[4] = {0xA5A5, 0xAAAA, 0x5555,0x5a5a};
    uart_cfg(UART1_BASE_ADDR,BR_57600_40MHZ);
    unsigned char mesg1[] = "\n\r Write OK ";
    unsigned char mesg2[] = "\n\r write Error  ";
    unsigned char mesg3[] = "\n\r Buffer Erase ";
    unsigned char mesg4[] = "\n\r Buffer Not Erase ";

    /* Block erase command = 0x20 , then write = 0xD0 on block base adddress = 0x2000 */
    Flash_write(Flash_BASE_ADDR, 0x4000, 0x20);
    Flash_write(Flash_BASE_ADDR, 0x4000, 0xD0);
    read3 = Flash_Verify(Flash_BASE_ADDR ,0x4000);  /* check SR7 = 1 */
    if(read3 == 0x80)
        uart_puts(UART1_BASE_ADDR, (unsigned char *)&mesg3, sizeof(mesg3));
    else
        uart_puts(UART1_BASE_ADDR, (unsigned char *)&mesg4, sizeof(mesg4));

/* for Buffer write  Block address = (0x2000 * 4)  command = 0xE8 base address = 0x02000 */

    Flash_write(Flash_BASE_ADDR, 0x4000, 0xE8);  // command on block address
    read = Flash_Verify(Flash_BASE_ADDR ,0x4000);  // read status and check SR.7 = 1 (7th bit)or not
    Flash_write(Flash_BASE_ADDR, 0x4000, 4);   // set a counter 0x10 =16;
    for(i = 0, j = 0; i < 0x10; i = i + 4, j++)
    {
        Flash_write(Flash_BASE_ADDR, (0x4000 + i), data[j]);
    }
    Flash_write(Flash_BASE_ADDR,0x4000, 0xD0);  // Program resume for some time
    read1 = Flash_Verify(Flash_BASE_ADDR ,0x4000);  // check status of status buffer register bit-7 == 1 ???
    if(read1 == 0x80)
        uart_puts(UART1_BASE_ADDR, (unsigned char *)&mesg1, sizeof(mesg1));
    else
        uart_puts(UART1_BASE_ADDR, (unsigned char *)&mesg2, sizeof(mesg2));
    /* reading data from buffer */
    Flash_write(Flash_BASE_ADDR, 0x4000, 0xFF);
    for(i = 0, j = 0; i < 0x10; i = i + 4, j++)
    {
        read2 = Flash_Verify(Flash_BASE_ADDR , (0x4000 + i) );
    }
Posted
Comments
OriginalGriff 20-Sep-13 1:48am    
Use your code?
Or does it not work? If it doesn't, then why not? What needs fixing, what does it do that you didn't intend it to, or not do that you did?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900