cancel
Showing results for 
Search instead for 
Did you mean: 

USB MSD on STM32C071

UweK
Associate

Hello,

I tried to program a MSD on an STM32C071. My computer "sees" the USB device but didn't recognized it as a storage device. I use the NUCLEO-C071 and have setup the following:

RCC:
High Speed Clock(HSE): Crystal/Ceramic Resonator

Clock Configuration:
Input frequency: 8
HCLK: 48
ToUSB(Mhz) HSIUSB48: 48

CubeMX USB:
Mode: Device_Only,
USB interrupt enabled

CubeMX USBX:
UXDevice memory pool size: 1024*5
USBX Device Generate Core Init code: yes
USBX Device System Stack Size: 1024*5


In CubeIDE:
main.c:

/* USER CODE BEGIN 2 */
MX_USB_PCD_Init(); // Line 94
/* USER CODE END 2 */

/* USER CODE BEGIN USB_Init 2 */
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00 , PCD_SNG_BUF, 0x20); // Line 180
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80 , PCD_SNG_BUF, 0x60);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x81 , PCD_SNG_BUF, 0xA0);
ux_dcd_stm32_initialize((ULONG)NULL, (ULONG)&hpcd_USB_DRD_FS);
HAL_PCD_Start(&hpcd_USB_DRD_FS);
/* USER CODE END USB_Init 2 */


In ux_device_msc.c

/* USER CODE BEGIN PD */
#define STORAGE_LUN_NBR 1 //Line 35
#define STORAGE_BLK_NBR 24
#define STORAGE_BLK_SIZ 0x200
/* USER CODE END PD */

/* USER CODE BEGIN PV */
uint8_t buffer[STORAGE_BLK_NBR*STORAGE_BLK_SIZ]; /Line 48
/* USER CODE END PV */

/* USER CODE BEGIN USBD_STORAGE_Read */
memcpy(buffer, &data_pointer[lba*STORAGE_BLK_SIZ], number_blocks*STORAGE_BLK_SIZ ); // Line 109

/* USER CODE BEGIN USBD_STORAGE_Write */
memcpy(&data_pointer[lba*STORAGE_BLK_SIZ], buffer, number_blocks*STORAGE_BLK_SIZ ); // Line 139

The rest is all default

I figured out that the _ux_utility_memory_allocate(UX_NO_ALIGN, ....) returns 0 for the memory in ux_device_stack_initialize.c. The memory register tells me that I used 86,43% of memory. What must I do to have a running MSD?


Edited to apply source code formatting - please see How to insert source code for future reference.

1 ACCEPTED SOLUTION

Accepted Solutions
Gyessine
ST Employee

Hello @UweK 
-Can you try to increase memory pool size to 7KB
-Also, can you try to use this configuration instead :

HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00, PCD_SNG_BUF, 0x14);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80, PCD_SNG_BUF, 0x54);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_MSC_EPOUT_ADDR, PCD_SNG_BUF, 0x94);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_MSC_EPIN_ADDR, PCD_SNG_BUF, 0xD4);

If the issue persists, can you provide more details about your problem and your project. Does the PC indicate that the device has failed enumeration, or is it not detecting the device at all?
Are you using a data cable for both the USB connector and the STLINK connector?
Are you using an STM32 Nucleo board or a custom printed circuit board?
Can you share your app_azure_rtos.c and app_usbx_device.c files?
BR
Gyessine

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Gyessine
ST Employee

Hello @UweK 
-Can you try to increase memory pool size to 7KB
-Also, can you try to use this configuration instead :

HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x00, PCD_SNG_BUF, 0x14);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, 0x80, PCD_SNG_BUF, 0x54);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_MSC_EPOUT_ADDR, PCD_SNG_BUF, 0x94);
HAL_PCDEx_PMAConfig(&hpcd_USB_DRD_FS, USBD_MSC_EPIN_ADDR, PCD_SNG_BUF, 0xD4);

If the issue persists, can you provide more details about your problem and your project. Does the PC indicate that the device has failed enumeration, or is it not detecting the device at all?
Are you using a data cable for both the USB connector and the STLINK connector?
Are you using an STM32 Nucleo board or a custom printed circuit board?
Can you share your app_azure_rtos.c and app_usbx_device.c files?
BR
Gyessine

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello Gyessine,

 I tried your HAL_PCDEx_PMAConfig but this doesn't help. The memory pool size fix the problem.

I can see the device in the device manager but not as a drive in the file manager. But this is ok because a drive require at least 64KB, better 128KB. 

I want to develop a MSD with an EEPROM as a storage device. The local RAM was just a first test.  

Thank you very much for your help

Uwe