The custom application (APP_CUSTOM) lets you run arbitrary C code inside the VESC firmware. You get full access to the motor control interface, CAN bus, ADC inputs, timers, and every other peripheral — with no overhead from an external protocol.
Template structure
The starting point is applications/app_custom_template.c. It implements the three functions that the application framework calls:
And provides a main thread plus optional callbacks:
Full template
Key concepts
Thread lifecycle
stop_now and is_running are the two flags that safely shut down the thread. app_custom_stop sets stop_now = true and then busy-waits until is_running becomes false. The thread must check stop_now on every iteration and return when it is set.
Timeout watchdog
Call timeout_reset() inside your main loop on every iteration where the system is operating normally. If timeout_reset is not called within the configured timeout window (APPCONF_TIMEOUT_MSEC, default 1000 ms), the firmware applies the brake current defined by APPCONF_TIMEOUT_BRAKE_CURRENT and stops motor output.
Forgetting timeout_reset() in your loop will cause the motor to stop after one second of running your custom application.
PWM callback
pwm_callback is invoked every control iteration at the PWM switching frequency (typically tens of kHz). Keep it very short. Do not call blocking functions or allocate memory inside it.
Motor control API
The mc_interface.h header exposes the full motor control API. Common functions:
Terminal commands
Register custom commands with terminal_register_command_callback. They appear in the VESC Tool Terminal tab and can be used for debugging and calibration during development.
Framework API
These three functions are called by the main application dispatcher whenever the configuration changes or the application is started or stopped. You must implement all three.