Hello Support,
We got problems with the generated order of memory access using cgtools 6.1.12 with option -o3.
With cgtools 6.1.19 the access order is correct, but I did not find anything in the release note which described a similar bug to be corrected.
So I am not sure if this bug is know corrected or if it's just a side effect of other changes in the cgtools, so that the problem may occur in a slightly different situation.
The compiler options are: -k -pdsw225 -o3 -mv6700
The file with the testcase is added at the bottom of the mail, so here a short description of the case:
--- snip --- (line numbers for easier description)
[19] // sequence to read flash id: order of access is important
[20] *(volatile unsigned short*)(pFlashBase + 0x0AAA) = 0xAAAA;
[21] *(volatile unsigned short*)(pFlashBase + 0x0554) = 0x5555;
[22] *(volatile unsigned short*)(pFlashBase + 0x0AAA) = 0x9090;
[23]
[24] // read flash id (3 bytes)
[25] // must be read after writing the sequence
[26] arByte[0] = *(volatile unsigned char*)(pFlashBase + 0x0002);
[27] arByte[1] = *(volatile unsigned char*)(pFlashBase + 0x001C);
[28] arByte[2] = *(volatile unsigned char*)(pFlashBase + 0x001E);
--- snip ---
With cgtools 6.1.12 the read access of line 26 to 28 occurs before the write access of line 20 to 22.
And the write access of line 20 is not generated at all.
With cgtools 6.1.19 the order is correct. All write accesses are generated in the correct order and the read accesses occur after the writes.
Was there a bug in 6.1.12 which is fixed know, but I didn't found in the release notes?
What we need is a method to ensure a fixed order of those memory accesses. If volatile is not enough, what can we do else? Any pragma to tell the compiler not change the order?
Best regards
Stefan Bußmann
-------------------------------------------------------
Baumüller Nürnberg GmbH
Ostendstrasse 80-90, D-90482 Nürnberg
Tel: +49 (0)911 5432-285
Fax: +49 (0)911 5432-417
Email: s.bussmann@baumueller.de
URL: www.baumueller.de
-------------------------------------------------------
Geschäftsführer / Board: Dipl.-Ing. Andreas Baumüller, Jochen Loy, Dipl. Ing. Norbert Scholz
AR.-Vors.: / Chairman: Dipl. Ing. Günter Baumüller AG Nürnberg HRB 589
----- here the file testcase.c ----
// Testcase to demonstrate wrong order of memory access using option -o3
// with cgtools 6.1.12 and 6.1.13 we get wrong access order
// with cgtools 6.1.19 the access order is correct
// compiler options: -k -pdsw225 -o3 -mv6700
// static function - will be inlined automatically
// without inlining the access order is correct
static unsigned get_flash_devicetype(unsigned FlashAddr)
{
unsigned cpu_sr;
unsigned char arByte[3];
unsigned deviceType;
unsigned char* pFlashBase = (unsigned char*) (FlashAddr & 0xF0000000);
cpu_sr = _disable_interrupts();
// sequence to read flash id: order of access is important
*(volatile unsigned short*)(pFlashBase + 0x0AAA) = 0xAAAA;
*(volatile unsigned short*)(pFlashBase + 0x0554) = 0x5555;
*(volatile unsigned short*)(pFlashBase + 0x0AAA) = 0x9090;
// read flash id (3 bytes)
// must be read after writing the sequence
arByte[0] = *(volatile unsigned char*)(pFlashBase + 0x0002);
arByte[1] = *(volatile unsigned char*)(pFlashBase + 0x001C);
arByte[2] = *(volatile unsigned char*)(pFlashBase + 0x001E);
_restore_interrupts(cpu_sr);
deviceType = ((unsigned)(arByte[0] & 0xFF) << 16)
|((unsigned)(arByte[1] & 0xFF) << 8 )
|((unsigned)(arByte[2] & 0xFF));
return deviceType;
}
unsigned initFlashDevice(unsigned FlashAddr)
{
return get_flash_devicetype(FlashAddr);
}
----- end of testcase.c -----