forked from mfulz_github/qmk_firmware
		
	 c66df16644
			
		
	
	
		c66df16644
		
			
		
	
	
	
	
		
			
			* Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
		
			
				
	
	
		
			107 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			107 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| #include "bootloader.h"
 | |
| 
 | |
| #include "ch.h"
 | |
| #include "hal.h"
 | |
| #include "wait.h"
 | |
| 
 | |
| /* This code should be checked whether it runs correctly on platforms */
 | |
| #define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
 | |
| #define BOOTLOADER_MAGIC 0xDEADBEEF
 | |
| #define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
 | |
| 
 | |
| #ifndef STM32_BOOTLOADER_DUAL_BANK
 | |
| #    define STM32_BOOTLOADER_DUAL_BANK FALSE
 | |
| #endif
 | |
| 
 | |
| #if STM32_BOOTLOADER_DUAL_BANK
 | |
| 
 | |
| // Need pin definitions
 | |
| #    include "config_common.h"
 | |
| 
 | |
| #    ifndef STM32_BOOTLOADER_DUAL_BANK_GPIO
 | |
| #        error "No STM32_BOOTLOADER_DUAL_BANK_GPIO defined, don't know which pin to toggle"
 | |
| #    endif
 | |
| 
 | |
| #    ifndef STM32_BOOTLOADER_DUAL_BANK_POLARITY
 | |
| #        define STM32_BOOTLOADER_DUAL_BANK_POLARITY 0
 | |
| #    endif
 | |
| 
 | |
| #    ifndef STM32_BOOTLOADER_DUAL_BANK_DELAY
 | |
| #        define STM32_BOOTLOADER_DUAL_BANK_DELAY 100000
 | |
| #    endif
 | |
| 
 | |
| extern uint32_t __ram0_end__;
 | |
| 
 | |
| __attribute__((weak)) void bootloader_jump(void) {
 | |
|     // For STM32 MCUs with dual-bank flash, and we're incapable of jumping to the bootloader. The first valid flash
 | |
|     // bank is executed unconditionally after a reset, so it doesn't enter DFU unless BOOT0 is high. Instead, we do
 | |
|     // it with hardware...in this case, we pull a GPIO high/low depending on the configuration, connects 3.3V to
 | |
|     // BOOT0's RC charging circuit, lets it charge the capacitor, and issue a system reset. See the QMK discord
 | |
|     // #hardware channel pins for an example circuit.
 | |
|     palSetPadMode(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_MODE_OUTPUT_PUSHPULL);
 | |
| #    if STM32_BOOTLOADER_DUAL_BANK_POLARITY
 | |
|     palSetPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
 | |
| #    else
 | |
|     palClearPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
 | |
| #    endif
 | |
| 
 | |
|     // Wait for a while for the capacitor to charge
 | |
|     wait_ms(100);
 | |
| 
 | |
|     // Issue a system reset to get the ROM bootloader to execute, with BOOT0 high
 | |
|     NVIC_SystemReset();
 | |
| }
 | |
| 
 | |
| void enter_bootloader_mode_if_requested(void) {}  // not needed at all, but if anybody attempts to invoke it....
 | |
| 
 | |
| #elif defined(STM32_BOOTLOADER_ADDRESS)  // STM32_BOOTLOADER_DUAL_BANK
 | |
| 
 | |
| extern uint32_t __ram0_end__;
 | |
| 
 | |
| __attribute__((weak)) void bootloader_jump(void) {
 | |
|     *MAGIC_ADDR = BOOTLOADER_MAGIC;  // set magic flag => reset handler will jump into boot loader
 | |
|     NVIC_SystemReset();
 | |
| }
 | |
| 
 | |
| void enter_bootloader_mode_if_requested(void) {
 | |
|     unsigned long *check = MAGIC_ADDR;
 | |
|     if (*check == BOOTLOADER_MAGIC) {
 | |
|         *check = 0;
 | |
|         __set_CONTROL(0);
 | |
|         __set_MSP(*(__IO uint32_t *)STM32_BOOTLOADER_ADDRESS);
 | |
|         __enable_irq();
 | |
| 
 | |
|         typedef void (*BootJump_t)(void);
 | |
|         BootJump_t boot_jump = *(BootJump_t *)(STM32_BOOTLOADER_ADDRESS + 4);
 | |
|         boot_jump();
 | |
|         while (1)
 | |
|             ;
 | |
|     }
 | |
| }
 | |
| 
 | |
| #elif defined(KL2x) || defined(K20x)  // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS
 | |
| /* Kinetis */
 | |
| 
 | |
| #    if defined(BOOTLOADER_KIIBOHD)
 | |
| /* Kiibohd Bootloader (MCHCK and Infinity KB) */
 | |
| #        define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
 | |
| const uint8_t              sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
 | |
| __attribute__((weak)) void bootloader_jump(void) {
 | |
|     __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic));
 | |
|     // request reset
 | |
|     SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
 | |
| }
 | |
| 
 | |
| #    else /* defined(BOOTLOADER_KIIBOHD) */
 | |
| /* Default for Kinetis - expecting an ARM Teensy */
 | |
| #        include "wait.h"
 | |
| __attribute__((weak)) void bootloader_jump(void) {
 | |
|     wait_ms(100);
 | |
|     __BKPT(0);
 | |
| }
 | |
| #    endif /* defined(BOOTLOADER_KIIBOHD) */
 | |
| 
 | |
| #else /* neither STM32 nor KINETIS */
 | |
| __attribute__((weak)) void bootloader_jump(void) {}
 | |
| #endif
 |