STM32G474 CORDIC: Preserve the Numeric Contract Before Claiming a Speedup

Moving a trigonometric calculation to the STM32G474 CORDIC changes more than the function call. Angle units, fixed-point representation, vector magnitude, result ordering and peripheral configuration become part of the algorithm's interface. A fast answer in the wrong numeric domain is not a successful acceleration.

This discussion uses AN5325 Rev 8 and the CORDIC description in RM0440 Rev 9. It concerns the G474 implementation, not a benchmark run or a promise that every workload becomes faster.

Write down the mathematical interface before packing integers

For circular functions, AN5325 describes normalized angles: radians are divided by pi for input and normalized angle results are multiplied by pi to recover radians. The representation therefore carries a unit convention that an ordinary floating-point radians API may not share.

Make that conversion visible at the adapter boundary. Record the mathematical quantity, its accepted range, the fixed-point format, rounding policy and output conversion. Avoid allowing a variable named angle to alternate between radians and normalized units without an explicit change of representation.

Boundary handling also matters. Signed fractional formats have an asymmetric representable range; a nominal positive endpoint must not be converted through an unchecked cast. Define wrapping or clamping according to the application's angle convention and the documented function domain.

Two vectors of the same phase: coordinates 0.75 and 0.75 exceed unit modulus, while 0.5 and 0.5 remain inside; this is hypothetical geometry, not measured CORDIC output.
Original engineering concept diagram derived from the cited ST documents. No hardware test, electrical measurement or production qualification was performed.

A valid coordinate range is not a valid vector range

The application note requires a modulus within the supported range, even for a phase calculation that does not need the modulus as its final application result. It explicitly warns about a vector whose coordinates individually appear acceptable while its magnitude exceeds the engine's range.

For a hypothetical pair with both coordinates equal to 0.75, each scalar lies within the usual signed fractional interval, but the vector magnitude is approximately 1.061. A coordinate-only range check misses the relevant constraint.

Scaling both coordinates by the same positive factor preserves their mathematical phase. A pair of 0.5 and 0.5 has the same phase and a magnitude of approximately 0.707. That arithmetic suggests a normalization strategy, but the real adapter must handle its entire admitted input range, quantization and the application's zero-vector convention.

Do not independently clip each coordinate as a general replacement for common scaling. Independent clipping can change their ratio and therefore change the phase. The normalization policy belongs in the algorithm review, not only in a low-level driver test.

Distinguish interface width from achieved accuracy

AN5325 describes 16-bit and 32-bit input/output formats with a 24-bit internal CORDIC engine. A result stored in a 32-bit integer therefore does not establish 32 bits of mathematical accuracy.

Select the iteration setting and output format from the application's error requirement. Compare absolute or angular error using a suitable reference calculation over the actual domain, especially near boundaries and where downstream control is sensitive to small errors.

More iterations do not indefinitely recover precision lost to the engine or the output representation. Likewise, reducing the input precision before calling the accelerator can impose an error floor that no later conversion removes.

The acceptance criterion should state the quantity and units of error. “Matches the floating-point version” is incomplete without a tolerance and a defined set of inputs.

Preserve the configured write/read protocol

The note's cosine/sine example configures one angle write and two 32-bit result reads, with cosine read before sine. It also states that the first read waits until the result is available. Those are properties of that configured operation, not a universal one-write/one-read function interface.

Audit the configuration whenever another user can change the selected function, precision, scaling or argument/result counts. A caller must not inherit an incompatible setup left by a different computation.

The example can configure once when the parameters remain constant. If an application changes them between calls, include that configuration cost and the required ownership policy. Shared use from tasks or interrupts requires an application-level design that prevents interleaved transactions; the article does not claim a driver automatically supplies it.

Benchmark the replacement at the boundary the application sees

Measure conversion into the fixed-point domain, normalization, necessary configuration, argument writes, result reads and conversion back. If the algorithm can remain in fixed point across several stages, evaluate that separately from a one-off floating-point call replacement.

Use equivalent outputs in the comparison. A software baseline producing only one value is not the same workload as an accelerator transaction returning two useful results. Conversely, unused outputs still affect the required read protocol.

No cycle or accuracy measurements were performed here. The practical deliverable is an explicit numeric adapter and a test domain. Only after that contract is correct should cycle savings decide whether the CORDIC is the right implementation for the product.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *