I am beginning work on STM32 mass storage project. I want to make my device look like a flash drive on the PC so i can load and retrieve files. Eventually i would like to have this function as a firmware update tool and virtual com port depending on a set of circumstances.
For now i need to get the USB side up and running with some understanding in how it works.
I understand that i need to do the following:
USBD_INIT()
USBD_RegisterClass()
USBD_MSC_RegisterStorage()
USBD_Start
Following this i should get the device to detect in windows, create a drive and tell me the drive needs formatting.
I have a few examples that i am going to attempt to use to recreate in flowcode.
However i am struggling to wrap my head around a few aspects.
Code: Select all
#include "usb_device.h"
#include "usbd_core.h"
#include "usbd_desc.h"
#include "usbd_msc.h"
#include "usbd_storage_if.h"
/* Return USBD_OK if the Battery Charging Detection mode (BCD) is used, else USBD_FAIL */
extern USBD_StatusTypeDef USBD_LL_BatteryCharging(USBD_HandleTypeDef *pdev);
/* USB Device Core handle declaration */
USBD_HandleTypeDef hUsbDeviceFS;
/* init function */
void MX_USB_DEVICE_Init(void)
{
/* Init Device Library,Add Supported Class and Start the library*/
USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
USBD_RegisterClass(&hUsbDeviceFS, &USBD_MSC);
USBD_MSC_RegisterStorage(&hUsbDeviceFS, &USBD_Storage_Interface_fops_FS);
/* Verify if the Battery Charging Detection mode (BCD) is used : */
/* If yes, the USB device is started in the HAL_PCDEx_BCD_Callback */
/* upon reception of PCD_BCD_DISCOVERY_COMPLETED message. */
/* If no, the USB device is started now. */
if (USBD_LL_BatteryCharging(&hUsbDeviceFS) != USBD_OK) {
USBD_Start(&hUsbDeviceFS);
}
}
Within this function there are other functions that are called. They have variables that are being passed to them, but i dont know where they are coming from.
USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
Some have & infront of them - &hUsbDeviceFS and others just appear to be variables - DEVICE_FS
I cant figure out what these are or where they are getting their values from, so i dont understand how to implement these in flowcode. If i were to create these as variables, then i dont ever give them a value, to pass on.
Am i misunderstanding what these are?