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.

LP-MSPM0G3507: function used for erasing and writing the firmware for the particular memory location

Part Number: LP-MSPM0G3507

Tool/software:

Hello 
Send me the file that contains the flash control functions such as erasing and writing the firmware image to a specific memory location. I have already received the firmware image through UART, and now I want to write it to a particular memory address. How should I approach this in code? Also, if you have any example code or link, please share it.

  • i need to write the firmware image chunk by chunk from a particular memory location 
    starting address is 0x5800
    size is 0x0D000
    where i need to add the erase and write function in our code 
    this my code in this function i need to add the flash control function 

    void HandleReceivedData(char *ptr)
    {
        if ((rxIndex == 2)  && isInitialPacket)
        {
          totalPackets = (ptr[0] << 8) | ptr[1];
          UART_printf(UART_1_INST,"%d\n",totalPackets);
          uint32_t totalDataSize = totalPackets * 512;
          rxIndex = 0;
          isInitialPacket = false;
          uint8_t ack1 = 1;
         while (DL_UART_isTXFIFOFull(UART_0_INST));
        DL_UART_transmitData(UART_0_INST, ack1);
        }
        if ((rxIndex >=2) && !isInitialPacket)
        {
        uint16_t index = 0;
        int dataCount = 0;
        uint16_t startOfFrame = ((uint16_t)ptr[index] << 8) | ptr[index + 1];
        index += 2;
        if (startOfFrame == SOF)
        {
           
             uint16_t packetNumber = ((uint16_t)ptr[index] << 8) | ptr[index + 1];
            index += 2;

            uint16_t packetLength = ((uint16_t)ptr[index] << 8) | ptr[index + 1];
            index += 2;
            UART_printf(UART_1_INST,"packet number =%d,packetlength=%d\n",packetNumber,packetLength);
            for (dataCount = 0; dataCount < packetLength; dataCount++)
             {
               chunkBuff[dataCount] = ptr[index++];
             }
              if (dataCount == packetLength)
            {
             uint16_t receivedCRC = ((uint16_t)ptr[index] << 8) | ptr[index + 1];
             index += 2;
             uint16_t calculatedCRC = CalculateCRC((const uint8_t *)(ptr + 2), rxIndex - 6);
             uint16_t endOfFrame = ((uint16_t)ptr[index] << 8) | ptr[index + 1];
             index += 2;
             if (endOfFrame == EOF1 && receivedCRC == calculatedCRC)
             {
              uint8_t ack = 1;
             while (DL_UART_isTXFIFOFull(UART_0_INST));
             DL_UART_transmitData(UART_0_INST, ack);
              uint8_t progress = (packetNumber * 100) / totalPackets;
             UART_printf(UART_1_INST,"Flash Progress: %d%%\r\n", progress);
              isDataReceived = true;
             }

            }
                memset(chunkBuff, 0, packetLength);
               
               if((totalPackets == packetNumber) && isDataReceived)
              {
                UART_printf(UART_1_INST,"flashing is completed\n");

              }
        }
            isDataReceived = false;
           
            rxIndex = 0;
      }
    }
  • after using this it resolve the issue 

            for (dataCount = 0; dataCount < packetLength; dataCount++,addr+=1)
             {
               chunkBuff[dataCount] = ptr[index++];
               if(((dataCount+1) % 8) == 0 && dataCount != 0)
               {
                UART_printf(UART_1_INST,"datacount =%d\n",dataCount);
                uint16_t value =(dataCount-7);
                 UART_printf(UART_1_INST,"value =%d----------\n",value);
                UART_printf(UART_1_INST,"%d----------\n",value);
             DL_FlashCTL_unprotectSector(FLASHCTL, addr, DL_FLASHCTL_REGION_SELECT_MAIN);
            gCmdStatus = DL_FlashCTL_programMemoryFromRAM64WithECCGenerated(FLASHCTL, (addr),(uint32_t *)&chunkBuff[value]);
            if (gCmdStatus == DL_FLASHCTL_COMMAND_STATUS_FAILED) {
            gErrorType = ERROR_8BIT_W;
            UART_printf(UART_1_INST,"error is occurred while writing the memory------------------------\n");
            }
               }
             }