Skip to content

Enter DFU mode with stm32F401 (bootloader Issue) #8523

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

Closed
devHAA opened this issue Oct 24, 2018 · 18 comments
Closed

Enter DFU mode with stm32F401 (bootloader Issue) #8523

devHAA opened this issue Oct 24, 2018 · 18 comments

Comments

@devHAA
Copy link

devHAA commented Oct 24, 2018

Description

Hello,

I'm having troubles with mbed-os 5. With the previous version of mbed (v163) it worked perfectly. With the following piece of assembler code, the micro (stm32F401) enters DFU mode. But with the newest version of mbed-os 5 (5.10.2) doesn't work.

  • Target: NUCLEO-F401RE
  • Toolchain: GCC_ARM (7 2018-q2-update)
  • Using eclipse + mbed-cli (v1.8.2)
  • Mbed OS (5.10.2)
void enterDFU(){

__asm ("LDR     R0, =0x40023844");// RCC_APB2ENR
__asm ("LDR     R1, =0x00004000");// ENABLE SYSCFG CLOCK
__asm ("STR     R1, [R0, #0]");

__asm ("LDR     R0, =0x40013800");// remap ROM at zero
__asm ("LDR     R1, =0x00000001");// SYSCFG_MEMRMP
__asm ("STR     R1, [R0, #0]");

__asm ("LDR     R0, =0x1FFF0000");// ROM BASE
__asm ("LDR     SP,[R0, #0]");    // SP @ +0
__asm ("LDR     R0,[R0, #4]");    // PC @ +4

__asm ("BX      R0");             // Jump to Bootloader
}

I've been doing some tests and I think that the problem is in the last line __asm ("BX R0"); , when it should jump to the Bootloader. If I try to connect the device on the PC it says "descriptor request error".

Any ideas what may be happening, Thank you.

Issue request type

[ ] Question
[ ] Enhancement
[x] Bug

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 24, 2018

Just to be certain - you are using f401 with v163 (mbed 2 version), not Mbed OS 5.10.2 ?

@ARMmbed/team-st-mcd Please review

@devHAA
Copy link
Author

devHAA commented Oct 24, 2018

Just to be certain - you are using f401 with v163 (mbed 2 version), not Mbed OS 5.10.2 ?

@ARMmbed/team-st-mcd Please review

Yes @0xc0170, the version that works is mbed 2 (v163), and the version that doesn't work is mbed-os 5.10.2.

Thank you for your quick reply.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 24, 2018

Can you compare R0 value before and now? What toolchain - using online compiler?

I reviewed quickly recent changes , only change there was alignment for ARMCC change (affects RAM to be aligned to 8 byte). That should not have any affect to this issue.

If I try to connect the device on the PC it says "descriptor request error".

Look at ST forum to find some help - missing driver for instance?

@devHAA
Copy link
Author

devHAA commented Oct 25, 2018

Can you compare R0 value before and now? What toolchain - using online compiler?

I'm using eclipse with GCC_ARM compiler. In the online compiler the __asm is not recognized. The compiler error says "Expected an expression "__asm ("LDR R0, =0x40023844");"

I'm trying to see how to read R0 in c++, when I know how to do it I'll post it here

Look at ST forum to find some help - missing driver for instance?

This is not the problem, because as I said, with mbed 2 (v163) it works, and the PC takes the proper driver because the driver is installed.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 25, 2018

I'm using eclipse with GCC_ARM compiler. In the online compiler the __asm is not recognized. The compiler error says "Expected an expression "__asm ("LDR R0, =0x40023844");"

This code snippet from the mbed_application can help you: https://github.com/ARMmbed/mbed-os/blob/master/platform/mbed_application.c#L143 (using inline asm for ARMCC - the first one, later is for GCC and IAR).
You can debug your app and set a breakpoint to verify the last 4 instructions at least (I wonder what has changed on that address and then what you are loading to SP,PC and R0).

This is not the problem, because as I said, with mbed 2 (v163) it works, and the PC takes the proper driver because the driver is installed.

OK, might be the board is in bad state and cant connect.

@devHAA
Copy link
Author

devHAA commented Oct 25, 2018

OK, might be the board is in bad state and cant connect.

I just tried this simple example with the same board (NUCLEO-F401RE), using mbed 2 (v163), and then mbed-os 5.10.2. Both with the online compiler.

