From 3b258ef213d34b402c170fbb63dafbab53ea91b2 Mon Sep 17 00:00:00 2001
From: badlyby <badlyby@gmail.com>
Date: Fri, 19 Jul 2019 21:44:16 +0800
Subject: [PATCH] stm32/boards/NUCLEO_F722ZE: Add definition files for new
 board.

---
 ports/stm32/boards/NUCLEO_F722ZE/board_init.c |   8 ++
 .../boards/NUCLEO_F722ZE/mpconfigboard.h      |  68 ++++++++++++
 .../boards/NUCLEO_F722ZE/mpconfigboard.mk     |   6 +
 ports/stm32/boards/NUCLEO_F722ZE/pins.csv     | 104 ++++++++++++++++++
 .../boards/NUCLEO_F722ZE/stm32f7xx_hal_conf.h |  18 +++
 5 files changed, 204 insertions(+)
 create mode 100644 ports/stm32/boards/NUCLEO_F722ZE/board_init.c
 create mode 100644 ports/stm32/boards/NUCLEO_F722ZE/mpconfigboard.h
 create mode 100644 ports/stm32/boards/NUCLEO_F722ZE/mpconfigboard.mk
 create mode 100644 ports/stm32/boards/NUCLEO_F722ZE/pins.csv
 create mode 100644 ports/stm32/boards/NUCLEO_F722ZE/stm32f7xx_hal_conf.h

