feat(ch390): optimize SPI transfer, MAC fallback, and build settings for V1.0.0
- increase UART DMA/ring buffer sizes for mux traffic - switch SPI1 to Mode0 with prescaler /2 and align CubeMX settings - refactor CH390 memory read/write path with chunked SPI read and HAL bulk write - fallback to hardware MAC when configured MAC is invalid (all-zero) - add mux frame RTT logs and remove redundant UART1 polling - update Keil post-build viewer integration and include build viewer artifacts - update AT manual with all-zero MAC behavior
This commit is contained in:
@@ -60,6 +60,7 @@ extern SPI_HandleTypeDef hspi1;
|
||||
|
||||
/* Timeout for SPI operations (ms) */
|
||||
#define SPI_TIMEOUT 100
|
||||
#define CH390_SPI_CHUNK_SIZE 64u
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Low-level GPIO operations
|
||||
@@ -105,6 +106,24 @@ static uint8_t ch390_spi_exchange_byte(uint8_t byte)
|
||||
return rx_data;
|
||||
}
|
||||
|
||||
static int ch390_spi_read_bytes(uint8_t *data, uint16_t length)
|
||||
{
|
||||
static const uint8_t dummy_tx[CH390_SPI_CHUNK_SIZE] = {0};
|
||||
|
||||
while (length > 0u)
|
||||
{
|
||||
uint16_t chunk = (length > CH390_SPI_CHUNK_SIZE) ? CH390_SPI_CHUNK_SIZE : length;
|
||||
if (HAL_SPI_TransmitReceive(&hspi1, (uint8_t *)dummy_tx, data, chunk, SPI_TIMEOUT) != HAL_OK)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
data += chunk;
|
||||
length = (uint16_t)(length - chunk);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ch390_spi_apply_mode(uint32_t polarity, uint32_t phase)
|
||||
{
|
||||
hspi1.Init.CLKPolarity = polarity;
|
||||
@@ -281,16 +300,15 @@ void ch390_write_reg(uint8_t reg, uint8_t value)
|
||||
*/
|
||||
void ch390_read_mem(uint8_t *data, int length)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (data == NULL || length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ch390_cs(0); /* CS low - select */
|
||||
ch390_spi_exchange_byte(OPC_MEM_READ); /* Send memory read command */
|
||||
|
||||
/* Read data bytes */
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
data[i] = ch390_spi_dummy_read();
|
||||
}
|
||||
|
||||
(void)ch390_spi_read_bytes(data, (uint16_t)length);
|
||||
|
||||
ch390_cs(1); /* CS high - deselect */
|
||||
}
|
||||
@@ -322,16 +340,15 @@ void ch390_read_mem_dma(uint8_t *data, int length)
|
||||
*/
|
||||
void ch390_write_mem(uint8_t *data, int length)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (data == NULL || length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ch390_cs(0); /* CS low - select */
|
||||
ch390_spi_exchange_byte(OPC_MEM_WRITE); /* Send memory write command */
|
||||
|
||||
/* Write data bytes */
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
ch390_spi_exchange_byte(data[i]);
|
||||
}
|
||||
|
||||
(void)HAL_SPI_Transmit(&hspi1, data, (uint16_t)length, SPI_TIMEOUT);
|
||||
|
||||
ch390_cs(1); /* CS high - deselect */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user