From 121802cc1b1e1d86cd961a3b4aa3e4b9729b246d Mon Sep 17 00:00:00 2001 From: Michael Ossmann Date: Tue, 23 Jul 2024 08:40:17 -0400 Subject: [PATCH 1/3] firmware: Use fwup-util instead of dfu-util --- firmware/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/Makefile b/firmware/Makefile index ec86620..e9926b2 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -95,7 +95,7 @@ BUILD := _build # Flashing using Saturn-V. dfu: _build/$(BOARD)/firmware.bin - dfu-util -a 0 -d 1d50:615c -D $< || dfu-util -a 0 -d 1209:0010 -D $< + fwup-util --device 1d50:615c $< || fwup-util --device 1209:0010 $< # Flashing using the Black Magic Probe, From 91e1d36de6ef4fa312a1263ab8975f14047909d8 Mon Sep 17 00:00:00 2001 From: Michael Ossmann Date: Tue, 23 Jul 2024 09:16:27 -0400 Subject: [PATCH 2/3] firmware: Extend Cynthion r1.4 detection voltage This broadens the Cynthion r1.4 hardware revision detection voltage range by 0.5%. Ranges for future hardware revisions will be separated by a 1% guard band. For example, while r1.4 uses the range 21-22%, r1.5 will use 18-19% instead of the previously anticipated 19-20%. --- firmware/src/boards/cynthion_d11/board_rev.c | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/firmware/src/boards/cynthion_d11/board_rev.c b/firmware/src/boards/cynthion_d11/board_rev.c index f4d1b9f..5fcc69e 100644 --- a/firmware/src/boards/cynthion_d11/board_rev.c +++ b/firmware/src/boards/cynthion_d11/board_rev.c @@ -52,10 +52,10 @@ void detect_hardware_revision(void) while (!hri_adc_get_interrupt_RESRDY_bit(ADC)); uint16_t reading = hri_adc_read_RESULT_reg(ADC); - // Convert ADC measurement to a percentage of the reference voltage. - uint32_t percentage = (((uint32_t)reading * 100) + 2048) >> 12; - if (percentage > 51) { - percentage = 100 - percentage; + // Convert ADC measurement to per mille of the reference voltage. + uint32_t permille = (((uint32_t)reading * 1000) + 20480) >> 12; + if (permille > 510) { + permille = 1000 - permille; gsg_production = true; } @@ -63,7 +63,7 @@ void detect_hardware_revision(void) hardware version | percent of +3V3 ___________________________________________ 0.6 | 0-1 - future versions | 2-20 + future versions | 2-19 1.4 | 21-22 1.3 | 23-24 1.2 | 25-26 @@ -79,21 +79,21 @@ void detect_hardware_revision(void) // Identify the board revision by comparing against expected thresholds. struct { uint16_t version; - uint8_t threshold; + uint16_t threshold; } revisions[] = { - { CYNTHION_REV_0_6, 1 }, - { CYNTHION_REV_UNKNOWN, 20 }, - { CYNTHION_REV_1_4, 22 }, - { CYNTHION_REV_1_3, 24 }, - { CYNTHION_REV_1_2, 26 }, - { CYNTHION_REV_1_0, 28 }, - { CYNTHION_REV_1_1, 31 }, - { CYNTHION_REV_UNKNOWN, 48 }, - { CYNTHION_REV_0_7, 51 }, + { CYNTHION_REV_0_6, 10 }, + { CYNTHION_REV_UNKNOWN, 195 }, + { CYNTHION_REV_1_4, 220 }, + { CYNTHION_REV_1_3, 240 }, + { CYNTHION_REV_1_2, 260 }, + { CYNTHION_REV_1_0, 280 }, + { CYNTHION_REV_1_1, 310 }, + { CYNTHION_REV_UNKNOWN, 480 }, + { CYNTHION_REV_0_7, 510 }, }; int i = 0; - while (percentage > revisions[i].threshold) { ++i; } + while (permille > revisions[i].threshold) { ++i; } revision = revisions[i].version; } From eddf962e5bd9e7bde7b6cadb697587757b4a94e8 Mon Sep 17 00:00:00 2001 From: Michael Ossmann Date: Tue, 23 Jul 2024 09:40:43 -0400 Subject: [PATCH 3/3] firmware: Add vendor request for ADC debugging --- firmware/src/board_rev.c | 8 ++++++++ firmware/src/board_rev.h | 5 +++++ firmware/src/boards/cynthion_d11/board_rev.c | 11 ++++++++++- firmware/src/vendor.c | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/firmware/src/board_rev.c b/firmware/src/board_rev.c index cf21f53..c271e8f 100644 --- a/firmware/src/board_rev.c +++ b/firmware/src/board_rev.c @@ -39,3 +39,11 @@ __attribute__((weak)) const char *get_product_string(void) { return "Apollo Debugger"; } + +/** + * Return the raw ADC value. + */ +__attribute__((weak)) uint16_t get_adc_reading(void) +{ + return 0; +} diff --git a/firmware/src/board_rev.h b/firmware/src/board_rev.h index 30fbb13..d574305 100644 --- a/firmware/src/board_rev.h +++ b/firmware/src/board_rev.h @@ -32,4 +32,9 @@ const char *get_manufacturer_string(void); */ const char *get_product_string(void); +/** + * Return the raw ADC value. + */ +uint16_t get_adc_reading(void); + #endif diff --git a/firmware/src/boards/cynthion_d11/board_rev.c b/firmware/src/boards/cynthion_d11/board_rev.c index 5fcc69e..7fd6afe 100644 --- a/firmware/src/boards/cynthion_d11/board_rev.c +++ b/firmware/src/boards/cynthion_d11/board_rev.c @@ -21,6 +21,7 @@ static uint16_t revision = CYNTHION_REV_UNKNOWN; static bool gsg_production = false; +static uint16_t reading = 0xffff; /** * Detect hardware revision using Cynthion pin straps. @@ -50,7 +51,7 @@ void detect_hardware_revision(void) // Retrieve a single ADC reading. hri_adc_set_SWTRIG_START_bit(ADC); while (!hri_adc_get_interrupt_RESRDY_bit(ADC)); - uint16_t reading = hri_adc_read_RESULT_reg(ADC); + reading = hri_adc_read_RESULT_reg(ADC); // Convert ADC measurement to per mille of the reference voltage. uint32_t permille = (((uint32_t)reading * 1000) + 20480) >> 12; @@ -121,4 +122,12 @@ const char *get_product_string(void) return (gsg_production) ? "Cynthion Apollo Debugger" : "Apollo Debugger"; } +/** + * Return the raw ADC value. + */ +uint16_t get_adc_reading(void) +{ + return reading; +} + #endif diff --git a/firmware/src/vendor.c b/firmware/src/vendor.c index fec784f..693b374 100644 --- a/firmware/src/vendor.c +++ b/firmware/src/vendor.c @@ -21,6 +21,7 @@ #include "debug_spi.h" #include "usb_switch.h" #include "fpga_adv.h" +#include "board_rev.h" #define USB_API_MAJOR 1 #define USB_API_MINOR 1 @@ -32,6 +33,7 @@ enum { VENDOR_REQUEST_SET_LED_PATTERN = 0xa1, VENDOR_REQUEST_GET_FIRMWARE_VERSION = 0xa2, VENDOR_REQUEST_GET_USB_API_VERSION = 0xa3, + VENDOR_REQUEST_GET_ADC_READING = 0xa4, // // JTAG requests. @@ -161,6 +163,19 @@ bool handle_get_usb_api_version_request(uint8_t rhport, tusb_control_request_t c } +/** + * Request raw ADC reading. + */ +bool handle_get_adc_reading_request(uint8_t rhport, tusb_control_request_t const* request) +{ + static char buf[2]; + uint16_t reading = get_adc_reading(); + buf[0] = reading >> 8; + buf[1] = reading & 0xff; + return tud_control_xfer(rhport, request, buf, sizeof(buf)); +} + + /** * Request that changes the active LED pattern. */ @@ -213,6 +228,8 @@ bool handle_allow_fpga_takeover_usb_finish(uint8_t rhport, tusb_control_request_ static bool handle_vendor_request_setup(uint8_t rhport, tusb_control_request_t const* request) { switch(request->bRequest) { + case VENDOR_REQUEST_GET_ADC_READING: + return handle_get_adc_reading_request(rhport, request); case VENDOR_REQUEST_GET_ID: return handle_get_id_request(rhport, request); case VENDOR_REQUEST_GET_FIRMWARE_VERSION: