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.

Problem in understanding Code in Appendix B of spra568

Hi, 

I want to interface Flash with my DSP C6713. I am following code in Appendix B of spra568 for my reference.

I have two ambiguities

1). Which processor is being coded in spra568?

2). Second what are the addresses in erase_flash function? i.e

int erase_flash(int *flash_ptr)
{
/* Control addresses are left shifted so that */
/* they appear correctly on the EMIF's EA[19:2] */
/* unsigned char << 2 == Word */
//write erase chip cmd sequence
int *ctrl_addr1 = flash_ptr + (0x555 << 2);
int *ctrl_addr2 = (int *) ((int)flash_ptr + (0x2aa << 2));
int pass = TRUE;
*ctrl_addr1 = 0xaa; /* Erase sequence writes to addr1 and addr2 */
*ctrl_addr2 = 0x55; /* with this data */
*ctrl_addr1 = 0x80;
*ctrl_addr1 = 0xaa;
*ctrl_addr2 = 0x55;
*ctrl_addr1 = 0x10;
pass = poll_data(flash_ptr, (unsigned char) 0xff);
if (!pass)
printf("failed erase\n\n");
return pass;
}

 what address are (0x555) and 0x2aa in

int *ctrl_addr1 = flash_ptr + (0x555 << 2);

and 

int *ctrl_addr2 = (int *) ((int)flash_ptr + (0x2aa << 2));