#include "mbed.h"

#if defined(__CC_ARM)
    __asm static void enterDFU(){
        LDR     R0, =0x40023844
        LDR     R1, =0x00004000
        STR     R1, [R0, #0]
        
        LDR     R0, =0x40013800
        LDR     R1, =0x00000001
        STR     R1, [R0, #0]
        
        LDR     R0, =0x1FFF0000
        LDR     SP,[R0, #0]
        LDR     R0,[R0, #4]
        BX      R0
    }
#endif

int main() {     
    enterDFU();  
}

With the mbed 2 (v163) it works perfect (PC recognized it as STM Device in DFU Mode), but with mbed-os 5.10.2 doesn't work. It says Unknown USB Device (Device Descriptor Request Failed)

@ARMmbed ARMmbed deleted a comment from ciarmcom Oct 25, 2018
@ARMmbed ARMmbed deleted a comment from ciarmcom Oct 25, 2018
@ciarmcom
Copy link
Member

Internal Jira reference: https://jira.arm.com/browse/MBOCUSTRIA-107

@elm3
Copy link

elm3 commented Jan 7, 2019

is the ST team (@ARMmbed/team-st-mcd) reviewing or aware?

@devHAA
Copy link
Author

devHAA commented Jan 24, 2019

@ciarmcom @adbridge @0xc0170 any updates with this issue?

I'm stuck with mbed2 because I can't use mbed-os without the DFU mode working.

Please, can anyone from the ARMmbed team tell us if this is being investigated?

Thank you.

@cmonr
Copy link
Contributor

cmonr commented Jan 30, 2019

@devHAA Right now, it seems like this is waiting on @ARMmbed/team-st-mcd to take a look.

@jeromecoutant
Copy link
Collaborator

  • v5.9.6: OK
  • v5.10.2: FAILED

Maybe you can check intermediate version ?

@devHAA
Copy link
Author

devHAA commented Feb 5, 2019

  • v5.9.6: OK
  • v5.10.2: FAILED

Maybe you can check intermediate version ?

Ok, after some test, still no lucky:

v5.10.2 -> failed
v5.11.3 -> failed (latest release)

@jeromecoutant
Copy link
Collaborator

I would like to know what happened between 5.9.6 and 5.10.2 ?
Could you check 5.9.7, 5.10.0 and 1 ....?

@devHAA
Copy link
Author

devHAA commented Feb 5, 2019

I would like to know what happened between 5.9.6 and 5.10.2 ?
Could you check 5.9.7, 5.10.0 and 1 ....?

Just checked v5.9.6 but is not working for me neither, is it working for you?

@neurodigitaltechnologies

Dear all,
How is this bug going on, please? I think we are a lot of people stuck with MBED OS 2 because of this.
@devHAA @jeromecoutant @ciarmcom @adbridge @0xc0170
Is there any solution, fix or workaround?
Can you elevate the priority, please? We have an upgrade in the technology roadmap pending on this issue to make a final decision about next platform.
Many thanks in advance!

@fpistm
Copy link

fpistm commented Jun 11, 2019

Hi @devHAA and all,

could you test this:

#include "mbed.h"

#if defined(__CC_ARM)
    __asm static void enterDFU(){
        LDR     R0, =0x40023844 // RCC_APB2ENR
        LDR     R1, =0x00004000 // ENABLE SYSCFG CLOCK
        STR     R1, [R0, #0]
        
        LDR     R0, =0x40013800 // remap ROM at zero
        LDR     R1, =0x00000001 // SYSCFG_MEMRMP
        STR     R1, [R0, #0]
        
        LDR     R0, =0x1FFF0000 // ROM BASE
        LDR     SP,[R0, #0]     // SP @ +0
        LDR     R0,[R0, #4]     // PC @ +4
        BX      R0              // Jump to Bootloader
    }
#endif

int main() {
    DigitalOut usb_dp_pin(USB_OTG_FS_DP, 1) ;
    wait(0.01);
    usb_dp_pin=0;
   
    enterDFU();  
}

Note: edited to be more mbed compliant. Thanks @LMESTM 😉

@jeromecoutant
Copy link
Collaborator

@neurodigitaltechnologies
Any feedback ?
Thx

@jeromecoutant
Copy link
Collaborator

@adbridge Could we close this issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants