- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have a board with a cyble-222014-01 device
I want a simple example in how to write to user flash area and read again, i have tried foloowing code:
const uint8_t row[CY_FLASH_SIZEOF_ROW] CY_ALIGN(CY_FLASH_SIZEOF_ROW) = {0};
uint8_t data[CY_FLASH_SIZEOF_ROW];
int rowNum;
// calculate which row in the flash that the "row" array resides
rowNum = ((int)row - CY_FLASH_BASE) / CY_FLASH_SIZEOF_ROW;
memcpy(data,row,(int)CY_FLASH_SIZEOF_ROW);
data[1]=123;
uint32 rval = CySysFlashWriteRow(rowNum,data);
if(rval == CY_SYS_FLASH_SUCCESS )
{
uint8 ok = 1;
}
my problem here is that rval is not 0 but 4 = CY_SYS_FLASH_INVALID_ADDR, when i try to write.
Anyone can help here
Solved! Go to Solution.
- Tags:
- Userflash write
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @EsFr_4600111 ,
I have tried your code at my end and found out that you have placed ' const uint8_t row[CY_FLASH_SIZEOF_ROW] CY_ALIGN(CY_FLASH_SIZEOF_ROW) = {0};' inside the main function. This allocates the memory region in RAM not in Flash. This is causing the error while executing.
You need to place row variable outside the main function. The modified code will be as follows:
#include "project.h"
const uint8_t row[CY_FLASH_SIZEOF_ROW] CY_ALIGN(CY_FLASH_SIZEOF_ROW) = {0};
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
uint8_t data[CY_FLASH_SIZEOF_ROW];
int rowNum;
// calculate which row in the flash that the "row" array resides
rowNum = ((int)row - CY_FLASH_BASE) / CY_FLASH_SIZEOF_ROW;
memcpy(data,row,(int)CY_FLASH_SIZEOF_ROW);
data[1]=123;
volatile uint32 rval = CySysFlashWriteRow(rowNum,data);
if(rval == CY_SYS_FLASH_SUCCESS )
{
uint8 ok = 1;
}
for(;;)
{
/* Place your application code here. */
}
}
/* [] END OF FILE */
Best regards,
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
Is there a reason you are not using emEEPROM component? This emulates an EEPROM using FLASH in PSoC's that do not contain EEPROM. The API's are all written for you.
regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Im not able to see the emEEPROM component in the creator . Are you sure its enabled for cyble-222014-01 chip?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @EsFr_4600111 ,
I have tried your code at my end and found out that you have placed ' const uint8_t row[CY_FLASH_SIZEOF_ROW] CY_ALIGN(CY_FLASH_SIZEOF_ROW) = {0};' inside the main function. This allocates the memory region in RAM not in Flash. This is causing the error while executing.
You need to place row variable outside the main function. The modified code will be as follows:
#include "project.h"
const uint8_t row[CY_FLASH_SIZEOF_ROW] CY_ALIGN(CY_FLASH_SIZEOF_ROW) = {0};
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
uint8_t data[CY_FLASH_SIZEOF_ROW];
int rowNum;
// calculate which row in the flash that the "row" array resides
rowNum = ((int)row - CY_FLASH_BASE) / CY_FLASH_SIZEOF_ROW;
memcpy(data,row,(int)CY_FLASH_SIZEOF_ROW);
data[1]=123;
volatile uint32 rval = CySysFlashWriteRow(rowNum,data);
if(rval == CY_SYS_FLASH_SUCCESS )
{
uint8 ok = 1;
}
for(;;)
{
/* Place your application code here. */
}
}
/* [] END OF FILE */
Best regards,
Raj