Hi guys,
I need to save some data in flash memory to be available after each on-off, but I need to modify them when I receive specific commands (from CANbus).
I read the application note and hardware manual, so I think to work in CPU rewrite mode, in EW1 mode.
How can I do to save default data one time at the first ignition?
In this way, if these data are modify during program execution, I can use the new parameters instead the default ones.
Thank for the answers.
Valeria
I know that R8C/27 haven't can interface,
the circuit is supply with external CAN controller and CAN transceiver. That was just a clarification.
But that isn't the question.
2KB of memory are enough for my application.
I have to store 20bytes of parameters.
Could you answer to my question please?
Ty
Yes, EW1 mode is fine to store some initialisation data in flash. It does not really make a big difference if you use program flash or data flash. Data flash has only frm specification a higher number of program-erase cycles. And of course it is faster to erase small data flash blocks than larger program flash blocks.
And you could include a default data set as constants in your application. Then the default data is already programmed when you write your software to the device.
Thank you FrankL.
Do you mean that i could store the default data making
"#define DEFAULT_DATA_0
#define DEFAULT_DATA_1
#define DEFAULT_DATA_2
ecc..." ?
But in this way, at power-on i find again the same default data, so there?
In my application I need to read from the flash the parameters at power-on, but if I have changed those values during the previous execution I'll must use the new parameters.
I explain with a simple flowchart what I would like to do:
Start -> is blockA = 0xFF ? YES (it means that it is the first power-on after reprogramming) -> write default data into blockA
NO (it means that the program has been already execute ) -> read data into blockA
I chose to use data blocks (A in this case) because my program take up more over one block capacity of program memory .
You don't understand what I was talking about. Constants are not #defines. I proposed something like that:
const unsigned char INIT_VALUES[]={0x00, 0x01, 0x02, 0x03, 0x04};
If you compile for R8C this const table should be located in rom_NO section.
If this rom_NO section is in data flash, you can go and reprogram in your software the values for INIT_VALUES.
If you reprogram your software you will have the start values for INIT_VALUES in data flash.
Infact it's not so clear.
so please bear with me.
I have tried to define an array of constant values.
in the map memory turn out stored in data_NO section, at the start address 0x450.
In the datasheet is written that the start address of blockA is 0x2400.
I suppose that the array didn't locate in data flash memory.
The 27 should have two block of Flash that you can work with. As long as you are running out of Block 0 you can run from Block 1 (and vice versa).
Of course you could move your array to the section of Flash that's called DataFlash. It can store data and code just like normal flash.
Lots of good message threads cover memory mapping and sections:
http://www.renesasrulz.com/message/6553
http://www.renesasrulz.com/message/3124
Yes I did. It's just the document where I found the near pointer.
This is my code:
flash_read((BUF_PTR_TYPE)read_buf, (FLASH_PTR_TYPE) 0x2400);
for (i = 0; i < RECORD_SIZE; i++)
{
if (read_buf[i] != 0xFF)
{
memory_empty = 0;
break;
}
else
memory_empty = 1;
}
if (memory_empty == 1)
{
default_data(write_buf);
do
{
while(block_erase(BLOCK_A) != COMPLETE)
;
result = data_write((FLASH_PTR_TYPE)0x2400, (BUF_PTR_TYPE)write_buf, RECORD_SIZE);
} while(result != COMPLETE);
}
where the functions are similar to the original ones in sample code:
void flash_read(BUF_PTR_TYPE buf_read, FLASH_PTR_TYPE block)
{
int i;
for (i = 0; i < RECORD_SIZE; i++)
{
*buf_read = *block;
buf_read++;
block++;
}
}
unsigned char block_erase(unsigned char block)
{
unsigned char erase_result;
volatile FLASH_PTR_TYPE flash_addr;
unsigned char ret_value;
flash_addr = (FLASH_PTR_TYPE) block_addresses[ block ];
fmr01 = 0;
asm("");
fmr01 = 1; // CPU rewrite mode enabled
fmr11 = 0;
asm(" "); /* Description for preventing the abbreviation by optimization */
fmr11 = 1; /* EW1 mode */
*flash_addr = 0x50;
*flash_addr = 0x20; /* Block erase command write */
*flash_addr = 0xD0; /* Block erase command write */
while(fmr00 != 1)
;
erase_result = full_sts_chk(flash_addr);
fmr0 = 0;
return erase_result;
}
void default_data(BUF_PTR_TYPE data)
{
data[0] = 0x00; // x_os low
data[1] = 0x00;
data[2] = 0x00; // CYM deactivate (request position)
data[3] = 0x00; // request position ID 0x100
data[4] = 0x01;
data[5] = 0x01; // reply position ID 0x101
data[6] = 0x01;
data[7] = 0x01; // cyclic position ID 0x201
data[8] = 0x02;
data[9] = 0x00; // set parameter ID 0x0300
data[10]= 0x03;
data[11]= 0x01; // reply parameter ID 0x301
data[12]= 0x03;
data[13]= 0x07; // baudrate 500kbps
data[14]= 0x00; // averaging deactivated
data[15]= 0x02; // status default parameter
data[16]= 0x64; // CYT 2bytes 100ms
data[17]= 0x11;
data[18]= 0x22; // y_os low
data[19]= 0x33;
}
unsigned char data_write(FLASH_PTR_TYPE flash_addr, BUF_PTR_TYPE buffer_addr, unsigned int bytes)
{
unsigned char program_result = COMPLETE; /* program result */
int i; /* loop counter */
fmr01 = 0;
asm("");
fmr01 = 1; // CPU rewrite mode enabled
fmr11 = 0;
asm(" "); /* Description for preventing the abbreviation by optimization */
fmr11 = 1; /* EW1 mode */
/* write record data */
*flash_addr = 0x50; // Clear status register
while(bytes)
{
/* Write to the flash sequencer by writting to that area of flash memory */
*flash_addr = 0x40; // Send write command
*flash_addr = *buffer_addr; // Write next word of data
while(fmr00 != 1) /* Ready? */
;
flash_addr++; // Advance to next flash write address
buffer_addr++; // Advance to next data buffer address
/* NOTE: The R8C writes to flash a 8 bits at a time where as the M16C
* writes to flash 16 bits at a time. */
bytes--; // Subract 1 from byte counter
}
/* Program status check */
program_result = full_sts_chk(flash_addr);
fmr0 = 0;
return program_result;
}
Suppose that this code be in a loop.
After some cycles (about 5 or 20 or 40, number of cycles is never the same) the values that I stored zeroing.
Why that happens? Is it matter of pointers?
Thank you guys.
To help debug, can you dump the data out of a serial port and log it in a PC terminal program? If you have access to an RS232 port this would be easy, and would allow you to see the data that's being flashed to memory.
FAR pointers shouldn't be required on the 27. Everything in memory is NEAR for the 27.
Hi! I am a new entry in this forum. I hope I find a solution for my problem. I'm working with a R8C/27 and I think I have the same problem of iValeria. I've generated startup files in assembler mode and I'm trying to store during the execution of my code some data in Block A. I'm using the same code posted by iValeria but in read operation I obtain only 0xFF values and I'm not able to erase or write Block A (or Block B). Is it necessary to modify sect30.inc to use data flash? If yes, in what manner?
Thank you!!
Stefano
Please try this sample. This works on my R8C/27.
http://www.renesasrulz.com/servlet/JiveServlet/downloadBody/1591-102-1-1472/FlashAPI_R8C.zip
©2003–2009 Renesas Technology Corp. All rights reserved. Using Our Website | Privacy
Contact us