Skip to content

Commit

Permalink
wip: trying to trigger DFU mode from application
Browse files Browse the repository at this point in the history
  • Loading branch information
heiso committed Nov 11, 2024
1 parent 78d346c commit dffe6d3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions firmware/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define VENDOR_REQUEST_KEYS 0xfe
#define VENDOR_REQUEST_CONFIG 0xff
#define VENDOR_REQUEST_RESET_CONFIG 0xfd
#define VENDOR_REQUEST_DFU_MODE 0xfc

#define VENDOR_VALUE_GET_LENGTH 0x00
#define VENDOR_VALUE_GET 0x01
Expand Down Expand Up @@ -137,6 +138,26 @@ static void remove_from_hid_report(struct key *key, uint8_t layer);

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

// https://stm32f4-discovery.net/2017/04/tutorial-jump-system-memory-software-stm32/
void jump_to_bootloader(void) {
__enable_irq();
HAL_RCC_DeInit();
HAL_DeInit();
SysTick->CTRL = SysTick->LOAD = SysTick->VAL = 0;
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();

const uint32_t p = (*((uint32_t *)0x1FFF0000));
__set_MSP(p);

void (*SysMemBootJump)(void);
SysMemBootJump = (void (*)(void))(*((uint32_t *)0x1FFF0004));
SysMemBootJump();

while (1) {
}
}

void readConfig() {
memcpy(&user_config, (uint32_t *)CONFIG_ADDRESS, sizeof(user_config));
}
Expand Down Expand Up @@ -953,6 +974,17 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
}
}

case VENDOR_REQUEST_DFU_MODE: {
if (request->wValue == VENDOR_VALUE_SET) {
if (stage == CONTROL_STAGE_SETUP) {
jump_to_bootloader();
return tud_control_status(rhport, request);
}

break;
}
}

case VENDOR_REQUEST_KEYS: {
switch (request->wValue) {
case VENDOR_VALUE_GET_LENGTH: {
Expand Down
1 change: 1 addition & 0 deletions web-app/app/routes/_layout.configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export default function Index() {
<Button onClick={loadUserConfig}>Load Config</Button>
<Button onClick={persistUserConfig}>Save Config</Button>
<Button onClick={() => write('VENDOR_REQUEST_RESET_CONFIG')}>Reset Config</Button>
<Button onClick={() => write('VENDOR_REQUEST_DFU_MODE')}>DFU Mode</Button>
</div>
</>
)}
Expand Down
1 change: 1 addition & 0 deletions web-app/app/useDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const vendorRequests = {
VENDOR_REQUEST_KEYS: 0xfe,
VENDOR_REQUEST_CONFIG: 0xff,
VENDOR_REQUEST_RESET_CONFIG: 0xfd,
VENDOR_REQUEST_DFU_MODE: 0xfc,
}

const vendorValues = {
Expand Down

0 comments on commit dffe6d3

Please sign in to comment.