cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32f4 data read/write from usb

FOztu.1
Associate II

Hi,

I am triying to do a mp3 player using usb.Firstly,I am triying simple things writing message to usb or reading message from usb.I compiled code there is 0 error 0 warnigs but it didnt work.

I am sharing code waiting for your answers.

Thank you.

switch(Appli_state)

{

case APPLICATION_IDLE:

break;

case APPLICATION_START:

if(f_mount(&myUsbFatFS, (TCHAR const*)USBHPath,0) == FR_OK) 

{

//Turn Green LED ON

HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);

}

break;

case APPLICATION_READY:

if(HAL_GPIO_ReadPin(Button_GPIO_Port, Button_Pin) == GPIO_PIN_SET)

{

if(UsbTest_Write()) HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_SET);

else HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET);

HAL_Delay(1000);

}

break;

case APPLICATION_DISCONNECT:

//Turn Green LED OFF

HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);

break;

  }

4 REPLIES 4
FOztu.1
Associate II

bool UsbTest_Write(void)

{

//Open or Create file for writing

if(f_open(&myFile, "TEST2.TXT", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)

{

return 0;

}

//Copy test Text to my temporary read/write buffer

sprintf(rwtext, "H");

//Write to text file

res = f_write(&myFile, (const void *)rwtext, strlen(rwtext), &byteswritten);

if((res != FR_OK) || (byteswritten == 0))

{

return 0;

}

f_close(&myFile);

return 1; //Success

}

>>.I compiled code there is 0 error 0 warnings but it didn't work.

Doesn't that just mean there aren't any syntax errors? Not that the code is either functional or correct.

This is all rather top-level stuff, not clear if you're even observing error codes or reporting them. You should instrument the DISKIO code and check if that succeeds or not, guessing it doesn't.

Try testing the Host USB MSC code, or the Firmware Update code,

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Ons KOOLI
Senior III

Hi FOztu.1,

In fact, there is a ready developed app provided by ST that does the job.The X-CUBE-AUDIO package contains advanced Audio projects for STM32F469I and STM32F746G Discovery boards. You can find what you are looking for in an application called Audio_MP3_player.

Best Regards,

Ons.

Thank you