-
-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blackpill-f4: bootloader LED issues #1516
Comments
Platforms like blackmagic/src/platforms/stlink/usbdfu.c Lines 85 to 96 in b2156f9
(or outright GPIO_C13) in usbdfu.c via systick_handler ,blackmagic/src/platforms/swlink/usbdfu.c Lines 92 to 99 in b2156f9
and I would like to port that behaviour to blackpill-f4 platform as well. Something as simple as diff --git a/src/platforms/common/blackpill-f4/usbdfu.c b/src/platforms/common/blackpill-f4/usbdfu.c
index a116e41e..0cc6a521 100644
--- a/src/platforms/common/blackpill-f4/usbdfu.c
+++ b/src/platforms/common/blackpill-f4/usbdfu.c
@@ -51,10 +51,16 @@ int main(void)
rcc_clock_setup_pll(&rcc_hse_25mhz_3v3[PLATFORM_CLOCK_FREQ]);
+ /* Use SysTick at 10Hz to toggle-blink the blue LED at 5 Hz */
+ systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
+ systick_set_reload(96000000U/8/10);
+ systick_interrupt_enable();
+ systick_counter_enable();
+
/* Assert blue LED as indicator we are in the bootloader */
rcc_periph_clock_enable(RCC_GPIOC);
gpio_mode_setup(LED_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LED_BOOTLOADER);
- gpio_set(LED_PORT, LED_BOOTLOADER);
+ gpio_clear(LED_PORT, LED_BOOTLOADER);
/* Enable peripherals */
rcc_periph_clock_enable(RCC_OTGFS);
@@ -76,3 +82,8 @@ int main(void)
void dfu_event(void)
{
}
+
+void sys_tick_handler(void)
+{
+ gpio_toggle(LED_PORT, LED_BOOTLOADER);
+} The 96e6 could be a blackmagic/src/platforms/native/usbdfu.c Lines 90 to 94 in b2156f9
When attaching external LEDs please keep in mind the note from RM0383 on RTC/LSE pins GPIO PC13/PC14/PC15:
BMP firmware does not use neither LSE pads/crystals nor the RTC IP block, so I think we could use all three pins as sinking slow GPIOs, active-low, like designed on stm32f103-minimum and blackpill-f4 PCBs. My thoughts on this are: honestly this entire situation asks for a BSP abstraction, factoring out the led_enable/led_disable and GPIO_ACTIVE_HIGH / GPIO_ACTIVE_LOW, like in STM32Cube_F4 packages, or in Linux device-tree gpio bindings. There's already a lot of code in BMP using For I don't know what to do with LED_ERROR or LED_UART. blackmagic/src/platforms/common/stm32/timing_stm32.c Lines 57 to 59 in b2156f9
but it only ever uses LED_ERROR to blink out the morse error message, I think. LED_UART is used in aux_serial.c+usb_serial.c to indicate hardware USART activity (both on reception and transmission. @lenvm Are you using a breadboard with additional LEDs for UART/ERROR/BOOTLOADER? Can you post something like a fritzing or imgur photo of your setup? |
Hi @ALTracer, thanks for your inputs! I am using a small PCB that I've prototyped. It's still a work in progress. The PCB has a Black Magic Debug Unified Connector and uses all 4 LEDs: LED_IDLE_RUN, LED_BOOTLOADER, LED_ERROR and LED_UART. It also has the UART TX and RX pins broken out to a 2x1 2.54mm header, to allow easy connection to a UART with jump wires. It would therefore be convenient to me to retain at least the LED_IDLE_RUN (with bootlader functionality), LED_ERROR and LED_UART. It would be cool if the LED_IDLE_RUN (PC13) blinks when the bootloader is active. As written in the description of the first issue, I cannot get LED_IDLE_RUN to work on PC13, so it would be helpful to first figure out why this is the case. Only when using LED_BOOTLOADER as PC13, the LED on PC13 works properly. To answer your unrelated question: I use |
@lenvm That's why I'm asking. I need to understand how you've wired the LEDs. WeAct MiniF4 schematic shows two LEDs:
Strange. It works on vanilla blackpill-f4 boards for me, as in, the LED toggles sometimes on blackmagic activity.
Reading some more through DS and RM I noticed a second remark from ST. RM0383 (and RM0090), paragraph 8.3.13:
After watching all 10 GPIOC registers via OOCD+DragonProbe Pico during quite a few different resets (BMP->BMPDFU and back, ST DFU, triggered both by PA0 key + nRST key, or We specifically call My conclusion is that once you hand over control to ST DFU, all bets are off. It sets RCC to 60MHz, drops voltage range to lowest, enables a bunch of peripherals and GPIO AF, and clobbers first 12 KBytes of SRAM. However, it works, and it's reliable. It would help you understand what is happening if you had a disassembled and cross-referenced listing of the dumpable 30k BootROM V9.x for STM32F401 at 0x1FFF0000-0x1FFF77FF. To be able to blink anything in "bootloader" mode, I need to fix the BMPBootloader for F411. Currently it only works enough to allow readouts and to seamlessly jump into payload on first boot. There's no DFU_DETACH command handler in dfucore.c (but there is one in usb_dfu_stub.c); rather, it detaches after download. I see why this was a problem. |
I have also tested the code on a vanilla board as I have multiple boards. There I obtain the same results. The PC13 LED is not turning on when used as LED_IDLE_RUN, but it is turning on when LED_BOOTLOADER is defined as PC13. Interesting that you mention “ The LEDs that I have connected on my PCB (PC14, PC15, PA1) are wired as |
Did you also look into, or try to change, any of LED handling logic? Once BMP DFU F4 sector erase bug got fixed, I returned to hacking and added the mentioned systick blinking of LED_BOOTLOADER. Of course, I saw nothing, because I don't have a bunch of free LEDs laying around to plug into a proto board. After adding LED_IDLE_RUN, the onboard PC13 active-low LED started blinking. You can cherry-pick ALTracer@57e40b0 to reproduce this. On another note, I pitched the idea of JTAG shield with level-shifters, headers and additional LEDs to the PCB designers on my team. Are your boards/designs open-source hardware? I've found a |
I did have a look into the LED handling logic. Although I don’t find the defines used for SET_IDLE_STATE and SET_ERROR_STATE particularly nice in terms of code (see blackpill-f4.h#L215-L222), and sometimes Regarding your question if my PCB design is open source: Following the discussion on why the BMP design files are not published, I understand @esden’s reasoning that this project is only being properly maintained thanks to the hardware sales, for which I’m very grateful. I would therefore not want to open my PCB design and reduce the sales of native BMPs, unless @esden would give his explicit go ahead. On top of this I would like to guarantee a certain quality of the hardware released and have first managed to get the boards with this shield PCB (including the LEDs) working properly, and spent some more time on testing and improving the design. |
I have done some additional research on the bugs described. 1. LED_IDLE_RUN issue [Resolved]I have been able to resolve the issue that LED_IDLE_RUN does not work when it is assigned to PC13. The schematic of PC13 is as follows:
This change will be implemented in #1645 2. LED_BOOTLOADER issue [Open]The issue that LED_BOOTLOADER only works on PC13 is caused by LED_BOOTLOADER always being low. Therefore, only an LED that turns on when being pulled low will work (PC13), whereas other LEDs that need to be pulled high to turn on (PC14, PC15) will not work. The issue is that LED_BOOTLOADER is always low, whereas one would expect that it is high when the bootloader is active, and low when the bootloader is inactive. My observations:
@dragonmux, do you perhaps have a clue why LED_BOOTLOADER is always low when it is setup as a pin? |
I have done some additional investigations. The pin assigned as LED_BOOTLOADER only stays low when the boot loader is activated using the following steps:
The pin assigned as LED_BOOTLOADER becomes high, and therefore functions as expected, in the following cases:
Is the expected behavior for the LED_BOOTLOADER pin that it stays low when the bootloader is activated using the NRST and BOOT0 buttons? Or should the user also expect the bootloader LED to turn on in this case? |
For consistency with other platforms, we'd expect it to turn on in that case. Unfortunately we don't have particular familiarity with the project's Black Pill bootloader, so can't offer any salient advice, though it seems you're making good progress on analysing the behaviour and trying to find a solution. |
I am encountering two issues with the LED_BOOTLOADER on the blackpill-f4 platforms.
1. Bootloader LED only works on PC13
Description
The bootloader LED only works when it is assigned to PC13. If LED_BOOTLOADER is set to for instance PC15, as in the most recent commit (df014ff), the bootloader LED does not work.
Details
The easy solution would be to swap the pin assignment of LED_BOOTLOADER and LED_IDLE_RUN, as then the LEDs are working. I would however prefer not to swap these pins, and understand what is the root cause of this issue.
2. Bootloader LED works inverted
Description
The bootloader LED works inverted to my expectation.
Details
I would appreciate your input to find out what could be the cause of and a fix for both of these issues.
The text was updated successfully, but these errors were encountered: