Task Critical blocks USB

I am using free RTOS on STM32 hardware which I have designed. There is an STM32F103RG MCU connected to an accelerometer (MMA8415Q), gyroscope(L3G2400D) and USB. The accelerometer is ineterfaced on I2C and Gyroscope on SPI. For the accelerometer and gyroscope routines I use taskENTER_CRITICAL and taskEXIT_CRITICAL during the I2C and SPI access. At the beginning of the program I just read the accelerometer and Gyroscope device ID registers. After this I go ahead and init the USB section for using VCOM. If I read the accelerometer and Gyrocope registers, the USB is not enumerated by Windows and says Windows cannot recognise device.
If i comment out the taskENTER_CRITICAL and taskEXIT_CRITICAL from the accelerometer and Gyroscope routines then the Windows enumerated USB properly. Can anyone advise on the above problem. Thanks.. Royston

Task Critical blocks USB

You are asking about application design, not really FreeRTOS, but if the critical section is preventing interrupts that are needed to enumerate the USB then the critical section must be very very long, which is never good. If there is only one device on I2C and one device on SPI, then I doubt a critical section is needed around the whole access, and suspect it will only be needed around the access of any registers that are shared by the two serial buses. You might have better luck using scheduler locking, which will leave interrupts enabled, or making the USB interrupt above configMAX_SYSCALL_INTERRUPT_PRIORITY if it does not make any FreeRTOS API calls.

Task Critical blocks USB

Thank you davedoors for your reply. I have configured the USB priority to be above the SYSCALL priority. Please find code snippet as below. void USB_Interrupts_Config(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;   NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 14;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
} And my FreeRTOS SYSCALL priority is as follows: /* This is the raw value as per the Cortex-M3 NVIC.  Values can be 255 (lowest) to 0 (1?) (highest). */ #define configKERNEL_INTERRUPT_PRIORITY 255
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 /* equivalent to 0xa0, or priority 5. */ /* This is the value being used as per the ST library which permits 16 priority values, 0 to 15.  This must correspond to the
configKERNEL_INTERRUPT_PRIORITY setting.  Here 15 corresponds to the lowest NVIC value of 255. */ #define configLIBRARY_KERNEL_INTERRUPT_PRIORITY 15 I am a bit confused with the priority setting here. Does the FreeRTOS scheduler use priority 15 or does it use priority 5 as stated above. Thanks in advance Royston