Hi Ruby,
I am not aware of any necessary delay for reading D-Flash.
Unfortunately, I was not able to reproduce described issue.
Is _startup() function first function executed after reset (like _Startup() function in standard project)?
If yes, I cannot see stack initialization command in your code.
For example: INIT_SP_FROM_STARTUP_DESC();
The same is valid for zero out and copy down functions like standard Init(); function.
I created very simple code in main.c file:
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
const unsigned char mydata @0x000800 = 0x23;
void main(void) {
volatile unsigned char c;
c=*(unsigned char * __far)0x100000;
DDRA = 0x01;
if (c == 0x23) PORTA = 0x01;
else PORTA = 0x00;
for(;;) {
} /* loop forever */
}
Additionally I placed “mydata” name into ENTRIES section in prm file because mydata is not directly referenced in the code and I want avoid to optimizing it out.
The c variable is loaded correctly despite on fact whether main() is called after or before Init() function.
If the variable c is declared inside main() function, it will be created on the stack.
If the variable c is declared as the global variable, it will be created on RAM.
This leads me to question how did you test variable c value and how you signalize it?
When the variable is on the stack, there may be some problem with address position or stack pointer modifying.
When you use BDM for reading variable c value, the BDM communication needs some time for reading it and 0 may be just initial value before getting first value.
Could you please specify your MCU by part number and maskset?
I tested P9S12XET256MAL with maskset 1M53J running on 16MHz crystal.
The MCU was not partitioned (DFPART,ERPART=0xFF)
If you send me your project, I may shortly check it for any obvious or potential issues.
I hope it helps you.
Have a great day,
Radek
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------