From 4c4a719686704d8e7fac230bea271339217acc53 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 10 Nov 2026 10:56:37 +0700 Subject: [PATCH] PM5: skip the RSSI ADC re-init when the channel is unchanged EmGetCmdTimeout() calls AdcSetupRssiChannel() before every listen. On AT32 that resets the ADC, waits for ready, runs both calibration phases and a blocking 640.5 cycle vref conversion, all before Uart14aInit and before the SSC is read. The single byte SPI4 buffer overruns meanwhile, so a reader frame sent close to the minimum FDT loses its start. Hardware paced frames like the MIFARE auth nR/aR hit this; host paced activation frames do not. The Miller decoder then syncs mid frame and logs short fragments with parity errors. Keep the full setup for the first call or a channel change. Otherwise clear a stale conversion flag and restart the conversion. A dropped ADC (RDY clear) still takes the full path. RDV4 is unaffected. Reported in #3768. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + common_arm/rssi/rssi_hw_at32.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d077db09f..b1f54c767 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Fixed PM5 `hf mf sim` and other 14a sims - the RSSI ADC was reset and recalibrated before every listen, missing fast reader frames such as the auth nR/aR (@iceman1001) - Added `hf mf sam` and `hf mfdes sam` - read PACS from MIFARE Classic SE and DESFire EV1/EV2 through a HID SAM, as Seader does (@iceman1001) - Added `--dg` / `--save` to the HID SAM commands and `wiegand downgrade` - Seader style downgrades to iCLASS legacy / SR dumps, MIFARE Classic dumps and HID Prox clone commands (@iceman1001) - Changed `hf iclass sam`, `hf seos sam` - show the CSN / UID and the plaintext SIO seen during the read (@iceman1001) diff --git a/common_arm/rssi/rssi_hw_at32.c b/common_arm/rssi/rssi_hw_at32.c index 65c5c39ed..a7e6e0ce5 100644 --- a/common_arm/rssi/rssi_hw_at32.c +++ b/common_arm/rssi/rssi_hw_at32.c @@ -17,7 +17,18 @@ static void gpio_config(void) { gpio_init(AT32_GPIO_ADC_RSSI, &gpio_initstructure); } +// Channel of the last full setup, -1 = none +static int s_rssi_ch = -1; + void AdcSetupRssiChannel(adc_rssi_ch_t ch) { + // Full setup blocks for tens of us (reset, calibration, vref read), too slow + // for the 14a tag sim turnaround. Same channel and ADC still up: just restart. + if ((s_rssi_ch == (int)ch) && adc_flag_get(AT32_RSSI_ADC, ADC_RDY_FLAG)) { + adc_flag_clear(AT32_RSSI_ADC, ADC_OCCE_FLAG); // drop a stale result + AdcRssiConversionStart(); + return; + } + adc_common_config_type adc_common_struct; adc_base_config_type adc_base_struct; @@ -74,5 +85,6 @@ void AdcSetupRssiChannel(adc_rssi_ch_t ch) { } else { adc_ordinary_channel_set(AT32_RSSI_ADC, AT32_RSSI_ADC_LF_CHANNEL, 1, ADC_SAMPLETIME_640_5); } + s_rssi_ch = (int)ch; AdcRssiConversionStart(); }