Skip to main content
antonius
Associate III
Jan 22, 2016 2:29 PM UTC
Question

FatFS on STM32CubeMx question ?

Posted on January 22, 2016 at 15:29

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
    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    Jan 22, 2016 4:25 PM UTC
    Posted on January 22, 2016 at 17:25

    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.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    antonius
    antoniusAuthor
    Associate III
    Jan 22, 2016 7:30 PM UTC
    Posted on January 22, 2016 at 20:30

    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;

    }   Thanks

    Tesla DeLorean
    Guru
    Jan 23, 2016 5:49 PM UTC
    Posted on January 23, 2016 at 18:49

    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

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    antonius
    antoniusAuthor
    Associate III
    Jan 23, 2016 10:14 PM UTC
    Posted on January 23, 2016 at 23:14

    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 ??

    Tesla DeLorean
    Guru
    Jan 24, 2016 1:18 AM UTC
    Posted on January 24, 2016 at 02:18

    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.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..