2019-06-28 15:36:08 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
|
2019-07-24 14:21:27 -04:00
|
|
|
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
|
2019-06-28 15:36:08 -04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "supervisor/port.h"
|
|
|
|
#include "boards/board.h"
|
2019-07-09 13:03:22 -04:00
|
|
|
#include "tick.h"
|
2019-07-18 17:55:57 -04:00
|
|
|
|
2019-09-12 13:47:01 -04:00
|
|
|
#include "common-hal/microcontroller/Pin.h"
|
2019-09-19 16:02:52 -04:00
|
|
|
#include "common-hal/busio/I2C.h"
|
2019-09-27 17:59:55 -04:00
|
|
|
#include "common-hal/busio/SPI.h"
|
2019-10-04 14:37:18 -04:00
|
|
|
#include "common-hal/busio/UART.h"
|
2019-10-27 19:17:01 -04:00
|
|
|
#include "common-hal/pulseio/PWMOut.h"
|
2020-02-29 14:44:33 -05:00
|
|
|
#include "common-hal/pulseio/PulseOut.h"
|
2019-09-12 13:47:01 -04:00
|
|
|
|
2019-07-24 14:21:27 -04:00
|
|
|
#include "stm32f4/clocks.h"
|
|
|
|
#include "stm32f4/gpio.h"
|
2019-07-18 17:55:57 -04:00
|
|
|
|
2019-07-24 14:21:27 -04:00
|
|
|
#include "stm32f4xx_hal.h"
|
2019-07-18 17:55:57 -04:00
|
|
|
|
2019-06-28 15:36:08 -04:00
|
|
|
safe_mode_t port_init(void) {
|
2019-11-12 11:26:14 -05:00
|
|
|
HAL_Init();
|
2019-09-18 16:49:15 -04:00
|
|
|
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
|
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
2019-06-28 15:36:08 -04:00
|
|
|
|
2019-11-12 11:26:14 -05:00
|
|
|
stm32f4_peripherals_clocks_init();
|
|
|
|
stm32f4_peripherals_gpio_init();
|
2019-07-11 13:41:10 -04:00
|
|
|
|
2019-07-18 17:17:46 -04:00
|
|
|
tick_init();
|
2019-06-28 15:36:08 -04:00
|
|
|
|
|
|
|
return NO_SAFE_MODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_port(void) {
|
2019-11-12 11:26:14 -05:00
|
|
|
reset_all_pins();
|
2019-09-19 16:02:52 -04:00
|
|
|
i2c_reset();
|
2019-09-27 17:59:55 -04:00
|
|
|
spi_reset();
|
2019-10-04 14:37:18 -04:00
|
|
|
uart_reset();
|
2019-10-27 19:17:01 -04:00
|
|
|
pwmout_reset();
|
2020-02-29 14:44:33 -05:00
|
|
|
pulseout_reset();
|
2019-06-28 15:36:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset_to_bootloader(void) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_cpu(void) {
|
2019-11-12 11:26:14 -05:00
|
|
|
NVIC_SystemReset();
|
2019-06-28 15:36:08 -04:00
|
|
|
}
|
|
|
|
|
2020-01-18 21:06:56 -05:00
|
|
|
uint32_t *port_heap_get_bottom(void) {
|
|
|
|
return port_stack_get_limit();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *port_heap_get_top(void) {
|
|
|
|
return port_stack_get_top();
|
|
|
|
}
|
|
|
|
|
2019-10-18 05:00:09 -04:00
|
|
|
uint32_t *port_stack_get_limit(void) {
|
|
|
|
return &_ebss;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t *port_stack_get_top(void) {
|
|
|
|
return &_estack;
|
|
|
|
}
|
|
|
|
|
2019-06-28 15:36:08 -04:00
|
|
|
extern uint32_t _ebss;
|
|
|
|
// Place the word to save just after our BSS section that gets blanked.
|
|
|
|
void port_set_saved_word(uint32_t value) {
|
|
|
|
_ebss = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t port_get_saved_word(void) {
|
|
|
|
return _ebss;
|
|
|
|
}
|
|
|
|
|
2019-08-14 13:14:42 -04:00
|
|
|
void HardFault_Handler(void) {
|
2019-11-12 11:26:14 -05:00
|
|
|
reset_into_safe_mode(HARD_CRASH);
|
2019-09-12 13:47:01 -04:00
|
|
|
while (true) {
|
|
|
|
asm("nop;");
|
|
|
|
}
|
2019-08-14 13:14:42 -04:00
|
|
|
}
|