This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/RM57L843: NOR Flash read and write

Part Number: RM57L843
Other Parts Discussed in Thread: HALCOGEN

Tool/software: Code Composer Studio

Hello

I need an example code (HALCoGen and Code Composer Studio) for read and write NOR Flash "S29GL512T", which is connected parallel with RM57L843 on CS3.

Regards

Zain

  • Hi Zain,

    I did some read/write tests on NOR flash. Try to find my test case.
  • Hi Zain,

    Sorry for late response. I found my test case for NOR flash. Here is the function for NOR flash erase/read/write and init:

    /*
    * NOR Flash Code
    * By QJ Wang
    * March 19, 2012
    */

    #include "emif_norFlash.h"
    #include "HL_sys_common.h"
    #include "HL_emif.h"

    uint32_t timeout = 0x00100000;


    /* ------------------------------------------------------------------------ *
    * *
    * FLASH_init( ) *
    * *
    * Setup Flash *
    * *
    * ------------------------------------------------------------------------ */
    uint16_t FLASH_init( )
    {
    /*--------------------------------------------------------------*
    * *
    * NOR Flash ( socket ) *
    * Setup for S29Gl512N - 110 ns - 64 MBytes *
    * *
    *--------------------------------------------------------------*/

    emif_ASYNC3Init();
    FLASH_BASE_PTR8 = FLASH_RESET;
    return 0;
    }

    /* ------------------------------------------------------------------------ *
    * *
    * FLASH_waitWhileErasing( ) *
    * *
    * Wait while erasing ( SPANSION Flash ) *
    * *
    * ------------------------------------------------------------------------ */
    uint16_t _FLASH_waitWhileErasing( uint32_t addr, uint32_t timeout )
    {
    uint8_t* pdata = ( uint8_t* )addr;

    while ( --timeout > 0 )
    if ( *pdata == 0xFF )
    return 0; /* Good, erase completed */

    /* Timeout occured */
    FLASH_BASE_PTR8 = FLASH_RESET;
    return 1;
    }

    /* ------------------------------------------------------------------------ *
    * *
    * FLASH_waitWhileProgramming( ) *
    * *
    * Wait while programming ( SPANSION Flash ) *
    * *
    * ------------------------------------------------------------------------ */
    uint16_t _FLASH_waitWhileProgramming( uint32_t addr, uint16_t data, uint32_t timeout )
    {
    uint16_t* pdata = ( uint16_t* )addr;

    while ( --timeout > 0 )
    if ( *pdata == data )
    return 0; /* Good, programming completed */

    /* Timeout occured */
    FLASH_BASE_PTR8 = FLASH_RESET;

    return 1;
    }


    /* ------------------------------------------------------------------------ *
    * *
    * FLASH_erase( start, length ) *
    * Erase Flash containing address ( start ) to ( start + length ). *
    * Flash can only erase entire blocks containing the range. *
    * *
    * start <- starting address *
    * length <- length in bytes *
    * *
    * ------------------------------------------------------------------------ */
    uint16_t FLASH_erase( uint32_t start, uint32_t length )
    {
    uint32_t addr;
    uint32_t end;
    volatile uint16_t* addr16;

    end = start + length - 1; // Calculate end of range
    start &= 0xFFFFFFFE; // Align to 16-bit words

    /*
    * Erase each Flash block in the range
    */
    for ( addr = start ; addr <= end ; addr += FLASH_PAGESIZE )
    {
    addr16 = ( volatile uint16_t* )addr;
    *addr16 = FLASH_RESET; // Reset Flash
    FLASH_CTL555 = FLASH_CMD_AA;
    FLASH_CTL2AA = FLASH_CMD_55;
    FLASH_CTL555 = FLASH_ERASE; // Erase sector command
    FLASH_CTL555 = FLASH_CMD_AA;
    FLASH_CTL2AA = FLASH_CMD_55;
    *addr16 = FLASH_ERASE_SECTOR; // Erase sector confirm

    #ifdef EMIF_USE_REORDER_FIX
    EMIF_REVID = 0;
    #endif

    if ( _FLASH_waitWhileErasing( addr, timeout ) )
    {
    *addr16 = FLASH_RESET;
    return -1;
    }
    }

    return 0;
    }
    /* ------------------------------------------------------------------------ *
    * *
    * FLASH_write( src, dst, length ) *
    * Write to Flash address [dst] the data at a non-Flash address [src] *
    * for [length] #bytes. *
    * *
    * src <- source address *
    * dest <- destination address *
    * length <- length in bytes *
    * *
    * ------------------------------------------------------------------------ */
    uint16_t FLASH_write( uint32_t src, uint32_t dst, uint32_t length )
    {
    uint32_t i;
    uint8_t* psrc8;
    uint16_t* pdst16;

    uint8_t extra_byte_to_write;
    uint16_t full_word_to_write = 0;
    uint8_t* lower_byte_to_write = ( uint8_t* )( &full_word_to_write );
    uint8_t* upper_byte_to_write = ( uint8_t* )( &full_word_to_write + 1 );

    /* Align to 16-bit Flash memory */
    if ( ( dst & 1 ) == 1 )
    {
    *lower_byte_to_write = *( uint8_t* )( dst - 1 );
    *upper_byte_to_write = *( uint8_t* )( src );
    FLASH_write( ( uint32_t )&full_word_to_write, dst - 1, 2 );
    dst = dst + 1;
    src = src + 1;
    length = length - 1;
    }

    /*
    * Align to 8 or 16 bits
    */
    extra_byte_to_write = length & 1;

    psrc8 = ( uint8_t* )src;
    pdst16 = ( uint16_t* )dst;
    length &= 0xFFFFFFFE;
    for ( i = 0 ; i < length ; i += 2 )
    {
    /*
    * Read the 16-bit source data as 2 x 8-bit bytes.
    * This seems rather odd, but avoids any paging problems when
    * data is across multiple cache pages and the MMU is active.
    */
    full_word_to_write = *psrc8 | ( *( uint8_t* )( psrc8 + 1 ) << 8 );
    psrc8 += 2;

    /* Program one 16-bit word */
    FLASH_CTL555 = FLASH_CMD_AA;
    FLASH_CTL2AA = FLASH_CMD_55;
    FLASH_CTL555 = FLASH_PROGRAM;
    *pdst16 = full_word_to_write;

    /* Wait for programming to complete */
    if ( _FLASH_waitWhileProgramming( ( uint32_t )pdst16, full_word_to_write, timeout ) )
    return -1;

    pdst16++;
    }

    /* Align 16-bit SRC last */
    if ( extra_byte_to_write == 1 )
    {
    *lower_byte_to_write = *psrc8;
    *upper_byte_to_write = ( *pdst16 ) >> 8;
    FLASH_write( ( uint32_t )&full_word_to_write, ( uint32_t )pdst16, 2 );
    }

    /*
    * Set to Read Mode
    */
    FLASH_BASE_PTR8 = FLASH_RESET;

    return 0;
    }

    /* ------------------------------------------------------------------------ *
    * *
    * FLASH_read( src, dst, length ) *
    * Read from Flash address ( src ) to the data at non-Flash address *
    * ( dst ) for ( length ) bytes. *
    * *
    * src <- source address *
    * dest <- destination address *
    * length <- length in bytes *
    * *
    * ------------------------------------------------------------------------ */
    uint16_t FLASH_read( uint32_t src, uint32_t dst, uint32_t length )
    {
    uint32_t i;
    uint16_t* psrc16 = ( uint16_t* )src;
    uint16_t* pdst16 = ( uint16_t* )dst;

    /*
    * Set to Read Mode
    */
    FLASH_BASE_PTR8 = FLASH_RESET;

    /*
    * Read Data to Buffer
    */
    for ( i = 0 ; i < length ; i += 2 )
    *pdst16++ = *psrc16++;

    return 0;
    }
  • Hello Wang

    sorry for late reply. I need the HALCoGEN steps to configure the Parallel Flash or any other Async memory in normal mode.

    regards

    Zain

  • Hi Zain,

    The EMIF Async configuration in HALCoGen is very straight forward.
    1. Enable async modules (
    2. If external wait is required
    3. EMIF clock
    4. Async mode
    5. and the timing: you can use the maximum value first, then adjust the value based on the datasheet of the memory device.