-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bootloader jumper keycode
- Loading branch information
Showing
10 changed files
with
326 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef __BOOTLOADER_H__ | ||
#define __BOOTLOADER_H__ | ||
|
||
#include "main.h" | ||
|
||
#define BOOTLOADER_MAGIC_ADDR ((uint32_t*) ((uint32_t) 0x20001000)) //4k into SRAM (out of 6k) | ||
#define BOOTLOADER_MAGIC_TOKEN 0xDEADBEEF // :D//Value taken from CD00167594.pdf page 35, system memory start. | ||
#define BOOTLOADER_START_ADDR 0x1fffc400 //for ST32F042 | ||
|
||
void BOOTLOADER_Init(); | ||
void BOOTLOADER_Jump(); | ||
|
||
#endif //__BOOTLOADER_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef __KEYCODE_H__ | ||
#define __KEYCODE_H__ | ||
|
||
#include <stdint.h> | ||
|
||
#define SHIFT 0x80 | ||
|
||
#define KEY_LEFT_CTRL 0x80 | ||
#define KEY_LEFT_SHIFT 0x81 | ||
#define KEY_LEFT_ALT 0x82 | ||
#define KEY_LEFT_GUI 0x83 | ||
#define KEY_RIGHT_CTRL 0x84 | ||
#define KEY_RIGHT_SHIFT 0x85 | ||
#define KEY_RIGHT_ALT 0x86 | ||
#define KEY_RIGHT_GUI 0x87 | ||
|
||
#define KEY_UP_ARROW 0xDA | ||
#define KEY_DOWN_ARROW 0xD9 | ||
#define KEY_LEFT_ARROW 0xD8 | ||
#define KEY_RIGHT_ARROW 0xD7 | ||
#define KEY_BACKSPACE 0xB2 | ||
#define KEY_TAB 0xB3 | ||
#define KEY_RETURN 0xB0 | ||
#define KEY_ESC 0xB1 | ||
#define KEY_INSERT 0xD1 | ||
#define KEY_DELETE 0xD4 | ||
#define KEY_PAGE_UP 0xD3 | ||
#define KEY_PAGE_DOWN 0xD6 | ||
#define KEY_HOME 0xD2 | ||
#define KEY_END 0xD5 | ||
#define KEY_CAPS_LOCK 0xC1 | ||
#define KEY_F1 0xC2 | ||
#define KEY_F2 0xC3 | ||
#define KEY_F3 0xC4 | ||
#define KEY_F4 0xC5 | ||
#define KEY_F5 0xC6 | ||
#define KEY_F6 0xC7 | ||
#define KEY_F7 0xC8 | ||
#define KEY_F8 0xC9 | ||
#define KEY_F9 0xCA | ||
#define KEY_F10 0xCB | ||
#define KEY_F11 0xCC | ||
#define KEY_F12 0xCD | ||
|
||
typedef KEY_REPORT{ | ||
uint8_t modifiers; | ||
uint8_t reserved; | ||
uint8_t keys[6]; | ||
}KEY_REPORT_TypeDef; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "bootloader.h" | ||
|
||
void BOOTLOADER_Jump(){ | ||
//https://community.st.com/s/question/0D50X00009Xkg1VSAR/jump-to-usb-dfu-bootloader-in-startup-code-on-stm32f042 | ||
//call this at any time to initiate a reboot into bootloader | ||
*BOOTLOADER_MAGIC_ADDR = BOOTLOADER_MAGIC_TOKEN; | ||
NVIC_SystemReset(); | ||
} | ||
void BOOTLOADER_Init(){ | ||
uint32_t jumpaddr; | ||
if (*BOOTLOADER_MAGIC_ADDR == BOOTLOADER_MAGIC_TOKEN){ | ||
// 要求转跳Bootloader | ||
*BOOTLOADER_MAGIC_ADDR=0; | ||
// 初始化Boot0引脚 | ||
GPIO_InitTypeDef GPIO_InitStruct; | ||
__HAL_RCC_GPIOB_CLK_ENABLE(); | ||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET); | ||
GPIO_InitStruct.Pin = GPIO_PIN_8; | ||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | ||
GPIO_InitStruct.Pull = GPIO_NOPULL; | ||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; | ||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); | ||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); // 拉高Boot0 | ||
|
||
void (*bootloader)(void) = 0; //Zero the function pointer. | ||
jumpaddr = *(__IO uint32_t*)(BOOTLOADER_START_ADDR + 4); | ||
bootloader = (void (*)(void)) jumpaddr; //Set the function pointerto bootaddr +4 | ||
__set_MSP(*(__IO uint32_t*) BOOTLOADER_START_ADDR); //load the stackpointer - bye bye program | ||
bootloader(); //Go to DFU mode | ||
//this should never be hit, trap for debugging | ||
while(1){} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.