diff --git a/src/drivers/boards/common/board_common.h b/src/drivers/boards/common/board_common.h index 842b6beafb..e69446238d 100644 --- a/src/drivers/boards/common/board_common.h +++ b/src/drivers/boards/common/board_common.h @@ -185,6 +185,14 @@ #endif +/************************************************************************************ + * Public Data + ************************************************************************************/ +typedef enum board_reset_e { + board_reset_normal = 0, + board_reset_extended = 1, + board_reset_enter_bootloader = 2 +} board_reset_e; /************************************************************************************ * Private Functions ************************************************************************************/ @@ -241,3 +249,30 @@ __EXPORT int board_get_dma_usage(uint16_t *dma_total, uint16_t *dma_used, uint16 __EXPORT void board_rc_input(bool invert_on); # endif #endif + +/************************************************************************************ + * Name: board_reset + * + * Description: + * All boards my optionally provide this API to reset the board + * + ************************************************************************************/ +#if defined(BOARD_HAS_NO_RESET) +# define board_system_reset(status) +#else +__EXPORT void board_system_reset(int status) noreturn_function; +#endif +/************************************************************************************ + * Name: board_set_bootload_mode + * + * Description: + * All boards my optionally provide this API to enter configure the entry to + * boot loade mode on the next system reset. + * + ************************************************************************************/ + +#if defined(BOARD_HAS_NO_BOOTLOADER) +# define board_set_bootload_mode(mode) +#else +__EXPORT int board_set_bootload_mode(board_reset_e mode); +#endif diff --git a/src/drivers/boards/common/stm32/board_reset.c b/src/drivers/boards/common/stm32/board_reset.c new file mode 100644 index 0000000000..ff8e7df363 --- /dev/null +++ b/src/drivers/boards/common/stm32/board_reset.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * + * Copyright (C) 2017 PX4 Development Team. All rights reserved. + * Author: @author David Sidrane + * + * 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 PX4 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. + * + ****************************************************************************/ + +/** + * @file board_reset.c + * Implementation of STM32 based Board RESET API + */ + +#include +#include +#include +#include + + +int board_set_bootload_mode(board_reset_e mode) +{ + uint32_t regvalue = 0; + + switch (mode) { + case board_reset_normal: + case board_reset_extended: + break; + + case board_reset_enter_bootloader: + regvalue = 0xb007b007; + break; + + default: + return -EINVAL; + } + + stm32_pwr_enablebkp(true); + *(uint32_t *)STM32_BKP_BASE = regvalue; + stm32_pwr_enablebkp(false); + return OK; +} + + +void board_system_reset(int status) +{ + board_reset(status); + + while (1); +}