2023-12-03 07:50 PM - last edited on 2024-11-16 03:14 AM by Andrew Neil
I am facing a issue as follows "
I am currently working on a project that involves integrating USB functionality for data transfer and data logging on an STM32F407VG micro-controller. Specifically, I want to log data files on an SD card and enable the user to download these logged files from the SD card via USB. Additionally, I'd like to allow users to copy files from their PC to the SD card via USB, all through the STM32F407VG using the SDIO communication protocol.
I'm facing a challenge in making the USB_OTG_FS (On-The-Go Full Speed USB) and the SD card (using FatFS) work together seamlessly. I would greatly appreciate your guidance and any insights you might have on how to achieve this integration.
"
Here is my sample code:
#include "usbd_storage_if.h"
extern SD_HandleTypeDef hsd;
#define STORAGE_LUN_NBR 1
#define STORAGE_BLK_NBR 0x10000
#define STORAGE_BLK_SIZ 0x200
const int8_t STORAGE_Inquirydata_FS[] = {
0x00,
0x80,
0x02,
0x02,
(STANDARD_INQUIRY_DATA_LEN - 5),
0x00,
0x00,
0x00,
'S', 'T', 'M', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
'P', 'r', 'o', 'd', 'u', 'c', 't', ' ', /* Product : 16 Bytes */
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'0', '.', '0' ,'1' /* Version : 4 Bytes */
};
static int8_t STORAGE_Init_FS(uint8_t lun);
static int8_t STORAGE_GetCapacity_FS(uint8_t lun, uint32_t *block_num, uint16_t *block_size);
static int8_t STORAGE_IsReady_FS(uint8_t lun);
static int8_t STORAGE_IsWriteProtected_FS(uint8_t lun);
static int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
static int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
static int8_t STORAGE_GetMaxLun_FS(void);
USBD_StorageTypeDef USBD_Storage_Interface_fops_FS =
{
STORAGE_Init_FS,
STORAGE_GetCapacity_FS,
STORAGE_IsReady_FS,
STORAGE_IsWriteProtected_FS,
STORAGE_Read_FS,
STORAGE_Write_FS,
STORAGE_GetMaxLun_FS,
(int8_t *)STORAGE_Inquirydata_FS
};
int8_t STORAGE_Init_FS(uint8_t lun)
{
return (USBD_OK);
}
int8_t STORAGE_GetCapacity_FS(uint8_t lun, uint32_t *block_num, uint16_t *block_size)
{
HAL_SD_CardInfoTypeDef info;
int8_t ret = -1;
HAL_SD_GetCardInfo(&hsd, &info);
*block_num = info.LogBlockNbr - 1;
*block_size = info.LogBlockSize;
ret = 0;
return ret;
}
int8_t STORAGE_IsReady_FS(uint8_t lun)
{
return (USBD_OK);
}
int8_t STORAGE_IsWriteProtected_FS(uint8_t lun)
{
return (USBD_OK);
}
int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
int8_t ret = -1;
HAL_SD_ReadBlocks(&hsd, buf, blk_addr, blk_len, HAL_MAX_DELAY);
/* Wait until SD card is ready to use for new operation */
while (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER){}
ret = 0;
return ret;
}
int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)
{
int8_t ret = -1;
HAL_SD_WriteBlocks(&hsd, buf, blk_addr, blk_len, HAL_MAX_DELAY);
while (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER){}
ret = 0;
return ret;
}
int8_t STORAGE_GetMaxLun_FS(void)
{
return (STORAGE_LUN_NBR - 1);
}
please go through my code (atteched below) and let me know what to do? and how to integrate USB and SD card simultaneously?
my observation: I took two STM32F407VGT6 microcontrollers and connect them the to same SDIO source it(setup) is not working when both boards are powered on but when USB and FATFS works fine seperatly the problem is in two pins (PC10 and PC11) D2 & D3 please give me solution for the following:
I am still facing issues in my project. I want to use USB functionality, but I am unable to do so due to a problem with SDIO pins PC10 (SDIO_D2) and PC11 (SDIO_D3). I am trying to connect two STM32F407VGT6 microcontrollers with the SDIO pins of the same discovery board (DM-STF4BB). We have uploaded USB (device-Mass storage device) code in one microcontroller, but that code only works when PC10 and PC11 pins are not shorted/connected. It doesn't matter if the second board is powered or not; connecting these two pins will always create a problem. And I want design a PCB in which only single controller will be powered at a time please guide me what to do, we can not use shottkey diode in PC 10&11 and VCC because of voltage loss, will MOSFET work ?
Consider the two red lines as PC10 and PC11 (D2 and D3 respectively), green lines as other SDIO lines with ground, and blue lines as VCC. Two squares represent STM32F4, and the rectangle below represents the SDIO device with an SD card.
code is uploaded in first STM32 on the left side
USB and FATFS functionality will only work in the following configuration
where as the USB will not even detect by any of the following configurations:
2023-12-03 08:52 PM
>>I have tried it posting on different- different forums like Stack overflow, ST Community forum, Quora and many more but still I am waiting for my issue to be resolved please help me out !!
And you've already opened a dozen threads here on this same project, with little interest. Pick one, and please don't open any more.
Perhaps you need more fonts and colours? Or some other engineers on the team.
Trying to share an SD Card between two boards seems like a bad plan. Why can't you have FAT-FS and USB-MSC work on a single board?
Concurrent usage is problematic due to coherency issues with the Windows system wanting to cache. One devices would need to own the resource, deferring the other with either Busy or Media Changed. Likely being in either Logging Mode, or being in On-load / Off-load mode to a PC.
Transferring files, via USART between two systems, probably want a protocol, people have been doing it for decades, perhaps review a couple of examples that worked. Jamming a continuous stream over the cable is not the answer / approach.
Your project as it stands looks to be an unworkable train wreck.
2023-12-03 10:30 PM
>>Why can't you have FAT-FS and USB-MSC work on a single board?<<
>>
I have tried using FAT-FS and USB-MSC on the same board, but it does not work. When I enable FATFS from STM CubeMax, USB functionality stops working. However, if I disable it, I can use USB on the same board again with the same code. Apart from this, I experimented with sending files from the SD card to the system via USB using a GUI. However, when sending the data over UART, the speed is notably slow.
(For example: " if I log UBX data in a file for 1 hour at 10 Hz and attempt to send that file via UART, it takes 24 minutes to transmit. I adopted this approach due to USB not functioning properly.")
As of now my task is to efficiently send the file to the device using USB, but I am facing difficulties in achieving this. Please provide assistance, and I apologize for any inconvenience caused by the previous threads.