Full GDB debugging via USB on BluePill board (STM32F103ะก8T)

This article will focus on programming and full debugging of the STM32F103C8T6 microcontroller via USB.





Once, colleagues received an offer to participate in an IoT project. The system provided for single-threaded script launch. Debugging was done using logs. And then I got the idea of โ€‹โ€‹a full-fledged remote debugging of projects for microcontrollers.





, . BluePill STM32F103. MicroUSB, . UART GSM .





, . :





  1. USB .





  2. GDB.





  3. GDB .





  4. .





. (bootloader).





1. . .. USB. USB- WinUSB. libopencm3. , , , , "MSFT100" "WINUSB". WinUSB. (USB-Endpoint) control endpoint 0, bulk out endpoint 1, bulk in endpoint 81, bulk in endpoint 82. USB, endpoint 1- , endpoint 81 - , 82 - (). USB "USB in a NutShell".





2. . . . , ,- . , Cortex M . Thread Handler. , . Handler mode . , flash- STM32F103C8T6 Handler , .





Flash Thread . , , . . , - , , . , , . , , , . , , "" , Flash .





. , , , , . . ,- , . , Bootloader-e. , . " " . - .





3. GDB-. BlackMagic, . arm-none-eabi-gdb. , . GDB- WinUSB.





4. , printf. endpoint 82. 8 - , USB (Host-).





printf bootloader-. ? , , / . , BIOS int13, ms-dos int21. , .. "svc". , SVC, bootloader-. .





Bootloader 10Kb flash , 16Kb . 4K . USB, , . . 16Kb 20Kb 48Kb flash . Flash- STM32F103C8T6 64Kb 128Kb,- 112Kb.





, . , , , . , step . , , .





, - :





  1. GDB. .. /. STM32CubeIDE. 0x8004000.





  2. .





  3. .





  4. .





  5. .





  6. .





  7. Forced stop.





  8. Debug printing to the GDB server console.





In debugged firmware, you cannot change the address of the interrupt handler vector. Although it is possible to add the setVectorBase system call, which solves the issue. Interrupt priorities cannot be changed to arbitrary values. The priority must be in the range 0x40 - 0xF0. You cannot disable systick interrupts, usb interrupts, and DebugMon interrupts, SvcHandler interrupts, as well as all FaultHandler-s.





The project prototype code is available here








All Articles