atmel-samd: turn off timer clocks after both timers sharing a GCLK channel are free

未关闭
#11,778 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
56/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
c
领域
embedded-iot

调研方向

Start with timer_handler.c and inspect tc_gclk_ids[], tcc_gclk_ids[], and the timer allocation and release paths. Read the linked issue #11776 for why disabling a shared GCLK channel caused hangs. Track whether each timer pair is in use, then test the leak and partner-timer scenarios described here; done means reload no longer hangs and a partner PWMOut keeps running.

由索引模型根据 Issue 内容生成。

描述

atmel-samd enhancement

Drafted by Claude, reviewed by @dhalbert.

Background

@tannewt's atmel-samd finalizer-cleanup commit added turn_off_clocks() in timer_handler.c. PWMOut, PulseIn, PulseOut, AudioOut, RGBMatrix and PewPew called it when they released a timer. It disabled the timer's GCLK peripheral channel and its APB clock.

However, #11776 removes it, because timers share GCLK peripheral channels in pairs, and it caused a hang. Releasing one timer stopped its partner's clock:

  • A PWMOut on the partner timer stopped running.
  • Deinitializing the partner then waited forever for its software reset to sync. Boards hung at the end of the VM, with USB gone.
Timers sharing a channel
SAMD21 TCC0/TCC1, TCC2/TC3, TC4/TC5, TC6/TC7
SAMD51 TC0/TC1, TCC0/TCC1, TC2/TC3, TCC2/TCC3, TC4/TC5, TC6/TC7 (TCC4 has its own)
Proposal

Bring back turn_off_clocks(), but disable a shared GCLK peripheral channel only when neither timer in its pair is in use. The APB clock is per timer, so it can still be turned off on its own.

This needs a record of which timers are in use, for example a bitmask set when a timer is allocated and cleared in turn_off_clocks(). Each timer's peripheral channel ID from tc_gclk_ids[] and tcc_gclk_ids[] finds its partner.

How to test
  • Leak one of each pin-owning object, including PWMOut and PulseOut on both timers of a pair, then reload. The board shouldn't hang.
  • A PWMOut keeps running after an object on its partner timer is deinited.
主要语言
C
星标
4.6k
派生
1.4k
平均合并
1 天 3 小时
30 天内合并 PR
186

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

adafruit/circuitpython 的其他 Issue

查看 adafruit/circuitpython 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。