plz do reply

  • Maheen,

    This routine is used to erase entire FLASH memory AM29LV800 (Appendix A) / AM29LV0400 (Appendix B)

    #define CE1_ADDRS 0x01400000
    #define FLASH_ADDRS CE1_ADDRS

    int * flash_ptr = (int *)FLASH_ADDRS;
    Here, flash_ptr is address of the FLASH

    If you are using AMD29LV400BT flash chip with C6713 device, take this code for erase, read and write.

    7343.AMD29LV400BT.zip

    You can find the flash chip ID using this function.
    Int16 TEST_flashID()
    {

        Uint16 MfgId,DevId;
        Int16 i;

        /* Reset flash */
        *((volatile Uint8 *)DSK6713_FLASH_BASE) = 0xf0;

        /* Configure to read manufacturer ID */
        *((volatile Uint8 *)DSK6713_FLASH_CTL555) = 0xaa;
        *((volatile Uint8 *)DSK6713_FLASH_CTL2AA) = 0x55;
        *((volatile Uint8 *)DSK6713_FLASH_CTL555) = 0x90;

        /* Insert small delay for device to respond */
        for (i = 0; i < 100; i++);

        /* Read IDs */
        MfgId = *((Uint8 *)DSK6713_FLASH_BASE) & 0xff;
        DevId = *((Uint8 *)(DSK6713_FLASH_BASE + 1)) & 0xff;

        /* Reset flash */
        *((Uint16 *)DSK6713_FLASH_BASE) = 0xf0;

        /* Check IDs */
        if ((MfgId != 0x01) || (DevId != 0xb9))
            return 1;

        /* Test passed */
        return 0;
    }

  • Yes I'm interfacing AM29LV400 with C6713.  Thanks Alot for sharing this code.  I am going to look at it now.

    Also please verify if I doing the right thing that is 

    I am copying the exact code to interface flash with EMIF provided in Appendix B of spra568. The only change I've made is that  I have replaced the function of "emif_config();" with "EMIF_config(&MyConfig);". 

    My reference was spru401j. In its chapter 9 it has mentioned in 9-5 

    This is the EMIF configuration structure used to set up the EMIF peripheral.
    You create and initialize this structure and then pass its address to the EMIF_config() function.


    that is I have removed 

    void emif_config();

     and have placed 

    void EMIF_config(EMIF_Config *config);
    EMIF_Config MyConfig = { 
    0x01800000, /* gblctl */
    0x01800008, /* cectl0 */
    0x01800004, /* cectl1 */
    0x01800010, /* cectl2 */
    0x01800014, /* cectl3 */
    0x01800018, /* sdctl */
    0x0180001C, /* sdtim */
    0x01800020 /* sdext */
    };

    and have called it in main where previously  "emif_config();" was being called. 

    Rest of the code is exactly same. Values in the above registers are obtained from datasheet of DSP C6713 (peripheral register descriptions).

    Now kindly let me know if I have done the right thing? and it will work in hardware.?

     It would be a great help.

    Thanks 

    Maheen.

  • Maheen,

    Please find the EMIF_Config code at the BSL as per the below path,
    DSK6713\c6000\dsk6713\lib\dsk6713bsl\dsk6713.c

  • Pubesh,

    Thank you for share the codes with me. But my question was

    Is method right or is their any problem in my code?

    2nd

    where is main function in all these .c files. These files can be called in main function but if i don't know which function needs to be done first how will I call these functions in main.

    If  I don't make a main function it gives me error

    unresolved symbol_main.

    A quick reply would be appreciated.

    Waiting for reply.

    Thank you

    Maheen

  • this is my code please verify if its correct

    #define CE1_ADDRS 0x90000000 //EMIF CE1 space control 0x90000000 CE1 register value at another link
    #define INT_MEM 0x80000000 // src Source address register value
    #define FLASH_ADDRS CE1_ADDRS

    #define SRC_ADDRS INT_MEM // not sure about this address yet

    #define LENGTH 0x400
    #define TRUE 1
    #define FALSE 0

    #include <stdio.h>
    #include <stdlib.h>
    #include <csl_emif.h>
    #include <csl.h>
    #include <dsk6713.h> /* General functions */
    //#include <emif.h>
    void load_source (unsigned char *source, int num_words);
    int erase_flash(int *flash_addrs);
    int program_flash(unsigned char *source, int *flash_addrs, int num_words);
    int poll_data(int *,unsigned char );
    //void emif_config();
    /****************************************************************************/
    /* emif_config :Routine to configure the Emif for operation with */
    /* AM29LV040-70 at CE1. This routine sets the CE1 control register */
    /* for a 32 bit asynchronous memory interface with the following */
    /* parameters: */
    /* Mtype = 010 */
    /* Read Setup/Strobe/Hold = 1/17/3 */
    /* Write Setup/Strobe/Hold = 2/11/3 */
    /* */
    /****************************************************************************/

    void EMIF_config(EMIF_Config *config);
    EMIF_Config MyConfig = {
    0x01800000, /* gblctl */
    0x01800008, /* cectl0 */
    0x01800004, /* cectl1 */
    0x01800010, /* cectl2 */
    0x01800014, /* cectl3 */
    0x01800018, /* sdctl */
    0x0180001C, /* sdtim */
    0x01800020 /* sdext */
    };

    void main()
    {
    int pass = TRUE;
    int *flash_ptr = (int *)FLASH_ADDRS;
    unsigned char *src_ptr = (unsigned char *)SRC_ADDRS;
    //emif_config();
    EMIF_config(&MyConfig);
    load_source(src_ptr, LENGTH);
    pass = erase_flash(flash_ptr);
    if (pass)
    {
    pass = program_flash(src_ptr, flash_ptr, LENGTH);
    if (!pass)
    printf("Failed in program operation");
    else
    printf("Successful erase and program!!!");
    }
    else
    printf("Failed in erase operation");
    }

    /****************************************************************************/
    /* load_source :Routine to load the source memory with data. This routine */
    /* loads an incrementing count into the source memory for */
    /* demonstration purposes. */
    /* Inputs: */
    /* source_ptr : Address to be used as the source buffer */
    /* code_ptr : Length to be programmed */
    /* */
    /****************************************************************************/
    void load_source(unsigned char *source_ptr, int length)
    {
    int i;
    for (i = 0; i < length; i ++)
    {
    *source_ptr++ = i;
    }
    }
    /****************************************************************************/
    /* erase_flash : Routine to erase entire FLASH memory AM29LV040 (512Kx8bit)*/
    /* Inputs: */
    /* flash_ptr: Address of the FLASH */
    /* Return value: */
    /* Returns TRUE if passed, or FALSE if failed. Pass or failure is */
    /* determined during the poll_data routine. */
    /* */
    /****************************************************************************/
    int erase_flash(int *flash_ptr)
    {
    /* Control addresses are left shifted so that */
    /* they appear correctly on the EMIF's EA[19:2] */
    /* unsigned char << 2 == Word */
    //address 0x555 and 0x2aa depends on JEDEC std. pg10 spra568
    int *ctrl_addr1 = flash_ptr + (0x555 << 2); // depends on JEDEC std. pg10 spra568
    int *ctrl_addr2 = (int *) ((int)flash_ptr + (0x2aa << 2));
    int pass = TRUE;
    *ctrl_addr1 = 0xaa; /* Erase sequence writes to addr1 and addr2 */
    *ctrl_addr2 = 0x55; /* with this data */
    *ctrl_addr1 = 0x80;
    *ctrl_addr1 = 0xaa;
    *ctrl_addr2 = 0x55;
    *ctrl_addr1 = 0x10;
    pass = poll_data(flash_ptr, (unsigned char) 0xff);
    if (!pass)
    printf("failed erase\n\n");
    return pass;
    }
    /*************************************************************************/
    /* program_flash: Routine to program FLASH AM29LV040(512K x 8bit) */
    /* Inputs: q */
    /* flash_ptr: Address of the FLASH PEROM */
    /* code_ptr : Address of the array containing the code to program */
    /* Return value: */
    /* Returns TRUE if passed, or FALSE if failed. Pass or failure is */
    /* determined during the poll_data routine. */
    /* */
    /*************************************************************************/
    int program_flash(unsigned char * source_ptr, int * flash_ptr, int length)
    {
    int i;
    unsigned char data;
    int pass;
    /* Control addresses are left shifted so that */
    /* they appear correctly on the EMIF's EA[19:2] */
    //SPRA568
    /* Short << 1 == Word */
    int *ctrl_addr1 = (int *) ((int*)flash_ptr + (0x555 << 2));
    int *ctrl_addr2 = (int *) ((int*)flash_ptr + (0x2aa << 2));
    for (i = 0; i < length; i++)
    {
    *ctrl_addr1 = 0x00aa;
    *ctrl_addr2 = 0x0055;
    *ctrl_addr1 = 0x00a0;
    *flash_ptr++ = data = *source_ptr++;
    pass = poll_data(flash_ptr-1, data);
    }
    if (!pass)
    printf("Failed at address %x \n\n", (int) flash_ptr);
    return pass;
    }
    /****************************************************************************/
    /* poll_data: Routine to determine if Flash has successfully completed the */
    /* program or erase algorithm. This routine will loop until */
    /* either the embedded algorithm has successfully completed or */
    /* until it has failed. */
    /* */
    /* Inputs: */
    /* prog_ptr : Address just programmed */
    /* prog_data: Data just programmed to flash */
    /* Return value: */
    /* Returns TRUE if passed, or FALSE if failed. */
    /* */
    /****************************************************************************/
    int poll_data(int *prog_ptr, unsigned char prog_data)
    {
    unsigned char data;
    int fail = FALSE;
    do
    {
    data = (unsigned char) *prog_ptr;
    if (data != prog_data)
    { /* is D7 != Data? */
    if ((data & 0x20) == 0x20)
    { /*is D5 = 1 ? */
    data = (unsigned char) *prog_ptr;
    if (data != prog_data) /* is D7 = Data? */
    fail = TRUE;
    }
    else
    return TRUE; /* PASS*/
    }
    else
    return TRUE; /*PASS*/
    }
    while (!fail);
    return FALSE; /* FAIL*/
    }

  • You can find the target content includes Board Supprt Library (BSL), gel file and example tests.
    http://c6000.spectrumdigital.com/dsk6713/
    Please see the flash related calls at the BSL (DSK6713\c6000\dsk6713\lib\dsk6713bsl).
    Take this as a reference code and use it on your custom board.
    http://processors.wiki.ti.com/index.php/C6713DSK_in_CCSv5

  • Thanks for sharing it. 
    I already have this folder. And I cannot for the time being shift to CCSv5. Kindly tell me which example are you referring to in bsl folder. I have 4 projects

    dsk_app, led, ledprd, post, tone 

    in my bsl folder.

    Which project among these is helpful in interfacing 

    Flash AM29LV400 with C6713 ?

    and please reply soon. Waiting for your response. 

    Regards,

    Maheen

  • Also please refer me JTAG emulators other than XDS510 USB PLUS JTAG Emulator with 14 pin Target Adapter Cable.

    that are compatible with C6713. Can XDS100v2 USB JTAG Emulator be used to program flash with C6713.?

    Thank you.

  • Also I would like to correct here that I'm coding for C6713B.

  • Maheen,
    You can get the flash read write and erase function calls
    DSK6713\c6000\dsk6713\lib\dsk6713bsl
    This project build as a lib for BSL. You need to understand the BSL package then used it accordingly on your board.  It may require code changes for custom board not for flash chip.
    The file dsk6713.h must be included in every program that uses the BSL.
    dsk6713_flash.h because it uses their respective BSL modules.
    DSK6713\examples\dsk6713\bsl\post
    Here you can find the TEST_flashID function call, use to check flash chip able to access.
    For  the EMIF_Config code at the BSL as per the below path,
    DSK6713\c6000\dsk6713\lib\dsk6713bsl\dsk6713.c

  • Maheen,
    Find this wiki page for more details for xds100
    http://processors.wiki.ti.com/index.php/XDS100

    See this section mentioned here for suitable device with CCS and XDS100
    "Code Composer Studio v4.x Support (XDS100v1 and XDS100v2 hardware)"
    "Code Composer Studio v3.3 Support (XDS100v1 HW only)"
    "Code Composer Studio v5.1.x Support (XDS100v1, XDS100v2 and XDS100v3 hardware)"

    In addition that, refer this wiki article for make successful connection
    http://processors.wiki.ti.com/index.php/XDS_Target_Connection_Guide