Page 1 of 1
Using Flash Memory problem
Posted: Wed Aug 28, 2019 1:32 pm
by gonzalo
Hi Tom,
I am trying to save in the non volatile memory data in order to mantain it after turn off the KFLOP. I am using the ProgramFlashNoMessages() from the FLASH_USER possition and is working fine, I can sabe it and reade it in the positions but the problem is that the memory deletes after reboot the KFLOP, how can I fix it?
Many thnaks in advance,
Best Regards,
Gonzalo
Re: Using Flash Memory problem
Posted: Wed Aug 28, 2019 4:08 pm
by TomKerekes
Hi Gonzalo,
The Flash memory space accessed in banks. Are you setting the bank? See the example below. Otherwise post the code that writes and reads the data.
Code: Select all
#include "KMotionDef.h"
main()
{
double *p=(double*)FLASH_USER; // pointer to the FLASH Chip
SetFlashBank(p); // the DSP external bus is banked, this routine selects the bank for the address
// now we can access the data
printf("Saved 0 1 2 = %f %f next word = %X\n",p[0],p[1],*(int*)(&p[2]));
}
Re: Using Flash Memory problem
Posted: Wed Aug 28, 2019 4:51 pm
by gonzalo
Hi Tom,
Code to save the data into FLASH:
Code: Select all
#include "KMotionDef.h"
#define FLASHD ((volatile double *)0x90100000)
double ATT_POS[256]; // variable 1
double ATT_POW[256]; // variable 2
double BET_POS_L1[8]; // variable 3
double BET_POS_L2[8]; // variable 4
double DataToSave[528]; // all variables toguether
int a;
// for testing
main()
{
a=0;
for (a=0; a<528; a=a+1)
{
DataToSave[a]=a;
}
Save_Data_Memory();
Read_Data_Memory();
}
// Flash the Destinations of all the axes after all host applications
// stop requesting status and nothing is moving for a period of Time_sec
// and the last flashed positions are different from the current
void Save_Data_Memory(void)
{
SetFlashBank(FLASH_USER); // Flash must be bank selected
// write 528 x 8 bytes of the buffer to the 2nd MByte of the Flash Chip
ProgramFlashNoMessages((volatile char *)DataToSave,4224,FLASH_USER);
}
void Read_Data_Memory(void)
{
int i;
i=0;
// copy Flash to Dests and Positions
for (i=0; i<256; i=i+1)
{
ATT_POS[i] = FLASHD[i]; // copy Flash to variable
printf("next Value is %f\n",ATT_POS[i]);
}
for (i=256; i<512; i=i+1)
{
ATT_POW[i-256] = FLASHD[i]; // copy Flash to variable
printf("next Value is %f\n",ATT_POW[i-256]);
Delay_sec(0.05);
}
for (i=512; i<520; i=i+1)
{
BET_POS_L1[i-512] = FLASHD[i]; // copy Flash to variable
printf("next Value is %f\n",BET_POS_L1[i-512]);
Delay_sec(0.05);
}
for (i=520; i<528; i=i+1)
{
BET_POS_L2[i-520] = FLASHD[i]; // copy Flash to Dests
printf("next Value is %f\n",BET_POS_L2[i-520]);
Delay_sec(0.05);
}
}
And the code to read the FLASH
Code: Select all
#include "KMotionDef.h"
#define FLASHD ((volatile double *)0x90100000)
main()
{
printf("Value is %f\n",FLASHD[50]);//+i*FLASH_BLOCK_SIZE/sizeof(double)
}
After save the data in the FLASH I can read it (print it), the problem is when I reboot the KFLOP that I loose all the data, I donĀ“t read the same variables.
Many thanks!!!
Re: Using Flash Memory problem
Posted: Wed Aug 28, 2019 5:43 pm
by TomKerekes
Hi Gonzalo,
You must set the Flash Bank:
Code: Select all
#include "KMotionDef.h"
#define FLASHD ((volatile double *)0x90100000)
main()
{
SetFlashBank(&FLASHD[50]); // the DSP external bus is banked, this routine selects the bank for the address
printf("Value is %f\n",FLASHD[50]);//+i*FLASH_BLOCK_SIZE/sizeof(double)
}
Re: Using Flash Memory problem
Posted: Thu Aug 29, 2019 8:09 am
by gonzalo
Great Tom!! Many thanks again!!