Other Parts Discussed in Thread: CC2642R
Tool/software:
Good afternoon,
I am deploying backup factory image on the cc2642.
I want to save an oad factory image to the external flash memory.
Only I cannot read from the address 0x00.
I then end up in an error_spin.
Do I have to convert a bit somewhere because it is protected memory?
The oad factory image with NVS driver for the MX25 does work
Who can help me
The code is described below
--------------------------------------------------------------------------------------
spiflash.c
int8_t spiflash_Write(uint32_t addr, void*buffer, size_t bufferSize)
{
uint8_t *srcBuf;
size_t lenBuf, lenWrite, lenDone;
uint8_t wbuf[4];
int8_t status = true;
int retval = 0;
/* Validate address and length */
//if (offset + bufferSize > hwAttrs->regionSize)
//{
// return (NVS_STATUS_INV_OFFSET);
//}
srcBuf = buffer;
lenBuf = bufferSize;
lenDone = 0;
while (lenBuf > 0)
{
/* Wait till previous erase/program operation completes */
int8_t ret = spiflash_waitReady();
if (ret)
{
status = false;
break;
}
ret = spiflash_command(CMD_WREN);
if (ret)
{
status = false;
break;
}
wbuf[0] = CMD_PP;
wbuf[1] = ((addr + lenDone) >> 16) & 0xff;
wbuf[2] = ((addr + lenDone) >> 8) & 0xff;
wbuf[3] = (addr + lenDone) & 0xff;
lenWrite = SPIFLASH_PROGRAM_PAGE_SIZE - ((addr + lenDone) % SPIFLASH_PROGRAM_PAGE_SIZE);
if (lenBuf < lenWrite)
{
lenWrite = lenBuf;
}
spiflashAssert();
if (spiflash_write(wbuf, sizeof(wbuf)) != 0)
{
status = false;
break;
}
if (spiflash_write(srcBuf, lenWrite) != 0)
{
status = false;
break;
}
spiflashDeassert();
srcBuf += lenWrite;
lenDone += lenWrite;
lenBuf -= lenWrite;
}
if (status == false)
{
retval = -1;
}
return (retval);
}
static int8_t spiflash_write(const uint8_t *data, size_t length)
{
return (fxPtrSpi_Flash->write(buffer, buffersize));
}
--------------------------------------------------------------------------------------
SPI.c
static int8_t spi0_write(const uint8_t *data, size_t length)
{
SPI_Transaction spiTransaction;
spiTransaction.rxBuf = NULL;
/* Work around SPI transfer from address 0x0, transfer first byte from local buffer*/
if (data == NULL)
{
uint8_t byte0 = *data;
spiTransaction.count = 1;
spiTransaction.txBuf = (void *)&byte0;
if (!SPI_transfer(spiHandle, &spiTransaction))
{
warnings_Set(spi_failed);
return SPI_ERROR;
}
data++;
length--;
if (length == 0)
{
return SPI_SUCCES;
}
}
spiTransaction.count = length;
spiTransaction.txBuf = (void *)data;
if(!SPI_transfer(spiHandle, &spiTransaction))
{
warnings_Set(spi_failed);
return SPI_ERROR;
}
return SPI_SUCCES;
}