Application Specific Configuration
This section defines the configuration constants related to μC/USB-Device but that are application-specific. All these configuration constants relate to the RTOS. For many OSs, the μC/USB-Device task priorities and stack sizes will need to be explicitly configured for the particular OS (consult the specific OS’s documentation for more information).
These configuration constants should be defined in an application’s app_cfg.h
file.
Task Priorities
As mentioned in the Task Model section, μC/USB-Device needs one core task and one optional debug task for its proper operation. The priority of μC/USB-Device’s core task greatly depends on the USB requirements of your application. For some applications, it might be better to set it at a high priority, especially if your application requires a lot of tasks and is CPU intensive. In that case, if the core task has a low priority, it might not be able to process the bus and control requests on time. On the other hand, for some applications, you might want to give the core task a low priority, especially if you plan on using asynchronous communication and if you know you will have quite a lot of code in your callback functions.
The priority of the debug task should generally be low since it is not critical and the task performed can be executed in the background.
For the μC/OS-II and μC/OS-III RTOS ports, the following macros must be configured within app_cfg.h
:
USBD_OS_CFG_CORE_TASK_PRIO
USBD_OS_CFG_TRACE_TASK_PRIO
Note: if USBD_CFG_DBG_TRACE_EN
is set to DEF_DISABLED
, USBD_OS_CFG_TRACE_TASK_PRIO
should not be defined.
Task Stack Sizes
For the µC/OS-II and µC/OS-III RTOS ports, the following macros must be configured within app_cfg.h
to set the internal task stack sizes:
USBD_OS_CFG_CORE_TASK_STK_SIZE 1000
USBD_OS_CFG_TRACE_TASK_STK_SIZE 1000
Note: if USBD_CFG_DBG_TRACE_EN
is set to DEF_DISABLED
, USBD_OS_CFG_TRACE_TASK_STK_SIZE
should not be defined.
The arbitrary stack size of 1000 is a good starting point for most applications.
The only guaranteed method of determining the required task stack sizes is to calculate the maximum stack usage for each task. Obviously, the maximum stack usage for a task is the total stack usage along the task’s most-stack-greedy function path. Note that the most-stack-greedy function path is not necessarily the longest or deepest function path.
The easiest and best method for calculating the maximum stack usage for any task/function should be performed statically by the compiler or by a static analysis tool since these can calculate function/task maximum stack usage based on the compiler’s actual code generation and optimization settings. So for optimal task stack configuration, we recommend to invest in a task stack calculator tool compatible with your build toolchain.