Skip to content

Commit 107247f

Browse files
danielinuxdgarske
authored andcommitted
Fix xmodem packet number sync
1 parent 9d563ae commit 107247f

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

test-app/app_stm32h5.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern const CK_FUNCTION_LIST wolfpkcs11nsFunctionList;
4747
volatile unsigned int jiffies = 0;
4848

4949
/* Usart irq-based read function */
50-
static uint8_t uart_buf_rx[256];
50+
static uint8_t uart_buf_rx[1024];
5151
static uint32_t uart_rx_bytes = 0;
5252
static uint32_t uart_processed = 0;
5353
static int uart_rx_isr(unsigned char *c, int len);
@@ -273,6 +273,7 @@ static int cmd_update_xmodem(const char *args)
273273
uint32_t i = 0;
274274
uint8_t pkt_num_inv;
275275
uint8_t crc, calc_crc;
276+
int transfer_started = 0;
276277

277278

278279
printf("Erasing update partition...");
@@ -316,9 +317,10 @@ static int cmd_update_xmodem(const char *args)
316317
pkt_num = xpkt[1];
317318
pkt_num_inv = ~xpkt[2];
318319
if (pkt_num == pkt_num_inv) {
319-
if (pkt_num_expected == 0xFF) /* re-sync */
320+
if (!transfer_started) /* sync */ {
320321
(pkt_num_expected = pkt_num);
321-
else if (pkt_num_expected != pkt_num) {
322+
transfer_started = 1;
323+
} else if (pkt_num_expected != pkt_num) {
322324
uart_tx(XNAK);
323325
continue;
324326
}
@@ -345,6 +347,7 @@ static int cmd_update_xmodem(const char *args)
345347
pkt_num_expected++;
346348
dst_flash += XMODEM_PAYLOAD_SIZE;
347349
t_size = *((uint32_t *)(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 4));
350+
t_size += IMAGE_HEADER_SIZE;
348351
if ((uint32_t)dst_flash >= (WOLFBOOT_PARTITION_UPDATE_ADDRESS + t_size)) {
349352
ret = 0;
350353
extra_led_off();
@@ -640,7 +643,7 @@ void isr_usart3(void)
640643
usr_led_on();
641644
reg = UART3_ISR;
642645
if (reg & UART_ISR_RX_NOTEMPTY) {
643-
if (uart_rx_bytes >= 255)
646+
if (uart_rx_bytes >= 1023)
644647
reg = UART3_RDR;
645648
else
646649
uart_buf_rx[uart_rx_bytes++] = (unsigned char)(UART3_RDR & 0xFF);

0 commit comments

Comments
 (0)