2016-01-22 06:29 AM
Guys,
I tried to use HAL_SPI from STM32CubeMX with FATFs but I got this error when I compiled the function below argument of type ''const BYTE *'' is incompatible with parameter of type ''BYTE *'' How can I fix it ?DRESULT disk_write(BYTE pdrv,
const
BYTE *buff, DWORD sector, UINT count)
{
DRESULT res;
if (pdrv || !count) return RES_PARERR;
if (Stat & STA_NOINIT) return RES_NOTRDY;
if (Stat & STA_PROTECT) return RES_WRPRT;
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
if (count == 1) { /* Single block write */
if ((send_cmd(CMD24, sector) == 0) /* WRITE_BLOCK */
&& xmit_datablock(buff, 0xFE))
count = 0;
}
else { /* Multiple block write */
if (CardType & CT_SDC) send_cmd(ACMD23, count);
if (send_cmd(CMD25, sector) == 0) { /* WRITE_MULTIPLE_BLOCK */
do {
if (!xmit_datablock(buff, 0xFC)) break;
buff += 512;
} while (--count);
if (!xmit_datablock(0, 0xFD)) /* STOP_TRAN token */
count = 1;
}
}
deselect();
return count ? RES_ERROR : RES_OK;
//res = disk.drv[pdrv]->disk_write(buff, sector, count);
//return res;
}
thanks
2016-01-22 08:25 AM
Which lines is it actually complaining about? Presumably the xmit_datablock() ones?
You could change the parameters of the function(s), or cast as appropriate.2016-01-22 11:30 AM
Yes this function is complaining to me :
xmit_datablock(buff, 0xFE) Any ideas on how to fix it ? if I put to const BYTE *buff, it will not be compiled....
static int xmit_datablock ( BYTE *buff, /* 512 byte data block to be transmitted */ BYTE token /* Data/Stop token */ ) { BYTE resp; if (!wait_ready(500)) return 0; xchg_spi(token); /* Xmit data token */ if (token != 0xFD) { /* Is data token */ xmit_spi_multi(buff, 512); /* Xmit the data block to the MMC */ xchg_spi(0xFF); /* CRC (Dummy) */ xchg_spi(0xFF); resp = xchg_spi(0xFF); /* Reveive data response */ if ((resp & 0x1F) != 0x05) /* If not accepted, return with error */ return 0; } return 1; } Thanks2016-01-23 09:49 AM
Well the compiler is going to be intolerant of you switching back and forth about whether the data pointed to can be changed, or not. So go through your code and subroutines and define everything coherently.
https://en.wikipedia.org/wiki/Const_%28computer_programming%29
2016-01-23 02:14 PM
If I delete all the ''const'' it's compiled properly, would it be ok ?
I can run it as well on the chip .... Why can't I read this message properly on this forum ? The message is overlapping each other ? is the Css file not working normally ??2016-01-23 05:18 PM
It has to do with what you posted into the first post, suggest you edit that and get rid of any goofy formatting, fonts, etc
So copy and paste it into Notepad, delete the original stuff, and copy and paste it back.