2.9 KiB
SPI DAQ Transmission Feature
This plan outlines the changes needed to support continuous 24kHz transmission of DAQ_Packet_t variables via SPI based on the "test_data:" UART command.
User Review Required
Warning
SPI Pin Conflict with PWM: The standard SPI pin mapping configures
PA2,PA3,PA4, andPA5. However, in your applicationinit.c,PA0toPA5are mapped to Alternative Function 6 (GPIO_AF_6) as EPWM output for motor control. Please review and clarify which pins you want to use for the SPI bus. If there are alternate routing mappings or a second SPI interface (SPI1), please specify them.
Caution
Performance Constraint at 24kHz:
DAQ_Packet_tis 34-36 bytes long (depending on packing). Transmitting this much data at 24,000 times per second means pushing an SPI bandwidth of almost 7 Megabits per second (if back-to-back), plus software overhead. If standard polling is used, this could take a significant chunk of time out of the 41.6µs period. Please advise if a high SPI Baudrate or DMA is available/desired.
Proposed Changes
[MODIFY] main.c
- Add global runtime flag:
bool send_daq_enabled = false;. - Extend
cmd_parserto checkstrncmp(data, "test_data:1", 11) == 0(enable) andtest_data:0(disable). - Inside the
flag_24Khz_timerloop, populateDAQ_Packet_tstructure (using actualtimestamp,phaseduty values mapped to current/voltage,dds_amp,dds_ftw, etc.). - Send the structure bytes over SPI0 if
send_daq_enabled == true.
[MODIFY] main.h
- Provide the definition of
DAQ_Packet_t. Ensure it has#pragma pack(push, 1)behavior to preserve proper byte alignment for parsing.
[MODIFY] init.c
- Create
spi_config(void)function taking into account the relevantGPIO_AF_xmappings and highest reasonably possible.SPI_BaudRatePrescaler. - Initialize
SPI0in Master mode. - Call
spi_config()inSYS_Config().
[MODIFY] init.h
- Add function prototype for
spi_config().
Open Questions
- Which specific GPIO pins should be configured for the SPI bus mapping to avoid conflict with
EPWM? - What data exactly should be mapping into variables like
i_u,v_u,v_bus,error_valetc? Currently there arephase[0].dutyand predefined values. Should we mock these fields, leave them as0, or link them to specific placeholders? - Can we assume SPI0 in Master mode is perfectly fine for this application?
- CRC16 Implementation: Is the
crc16field generated by software or a hardware peripheral?
Verification Plan
Automated/Code Verification
- Compile code to ensure
DAQ_Packet_tstructures are safely populated and no definitions are missing.
Manual Verification
- Send
test_data:1over UART. - Measure the SPI clock and
MOSIpin using a logic analyzer to verify data is successfully bursted exactly at the 24kHz rate. - Parse the resulting values logic analyzer to ensure
DAQ_Packet_tcrc16and fields align correctly.