MCPWM Advanced Topics
Power management and sleep
With power management enabled, mcpwm_timer_enable() and mcpwm_capture_timer_enable() hold an esp_pm_lock_type_t::ESP_PM_NO_LIGHT_SLEEP lock so the timer keeps a stable clock frequency. Call mcpwm_timer_disable() or mcpwm_capture_timer_disable() to release the lock.
Both the timer config and the capture timer config carry an allow_pd field (the latter in mcpwm_capture_timer_config_t). Set it if the application permits MCPWM's power domain to power down during sleep. The driver then saves and restores registers, at the cost of extra RAM. This capability is target dependent.
ISR and task safety
Callbacks for timer, comparator, fault, operator brake, and capture run in ISR context. Keep them non-blocking and use ISR-safe RTOS calls only. The first callback registered in a group fixes its shared interrupt priority; make all later event users in that group use the same priority.
Factory functions such as mcpwm_new_timer() are thread-safe. mcpwm_timer_set_period() and mcpwm_comparator_set_compare_value() may run from ISR context. Other control APIs are not generally thread-safe; serialize them if more than one task can access the same object.
Cache-safe real-time operation
Normally, MCPWM interrupts are deferred while cache is disabled (for example during flash operations). Enable when callbacks must continue to run; this places ISR-required code in IRAM and objects in DRAM, increasing internal RAM use.
Note
With this option enabled, MCPWM interrupts still fire immediately and are not deferred even while cache is disabled. However, every function on the interrupt path — including your registered callback and all functions it calls — must live in IRAM: with cache off, the CPU cannot fetch instructions from flash, so calling any function still resident in flash crashes the CPU. The option only moves the driver's own ISR code to IRAM; you must place your callbacks and the functions they call in IRAM explicitly (for example with IRAM_ATTR).
additionally places mcpwm_timer_set_period() and mcpwm_comparator_set_compare_value() in IRAM, so those calls keep working even while cache is off — for example you can retune the PWM period or duty from a cache-disabled context, such as inside a flash-writing routine, without waiting for the cache to be re-enabled.
Kconfig options
enables cache-safe interrupts.
moves selected control functions to IRAM.
forces the MCPWM driver to compile in and print its own debug logs, ignoring the global log settings, and raises the runtime log level to verbose for the driver only — other modules are unaffected. The price is increased firmware size.