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
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
#include "stm32f4xx_hal.h"
|
|
|
|
|
|
|
|
#define B1_Pin GPIO_PIN_13
|
|
|
|
#define B1_GPIO_Port GPIOC
|
|
|
|
#define USART_TX_Pin GPIO_PIN_2
|
|
|
|
#define USART_TX_GPIO_Port GPIOA
|
|
|
|
#define USART_RX_Pin GPIO_PIN_3
|
|
|
|
#define USART_RX_GPIO_Port GPIOA
|
|
|
|
#define LD2_Pin GPIO_PIN_5
|
|
|
|
#define LD2_GPIO_Port GPIOA
|
|
|
|
#define TMS_Pin GPIO_PIN_13
|
|
|
|
#define TMS_GPIO_Port GPIOA
|
|
|
|
#define TCK_Pin GPIO_PIN_14
|
|
|
|
#define TCK_GPIO_Port GPIOA
|
|
|
|
#define SWO_Pin GPIO_PIN_3
|
|
|
|
#define SWO_GPIO_Port GPIOB
|
|
|
|
|
|
|
|
//UART_HandleTypeDef huart2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include "shared-module/gamepad/__init__.h"
|
|
|
|
#include "common-hal/microcontroller/Pin.h"
|
|
|
|
#include "common-hal/bleio/__init__.h"
|
|
|
|
#include "common-hal/busio/I2C.h"
|
|
|
|
#include "common-hal/busio/SPI.h"
|
|
|
|
#include "common-hal/busio/UART.h"
|
|
|
|
#include "common-hal/pulseio/PWMOut.h"
|
|
|
|
#include "common-hal/pulseio/PulseOut.h"
|
|
|
|
#include "common-hal/pulseio/PulseIn.h"
|
|
|
|
#include "common-hal/rtc/RTC.h"
|
|
|
|
#include "tick.h"
|
|
|
|
*/
|
|
|
|
|
|
|
|
//#include "shared-bindings/rtc/__init__.h"
|
|
|
|
|
|
|
|
static void power_warning_handler(void) {
|
|
|
|
reset_into_safe_mode(BROWNOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
safe_mode_t port_init(void) {
|
|
|
|
|
|
|
|
HAL_Init();
|
|
|
|
|
|
|
|
//clock setup
|
|
|
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
|
|
|
|
|
|
/** Configure the main internal regulator output voltage
|
|
|
|
*/
|
|
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
|
|
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
|
|
|
/** Initializes the CPU, AHB and APB busses clocks
|
|
|
|
*/
|
|
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
|
|
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
|
|
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
|
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
|
|
|
RCC_OscInitStruct.PLL.PLLM = 16;
|
|
|
|
RCC_OscInitStruct.PLL.PLLN = 336;
|
|
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
|
|
|
|
RCC_OscInitStruct.PLL.PLLQ = 4;
|
|
|
|
/** Initializes the CPU, AHB and APB busses clocks
|
|
|
|
*/
|
|
|
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
|
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
|
|
|
|
|
|
|
|
|
|
//GPIO setup
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
|
|
|
|
/* GPIO Ports Clock Enable */
|
|
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
|
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
|
|
|
|
|
|
|
|
/*Configure GPIO pin : B1_Pin */
|
|
|
|
GPIO_InitStruct.Pin = B1_Pin;
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
/*Configure GPIO pin : LD2_Pin */
|
|
|
|
GPIO_InitStruct.Pin = LD2_Pin;
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
|
|
HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
|
|
|
|
|
|
|
|
//USART2 setup
|
|
|
|
// huart2.Instance = USART2;
|
|
|
|
// huart2.Init.BaudRate = 115200;
|
|
|
|
// huart2.Init.WordLength = UART_WORDLENGTH_8B;
|
|
|
|
// huart2.Init.StopBits = UART_STOPBITS_1;
|
|
|
|
// huart2.Init.Parity = UART_PARITY_NONE;
|
|
|
|
// huart2.Init.Mode = UART_MODE_TX_RX;
|
|
|
|
// huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
|
|
// huart2.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
|
|
|
2019-07-01 19:47:10 -04:00
|
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
|
2019-06-28 15:36:08 -04:00
|
|
|
|
|
|
|
return NO_SAFE_MODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_port(void) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_to_bootloader(void) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_cpu(void) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HardFault_Handler(void) {
|
|
|
|
|
|
|
|
}
|