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.

RTOS/MSP432E401Y: FLASH READ ISSUE

Part Number: MSP432E401Y

Tool/software: TI-RTOS

Hi,

I am using "nvsinternal" program for reading and writing the flash & it is working fine.

However i changed the code for writing and reading the 1000 bytes.

And my code is as follows.

Initially i am sending data for writing and then sending data for reading.

so here while reading, i am able to read the five bytes correctly and remaining all are coming as zeros instead of actual data.

First of all let me know whether the way of writing the code is right or not and also suggest me the reason for reading  properly 5 bytes only.

Thank you

Regards

Kalyan.

  • Hello,
    I do not have a reason for only 5 bytes being properly read. I do not see any erase routines in your code. Please note that the write process only changes 1's to 0's, so it is important to erase (0 to 1) before writing to the space.

    Regards,
    Chris
  • /*
     * Copyright (c) 2017-2018, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    /*
     *  ======== nvsinternal.c ========
     */
    
    #include <string.h>
    #include <stdlib.h>
    #include <stdint.h>
    
    #include <stdbool.h>
    #include <stdio.h>
    #include <xdc/runtime/System.h>
    
    /* DriverLib Includes */
    #include <ti/devices/msp432e4/driverlib/driverlib.h>
    
    /* Driver Header files */
    #include <ti/display/Display.h>
    #include <ti/drivers/NVS.h>
    #include <ti/drivers/UART.h>
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/eeprom.h>
    #include <ti/drivers/types.h>
    
    /* For usleep() */
    #include <unistd.h>
    
    #include <pthread.h>
    
    /* Example/Board Header files */
    #include "Board.h"
    
    #define FOOTER "=================================================="
    
    /* Buffer placed in RAM to hold bytes read from non-volatile storage. */
    unsigned char buffer2[1000];
    unsigned char buffer1[10];
    unsigned char Rd_Buffer[1000];
    /*
     * Some devices have a minimum FLASH write size of 4-bytes (1 word). Trying
     * to write a non-multiple of 4 amount of data will fail. This array is
     * rounded up (to next multiple of 4) to meet this requirement. Refer to NVS
     * driver documentation for more details.
     */
    //static const char signature[52] =    {"SimpleLink SDK Non-Volatile Storage (NVS) Example."};
    
    unsigned char Start_Bit=0,Cmd_ID,Data_Received;
    unsigned char Rx_Buffer[6]    =  {'0','0','0','0','0','0'} ;
    unsigned char buffer3[10];
    unsigned char Tx_Buffer[1000]  =   {'6','7','8','9',
                                        '1','b','c','d',
                                        'a','b','c','d',
                                        '1','2','3','4',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        '1','x','z','z',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        '1','1','1','1',
                                        '1','1','1','1',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        'a','b','c','d',
                                        '1','2','3','4',
                                        'a','b','c','d',
                                        '1','2','3','4'
                                        } ;
    
    int i=0,Count=0;
    uint32_t ui32Index;
    uint32_t ui32EEPROMInitStatus;
    uint32_t ui32EEPROMReadData[16];
    bool     bStatus;
    
    unsigned char Wr_Data[5];
    //bStatus = true;
    
    UART_Handle uart;
    UART_Params uartParams;
    
    NVS_Handle nvsHandle;
    NVS_Attrs regionAttrs;
    NVS_Params nvsParams;
    
    Display_Handle displayHandle;
    
    void *Rx_Thread(void *arg0);
    void *Proc_Thread(void *arg0);
    
    const char  echoPrompt3[] = "Write Executing..........\r\n";
    const char  echoPrompt4[] = "Read Executing..........\r\n";
    const char  echoPrompt[] = "Uart Initialised...\r\n";
    //    const char  echoPrompt1[] = "Erasing Flash sector........\r\n";
    //    const char  echoPrompt2[] = "Writing signature to flash..........\r\n";
    //    const char  echoPrompt3[] = "Write Executing..........\r\n";
    //    const char  echoPrompt4[] = "Read Executing..........\r\n";
    const char  Test1[] = "Test Passed...\r\n";
    const char  Test2[] = "Test Failed...\r\n";
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        bStatus = true;
    
        Wr_Data[0] = 0x7A;
        Wr_Data[1] = 0x7B;
        Wr_Data[2] = 0x7C;
        Wr_Data[3] = 0x7D;
        Wr_Data[4] = 0x7E;
    
        Display_init();
        NVS_init();
        UART_init();
        GPIO_init();
    
        GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        displayHandle = Display_open(Display_Type_UART, NULL);
        if (displayHandle == NULL)
        {
            /* Display_open() failed */
            while (1);
        }
    
        NVS_Params_init(&nvsParams);
        nvsHandle = NVS_open(Board_NVSINTERNAL, &nvsParams);
    
        if (nvsHandle == NULL)
        {
            Display_printf(displayHandle, 0, 0, "NVS_open() failed.");
    
            return (NULL);
        }
    
        Display_printf(displayHandle, 0, 0, "\n");
    
        UART_Params_init(&uartParams);
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readDataMode = UART_DATA_BINARY;
        uartParams.readReturnMode = UART_RETURN_FULL;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 115200;
       // uartParams.readCallback =   UART_MODE_CALLBACK;
    
        uart    =   UART_open(Board_UART4, &uartParams);
    
        if (uart == NULL)
        {
               /* UART_open() failed */
               while (1);
        }
        else
        {
            Display_printf(displayHandle, 0, 0, "UART Initialized.......");
            UART_write(uart, echoPrompt, sizeof(echoPrompt));
        }
    
        /*
         * This will populate a NVS_Attrs structure with properties specific
         * to a NVS_Handle such as region base address, region size,
         * and sector size.
         */
        NVS_getAttrs(nvsHandle, &regionAttrs);
    
        /* Display the NVS region attributes */
        Display_printf(displayHandle, 0, 0, "Region Base Address: 0x%x",regionAttrs.regionBase);
        Display_printf(displayHandle, 0, 0, "Sector Size: 0x%x",regionAttrs.sectorSize);
        Display_printf(displayHandle, 0, 0, "Region Size: 0x%x\n",regionAttrs.regionSize);
    
    
        /*      ***********************************************************************       */
        /*                              WHILE CONDITION                                       */
        /*      ***********************************************************************       */
    
        while(1)
        {
            UART_read(uart, &buffer1, 1);
            //      UART_write(uart,  &buffer1, 1);
    
           if((buffer1[0]    ==  0x24)  &&  (Start_Bit  ==  0))
           {
              Start_Bit    =   1;
              Count =   0;
           }
    
           if(Start_Bit ==  1)
           {
               Rx_Buffer[Count] =   buffer1[0];
               Count++;
               if(Count ==  4)
               {
                   Start_Bit    =   0;
                   Data_Received    =   1;
                   Cmd_ID   =   Rx_Buffer[1];
               }
           }
    
           if(Data_Received ==  1)
           {
               UART_write(uart,  &Rx_Buffer, 4);
               Data_Received    =   0;
           }
    
           switch(Cmd_ID)
           {
           case 0x61:
               NVS_erase(nvsHandle, 0, regionAttrs.regionSize);
               for(i=0;i<250;i++)
               {
                  NVS_write(nvsHandle, 0+(4*i), &Tx_Buffer[i], 4,NVS_WRITE_POST_VERIFY);
                  Display_printf(displayHandle, 0, 0, "i= %d and Write Data: %x,%x,%x,%x\n",i, Tx_Buffer[0+(4*i)],Tx_Buffer[(4*i)+1],Tx_Buffer[(4*i)+2],Tx_Buffer[(4*i)+3]);
               }
    
               UART_write(uart, &echoPrompt3, sizeof(echoPrompt3));
               Cmd_ID   =   0;
               break;
    
           case 0x62:
               for(i=0;i<250;i++)
               {
                  NVS_read(nvsHandle, (4*i), &Rd_Buffer[i], 4);
                  //sleep(1);
                  Display_printf(displayHandle, 0, 0, "Read Data[%d ]:   %x,%x,%x,%x\n, ",i, Rd_Buffer[(4*i)],Rd_Buffer[(4*i)+1],Rd_Buffer[(4*i)+2],Rd_Buffer[(4*i)+3]);
               }
    
    //           NVS_read(nvsHandle, 0, &buffer2, 1);
    //           Display_printf(displayHandle, 0, 0, "Read Data:  %s\n", buffer2[0]);
               UART_write(uart, &echoPrompt4, sizeof(echoPrompt4));
    
               Cmd_ID   =   0;
               break;
           }
        }
    
    
    
    

    Hello Chris,

    Thank you for the reply.

    I have attached nvsinternal.c file to this post.

    Could you please go through it.

    I am sending $a12 for writing the data and $b34 for reading the data.

    Thank you

    Regards

    Kalyan.

  • Hello Chris,

    Please reply to my earlier queries.

    One more thing i observed was that - if i write the 1000 bytes at a time instead of four bytes in 250 times, i am getting the proper results for reading operation.

    That is

    NVS_write(nvsHandle, 0, &Tx_Buffer, 1000,NVS_WRITE_POST_VERIFY);

    NVS_read(nvsHandle, 0, &Rd_Buffer, 1000);

    working fine.

    And one more thing is that if i use two arrays for writing the data -        with offset 0 & array1 of 4 bytes for the first write operation and with offset 4 & array2 of 5 bytes, The results are proper when i use

    NVS_read(nvsHandle, 0, &Rd_Buffer1, 4);

    NVS_read(nvsHandle, 4, &Rd_Buffer1, 5);

            

    But in the attached .c file, i am not able to find where the mistake is. Please go through it.

    One more thing is that

    the above initialization means that the flash is divided into 8 chunks of each size 16kB?. 

    Thank you

    Regards

    Kalyan

  • Hello,

    I could not get the code to run and will need to look into the errors.

    In the board file you should see that the space flashBuf is being set aside for the application.

    #define SECTORSIZE       (0x4000)
    #define NVS_REGIONS_BASE (0xE0000)
    #define REGIONSIZE       (SECTORSIZE * 8)
    
    /*
     * Reserve flash sectors for NVS driver use
     * by placing an uninitialized byte array
     * at the desired flash address.
     */
    #if defined(__TI_COMPILER_VERSION__)
    
    /*
     * Place uninitialized array at NVS_REGIONS_BASE
     */
    #pragma LOCATION(flashBuf, NVS_REGIONS_BASE);
    #pragma NOINIT(flashBuf);
    static char flashBuf[REGIONSIZE];

    Each sector is 16Kb with 8Kb in each bank.  Since the region base is 0xE0000, this will be in the high region and sectors 24-31.

      

    Regards,

    Chris

  • Can you confirm this is what you are seeing?

    (1) I can see the correct value being written to in Flash

    (2) I can also see the correct value being returned to Rd_Buffer[] by the NVS_Read API

    (3) Display_printf is printing '0' instead of the content of Rd_Buffer[]

    Regards,

    Chris

  • Hello,

    In both the write and read APIs you are multiplying the offset to the NVS region but you are not multiplying the index of the buffer being written to or from.

    NVS_write(nvsHandle, 0+(4*i), &Tx_Buffer[i], 4,NVS_WRITE_POST_VERIFY);
    NVS_read(nvsHandle, (4*i), &Rd_Buffer[i], 4);
    
    NVS_write(nvsHandle, 0+(4*i), &Tx_Buffer[4*i], 4,NVS_WRITE_POST_VERIFY);
    NVS_read(nvsHandle, (4*i), &Rd_Buffer[4*i], 4);

    Regards,

    Chris

**Attention** This is a public forum