diff options
-rw-r--r-- | projects/cli-test/cli-test.c | 8 | ||||
-rwxr-xr-x | projects/cli-test/filetransfer | 21 | ||||
-rw-r--r-- | stm-init.c | 4 |
3 files changed, 25 insertions, 8 deletions
diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c index 86e11ce..6102d32 100644 --- a/projects/cli-test/cli-test.c +++ b/projects/cli-test/cli-test.c @@ -62,20 +62,24 @@ int cmd_filetransfer(struct cli_def *cli, const char *command, char *argv[], int cli_print(cli, "OK, write file size (4 bytes), data in 4096 byte chunks, CRC-32 (4 bytes)"); uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, 4, 1000); - cli_print(cli, "Filesize %li", filesize); + cli_print(cli, "File size %li", filesize); while (filesize) { if (filesize < n) { n = filesize; } - uart_receive_bytes(STM_UART_MGMT, (void *) &buf, n, 1000); + if (uart_receive_bytes(STM_UART_MGMT, (void *) &buf, n, 1000) != HAL_OK) { + cli_print(cli, "Receive timed out"); + return CLI_ERROR; + } filesize -= n; my_crc = update_crc(my_crc, buf, n); counter++; uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4); } + cli_print(cli, "Send CRC-32"); uart_receive_bytes(STM_UART_MGMT, (void *) &crc, 4, 1000); cli_print(cli, "CRC-32 %li", crc); if (crc == my_crc) { diff --git a/projects/cli-test/filetransfer b/projects/cli-test/filetransfer index 3e8e043..674a7f1 100755 --- a/projects/cli-test/filetransfer +++ b/projects/cli-test/filetransfer @@ -51,7 +51,7 @@ def send_file(filename, device='/dev/ttyUSB0', initiate=True): size = s.st_size src = open(filename, 'rb') - dst = serial.Serial(device, 921600, timeout=1) + dst = serial.Serial(device, 921600, timeout=0.1) if initiate: response = _execute(dst, 'filetransfer') @@ -71,12 +71,25 @@ def send_file(filename, device='/dev/ttyUSB0', initiate=True): break dst.write(data) print("Wrote {!s} bytes".format(len(data))) - crc = crc32(data, crc) & 0xffffffff - new_counter = struct.unpack('<I', dst.read(4))[0] + # read ACK (a counter of number of 4k chunks received) + while True: + ack = dst.read(4) + if len(ack) == 4: + break + print('ERROR: Did not receive an ACK, got {!r}'.format(ack)) + dst.write('\r') + new_counter = struct.unpack('<I', ack)[0] if new_counter != counter + 1: - print('ERROR: Did not receive the expected counter as ACK (got {!r}, not {!r})'.format(new_counter, counter)) + print('ERROR: Did not receive the expected counter as ACK (got {!r}/{!r}, not {!r})'.format(new_counter, ack, counter)) + flush = dst.read(100) + print('FLUSH data: {!r}'.format(flush)) return False counter += 1 + + crc = crc32(data, crc) & 0xffffffff + + _read(dst) + # 3. Write CRC-32 (4 bytes) _write(dst, struct.pack('<I', crc)) _read(dst) @@ -105,7 +105,7 @@ static void MX_USART1_UART_Init(void) huart_mgmt.Init.StopBits = UART_STOPBITS_1; huart_mgmt.Init.Parity = UART_PARITY_NONE; huart_mgmt.Init.Mode = UART_MODE_TX_RX; - huart_mgmt.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS; //UART_HWCONTROL_NONE; + huart_mgmt.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS; huart_mgmt.Init.OverSampling = UART_OVERSAMPLING_16; if (HAL_UART_Init(&huart_mgmt) != HAL_OK) { @@ -122,7 +122,7 @@ static void MX_USART2_UART_Init(void) huart_user.Init.StopBits = UART_STOPBITS_1; huart_user.Init.Parity = UART_PARITY_NONE; huart_user.Init.Mode = UART_MODE_TX_RX; - huart_user.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart_user.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS; huart_user.Init.OverSampling = UART_OVERSAMPLING_16; if (HAL_UART_Init(&huart_user) != HAL_OK) { |