From 4c9be69148f9e66a3f4f08a15e4fea38565a19c2 Mon Sep 17 00:00:00 2001 From: Christian Herrmann Date: Mon, 9 Nov 2026 10:28:17 +0700 Subject: [PATCH] PM5: zero-init TMR2 input config in StartCountSspClk StartCountSspClk() declared its tmr_input_config_type on the stack without initialising it and never set input_filter_value. tmr_input_channel_init() copies that field into TMR2 CM1.C2DF, so the digital input filter on the ssp_clk pin took whatever low nibble was left on the stack, and could change from call to call depending on the caller's stack contents. TMR2 is clocked by that filtered input (C2DF2, external clock mode A), so the filter decides which ssp_clk edges get counted. With fDTS at 288 MHz, filter values around 13 need ~556 ns of stable input against a ~590 ns ssp_clk half period (fc/16 in 14a reader modes). Edges are then dropped some of the time, and 14-15 drop every edge. In sniffer mode (fc/8) values from about 10 already break. Lost ticks delay frame timing derived from GetCountSspClk() (ReaderTransmit timing, sync_time loops) by a varying amount. This shows up as random nonce distance jitter and slow distance calibration in hf mf nested/autopwn on PM5. Zero-initialise the struct so the filter is off (C2DF = 0), matching StartLoEdgeCapture() in the same file. Reported by @adrian-stepien in #3709. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + common_arm/ticks/ticks_hw_at32.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64e75ac5d..46f29a968 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac ## [unreleased][unreleased] - Fixed `lf em 4x50 rdbl/info/dump`, `lf search` - RM was sent into the tag data instead of the second listen window on strong, AC-coupled signals, so every command failed; reads now retry within 1 s (@abou28) +- Fixed PM5 ssp_clk counter - uninitialised TMR2 input filter could drop edges, skewing ISO14443-A timing and `hf mf nested` (@adrian-stepien) - Changed `lf cotag sim` - add and default to passive mode, improve field drop and activation sequence detection (@towelbyte) - Fixed `lf noralsy clone` and `sim` - CN above 9999999 and years outside 1961-2060 are refused instead of cut (@matrix) - Fixed `trace list` - Topaz commands end at the frames their code takes, ISO14443-A frames in Topaz traces and ISO15693 frames in iCLASS traces get their own CRC, five byte ISO14443-A answers and FeliCa frames get a real CRC check, frames of 256 bytes and more are checked and annotated whole (@matrix) diff --git a/common_arm/ticks/ticks_hw_at32.c b/common_arm/ticks/ticks_hw_at32.c index 6275b4157..79b02e233 100644 --- a/common_arm/ticks/ticks_hw_at32.c +++ b/common_arm/ticks/ticks_hw_at32.c @@ -180,7 +180,7 @@ void StartCountSspClk(void) { gpio_pin_mux_config(CRM_GPIO_COUNT_SSP_CLK, CRM_GPIO_COUNT_SSP_CLK_SOURCE, CRM_GPIO_COUNT_SSP_CLK_MUX); // important !!! remap gpio to be timer EXT(CHx) function. // timer init - tmr_input_config_type tmr_input_config_struct; + tmr_input_config_type tmr_input_config_struct = {0}; tmr_input_config_struct.input_channel_select = AT32_TMR_COUNT_SSP_CLK_IN_CH; tmr_input_config_struct.input_mapped_select = TMR_CC_CHANNEL_MAPPED_DIRECT; tmr_input_config_struct.input_polarity_select = TMR_INPUT_RISING_EDGE;