Using Flash Memory problem

Moderators: TomKerekes, dynomotion

Post Reply
gonzalo
Posts: 13
Joined: Wed Feb 27, 2019 4:03 pm

Using Flash Memory problem

Post by gonzalo » Wed Aug 28, 2019 1:32 pm

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

User avatar
TomKerekes
Posts: 1072
Joined: Mon Dec 04, 2017 1:49 am

Re: Using Flash Memory problem

Post by TomKerekes » Wed Aug 28, 2019 4:08 pm

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]));
}
Regards,

Tom Kerekes
Dynomotion, Inc.

gonzalo
Posts: 13
Joined: Wed Feb 27, 2019 4:03 pm

Re: Using Flash Memory problem

Post by gonzalo » Wed Aug 28, 2019 4:51 pm

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!!!

User avatar
TomKerekes
Posts: 1072
Joined: Mon Dec 04, 2017 1:49 am

Re: Using Flash Memory problem

Post by TomKerekes » Wed Aug 28, 2019 5:43 pm

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)
}
Regards,

Tom Kerekes
Dynomotion, Inc.

gonzalo
Posts: 13
Joined: Wed Feb 27, 2019 4:03 pm

Re: Using Flash Memory problem

Post by gonzalo » Thu Aug 29, 2019 8:09 am

Great Tom!! Many thanks again!!

Post Reply