Hi all
I am using the flexram as an eeprom, configured by Processor Expert. In the init function, the program tests whether the flexram has been partitioned previously, see lines 59 - 61 of "ProcessorExper.c" in attacheed project. I am wondering why the PE function "Cpu_GetFlexNVMPartitionCode()" always returns 0, although the flexram is configured correctly (and works as expected). It should response 0x2205. Does anyone know why?
And there is a second strange behaviour: If I erase the chip (= flexram settings overwritten) and call the "init_internal_eeprom()" from "taskA", the function crashes at line 64. If it is called from within "main" after a chip erase, everything works! Any suggestions?
Setup:
- Target = MK22FX512VLH12
- Processor Expert 10.3.0
- IAR 7.40.1
Best regards,
Mathias
Original Attachment has been moved to: FlexMem_Test.zip
Solved! Go to Solution.
Hi Mathias Bucher,
Thank you for your interest in Freescale kinetis product.
1:Cpu_GetFlexNVMPartitionCode() function question:
I think your Cpu_GetFlexNVMPartitionCode() function is not correct. This function return vaulue is :
return (uint16_t)(((FTFE_PDD_Cmd_ReadPartition_GetEepromDataSize(FTFE_BASE_PTR) & 0x3F) << 8) | (FTFE_PDD_Cmd_ReadPartition_GetEepromBackUpSize(FTFE_BASE_PTR) & 0x0F));
I check it, it actually is : (FCCOB4 &0X3f)<<8 |( FCCOB5&0x0f). in the above code of Cpu_GetFlexNVMPartitionCode(), FCCOB4 is define to 0, and nothing defined to FCCOB5, then of course, this function is return 0.
I think this usage is not correct, you don't need to use this function, you can do the partition like this function:
int partition_flash(int eeprom_size, int dflash_size)
{
/* Test to make sure the device is not already partitioned. If it
* is already partitioned, then return with no action performed.
*/
if ((SIM_FCFG1 & SIM_FCFG1_DEPART(0xF)) != 0x00000F00)
{
printf("\nDevice is already partitioned.\n");
return 0;
}
/* Write the FCCOB registers */
FTFE_FCCOB0 = FTFEF_CCOB0_CCOBn(0x80); // Selects the PGMPART command
FTFE_FCCOB1 = 0x00;
FTFE_FCCOB2 = 0x00;
FTFE_FCCOB3 = 0x00;
/* FCCOB4 is written with the code for the subsystem sizes (eeprom_size define) */
FTFE_FCCOB4 = eeprom_size;
/* FFCOB5 is written with the code for the Dflash size (dflash_size define) */
FTFE_FCCOB5 = dflash_size;
/* All required FCCOBx registers are written, so launch the command */
FTFE_FSTAT = FTFE_FSTAT_CCIF_MASK;
/* Wait for the command to complete */
while(!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK));
return 1;
}
2: working in taskA question
You are working ok within main function, and when working from task A, the function crashes.
It is because, erase and do flash partition process shouldn't be broken when it is working, when your function working in task A, if your task time is over(task time is shorter than the task function execution time ), even your flash function is still not completed, your flash function will be stopped, then it will have problem. you can put your flash function in main.
Wish it helps you!
If you still have question, please contact me!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Mathias Bucher,
Thank you for your interest in Freescale kinetis product.
1:Cpu_GetFlexNVMPartitionCode() function question:
I think your Cpu_GetFlexNVMPartitionCode() function is not correct. This function return vaulue is :
return (uint16_t)(((FTFE_PDD_Cmd_ReadPartition_GetEepromDataSize(FTFE_BASE_PTR) & 0x3F) << 8) | (FTFE_PDD_Cmd_ReadPartition_GetEepromBackUpSize(FTFE_BASE_PTR) & 0x0F));
I check it, it actually is : (FCCOB4 &0X3f)<<8 |( FCCOB5&0x0f). in the above code of Cpu_GetFlexNVMPartitionCode(), FCCOB4 is define to 0, and nothing defined to FCCOB5, then of course, this function is return 0.
I think this usage is not correct, you don't need to use this function, you can do the partition like this function:
int partition_flash(int eeprom_size, int dflash_size)
{
/* Test to make sure the device is not already partitioned. If it
* is already partitioned, then return with no action performed.
*/
if ((SIM_FCFG1 & SIM_FCFG1_DEPART(0xF)) != 0x00000F00)
{
printf("\nDevice is already partitioned.\n");
return 0;
}
/* Write the FCCOB registers */
FTFE_FCCOB0 = FTFEF_CCOB0_CCOBn(0x80); // Selects the PGMPART command
FTFE_FCCOB1 = 0x00;
FTFE_FCCOB2 = 0x00;
FTFE_FCCOB3 = 0x00;
/* FCCOB4 is written with the code for the subsystem sizes (eeprom_size define) */
FTFE_FCCOB4 = eeprom_size;
/* FFCOB5 is written with the code for the Dflash size (dflash_size define) */
FTFE_FCCOB5 = dflash_size;
/* All required FCCOBx registers are written, so launch the command */
FTFE_FSTAT = FTFE_FSTAT_CCIF_MASK;
/* Wait for the command to complete */
while(!(FTFE_FSTAT & FTFE_FSTAT_CCIF_MASK));
return 1;
}
2: working in taskA question
You are working ok within main function, and when working from task A, the function crashes.
It is because, erase and do flash partition process shouldn't be broken when it is working, when your function working in task A, if your task time is over(task time is shorter than the task function execution time ), even your flash function is still not completed, your flash function will be stopped, then it will have problem. you can put your flash function in main.
Wish it helps you!
If you still have question, please contact me!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Jingjing
1: Thank you, works now.
2: Ok, I will call the init function from main. Maybe a second solution is to disable the interrupts inside the EEPROM init function..
Best regards,
Mathias
Hello Mathias,
An example of partitioning of the FlexNVM is available in the following discussion thread Reset when calling SetFlexNVMPartition() using KDS, PE and K22
Best Regards,
Marek Neuzil