Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] How to fix FatFS compilation on STM32 ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,442
Guys,

I tried to compile FatFS on STM32 but got this error, how to fix it ?
thanks

Code:
..\Middlewares\Third_Party\FatFs\src\diskio.c(443): error:  #167: argument of type "const BYTE *" is incompatible with parameter of type "BYTE *"
 

Probably a problem of compiler options.

FatFs is using const attribute e.g. for write buffers, if you want to assign a non constant object to it, you need either to relax type checking or use a type cast.
 

Probably a problem of compiler options.

FatFs is using const attribute e.g. for write buffers, if you want to assign a non constant object to it, you need either to relax type checking or use a type cast.

Here's the function :
Code:
#if _USE_WRITE == 1
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;
}
#endif /* _USE_WRITE == 1 */

I got error on :
xmit_datablock(buff, 0xFE))

....
you need either to relax type checking or use a type cast

How can I do that ?
 

In recent fatfs implementations that I reviewed, xmit_datablock() has also const BYTE * buff parameter, thus the problem doesn't occur.

I'm not sure if GCC has a global option to relax type checking for const pointers. I would use a type cast (BYTE *).
 

In recent fatfs implementations that I reviewed, xmit_datablock() has also const BYTE * buff parameter, thus the problem doesn't occur.

I'm not sure if GCC has a global option to relax type checking for const pointers. I would use a type cast (BYTE *).

if I put :
Code:
static
int xmit_datablock (
	  const 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;
}

I got :
Code:
..\Middlewares\Third_Party\FatFs\src\diskio.c(237): error:  #167: argument of type "const BYTE *" is incompatible with parameter of type "uint8_t *"
\
because of :
xmit_spi_multi(buff, 512);

Code:
/* Send a data block fast */
static
void xmit_spi_multi (
	 uint8_t *p,	/* Data block to be sent */
	UINT cnt		
)
{
	while(HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY); 
	HAL_SPI_Transmit(&hspi2,p,cnt,100);
}

/* Receive a data block fast */
static
void rcvr_spi_multi (
	BYTE *p,	/* Data buffer */
	UINT cnt	/* Size of data block (must be multiple of 2) */
)
{
	while(HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY); 
	HAL_SPI_Receive(&hspi2,p,cnt,100);
}

I don't think I can change uint8_t *p ....to const BYTE....because it's from HAL STM32CubeMX...

- - - Updated - - -

I change to BYTE, I got :
Code:
..\Middlewares\Third_Party\FatFs\src\diskio.c(237): error:  #167: argument of type "const BYTE *" is incompatible with parameter of type "BYTE *"

- - - Updated - - -

Code:
static
void xmit_spi_multi (
	 const BYTE *p,	/* Data block to be sent */
	UINT cnt		
)
{
	while(HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY); 
	HAL_SPI_Transmit(&hspi2,p,cnt,100);
}


}

..\Middlewares\Third_Party\FatFs\src\diskio.c(132): error: #167: argument of type "const BYTE *" is incompatible with parameter of type "uint8_t *"
 

Have you tried to cast const BTYE * to (BYTE *)?

Code:
static
int xmit_datablock (
	  const 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;
}

const BYTE *buff to (BYTE *buff) ??

- - - Updated - - -

It works fine if I erased "const"
Code:
//#if	_USE_WRITE
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;
}

- - - Updated - - -

I got this error if I deleted all const :

..\Middlewares\Third_Party\FatFs\src\ff.c(2728): error: #167: argument of type "const BYTE *" is incompatible with parameter of type "BYTE *"
 

Did you also update the declaration in the header?
Susan
 

Consider using CMSIS compliant ARM library to avoid such issues.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top