Skip to content

Commit f8c5df0

Browse files
authored
Merge pull request #473 from NordicSemiconductor/fix/sdfu-cancel-wait-for-device
Fix/sdfu cancel wait for device
2 parents 6fd9b23 + 90b4998 commit f8c5df0

File tree

7 files changed

+59
-46
lines changed

7 files changed

+59
-46
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
with UICR will not be displayed anymore.
77
- The SoC is now detected before each operation to ensure the app works even
88
if the SoC changes between operations.
9+
- Memory layout and device informaion now updates correclty when switching
10+
between selected devices quickly.
911

1012
## 4.4.0 - 2024-06-13
1113

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"prepare": "husky install"
4747
},
4848
"devDependencies": {
49-
"@nordicsemiconductor/pc-nrfconnect-shared": "^182.0.0"
49+
"@nordicsemiconductor/pc-nrfconnect-shared": "^185.0.0"
5050
},
5151
"eslintConfig": {
5252
"extends": "./node_modules/@nordicsemiconductor/pc-nrfconnect-shared/config/eslintrc"

src/actions/targetActions.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ import * as jlinkTargetActions from './jlinkTargetActions';
2121
import * as mcubootTargetActions from './mcubootTargetActions';
2222
import * as usbsdfuTargetActions from './usbsdfuTargetActions';
2323

24-
let abortController: AbortController;
25-
2624
export const openDevice =
27-
(device: Device): AppThunk =>
25+
(device: Device, abortController: AbortController): AppThunk =>
2826
async dispatch => {
29-
abortController = new AbortController();
30-
3127
dispatch(setDeviceBusy(true));
3228
try {
3329
if (device.traits.jlink) {
@@ -37,7 +33,9 @@ export const openDevice =
3733
} else if (device.traits.mcuBoot) {
3834
dispatch(mcubootTargetActions.openDevice(device));
3935
} else if (device.traits.nordicDfu) {
40-
dispatch(usbsdfuTargetActions.openDevice(device));
36+
dispatch(
37+
usbsdfuTargetActions.openDevice(device, abortController)
38+
);
4139
} else {
4240
logger.warn('No operations possible for device.');
4341
logger.warn(
@@ -62,10 +60,6 @@ export const openDevice =
6260
dispatch(setDeviceBusy(false));
6361
};
6462

65-
export const closeDevice = () => {
66-
abortController.abort();
67-
};
68-
6963
export const updateTargetWritable =
7064
(): AppThunk<RootState> => (dispatch, getState) => {
7165
const device = selectedDevice(getState());

src/actions/usbsdfuTargetActions.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,18 @@ import {
5757
} from '../util/usbsdfuHelpers';
5858
import * as userInputActions from './userInputActions';
5959

60+
let abortController: AbortController | undefined;
61+
6062
const defaultDfuImage: DfuImage = {
6163
name: '',
6264
initPacket: defaultInitPacket,
6365
firmwareImage: Buffer.alloc(0),
6466
};
6567

6668
export const openDevice =
67-
(device: Device): AppThunk<RootState> =>
69+
(device: Device, controller: AbortController): AppThunk<RootState> =>
6870
dispatch => {
71+
abortController = controller;
6972
logger.info(
7073
'Using nrfutil-device to communicate with target via USB SDFU protocol'
7174
);
@@ -91,7 +94,10 @@ export const refreshMemoryLayout =
9194
device,
9295
async deviceInBootLoader => {
9396
const fwInfo = await NrfutilDeviceLib.getFwInfo(
94-
deviceInBootLoader
97+
deviceInBootLoader,
98+
undefined,
99+
undefined,
100+
abortController
95101
);
96102
dispatch(
97103
updateCoreOperations({
@@ -219,7 +225,13 @@ export const resetDevice =
219225
state: 'loading',
220226
})
221227
);
222-
await NrfutilDeviceLib.reset(device);
228+
await NrfutilDeviceLib.reset(
229+
device,
230+
undefined,
231+
undefined,
232+
undefined,
233+
abortController
234+
);
223235
logger.info(`Resetting device completed`);
224236
dispatch(
225237
updateCoreOperations({
@@ -521,7 +533,10 @@ export const operateDFU = async (
521533
await NrfutilDeviceLib.program(
522534
device,
523535
{ buffer: zipBuffer, type: 'zip' },
524-
onProgress
536+
onProgress,
537+
undefined,
538+
undefined,
539+
abortController
525540
);
526541

527542
logger.info('All dfu images have been written to the target device');

src/components/DeviceSelector.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,27 @@ import {
1111
DeviceSelector,
1212
} from '@nordicsemiconductor/pc-nrfconnect-shared';
1313

14-
import { closeDevice, openDevice } from '../actions/targetActions';
14+
import { openDevice } from '../actions/targetActions';
1515
import { resetDeviceInfo } from '../reducers/deviceDefinitionReducer';
1616
import { setShowMcuBootProgrammingDialog } from '../reducers/mcubootReducer';
1717
import { setShowModemProgrammingDialog } from '../reducers/modemReducer';
1818
import { deselectDevice } from '../reducers/targetReducer';
1919
import { setUsbSdfuProgrammingDialog } from '../reducers/usbSdfuReducer';
2020

21-
const abortController = new AbortController();
22-
23-
export const getAbortController = () => abortController;
24-
2521
export default () => {
2622
const dispatch = useDispatch();
2723
return (
2824
<DeviceSelector
2925
deviceFilter={device => !!device.serialNumber}
30-
onDeviceSelected={(device: SharedDevice) => {
31-
dispatch(openDevice(device));
26+
onDeviceSelected={(device: SharedDevice, _, abortController) => {
27+
dispatch(openDevice(device, abortController));
3228
}}
3329
onDeviceDeselected={() => {
3430
dispatch(setShowMcuBootProgrammingDialog(false));
3531
dispatch(setShowModemProgrammingDialog(false));
3632
dispatch(setUsbSdfuProgrammingDialog(false));
3733
dispatch(deselectDevice());
3834
dispatch(resetDeviceInfo());
39-
closeDevice();
4035
}}
4136
deviceListing={{
4237
nordicUsb: true,

src/components/UsbSdfuUpdateDialog.tsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,18 @@ export default () => {
7373
})
7474
);
7575

76+
let canceled = false;
77+
7678
// We might have more that one reboot of the device during the next operation
7779
dispatch(
7880
setWaitForDevice({
7981
timeout: 10000,
8082
when: 'always',
8183
once: false,
8284
skipRefetchDeviceInfo: true,
85+
onCanceled: () => {
86+
canceled = true;
87+
},
8388
})
8489
);
8590

@@ -121,23 +126,25 @@ Are you sure you want to continue?`,
121126
setWriting(false);
122127
dispatch(clearConfirmBeforeClose('usbSdfuProgramming'));
123128

124-
// Operation done reconnect one more time only
125-
dispatch(
126-
setWaitForDevice({
127-
timeout: 10000,
128-
when: 'always',
129-
once: true,
130-
onSuccess: programmedDevice =>
131-
dispatch(refreshMemoryLayout(programmedDevice)),
132-
})
133-
);
134-
135-
dispatch(
136-
updateCoreOperations({
137-
core: 'Application',
138-
state: 'idle',
139-
})
140-
);
129+
if (!canceled) {
130+
// Operation done reconnect one more time only
131+
dispatch(
132+
setWaitForDevice({
133+
timeout: 10000,
134+
when: 'always',
135+
once: true,
136+
onSuccess: programmedDevice =>
137+
dispatch(refreshMemoryLayout(programmedDevice)),
138+
})
139+
);
140+
141+
dispatch(
142+
updateCoreOperations({
143+
core: 'Application',
144+
state: 'idle',
145+
})
146+
);
147+
}
141148
}, [device, dispatch, images]);
142149

143150
useEffect(() => {

0 commit comments

Comments
 (0)