2020-10-27 13:44:18 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Damien P. George
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#ifndef MICROPY_INCLUDED_STM32_BOARDCTRL_H
|
|
|
|
#define MICROPY_INCLUDED_STM32_BOARDCTRL_H
|
|
|
|
|
|
|
|
#include "py/mpconfig.h"
|
|
|
|
|
2021-10-13 08:40:06 +01:00
|
|
|
// Additional entries for use with pendsv_schedule_dispatch.
|
|
|
|
#ifndef MICROPY_BOARD_PENDSV_ENTRIES
|
|
|
|
#define MICROPY_BOARD_PENDSV_ENTRIES
|
|
|
|
#endif
|
|
|
|
|
2022-07-06 12:26:42 +01:00
|
|
|
#ifndef MICROPY_BOARD_FATAL_ERROR
|
|
|
|
#define MICROPY_BOARD_FATAL_ERROR boardctrl_fatal_error
|
|
|
|
#endif
|
|
|
|
|
2021-03-10 22:04:36 +00:00
|
|
|
#ifndef MICROPY_BOARD_STARTUP
|
|
|
|
#define MICROPY_BOARD_STARTUP powerctrl_check_enter_bootloader
|
|
|
|
#endif
|
|
|
|
|
2022-04-27 09:58:09 +01:00
|
|
|
#ifndef MICROPY_BOARD_ENTER_BOOTLOADER
|
2022-06-17 04:57:47 +01:00
|
|
|
#if MICROPY_HW_USES_BOOTLOADER
|
|
|
|
#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) boardctrl_maybe_enter_mboot(nargs, args)
|
|
|
|
#else
|
2022-04-27 09:58:09 +01:00
|
|
|
#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args)
|
|
|
|
#endif
|
2022-06-17 04:57:47 +01:00
|
|
|
#endif
|
2022-04-27 09:58:09 +01:00
|
|
|
|
2020-11-11 07:14:50 +00:00
|
|
|
#ifndef MICROPY_BOARD_EARLY_INIT
|
|
|
|
#define MICROPY_BOARD_EARLY_INIT()
|
|
|
|
#endif
|
|
|
|
|
2020-10-27 13:44:18 +00:00
|
|
|
#ifndef MICROPY_BOARD_BEFORE_SOFT_RESET_LOOP
|
|
|
|
#define MICROPY_BOARD_BEFORE_SOFT_RESET_LOOP boardctrl_before_soft_reset_loop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MICROPY_BOARD_TOP_SOFT_RESET_LOOP
|
|
|
|
#define MICROPY_BOARD_TOP_SOFT_RESET_LOOP boardctrl_top_soft_reset_loop
|
|
|
|
#endif
|
|
|
|
|
2021-04-08 12:11:24 +01:00
|
|
|
#ifndef MICROPY_BOARD_RUN_BOOT_PY
|
|
|
|
#define MICROPY_BOARD_RUN_BOOT_PY boardctrl_run_boot_py
|
2020-10-27 13:44:18 +00:00
|
|
|
#endif
|
|
|
|
|
2021-04-08 12:11:24 +01:00
|
|
|
#ifndef MICROPY_BOARD_RUN_MAIN_PY
|
|
|
|
#define MICROPY_BOARD_RUN_MAIN_PY boardctrl_run_main_py
|
2020-10-27 13:44:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MICROPY_BOARD_START_SOFT_RESET
|
|
|
|
#define MICROPY_BOARD_START_SOFT_RESET boardctrl_start_soft_reset
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MICROPY_BOARD_END_SOFT_RESET
|
|
|
|
#define MICROPY_BOARD_END_SOFT_RESET boardctrl_end_soft_reset
|
|
|
|
#endif
|
|
|
|
|
2021-10-13 08:29:00 +01:00
|
|
|
// Called when USBD CDC data is available.
|
|
|
|
// Default function defined in usbd_cdc_interface.h.
|
|
|
|
#ifndef MICROPY_BOARD_USBD_CDC_RX_EVENT
|
|
|
|
#define MICROPY_BOARD_USBD_CDC_RX_EVENT usbd_cdc_rx_event_callback
|
|
|
|
#endif
|
|
|
|
|
2021-10-13 08:37:48 +01:00
|
|
|
// Called to poll Bluetooth HCI now.
|
|
|
|
// Default function defined in mpbthciport.h.
|
|
|
|
#ifndef MICROPY_BOARD_BT_HCI_POLL_NOW
|
|
|
|
#define MICROPY_BOARD_BT_HCI_POLL_NOW mp_bluetooth_hci_poll_now_default
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Called to poll Bluetooth HCI after the given timeout.
|
|
|
|
// Default function defined in mpbthciport.h.
|
|
|
|
#ifndef MICROPY_BOARD_BT_HCI_POLL_IN_MS
|
|
|
|
#define MICROPY_BOARD_BT_HCI_POLL_IN_MS mp_bluetooth_hci_poll_in_ms_default
|
|
|
|
#endif
|
|
|
|
|
2021-04-28 01:30:17 +01:00
|
|
|
// Constants to return from boardctrl_run_boot_py, boardctrl_run_main_py.
|
2021-04-08 12:11:24 +01:00
|
|
|
enum {
|
|
|
|
BOARDCTRL_CONTINUE,
|
|
|
|
BOARDCTRL_GOTO_SOFT_RESET_EXIT,
|
|
|
|
};
|
|
|
|
|
2021-04-28 01:30:17 +01:00
|
|
|
// Constants for boardctrl_state_t.reset_mode.
|
|
|
|
enum {
|
|
|
|
BOARDCTRL_RESET_MODE_NORMAL = 1,
|
|
|
|
BOARDCTRL_RESET_MODE_SAFE_MODE = 2,
|
|
|
|
BOARDCTRL_RESET_MODE_FACTORY_FILESYSTEM = 3,
|
|
|
|
BOARDCTRL_RESET_MODE_BOOTLOADER = 4,
|
|
|
|
};
|
|
|
|
|
2020-10-27 13:44:18 +00:00
|
|
|
typedef struct _boardctrl_state_t {
|
|
|
|
uint8_t reset_mode;
|
|
|
|
bool log_soft_reset;
|
|
|
|
} boardctrl_state_t;
|
|
|
|
|
2022-07-06 12:26:42 +01:00
|
|
|
NORETURN void boardctrl_fatal_error(const char *msg);
|
2022-06-17 04:57:47 +01:00
|
|
|
void boardctrl_maybe_enter_mboot(size_t n_args, const void *args);
|
2020-10-27 13:44:18 +00:00
|
|
|
void boardctrl_before_soft_reset_loop(boardctrl_state_t *state);
|
|
|
|
void boardctrl_top_soft_reset_loop(boardctrl_state_t *state);
|
2021-04-08 12:11:24 +01:00
|
|
|
int boardctrl_run_boot_py(boardctrl_state_t *state);
|
|
|
|
int boardctrl_run_main_py(boardctrl_state_t *state);
|
2020-10-27 13:44:18 +00:00
|
|
|
void boardctrl_start_soft_reset(boardctrl_state_t *state);
|
|
|
|
void boardctrl_end_soft_reset(boardctrl_state_t *state);
|
|
|
|
|
|
|
|
#endif // MICROPY_INCLUDED_STM32_BOARDCTRL_H
|