Conversation
$clog2(TIMER_CNT) is 0 when TIMER_CNT == 1, which made slave_address_int's declared range [-1:0] (an inverted, 2-bit-wide range instead of the intended 0-width) and the PADDR part-select driving it an inverted [x:x+1] range -- both illegal on a descending-declared vector, matching the reporter's "part-select ... does not match declaration" symptom. Add a SLAVE_ADDR_BITS localparam that special-cases TIMER_CNT == 1 to a constant-zero, 1-bit slave_address_int instead of computing a negative width from $clog2(1). There is only one timer in that configuration, so no address bits are needed to select among timers. The TIMER_CNT > 1 path is untouched, just moved into its own generate branch alongside the new single-timer branch. Fixes pulp-platform#7
…form#7) Two tests against the sole timer instance in a TIMER_CNT=1 build, driven over its APB interface (Verilator, cocotb classic Makefile flow): - test_single_timer_builds_and_counts: enables the timer and confirms its count register actually advances, proving the TIMER_CNT==1 address-select path reaches the instance (not just that it elaborates). - test_single_timer_compare_register: writes and reads back REG_CMP through the same path, as a second, independent register. Against the unmodified RTL this fails to even build (the SELRANGE lint error from pulp-platform#7); against the fix in the parent commit both tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7.
Bug
apb_timerfails to elaborate whenTIMER_CNTis set to1.$clog2(TIMER_CNT)is0in that case, which makesslave_address_int's declared range[$clog2(TIMER_CNT)-1:0]evaluate to[-1:0]-- an inverted, 2-bit-wide range instead of the intended 0-width -- and thePADDRpart-select driving it an inverted[3:4]slice (relative toPADDR's own descending[APB_ADDR_WIDTH-1:0]declaration). This matches the "part-select ... does not match declaration" error from the original report (VivadoSynth 8-523); reproduced here with Verilator:Fix
Adds a
SLAVE_ADDR_BITSlocalparam that special-casesTIMER_CNT == 1to a constant-zero, 1-bitslave_address_int, instead of computing a negative width from$clog2(1). With only one timer, no address bits are needed to select among timers, so this sidesteps the edge case entirely rather than working around its symptom. TheTIMER_CNT > 1path is unchanged -- it's the same expression as before, just moved into its own generate branch (gen_slave_address_multi) alongside the new single-timer branch (gen_slave_address_single).Verified
TIMER_CNT=2andTIMER_CNT=4are unaffected (re-linted before and after this change).Test
Added a cocotb regression test (
verify/, Verilator) that buildsapb_timerwithTIMER_CNT=1and drives the one timer instance over its APB interface: enabling it and confirming the count register advances, and a separate write/read-back check onREG_CMP. Both fail to build against the unmodified RTL (theSELRANGEerror above) and pass against this fix.