The printf function causes code execution to hang in the USBH_UserProcess function.
Keil
A USB drive is connected to the STM32F407VGT6.
The USBH_UserProcess function is located in the FatFs library for USB drives.
I wrote this code in the USBH_UserProcess function:
uint8_t Array[1000]={0};
for(int i=0; i<1000;i++)
{
printf("%d\n", Array[i]);
}
This code is located in the USBH_UserProcess function, in the usb_host.c file.
More details, including the USBH_UserProcess function code:
case HOST_USER_CLASS_ACTIVE:
Appli_state = APPLICATION_READY;
uint8_t Array[1000]={0};
for(int i=0; i<1000;i++)
{
printf("%d\n", Array[i]);
}
break;
The USB is configured and working correctly, there are no problems with this.
The first error is that printf does not output anything to the console.
The second error is that this code freezes the execution of the code.
Four factors must coincide for such an error to occur.
1. The "Array" must be large. My Array size is 1000 bytes.
2. The "Array" must be in the USBH_UserProcess function. If you make the "Array" array global, the error disappears.
3. In the "for" loop, the increment must have a large number. I have i<1000;
4. You need to use printf("%d\n", Array[i]); in a cycle.
I need all 4 factors.
As I already wrote, the error disappears if you make the "Array" array global.
Has anyone encountered such a problem?
Fortunately, as I already wrote, I found a solution, but I’m wondering why this error occurs.
