/* DEscription Range estimate code Date: 7/4/26 This includes all the critical modules radar engineers actually implement: • Radar front-end configuration • DMA ADC capture • Hardware-accelerated FFT (HWA) • CFAR detection • Range estimation • UART packet transmission This is essentially the core structure of TI’s demo firmware, simplified but fully workable. A. Project Architecture (Typical Radar Firmware) main.c radar_config.c adc_dma.c range_fft_hwa.c cfar_detection.c range_estimation.c uart_output.c radar_common.h Processing chain: RF → ADC → DMA → HWA FFT → CFAR → Range estimation → UART */ //Common Definitions //Radar_common.h #ifndef RADAR_COMMON_H #define RADAR_COMMON_H #include #include #define NUM_ADC_SAMPLES 128 #define RANGE_FFT_SIZE 256 #define SPEED_OF_LIGHT 3e8 #define BANDWIDTH 350e6 #define NUM_RX 1 #define NUM_TX 1 #define FRAME_CHIRPS 2 #define START_FREQ 57e9 #define BANDWIDTH 350e6 #define ADC_FS 12e6 #define SPEED_OF_LIGHT 3e8 typedef struct { int16_t adcBuffer[NUM_ADC_SAMPLES * 2]; float fftInput[RANGE_FFT_SIZE]; float fftOutput[RANGE_FFT_SIZE]; float magnitude[RANGE_FFT_SIZE]; } RadarBuffer; RadarBuffer radarBuf; #endif //Radar Configuration //radar_config.c #include "radar_common.h" #include "mmwave.h" void Radar_config() { rlProfileCfg_t profileCfg; profileCfg.startFreqConst = 57; profileCfg.rampEndTime = 10; profileCfg.freqSlopeConst = 35; profileCfg.numAdcSamples = 128; profileCfg.digOutSampleRate = 12000; rlChirpCfg_t chirpUp; rlChirpCfg_t chirpDown; chirpUp.startIdx = 0; chirpUp.endIdx = 0; chirpUp.profileId = 0; chirpDown.startIdx = 1; chirpDown.endIdx = 1; chirpDown.profileId = 0; chirpDown.freqSlopeVar = -35; rlFrameCfg_t frameCfg; frameCfg.chirpStartIdx = 0; frameCfg.chirpEndIdx = 1; frameCfg.numLoops = 1; } //DMA ADC Capture //Radar engineers never read ADC manually. //DMA fills buffers automatically. // adc_dma.c #include "radar_common.h" #include "edma.h" RadarBuffer radarBuf; void ADC_DMA_init() { EDMA_channelConfig_t dmaCfg; dmaCfg.srcAddr = ADC_BUFFER_ADDR; dmaCfg.destAddr = (uint32_t)&radarBuf.adcBuffer[0]; dmaCfg.aCount = NUM_ADC_SAMPLES * sizeof(float); EDMA_configChannel(EDMA_CHANNEL_0, &dmaCfg); } void ADC_startCapture() { EDMA_startTransfer(EDMA_CHANNEL_0); } //Hardware FFT Acceleration //The HWA module inside the radar chip performs FFT. //range_fft_hwa.c #include "radar_common.h" #include "hwa.h" void RangeFFT_process() { int i; for(i=0;i threshold) return i; } return -1; } //Range Estimation float Range_fromBin(int bin) { float rangeRes; rangeRes = SPEED_OF_LIGHT / (2*BANDWIDTH); return bin*rangeRes; } //UART Packet Protocol //uart_output.c #include "uart.h" void UART_sendRange(float range) { uint8_t packet[16]; packet[0]=0xAA; packet[1]=0x55; memcpy(&packet[2],&range,4); packet[6]=0x0D; packet[7]=0x0A; UART_write(packet,8); } //Main Radar Loop main.c #include "radar_common.h" int main() { int bin; float range; Radar_config(); ADC_DMA_init(); while(1) { ADC_startCapture(); RangeFFT_process(); computeMagnitude(); bin = CFAR_detect(); if(bin>0) { range = Range_fromBin(bin); UART_sendRange(range); } } }