diff options
author | Paul Selkirk <paul@psgd.org> | 2017-10-17 00:27:11 -0400 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2017-10-17 00:27:11 -0400 |
commit | 03b14b4cd4a214a92e3968ff33a13c2086896864 (patch) | |
tree | 4b391205211d55a0cba4750682784f5d1799fb44 /projects | |
parent | 5af4a915edf3e77705fa2625081200b61f8dda26 (diff) |
Overhaul UART API
MGMT is the default UART, and no one should have to explicitly refer to
the UART unless they need USER (hsm.c:hal_serial_send_char).
The default UART is now exposed in the header file, so that the
default-using functions can be macros, which saves a few bytes in code
space, and a few microseconds in function call overhead.
Diffstat (limited to 'projects')
-rw-r--r-- | projects/board-test/fmc-perf.c | 4 | ||||
-rw-r--r-- | projects/board-test/fmc-test.c | 5 | ||||
-rw-r--r-- | projects/board-test/keystore-perf.c | 21 | ||||
-rw-r--r-- | projects/board-test/rtc-test.c | 7 | ||||
-rw-r--r-- | projects/board-test/spiflash-perf.c | 25 | ||||
-rw-r--r-- | projects/bootloader/bootloader.c | 12 | ||||
-rw-r--r-- | projects/bootloader/dfu.c | 54 | ||||
-rw-r--r-- | projects/bootloader/log.c | 4 | ||||
-rw-r--r-- | projects/cli-test/cli-test.c | 1 | ||||
-rw-r--r-- | projects/cli-test/mgmt-cli.c | 7 | ||||
-rw-r--r-- | projects/cli-test/mgmt-dfu.c | 4 | ||||
-rw-r--r-- | projects/cli-test/mgmt-keystore.c | 4 | ||||
-rw-r--r-- | projects/cli-test/mgmt-masterkey.c | 8 | ||||
-rw-r--r-- | projects/cli-test/mgmt-misc.c | 8 | ||||
-rw-r--r-- | projects/cli-test/mgmt-show.c | 4 | ||||
-rw-r--r-- | projects/cli-test/test-fmc.c | 12 | ||||
-rw-r--r-- | projects/hsm/hsm.c | 1 | ||||
-rw-r--r-- | projects/hsm/log.c | 4 | ||||
-rw-r--r-- | projects/hsm/mgmt-cli.c | 6 | ||||
-rw-r--r-- | projects/hsm/mgmt-masterkey.c | 4 | ||||
-rw-r--r-- | projects/hsm/mgmt-misc.c | 8 |
21 files changed, 98 insertions, 105 deletions
diff --git a/projects/board-test/fmc-perf.c b/projects/board-test/fmc-perf.c index 5ed47ec..e87f282 100644 --- a/projects/board-test/fmc-perf.c +++ b/projects/board-test/fmc-perf.c @@ -56,11 +56,11 @@ static void _time_check(char *label, const uint32_t t0) uint32_t t = HAL_GetTick() - t0; uart_send_string(label); - uart_send_integer(t / 1000, 0); + uart_send_integer(t / 1000, 1); uart_send_char('.'); uart_send_integer(t % 1000, 3); uart_send_string(" seconds, "); - uart_send_integer(((1000 * TEST_NUM_ROUNDS) / t), 0); + uart_send_integer(((1000 * TEST_NUM_ROUNDS) / t), 1); uart_send_string("/sec\r\n"); } diff --git a/projects/board-test/fmc-test.c b/projects/board-test/fmc-test.c index ed5891a..2002f57 100644 --- a/projects/board-test/fmc-test.c +++ b/projects/board-test/fmc-test.c @@ -85,7 +85,6 @@ int main(void) int i; stm_init(); - uart_set_default(STM_UART_MGMT); uart_send_string("Keep calm for FPGA bitstream loading...\r\n"); @@ -142,9 +141,9 @@ int main(void) } uart_send_string("Success "); - uart_send_integer(successful_runs, 0); + uart_send_integer(successful_runs, 1); uart_send_string(", fail "); - uart_send_integer(failed_runs, 0); + uart_send_integer(failed_runs, 1); uart_send_string("\r\n"); if (VERBOSE) uart_send_string("\r\n"); diff --git a/projects/board-test/keystore-perf.c b/projects/board-test/keystore-perf.c index 3552d30..c2aa4fb 100644 --- a/projects/board-test/keystore-perf.c +++ b/projects/board-test/keystore-perf.c @@ -22,7 +22,7 @@ static void test_read_data(void) err = keystore_read_data(i * KEYSTORE_SUBSECTOR_SIZE, read_buf, KEYSTORE_SUBSECTOR_SIZE); if (err != HAL_OK) { uart_send_string("ERROR: keystore_read_data returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string("\r\n"); break; } @@ -42,13 +42,13 @@ static void _read_verify(uint8_t *vrfy_buf) err = keystore_read_data(i * KEYSTORE_SUBSECTOR_SIZE, read_buf, KEYSTORE_SUBSECTOR_SIZE); if (err != HAL_OK) { uart_send_string("ERROR: keystore_read_data returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string("\r\n"); break; } if (memcmp(read_buf, vrfy_buf, KEYSTORE_SUBSECTOR_SIZE) != 0) { uart_send_string("ERROR: verify failed in subsector "); - uart_send_integer(i, 0); + uart_send_integer(i, 1); uart_send_string("\r\n"); break; } @@ -67,7 +67,7 @@ static void test_erase_sector(void) err = keystore_erase_sector(i); if (err != HAL_OK) { uart_send_string("ERROR: keystore_erase_sector returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string("\r\n"); break; } @@ -86,7 +86,7 @@ static void test_erase_subsector(void) err = keystore_erase_subsector(i); if (err != HAL_OK) { uart_send_string("ERROR: keystore_erase_subsector returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string("\r\n"); break; } @@ -123,9 +123,9 @@ static void test_write_data(void) err = keystore_write_data(i * KEYSTORE_SUBSECTOR_SIZE, write_buf, KEYSTORE_SUBSECTOR_SIZE); if (err != HAL_OK) { uart_send_string("ERROR: keystore_write_data returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string(" for subsector "); - uart_send_integer(i, 0); + uart_send_integer(i, 1); uart_send_string("\r\n"); break; } @@ -151,15 +151,15 @@ static void _time_check(char *label, const uint32_t t0, uint32_t n_rounds) uint32_t t = HAL_GetTick() - t0; uart_send_string(label); - uart_send_integer(t / 1000, 0); + uart_send_integer(t / 1000, 1); uart_send_char('.'); uart_send_integer(t % 1000, 3); uart_send_string(" sec"); if (n_rounds > 1) { uart_send_string(" for "); - uart_send_integer(n_rounds, 0); + uart_send_integer(n_rounds, 1); uart_send_string(" rounds, "); - uart_send_integer(t / n_rounds, 0); + uart_send_integer(t / n_rounds, 1); uart_send_char('.'); uart_send_integer(((t % n_rounds) * 100) / n_rounds, 2); uart_send_string(" ms each"); @@ -177,7 +177,6 @@ static void _time_check(char *label, const uint32_t t0, uint32_t n_rounds) int main(void) { stm_init(); - uart_set_default(STM_UART_MGMT); if (keystore_check_id() != HAL_OK) { uart_send_string("ERROR: keystore_check_id failed\r\n"); diff --git a/projects/board-test/rtc-test.c b/projects/board-test/rtc-test.c index f1c2db1..bbb297a 100644 --- a/projects/board-test/rtc-test.c +++ b/projects/board-test/rtc-test.c @@ -94,7 +94,7 @@ void dump_sram() request_data(buf, RTC_RTC_ADDR, 0x0, RTC_SRAM_TOTAL_BYTES); uart_send_string("SRAM contents:\r\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, RTC_SRAM_TOTAL_BYTES); + uart_send_hexdump(buf, 0, RTC_SRAM_TOTAL_BYTES); uart_send_string("\r\n"); } @@ -104,12 +104,12 @@ void dump_eeprom() request_data(buf, RTC_EEPROM_ADDR, 0x0, RTC_EEPROM_TOTAL_BYTES); uart_send_string("EEPROM contents:\r\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, RTC_EEPROM_TOTAL_BYTES); + uart_send_hexdump(buf, 0, RTC_EEPROM_TOTAL_BYTES); uart_send_string("\r\n"); request_data(buf, RTC_EEPROM_ADDR, RTC_EEPROM_EUI48_OFFSET, RTC_EEPROM_EUI48_BYTES); uart_send_string("EEPROM EUI-48:\r\n"); - uart_send_hexdump(STM_UART_MGMT, buf, RTC_EEPROM_EUI48_OFFSET, RTC_EEPROM_EUI48_BYTES); + uart_send_hexdump(buf, RTC_EEPROM_EUI48_OFFSET, RTC_EEPROM_EUI48_BYTES); uart_send_string("\r\n"); } @@ -131,7 +131,6 @@ int main() { stm_init(); - uart_set_default(STM_UART_MGMT); uart_send_string("\r\n\r\n*** Init done\r\n"); dump_sram(); diff --git a/projects/board-test/spiflash-perf.c b/projects/board-test/spiflash-perf.c index 2691504..36c6131 100644 --- a/projects/board-test/spiflash-perf.c +++ b/projects/board-test/spiflash-perf.c @@ -35,7 +35,7 @@ static void test_read_page(void) err = n25q128_read_page(ctx, i, read_buf); if (err != HAL_OK) { uart_send_string("ERROR: n25q128_read_page returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string("\r\n"); break; } @@ -55,7 +55,7 @@ static void test_read_subsector(void) err = n25q128_read_subsector(ctx, i, read_buf); if (err != HAL_OK) { uart_send_string("ERROR: n25q128_read_subsector returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string("\r\n"); break; } @@ -77,13 +77,13 @@ static void _read_verify(uint8_t *vrfy_buf) err = n25q128_read_page(ctx, i, read_buf); if (err != HAL_OK) { uart_send_string("ERROR: n25q128_read_page returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string("\r\n"); break; } if (memcmp(read_buf, vrfy_buf, N25Q128_PAGE_SIZE) != 0) { uart_send_string("ERROR: verify failed in page "); - uart_send_integer(i, 0); + uart_send_integer(i, 1); uart_send_string("\r\n"); break; } @@ -102,7 +102,7 @@ static void test_erase_sector(void) err = n25q128_erase_sector(ctx, i); if (err != HAL_OK) { uart_send_string("ERROR: n25q128_erase_sector returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string("\r\n"); break; } @@ -121,7 +121,7 @@ static void test_erase_subsector(void) err = n25q128_erase_subsector(ctx, i); if (err != HAL_OK) { uart_send_string("ERROR: n25q128_erase_subsector returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string("\r\n"); break; } @@ -138,7 +138,7 @@ static void test_erase_bulk(void) err = n25q128_erase_bulk(ctx); if (err != HAL_OK) { uart_send_string("ERROR: n25q128_erase_bulk returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string("\r\n"); } } @@ -173,9 +173,9 @@ static void test_write_page(void) err = n25q128_write_page(ctx, i, write_buf); if (err != HAL_OK) { uart_send_string("ERROR: n25q128_write_page returned "); - uart_send_integer(err, 0); + uart_send_integer(err, 1); uart_send_string(" for page "); - uart_send_integer(i, 0); + uart_send_integer(i, 1); uart_send_string("\r\n"); break; } @@ -201,15 +201,15 @@ static void _time_check(char *label, const uint32_t t0, uint32_t n_rounds) uint32_t t = HAL_GetTick() - t0; uart_send_string(label); - uart_send_integer(t / 1000, 0); + uart_send_integer(t / 1000, 1); uart_send_char('.'); uart_send_integer(t % 1000, 3); uart_send_string(" sec"); if (n_rounds > 1) { uart_send_string(" for "); - uart_send_integer(n_rounds, 0); + uart_send_integer(n_rounds, 1); uart_send_string(" rounds, "); - uart_send_integer(t / n_rounds, 0); + uart_send_integer(t / n_rounds, 1); uart_send_char('.'); uart_send_integer(((t % n_rounds) * 100) / n_rounds, 2); uart_send_string(" ms each"); @@ -227,7 +227,6 @@ static void _time_check(char *label, const uint32_t t0, uint32_t n_rounds) int main(void) { stm_init(); - uart_set_default(STM_UART_MGMT); if (n25q128_check_id(ctx) != HAL_OK) { uart_send_string("ERROR: n25q128_check_id failed\r\n"); diff --git a/projects/bootloader/bootloader.c b/projects/bootloader/bootloader.c index ead87d0..c62df12 100644 --- a/projects/bootloader/bootloader.c +++ b/projects/bootloader/bootloader.c @@ -84,7 +84,7 @@ int should_dfu() for (i = 0; i < 50; i++) { HAL_Delay(100); led_toggle(LED_BLUE); - if (uart_recv_char2(STM_UART_MGMT, &rx, 0) == HAL_OK) { + if (uart_recv_char(&rx, 0) == HAL_OK) { if (rx == 13) return 1; } } @@ -100,7 +100,7 @@ int main(void) stm_init(); - uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\nThis is the bootloader speaking..."); + uart_send_string("\r\n\r\nThis is the bootloader speaking..."); if (should_dfu()) { led_off(LED_BLUE); @@ -110,9 +110,9 @@ int main(void) */ led_off(LED_BLUE); led_on(LED_RED); - uart_send_string2(STM_UART_MGMT, (char *) "dfu_receive_firmware failed: "); - uart_send_number2(STM_UART_MGMT, status, 3, 16); - uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\nRebooting in three seconds\r\n"); + uart_send_string("dfu_receive_firmware failed: "); + uart_send_hex(status, 2); + uart_send_string("\r\n\r\nRebooting in three seconds\r\n"); HAL_Delay(3000); HAL_NVIC_SystemReset(); while (1) {}; @@ -124,7 +124,7 @@ int main(void) */ *dfu_control = HARDWARE_EARLY_DFU_JUMP; - uart_send_string2(STM_UART_MGMT, (char *) "loading firmware\r\n\r\n"); + uart_send_string("loading firmware\r\n\r\n"); /* De-initialize hardware by rebooting */ HAL_NVIC_SystemReset(); diff --git a/projects/bootloader/dfu.c b/projects/bootloader/dfu.c index a0ff372..83aef20 100644 --- a/projects/bootloader/dfu.c +++ b/projects/bootloader/dfu.c @@ -53,7 +53,7 @@ static int getline(char *buf, int len) uint8_t c; for (i = 0; i < len; ++i) { - if (uart_recv_char2(STM_UART_MGMT, &c, HAL_MAX_DELAY) != CMSIS_HAL_OK) + if (uart_recv_char(&c, HAL_MAX_DELAY) != CMSIS_HAL_OK) return -1; if (c == '\r') { buf[i] = '\0'; @@ -67,7 +67,7 @@ static int getline(char *buf, int len) static void uart_flush(void) { uint8_t c; - while (uart_recv_char2(STM_UART_MGMT, &c, 0) == CMSIS_HAL_OK) { ; } + while (uart_recv_char(&c, 0) == CMSIS_HAL_OK) { ; } } static int do_login(void) @@ -79,7 +79,7 @@ static int do_login(void) int n; uart_flush(); - uart_send_string2(STM_UART_MGMT, "\r\nUsername: "); + uart_send_string("\r\nUsername: "); if (getline(username, sizeof(username)) <= 0) return -1; if (strcmp(username, "wheel") == 0) @@ -92,7 +92,7 @@ static int do_login(void) user = HAL_USER_NONE; uart_flush(); - uart_send_string2(STM_UART_MGMT, "\r\nPassword: "); + uart_send_string("\r\nPassword: "); if ((n = getline(pin, sizeof(pin))) <= 0) return -1; @@ -101,7 +101,7 @@ static int do_login(void) hal_ks_init_read_only_pins_only(); if (hal_rpc_login(client, user, pin, n) != LIBHAL_OK) { - uart_send_string2(STM_UART_MGMT, "\r\nAccess denied\r\n"); + uart_send_string("\r\nAccess denied\r\n"); return -1; } return 0; @@ -118,33 +118,33 @@ int dfu_receive_firmware(void) return -1; /* Fake the CLI */ - uart_send_string2(STM_UART_MGMT, "\r\ncryptech> "); + uart_send_string("\r\ncryptech> "); char cmd[64]; if (getline(cmd, sizeof(cmd)) <= 0) return -1; if (strcmp(cmd, "firmware upload") != 0) { - uart_send_string2(STM_UART_MGMT, "\r\nInvalid command \""); - uart_send_string2(STM_UART_MGMT, cmd); - uart_send_string2(STM_UART_MGMT, "\"\r\n"); + uart_send_string("\r\nInvalid command \""); + uart_send_string(cmd); + uart_send_string("\"\r\n"); return -1; } - uart_send_string2(STM_UART_MGMT, "OK, write size (4 bytes), data in 4096 byte chunks, CRC-32 (4 bytes)\r\n"); + uart_send_string("OK, write size (4 bytes), data in 4096 byte chunks, CRC-32 (4 bytes)\r\n"); /* Read file size (4 bytes) */ - uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, sizeof(filesize), 10000); + uart_receive_bytes((void *) &filesize, sizeof(filesize), 10000); if (filesize < 512 || filesize > DFU_FIRMWARE_END_ADDR - DFU_FIRMWARE_ADDR) { - uart_send_string2(STM_UART_MGMT, "Invalid filesize "); - uart_send_number2(STM_UART_MGMT, filesize, 1, 10); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string("Invalid filesize "); + uart_send_integer(filesize, 1); + uart_send_string("\r\n"); return -1; } HAL_FLASH_Unlock(); - uart_send_string2(STM_UART_MGMT, "Send "); - uart_send_number2(STM_UART_MGMT, filesize, 1, 10); - uart_send_string2(STM_UART_MGMT, " bytes of data\r\n"); + uart_send_string("Send "); + uart_send_integer(filesize, 1); + uart_send_string(" bytes of data\r\n"); while (filesize) { /* By initializing buf to the same value that erased flash has (0xff), we don't @@ -156,7 +156,7 @@ int dfu_receive_firmware(void) n = filesize; } - if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 10000) != CMSIS_HAL_OK) { + if (uart_receive_bytes((void *) buf, n, 10000) != CMSIS_HAL_OK) { return -2; } filesize -= n; @@ -170,7 +170,7 @@ int dfu_receive_firmware(void) /* ACK this chunk by sending the current chunk counter (4 bytes) */ counter++; - uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4); + uart_send_bytes((void *) &counter, 4); led_toggle(LED_BLUE); } @@ -178,20 +178,20 @@ int dfu_receive_firmware(void) HAL_FLASH_Lock(); - uart_send_string2(STM_UART_MGMT, "Send CRC-32\r\n"); + uart_send_string("Send CRC-32\r\n"); /* The sending side will now send its calculated CRC-32 */ - uart_receive_bytes(STM_UART_MGMT, (void *) &crc, sizeof(crc), 10000); + uart_receive_bytes((void *) &crc, sizeof(crc), 10000); - uart_send_string2(STM_UART_MGMT, "CRC-32 0x"); - uart_send_number2(STM_UART_MGMT, crc, 1, 16); - uart_send_string2(STM_UART_MGMT, ", calculated CRC 0x"); - uart_send_number2(STM_UART_MGMT, my_crc, 1, 16); + uart_send_string("CRC-32 0x"); + uart_send_hex(crc, 1); + uart_send_string(", calculated CRC 0x"); + uart_send_hex(my_crc, 1); if (crc == my_crc) { - uart_send_string2(STM_UART_MGMT, "CRC checksum MATCHED\r\n"); + uart_send_string("CRC checksum MATCHED\r\n"); return 0; } else { - uart_send_string2(STM_UART_MGMT, "CRC checksum did NOT match\r\n"); + uart_send_string("CRC checksum did NOT match\r\n"); } led_on(LED_RED); diff --git a/projects/bootloader/log.c b/projects/bootloader/log.c index c0d9df4..fbc0e73 100644 --- a/projects/bootloader/log.c +++ b/projects/bootloader/log.c @@ -63,6 +63,6 @@ void hal_log(const hal_log_level_t level, const char *format, ...) vsnprintf(buffer, sizeof(buffer), format, ap); va_end(ap); - uart_send_string2(STM_UART_MGMT, buffer); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string(buffer); + uart_send_string("\r\n"); } diff --git a/projects/cli-test/cli-test.c b/projects/cli-test/cli-test.c index c288257..82946fa 100644 --- a/projects/cli-test/cli-test.c +++ b/projects/cli-test/cli-test.c @@ -57,7 +57,6 @@ int main() { stm_init(); - uart_set_default(STM_UART_MGMT); led_on(LED_GREEN); diff --git a/projects/cli-test/mgmt-cli.c b/projects/cli-test/mgmt-cli.c index 6910c4d..d7f7383 100644 --- a/projects/cli-test/mgmt-cli.c +++ b/projects/cli-test/mgmt-cli.c @@ -104,9 +104,8 @@ void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart) static void uart_cli_print(struct cli_def *cli __attribute__ ((unused)), const char *buf) { - char crlf[] = "\r\n"; - uart_send_string2(STM_UART_MGMT, buf); - uart_send_string2(STM_UART_MGMT, crlf); + uart_send_string(buf); + uart_send_string("\r\n"); } static ssize_t uart_cli_read(struct cli_def *cli __attribute__ ((unused)), void *buf, size_t count) @@ -120,7 +119,7 @@ static ssize_t uart_cli_read(struct cli_def *cli __attribute__ ((unused)), void static ssize_t uart_cli_write(struct cli_def *cli __attribute__ ((unused)), const void *buf, size_t count) { - uart_send_bytes(STM_UART_MGMT, (uint8_t *) buf, count); + uart_send_bytes((uint8_t *) buf, count); return (ssize_t)count; } diff --git a/projects/cli-test/mgmt-dfu.c b/projects/cli-test/mgmt-dfu.c index 7b78d38..c7273f4 100644 --- a/projects/cli-test/mgmt-dfu.c +++ b/projects/cli-test/mgmt-dfu.c @@ -64,8 +64,8 @@ static int cmd_dfu_dump(struct cli_def *cli, const char *command, char *argv[], cli_print(cli, "First 256 bytes from DFU application address %p:\r\n", dfu_firmware); - uart_send_hexdump(STM_UART_MGMT, (uint8_t *) dfu_firmware, 0, 0xff); - uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\n"); + uart_send_hexdump((uint8_t *) dfu_firmware, 0, 0xff); + cli_print(cli, "\n"); return CLI_OK; } diff --git a/projects/cli-test/mgmt-keystore.c b/projects/cli-test/mgmt-keystore.c index 8c16f35..6d0d38d 100644 --- a/projects/cli-test/mgmt-keystore.c +++ b/projects/cli-test/mgmt-keystore.c @@ -239,8 +239,8 @@ static int cmd_keystore_show_data(struct cli_def *cli, const char *command, char } cli_print(cli, "First page from keystore memory:\r\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); - uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\n"); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); + cli_print(cli, "\n"); return CLI_OK; } diff --git a/projects/cli-test/mgmt-masterkey.c b/projects/cli-test/mgmt-masterkey.c index 0f6e352..811e15b 100644 --- a/projects/cli-test/mgmt-masterkey.c +++ b/projects/cli-test/mgmt-masterkey.c @@ -102,7 +102,7 @@ static int cmd_masterkey_status(struct cli_def *cli, const char *command, char * status = hal_mkm_volatile_read(&buf[0], sizeof(buf)); if (status == LIBHAL_OK || status == HAL_ERROR_MASTERKEY_NOT_SET) { cli_print(cli, "\nVolatile read-out:\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); cli_print(cli, "\n"); } else { cli_print(cli, "Failed reading from volatile memory: %s", hal_error_string(status)); @@ -111,7 +111,7 @@ static int cmd_masterkey_status(struct cli_def *cli, const char *command, char * status = hal_mkm_flash_read(&buf[0], sizeof(buf)); if (status == LIBHAL_OK || status == HAL_ERROR_MASTERKEY_NOT_SET) { cli_print(cli, "\nFlash read-out:\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); cli_print(cli, "\n"); } else { cli_print(cli, "Failed reading from flash: %s", hal_error_string(status)); @@ -134,7 +134,7 @@ static int cmd_masterkey_set(struct cli_def *cli, const char *command, char *arg } cli_print(cli, "Parsed key:\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); cli_print(cli, "\n"); if ((err = hal_mkm_volatile_write(buf, sizeof(buf))) == LIBHAL_OK) { @@ -175,7 +175,7 @@ static int cmd_masterkey_unsecure_set(struct cli_def *cli, const char *command, } cli_print(cli, "Parsed key:\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); cli_print(cli, "\n"); if ((err = hal_mkm_flash_write(buf, sizeof(buf))) == LIBHAL_OK) { diff --git a/projects/cli-test/mgmt-misc.c b/projects/cli-test/mgmt-misc.c index 1216bd5..db8dbd2 100644 --- a/projects/cli-test/mgmt-misc.c +++ b/projects/cli-test/mgmt-misc.c @@ -67,7 +67,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal cli_print(cli, "OK, write size (4 bytes), data in %li byte chunks, CRC-32 (4 bytes)", (uint32_t) n); - if (uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, sizeof(filesize), 1000) != CMSIS_HAL_OK) { + if (uart_receive_bytes((void *) &filesize, sizeof(filesize), 1000) != CMSIS_HAL_OK) { cli_print(cli, "Receive timed out"); goto fail; } @@ -82,7 +82,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal if (filesize < n) n = filesize; - if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 1000) != CMSIS_HAL_OK) { + if (uart_receive_bytes((void *) buf, n, 1000) != CMSIS_HAL_OK) { cli_print(cli, "Receive timed out"); goto fail; } @@ -98,12 +98,12 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal } counter++; - uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4); + uart_send_bytes((void *) &counter, 4); } my_crc = hal_crc32_finalize(my_crc); cli_print(cli, "Send CRC-32"); - uart_receive_bytes(STM_UART_MGMT, (void *) &crc, sizeof(crc), 1000); + uart_receive_bytes((void *) &crc, sizeof(crc), 1000); cli_print(cli, "CRC-32 0x%x, calculated CRC 0x%x", (unsigned int) crc, (unsigned int) my_crc); if (crc == my_crc) { cli_print(cli, "CRC checksum MATCHED"); diff --git a/projects/cli-test/mgmt-show.c b/projects/cli-test/mgmt-show.c index e276b15..4338dcd 100644 --- a/projects/cli-test/mgmt-show.c +++ b/projects/cli-test/mgmt-show.c @@ -130,8 +130,8 @@ static int cmd_show_keystore_data(struct cli_def *cli, const char *command, char } cli_print(cli, "First page from keystore memory:\r\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); - uart_send_string2(STM_UART_MGMT, (char *) "\r\n\r\n"); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); + cli_print(cli, "\n"); for (i = 0; i < 8; i++) { if (buf[i] == 0xff) break; /* never written */ diff --git a/projects/cli-test/test-fmc.c b/projects/cli-test/test-fmc.c index a1d6eea..87f80ce 100644 --- a/projects/cli-test/test-fmc.c +++ b/projects/cli-test/test-fmc.c @@ -121,9 +121,9 @@ int test_fpga_data_bus(struct cli_def *cli, uint32_t test_rounds) data_diff = buf ^ rnd; if (data_diff) { cli_print(cli, "Data bus FAIL: expected %lx got %lx", rnd, buf); - uart_send_string2(STM_UART_MGMT, (char *) "Binary diff: "); - uart_send_number2(STM_UART_MGMT, data_diff, 32, 2); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string((char *) "Binary diff: "); + uart_send_binary(data_diff, 32); + uart_send_string("\r\n"); break; } @@ -192,9 +192,9 @@ int test_fpga_address_bus(struct cli_def *cli, uint32_t test_rounds) addr_diff = buf ^ addr; if (addr_diff) { cli_print(cli, "Address bus FAIL: expected 0x%lx got 0x%lx", addr, buf); - uart_send_string2(STM_UART_MGMT, (char *) "Binary diff: "); - uart_send_number2(STM_UART_MGMT, addr_diff, 32, 2); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string((char *) "Binary diff: "); + uart_send_binary(addr_diff, 32); + uart_send_string("\r\n"); break; } diff --git a/projects/hsm/hsm.c b/projects/hsm/hsm.c index a36c64b..7fc7410 100644 --- a/projects/hsm/hsm.c +++ b/projects/hsm/hsm.c @@ -409,7 +409,6 @@ void hal_sleep(const unsigned seconds) { task_delay(seconds * 1000); } int main(void) { stm_init(); - uart_set_default(STM_UART_MGMT); led_on(LED_GREEN); if (hal_rpc_server_init() != LIBHAL_OK) diff --git a/projects/hsm/log.c b/projects/hsm/log.c index c0d9df4..fbc0e73 100644 --- a/projects/hsm/log.c +++ b/projects/hsm/log.c @@ -63,6 +63,6 @@ void hal_log(const hal_log_level_t level, const char *format, ...) vsnprintf(buffer, sizeof(buffer), format, ap); va_end(ap); - uart_send_string2(STM_UART_MGMT, buffer); - uart_send_string2(STM_UART_MGMT, "\r\n"); + uart_send_string(buffer); + uart_send_string("\r\n"); } diff --git a/projects/hsm/mgmt-cli.c b/projects/hsm/mgmt-cli.c index 23a0a40..2b5be1f 100644 --- a/projects/hsm/mgmt-cli.c +++ b/projects/hsm/mgmt-cli.c @@ -112,8 +112,8 @@ void HAL_UART1_RxCpltCallback(UART_HandleTypeDef *huart) static void uart_cli_print(struct cli_def *cli __attribute__ ((unused)), const char *buf) { char crlf[] = "\r\n"; - uart_send_string2(STM_UART_MGMT, buf); - uart_send_string2(STM_UART_MGMT, crlf); + uart_send_string(buf); + uart_send_string(crlf); } static ssize_t uart_cli_read(struct cli_def *cli __attribute__ ((unused)), void *buf, size_t count) @@ -127,7 +127,7 @@ static ssize_t uart_cli_read(struct cli_def *cli __attribute__ ((unused)), void static ssize_t uart_cli_write(struct cli_def *cli __attribute__ ((unused)), const void *buf, size_t count) { - uart_send_bytes(STM_UART_MGMT, (uint8_t *) buf, count); + uart_send_bytes((uint8_t *) buf, count); return (ssize_t)count; } diff --git a/projects/hsm/mgmt-masterkey.c b/projects/hsm/mgmt-masterkey.c index 8675637..765cb10 100644 --- a/projects/hsm/mgmt-masterkey.c +++ b/projects/hsm/mgmt-masterkey.c @@ -111,7 +111,7 @@ static int _masterkey_set(struct cli_def *cli, char *argv[], int argc, return CLI_ERROR; } cli_print(cli, "Random key:\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); cli_print(cli, "\n"); } @@ -122,7 +122,7 @@ static int _masterkey_set(struct cli_def *cli, char *argv[], int argc, } cli_print(cli, "Parsed key:\n"); - uart_send_hexdump(STM_UART_MGMT, buf, 0, sizeof(buf) - 1); + uart_send_hexdump(buf, 0, sizeof(buf) - 1); cli_print(cli, "\n"); } diff --git a/projects/hsm/mgmt-misc.c b/projects/hsm/mgmt-misc.c index 65da7ff..b06003f 100644 --- a/projects/hsm/mgmt-misc.c +++ b/projects/hsm/mgmt-misc.c @@ -60,7 +60,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal cli_print(cli, "OK, write size (4 bytes), data in %li byte chunks, CRC-32 (4 bytes)", (uint32_t) n); - if (uart_receive_bytes(STM_UART_MGMT, (void *) &filesize, sizeof(filesize), 2000) != CMSIS_HAL_OK) { + if (uart_receive_bytes((void *) &filesize, sizeof(filesize), 2000) != CMSIS_HAL_OK) { cli_print(cli, "Receive timed out"); goto fail; } @@ -75,7 +75,7 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal if (filesize < n) n = filesize; - if (uart_receive_bytes(STM_UART_MGMT, (void *) buf, n, 2000) != CMSIS_HAL_OK) { + if (uart_receive_bytes((void *) buf, n, 2000) != CMSIS_HAL_OK) { cli_print(cli, "Receive timed out"); goto fail; } @@ -91,12 +91,12 @@ int cli_receive_data(struct cli_def *cli, uint8_t *buf, size_t len, cli_data_cal } counter++; - uart_send_bytes(STM_UART_MGMT, (void *) &counter, 4); + uart_send_bytes((void *) &counter, 4); } my_crc = hal_crc32_finalize(my_crc); cli_print(cli, "Send CRC-32"); - uart_receive_bytes(STM_UART_MGMT, (void *) &crc, sizeof(crc), 2000); + uart_receive_bytes((void *) &crc, sizeof(crc), 2000); cli_print(cli, "CRC-32 0x%x, calculated CRC 0x%x", (unsigned int) crc, (unsigned int) my_crc); if (crc == my_crc) { cli_print(cli, "CRC checksum MATCHED"); |