Altera_Forum
Honored Contributor
20 years agoCompact flash perculiarities
Hello
I am using bothe the EP1C20 Nios dev board and the EP2C35 dev board. On both of them I use the same cf core provided by Altera. I get strange results on both boards with sevsral compact flash cards and in one instance: a card works fine on the EP1C20 and does not work well on the EP2C35 board. The strange thing I get is that the initial IDE test fails (the test is a very simple one: writes a value to the sector register of the core and reads it to confirm the write). As far as I can see in hardware, there is actually a failure, but its source is not clear. Here is the code that fails:int IDE_initialize(void)
{
IDE_setVerbosity(0);
IOWR_ALTERA_AVALON_CF_CTL_CONTROL(ctl_base, ALTERA_AVALON_CF_CTL_STATUS_POWER_MSK);
# if 1
{
// Register test:
unsigned char ucWrite;
unsigned char ucRead;
int iGood = 1;
for (ucWrite = 0; ucWrite < 10; ++ucWrite)
{
IOWR_ALTERA_AVALON_CF_IDE_SECTOR_NUMBER(ide_base, ucWrite);
ucRead = IORD_ALTERA_AVALON_CF_IDE_SECTOR_NUMBER(ide_base);
if (ucWrite != ucRead)
{
iGood = 0;
printf("verify fail: wrote 0x%X, read 0x%X\n", ucWrite, ucRead);
}
}
if (iGood)
{
printf("wrote and verified %d values successfully.\n", ucWrite);
}
else
{
printf("failed to write and verify all the values.\n");
printf("Did you remember to insert or re-insert the card?\n");
return 0;
}
}# endif
// enable insert detect interrupt
alt_irq_register(ctl_irq, 0, CTLTrapHandler);
IOWR_ALTERA_AVALON_CF_CTL_CONTROL(ctl_base, ALTERA_AVALON_CF_CTL_STATUS_POWER_MSK
+ ALTERA_AVALON_CF_CTL_STATUS_IRQ_EN_MSK);
// enable IDE interrupts
alt_irq_register(ide_irq, 0, IDETrapHandler);
IOWR_ALTERA_AVALON_CF_IDE_CTL(ctl_base, ALTERA_AVALON_CF_IDE_CTL_IRQ_EN_MSK);
if (!IDE_identifyDevice(0))
{
return 0;
}
IDE_initializeDeviceParameters(0, getLogicalHeads(),
getLogicalCylinders(), getSectorsPerTrack());
return 1;
} And here is the output to the console:[list]verify fail: wrote 0x0, read 0x1 verify fail: wrote 0x2, read 0x1 verify fail: wrote 0x3, read 0x1 verify fail: wrote 0x4, read 0x1 verify fail: wrote 0x5, read 0x1 verify fail: wrote 0x6, read 0x1 verify fail: wrote 0x7, read 0x1 verify fail: wrote 0x8, read 0x1 verify fail: wrote 0x9, read 0x1[/list] There are no timing problems in the design and as mentioned before, the same thing may fail with two or three cards and then work with the fourth one. Has anyone come accross this problem before ? Nir