usb_1.4.0 FreeRTOS static build

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

usb_1.4.0 FreeRTOS static build

642 Views
phantomgz
Contributor III

I have clone and import a project of usb_host_msd_fatfs/freerots, it's running well.

 

after that I want to use freertos work in static allocation mode. so modify FreeRTOSConfig.h with :

#define configSUPPORT_STATIC_ALLOCATION 1

and define my vApplicationGetIdleTaskMemory() , vApplicationGetTimerTaskMemory().

the project can compile well, but when download and  run on target board, it stuck in 'HardFault_Handler:'

 

after some digging, I found application will create 2 mutex, one for USB_HostInit(), the other for USB_HostKhciCreate(), all they will call USB_OsaMutexCreate(), it take memory use for mutex from s_UsbFreertosMutexStruct[USB_OSA_FREERTOS_MUTEX_COUNT], but in 'usb_osa_freertos.c'

#define USB_OSA_FREERTOS_MUTEX_COUNT (1U)

it just define 1 entry for static mutex. so I change (1U) to (2U). after that the project work.

 

another question, in 'usb_osa_freertos.c", the code for 'USB_OsaMutexCreate()"

 

usb_osa_status_t USB_OsaMutexCreate(usb_osa_mutex_handle *handle)
{
#if (defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION > 0U))
    usb_osa_sem_struct_t *mutex;
    USB_OSA_SR_ALLOC();
#endif
    if (!handle)
    {
        return kStatus_USB_OSA_Error;
    }
#if (defined(configSUPPORT_STATIC_ALLOCATION) && (configSUPPORT_STATIC_ALLOCATION > 0U))
    USB_OSA_ENTER_CRITICAL();
    for (uint32_t index = 0; index < USB_OSA_FREERTOS_MUTEX_COUNT; index++)
    {
        if (0 == s_UsbFreertosMutexStruct[index].isUsed)
        {
            mutex = &s_UsbFreertosMutexStruct[index];
            mutex->isUsed = 1U;
            break;
        }
    }
    USB_OSA_EXIT_CRITICAL();
    if (NULL == mutex)
    {
        return kStatus_USB_OSA_Error;
    }

 

if there is no free entry in 's_UsbFreertosMutexStruct' , variable 'mutex' may cause not init before access in "if(NULL == mutex)", make this compare take a mistaken result.

so I change to:

usb_osa_sem_struct_t *mutex = NULL

 

I hope this post can help for somebody want to work in same circumstances.

 

Cai.

Labels (1)
Tags (4)
0 Kudos
0 Replies