- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm using an MB9BF368R with IAR Workbench and PDL 2.1.
When I'm trying to write an 16-bit value to workflash, only 8-bit were written.
Here is my code example:
__disable_interrupt();
uint32_t adr = 0x200C008D;
WFlash_ChipErase();
uint16_t test = 0x12AB;
WFlash_WriteData16Bit((uint16_t*)adr, (uint16_t*)&test, 1);
__enable_interrupt();
Does anyone have a code example of how to use the PDL 2.1 workflash functions?
BR
Jürgen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
PDL has Flash code example, you can refer it for testing firstly.
Cypress\PDL\2.1.0\example\flash\fm4
The following is code example
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "pdl_header.h"
/******************************************************************************/
/* Local pre-processor symbols/macros ('#define') */
/******************************************************************************/
#define TEST_SIZE 100
#define TEST_MAINSECTOR 0x2000
#define TEST_WORKSECTOR 0x200C0000
/******************************************************************************/
/* Global variable definitions (declared in header file with 'extern') */
/******************************************************************************/
uint8_t u8TestData[TEST_SIZE];
/******************************************************************************/
/* Local type definitions ('typedef') */
/******************************************************************************/
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
/******************************************************************************/
/* Local variable definitions ('static') */
/******************************************************************************/
static void delay(void)
{
uint32_t u32dly;
u32dly = SystemCoreClock/5;
while(u32dly--);
}
/******************************************************************************/
/* Function implementation - global ('extern') and local ('static') */
/******************************************************************************/
/**
******************************************************************************
** \brief Main function of project for MCU evaluation board
**
** \return int32_t return value, if needed
******************************************************************************/
int32_t main(void)
{
uint32_t i;
uint8_t * pt;
uint8_t *paddr = (uint8_t *)TEST_MAINSECTOR;
pt = (uint8_t *)u8TestData;
SystemCoreClockUpdate();
#ifdef DEBUG_PRINT
//Uart_Io_Init();
#endif
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("main flash Example Program Start \n");
printf("==================================================\n");
#endif
delay();
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("main flash erase \n");
printf("==================================================\n");
#endif
delay();
MFlash_SectorErase((uint16_t*)TEST_MAINSECTOR);
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = i;
}
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("main flash write 16bit data \n");
printf("==================================================\n");
#endif
delay();
MFlash_WriteData16Bit((uint16_t*)TEST_MAINSECTOR, (uint16_t*)u8TestData,\
sizeof(u8TestData)/sizeof(uint16_t));
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = 0xff;
}
for(i=0;i<TEST_SIZE;i++)
{
*pt++ = *paddr++;
}
for(i=0;i<TEST_SIZE;i++)
{
if(i != u8TestData)
{
#ifdef DEBUG_PRINT
printf("main flash 16bit write data fail \n");
#endif
while(1);
}
}
#ifdef DEBUG_PRINT
printf("main flash 16bit write data successfully \n");
#endif
delay();
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("main flash erase \n");
printf("==================================================\n");
#endif
delay();
MFlash_SectorErase((uint16_t*)TEST_MAINSECTOR);
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("main flash write 32bit data \n");
printf("==================================================\n");
#endif
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = TEST_SIZE - i;
}
delay();
MFlash_WriteData32Bit((uint32_t*)TEST_MAINSECTOR, (uint32_t*)u8TestData, \
sizeof(u8TestData)/sizeof(uint32_t),TRUE);
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = 0xff;
}
paddr = (uint8_t *)TEST_MAINSECTOR;
pt = (uint8_t *)u8TestData;
for(i=0;i<TEST_SIZE;i++)
{
*pt++ = *paddr++;
}
for(i=0;i<TEST_SIZE;i++)
{
if((TEST_SIZE-i) != u8TestData)
{
#ifdef DEBUG_PRINT
printf("main flash 32bit write data fail \n");
#endif
while(1);
}
}
#ifdef DEBUG_PRINT
printf("main flash 32bit write data successfully \n");
printf("==================================================\n");
printf("main flash Example Program End \n");
printf("==================================================\n");
#endif
paddr = (uint8_t *)TEST_WORKSECTOR;
pt = (uint8_t *)u8TestData;
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("work flash Example Program Start \n");
printf("==================================================\n");
#endif
delay();
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("work flash erase \n");
printf("==================================================\n");
#endif
delay();
WFlash_SectorErase((uint16_t*)TEST_WORKSECTOR);
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = i;
}
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("work flash write 16bit data \n");
printf("==================================================\n");
#endif
delay();
WFlash_WriteData16Bit((uint16_t*)TEST_WORKSECTOR, (uint16_t*)u8TestData, \
sizeof(u8TestData)/sizeof(uint16_t));
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = 0xff;
}
for(i=0;i<TEST_SIZE;i++)
{
*pt++ = *paddr++;
}
for(i=0;i<TEST_SIZE;i++)
{
if(i != u8TestData)
{
#ifdef DEBUG_PRINT
printf("work flash 16bit write data fail \n");
#endif
while(1);
}
}
#ifdef DEBUG_PRINT
printf("work flash 16bit write data successfully \n");
#endif
delay();
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("work flash erase \n");
printf("==================================================\n");
#endif
delay();
WFlash_SectorErase((uint16_t*)TEST_WORKSECTOR);
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("work flash write 32bit data \n");
printf("==================================================\n");
#endif
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = TEST_SIZE - i;
}
delay();
WFlash_WriteData32Bit((uint32_t*)TEST_WORKSECTOR, (uint32_t*)u8TestData, \
sizeof(u8TestData)/sizeof(uint32_t));
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = 0xff;
}
paddr = (uint8_t *)TEST_WORKSECTOR;
pt = (uint8_t *)u8TestData;
for(i=0;i<TEST_SIZE;i++)
{
*pt++ = *paddr++;
}
for(i=0;i<TEST_SIZE;i++)
{
if((TEST_SIZE-i) != u8TestData)
{
#ifdef DEBUG_PRINT
printf("work flash 32bit write data fail \n");
#endif
while(1);
}
}
#ifdef DEBUG_PRINT
printf("work flash 32bit write data successfully \n");
printf("==================================================\n");
printf("work flash Example Program End \n");
printf("==================================================\n");
#endif
while(1);
}
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
PDL has Flash code example, you can refer it for testing firstly.
Cypress\PDL\2.1.0\example\flash\fm4
The following is code example
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "pdl_header.h"
/******************************************************************************/
/* Local pre-processor symbols/macros ('#define') */
/******************************************************************************/
#define TEST_SIZE 100
#define TEST_MAINSECTOR 0x2000
#define TEST_WORKSECTOR 0x200C0000
/******************************************************************************/
/* Global variable definitions (declared in header file with 'extern') */
/******************************************************************************/
uint8_t u8TestData[TEST_SIZE];
/******************************************************************************/
/* Local type definitions ('typedef') */
/******************************************************************************/
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
/******************************************************************************/
/* Local variable definitions ('static') */
/******************************************************************************/
static void delay(void)
{
uint32_t u32dly;
u32dly = SystemCoreClock/5;
while(u32dly--);
}
/******************************************************************************/
/* Function implementation - global ('extern') and local ('static') */
/******************************************************************************/
/**
******************************************************************************
** \brief Main function of project for MCU evaluation board
**
** \return int32_t return value, if needed
******************************************************************************/
int32_t main(void)
{
uint32_t i;
uint8_t * pt;
uint8_t *paddr = (uint8_t *)TEST_MAINSECTOR;
pt = (uint8_t *)u8TestData;
SystemCoreClockUpdate();
#ifdef DEBUG_PRINT
//Uart_Io_Init();
#endif
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("main flash Example Program Start \n");
printf("==================================================\n");
#endif
delay();
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("main flash erase \n");
printf("==================================================\n");
#endif
delay();
MFlash_SectorErase((uint16_t*)TEST_MAINSECTOR);
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = i;
}
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("main flash write 16bit data \n");
printf("==================================================\n");
#endif
delay();
MFlash_WriteData16Bit((uint16_t*)TEST_MAINSECTOR, (uint16_t*)u8TestData,\
sizeof(u8TestData)/sizeof(uint16_t));
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = 0xff;
}
for(i=0;i<TEST_SIZE;i++)
{
*pt++ = *paddr++;
}
for(i=0;i<TEST_SIZE;i++)
{
if(i != u8TestData)
{
#ifdef DEBUG_PRINT
printf("main flash 16bit write data fail \n");
#endif
while(1);
}
}
#ifdef DEBUG_PRINT
printf("main flash 16bit write data successfully \n");
#endif
delay();
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("main flash erase \n");
printf("==================================================\n");
#endif
delay();
MFlash_SectorErase((uint16_t*)TEST_MAINSECTOR);
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("main flash write 32bit data \n");
printf("==================================================\n");
#endif
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = TEST_SIZE - i;
}
delay();
MFlash_WriteData32Bit((uint32_t*)TEST_MAINSECTOR, (uint32_t*)u8TestData, \
sizeof(u8TestData)/sizeof(uint32_t),TRUE);
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = 0xff;
}
paddr = (uint8_t *)TEST_MAINSECTOR;
pt = (uint8_t *)u8TestData;
for(i=0;i<TEST_SIZE;i++)
{
*pt++ = *paddr++;
}
for(i=0;i<TEST_SIZE;i++)
{
if((TEST_SIZE-i) != u8TestData)
{
#ifdef DEBUG_PRINT
printf("main flash 32bit write data fail \n");
#endif
while(1);
}
}
#ifdef DEBUG_PRINT
printf("main flash 32bit write data successfully \n");
printf("==================================================\n");
printf("main flash Example Program End \n");
printf("==================================================\n");
#endif
paddr = (uint8_t *)TEST_WORKSECTOR;
pt = (uint8_t *)u8TestData;
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("work flash Example Program Start \n");
printf("==================================================\n");
#endif
delay();
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("work flash erase \n");
printf("==================================================\n");
#endif
delay();
WFlash_SectorErase((uint16_t*)TEST_WORKSECTOR);
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = i;
}
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("work flash write 16bit data \n");
printf("==================================================\n");
#endif
delay();
WFlash_WriteData16Bit((uint16_t*)TEST_WORKSECTOR, (uint16_t*)u8TestData, \
sizeof(u8TestData)/sizeof(uint16_t));
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = 0xff;
}
for(i=0;i<TEST_SIZE;i++)
{
*pt++ = *paddr++;
}
for(i=0;i<TEST_SIZE;i++)
{
if(i != u8TestData)
{
#ifdef DEBUG_PRINT
printf("work flash 16bit write data fail \n");
#endif
while(1);
}
}
#ifdef DEBUG_PRINT
printf("work flash 16bit write data successfully \n");
#endif
delay();
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("work flash erase \n");
printf("==================================================\n");
#endif
delay();
WFlash_SectorErase((uint16_t*)TEST_WORKSECTOR);
#ifdef DEBUG_PRINT
printf("==================================================\n");
printf("work flash write 32bit data \n");
printf("==================================================\n");
#endif
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = TEST_SIZE - i;
}
delay();
WFlash_WriteData32Bit((uint32_t*)TEST_WORKSECTOR, (uint32_t*)u8TestData, \
sizeof(u8TestData)/sizeof(uint32_t));
for(i=0;i<TEST_SIZE;i++)
{
u8TestData = 0xff;
}
paddr = (uint8_t *)TEST_WORKSECTOR;
pt = (uint8_t *)u8TestData;
for(i=0;i<TEST_SIZE;i++)
{
*pt++ = *paddr++;
}
for(i=0;i<TEST_SIZE;i++)
{
if((TEST_SIZE-i) != u8TestData)
{
#ifdef DEBUG_PRINT
printf("work flash 32bit write data fail \n");
#endif
while(1);
}
}
#ifdef DEBUG_PRINT
printf("work flash 32bit write data successfully \n");
printf("==================================================\n");
printf("work flash Example Program End \n");
printf("==================================================\n");
#endif
while(1);
}
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the code example.
I couldn't find the example in my pdl folder.
I have tried to get the code below to work, but only 8 of the 16 bit were written to the workflash.
#define WORK_FLASH_ADDRESS_BT_ADDRESS1 0x200C008D
void WriteFlash()
{
__disable_interrupt();
// erase sector0 of Work Flash
WFlash_ChipErase();
uint8_t test[6];
test[0] = 0xAB;
test[1] = 0x12;
test[2] = 0x67;
test[3] = 0xEE;
test[4] = 0x1A;
test[5] = 0xE5;
WFlash_WriteData16Bit((uint16_t*)WORK_FLASH_ADDRESS_BT_ADDRESS1, (uint16_t*)test, sizeof(test)/sizeof(uint16_t));
test1 = Flash_ReadUInt16(WORK_FLASH_ADDRESS_BT_ADDRESS1);
__enable_interrupt();
}
But the flash looks like this:
Do you have any Idea?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't have MB9BF368R board, so I cannot help to test.
could you please download PDLv2.0.x to try again.
you can use the example code directly to test.
\Cypress\FM_PDL_2.0.2\example\flash\fm4\type1_6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have downloaded the PDLv2.0.2 and there I have found the flash examples.
I have done some tests and now the read and write function of the workflash is working great.
Thanks for your support.