On an STM32F4 target board, I have a USB flash port that works 100% OK. By this, I mean that I am able to transfer data from an FRAM chip to the USB flash. I can do this after initializing peripheral interfaces and going through the USB flash interface to verify the device is connected, then mounted, then transfer. The transfer takes under 1 second. This is using a C program, before I initialize FreeRTOS tasks or launch the scheduler (They are essentially commented out to test this functionality)
Now, I would like to do this through FreeRTOS, after I launch the scheduler. On my board, I have a push button that I can press and detect such that, when a USB flash is inserted, the user can push and hold the button, and a transfer can be executed. In FreeRTOS, after detecting the button press in a task, I send a message into the Queue and
then call the function
USBconnected = initializeUSB();
Which returns TRUE if device is mounted successfully. It returns true, then calls the function “usbTransfer()” and begins the data transfer from RAM to flash. However - that’s as far as it goes. It never finishes, and seems to hang up. The file never gets opened but never gets finished writing and not closed. I have tried things like using vTaskSuspend on other running tasks but to no avail.
I know that the USB interfaces can be quirky, and maybe I need to do other things in FreeRTOS to use it?
Any suggestions on what might be wrong?
If I put the code (below) at the start of my program, before even creating a task, it executes and transfers the data. I think this ascertains that interrupts are not interfering with the USB function, as the same ones are kept enable from the time initializeSystem() is called.
It is something after launching the scheduler that is causing it.
main()
{
// set up I/O and enable interrupts
initializeSystem();
I am using FreeRTOS 9.0.0, and have config Assert set as this:
-#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
To be clear, if assert is called, should halting execution in the IAR debugger stop at the point that assert is stopped (looping) at?
I found that the file usb_bsp.c was set to NVIC_PriorityGroup_2, and I have changed it to NVIC_PriorityGroup_4. I am unable to get to it and test for a couple of days though. It seems likely that this might be the cause of the problems by what I have read at your link.
taskDISABLE_INTERRUPTS() will probably only disable interrupts up to and
including the priority set by configMAX_SYSCALL_INTERRUPT_PRIORITY. If
all your interrupts are at or below that value (meaning a numerically
higher value on a Cortex-M) then no code other than the infinite loop
will run. If you have interrupts above that priority then they will
continue to run, but always return back to the infinite loop.