summaryrefslogtreecommitdiff
path: root/ports/stm32f4/supervisor
diff options
context:
space:
mode:
Diffstat (limited to 'ports/stm32f4/supervisor')
-rwxr-xr-xports/stm32f4/supervisor/cpu.s27
-rw-r--r--ports/stm32f4/supervisor/internal_flash.c73
-rw-r--r--ports/stm32f4/supervisor/internal_flash.h37
-rw-r--r--ports/stm32f4/supervisor/internal_flash_root_pointers.h31
-rw-r--r--ports/stm32f4/supervisor/port.c80
-rw-r--r--ports/stm32f4/supervisor/qspi_flash.c162
-rw-r--r--ports/stm32f4/supervisor/serial.c75
-rw-r--r--ports/stm32f4/supervisor/usb.c80
8 files changed, 565 insertions, 0 deletions
diff --git a/ports/stm32f4/supervisor/cpu.s b/ports/stm32f4/supervisor/cpu.s
new file mode 100755
index 000000000..9e6807a5e
--- /dev/null
+++ b/ports/stm32f4/supervisor/cpu.s
@@ -0,0 +1,27 @@
+.syntax unified
+.cpu cortex-m4
+.thumb
+.text
+.align 2
+
+@ uint cpu_get_regs_and_sp(r0=uint regs[10])
+.global cpu_get_regs_and_sp
+.thumb
+.thumb_func
+.type cpu_get_regs_and_sp, %function
+cpu_get_regs_and_sp:
+@ store registers into given array
+str r4, [r0], #4
+str r5, [r0], #4
+str r6, [r0], #4
+str r7, [r0], #4
+str r8, [r0], #4
+str r9, [r0], #4
+str r10, [r0], #4
+str r11, [r0], #4
+str r12, [r0], #4
+str r13, [r0], #4
+
+@ return the sp
+mov r0, sp
+bx lr
diff --git a/ports/stm32f4/supervisor/internal_flash.c b/ports/stm32f4/supervisor/internal_flash.c
new file mode 100644
index 000000000..fa776ae1d
--- /dev/null
+++ b/ports/stm32f4/supervisor/internal_flash.c
@@ -0,0 +1,73 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013, 2014 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.
+ */
+#include "supervisor/flash.h"
+
+#include <stdint.h>
+#include <string.h>
+
+#include "extmod/vfs.h"
+#include "extmod/vfs_fat.h"
+#include "py/mphal.h"
+#include "py/obj.h"
+#include "py/runtime.h"
+#include "lib/oofatfs/ff.h"
+
+
+/*------------------------------------------------------------------*/
+/* Internal Flash API
+ *------------------------------------------------------------------*/
+static inline uint32_t lba2addr(uint32_t block) {
+}
+
+void supervisor_flash_init(void) {
+}
+
+uint32_t supervisor_flash_get_block_size(void) {
+ return FILESYSTEM_BLOCK_SIZE;
+}
+
+uint32_t supervisor_flash_get_block_count(void) {
+ return false;
+}
+
+void supervisor_flash_flush(void) {
+
+}
+
+mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) {
+
+ return 0; // success
+}
+
+mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32_t num_blocks) {
+
+
+ return 0; // success
+}
+
+void supervisor_flash_release_cache(void) {
+}
+
diff --git a/ports/stm32f4/supervisor/internal_flash.h b/ports/stm32f4/supervisor/internal_flash.h
new file mode 100644
index 000000000..8c015a3e4
--- /dev/null
+++ b/ports/stm32f4/supervisor/internal_flash.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2013, 2014 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_STM32F4_INTERNAL_FLASH_H
+#define MICROPY_INCLUDED_STM32F4_INTERNAL_FLASH_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "py/mpconfig.h"
+
+#define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms
+#define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2)
+
+#endif // MICROPY_INCLUDED_STM32F4_INTERNAL_FLASH_H
diff --git a/ports/stm32f4/supervisor/internal_flash_root_pointers.h b/ports/stm32f4/supervisor/internal_flash_root_pointers.h
new file mode 100644
index 000000000..7a8681bd9
--- /dev/null
+++ b/ports/stm32f4/supervisor/internal_flash_root_pointers.h
@@ -0,0 +1,31 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 Scott Shawcroft for Adafruit Industries LLC
+ *
+ * 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_STM32F4_INTERNAL_FLASH_ROOT_POINTERS_H
+#define MICROPY_INCLUDED_STM32F4_INTERNAL_FLASH_ROOT_POINTERS_H
+
+#define FLASH_ROOT_POINTERS
+
+#endif // MICROPY_INCLUDED_STM32F4_INTERNAL_FLASH_ROOT_POINTERS_H
diff --git a/ports/stm32f4/supervisor/port.c b/ports/stm32f4/supervisor/port.c
new file mode 100644
index 000000000..af4d1b8d8
--- /dev/null
+++ b/ports/stm32f4/supervisor/port.c
@@ -0,0 +1,80 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ * Copyright (c) 2019 Lucian Copeland 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 "tick.h"
+
+#include "stm32f4/clocks.h"
+#include "stm32f4/gpio.h"
+
+#include "stm32f4xx_hal.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();
+
+ stm32f4_peripherals_clocks_init();
+ stm32f4_peripherals_gpio_init();
+
+ tick_init();
+ board_init();
+
+ 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) {
+
+// }
diff --git a/ports/stm32f4/supervisor/qspi_flash.c b/ports/stm32f4/supervisor/qspi_flash.c
new file mode 100644
index 000000000..f3915273b
--- /dev/null
+++ b/ports/stm32f4/supervisor/qspi_flash.c
@@ -0,0 +1,162 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 hathach for Adafruit Industries
+ * Copyright (c) 2018 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 "supervisor/spi_flash_api.h"
+
+#include <stdint.h>
+#include <string.h>
+
+#include "py/mpconfig.h" // for EXTERNAL_FLASH_QSPI_DUAL
+//#include "nrfx_qspi.h"
+
+//#include "shared-bindings/microcontroller/__init__.h"
+
+#include "supervisor/shared/external_flash/common_commands.h"
+#include "supervisor/shared/external_flash/qspi_flash.h"
+
+bool spi_flash_command(uint8_t command) {
+ // nrf_qspi_cinstr_conf_t cinstr_cfg = {
+ // .opcode = command,
+ // .length = 1,
+ // .io2_level = true,
+ // .io3_level = true,
+ // .wipwait = false,
+ // .wren = false
+ // };
+ return false; //nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, NULL) == NRFX_SUCCESS;
+}
+
+bool spi_flash_read_command(uint8_t command, uint8_t* response, uint32_t length) {
+ // nrf_qspi_cinstr_conf_t cinstr_cfg = {
+ // .opcode = command,
+ // .length = length + 1,
+ // .io2_level = true,
+ // .io3_level = true,
+ // .wipwait = false,
+ // .wren = false
+ // };
+ // return nrfx_qspi_cinstr_xfer(&cinstr_cfg, NULL, response) == NRFX_SUCCESS;
+ return false;
+
+}
+
+bool spi_flash_write_command(uint8_t command, uint8_t* data, uint32_t length) {
+ // nrf_qspi_cinstr_conf_t cinstr_cfg = {
+ // .opcode = command,
+ // .length = length + 1,
+ // .io2_level = true,
+ // .io3_level = true,
+ // .wipwait = false,
+ // .wren = false // We do this manually.
+ // };
+ // return nrfx_qspi_cinstr_xfer(&cinstr_cfg, data, NULL) == NRFX_SUCCESS;
+ return false;
+}
+
+bool spi_flash_sector_command(uint8_t command, uint32_t address) {
+ // if (command != CMD_SECTOR_ERASE) {
+ // return false;
+ // }
+ // return nrfx_qspi_erase(NRF_QSPI_ERASE_LEN_4KB, address) == NRFX_SUCCESS;
+ return false;
+}
+
+bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t length) {
+ // return nrfx_qspi_write(data, length, address) == NRFX_SUCCESS;
+ return false;
+}
+
+bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t length) {
+ // return nrfx_qspi_read(data, length, address) == NRFX_SUCCESS;
+ return false;
+}
+
+void spi_flash_init(void) {
+ // Init QSPI flash
+// nrfx_qspi_config_t qspi_cfg = {
+// .xip_offset = 0,
+// .pins = {
+// .sck_pin = MICROPY_QSPI_SCK,
+// .csn_pin = MICROPY_QSPI_CS,
+// .io0_pin = MICROPY_QSPI_DATA0,
+// .io1_pin = NRF_QSPI_PIN_NOT_CONNECTED,
+// .io2_pin = NRF_QSPI_PIN_NOT_CONNECTED,
+// .io3_pin = NRF_QSPI_PIN_NOT_CONNECTED,
+
+// },
+// .prot_if = {
+// .readoc = NRF_QSPI_READOC_FASTREAD,
+// .writeoc = NRF_QSPI_WRITEOC_PP,
+// .addrmode = NRF_QSPI_ADDRMODE_24BIT,
+// .dpmconfig = false
+// },
+// .phy_if = {
+// .sck_freq = NRF_QSPI_FREQ_32MDIV16, // Start at a slow 2MHz and speed up once we know what we're talking to.
+// .sck_delay = 10, // min time CS must stay high before going low again. in unit of 62.5 ns
+// .spi_mode = NRF_QSPI_MODE_0,
+// .dpmen = false
+// },
+// .irq_priority = 7,
+// };
+
+// #if EXTERNAL_FLASH_QSPI_DUAL
+// qspi_cfg.pins.io1_pin = MICROPY_QSPI_DATA1;
+// qspi_cfg.prot_if.readoc = NRF_QSPI_READOC_READ2O;
+// qspi_cfg.prot_if.writeoc = NRF_QSPI_WRITEOC_PP2O;
+// #else
+// qspi_cfg.pins.io1_pin = MICROPY_QSPI_DATA1;
+// qspi_cfg.pins.io2_pin = MICROPY_QSPI_DATA2;
+// qspi_cfg.pins.io3_pin = MICROPY_QSPI_DATA3;
+// qspi_cfg.prot_if.readoc = NRF_QSPI_READOC_READ4IO;
+// qspi_cfg.prot_if.writeoc = NRF_QSPI_WRITEOC_PP4O;
+// #endif
+
+// // No callback for blocking API
+// nrfx_qspi_init(&qspi_cfg, NULL, NULL);
+}
+
+void spi_flash_init_device(const external_flash_device* device) {
+ // check_quad_enable(device);
+
+ // // Switch to single output line if the device doesn't support quad programs.
+ // if (!device->supports_qspi_writes) {
+ // NRF_QSPI->IFCONFIG0 &= ~QSPI_IFCONFIG0_WRITEOC_Msk;
+ // NRF_QSPI->IFCONFIG0 |= QSPI_IFCONFIG0_WRITEOC_PP << QSPI_IFCONFIG0_WRITEOC_Pos;
+ // }
+
+ // // Speed up as much as we can.
+ // // Start at 16 MHz and go down.
+ // // At 32 MHz GD25Q16C doesn't work reliably on Feather 52840, even though it should work up to 104 MHz.
+ // // sckfreq = 0 is 32 Mhz
+ // // sckfreq = 1 is 16 MHz, etc.
+ // uint8_t sckfreq = 1;
+ // while (32000000 / (sckfreq + 1) > device->max_clock_speed_mhz * 1000000 && sckfreq < 16) {
+ // sckfreq += 1;
+ // }
+ // NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_SCKFREQ_Msk;
+ // NRF_QSPI->IFCONFIG1 |= sckfreq << QSPI_IFCONFIG1_SCKFREQ_Pos;
+}
diff --git a/ports/stm32f4/supervisor/serial.c b/ports/stm32f4/supervisor/serial.c
new file mode 100644
index 000000000..3154dc3e5
--- /dev/null
+++ b/ports/stm32f4/supervisor/serial.c
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017, 2018 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 "py/mphal.h"
+#include <string.h>
+#include "supervisor/serial.h"
+#include "stm32f4xx_hal.h"
+
+UART_HandleTypeDef huart2;
+
+void serial_init(void) {
+ huart2.Instance = USART2;
+ huart2.Init.BaudRate = 9600;
+ 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;
+ if (HAL_UART_Init(&huart2) == HAL_OK)
+ {
+ //HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
+ }
+ //HAL_UART_Transmit(&huart2, (uint8_t*)"Serial On", 9, 5000);
+ //HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET);
+}
+
+bool serial_connected(void) {
+ return true;
+}
+
+char serial_read(void) {
+ uint8_t data;
+ HAL_UART_Receive(&huart2, &data, 1,5000);
+ return data;
+}
+
+bool serial_bytes_available(void) {
+ return __HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE);
+}
+
+void serial_write(const char* text) {
+ serial_write_substring(text, strlen(text));
+}
+
+void serial_write_substring(const char *text, uint32_t len) {
+ if (len == 0) {
+ return;
+ }
+ HAL_UART_Transmit(&huart2, (uint8_t*)text, len, 5000);
+}
+
diff --git a/ports/stm32f4/supervisor/usb.c b/ports/stm32f4/supervisor/usb.c
new file mode 100644
index 000000000..913523523
--- /dev/null
+++ b/ports/stm32f4/supervisor/usb.c
@@ -0,0 +1,80 @@
+/*
+ * This file is part of the Micro Python project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2018 hathach 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 "tick.h"
+#include "supervisor/usb.h"
+#include "lib/utils/interrupt_char.h"
+#include "lib/mp-readline/readline.h"
+#include "stm32f4xx_hal.h"
+
+#define USB_OTGFS_VBUS_Pin GPIO_PIN_9
+#define USB_OTGFS_VBUS_GPIO_Port GPIOA
+#define USB_OTGFS_ID_Pin GPIO_PIN_10
+#define USB_OTGFS_ID_GPIO_Port GPIOA
+#define USB_OTGFS_DM_Pin GPIO_PIN_11
+#define USB_OTGFS_DM_GPIO_Port GPIOA
+#define USB_OTGFS_DP_Pin GPIO_PIN_12
+#define USB_OTGFS_DP_GPIO_Port GPIOA
+
+
+void init_usb_hardware(void) {
+ // HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET); //LED 2
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
+ /**USB_OTG_FS GPIO Configuration
+ PA10 ------> USB_OTG_FS_ID
+ PA11 ------> USB_OTG_FS_DM
+ PA12 ------> USB_OTG_FS_DP
+ */
+ GPIO_InitStruct.Pin = USB_OTGFS_VBUS_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ HAL_GPIO_Init(USB_OTGFS_VBUS_GPIO_Port, &GPIO_InitStruct);
+
+ GPIO_InitStruct.Pin = USB_OTGFS_DM_Pin|USB_OTGFS_DP_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ //TinyUSB suggestion
+ GPIO_InitStruct.Pin = USB_OTGFS_ID_Pin;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /* Peripheral clock enable */
+ __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
+
+ /* Peripheral interrupt init */
+ HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
+ HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
+
+ //HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET); //LED 3
+}