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.

MSP432E401Y: BSL-Scripter 3.4 E4xx DFU Erase block bug

Part Number: MSP432E401Y

It is impossible to erase a block higher than 1FC00 with BSL-Scripter 3.4. But with MSP432E401Y, the flash memory go up to 0x100000.

Found this into BSL Scripter:

In file: Family32bit_E4xxUsbDfu.cpp

Address >> 10 is like / 1024. Right! Not 16kB

 So address >> 10 is not a number of block of 16kB but number of block of 1kB. Which 0x7F will trunk useful information to erase block higher than 0x1FC00. But E401Y do have flash up to 0x100000.

                 // Maximum block number is 0x40 (64 blocks of 16kB)

                uint16_t numOfBlocks = (uint16_t)((address >> 10) & 0x000007F);

 Should be this instead:

                 // Maximum block number is 0x400 (1024 blocks of 1kB) for a 1MB device

                uint16_t numOfBlocks = (uint16_t)((address >> 10) & 0x00003FF);  // or better ((msp432eDeviceInfo->flashTop >> 10)  - 1)

  • Germain,

    Thank you for pointing this out, I'll look more into this. 

    Thanks,

    Seong

  • Since I know which block I can erase, I tried to erase a block accepted by the BSL-scripter tools.But it still not working...

    MODE E4xx USB
    //VERBOSE
    // Erase app section only, do not erase MSC disk and boot
    ERASE_BLOCK 0x14000 1
    //RX_DATA_BLOCK_FAST terminalboard_MSP432E401Y_tirtos.txt
    //REBOOT_RESET

    The BSL fall into "IntDefaultHandler()" which telling me there is something that get corrupted. I tried to follow with debugger and I can tell it crash after the flash erase but can't find where and why yet. BSL-scripter fall in time out each time...

    I've not been able to compile the bsl scripter... I've not been able to get the good library from boost.

    Severity    Code    Description    Project    File    Line    Suppression State
    Error    LNK1104    cannot open file 'libboost_system-vc140-mt-sgd-1_58.lib'    BSL-Scripter    C:\ti\BSL-Scripter\Source\LINK    1    

    My boost do have this into stage library:

    libboost_system-vc140-mt-gd-1_58.lib
    libboost_system-vc140-mt--1_58.lib

    I don't know how to produce the version the "sgd".

    Germain

  • Hi,

    Still continue to share my findings.

    I know why the BSL on target is crashing. It received a request of 6 bytes with a command Upload which should always return at least 8 bytes in header.

            for(ui32Loop = (ui16ToSend - sizeof(tDFUDownloadProgHeader)); ui32Loop;
                ui32Loop--)
            {
                *pui8To++ = *pui8From++;
            }

    ui16ToSend is 6 and sizeof(tDFUDownloadProgHeader) is 8... negative number it will give.

    I think each command that is not RX_DATA_BLOCK_FAST and REBOOT_RESET will do this for E4xx devices. Here is why:

    void Interpreter::executeOtherCommandE4xx()
    {
    	ptrComm->resetBytesWritten();
    	ptrTarget->selectCommand(&commandParams);
    	ptrComm->transmitBuffer(ptrTarget->retPtrCommandBuffer());
    	// In REBOOT_RESET command, the USB DFU does not set the response bytes
    	if (commandParams.command != Command::REBOOT_RESET)
    	{
    		ptrComm->receiveBuffer(UsbDfuResponseSize::GET_STATUS);
    	}
    	scripterStream->showVerboseE4xxUsbDfu(ptrTarget->retPtrCommandBuffer(), ptrComm->retPtrRxBuffer(), Msp432ECommandSize::SIZE, UsbDfuResponseSize::GET_STATUS, this->enVerbose);
    }
    

    If you look into receiveBuffer(), it will ask for get_status and will trig an UPLOAD with a size of 6. This is explaining why BSL is receiving a bad command...

    There is another problem. MASS_ERASE is not correct. It want to erase everything including the BSL and the FLASH_RSVD_SPACE. It is ok with internal BSL, but with a user BSL it won't work anymore.

    Here is what I want to do, but I don't know how to get tDFUDeviceInfo that is private in the UsbDfuComm class.

    void Family32bit_E4xxUsbDfu::massErase()
    {
        //const uint16_t startBlockAddress = 0;
        const uint16_t startBlockAddress = tDFUDeviceInfo->ulAppStartAddr;
        //const uint16_t totalBlocks = ProgramMemorySize::MSP432E / SegmentSize::MSP432E;
        const uint16_t totalBlocks = tDFUDeviceInfo->ulAppStartAddr / tDFUDeviceInfo->usFlashBlockSize;
        commandBuffer.clear();
        commandBuffer.push_back(Msp432ESpecificCommand::ERASE);
        commandBuffer.push_back(Msp432ESpecificCommand::RESERVED_VALUE);
        commandBuffer.push_back((uint8_t)(startBlockAddress & 0x00FF));
        commandBuffer.push_back((uint8_t)((startBlockAddress >> 8) & 0x00FF));
        commandBuffer.push_back((uint8_t)(totalBlocks & 0x00FF));
        commandBuffer.push_back((uint8_t)((totalBlocks >> 8) & 0x00FF));
        commandBuffer.push_back(Msp432ESpecificCommand::RESERVED_VALUE);
        commandBuffer.push_back(Msp432ESpecificCommand::RESERVED_VALUE);
    }

    Still need to find a way to make it work, maybe by resquesting 8 bytes instead of 6. I've been able to compile boost with static library, but now Visual Studio 2019 don't like the use of stdin and stdout. Need to find an older version.

  • Find a new bug. If I write a block of 1024bytes align with 1024bytes as requested. It crashed... Here is why:

    std:vector cannot return .at(0) with a size of 0. The protocol request to always send a transmitBuffer of 0 at the end, isn't. It look it doesn't, only when it end align with 1kB.

    void Interpreter::executeRxCommand()
    {
    ...
    				//Send package with no loop, as the maximum package size is 1024 and has to be followed by 
    				//   payload length 0
    				ptrTarget->selectRxCommand(&commandParams, scripterStream->retDataBlockRead());
    				ptrComm->transmitBuffer(ptrTarget->retPtrCommandBuffer());
    				ptrComm->receiveBuffer(0);
    				scripterStream->showVerboseE4xxUsbDfu(ptrTarget->retPtrCommandBuffer(), ptrComm->retPtrRxBuffer(), scripterStream->retDataBlockRead()->data.size(), UsbDfuResponseSize::GET_STATUS, this->enVerbose);
    				scripterStream->clearDataBlock();
    ...

    void UsbDfuComm::transmitBuffer(std::vector<uint8_t>* txBuffer)
    {
    	std::vector<uint8_t> checkRebootCommand(8, Msp432ESpecificCommand::RESERVED_VALUE);
    	checkRebootCommand.at(0) = Msp432ESpecificCommand::RESET;
    
    	if ((txBuffer->size() == 8) && 
    		(std::equal(checkRebootCommand.begin(), checkRebootCommand.end(), txBuffer->begin())))
    	{
    		dfuTransferOutResetDevice(UsbDfuStandardCommand::DNLOAD,
    			                      blockIndex,
    			                      &txBuffer->at(0),
    			                      txBuffer->size());
    	}
    	else
    	{
    		printf("txBuffer addr=%08X\n", txBuffer);
    		printf("txBuffer size=%d\n", txBuffer->size());
    		printf("txBuffer addr=%08X\n", &txBuffer->at(0));
    		dfuTransferOut(UsbDfuStandardCommand::DNLOAD,
    				blockIndex,
    				&txBuffer->at(0),
    				txBuffer->size());
    
    		dfuGetStatus();

    Finally get able to compile BSL-scripter. I have installed studio 2013 (sln was built with this version) and compile boost with .\b2 runtime-link=static.

    I had fix all previous bug. I can share if it could help someone else.

  • Germain,

    I've reached out to the subject matter expert, but she will be out of office until next week. Please expect some delay before we can get back to you. 

    BR,

    Seong

  • Germain,

    Please share the fix to the bugs you found so that others with similar issues can refer to it.

    I've reported the erase block bug you found to our tools team. 

    Thanks,

    Seong

  • diff -r 8f79124828e7 CommInterface.h
    --- a/CommInterface.h	Tue Dec 24 13:37:20 2019 -0500
    +++ b/CommInterface.h	Tue Jan 07 14:25:29 2020 -0500
    @@ -266,4 +266,17 @@
     	*Returns:	  std::string
     	***********************************************************************************/
     	virtual std::string translateResponse(CommandParams *cmdParams, std::vector<uint8_t>* buffer, uint8_t idx) = 0;
    +
    +	// ABB: GHE
    +	/*******************************************************************************
    +	*Function:    getDevInfo
    +	*Description: Get device info from this class, must be called after init()
    +	*Parameters:  -
    +	*Returns:     struct specific for the target
    +	*******************************************************************************/
    +	virtual void* getDevInfo()
    +	{
    +		return NULL;
    +	}
    +
     };
    \ No newline at end of file
    diff -r 8f79124828e7 Family32bit_E4xxUsbDfu.cpp
    --- a/Family32bit_E4xxUsbDfu.cpp	Tue Dec 24 13:37:20 2019 -0500
    +++ b/Family32bit_E4xxUsbDfu.cpp	Tue Jan 07 14:25:29 2020 -0500
    @@ -186,8 +186,18 @@
     
     void Family32bit_E4xxUsbDfu::eraseBlock(uint32_t address, uint16_t blocks)
     {
    -	// Maximum block number is 0x40 (64 blocks of 16kB)
    -	uint16_t numOfBlocks = (uint16_t)((address >> 10) & 0x000007F);
    +	// First, erase must be align with flash block 0x4000
    +	if ((address & (msp432eDeviceInfo.flashBlock - 1)) != 0)
    +		throw std::runtime_error("[ERROR_MESSAGE]Erase block address must be align with flash block size (0x4000)");
    +	// Is address still in flash memory
    +	if ((address < msp432eDeviceInfo.flashTop) && (address > (msp432eDeviceInfo.flashTop - msp432eDeviceInfo.flashBlock)))
    +		throw std::runtime_error("[ERROR_MESSAGE]Erase block address not valid");
    +	// Are we erasing to much memory
    +	if (((address + (blocks * msp432eDeviceInfo.flashBlock)) < msp432eDeviceInfo.flashTop) &&
    +			((address + (blocks * msp432eDeviceInfo.flashBlock)) >(msp432eDeviceInfo.flashTop - msp432eDeviceInfo.flashBlock)))
    +		throw std::runtime_error("[ERROR_MESSAGE]Number of block too high");
    +
    +	uint16_t numOfBlocks = (uint16_t)(address >> 10);
     	commandBuffer.clear();
     	commandBuffer.push_back(Msp432ESpecificCommand::ERASE);
     	commandBuffer.push_back(Msp432ESpecificCommand::RESERVED_VALUE);
    @@ -201,8 +211,11 @@
     
     void Family32bit_E4xxUsbDfu::massErase()
     {
    -	const uint16_t startBlockAddress = 0;
    -	const uint16_t totalBlocks = ProgramMemorySize::MSP432E / SegmentSize::MSP432E;
    +	const uint16_t startBlockAddress = msp432eDeviceInfo.appStartAddr >> 10;
    +	if (msp432eDeviceInfo.flashBlock == 0)
    +		throw std::runtime_error("[ERROR_MESSAGE]Flash block size invalid");
    +
    +	const uint16_t totalBlocks = (msp432eDeviceInfo.flashTop - msp432eDeviceInfo.appStartAddr) / msp432eDeviceInfo.flashBlock;
     	commandBuffer.clear();
     	commandBuffer.push_back(Msp432ESpecificCommand::ERASE);
     	commandBuffer.push_back(Msp432ESpecificCommand::RESERVED_VALUE);
    @@ -241,4 +254,10 @@
     	commandBuffer.push_back((uint8_t)((length & 0x0000FF00) >> 8));
     	commandBuffer.push_back((uint8_t)((length & 0x00FF0000) >> 8));
     	commandBuffer.push_back((uint8_t)((length & 0xFF000000) >> 8));
    -}
    \ No newline at end of file
    +}
    +
    +// ABB: GHE
    +void Family32bit_E4xxUsbDfu::setDevInfo(void *devInfo)
    +{
    +	msp432eDeviceInfo = *((MSP432EUsbDeviceInfo *)devInfo);
    +}
    diff -r 8f79124828e7 Family32bit_E4xxUsbDfu.h
    --- a/Family32bit_E4xxUsbDfu.h	Tue Dec 24 13:37:20 2019 -0500
    +++ b/Family32bit_E4xxUsbDfu.h	Tue Jan 07 14:25:29 2020 -0500
    @@ -144,6 +144,15 @@
     	*******************************************************************************/
     	uint8_t retNumOfResponse(CommandParams* cmdParams) OVERRIDE;
     
    +	// ABB: GHE
    +	/*******************************************************************************
    +	*Function:    setDevInfo
    +	*Description: Set device info in this class
    +	*Parameters:  struct specific for the target
    +	*Returns:     -
    +	*******************************************************************************/
    +	void setDevInfo(void *devInfo);
    +
     private:
     
     	/***********************************************************************************
    @@ -156,6 +165,9 @@
     	uint32_t address;
     	uint16_t blocks;
     
    +	// ABB: GHE
    +	MSP432EUsbDeviceInfo msp432eDeviceInfo;
    +
     	/***********************************************************************************
     	*Private functions
     	***********************************************************************************/
    diff -r 8f79124828e7 Interpreter.cpp
    --- a/Interpreter.cpp	Tue Dec 24 13:37:20 2019 -0500
    +++ b/Interpreter.cpp	Tue Jan 07 14:25:29 2020 -0500
    @@ -261,6 +261,7 @@
     			interpretMode(&cliParamsVector);
     			callFactory();
     			ptrComm->init(&modeParams);
    +			ptrTarget->setDevInfo(ptrComm->getDevInfo());
     		}
     
     		/***********************************************************************************
    @@ -748,6 +749,7 @@
     					interpretMode(&commandParams.params);
     					callFactory();
     					ptrComm->init(&modeParams);
    +					ptrTarget->setDevInfo(ptrComm->getDevInfo());
     				}
     				else
     				{
    @@ -760,6 +762,7 @@
     				interpretMode(&commandParams.params);
     				callFactory();
     				ptrComm->init(&modeParams);
    +				ptrTarget->setDevInfo(ptrComm->getDevInfo());
     			}
     			else
     			{
    @@ -1242,7 +1245,7 @@
     							ptrComm->transmitBuffer(ptrTarget->retPtrCommandBuffer());
     							ptrComm->receiveBuffer(numOfResponse);
     							scripterStream->showVerboseE4xx(ptrComm->retPtrTxBuffer(), ptrComm->retPtrRxBuffer(), this->enVerbose);
    -						}
    +						}
     					}
     
     					while (ptrComm->retBytesSent() < scripterStream->retDataBlockRead()->data.size())
    @@ -1586,7 +1589,7 @@
     	// In REBOOT_RESET command, the USB DFU does not set the response bytes
     	if (commandParams.command != Command::REBOOT_RESET)
     	{
    -		ptrComm->receiveBuffer(UsbDfuResponseSize::GET_STATUS);
    +		//ptrComm->receiveBuffer(UsbDfuResponseSize::GET_STATUS);
     	}
     	scripterStream->showVerboseE4xxUsbDfu(ptrTarget->retPtrCommandBuffer(), ptrComm->retPtrRxBuffer(), Msp432ECommandSize::SIZE, UsbDfuResponseSize::GET_STATUS, this->enVerbose);
     }
    diff -r 8f79124828e7 Release/BSL-Scripter.exe
    Binary file Release/BSL-Scripter.exe has changed
    diff -r 8f79124828e7 TargetInterface.h
    --- a/TargetInterface.h	Tue Dec 24 13:37:20 2019 -0500
    +++ b/TargetInterface.h	Tue Jan 07 14:25:29 2020 -0500
    @@ -132,6 +132,15 @@
     	*******************************************************************************/
     	virtual uint8_t retNumOfResponse(CommandParams* cmdParams) = 0;
     
    +	// ABB: GHE
    +	/*******************************************************************************
    +	*Function:    setDevInfo
    +	*Description: Set device info in this class
    +	*Parameters:  struct specific for the target
    +	*Returns:     -
    +	*******************************************************************************/
    +	virtual void setDevInfo(void *devInfo){}
    +
     protected:
     
     };
    diff -r 8f79124828e7 UsbDfuComm.cpp
    --- a/UsbDfuComm.cpp	Tue Dec 24 13:37:20 2019 -0500
    +++ b/UsbDfuComm.cpp	Tue Jan 07 14:25:29 2020 -0500
    @@ -130,31 +130,24 @@
     		throw std::runtime_error(translateLibUsbErrorCode(result));
     	}
     
    -	try
    +	// Open device handle of USB DFU device
    +	if (dfuDeviceInit() != nullptr)
     	{
    -		// Open device handle of USB DFU device
    -		if (dfuDeviceInit() != nullptr)
    -		{
    -			// Make sure the device is in DFU Idle State
    -			dfuMakeIdle(true);
    +		// Make sure the device is in DFU Idle State
    +		dfuMakeIdle(true);
     
    -			// Send MSP432E Specific Command , to validate the USB DFU version on the device
    -			dfuMsp432eSpecificCommandClass();
    +		// Send MSP432E Specific Command , to validate the USB DFU version on the device
    +		dfuMsp432eSpecificCommandClass();
     
    -			// Obtain the device info 
    -			dfuGetDeviceInfo();
    +		// Obtain the device info 
    +		dfuGetDeviceInfo();
     
    -			// Bring back device to Idle State
    -			dfuGetStatus();
    -		}
    -		else
    -		{
    -			throw std::runtime_error("[ERROR_MESSAGE]Initialization of USB DFU failed!");
    -		}
    +		// Bring back device to Idle State
    +		dfuGetStatus();
     	}
    -	catch (std::runtime_error& e)
    +	else
     	{
    -		std::cout << e.what() << std::endl;
    +		throw std::runtime_error("[ERROR_MESSAGE]Initialization of USB DFU failed!");
     	}
      }
     
    @@ -173,11 +166,20 @@
     	}
     	else
     	{
    -		dfuTransferOut(UsbDfuStandardCommand::DNLOAD,
    -			           blockIndex,
    -			           &txBuffer->at(0),
    -			           txBuffer->size());
    -
    +		if (txBuffer->size() > 0)
    +		{
    +			dfuTransferOut(UsbDfuStandardCommand::DNLOAD,
    +				blockIndex,
    +				&txBuffer->at(0),
    +				txBuffer->size());
    +		}
    +		else
    +		{
    +			dfuTransferOut(UsbDfuStandardCommand::DNLOAD,
    +				blockIndex,
    +				NULL,
    +				0);
    +		}
     		dfuGetStatus();
     
     		while (dfuStatus->state != UsbDfuStandardState::DFU_IDLE ||
    @@ -842,4 +844,10 @@
     		msp432eDeviceInfo->flashTop = util->concatenateBytesToUlong(&rxBuffer, 12);
     		msp432eDeviceInfo->appStartAddr = util->concatenateBytesToUlong(&rxBuffer, 16);
     	}
    -}
    \ No newline at end of file
    +}
    +
    +// ABB: GHE
    +void* UsbDfuComm::getDevInfo()
    +{
    +	return msp432eDeviceInfo;
    +}
    diff -r 8f79124828e7 UsbDfuComm.h
    --- a/UsbDfuComm.h	Tue Dec 24 13:37:20 2019 -0500
    +++ b/UsbDfuComm.h	Tue Jan 07 14:25:29 2020 -0500
    @@ -270,6 +270,15 @@
     	***********************************************************************************/
     	std::string translateResponse(CommandParams *cmdParams, std::vector<uint8_t>* buffer, uint8_t idx) OVERRIDE;
     
    +	// ABB: GHE
    +	/*******************************************************************************
    +	*Function:    getDevInfo
    +	*Description: Get device info from this class, must be called after init()
    +	*Parameters:  -
    +	*Returns:     struct specific for the target
    +	*******************************************************************************/
    +	void* getDevInfo();
    +
     private:
     
     	UsbDfuComm& operator= (const UsbDfuComm &com)
    diff -r 8f79124828e7 Version.h
    --- a/Version.h	Tue Dec 24 13:37:20 2019 -0500
    +++ b/Version.h	Tue Jan 07 14:25:29 2020 -0500
    @@ -4,8 +4,8 @@
     
     namespace Version
     {
    -	const uint8_t MAJOR = 3;
    -	const uint8_t MINOR = 4;
    +	const uint8_t MAJOR = 99;
    +	const uint8_t MINOR = 0;
     	const uint8_t BUG = 0;
     	const uint8_t BUILD = 1;
     }
    \ No newline at end of file
    

**Attention** This is a public forum