diff --git a/arch/arm/src/stm32/Make.defs b/arch/arm/src/stm32/Make.defs index 2d5f7a8c4a..5addfc9316 100644 --- a/arch/arm/src/stm32/Make.defs +++ b/arch/arm/src/stm32/Make.defs @@ -93,6 +93,7 @@ CHIP_CSRCS += stm32_lsi.c stm32_gpio.c stm32_exti_gpio.c stm32_flash.c CHIP_CSRCS += stm32_irq.c stm32_dma.c stm32_lowputc.c CHIP_CSRCS += stm32_serial.c stm32_spi.c stm32_i2s.c stm32_sdio.c stm32_tim.c CHIP_CSRCS += stm32_waste.c stm32_ccm.c stm32_uid.c stm32_capture.c +CHIP_CSRCS += stm32_dfumode.c ifeq ($(CONFIG_TIMER),y) CHIP_CSRCS += stm32_tim_lowerhalf.c diff --git a/arch/arm/src/stm32/stm32_dfumode.c b/arch/arm/src/stm32/stm32_dfumode.c new file mode 100644 index 0000000000..0d37da1505 --- /dev/null +++ b/arch/arm/src/stm32/stm32_dfumode.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * arch/arm/src/stm32/stm32_dfumode.c + * + * Copyright (C) 2019 Bill Gatliff. All rights reserved. + * Copyright (C) 2019 Gregory Nutt. All rights reserved. + * Author: Bill Gatliff + * Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "stm32_dfumode.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_dfumode + * + * Description: + * Reboot the part in DFU mode. + * + * https://community.st.com/s/question/0D50X00009XkhAzSAJ/calling-stm32429ieval-bootloader + * + ****************************************************************************/ + +void stm32_dfumode(void) +{ + _warn("Entering DFU mode...\n"); + sleep(1); + + asm("ldr r0, =0x40023844\n\t" /* RCC_APB2ENR */ + "ldr r1, =0x00004000\n\t" /* Enable SYSCFG clock */ + "str r1, [r0, #0]\n\t" + "ldr r0, =0x40013800\n\t" /* SYSCFG_MEMRMP */ + "ldr r1, =0x00000001\n\t" /* Map ROM at zero */ + "str r1, [r0, #0]\n\t" + "ldr r0, =0x1fff0000\n\t" /* ROM base */ + "ldr sp,[r0, #0]\n\t" /* SP @ 0 */ + "ldr r0,[r0, #4]\n\t" /* PC @ 4 */ + "bx r0\n"); + + __builtin_unreachable(); /* Tell compiler we will not return */ +} diff --git a/arch/arm/src/stm32/stm32_dfumode.h b/arch/arm/src/stm32/stm32_dfumode.h new file mode 100644 index 0000000000..c06397b1c0 --- /dev/null +++ b/arch/arm/src/stm32/stm32_dfumode.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * arch/arm/src/stm32/stm32_dfumode.h + * + * Copyright (C) 2019 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_STM32_DFUMODE_H +#define __ARCH_ARM_SRC_STM32_DFUMODE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_dfumode + * + * Description: + * Reboot the part in DFU mode. + * + * https://community.st.com/s/question/0D50X00009XkhAzSAJ/calling-stm32429ieval-bootloader + * + ****************************************************************************/ + +void stm32_dfumode(void) noreturn_function; + +#endif /* __ARCH_ARM_SRC_STM32_DFUMODE_H */