diff --git a/ports/stm32/boards/NUCLEO_F722ZE/board_init.c b/ports/stm32/boards/NUCLEO_F722ZE/board_init.c
new file mode 100644
index 000000000..5a7c6052a
--- /dev/null
+++ b/ports/stm32/boards/NUCLEO_F722ZE/board_init.c
@@ -0,0 +1,8 @@
+#include "py/mphal.h"
+
+void board_early_init(void) {
+    // Turn off the USB switch
+    #define USB_PowerSwitchOn pin_G6
+    mp_hal_pin_output(USB_PowerSwitchOn);
+    mp_hal_pin_low(USB_PowerSwitchOn);
+}
diff --git a/ports/stm32/boards/NUCLEO_F722ZE/mpconfigboard.h b/ports/stm32/boards/NUCLEO_F722ZE/mpconfigboard.h
new file mode 100644
index 000000000..5a7f65006
--- /dev/null
+++ b/ports/stm32/boards/NUCLEO_F722ZE/mpconfigboard.h
@@ -0,0 +1,68 @@
+// This board is only confirmed to operate using DFU mode and openocd.
+// DFU mode can be accessed by setting BOOT0 (see schematics)
+// To use openocd run "OPENOCD_CONFIG=boards/openocd_stm32f7.cfg" in
+// the make command.
+
+#define MICROPY_HW_BOARD_NAME       "NUCLEO-F722ZE"
+#define MICROPY_HW_MCU_NAME         "STM32F722"
+
+#define MICROPY_HW_HAS_SWITCH       (1)
+#define MICROPY_HW_HAS_FLASH        (1)
+#define MICROPY_HW_ENABLE_RNG       (1)
+#define MICROPY_HW_ENABLE_RTC       (1)
+#define MICROPY_HW_ENABLE_DAC       (1)
+#define MICROPY_HW_ENABLE_USB       (1)
+
+#define MICROPY_BOARD_EARLY_INIT    board_early_init
+void board_early_init(void);
+
+// HSE is 8MHz, run SYSCLK at 216MHz
+#define MICROPY_HW_CLK_PLLM         (4)
+#define MICROPY_HW_CLK_PLLN         (216)
+#define MICROPY_HW_CLK_PLLP         (RCC_PLLP_DIV2)
+#define MICROPY_HW_CLK_PLLQ         (9)
+#define MICROPY_HW_FLASH_LATENCY    (FLASH_LATENCY_7) // 210-216 MHz needs 7 wait states
+
+// UART config
+#define MICROPY_HW_UART2_TX         (pin_D5)
+#define MICROPY_HW_UART2_RX         (pin_D6)
+#define MICROPY_HW_UART2_RTS        (pin_D4)
+#define MICROPY_HW_UART2_CTS        (pin_D3)
+#define MICROPY_HW_UART3_TX         (pin_D8)
+#define MICROPY_HW_UART3_RX         (pin_D9)
+#define MICROPY_HW_UART6_TX         (pin_G14)
+#define MICROPY_HW_UART6_RX         (pin_G9)
+#define MICROPY_HW_UART_REPL        PYB_UART_3
+#define MICROPY_HW_UART_REPL_BAUD   115200
+
+// I2C buses
+#define MICROPY_HW_I2C1_SCL         (pin_B8)
+#define MICROPY_HW_I2C1_SDA         (pin_B9)
+
+// SPI buses
+#define MICROPY_HW_SPI3_NSS         (pin_A4)
+#define MICROPY_HW_SPI3_SCK         (pin_B3)
+#define MICROPY_HW_SPI3_MISO        (pin_B4)
+#define MICROPY_HW_SPI3_MOSI        (pin_B5)
+
+// CAN buses
+#define MICROPY_HW_CAN1_TX          (pin_B9)
+#define MICROPY_HW_CAN1_RX          (pin_B8)
+
+// USRSW is pulled low, and pressing the button makes the input go high
+#define MICROPY_HW_USRSW_PIN        (pin_C13)
+#define MICROPY_HW_USRSW_PULL       (GPIO_NOPULL)
+#define MICROPY_HW_USRSW_EXTI_MODE  (GPIO_MODE_IT_RISING)
+#define MICROPY_HW_USRSW_PRESSED    (1)
+
+// LEDs
+#define MICROPY_HW_LED1             (pin_B0) // green
+#define MICROPY_HW_LED2             (pin_B7) // blue
+#define MICROPY_HW_LED3             (pin_B14) // red
+#define MICROPY_HW_LED_ON(pin)      (mp_hal_pin_high(pin))
+#define MICROPY_HW_LED_OFF(pin)     (mp_hal_pin_low(pin))
+
+// USB config (CN13 - USB OTG FS)
+#define MICROPY_HW_USB_FS              (1)
+#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
+#define MICROPY_HW_USB_OTG_ID_PIN      (pin_A10)
diff --git a/ports/stm32/boards/NUCLEO_F722ZE/mpconfigboard.mk b/ports/stm32/boards/NUCLEO_F722ZE/mpconfigboard.mk
new file mode 100644
index 000000000..667c8e55d
--- /dev/null
+++ b/ports/stm32/boards/NUCLEO_F722ZE/mpconfigboard.mk
@@ -0,0 +1,6 @@
+MCU_SERIES = f7
+CMSIS_MCU = STM32F722xx
+AF_FILE = boards/stm32f722_af.csv
+LD_FILES = boards/stm32f722.ld boards/common_ifs.ld
+TEXT0_ADDR = 0x08000000
+TEXT1_ADDR = 0x08020000
diff --git a/ports/stm32/boards/NUCLEO_F722ZE/pins.csv b/ports/stm32/boards/NUCLEO_F722ZE/pins.csv
new file mode 100644
index 000000000..228d83a02
--- /dev/null
+++ b/ports/stm32/boards/NUCLEO_F722ZE/pins.csv
@@ -0,0 +1,104 @@
+A0,PA3
+A1,PC0
+A2,PC3
+A3,PF3
+A4,PF5
+A5,PF10
+A6,PB1
+A7,PC2
+A8,PF4
+D0,PG9
+D1,PG14
+D2,PF15
+D3,PE13
+D4,PF14
+D5,PE11
+D6,PE9
+D7,PF13
+D8,PF12
+D9,PD15
+D10,PD14
+D11,PA7
+D12,PA6
+D13,PA5
+D14,PB9
+D15,PB8
+D16,PC6
+D17,PB15
+D18,PB13
+D19,PB12
+D20,PA15
+D21,PC7
+D22,PB5
+D23,PB3
+D24,PA4
+D25,PB4
+D26,PB6
+D27,PB2
+D28,PD13
+D29,PD12
+D30,PD11
+D31,PE2
+D32,PA0
+D33,PB0
+D34,PE0
+D35,PB11
+D36,PB10
+D37,PE15
+D38,PE14
+D39,PE12
+D40,PE10
+D41,PE7
+D42,PE8
+D43,PC8
+D44,PC9
+D45,PC10
+D46,PC11
+D47,PC12
+D48,PD2
+D49,PG2
+D50,PG3
+D51,PD7
+D52,PD6
+D53,PD5
+D54,PD4
+D55,PD3
+D56,PE2
+D57,PE4
+D58,PE5
+D59,PE6
+D60,PE3
+D61,PF8
+D62,PF7
+D63,PF9
+D64,PG1
+D65,PG0
+D66,PD1
+D67,PD0
+D68,PF0
+D69,PF1
+D70,PF2
+D71,PA7
+LED1,PB0
+LED2,PB7
+LED3,PB14
+SW,PC13
+SD_SW,PC13
+OTG_FS_POWER,PG6
+OTG_FS_OVER_CURRENT,PG7
+USB_VBUS,PA9
+USB_ID,PA10
+USB_DM,PA11
+USB_DP,PA12
+USB_POWER,PG6
+VCP_TX,PD8
+VCP_RX,PD9
+UART2_TX,PD5
+UART2_RX,PD6
+UART2_RTS,PD4
+UART2_CTS,PD3
+UART6_TX,PG14
+UART6_RX,PG9
+SPI_B_NSS,PA4
+SPI_B_SCK,PB3
+SPI_B_MOSI,PB5
diff --git a/ports/stm32/boards/NUCLEO_F722ZE/stm32f7xx_hal_conf.h b/ports/stm32/boards/NUCLEO_F722ZE/stm32f7xx_hal_conf.h
new file mode 100644
index 000000000..9355a3867
--- /dev/null
+++ b/ports/stm32/boards/NUCLEO_F722ZE/stm32f7xx_hal_conf.h
@@ -0,0 +1,18 @@
+/* This file is part of the MicroPython project, http://micropython.org/
+ * MIT License; Copyright (c) 2019 Damien P. George
+ */
+#ifndef MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H
+#define MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H
+
+#include "boards/stm32f7xx_hal_conf_base.h"
+
+// Oscillator values in Hz
+#define HSE_VALUE (8000000)
+#define LSE_VALUE (32768)
+#define EXTERNAL_CLOCK_VALUE (12288000)
+
+// Oscillator timeouts in ms
+#define HSE_STARTUP_TIMEOUT (5000)
+#define LSE_STARTUP_TIMEOUT (5000)
+
+#endif // MICROPY_INCLUDED_STM32F7XX_HAL_CONF_H
-- 
GitLab