laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42170?usp=email )
Change subject: dfu: mainloop: work on a local copy of dfu_state
......................................................................
dfu: mainloop: work on a local copy of dfu_state
Prevent race conditions between main loop and irq.
Copy at the start of the loop the dfu state and work on it.
Change-Id: Ic146c8fa5ba25425cf785bae66f9c99b0faab944
---
M usb_start.c
1 file changed, 6 insertions(+), 3 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/usb_start.c b/usb_start.c
index 47e287f..13fbfd3 100644
--- a/usb_start.c
+++ b/usb_start.c
@@ -159,8 +159,11 @@
ASSERT(application_start_address > 0);
while (true) { // main DFU infinite loop
+ enum usb_dfu_state last_dfu_state = dfu_state;
+
// run the second part of the USB DFU state machine handling non-USB aspects
- if (USB_DFU_STATE_DFU_DNLOAD_SYNC == dfu_state || USB_DFU_STATE_DFU_DNBUSY == dfu_state) { // there is some data to be flashed
+ if (USB_DFU_STATE_DFU_DNLOAD_SYNC == last_dfu_state ||
+ USB_DFU_STATE_DFU_DNBUSY == last_dfu_state) { // there is some data to be flashed
LED_SYSTEM_off(); // switch LED off to indicate we are flashing
if (dfu_download_length > 0) { // there is some data to be flashed
int32_t rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset, dfu_download_data, dfu_download_length); // write downloaded data chunk to flash
@@ -182,7 +185,7 @@
}
LED_SYSTEM_on(); // switch LED on to indicate USB DFU can resume
}
- if (USB_DFU_STATE_DFU_MANIFEST == dfu_state) { // we can start manifestation (finish flashing)
+ if (USB_DFU_STATE_DFU_MANIFEST == last_dfu_state) { // we can start manifestation (finish flashing)
// in theory every DFU files should have a suffix to with a CRC to check the data
// in practice most downloaded files are just the raw binary with DFU suffix
dfu_manifestation_complete = true; // we completed flashing and all checks
@@ -192,7 +195,7 @@
dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET;
}
}
- if (USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET == dfu_state) {
+ if (USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET == last_dfu_state) {
if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_WILL_DETACH) {
usb_dfu_reset(USB_EV_RESET, 0); // immediately reset
} else { // wait for USB reset
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42170?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: Ic146c8fa5ba25425cf785bae66f9c99b0faab944
Gerrit-Change-Number: 42170
Gerrit-PatchSet: 4
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42171?usp=email )
Change subject: dfu: irq: replace if(states) with a switch case
......................................................................
dfu: irq: replace if(states) with a switch case
Improves the overview. No functional change.
Change-Id: Ic32fe16dff4b7bb933ec62e36a9c7c7829aece1b
---
M usb/class/dfu/device/dfudf.c
1 file changed, 7 insertions(+), 2 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/usb/class/dfu/device/dfudf.c b/usb/class/dfu/device/dfudf.c
index a067185..76dcc9b 100644
--- a/usb/class/dfu/device/dfudf.c
+++ b/usb/class/dfu/device/dfudf.c
@@ -162,9 +162,11 @@
case USB_DFU_GETSTATUS: // get status
// per DFU 1.1 spec, bState must report the state the device will enter
// after this response, so perform state transitions before building response
- if (USB_DFU_STATE_DFU_DNLOAD_SYNC == dfu_state) {
+ switch (dfu_state) {
+ case USB_DFU_STATE_DFU_DNLOAD_SYNC: // download has not completed
dfu_state = USB_DFU_STATE_DFU_DNBUSY; // switch to busy state
- } else if (USB_DFU_STATE_DFU_MANIFEST_SYNC == dfu_state) {
+ break;
+ case USB_DFU_STATE_DFU_MANIFEST_SYNC:
if (!dfu_manifestation_complete) {
dfu_state = USB_DFU_STATE_DFU_MANIFEST; // go to manifest mode
} else if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_MANIFEST_TOLERANT) {
@@ -172,6 +174,9 @@
} else { // this should not happen (after manifestation the state should be dfuMANIFEST-WAIT-RESET if we are not manifest tolerant)
dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET; // wait for reset
}
+ break;
+ default:
+ break;
}
response[0] = dfu_status; // set status
response[1] = 10; // set poll timeout (24 bits, in milliseconds) to small value for periodical poll
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42171?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: Ic32fe16dff4b7bb933ec62e36a9c7c7829aece1b
Gerrit-Change-Number: 42171
Gerrit-PatchSet: 4
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: Hoernchen <ewild(a)sysmocom.de>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42173?usp=email )
Change subject: dfu: usb_dfu() convert if() intos switch/case
......................................................................
dfu: usb_dfu() convert if() intos switch/case
Improves the overview of the handled states.
No functional change.
Change-Id: Ie0abcdb51612598e77cacf7772276919ded17d5a
---
M usb_start.c
1 file changed, 10 insertions(+), 6 deletions(-)
Approvals:
laforge: Looks good to me, approved
pespin: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/usb_start.c b/usb_start.c
index 13fbfd3..78711f1 100644
--- a/usb_start.c
+++ b/usb_start.c
@@ -162,8 +162,9 @@
enum usb_dfu_state last_dfu_state = dfu_state;
// run the second part of the USB DFU state machine handling non-USB aspects
- if (USB_DFU_STATE_DFU_DNLOAD_SYNC == last_dfu_state ||
- USB_DFU_STATE_DFU_DNBUSY == last_dfu_state) { // there is some data to be flashed
+ switch (last_dfu_state) {
+ case USB_DFU_STATE_DFU_DNLOAD_SYNC:
+ case USB_DFU_STATE_DFU_DNBUSY: // there is some data to be flashed
LED_SYSTEM_off(); // switch LED off to indicate we are flashing
if (dfu_download_length > 0) { // there is some data to be flashed
int32_t rc = flash_write(&FLASH_0, application_start_address + dfu_download_offset, dfu_download_data, dfu_download_length); // write downloaded data chunk to flash
@@ -184,8 +185,8 @@
dfu_state = USB_DFU_STATE_DFU_DNLOAD_IDLE; // indicate flashing can continue
}
LED_SYSTEM_on(); // switch LED on to indicate USB DFU can resume
- }
- if (USB_DFU_STATE_DFU_MANIFEST == last_dfu_state) { // we can start manifestation (finish flashing)
+ break;
+ case USB_DFU_STATE_DFU_MANIFEST: // we can start manifestation (finish flashing)
// in theory every DFU files should have a suffix to with a CRC to check the data
// in practice most downloaded files are just the raw binary with DFU suffix
dfu_manifestation_complete = true; // we completed flashing and all checks
@@ -194,13 +195,16 @@
} else {
dfu_state = USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET;
}
- }
- if (USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET == last_dfu_state) {
+ break;
+ case USB_DFU_STATE_DFU_MANIFEST_WAIT_RESET:
if (usb_dfu_func_desc->bmAttributes & USB_DFU_ATTRIBUTES_WILL_DETACH) {
usb_dfu_reset(USB_EV_RESET, 0); // immediately reset
} else { // wait for USB reset
usb_d_register_callback(USB_D_CB_EVENT, (FUNC_PTR)usb_dfu_reset); // register new USB reset event handler
}
+ break;
+ default:
+ break;
}
}
}
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42173?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: Ie0abcdb51612598e77cacf7772276919ded17d5a
Gerrit-Change-Number: 42173
Gerrit-PatchSet: 4
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Attention is currently required from: lynxis lazus, pespin.
laforge has posted comments on this change by lynxis lazus. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42170?usp=email )
Change subject: dfu: mainloop: work on a local copy of dfu_state
......................................................................
Patch Set 4: Code-Review+2
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42170?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: Ic146c8fa5ba25425cf785bae66f9c99b0faab944
Gerrit-Change-Number: 42170
Gerrit-PatchSet: 4
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Comment-Date: Tue, 10 Mar 2026 09:43:41 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Attention is currently required from: mschramm, pespin.
lynxis lazus has posted comments on this change by lynxis lazus. ( https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42168?usp=email )
Change subject: Improve comments on errata 2.6.10
......................................................................
Patch Set 2:
(2 comments)
Patchset:
PS1:
> The point here is: there is no such facility nor even a concept of a 'low-priority' WDT in this Cort […]
Done
PS1:
> And what is the correct explanation?
updated the comments, should be correct now.
--
To view, visit https://gerrit.osmocom.org/c/osmo-asf4-dfu/+/42168?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmo-asf4-dfu
Gerrit-Branch: master
Gerrit-Change-Id: I3c35f590a4e43d778e70f2f377e0d470c3a652b2
Gerrit-Change-Number: 42168
Gerrit-PatchSet: 2
Gerrit-Owner: lynxis lazus <lynxis(a)fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: mschramm <mschramm(a)sysmocom.de>
Gerrit-Attention: mschramm <mschramm(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Tue, 10 Mar 2026 09:34:41 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: mschramm <mschramm(a)sysmocom.de>
Comment-In-Reply-To: Hoernchen <ewild(a)sysmocom.de>
Comment-In-Reply-To: lynxis lazus <lynxis(a)fe80.eu>