stlink-org / stlink

Open source STM32 MCU programming toolset
BSD 3-Clause "New" or "Revised" License
4.34k stars 1.23k forks source link

Target reset is less reliable on testing branch #1409

Open hyves42 opened 2 months ago

hyves42 commented 2 months ago

In order to allow developers to isolate and target your respective issue, please take some time to select the check boxes below and fill out each of the following items appropriate to your specific problem.

I noticed a regression between st-flash 1.7.0 from ubuntu repos and the current testing branch

I generally reset the target board with the following command:

$ st-flash reset

Expected/description: The target resets (OK on v1.7.0)

This does not work anymore on the testing branch, the target does not reset.

Interestingly enough, nucleo boards still reset fine, I only see issues when I connect an external board via stlink.

Investigations:

I found a way to fix it but I don't know enough about stlink internals to see if it's a good solution.

The changes since 1.7.0 relevant to this issue are:

hyves42 commented 2 months ago

I tried to investigate this issue again today. It was actually not that easy to reproduce, and it finally happened after I reflashed the stm32 with stlink-gui 1.7.0.

After that, no matter how many times I unplugged or rebooted my setup, I was not able to perform any successful reset with st-flash reset from testing branch. The fix suggested above in stlink_exit_debug_mode() still works.

I can see a pulse on nRST in both cases so I guess the reset is actually performed, but maybe the processor is left in a not running state ?

salyzyn commented 2 months ago

JAFO here with some thoughts:

Summary: please check the target Boot0 line for pull down to be sure the external board is not the cause.

hyves42 commented 2 months ago

Boot0 is indeed tied to ground on the external board. I'm using both an STM32-V3-SET and some nucleo boards as STlink V2. Also I had no issue before with version 1.7.0 or with official ST tools so I don't think it is an hardware issue.

Tested again today, as long as I'm not unplugging anything randomly and not exiting stlink-gui before disconnecting I have no issue with board reset so I changed the title of this issue to something less alarming.

But still, version 1.7.0 can handle reset in cases where the system state is unclear better than the testing branch.

Nightwalker-87 commented 1 month ago

@hyves42: Please have a look at #1260 as well. Maybe this can give some further hints.

Nightwalker-87 commented 1 month ago

Can someone with the respective hardware and knowledge please help to debug this?

Ant-ON commented 4 weeks ago

@Nightwalker-87 After a software reset, the core remains in the Halt state. After the reset, you must run the core so that the firmware can start...

Nightwalker-87 commented 4 weeks ago

... which does not sound like a bug to me really. I think to have read this in an earlier ticket targeting this topic.

Ant-ON commented 4 weeks ago

@Nightwalker-87 But this is not the user expected behavior... @hyves42 Try to change reset code in the src/st-flash/flash.c file:

        // reset
        if (stlink_reset(sl, RESET_AUTO)) {
            printf("Failed to reset device\n");
            goto on_error;
        } 

to

        // reset
        if (stlink_reset(sl, RESET_AUTO)) {
            printf("Failed to reset device\n");
            goto on_error;
        } else
            stlink_run(sl, RUN_NORMAL);