From a3673cc79b651a5be1474130313e5b6fa93572d4 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Mon, 22 Jul 2019 17:16:33 -0400 Subject: [PATCH 01/27] Set up for new tinyusb integration. Not yet functional. --- lib/tinyusb | 2 +- main.c | 4 + ports/stm32f4/Makefile | 3 +- ports/stm32f4/mpconfigport.mk | 6 +- ports/stm32f4/supervisor/port.c | 328 ++++++++++----------------- ports/stm32f4/supervisor/port_411.c | 246 -------------------- ports/stm32f4/supervisor/port_F412.c | 326 ++++++++++++++++++++++++++ supervisor/shared/usb/usb.c | 4 +- 8 files changed, 462 insertions(+), 457 deletions(-) delete mode 100644 ports/stm32f4/supervisor/port_411.c create mode 100644 ports/stm32f4/supervisor/port_F412.c diff --git a/lib/tinyusb b/lib/tinyusb index 0848c462b3e43..97e2629d64758 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 0848c462b3e431a9da42e96537d2b597a4579636 +Subproject commit 97e2629d647584681b2883f2081fa2cddb3d61cc diff --git a/main.c b/main.c index 7e1058e94387e..7545425c57ce4 100755 --- a/main.c +++ b/main.c @@ -190,7 +190,11 @@ void cleanup_after_vm(supervisor_allocation* heap) { supervisor_move_memory(); reset_port(); + + #if CIRCUITPY_BOARD reset_board_busses(); + #endif + reset_board(); reset_status_led(); } diff --git a/ports/stm32f4/Makefile b/ports/stm32f4/Makefile index d91b4aa551d89..e2ecd61be9670 100755 --- a/ports/stm32f4/Makefile +++ b/ports/stm32f4/Makefile @@ -185,7 +185,6 @@ SRC_C += \ mphalport.c \ tick.c \ boards/$(BOARD)/board.c \ - boards/$(BOARD)/pins.c \ lib/libc/string0.c \ lib/mp-readline/readline.c \ lib/oofatfs/ff.c \ @@ -198,6 +197,8 @@ SRC_C += \ lib/utils/stdout_helpers.c \ lib/utils/sys_stdio_mphal.c \ supervisor/shared/memory.c + + #boards/$(BOARD)/pins.c \ ifneq ($(USB),FALSE) SRC_C += lib/tinyusb/src/portable/st/stm32f4/dcd_stm32f4.c diff --git a/ports/stm32f4/mpconfigport.mk b/ports/stm32f4/mpconfigport.mk index de8cec321eacd..aec0996be54d5 100644 --- a/ports/stm32f4/mpconfigport.mk +++ b/ports/stm32f4/mpconfigport.mk @@ -34,16 +34,16 @@ CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOIO = 0 CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BLEIO = 0 -CIRCUITPY_BOARD = 1 +CIRCUITPY_BOARD = 0 CIRCUITPY_BUSIO = 0 -CIRCUITPY_DIGITALIO = 1 +CIRCUITPY_DIGITALIO = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_GAMEPAD = 0 CIRCUITPY_GAMEPADSHIFT = 0 CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_MATH = 0 -CIRCUITPY_MICROCONTROLLER = 1 +CIRCUITPY_MICROCONTROLLER = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NETWORK = 0 CIRCUITPY_NVM = 0 diff --git a/ports/stm32f4/supervisor/port.c b/ports/stm32f4/supervisor/port.c index 04c98ab90464c..8a106c477610b 100644 --- a/ports/stm32f4/supervisor/port.c +++ b/ports/stm32f4/supervisor/port.c @@ -32,173 +32,74 @@ //#include "shared-bindings/rtc/__init__.h" #include "stm32f4xx_hal.h" - -#define LED3_Pin GPIO_PIN_2 -#define LED3_GPIO_Port GPIOE -#define LED4_Pin GPIO_PIN_3 -#define LED4_GPIO_Port GPIOE -#define DFSDM_DATIN3_Pin GPIO_PIN_4 -#define DFSDM_DATIN3_GPIO_Port GPIOE -#define A0_Pin GPIO_PIN_0 -#define A0_GPIO_Port GPIOF -#define LCD_BLCTRL_Pin GPIO_PIN_5 -#define LCD_BLCTRL_GPIO_Port GPIOF -#define QSPI_BK1_IO3_Pin GPIO_PIN_6 -#define QSPI_BK1_IO3_GPIO_Port GPIOF -#define QSPI_BK1_IO2_Pin GPIO_PIN_7 -#define QSPI_BK1_IO2_GPIO_Port GPIOF -#define QSPI_BK1_IO0_Pin GPIO_PIN_8 -#define QSPI_BK1_IO0_GPIO_Port GPIOF -#define QSPI_BK1_IO1_Pin GPIO_PIN_9 -#define QSPI_BK1_IO1_GPIO_Port GPIOF -#define STLK_MCO_Pin GPIO_PIN_0 -#define STLK_MCO_GPIO_Port GPIOH -#define DFSDM_CKOUT_Pin GPIO_PIN_2 -#define DFSDM_CKOUT_GPIO_Port GPIOC -#define JOY_SEL_Pin GPIO_PIN_0 -#define JOY_SEL_GPIO_Port GPIOA -#define STLINK_RX_Pin GPIO_PIN_2 -#define STLINK_RX_GPIO_Port GPIOA -#define STLINK_TX_Pin GPIO_PIN_3 -#define STLINK_TX_GPIO_Port GPIOA -#define CODEC_I2S3_WS_Pin GPIO_PIN_4 -#define CODEC_I2S3_WS_GPIO_Port GPIOA -#define DFSDM_DATIN0_Pin GPIO_PIN_1 -#define DFSDM_DATIN0_GPIO_Port GPIOB -#define QSPI_CLK_Pin GPIO_PIN_2 -#define QSPI_CLK_GPIO_Port GPIOB -#define EXT_RESET_Pin GPIO_PIN_11 -#define EXT_RESET_GPIO_Port GPIOF -#define CTP_RST_Pin GPIO_PIN_12 -#define CTP_RST_GPIO_Port GPIOF -#define JOY_RIGHT_Pin GPIO_PIN_14 -#define JOY_RIGHT_GPIO_Port GPIOF -#define JOY_LEFT_Pin GPIO_PIN_15 -#define JOY_LEFT_GPIO_Port GPIOF -#define JOY_UP_Pin GPIO_PIN_0 -#define JOY_UP_GPIO_Port GPIOG -#define JOY_DOWN_Pin GPIO_PIN_1 -#define JOY_DOWN_GPIO_Port GPIOG -#define D4_Pin GPIO_PIN_7 -#define D4_GPIO_Port GPIOE -#define D5_Pin GPIO_PIN_8 -#define D5_GPIO_Port GPIOE -#define D6_Pin GPIO_PIN_9 -#define D6_GPIO_Port GPIOE -#define D7_Pin GPIO_PIN_10 -#define D7_GPIO_Port GPIOE -#define D8_Pin GPIO_PIN_11 -#define D8_GPIO_Port GPIOE -#define D9_Pin GPIO_PIN_12 -#define D9_GPIO_Port GPIOE -#define D10_Pin GPIO_PIN_13 -#define D10_GPIO_Port GPIOE -#define D11_Pin GPIO_PIN_14 -#define D11_GPIO_Port GPIOE -#define D12_Pin GPIO_PIN_15 -#define D12_GPIO_Port GPIOE -#define I2C2_SCL_Pin GPIO_PIN_10 -#define I2C2_SCL_GPIO_Port GPIOB -#define M2_CKIN_Pin GPIO_PIN_11 -#define M2_CKIN_GPIO_Port GPIOB -#define CODEC_I2S3_SCK_Pin GPIO_PIN_12 -#define CODEC_I2S3_SCK_GPIO_Port GPIOB -#define D13_Pin GPIO_PIN_8 -#define D13_GPIO_Port GPIOD -#define D14_Pin GPIO_PIN_9 -#define D14_GPIO_Port GPIOD -#define D15_Pin GPIO_PIN_10 -#define D15_GPIO_Port GPIOD -#define LCD_RESET_Pin GPIO_PIN_11 -#define LCD_RESET_GPIO_Port GPIOD -#define D0_Pin GPIO_PIN_14 -#define D0_GPIO_Port GPIOD -#define D1_Pin GPIO_PIN_15 -#define D1_GPIO_Port GPIOD -#define CODEC_INT_Pin GPIO_PIN_2 -#define CODEC_INT_GPIO_Port GPIOG -#define LCD_TE_Pin GPIO_PIN_4 -#define LCD_TE_GPIO_Port GPIOG -#define CTP_INT_Pin GPIO_PIN_5 -#define CTP_INT_GPIO_Port GPIOG -#define QSPI_BK1_NCS_Pin GPIO_PIN_6 -#define QSPI_BK1_NCS_GPIO_Port GPIOG -#define USB_OTGFS_OVRCR_Pin GPIO_PIN_7 -#define USB_OTGFS_OVRCR_GPIO_Port GPIOG -#define USB_OTGFS_PPWR_EN_Pin GPIO_PIN_8 -#define USB_OTGFS_PPWR_EN_GPIO_Port GPIOG -#define CODEC_I2S3_MCK_Pin GPIO_PIN_7 -#define CODEC_I2S3_MCK_GPIO_Port GPIOC -#define uSD_D0_Pin GPIO_PIN_8 -#define uSD_D0_GPIO_Port GPIOC -#define uSD_D1_Pin GPIO_PIN_9 -#define uSD_D1_GPIO_Port GPIOC -#define M2_CKINA8_Pin GPIO_PIN_8 -#define M2_CKINA8_GPIO_Port GPIOA -#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 +#define DATA_Ready_Pin GPIO_PIN_2 +#define DATA_Ready_GPIO_Port GPIOE +#define CS_I2C_SPI_Pin GPIO_PIN_3 +#define CS_I2C_SPI_GPIO_Port GPIOE +#define INT1_Pin GPIO_PIN_4 +#define INT1_GPIO_Port GPIOE +#define INT2_Pin GPIO_PIN_5 +#define INT2_GPIO_Port GPIOE +#define PC14_OSC32_IN_Pin GPIO_PIN_14 +#define PC14_OSC32_IN_GPIO_Port GPIOC +#define PC15_OSC32_OUT_Pin GPIO_PIN_15 +#define PC15_OSC32_OUT_GPIO_Port GPIOC +#define PH0_OSC_IN_Pin GPIO_PIN_0 +#define PH0_OSC_IN_GPIO_Port GPIOH +#define PH1_OSC_OUT_Pin GPIO_PIN_1 +#define PH1_OSC_OUT_GPIO_Port GPIOH +#define OTG_FS_PowerSwitchOn_Pin GPIO_PIN_0 +#define OTG_FS_PowerSwitchOn_GPIO_Port GPIOC +#define PDM_OUT_Pin GPIO_PIN_3 +#define PDM_OUT_GPIO_Port GPIOC +#define I2S3_WS_Pin GPIO_PIN_4 +#define I2S3_WS_GPIO_Port GPIOA +#define SPI1_SCK_Pin GPIO_PIN_5 +#define SPI1_SCK_GPIO_Port GPIOA +#define SPI1_MISO_Pin GPIO_PIN_6 +#define SPI1_MISO_GPIO_Port GPIOA +#define SPI1_MOSI_Pin GPIO_PIN_7 +#define SPI1_MOSI_GPIO_Port GPIOA +#define CLK_IN_Pin GPIO_PIN_10 +#define CLK_IN_GPIO_Port GPIOB +#define LD4_Pin GPIO_PIN_12 +#define LD4_GPIO_Port GPIOD +#define LD3_Pin GPIO_PIN_13 +#define LD3_GPIO_Port GPIOD +#define LD5_Pin GPIO_PIN_14 +#define LD5_GPIO_Port GPIOD +#define LD6_Pin GPIO_PIN_15 +#define LD6_GPIO_Port GPIOD +#define I2S3_MCK_Pin GPIO_PIN_7 +#define I2S3_MCK_GPIO_Port GPIOC +#define VBUS_FS_Pin GPIO_PIN_9 +#define VBUS_FS_GPIO_Port GPIOA +#define OTG_FS_ID_Pin GPIO_PIN_10 +#define OTG_FS_ID_GPIO_Port GPIOA +#define OTG_FS_DM_Pin GPIO_PIN_11 +#define OTG_FS_DM_GPIO_Port GPIOA +#define OTG_FS_DP_Pin GPIO_PIN_12 +#define OTG_FS_DP_GPIO_Port GPIOA #define SWDIO_Pin GPIO_PIN_13 #define SWDIO_GPIO_Port GPIOA #define SWCLK_Pin GPIO_PIN_14 #define SWCLK_GPIO_Port GPIOA -#define uSD_D2_Pin GPIO_PIN_10 -#define uSD_D2_GPIO_Port GPIOC -#define uSD_D3_Pin GPIO_PIN_11 -#define uSD_D3_GPIO_Port GPIOC -#define uSD_CLK_Pin GPIO_PIN_12 -#define uSD_CLK_GPIO_Port GPIOC -#define D2_Pin GPIO_PIN_0 -#define D2_GPIO_Port GPIOD -#define D3_Pin GPIO_PIN_1 -#define D3_GPIO_Port GPIOD -#define uSD_CMD_Pin GPIO_PIN_2 -#define uSD_CMD_GPIO_Port GPIOD -#define uSD_DETECT_Pin GPIO_PIN_3 -#define uSD_DETECT_GPIO_Port GPIOD -#define FMC_NOE_Pin GPIO_PIN_4 -#define FMC_NOE_GPIO_Port GPIOD -#define FMC_NWE_Pin GPIO_PIN_5 -#define FMC_NWE_GPIO_Port GPIOD -#define FMC_NE1_Pin GPIO_PIN_7 -#define FMC_NE1_GPIO_Port GPIOD +#define I2S3_SCK_Pin GPIO_PIN_10 +#define I2S3_SCK_GPIO_Port GPIOC +#define I2S3_SD_Pin GPIO_PIN_12 +#define I2S3_SD_GPIO_Port GPIOC +#define Audio_RST_Pin GPIO_PIN_4 +#define Audio_RST_GPIO_Port GPIOD +#define OTG_FS_OverCurrent_Pin GPIO_PIN_5 +#define OTG_FS_OverCurrent_GPIO_Port GPIOD #define SWO_Pin GPIO_PIN_3 #define SWO_GPIO_Port GPIOB -#define CODEC_I2S3ext_SD_Pin GPIO_PIN_4 -#define CODEC_I2S3ext_SD_GPIO_Port GPIOB -#define CODEC_I2S3_SD_Pin GPIO_PIN_5 -#define CODEC_I2S3_SD_GPIO_Port GPIOB -#define I2C1_SCL_Pin GPIO_PIN_6 -#define I2C1_SCL_GPIO_Port GPIOB -#define I2C1_SDA_Pin GPIO_PIN_7 -#define I2C1_SDA_GPIO_Port GPIOB -#define I2C2_SDA_Pin GPIO_PIN_9 -#define I2C2_SDA_GPIO_Port GPIOB -#define LED1_Pin GPIO_PIN_0 -#define LED1_GPIO_Port GPIOE -#define LED2_Pin GPIO_PIN_1 -#define LED2_GPIO_Port GPIOE - -/* -#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 "shared-bindings/rtc/__init__.h" +#define Audio_SCL_Pin GPIO_PIN_6 +#define Audio_SCL_GPIO_Port GPIOB +#define Audio_SDA_Pin GPIO_PIN_9 +#define Audio_SDA_GPIO_Port GPIOB +#define MEMS_INT2_Pin GPIO_PIN_1 +#define MEMS_INT2_GPIO_Port GPIOE static void power_warning_handler(void) { reset_into_safe_mode(BROWNOUT); @@ -207,7 +108,7 @@ static void power_warning_handler(void) { safe_mode_t port_init(void) { HAL_Init(); - //System clock init + //sys clock RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; @@ -217,17 +118,14 @@ safe_mode_t port_init(void) { __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the CPU, AHB and APB busses clocks */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; - 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_HSE; RCC_OscInitStruct.PLL.PLLM = 4; - RCC_OscInitStruct.PLL.PLLN = 72; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - RCC_OscInitStruct.PLL.PLLQ = 3; - RCC_OscInitStruct.PLL.PLLR = 2; + RCC_OscInitStruct.PLL.PLLN = 192; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; + RCC_OscInitStruct.PLL.PLLQ = 8; HAL_RCC_OscConfig(&RCC_OscInitStruct); /** Initializes the CPU, AHB and APB busses clocks */ @@ -235,64 +133,86 @@ safe_mode_t port_init(void) { |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.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); - - PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S_APB1|RCC_PERIPHCLK_SDIO - |RCC_PERIPHCLK_CLK48; - PeriphClkInitStruct.PLLI2S.PLLI2SN = 50; - PeriphClkInitStruct.PLLI2S.PLLI2SM = 4; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3); + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S; + PeriphClkInitStruct.PLLI2S.PLLI2SN = 200; + PeriphClkInitStruct.PLLI2S.PLLI2SM = 5; PeriphClkInitStruct.PLLI2S.PLLI2SR = 2; - PeriphClkInitStruct.PLLI2S.PLLI2SQ = 2; - PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLQ; - PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48; - PeriphClkInitStruct.PLLI2SSelection = RCC_PLLI2SCLKSOURCE_PLLSRC; - PeriphClkInitStruct.I2sApb1ClockSelection = RCC_I2SAPB1CLKSOURCE_PLLI2S; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); - HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); - - //GPIO Init + //GPIO setup GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); + /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOE, LED3_Pin|LED4_Pin|LED1_Pin|LED2_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOF, LCD_BLCTRL_Pin|EXT_RESET_Pin|CTP_RST_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_RESET); + HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET); + /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(USB_OTGFS_PPWR_EN_GPIO_Port, USB_OTGFS_PPWR_EN_Pin, GPIO_PIN_SET); - /*Configure GPIO pins : LED3_Pin LED4_Pin LED1_Pin LED2_Pin */ - GPIO_InitStruct.Pin = LED3_Pin|LED4_Pin|LED1_Pin|LED2_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin + |Audio_RST_Pin, GPIO_PIN_RESET); + + /*Configure GPIO pin : DATA_Ready_Pin */ + GPIO_InitStruct.Pin = DATA_Ready_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(DATA_Ready_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pin : CS_I2C_SPI_Pin */ + GPIO_InitStruct.Pin = CS_I2C_SPI_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(CS_I2C_SPI_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pins : INT1_Pin INT2_Pin MEMS_INT2_Pin */ + GPIO_InitStruct.Pin = INT1_Pin|INT2_Pin|MEMS_INT2_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; + GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - /*Configure GPIO pin : USB_OTGFS_PPWR_EN_Pin */ - GPIO_InitStruct.Pin = USB_OTGFS_PPWR_EN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + + /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */ + GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct); + + /*Configure GPIO pin : PA0 */ + GPIO_InitStruct.Pin = GPIO_PIN_0; + GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin + Audio_RST_Pin */ + GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin + |Audio_RST_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(USB_OTGFS_PPWR_EN_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + + /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */ + GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct); //Status LED chain - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_0, GPIO_PIN_RESET); //LED 1 - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET); //LED 2 - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET); //LED 3 - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_SET); //LED 4 + HAL_GPIO_WritePin(GPIOD, LD4_Pin, GPIO_PIN_RESET); //LED 1 + HAL_GPIO_WritePin(GPIOD, LD3_Pin, GPIO_PIN_SET); //LED 2 + HAL_GPIO_WritePin(GPIOD, LD5_Pin, GPIO_PIN_SET); //LED 3 + HAL_GPIO_WritePin(GPIOD, LD6_Pin, GPIO_PIN_SET); //LED 4 tick_init(); - // HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); board_init(); diff --git a/ports/stm32f4/supervisor/port_411.c b/ports/stm32f4/supervisor/port_411.c deleted file mode 100644 index 8a106c477610b..0000000000000 --- a/ports/stm32f4/supervisor/port_411.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * 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 -#include "supervisor/port.h" -#include "boards/board.h" - -#include "tick.h" -//#include "shared-bindings/rtc/__init__.h" - -#include "stm32f4xx_hal.h" -#define DATA_Ready_Pin GPIO_PIN_2 -#define DATA_Ready_GPIO_Port GPIOE -#define CS_I2C_SPI_Pin GPIO_PIN_3 -#define CS_I2C_SPI_GPIO_Port GPIOE -#define INT1_Pin GPIO_PIN_4 -#define INT1_GPIO_Port GPIOE -#define INT2_Pin GPIO_PIN_5 -#define INT2_GPIO_Port GPIOE -#define PC14_OSC32_IN_Pin GPIO_PIN_14 -#define PC14_OSC32_IN_GPIO_Port GPIOC -#define PC15_OSC32_OUT_Pin GPIO_PIN_15 -#define PC15_OSC32_OUT_GPIO_Port GPIOC -#define PH0_OSC_IN_Pin GPIO_PIN_0 -#define PH0_OSC_IN_GPIO_Port GPIOH -#define PH1_OSC_OUT_Pin GPIO_PIN_1 -#define PH1_OSC_OUT_GPIO_Port GPIOH -#define OTG_FS_PowerSwitchOn_Pin GPIO_PIN_0 -#define OTG_FS_PowerSwitchOn_GPIO_Port GPIOC -#define PDM_OUT_Pin GPIO_PIN_3 -#define PDM_OUT_GPIO_Port GPIOC -#define I2S3_WS_Pin GPIO_PIN_4 -#define I2S3_WS_GPIO_Port GPIOA -#define SPI1_SCK_Pin GPIO_PIN_5 -#define SPI1_SCK_GPIO_Port GPIOA -#define SPI1_MISO_Pin GPIO_PIN_6 -#define SPI1_MISO_GPIO_Port GPIOA -#define SPI1_MOSI_Pin GPIO_PIN_7 -#define SPI1_MOSI_GPIO_Port GPIOA -#define CLK_IN_Pin GPIO_PIN_10 -#define CLK_IN_GPIO_Port GPIOB -#define LD4_Pin GPIO_PIN_12 -#define LD4_GPIO_Port GPIOD -#define LD3_Pin GPIO_PIN_13 -#define LD3_GPIO_Port GPIOD -#define LD5_Pin GPIO_PIN_14 -#define LD5_GPIO_Port GPIOD -#define LD6_Pin GPIO_PIN_15 -#define LD6_GPIO_Port GPIOD -#define I2S3_MCK_Pin GPIO_PIN_7 -#define I2S3_MCK_GPIO_Port GPIOC -#define VBUS_FS_Pin GPIO_PIN_9 -#define VBUS_FS_GPIO_Port GPIOA -#define OTG_FS_ID_Pin GPIO_PIN_10 -#define OTG_FS_ID_GPIO_Port GPIOA -#define OTG_FS_DM_Pin GPIO_PIN_11 -#define OTG_FS_DM_GPIO_Port GPIOA -#define OTG_FS_DP_Pin GPIO_PIN_12 -#define OTG_FS_DP_GPIO_Port GPIOA -#define SWDIO_Pin GPIO_PIN_13 -#define SWDIO_GPIO_Port GPIOA -#define SWCLK_Pin GPIO_PIN_14 -#define SWCLK_GPIO_Port GPIOA -#define I2S3_SCK_Pin GPIO_PIN_10 -#define I2S3_SCK_GPIO_Port GPIOC -#define I2S3_SD_Pin GPIO_PIN_12 -#define I2S3_SD_GPIO_Port GPIOC -#define Audio_RST_Pin GPIO_PIN_4 -#define Audio_RST_GPIO_Port GPIOD -#define OTG_FS_OverCurrent_Pin GPIO_PIN_5 -#define OTG_FS_OverCurrent_GPIO_Port GPIOD -#define SWO_Pin GPIO_PIN_3 -#define SWO_GPIO_Port GPIOB -#define Audio_SCL_Pin GPIO_PIN_6 -#define Audio_SCL_GPIO_Port GPIOB -#define Audio_SDA_Pin GPIO_PIN_9 -#define Audio_SDA_GPIO_Port GPIOB -#define MEMS_INT2_Pin GPIO_PIN_1 -#define MEMS_INT2_GPIO_Port GPIOE - -static void power_warning_handler(void) { - reset_into_safe_mode(BROWNOUT); -} - -safe_mode_t port_init(void) { - HAL_Init(); - - //sys clock - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {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_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 4; - RCC_OscInitStruct.PLL.PLLN = 192; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; - RCC_OscInitStruct.PLL.PLLQ = 8; - HAL_RCC_OscConfig(&RCC_OscInitStruct); - /** 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_DIV4; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3); - PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S; - PeriphClkInitStruct.PLLI2S.PLLI2SN = 200; - PeriphClkInitStruct.PLLI2S.PLLI2SM = 5; - PeriphClkInitStruct.PLLI2S.PLLI2SR = 2; - HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); - - //GPIO setup - GPIO_InitTypeDef GPIO_InitStruct = {0}; - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOE_CLK_ENABLE(); - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOH_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin - |Audio_RST_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin : DATA_Ready_Pin */ - GPIO_InitStruct.Pin = DATA_Ready_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(DATA_Ready_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pin : CS_I2C_SPI_Pin */ - GPIO_InitStruct.Pin = CS_I2C_SPI_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(CS_I2C_SPI_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : INT1_Pin INT2_Pin MEMS_INT2_Pin */ - GPIO_InitStruct.Pin = INT1_Pin|INT2_Pin|MEMS_INT2_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - - /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */ - GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pin : PA0 */ - GPIO_InitStruct.Pin = GPIO_PIN_0; - GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin - Audio_RST_Pin */ - GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin - |Audio_RST_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */ - GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct); - - //Status LED chain - HAL_GPIO_WritePin(GPIOD, LD4_Pin, GPIO_PIN_RESET); //LED 1 - HAL_GPIO_WritePin(GPIOD, LD3_Pin, GPIO_PIN_SET); //LED 2 - HAL_GPIO_WritePin(GPIOD, LD5_Pin, GPIO_PIN_SET); //LED 3 - HAL_GPIO_WritePin(GPIOD, LD6_Pin, GPIO_PIN_SET); //LED 4 - - 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/port_F412.c b/ports/stm32f4/supervisor/port_F412.c new file mode 100644 index 0000000000000..04c98ab90464c --- /dev/null +++ b/ports/stm32f4/supervisor/port_F412.c @@ -0,0 +1,326 @@ +/* + * 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 +#include "supervisor/port.h" +#include "boards/board.h" + +#include "tick.h" +//#include "shared-bindings/rtc/__init__.h" + +#include "stm32f4xx_hal.h" + +#define LED3_Pin GPIO_PIN_2 +#define LED3_GPIO_Port GPIOE +#define LED4_Pin GPIO_PIN_3 +#define LED4_GPIO_Port GPIOE +#define DFSDM_DATIN3_Pin GPIO_PIN_4 +#define DFSDM_DATIN3_GPIO_Port GPIOE +#define A0_Pin GPIO_PIN_0 +#define A0_GPIO_Port GPIOF +#define LCD_BLCTRL_Pin GPIO_PIN_5 +#define LCD_BLCTRL_GPIO_Port GPIOF +#define QSPI_BK1_IO3_Pin GPIO_PIN_6 +#define QSPI_BK1_IO3_GPIO_Port GPIOF +#define QSPI_BK1_IO2_Pin GPIO_PIN_7 +#define QSPI_BK1_IO2_GPIO_Port GPIOF +#define QSPI_BK1_IO0_Pin GPIO_PIN_8 +#define QSPI_BK1_IO0_GPIO_Port GPIOF +#define QSPI_BK1_IO1_Pin GPIO_PIN_9 +#define QSPI_BK1_IO1_GPIO_Port GPIOF +#define STLK_MCO_Pin GPIO_PIN_0 +#define STLK_MCO_GPIO_Port GPIOH +#define DFSDM_CKOUT_Pin GPIO_PIN_2 +#define DFSDM_CKOUT_GPIO_Port GPIOC +#define JOY_SEL_Pin GPIO_PIN_0 +#define JOY_SEL_GPIO_Port GPIOA +#define STLINK_RX_Pin GPIO_PIN_2 +#define STLINK_RX_GPIO_Port GPIOA +#define STLINK_TX_Pin GPIO_PIN_3 +#define STLINK_TX_GPIO_Port GPIOA +#define CODEC_I2S3_WS_Pin GPIO_PIN_4 +#define CODEC_I2S3_WS_GPIO_Port GPIOA +#define DFSDM_DATIN0_Pin GPIO_PIN_1 +#define DFSDM_DATIN0_GPIO_Port GPIOB +#define QSPI_CLK_Pin GPIO_PIN_2 +#define QSPI_CLK_GPIO_Port GPIOB +#define EXT_RESET_Pin GPIO_PIN_11 +#define EXT_RESET_GPIO_Port GPIOF +#define CTP_RST_Pin GPIO_PIN_12 +#define CTP_RST_GPIO_Port GPIOF +#define JOY_RIGHT_Pin GPIO_PIN_14 +#define JOY_RIGHT_GPIO_Port GPIOF +#define JOY_LEFT_Pin GPIO_PIN_15 +#define JOY_LEFT_GPIO_Port GPIOF +#define JOY_UP_Pin GPIO_PIN_0 +#define JOY_UP_GPIO_Port GPIOG +#define JOY_DOWN_Pin GPIO_PIN_1 +#define JOY_DOWN_GPIO_Port GPIOG +#define D4_Pin GPIO_PIN_7 +#define D4_GPIO_Port GPIOE +#define D5_Pin GPIO_PIN_8 +#define D5_GPIO_Port GPIOE +#define D6_Pin GPIO_PIN_9 +#define D6_GPIO_Port GPIOE +#define D7_Pin GPIO_PIN_10 +#define D7_GPIO_Port GPIOE +#define D8_Pin GPIO_PIN_11 +#define D8_GPIO_Port GPIOE +#define D9_Pin GPIO_PIN_12 +#define D9_GPIO_Port GPIOE +#define D10_Pin GPIO_PIN_13 +#define D10_GPIO_Port GPIOE +#define D11_Pin GPIO_PIN_14 +#define D11_GPIO_Port GPIOE +#define D12_Pin GPIO_PIN_15 +#define D12_GPIO_Port GPIOE +#define I2C2_SCL_Pin GPIO_PIN_10 +#define I2C2_SCL_GPIO_Port GPIOB +#define M2_CKIN_Pin GPIO_PIN_11 +#define M2_CKIN_GPIO_Port GPIOB +#define CODEC_I2S3_SCK_Pin GPIO_PIN_12 +#define CODEC_I2S3_SCK_GPIO_Port GPIOB +#define D13_Pin GPIO_PIN_8 +#define D13_GPIO_Port GPIOD +#define D14_Pin GPIO_PIN_9 +#define D14_GPIO_Port GPIOD +#define D15_Pin GPIO_PIN_10 +#define D15_GPIO_Port GPIOD +#define LCD_RESET_Pin GPIO_PIN_11 +#define LCD_RESET_GPIO_Port GPIOD +#define D0_Pin GPIO_PIN_14 +#define D0_GPIO_Port GPIOD +#define D1_Pin GPIO_PIN_15 +#define D1_GPIO_Port GPIOD +#define CODEC_INT_Pin GPIO_PIN_2 +#define CODEC_INT_GPIO_Port GPIOG +#define LCD_TE_Pin GPIO_PIN_4 +#define LCD_TE_GPIO_Port GPIOG +#define CTP_INT_Pin GPIO_PIN_5 +#define CTP_INT_GPIO_Port GPIOG +#define QSPI_BK1_NCS_Pin GPIO_PIN_6 +#define QSPI_BK1_NCS_GPIO_Port GPIOG +#define USB_OTGFS_OVRCR_Pin GPIO_PIN_7 +#define USB_OTGFS_OVRCR_GPIO_Port GPIOG +#define USB_OTGFS_PPWR_EN_Pin GPIO_PIN_8 +#define USB_OTGFS_PPWR_EN_GPIO_Port GPIOG +#define CODEC_I2S3_MCK_Pin GPIO_PIN_7 +#define CODEC_I2S3_MCK_GPIO_Port GPIOC +#define uSD_D0_Pin GPIO_PIN_8 +#define uSD_D0_GPIO_Port GPIOC +#define uSD_D1_Pin GPIO_PIN_9 +#define uSD_D1_GPIO_Port GPIOC +#define M2_CKINA8_Pin GPIO_PIN_8 +#define M2_CKINA8_GPIO_Port GPIOA +#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 +#define SWDIO_Pin GPIO_PIN_13 +#define SWDIO_GPIO_Port GPIOA +#define SWCLK_Pin GPIO_PIN_14 +#define SWCLK_GPIO_Port GPIOA +#define uSD_D2_Pin GPIO_PIN_10 +#define uSD_D2_GPIO_Port GPIOC +#define uSD_D3_Pin GPIO_PIN_11 +#define uSD_D3_GPIO_Port GPIOC +#define uSD_CLK_Pin GPIO_PIN_12 +#define uSD_CLK_GPIO_Port GPIOC +#define D2_Pin GPIO_PIN_0 +#define D2_GPIO_Port GPIOD +#define D3_Pin GPIO_PIN_1 +#define D3_GPIO_Port GPIOD +#define uSD_CMD_Pin GPIO_PIN_2 +#define uSD_CMD_GPIO_Port GPIOD +#define uSD_DETECT_Pin GPIO_PIN_3 +#define uSD_DETECT_GPIO_Port GPIOD +#define FMC_NOE_Pin GPIO_PIN_4 +#define FMC_NOE_GPIO_Port GPIOD +#define FMC_NWE_Pin GPIO_PIN_5 +#define FMC_NWE_GPIO_Port GPIOD +#define FMC_NE1_Pin GPIO_PIN_7 +#define FMC_NE1_GPIO_Port GPIOD +#define SWO_Pin GPIO_PIN_3 +#define SWO_GPIO_Port GPIOB +#define CODEC_I2S3ext_SD_Pin GPIO_PIN_4 +#define CODEC_I2S3ext_SD_GPIO_Port GPIOB +#define CODEC_I2S3_SD_Pin GPIO_PIN_5 +#define CODEC_I2S3_SD_GPIO_Port GPIOB +#define I2C1_SCL_Pin GPIO_PIN_6 +#define I2C1_SCL_GPIO_Port GPIOB +#define I2C1_SDA_Pin GPIO_PIN_7 +#define I2C1_SDA_GPIO_Port GPIOB +#define I2C2_SDA_Pin GPIO_PIN_9 +#define I2C2_SDA_GPIO_Port GPIOB +#define LED1_Pin GPIO_PIN_0 +#define LED1_GPIO_Port GPIOE +#define LED2_Pin GPIO_PIN_1 +#define LED2_GPIO_Port GPIOE + +/* +#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 "shared-bindings/rtc/__init__.h" + +static void power_warning_handler(void) { + reset_into_safe_mode(BROWNOUT); +} + +safe_mode_t port_init(void) { + HAL_Init(); + + //System clock init + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {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_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + 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_HSE; + RCC_OscInitStruct.PLL.PLLM = 4; + RCC_OscInitStruct.PLL.PLLN = 72; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = 3; + RCC_OscInitStruct.PLL.PLLR = 2; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + /** 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; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); + + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S_APB1|RCC_PERIPHCLK_SDIO + |RCC_PERIPHCLK_CLK48; + PeriphClkInitStruct.PLLI2S.PLLI2SN = 50; + PeriphClkInitStruct.PLLI2S.PLLI2SM = 4; + PeriphClkInitStruct.PLLI2S.PLLI2SR = 2; + PeriphClkInitStruct.PLLI2S.PLLI2SQ = 2; + PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLQ; + PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48; + PeriphClkInitStruct.PLLI2SSelection = RCC_PLLI2SCLKSOURCE_PLLSRC; + PeriphClkInitStruct.I2sApb1ClockSelection = RCC_I2SAPB1CLKSOURCE_PLLI2S; + HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); + + HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); + + //GPIO Init + GPIO_InitTypeDef GPIO_InitStruct = {0}; + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOF_CLK_ENABLE(); + __HAL_RCC_GPIOH_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOG_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOE, LED3_Pin|LED4_Pin|LED1_Pin|LED2_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOF, LCD_BLCTRL_Pin|EXT_RESET_Pin|CTP_RST_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(USB_OTGFS_PPWR_EN_GPIO_Port, USB_OTGFS_PPWR_EN_Pin, GPIO_PIN_SET); + /*Configure GPIO pins : LED3_Pin LED4_Pin LED1_Pin LED2_Pin */ + GPIO_InitStruct.Pin = LED3_Pin|LED4_Pin|LED1_Pin|LED2_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + /*Configure GPIO pin : USB_OTGFS_PPWR_EN_Pin */ + GPIO_InitStruct.Pin = USB_OTGFS_PPWR_EN_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(USB_OTGFS_PPWR_EN_GPIO_Port, &GPIO_InitStruct); + + //Status LED chain + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_0, GPIO_PIN_RESET); //LED 1 + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET); //LED 2 + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET); //LED 3 + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_SET); //LED 4 + + tick_init(); + // HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); + + 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/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 0678a3a3fcf97..12db84308ba40 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -40,8 +40,8 @@ extern uint16_t usb_serial_number[1 + COMMON_HAL_MCU_PROCESSOR_UID_LENGTH * 2]; void load_serial_number(void) { // create serial number based on device unique id - uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; - common_hal_mcu_processor_get_uid(raw_id); + uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH] = {1,2,3,4}; + //common_hal_mcu_processor_get_uid(raw_id); static const char nibble_to_hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; From 0dee1a1646d86cdce10fe50c09c23cca411dbd7a Mon Sep 17 00:00:00 2001 From: Hierophect Date: Tue, 23 Jul 2019 17:04:03 -0400 Subject: [PATCH 02/27] Setup for changes --- ports/stm32f4/supervisor/port.c | 78 ++------------------------------- 1 file changed, 4 insertions(+), 74 deletions(-) diff --git a/ports/stm32f4/supervisor/port.c b/ports/stm32f4/supervisor/port.c index 8a106c477610b..515ca7c692ae3 100644 --- a/ports/stm32f4/supervisor/port.c +++ b/ports/stm32f4/supervisor/port.c @@ -29,77 +29,7 @@ #include "boards/board.h" #include "tick.h" -//#include "shared-bindings/rtc/__init__.h" - #include "stm32f4xx_hal.h" -#define DATA_Ready_Pin GPIO_PIN_2 -#define DATA_Ready_GPIO_Port GPIOE -#define CS_I2C_SPI_Pin GPIO_PIN_3 -#define CS_I2C_SPI_GPIO_Port GPIOE -#define INT1_Pin GPIO_PIN_4 -#define INT1_GPIO_Port GPIOE -#define INT2_Pin GPIO_PIN_5 -#define INT2_GPIO_Port GPIOE -#define PC14_OSC32_IN_Pin GPIO_PIN_14 -#define PC14_OSC32_IN_GPIO_Port GPIOC -#define PC15_OSC32_OUT_Pin GPIO_PIN_15 -#define PC15_OSC32_OUT_GPIO_Port GPIOC -#define PH0_OSC_IN_Pin GPIO_PIN_0 -#define PH0_OSC_IN_GPIO_Port GPIOH -#define PH1_OSC_OUT_Pin GPIO_PIN_1 -#define PH1_OSC_OUT_GPIO_Port GPIOH -#define OTG_FS_PowerSwitchOn_Pin GPIO_PIN_0 -#define OTG_FS_PowerSwitchOn_GPIO_Port GPIOC -#define PDM_OUT_Pin GPIO_PIN_3 -#define PDM_OUT_GPIO_Port GPIOC -#define I2S3_WS_Pin GPIO_PIN_4 -#define I2S3_WS_GPIO_Port GPIOA -#define SPI1_SCK_Pin GPIO_PIN_5 -#define SPI1_SCK_GPIO_Port GPIOA -#define SPI1_MISO_Pin GPIO_PIN_6 -#define SPI1_MISO_GPIO_Port GPIOA -#define SPI1_MOSI_Pin GPIO_PIN_7 -#define SPI1_MOSI_GPIO_Port GPIOA -#define CLK_IN_Pin GPIO_PIN_10 -#define CLK_IN_GPIO_Port GPIOB -#define LD4_Pin GPIO_PIN_12 -#define LD4_GPIO_Port GPIOD -#define LD3_Pin GPIO_PIN_13 -#define LD3_GPIO_Port GPIOD -#define LD5_Pin GPIO_PIN_14 -#define LD5_GPIO_Port GPIOD -#define LD6_Pin GPIO_PIN_15 -#define LD6_GPIO_Port GPIOD -#define I2S3_MCK_Pin GPIO_PIN_7 -#define I2S3_MCK_GPIO_Port GPIOC -#define VBUS_FS_Pin GPIO_PIN_9 -#define VBUS_FS_GPIO_Port GPIOA -#define OTG_FS_ID_Pin GPIO_PIN_10 -#define OTG_FS_ID_GPIO_Port GPIOA -#define OTG_FS_DM_Pin GPIO_PIN_11 -#define OTG_FS_DM_GPIO_Port GPIOA -#define OTG_FS_DP_Pin GPIO_PIN_12 -#define OTG_FS_DP_GPIO_Port GPIOA -#define SWDIO_Pin GPIO_PIN_13 -#define SWDIO_GPIO_Port GPIOA -#define SWCLK_Pin GPIO_PIN_14 -#define SWCLK_GPIO_Port GPIOA -#define I2S3_SCK_Pin GPIO_PIN_10 -#define I2S3_SCK_GPIO_Port GPIOC -#define I2S3_SD_Pin GPIO_PIN_12 -#define I2S3_SD_GPIO_Port GPIOC -#define Audio_RST_Pin GPIO_PIN_4 -#define Audio_RST_GPIO_Port GPIOD -#define OTG_FS_OverCurrent_Pin GPIO_PIN_5 -#define OTG_FS_OverCurrent_GPIO_Port GPIOD -#define SWO_Pin GPIO_PIN_3 -#define SWO_GPIO_Port GPIOB -#define Audio_SCL_Pin GPIO_PIN_6 -#define Audio_SCL_GPIO_Port GPIOB -#define Audio_SDA_Pin GPIO_PIN_9 -#define Audio_SDA_GPIO_Port GPIOB -#define MEMS_INT2_Pin GPIO_PIN_1 -#define MEMS_INT2_GPIO_Port GPIOE static void power_warning_handler(void) { reset_into_safe_mode(BROWNOUT); @@ -207,10 +137,10 @@ safe_mode_t port_init(void) { HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct); //Status LED chain - HAL_GPIO_WritePin(GPIOD, LD4_Pin, GPIO_PIN_RESET); //LED 1 - HAL_GPIO_WritePin(GPIOD, LD3_Pin, GPIO_PIN_SET); //LED 2 - HAL_GPIO_WritePin(GPIOD, LD5_Pin, GPIO_PIN_SET); //LED 3 - HAL_GPIO_WritePin(GPIOD, LD6_Pin, GPIO_PIN_SET); //LED 4 + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET); //LED 1 + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET); //LED 2 + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET); //LED 3 + HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET); //LED 4 tick_init(); From 267468834da5207d66a8701d3b5b60a1f63e8461 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Tue, 23 Jul 2019 19:40:26 -0400 Subject: [PATCH 03/27] Pin down some TUSB issues --- .gitmodules | 1 + ports/stm32f4/Makefile | 2 +- ports/stm32f4/supervisor/port.c | 84 ++++++----------------------- ports/stm32f4/supervisor/usb.c | 41 +++++++------- supervisor/shared/usb/tusb_config.h | 2 +- 5 files changed, 36 insertions(+), 94 deletions(-) diff --git a/.gitmodules b/.gitmodules index e2845395aace8..639e8dc79ced4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -77,6 +77,7 @@ path = lib/tinyusb url = https://github.com/hathach/tinyusb.git branch = develop + ignore = dirty [submodule "tools/huffman"] path = tools/huffman url = https://github.com/tannewt/huffman.git diff --git a/ports/stm32f4/Makefile b/ports/stm32f4/Makefile index 3224a85c547e7..5be123e447a59 100755 --- a/ports/stm32f4/Makefile +++ b/ports/stm32f4/Makefile @@ -135,7 +135,7 @@ LIBS += -lm endif # TinyUSB defines -CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_STM32F4 -DCFG_TUD_CDC_RX_BUFSIZE=1024 -DCFG_TUD_CDC_TX_BUFSIZE=1024 -DCFG_TUD_MSC_BUFSIZE=4096 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_MIDI_TX_BUFSIZE=128 +CFLAGS += -DHSE_VALUE=8000000 -DCFG_TUSB_MCU=OPT_MCU_STM32F4 -DCFG_TUD_CDC_RX_BUFSIZE=1024 -DCFG_TUD_CDC_TX_BUFSIZE=1024 -DCFG_TUD_MSC_BUFSIZE=4096 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_MIDI_TX_BUFSIZE=128 ###################################### diff --git a/ports/stm32f4/supervisor/port.c b/ports/stm32f4/supervisor/port.c index 515ca7c692ae3..471b90e0842a8 100644 --- a/ports/stm32f4/supervisor/port.c +++ b/ports/stm32f4/supervisor/port.c @@ -45,97 +45,43 @@ safe_mode_t port_init(void) { /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 4; - RCC_OscInitStruct.PLL.PLLN = 192; + RCC_OscInitStruct.PLL.PLLM = 8; + RCC_OscInitStruct.PLL.PLLN = 336; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; - RCC_OscInitStruct.PLL.PLLQ = 8; + RCC_OscInitStruct.PLL.PLLQ = 7; HAL_RCC_OscConfig(&RCC_OscInitStruct); - /** Initializes the CPU, AHB and APB busses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + + /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 + clocks dividers */ + RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3); - PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S; - PeriphClkInitStruct.PLLI2S.PLLI2SN = 200; - PeriphClkInitStruct.PLLI2S.PLLI2SM = 5; - PeriphClkInitStruct.PLLI2S.PLLI2SR = 2; - HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); + + SystemCoreClockUpdate(); //GPIO setup GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOE_CLK_ENABLE(); - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOH_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET); - - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin - |Audio_RST_Pin, GPIO_PIN_RESET); - - /*Configure GPIO pin : DATA_Ready_Pin */ - GPIO_InitStruct.Pin = DATA_Ready_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(DATA_Ready_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pin : CS_I2C_SPI_Pin */ - GPIO_InitStruct.Pin = CS_I2C_SPI_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(CS_I2C_SPI_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : INT1_Pin INT2_Pin MEMS_INT2_Pin */ - GPIO_InitStruct.Pin = INT1_Pin|INT2_Pin|MEMS_INT2_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - - /*Configure GPIO pin : OTG_FS_PowerSwitchOn_Pin */ - GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(OTG_FS_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pin : PA0 */ - GPIO_InitStruct.Pin = GPIO_PIN_0; - GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin - Audio_RST_Pin */ - GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin - |Audio_RST_Pin; + //LED pins + GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */ - GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_NOPULL; - HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct); - //Status LED chain HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET); //LED 1 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET); //LED 2 diff --git a/ports/stm32f4/supervisor/usb.c b/ports/stm32f4/supervisor/usb.c index 9135235238a38..3cb5ccd0f44e6 100644 --- a/ports/stm32f4/supervisor/usb.c +++ b/ports/stm32f4/supervisor/usb.c @@ -30,16 +30,7 @@ #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 - +//#include "tusb_config.h" void init_usb_hardware(void) { // HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET); //LED 2 @@ -49,32 +40,36 @@ void init_usb_hardware(void) { 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); + __HAL_RCC_GPIOA_CLK_ENABLE(); - GPIO_InitStruct.Pin = USB_OTGFS_DM_Pin|USB_OTGFS_DP_Pin; + /* Configure DM DP Pins */ + GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 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; + /* Configure VBUS Pin */ + GPIO_InitStruct.Pin = GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* This for ID line debug */ + GPIO_InitStruct.Pin = GPIO_PIN_10; + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Speed = GPIO_SPEED_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); + // /* 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 } diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h index 301805275a716..d7c5199be61e9 100644 --- a/supervisor/shared/usb/tusb_config.h +++ b/supervisor/shared/usb/tusb_config.h @@ -107,7 +107,7 @@ // USB RAM PLACEMENT //--------------------------------------------------------------------+ #define CFG_TUSB_ATTR_USBRAM -#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4) +#define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4) #ifdef __cplusplus From 981398406c61daada25f3e36601a3d0d118ac635 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Wed, 24 Jul 2019 16:23:35 -0400 Subject: [PATCH 04/27] Implement working (if useless) USB on F411 --- lib/tinyusb | 2 +- .../peripherals/stm32f4/stm32f411xe/clocks.c | 62 +++++++++---------- ports/stm32f4/supervisor/usb.c | 1 - ports/stm32f4/tick.c | 8 +-- supervisor/shared/usb/usb.c | 6 +- supervisor/shared/usb/usb_msc_flash.c | 2 +- 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 0848c462b3e43..97e2629d64758 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 0848c462b3e431a9da42e96537d2b597a4579636 +Subproject commit 97e2629d647584681b2883f2081fa2cddb3d61cc diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c index 5b7a1e2987199..f1ce6fef9f749 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c +++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c @@ -28,36 +28,34 @@ void stm32f4_peripherals_clocks_init(void) { //System clock init - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {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_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 4; - RCC_OscInitStruct.PLL.PLLN = 192; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; - RCC_OscInitStruct.PLL.PLLQ = 8; - HAL_RCC_OscConfig(&RCC_OscInitStruct); - /** 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_DIV4; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3); - PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S; - PeriphClkInitStruct.PLLI2S.PLLI2SN = 200; - PeriphClkInitStruct.PLLI2S.PLLI2SM = 5; - PeriphClkInitStruct.PLLI2S.PLLI2SR = 2; - HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_OscInitTypeDef RCC_OscInitStruct; + + /* Enable Power Control clock */ + __HAL_RCC_PWR_CLK_ENABLE(); + + /* The voltage scaling allows optimizing the power consumption when the device is + clocked below the maximum system frequency, to update the voltage scaling value + regarding system frequency refer to product datasheet. */ + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); + + /* Enable HSE Oscillator and activate PLL with HSE as source */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 8; + RCC_OscInitStruct.PLL.PLLN = 336; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; + RCC_OscInitStruct.PLL.PLLQ = 7; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + + /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 + clocks dividers */ + RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | 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; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); } diff --git a/ports/stm32f4/supervisor/usb.c b/ports/stm32f4/supervisor/usb.c index 3cb5ccd0f44e6..11885b3d927ef 100644 --- a/ports/stm32f4/supervisor/usb.c +++ b/ports/stm32f4/supervisor/usb.c @@ -30,7 +30,6 @@ #include "lib/utils/interrupt_char.h" #include "lib/mp-readline/readline.h" #include "stm32f4xx_hal.h" -//#include "tusb_config.h" void init_usb_hardware(void) { // HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET); //LED 2 diff --git a/ports/stm32f4/tick.c b/ports/stm32f4/tick.c index 2596e34d1715a..5bd2da6edcc9c 100644 --- a/ports/stm32f4/tick.c +++ b/ports/stm32f4/tick.c @@ -55,12 +55,12 @@ void SysTick_Handler(void) { } void tick_init() { - uint32_t ticks_per_ms = 16000000/ 1000; + uint32_t ticks_per_ms = SystemCoreClock/ 1000; SysTick_Config(ticks_per_ms); // interrupt is enabled } void tick_delay(uint32_t us) { - uint32_t ticks_per_us = 16000000 / 1000 / 1000; + uint32_t ticks_per_us = SystemCoreClock / 1000 / 1000; uint32_t us_between_ticks = SysTick->VAL / ticks_per_us; uint64_t start_ms = ticks_ms; while (us > 1000) { @@ -74,12 +74,12 @@ void tick_delay(uint32_t us) { // us counts down! void current_tick(uint64_t* ms, uint32_t* us_until_ms) { - uint32_t ticks_per_us = 16000000 / 1000 / 1000; + uint32_t ticks_per_us = SystemCoreClock / 1000 / 1000; *ms = ticks_ms; *us_until_ms = SysTick->VAL / ticks_per_us; } void wait_until(uint64_t ms, uint32_t us_until_ms) { - uint32_t ticks_per_us = 16000000 / 1000 / 1000; + uint32_t ticks_per_us = SystemCoreClock / 1000 / 1000; while(ticks_ms <= ms && SysTick->VAL / ticks_per_us >= us_until_ms) {} } diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 12db84308ba40..bccdca622d93a 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -60,10 +60,14 @@ bool usb_enabled(void) { void usb_init(void) { init_usb_hardware(); - load_serial_number(); + //load_serial_number(); tusb_init(); + while(1) { + tud_task(); + } + #if MICROPY_KBD_EXCEPTION // Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() callback will be invoked when Ctrl+C is received // This callback always got invoked regardless of mp_interrupt_char value since we only set it once here diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c index 205cb7b500119..a1ab464547d2f 100644 --- a/supervisor/shared/usb/usb_msc_flash.c +++ b/supervisor/shared/usb/usb_msc_flash.c @@ -197,7 +197,7 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun) { // Invoked when received Start Stop Unit command // - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage // - Start = 1 : active mode, if load_eject = 1 : load disk storage -bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) { +void tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) { if (load_eject) { if (lun > 1) { return false; From 90b1701b6cf5bfdd44e02bff6c6fd7c9061111c0 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Fri, 26 Jul 2019 14:06:27 -0400 Subject: [PATCH 05/27] Add CDC REPL access --- ports/stm32f4/background.c | 2 +- .../boards/stm32f411re_discovery/mpconfigboard.h | 2 ++ supervisor/shared/usb/usb.c | 13 +++++++------ supervisor/supervisor.mk | 1 + tools/gen_usb_descriptor.py | 6 +++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ports/stm32f4/background.c b/ports/stm32f4/background.c index e9872b0450969..9c4f3ab27e2f1 100644 --- a/ports/stm32f4/background.c +++ b/ports/stm32f4/background.c @@ -46,7 +46,7 @@ void run_background_tasks(void) { } running_background_tasks = true; filesystem_background(); - //usb_background(); + usb_background(); #if CIRCUITPY_DISPLAYIO displayio_refresh_displays(); diff --git a/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.h index 6754432823463..1b1410aea23af 100644 --- a/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.h +++ b/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.h @@ -33,6 +33,8 @@ #define FLASH_SIZE (0x7D000) #define FLASH_PAGE_SIZE (0x4000) +#define CIRCUITPY_AUTORELOAD_DELAY_MS 500 + #define CIRCUITPY_INTERNAL_NVM_SIZE (4096) #define AUTORESET_DELAY_MS 500 #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) \ No newline at end of file diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index bccdca622d93a..cfb39d4bb5b66 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -34,14 +34,19 @@ #include "tusb.h" +#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 8 + // Serial number as hex characters. This writes directly to the USB // descriptor. extern uint16_t usb_serial_number[1 + COMMON_HAL_MCU_PROCESSOR_UID_LENGTH * 2]; void load_serial_number(void) { // create serial number based on device unique id - uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH] = {1,2,3,4}; + uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; //common_hal_mcu_processor_get_uid(raw_id); + for (int i=0; i<2; i++) { + ((uint32_t*) raw_id)[i] = 0; + } static const char nibble_to_hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; @@ -60,14 +65,10 @@ bool usb_enabled(void) { void usb_init(void) { init_usb_hardware(); - //load_serial_number(); + load_serial_number(); tusb_init(); - while(1) { - tud_task(); - } - #if MICROPY_KBD_EXCEPTION // Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() callback will be invoked when Ctrl+C is received // This callback always got invoked regardless of mp_interrupt_char value since we only set it once here diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 2d50e7a8b1660..42a55243e068f 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -78,6 +78,7 @@ else shared-module/usb_midi/PortIn.c \ shared-module/usb_midi/PortOut.c \ $(BUILD)/autogen_usb_descriptor.c + CFLAGS += -DUSB_AVAILABLE endif diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index 10bbf5066343f..db17c97666595 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -273,17 +273,17 @@ def strings_in_order(cls): descriptor_list = [] descriptor_list.append(cdc_iad) descriptor_list.extend(cdc_interfaces) -descriptor_list.extend(msc_interfaces) +# descriptor_list.extend(msc_interfaces) # Only add the control interface because other audio interfaces are managed by it to ensure the # correct ordering. -descriptor_list.append(audio_control_interface) +# descriptor_list.append(audio_control_interface) # Put the CDC IAD just before the CDC interfaces. # There appears to be a bug in the Windows composite USB driver that requests the # HID report descriptor with the wrong interface number if the HID interface is not given # first. However, it still fetches the descriptor anyway. We could reorder the interfaces but # the Windows 7 Adafruit_usbser.inf file thinks CDC is at Interface 0, so we'll leave it # there for backwards compatibility. -descriptor_list.extend(hid_interfaces) +# descriptor_list.extend(hid_interfaces) configuration = standard.ConfigurationDescriptor( description="Composite configuration", From 343d5aa0ac7a38789790d8d9f113aceb6c9c0ae8 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Fri, 26 Jul 2019 16:48:23 -0400 Subject: [PATCH 06/27] Delete redundant file --- ports/stm32f4/supervisor/port_F412.c | 326 --------------------------- 1 file changed, 326 deletions(-) delete mode 100644 ports/stm32f4/supervisor/port_F412.c diff --git a/ports/stm32f4/supervisor/port_F412.c b/ports/stm32f4/supervisor/port_F412.c deleted file mode 100644 index 04c98ab90464c..0000000000000 --- a/ports/stm32f4/supervisor/port_F412.c +++ /dev/null @@ -1,326 +0,0 @@ -/* - * 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 -#include "supervisor/port.h" -#include "boards/board.h" - -#include "tick.h" -//#include "shared-bindings/rtc/__init__.h" - -#include "stm32f4xx_hal.h" - -#define LED3_Pin GPIO_PIN_2 -#define LED3_GPIO_Port GPIOE -#define LED4_Pin GPIO_PIN_3 -#define LED4_GPIO_Port GPIOE -#define DFSDM_DATIN3_Pin GPIO_PIN_4 -#define DFSDM_DATIN3_GPIO_Port GPIOE -#define A0_Pin GPIO_PIN_0 -#define A0_GPIO_Port GPIOF -#define LCD_BLCTRL_Pin GPIO_PIN_5 -#define LCD_BLCTRL_GPIO_Port GPIOF -#define QSPI_BK1_IO3_Pin GPIO_PIN_6 -#define QSPI_BK1_IO3_GPIO_Port GPIOF -#define QSPI_BK1_IO2_Pin GPIO_PIN_7 -#define QSPI_BK1_IO2_GPIO_Port GPIOF -#define QSPI_BK1_IO0_Pin GPIO_PIN_8 -#define QSPI_BK1_IO0_GPIO_Port GPIOF -#define QSPI_BK1_IO1_Pin GPIO_PIN_9 -#define QSPI_BK1_IO1_GPIO_Port GPIOF -#define STLK_MCO_Pin GPIO_PIN_0 -#define STLK_MCO_GPIO_Port GPIOH -#define DFSDM_CKOUT_Pin GPIO_PIN_2 -#define DFSDM_CKOUT_GPIO_Port GPIOC -#define JOY_SEL_Pin GPIO_PIN_0 -#define JOY_SEL_GPIO_Port GPIOA -#define STLINK_RX_Pin GPIO_PIN_2 -#define STLINK_RX_GPIO_Port GPIOA -#define STLINK_TX_Pin GPIO_PIN_3 -#define STLINK_TX_GPIO_Port GPIOA -#define CODEC_I2S3_WS_Pin GPIO_PIN_4 -#define CODEC_I2S3_WS_GPIO_Port GPIOA -#define DFSDM_DATIN0_Pin GPIO_PIN_1 -#define DFSDM_DATIN0_GPIO_Port GPIOB -#define QSPI_CLK_Pin GPIO_PIN_2 -#define QSPI_CLK_GPIO_Port GPIOB -#define EXT_RESET_Pin GPIO_PIN_11 -#define EXT_RESET_GPIO_Port GPIOF -#define CTP_RST_Pin GPIO_PIN_12 -#define CTP_RST_GPIO_Port GPIOF -#define JOY_RIGHT_Pin GPIO_PIN_14 -#define JOY_RIGHT_GPIO_Port GPIOF -#define JOY_LEFT_Pin GPIO_PIN_15 -#define JOY_LEFT_GPIO_Port GPIOF -#define JOY_UP_Pin GPIO_PIN_0 -#define JOY_UP_GPIO_Port GPIOG -#define JOY_DOWN_Pin GPIO_PIN_1 -#define JOY_DOWN_GPIO_Port GPIOG -#define D4_Pin GPIO_PIN_7 -#define D4_GPIO_Port GPIOE -#define D5_Pin GPIO_PIN_8 -#define D5_GPIO_Port GPIOE -#define D6_Pin GPIO_PIN_9 -#define D6_GPIO_Port GPIOE -#define D7_Pin GPIO_PIN_10 -#define D7_GPIO_Port GPIOE -#define D8_Pin GPIO_PIN_11 -#define D8_GPIO_Port GPIOE -#define D9_Pin GPIO_PIN_12 -#define D9_GPIO_Port GPIOE -#define D10_Pin GPIO_PIN_13 -#define D10_GPIO_Port GPIOE -#define D11_Pin GPIO_PIN_14 -#define D11_GPIO_Port GPIOE -#define D12_Pin GPIO_PIN_15 -#define D12_GPIO_Port GPIOE -#define I2C2_SCL_Pin GPIO_PIN_10 -#define I2C2_SCL_GPIO_Port GPIOB -#define M2_CKIN_Pin GPIO_PIN_11 -#define M2_CKIN_GPIO_Port GPIOB -#define CODEC_I2S3_SCK_Pin GPIO_PIN_12 -#define CODEC_I2S3_SCK_GPIO_Port GPIOB -#define D13_Pin GPIO_PIN_8 -#define D13_GPIO_Port GPIOD -#define D14_Pin GPIO_PIN_9 -#define D14_GPIO_Port GPIOD -#define D15_Pin GPIO_PIN_10 -#define D15_GPIO_Port GPIOD -#define LCD_RESET_Pin GPIO_PIN_11 -#define LCD_RESET_GPIO_Port GPIOD -#define D0_Pin GPIO_PIN_14 -#define D0_GPIO_Port GPIOD -#define D1_Pin GPIO_PIN_15 -#define D1_GPIO_Port GPIOD -#define CODEC_INT_Pin GPIO_PIN_2 -#define CODEC_INT_GPIO_Port GPIOG -#define LCD_TE_Pin GPIO_PIN_4 -#define LCD_TE_GPIO_Port GPIOG -#define CTP_INT_Pin GPIO_PIN_5 -#define CTP_INT_GPIO_Port GPIOG -#define QSPI_BK1_NCS_Pin GPIO_PIN_6 -#define QSPI_BK1_NCS_GPIO_Port GPIOG -#define USB_OTGFS_OVRCR_Pin GPIO_PIN_7 -#define USB_OTGFS_OVRCR_GPIO_Port GPIOG -#define USB_OTGFS_PPWR_EN_Pin GPIO_PIN_8 -#define USB_OTGFS_PPWR_EN_GPIO_Port GPIOG -#define CODEC_I2S3_MCK_Pin GPIO_PIN_7 -#define CODEC_I2S3_MCK_GPIO_Port GPIOC -#define uSD_D0_Pin GPIO_PIN_8 -#define uSD_D0_GPIO_Port GPIOC -#define uSD_D1_Pin GPIO_PIN_9 -#define uSD_D1_GPIO_Port GPIOC -#define M2_CKINA8_Pin GPIO_PIN_8 -#define M2_CKINA8_GPIO_Port GPIOA -#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 -#define SWDIO_Pin GPIO_PIN_13 -#define SWDIO_GPIO_Port GPIOA -#define SWCLK_Pin GPIO_PIN_14 -#define SWCLK_GPIO_Port GPIOA -#define uSD_D2_Pin GPIO_PIN_10 -#define uSD_D2_GPIO_Port GPIOC -#define uSD_D3_Pin GPIO_PIN_11 -#define uSD_D3_GPIO_Port GPIOC -#define uSD_CLK_Pin GPIO_PIN_12 -#define uSD_CLK_GPIO_Port GPIOC -#define D2_Pin GPIO_PIN_0 -#define D2_GPIO_Port GPIOD -#define D3_Pin GPIO_PIN_1 -#define D3_GPIO_Port GPIOD -#define uSD_CMD_Pin GPIO_PIN_2 -#define uSD_CMD_GPIO_Port GPIOD -#define uSD_DETECT_Pin GPIO_PIN_3 -#define uSD_DETECT_GPIO_Port GPIOD -#define FMC_NOE_Pin GPIO_PIN_4 -#define FMC_NOE_GPIO_Port GPIOD -#define FMC_NWE_Pin GPIO_PIN_5 -#define FMC_NWE_GPIO_Port GPIOD -#define FMC_NE1_Pin GPIO_PIN_7 -#define FMC_NE1_GPIO_Port GPIOD -#define SWO_Pin GPIO_PIN_3 -#define SWO_GPIO_Port GPIOB -#define CODEC_I2S3ext_SD_Pin GPIO_PIN_4 -#define CODEC_I2S3ext_SD_GPIO_Port GPIOB -#define CODEC_I2S3_SD_Pin GPIO_PIN_5 -#define CODEC_I2S3_SD_GPIO_Port GPIOB -#define I2C1_SCL_Pin GPIO_PIN_6 -#define I2C1_SCL_GPIO_Port GPIOB -#define I2C1_SDA_Pin GPIO_PIN_7 -#define I2C1_SDA_GPIO_Port GPIOB -#define I2C2_SDA_Pin GPIO_PIN_9 -#define I2C2_SDA_GPIO_Port GPIOB -#define LED1_Pin GPIO_PIN_0 -#define LED1_GPIO_Port GPIOE -#define LED2_Pin GPIO_PIN_1 -#define LED2_GPIO_Port GPIOE - -/* -#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 "shared-bindings/rtc/__init__.h" - -static void power_warning_handler(void) { - reset_into_safe_mode(BROWNOUT); -} - -safe_mode_t port_init(void) { - HAL_Init(); - - //System clock init - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {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_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - 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_HSE; - RCC_OscInitStruct.PLL.PLLM = 4; - RCC_OscInitStruct.PLL.PLLN = 72; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; - RCC_OscInitStruct.PLL.PLLQ = 3; - RCC_OscInitStruct.PLL.PLLR = 2; - HAL_RCC_OscConfig(&RCC_OscInitStruct); - /** 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; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); - - PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S_APB1|RCC_PERIPHCLK_SDIO - |RCC_PERIPHCLK_CLK48; - PeriphClkInitStruct.PLLI2S.PLLI2SN = 50; - PeriphClkInitStruct.PLLI2S.PLLI2SM = 4; - PeriphClkInitStruct.PLLI2S.PLLI2SR = 2; - PeriphClkInitStruct.PLLI2S.PLLI2SQ = 2; - PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLQ; - PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48; - PeriphClkInitStruct.PLLI2SSelection = RCC_PLLI2SCLKSOURCE_PLLSRC; - PeriphClkInitStruct.I2sApb1ClockSelection = RCC_I2SAPB1CLKSOURCE_PLLI2S; - HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); - - HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); - - //GPIO Init - GPIO_InitTypeDef GPIO_InitStruct = {0}; - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOE_CLK_ENABLE(); - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOF_CLK_ENABLE(); - __HAL_RCC_GPIOH_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOG_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOE, LED3_Pin|LED4_Pin|LED1_Pin|LED2_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOF, LCD_BLCTRL_Pin|EXT_RESET_Pin|CTP_RST_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_RESET); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(USB_OTGFS_PPWR_EN_GPIO_Port, USB_OTGFS_PPWR_EN_Pin, GPIO_PIN_SET); - /*Configure GPIO pins : LED3_Pin LED4_Pin LED1_Pin LED2_Pin */ - GPIO_InitStruct.Pin = LED3_Pin|LED4_Pin|LED1_Pin|LED2_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); - /*Configure GPIO pin : USB_OTGFS_PPWR_EN_Pin */ - GPIO_InitStruct.Pin = USB_OTGFS_PPWR_EN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(USB_OTGFS_PPWR_EN_GPIO_Port, &GPIO_InitStruct); - - //Status LED chain - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_0, GPIO_PIN_RESET); //LED 1 - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET); //LED 2 - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET); //LED 3 - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_SET); //LED 4 - - tick_init(); - // HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); - - 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) { - -// } From 6c7723905c03f4f06b6ef7a56277d4dfec18ab4f Mon Sep 17 00:00:00 2001 From: Hierophect Date: Mon, 29 Jul 2019 11:21:35 -0400 Subject: [PATCH 07/27] Add temp status LEDs --- ports/stm32f4/supervisor/serial.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/stm32f4/supervisor/serial.c b/ports/stm32f4/supervisor/serial.c index 3154dc3e583d0..984db2d0f9d82 100644 --- a/ports/stm32f4/supervisor/serial.c +++ b/ports/stm32f4/supervisor/serial.c @@ -42,10 +42,10 @@ void serial_init(void) { huart2.Init.OverSampling = UART_OVERSAMPLING_16; if (HAL_UART_Init(&huart2) == HAL_OK) { - //HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET); + 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); + HAL_UART_Transmit(&huart2, (uint8_t*)"Serial On", 9, 5000); + HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET); } bool serial_connected(void) { From e2fc55f829ba9e30ccf19c21d5aeacaf4a503fd6 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Wed, 31 Jul 2019 14:58:55 -0400 Subject: [PATCH 08/27] Add baseline HAL I2C support --- ports/stm32f4/Makefile | 1 + .../stm32f411re_discovery/mpconfigboard.mk | 3 +- .../stm32f412zg_discovery/stm32f4xx_hal_msp.c | 4 +- ports/stm32f4/common-hal/busio/I2C.c | 115 ++++++ ports/stm32f4/common-hal/busio/I2C.h | 44 ++ ports/stm32f4/common-hal/busio/OneWire.h | 33 ++ ports/stm32f4/common-hal/busio/SPI.c | 321 +++++++++++++++ ports/stm32f4/common-hal/busio/SPI.h | 42 ++ ports/stm32f4/common-hal/busio/UART.c | 375 ++++++++++++++++++ ports/stm32f4/common-hal/busio/UART.h | 46 +++ ports/stm32f4/common-hal/busio/__init__.c | 1 + ports/stm32f4/mpconfigport.mk | 1 + 12 files changed, 982 insertions(+), 4 deletions(-) create mode 100644 ports/stm32f4/common-hal/busio/I2C.c create mode 100644 ports/stm32f4/common-hal/busio/I2C.h create mode 100644 ports/stm32f4/common-hal/busio/OneWire.h create mode 100644 ports/stm32f4/common-hal/busio/SPI.c create mode 100644 ports/stm32f4/common-hal/busio/SPI.h create mode 100644 ports/stm32f4/common-hal/busio/UART.c create mode 100644 ports/stm32f4/common-hal/busio/UART.h create mode 100644 ports/stm32f4/common-hal/busio/__init__.c diff --git a/ports/stm32f4/Makefile b/ports/stm32f4/Makefile index 7f07444434f6c..15fed7bde5745 100755 --- a/ports/stm32f4/Makefile +++ b/ports/stm32f4/Makefile @@ -148,6 +148,7 @@ SRC_STM32 = \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fsmc.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sram.c \ + stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_i2c.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_dma.c \ stm32f4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2s.c \ diff --git a/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.mk index 7b865b57e0227..0d15aab498e49 100644 --- a/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.mk @@ -9,5 +9,4 @@ MCU_SUB_VARIANT = stm32f411xe CMSIS_MCU = STM32F411xE LD_FILE = boards/STM32F411VETx_FLASH.ld TEXT0_ADDR = 0x08000000 -TEXT1_ADDR = 0x08020000 - +TEXT1_ADDR = 0x08020000 \ No newline at end of file diff --git a/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c b/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c index 9d29f360797e6..54f444a71a16c 100644 --- a/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c +++ b/ports/stm32f4/boards/stm32f412zg_discovery/stm32f4xx_hal_msp.c @@ -273,14 +273,14 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) */ GPIO_InitStruct.Pin = I2C2_SCL_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; - GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF4_I2C2; HAL_GPIO_Init(I2C2_SCL_GPIO_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = I2C2_SDA_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; - GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF9_I2C2; HAL_GPIO_Init(I2C2_SDA_GPIO_Port, &GPIO_InitStruct); diff --git a/ports/stm32f4/common-hal/busio/I2C.c b/ports/stm32f4/common-hal/busio/I2C.c new file mode 100644 index 0000000000000..8e1e57c36c7c7 --- /dev/null +++ b/ports/stm32f4/common-hal/busio/I2C.c @@ -0,0 +1,115 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * 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 "shared-bindings/busio/I2C.h" +#include "py/mperrno.h" +#include "py/runtime.h" +#include "stm32f4xx_hal.h" + +#include "shared-bindings/microcontroller/__init__.h" +#include "supervisor/shared/translate.h" + +I2C_HandleTypeDef hi2c2; + +void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, + const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) { + hi2c2.Instance = I2C2; + hi2c2.Init.ClockSpeed = 100000; + hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2; + hi2c2.Init.OwnAddress1 = 0; + hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; + hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; + hi2c2.Init.OwnAddress2 = 0; + hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; + hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; + if(HAL_I2C_Init(&hi2c2) != HAL_OK) { + mp_raise_RuntimeError(translate("I2C Init Error")); + } else { + mp_printf(&mp_plat_print, "I2C INIT OK"); + } + + self->sda_pin = sda->number; + self->scl_pin = scl->number; + + claim_pin(sda); + claim_pin(scl); +} + +bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) { + return self->sda_pin == NO_PIN; +} + +void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { + if (common_hal_busio_i2c_deinited(self)) { + return; + } + + HAL_I2C_MspDeInit(&hi2c2); + + self->sda_pin = NO_PIN; + self->scl_pin = NO_PIN; +} + +bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { + return HAL_I2C_IsDeviceReady(&hi2c2, (uint16_t)(addr<<1),2,2) == HAL_OK; +} + +bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { + bool grabbed_lock = false; + + //Critical section code that may be required at some point. + // uint32_t store_primask = __get_PRIMASK(); + // __disable_irq(); + // __DMB(); + + if (!self->has_lock) { + grabbed_lock = true; + self->has_lock = true; + } + + // __DMB(); + // __set_PRIMASK(store_primask); + + return grabbed_lock; +} + +bool common_hal_busio_i2c_has_lock(busio_i2c_obj_t *self) { + return self->has_lock; +} + +void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) { + self->has_lock = false; +} + +uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, + const uint8_t *data, size_t len, bool transmit_stop_bit) { + return HAL_I2C_Master_Transmit(&hi2c2, (uint16_t)(addr<<1), (uint8_t *)data, (uint16_t)len, 2) == HAL_OK ? 0 : MP_EIO; +} + +uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, + uint8_t *data, size_t len) { + return HAL_I2C_Master_Receive(&hi2c2, (uint16_t)(addr<<1), data, (uint16_t)len, 2) == HAL_OK ? 0 : MP_EIO; +} diff --git a/ports/stm32f4/common-hal/busio/I2C.h b/ports/stm32f4/common-hal/busio/I2C.h new file mode 100644 index 0000000000000..9fe0258a1cba7 --- /dev/null +++ b/ports/stm32f4/common-hal/busio/I2C.h @@ -0,0 +1,44 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * 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_COMMON_HAL_BUSIO_I2C_H +#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_I2C_H + +#include "common-hal/microcontroller/Pin.h" + +#include "stm32f4xx_hal.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + I2C_HandleTypeDef i2c_handle; + bool has_lock; + uint8_t scl_pin; + uint8_t sda_pin; +} busio_i2c_obj_t; + +#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_I2C_H diff --git a/ports/stm32f4/common-hal/busio/OneWire.h b/ports/stm32f4/common-hal/busio/OneWire.h new file mode 100644 index 0000000000000..6e8c829793a26 --- /dev/null +++ b/ports/stm32f4/common-hal/busio/OneWire.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * 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_COMMON_HAL_BUSIO_ONEWIRE_H +#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_ONEWIRE_H + +// Use bitbangio. +#include "shared-module/busio/OneWire.h" + +#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_ONEWIRE_H diff --git a/ports/stm32f4/common-hal/busio/SPI.c b/ports/stm32f4/common-hal/busio/SPI.c new file mode 100644 index 0000000000000..a8b91998421af --- /dev/null +++ b/ports/stm32f4/common-hal/busio/SPI.c @@ -0,0 +1,321 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * 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 "shared-bindings/busio/SPI.h" +#include "py/mperrno.h" +#include "py/runtime.h" + +#include "boards/board.h" +#include "common-hal/microcontroller/Pin.h" + +void common_hal_busio_spi_construct(busio_spi_obj_t *self, + const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi, + const mcu_pin_obj_t * miso) { + // Sercom* sercom = NULL; + // uint8_t sercom_index; + // uint32_t clock_pinmux = 0; + // bool mosi_none = mosi == mp_const_none || mosi == NULL; + // bool miso_none = miso == mp_const_none || miso == NULL; + // uint32_t mosi_pinmux = 0; + // uint32_t miso_pinmux = 0; + // uint8_t clock_pad = 0; + // uint8_t mosi_pad = 0; + // uint8_t miso_pad = 0; + // uint8_t dopo = 255; + + // // Special case for SAMR boards. + // #ifdef PIN_PC19 + // if (miso == &pin_PC19) { + // if (mosi == &pin_PB30 && clock == &pin_PC18) { + // sercom = SERCOM4; + // sercom_index = 4; + // clock_pinmux = MUX_F; + // mosi_pinmux = MUX_F; + // miso_pinmux = MUX_F; + // clock_pad = 3; + // mosi_pad = 2; + // miso_pad = 0; + // dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad); + // } + // // Error, leave SERCOM unset to throw an exception later. + // } else { + // #endif + // for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) { + // sercom_index = clock->sercom[i].index; // 2 for SERCOM2, etc. + // if (sercom_index >= SERCOM_INST_NUM) { + // continue; + // } + // Sercom* potential_sercom = sercom_insts[sercom_index]; + // if ( + // #if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !defined(CIRCUITPY_BITBANG_APA102) + // (potential_sercom->SPI.CTRLA.bit.ENABLE != 0 && + // potential_sercom != status_apa102.spi_desc.dev.prvt && + // !apa102_sck_in_use)) { + // #else + // potential_sercom->SPI.CTRLA.bit.ENABLE != 0) { + // #endif + // continue; + // } + // clock_pinmux = PINMUX(clock->number, (i == 0) ? MUX_C : MUX_D); + // clock_pad = clock->sercom[i].pad; + // if (!samd_peripherals_valid_spi_clock_pad(clock_pad)) { + // continue; + // } + // for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { + // if (!mosi_none) { + // if (sercom_index == mosi->sercom[j].index) { + // mosi_pinmux = PINMUX(mosi->number, (j == 0) ? MUX_C : MUX_D); + // mosi_pad = mosi->sercom[j].pad; + // dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad); + // if (dopo > 0x3) { + // continue; // pad combination not possible + // } + // if (miso_none) { + // sercom = potential_sercom; + // break; + // } + // } else { + // continue; + // } + // } + // if (!miso_none) { + // for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) { + // if (sercom_index == miso->sercom[k].index) { + // miso_pinmux = PINMUX(miso->number, (k == 0) ? MUX_C : MUX_D); + // miso_pad = miso->sercom[k].pad; + // sercom = potential_sercom; + // break; + // } + // } + // } + // if (sercom != NULL) { + // break; + // } + // } + // if (sercom != NULL) { + // break; + // } + // } + // #ifdef PIN_PC19 + // } + // #endif + // if (sercom == NULL) { + // mp_raise_ValueError(translate("Invalid pins")); + // } + + // // Set up SPI clocks on SERCOM. + // samd_peripherals_sercom_clock_init(sercom, sercom_index); + + // #if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !defined(CIRCUITPY_BITBANG_APA102) + // // if we're re-using the dotstar sercom, make sure it is disabled or the init will fail out + // hri_sercomspi_clear_CTRLA_ENABLE_bit(sercom); + // #endif + // if (spi_m_sync_init(&self->spi_desc, sercom) != ERR_NONE) { + // mp_raise_OSError(MP_EIO); + // } + + // // Pads must be set after spi_m_sync_init(), which uses default values from + // // the prototypical SERCOM. + // hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo); + // hri_sercomspi_write_CTRLA_DIPO_bf(sercom, miso_pad); + + // // Always start at 250khz which is what SD cards need. They are sensitive to + // // SPI bus noise before they are put into SPI mode. + // uint8_t baud_value = samd_peripherals_spi_baudrate_to_baud_reg_value(250000); + // if (spi_m_sync_set_baudrate(&self->spi_desc, baud_value) != ERR_NONE) { + // // spi_m_sync_set_baudrate does not check for validity, just whether the device is + // // busy or not + // mp_raise_OSError(MP_EIO); + // } + + // gpio_set_pin_direction(clock->number, GPIO_DIRECTION_OUT); + // gpio_set_pin_pull_mode(clock->number, GPIO_PULL_OFF); + // gpio_set_pin_function(clock->number, clock_pinmux); + // claim_pin(clock); + // self->clock_pin = clock->number; + + // if (mosi_none) { + // self->MOSI_pin = NO_PIN; + // } else { + // gpio_set_pin_direction(mosi->number, GPIO_DIRECTION_OUT); + // gpio_set_pin_pull_mode(mosi->number, GPIO_PULL_OFF); + // gpio_set_pin_function(mosi->number, mosi_pinmux); + // self->MOSI_pin = mosi->number; + // claim_pin(mosi); + // } + + // if (miso_none) { + // self->MISO_pin = NO_PIN; + // } else { + // gpio_set_pin_direction(miso->number, GPIO_DIRECTION_IN); + // gpio_set_pin_pull_mode(miso->number, GPIO_PULL_OFF); + // gpio_set_pin_function(miso->number, miso_pinmux); + // self->MISO_pin = miso->number; + // claim_pin(miso); + // } + + // spi_m_sync_enable(&self->spi_desc); +} + +void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) { + // never_reset_sercom(self->spi_desc.dev.prvt); + + // never_reset_pin_number(self->clock_pin); + // never_reset_pin_number(self->MOSI_pin); + // never_reset_pin_number(self->MISO_pin); +} + +bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) { + //return self->clock_pin == NO_PIN; +} + +void common_hal_busio_spi_deinit(busio_spi_obj_t *self) { + // if (common_hal_busio_spi_deinited(self)) { + // return; + // } + // allow_reset_sercom(self->spi_desc.dev.prvt); + + // spi_m_sync_disable(&self->spi_desc); + // spi_m_sync_deinit(&self->spi_desc); + // reset_pin_number(self->clock_pin); + // reset_pin_number(self->MOSI_pin); + // reset_pin_number(self->MISO_pin); + // self->clock_pin = NO_PIN; +} + +bool common_hal_busio_spi_configure(busio_spi_obj_t *self, + uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) { + // uint8_t baud_reg_value = samd_peripherals_spi_baudrate_to_baud_reg_value(baudrate); + + // void * hw = self->spi_desc.dev.prvt; + // // If the settings are already what we want then don't reset them. + // if (hri_sercomspi_get_CTRLA_CPHA_bit(hw) == phase && + // hri_sercomspi_get_CTRLA_CPOL_bit(hw) == polarity && + // hri_sercomspi_read_CTRLB_CHSIZE_bf(hw) == ((uint32_t)bits - 8) && + // hri_sercomspi_read_BAUD_BAUD_bf(hw) == baud_reg_value) { + // return true; + // } + + // // Disable, set values (most or all are enable-protected), and re-enable. + // spi_m_sync_disable(&self->spi_desc); + // hri_sercomspi_wait_for_sync(hw, SERCOM_SPI_SYNCBUSY_MASK); + + // hri_sercomspi_write_CTRLA_CPHA_bit(hw, phase); + // hri_sercomspi_write_CTRLA_CPOL_bit(hw, polarity); + // hri_sercomspi_write_CTRLB_CHSIZE_bf(hw, bits - 8); + // hri_sercomspi_write_BAUD_BAUD_bf(hw, baud_reg_value); + // hri_sercomspi_wait_for_sync(hw, SERCOM_SPI_SYNCBUSY_MASK); + + // spi_m_sync_enable(&self->spi_desc); + // hri_sercomspi_wait_for_sync(hw, SERCOM_SPI_SYNCBUSY_MASK); + + return true; +} + +bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) { + bool grabbed_lock = false; + // CRITICAL_SECTION_ENTER() + // if (!self->has_lock) { + // grabbed_lock = true; + // self->has_lock = true; + // } + // CRITICAL_SECTION_LEAVE(); + return grabbed_lock; +} + +bool common_hal_busio_spi_has_lock(busio_spi_obj_t *self) { + return self->has_lock; +} + +void common_hal_busio_spi_unlock(busio_spi_obj_t *self) { + self->has_lock = false; +} + +bool common_hal_busio_spi_write(busio_spi_obj_t *self, + const uint8_t *data, size_t len) { + // if (len == 0) { + // return true; + // } + // int32_t status; + // if (len >= 16) { + // status = sercom_dma_write(self->spi_desc.dev.prvt, data, len); + // } else { + // struct io_descriptor *spi_io; + // spi_m_sync_get_io_descriptor(&self->spi_desc, &spi_io); + // status = spi_io->write(spi_io, data, len); + // } + return 0;//status >= 0; // Status is number of chars read or an error code < 0. +} + +bool common_hal_busio_spi_read(busio_spi_obj_t *self, + uint8_t *data, size_t len, uint8_t write_value) { + // if (len == 0) { + // return true; + // } + // int32_t status; + // if (len >= 16) { + // status = sercom_dma_read(self->spi_desc.dev.prvt, data, len, write_value); + // } else { + // self->spi_desc.dev.dummy_byte = write_value; + + // struct io_descriptor *spi_io; + // spi_m_sync_get_io_descriptor(&self->spi_desc, &spi_io); + + // status = spi_io->read(spi_io, data, len); + // } + return 0;//status >= 0; // Status is number of chars read or an error code < 0. +} + +bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uint8_t *data_in, size_t len) { + // if (len == 0) { + // return true; + // } + // int32_t status; + // if (len >= 16) { + // status = sercom_dma_transfer(self->spi_desc.dev.prvt, data_out, data_in, len); + // } else { + // struct spi_xfer xfer; + // xfer.txbuf = data_out; + // xfer.rxbuf = data_in; + // xfer.size = len; + // status = spi_m_sync_transfer(&self->spi_desc, &xfer); + // } + return 0;//status >= 0; // Status is number of chars read or an error code < 0. +} + +uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t* self) { + return 0;//samd_peripherals_spi_baud_reg_value_to_baudrate(hri_sercomspi_read_BAUD_reg(self->spi_desc.dev.prvt)); +} + +uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self) { + //void * hw = self->spi_desc.dev.prvt; + return 0;//hri_sercomspi_get_CTRLA_CPHA_bit(hw); +} + +uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self) { + //void * hw = self->spi_desc.dev.prvt; + return 0;//hri_sercomspi_get_CTRLA_CPOL_bit(hw); +} diff --git a/ports/stm32f4/common-hal/busio/SPI.h b/ports/stm32f4/common-hal/busio/SPI.h new file mode 100644 index 0000000000000..f7ff79b49bb17 --- /dev/null +++ b/ports/stm32f4/common-hal/busio/SPI.h @@ -0,0 +1,42 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * 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_COMMON_HAL_BUSIO_SPI_H +#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_SPI_H + +#include "common-hal/microcontroller/Pin.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + bool has_lock; + uint8_t clock_pin; + uint8_t MOSI_pin; + uint8_t MISO_pin; +} busio_spi_obj_t; + +#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/stm32f4/common-hal/busio/UART.c b/ports/stm32f4/common-hal/busio/UART.c new file mode 100644 index 0000000000000..e9a49171500a3 --- /dev/null +++ b/ports/stm32f4/common-hal/busio/UART.c @@ -0,0 +1,375 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 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 "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/busio/UART.h" + +#include "mpconfigport.h" +#include "lib/utils/interrupt_char.h" +#include "py/gc.h" +#include "py/mperrno.h" +#include "py/runtime.h" +#include "py/stream.h" +#include "supervisor/shared/translate.h" + +#include "tick.h" + +void common_hal_busio_uart_construct(busio_uart_obj_t *self, + const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, + uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, + uint8_t receiver_buffer_size) { + // Sercom* sercom = NULL; + // uint8_t sercom_index = 255; // Unset index + // uint32_t rx_pinmux = 0; + // uint8_t rx_pad = 255; // Unset pad + // uint32_t tx_pinmux = 0; + // uint8_t tx_pad = 255; // Unset pad + + // if (bits > 8) { + // mp_raise_NotImplementedError(translate("bytes > 8 bits not supported")); + // } + + // bool have_tx = tx != mp_const_none; + // bool have_rx = rx != mp_const_none; + // if (!have_tx && !have_rx) { + // mp_raise_ValueError(translate("tx and rx cannot both be None")); + // } + + // self->baudrate = baudrate; + // self->character_bits = bits; + // self->timeout_ms = timeout * 1000; + + // // This assignment is only here because the usart_async routines take a *const argument. + // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + + // for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) { + // Sercom* potential_sercom = NULL; + // if (have_tx) { + // sercom_index = tx->sercom[i].index; + // if (sercom_index >= SERCOM_INST_NUM) { + // continue; + // } + // potential_sercom = sercom_insts[sercom_index]; + // if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 || + // !(tx->sercom[i].pad == 0 || + // tx->sercom[i].pad == 2)) { + // continue; + // } + // tx_pinmux = PINMUX(tx->number, (i == 0) ? MUX_C : MUX_D); + // tx_pad = tx->sercom[i].pad; + // if (rx == mp_const_none) { + // sercom = potential_sercom; + // break; + // } + // } + // for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { + // if (((!have_tx && rx->sercom[j].index < SERCOM_INST_NUM && + // sercom_insts[rx->sercom[j].index]->USART.CTRLA.bit.ENABLE == 0) || + // sercom_index == rx->sercom[j].index) && + // rx->sercom[j].pad != tx_pad) { + // rx_pinmux = PINMUX(rx->number, (j == 0) ? MUX_C : MUX_D); + // rx_pad = rx->sercom[j].pad; + // sercom = sercom_insts[rx->sercom[j].index]; + // sercom_index = rx->sercom[j].index; + // break; + // } + // } + // if (sercom != NULL) { + // break; + // } + // } + // if (sercom == NULL) { + // mp_raise_ValueError(translate("Invalid pins")); + // } + // if (!have_tx) { + // tx_pad = 0; + // if (rx_pad == 0) { + // tx_pad = 2; + // } + // } + // if (!have_rx) { + // rx_pad = (tx_pad + 1) % 4; + // } + + // // Set up clocks on SERCOM. + // samd_peripherals_sercom_clock_init(sercom, sercom_index); + + // if (rx && receiver_buffer_size > 0) { + // self->buffer_length = receiver_buffer_size; + // // Initially allocate the UART's buffer in the long-lived part of the + // // heap. UARTs are generally long-lived objects, but the "make long- + // // lived" machinery is incapable of moving internal pointers like + // // self->buffer, so do it manually. (However, as long as internal + // // pointers like this are NOT moved, allocating the buffer + // // in the long-lived pool is not strictly necessary) + // self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, true); + // if (self->buffer == NULL) { + // common_hal_busio_uart_deinit(self); + // mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate RX buffer")); + // } + // } else { + // self->buffer_length = 0; + // self->buffer = NULL; + // } + + // if (usart_async_init(usart_desc_p, sercom, self->buffer, self->buffer_length, NULL) != ERR_NONE) { + // mp_raise_ValueError(translate("Could not initialize UART")); + // } + + // // usart_async_init() sets a number of defaults based on a prototypical SERCOM + // // which don't necessarily match what we need. After calling it, set the values + // // specific to this instantiation of UART. + + // // Set pads computed for this SERCOM. + // // TXPO: + // // 0x0: TX pad 0; no RTS/CTS + // // 0x1: TX pad 2; no RTS/CTS + // // 0x2: TX pad 0; RTS: pad 2, CTS: pad 3 (not used by us right now) + // // So divide by 2 to map pad to value. + // // RXPO: + // // 0x0: RX pad 0 + // // 0x1: RX pad 1 + // // 0x2: RX pad 2 + // // 0x3: RX pad 3 + + // // Doing a group mask and set of the registers saves 60 bytes over setting the bitfields individually. + + // sercom->USART.CTRLA.reg &= ~(SERCOM_USART_CTRLA_TXPO_Msk | + // SERCOM_USART_CTRLA_RXPO_Msk | + // SERCOM_USART_CTRLA_FORM_Msk); + // sercom->USART.CTRLA.reg |= SERCOM_USART_CTRLA_TXPO(tx_pad / 2) | + // SERCOM_USART_CTRLA_RXPO(rx_pad) | + // (parity == PARITY_NONE ? 0 : SERCOM_USART_CTRLA_FORM(1)); + + // // Enable tx and/or rx based on whether the pins were specified. + // // CHSIZE is 0 for 8 bits, 5, 6, 7 for 5, 6, 7 bits. 1 for 9 bits, but we don't support that. + // sercom->USART.CTRLB.reg &= ~(SERCOM_USART_CTRLB_TXEN | + // SERCOM_USART_CTRLB_RXEN | + // SERCOM_USART_CTRLB_PMODE | + // SERCOM_USART_CTRLB_SBMODE | + // SERCOM_USART_CTRLB_CHSIZE_Msk); + // sercom->USART.CTRLB.reg |= (have_tx ? SERCOM_USART_CTRLB_TXEN : 0) | + // (have_rx ? SERCOM_USART_CTRLB_RXEN : 0) | + // (parity == PARITY_ODD ? SERCOM_USART_CTRLB_PMODE : 0) | + // (stop > 1 ? SERCOM_USART_CTRLB_SBMODE : 0) | + // SERCOM_USART_CTRLB_CHSIZE(bits % 8); + + // // Set baud rate + // common_hal_busio_uart_set_baudrate(self, baudrate); + + // // Turn on rx interrupt handling. The UART async driver has its own set of internal callbacks, + // // which are set up by uart_async_init(). These in turn can call user-specified callbacks. + // // In fact, the actual interrupts are not enabled unless we set up a user-specified callback. + // // This is confusing. It's explained in the Atmel START User Guide -> Implementation Description -> + // // Different read function behavior in some asynchronous drivers. As of this writing: + // // http://start.atmel.com/static/help/index.html?GUID-79201A5A-226F-4FBB-B0B8-AB0BE0554836 + // // Look at the ASFv4 code example for async USART. + // usart_async_register_callback(usart_desc_p, USART_ASYNC_RXC_CB, usart_async_rxc_callback); + + + // if (have_tx) { + // gpio_set_pin_direction(tx->number, GPIO_DIRECTION_OUT); + // gpio_set_pin_pull_mode(tx->number, GPIO_PULL_OFF); + // gpio_set_pin_function(tx->number, tx_pinmux); + // self->tx_pin = tx->number; + // claim_pin(tx); + // } else { + // self->tx_pin = NO_PIN; + // } + + // if (have_rx) { + // gpio_set_pin_direction(rx->number, GPIO_DIRECTION_IN); + // gpio_set_pin_pull_mode(rx->number, GPIO_PULL_OFF); + // gpio_set_pin_function(rx->number, rx_pinmux); + // self->rx_pin = rx->number; + // claim_pin(rx); + // } else { + // self->rx_pin = NO_PIN; + // } + + // usart_async_enable(usart_desc_p); +} + +bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { + return 0;//self->rx_pin == NO_PIN && self->tx_pin == NO_PIN; +} + +void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { + // if (common_hal_busio_uart_deinited(self)) { + // return; + // } + // // This assignment is only here because the usart_async routines take a *const argument. + // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + // usart_async_disable(usart_desc_p); + // usart_async_deinit(usart_desc_p); + // reset_pin_number(self->rx_pin); + // reset_pin_number(self->tx_pin); + // self->rx_pin = NO_PIN; + // self->tx_pin = NO_PIN; +} + +// Read characters. +size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t len, int *errcode) { +// if (self->rx_pin == NO_PIN) { +// mp_raise_ValueError(translate("No RX pin")); +// } + +// // This assignment is only here because the usart_async routines take a *const argument. +// struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + +// if (len == 0) { +// // Nothing to read. +// return 0; +// } + +// struct io_descriptor *io; +// usart_async_get_io_descriptor(usart_desc_p, &io); + +// size_t total_read = 0; +// uint64_t start_ticks = ticks_ms; + +// // Busy-wait until timeout or until we've read enough chars. +// while (ticks_ms - start_ticks <= self->timeout_ms) { +// // Read as many chars as we can right now, up to len. +// size_t num_read = io_read(io, data, len); + +// // Advance pointer in data buffer, and decrease how many chars left to read. +// data += num_read; +// len -= num_read; +// total_read += num_read; +// if (len == 0) { +// // Don't need to read any more: data buf is full. +// break; +// } +// if (num_read > 0) { +// // Reset the timeout on every character read. +// start_ticks = ticks_ms; +// } +// #ifdef MICROPY_VM_HOOK_LOOP +// MICROPY_VM_HOOK_LOOP ; +// // Allow user to break out of a timeout with a KeyboardInterrupt. +// if (mp_hal_is_interrupted()) { +// break; +// } +// #endif +// // If we are zero timeout, make sure we don't loop again (in the event +// // we read in under 1ms) +// if (self->timeout_ms == 0) { +// break; +// } +// } + +// if (total_read == 0) { +// *errcode = EAGAIN; +// return MP_STREAM_ERROR; +// } + + return 0;//total_read; +} + +// Write characters. +size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data, size_t len, int *errcode) { + // if (self->tx_pin == NO_PIN) { + // mp_raise_ValueError(translate("No TX pin")); + // } + + // // This assignment is only here because the usart_async routines take a *const argument. + // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + + // struct io_descriptor *io; + // usart_async_get_io_descriptor(usart_desc_p, &io); + + // if (io_write(io, data, len) < 0) { + // *errcode = MP_EAGAIN; + // return MP_STREAM_ERROR; + // } + + // // Wait until write is complete or timeout. + // bool done = false; + // uint64_t start_ticks = ticks_ms; + // // Busy-wait for timeout. + // while (ticks_ms - start_ticks < self->timeout_ms) { + // if (usart_async_is_tx_empty(usart_desc_p)) { + // done = true; + // break; + // } + // #ifdef MICROPY_VM_HOOK_LOOP + // MICROPY_VM_HOOK_LOOP + // #endif + // } + + // if (!done) { + // *errcode = MP_EAGAIN; + // return MP_STREAM_ERROR; + // } + + // // All the characters got written. + return 0;//len; +} + +uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) { + return 0;//self->baudrate; +} + +void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) { + // This assignment is only here because the usart_async routines take a *const argument. + // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + // usart_async_set_baud_rate(usart_desc_p, + // // Samples and ARITHMETIC vs FRACTIONAL must correspond to USART_SAMPR in + // // hpl_sercom_config.h. + // _usart_async_calculate_baud_rate(baudrate, // e.g. 9600 baud + // PROTOTYPE_SERCOM_USART_ASYNC_CLOCK_FREQUENCY, + // 16, // samples + // USART_BAUDRATE_ASYNCH_ARITHMETIC, + // 0 // fraction - not used for ARITHMETIC + // )); + // self->baudrate = baudrate; +} + +uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) { + // // This assignment is only here because the usart_async routines take a *const argument. + // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + // struct usart_async_status async_status; + // usart_async_get_status(usart_desc_p, &async_status); + return 0;//async_status.rxcnt; +} + +void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) { + // This assignment is only here because the usart_async routines take a *const argument. + // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + // usart_async_flush_rx_buffer(usart_desc_p); + +} + +bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) { + // if (self->tx_pin == NO_PIN) { + // return false; + // } + // // This assignment is only here because the usart_async routines take a *const argument. + // const struct _usart_async_device * const usart_device_p = + // (struct _usart_async_device * const) &self->usart_desc.device; + return 0;//_usart_async_is_byte_sent(usart_device_p); +} diff --git a/ports/stm32f4/common-hal/busio/UART.h b/ports/stm32f4/common-hal/busio/UART.h new file mode 100644 index 0000000000000..6992339340409 --- /dev/null +++ b/ports/stm32f4/common-hal/busio/UART.h @@ -0,0 +1,46 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * 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_COMMON_HAL_BUSIO_UART_H +#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_UART_H + +#include "common-hal/microcontroller/Pin.h" + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + uint8_t rx_pin; + uint8_t tx_pin; + uint8_t character_bits; + bool rx_error; + uint32_t baudrate; + uint32_t timeout_ms; + uint32_t buffer_length; + uint8_t* buffer; +} busio_uart_obj_t; + +#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_BUSIO_UART_H diff --git a/ports/stm32f4/common-hal/busio/__init__.c b/ports/stm32f4/common-hal/busio/__init__.c new file mode 100644 index 0000000000000..41761b6743aea --- /dev/null +++ b/ports/stm32f4/common-hal/busio/__init__.c @@ -0,0 +1 @@ +// No busio module functions. diff --git a/ports/stm32f4/mpconfigport.mk b/ports/stm32f4/mpconfigport.mk index 814bb2b207d00..88423c6d6687b 100644 --- a/ports/stm32f4/mpconfigport.mk +++ b/ports/stm32f4/mpconfigport.mk @@ -19,4 +19,5 @@ ifeq ($(MCU_SUB_VARIANT), stm32f412zx) CIRCUITPY_BOARD = 1 CIRCUITPY_DIGITALIO = 1 CIRCUITPY_MICROCONTROLLER = 1 + CIRCUITPY_BUSIO = 1 endif From 06d53ef8a7eac57f46fd1895642731237ab72ec1 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Wed, 31 Jul 2019 17:06:44 -0400 Subject: [PATCH 09/27] minor debugging changes --- ports/stm32f4/supervisor/serial.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/stm32f4/supervisor/serial.c b/ports/stm32f4/supervisor/serial.c index 984db2d0f9d82..1532a8ae88c4d 100644 --- a/ports/stm32f4/supervisor/serial.c +++ b/ports/stm32f4/supervisor/serial.c @@ -33,7 +33,7 @@ UART_HandleTypeDef huart2; void serial_init(void) { huart2.Instance = USART2; - huart2.Init.BaudRate = 9600; + huart2.Init.BaudRate = 115200; huart2.Init.WordLength = UART_WORDLENGTH_8B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_NONE; @@ -44,7 +44,7 @@ void serial_init(void) { { HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET); } - HAL_UART_Transmit(&huart2, (uint8_t*)"Serial On", 9, 5000); + HAL_UART_Transmit(&huart2, (uint8_t*)"Serial On", 9, 2); HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET); } @@ -54,7 +54,7 @@ bool serial_connected(void) { char serial_read(void) { uint8_t data; - HAL_UART_Receive(&huart2, &data, 1,5000); + HAL_UART_Receive(&huart2, &data, 1,500); return data; } From 268cf0a3ccde382dfa17f97e29d2bb026ab605b8 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Sun, 4 Aug 2019 16:31:03 -0400 Subject: [PATCH 10/27] Quick fix for incorrect MCU package type --- .../{stm32f411re_discovery => stm32f411ve_discovery}/board.c | 0 .../mpconfigboard.h | 0 .../mpconfigboard.mk | 2 +- .../{stm32f411re_discovery => stm32f411ve_discovery}/pins.c | 0 .../stm32f4xx_hal_conf.h | 0 .../stm32f4xx_hal_msp.c | 0 6 files changed, 1 insertion(+), 1 deletion(-) rename ports/stm32f4/boards/{stm32f411re_discovery => stm32f411ve_discovery}/board.c (100%) rename ports/stm32f4/boards/{stm32f411re_discovery => stm32f411ve_discovery}/mpconfigboard.h (100%) rename ports/stm32f4/boards/{stm32f411re_discovery => stm32f411ve_discovery}/mpconfigboard.mk (83%) rename ports/stm32f4/boards/{stm32f411re_discovery => stm32f411ve_discovery}/pins.c (100%) rename ports/stm32f4/boards/{stm32f411re_discovery => stm32f411ve_discovery}/stm32f4xx_hal_conf.h (100%) rename ports/stm32f4/boards/{stm32f411re_discovery => stm32f411ve_discovery}/stm32f4xx_hal_msp.c (100%) diff --git a/ports/stm32f4/boards/stm32f411re_discovery/board.c b/ports/stm32f4/boards/stm32f411ve_discovery/board.c similarity index 100% rename from ports/stm32f4/boards/stm32f411re_discovery/board.c rename to ports/stm32f4/boards/stm32f411ve_discovery/board.c diff --git a/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h similarity index 100% rename from ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.h rename to ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h diff --git a/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk similarity index 83% rename from ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.mk rename to ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk index 7b865b57e0227..dfc8697a3264e 100644 --- a/ports/stm32f4/boards/stm32f411re_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk @@ -1,6 +1,6 @@ USB_VID = 0x239A USB_PID = 0x802A -USB_PRODUCT = "STM32F411RE Discovery Board - CPy" +USB_PRODUCT = "STM32F411VE Discovery Board - CPy" USB_MANUFACTURER = "Adafruit Industries LLC" MCU_SERIES = m4 diff --git a/ports/stm32f4/boards/stm32f411re_discovery/pins.c b/ports/stm32f4/boards/stm32f411ve_discovery/pins.c similarity index 100% rename from ports/stm32f4/boards/stm32f411re_discovery/pins.c rename to ports/stm32f4/boards/stm32f411ve_discovery/pins.c diff --git a/ports/stm32f4/boards/stm32f411re_discovery/stm32f4xx_hal_conf.h b/ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_conf.h similarity index 100% rename from ports/stm32f4/boards/stm32f411re_discovery/stm32f4xx_hal_conf.h rename to ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_conf.h diff --git a/ports/stm32f4/boards/stm32f411re_discovery/stm32f4xx_hal_msp.c b/ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_msp.c similarity index 100% rename from ports/stm32f4/boards/stm32f411re_discovery/stm32f4xx_hal_msp.c rename to ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_msp.c From a635d46b1a3d16695afa932f53842525eab638e3 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Sun, 4 Aug 2019 17:06:51 -0400 Subject: [PATCH 11/27] Fix merge related issues --- .gitmodules | 1 - lib/tinyusb | 2 +- ports/stm32f4/supervisor/internal_flash.c | 2 -- ports/stm32f4/supervisor/port.c | 6 ------ supervisor/shared/usb/usb_msc_flash.c | 2 +- 5 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.gitmodules b/.gitmodules index 2a97c81fcd7d5..7b57cab547993 100644 --- a/.gitmodules +++ b/.gitmodules @@ -77,7 +77,6 @@ path = lib/tinyusb url = https://github.com/hathach/tinyusb.git branch = develop - ignore = dirty [submodule "tools/huffman"] path = tools/huffman url = https://github.com/tannewt/huffman.git diff --git a/lib/tinyusb b/lib/tinyusb index 97e2629d64758..1ee9ef4f2b7c6 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 97e2629d647584681b2883f2081fa2cddb3d61cc +Subproject commit 1ee9ef4f2b7c6acfab6c398a4f57ca22036958f7 diff --git a/ports/stm32f4/supervisor/internal_flash.c b/ports/stm32f4/supervisor/internal_flash.c index fa776ae1de219..e05236948158f 100644 --- a/ports/stm32f4/supervisor/internal_flash.c +++ b/ports/stm32f4/supervisor/internal_flash.c @@ -39,8 +39,6 @@ /*------------------------------------------------------------------*/ /* Internal Flash API *------------------------------------------------------------------*/ -static inline uint32_t lba2addr(uint32_t block) { -} void supervisor_flash_init(void) { } diff --git a/ports/stm32f4/supervisor/port.c b/ports/stm32f4/supervisor/port.c index af4d1b8d84b3c..6030547acfd26 100644 --- a/ports/stm32f4/supervisor/port.c +++ b/ports/stm32f4/supervisor/port.c @@ -35,12 +35,6 @@ #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(); diff --git a/supervisor/shared/usb/usb_msc_flash.c b/supervisor/shared/usb/usb_msc_flash.c index a1ab464547d2f..205cb7b500119 100644 --- a/supervisor/shared/usb/usb_msc_flash.c +++ b/supervisor/shared/usb/usb_msc_flash.c @@ -197,7 +197,7 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun) { // Invoked when received Start Stop Unit command // - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage // - Start = 1 : active mode, if load_eject = 1 : load disk storage -void tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) { +bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) { if (load_eject) { if (lun > 1) { return false; From c375a5d37f8fa3016b0a328b3efaa165094e6387 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Wed, 7 Aug 2019 18:12:13 -0400 Subject: [PATCH 12/27] Add pin and module support for F411 --- ports/stm32f4/Makefile | 12 +- .../stm32f411ve_discovery/mpconfigboard.mk | 1 + .../boards/stm32f411ve_discovery/pins.c | 127 +++++++++--------- .../stm32f411ve_discovery/stm32f4xx_hal_msp.c | 2 +- .../stm32f412zg_discovery/mpconfigboard.mk | 1 + ports/stm32f4/common-hal/busio/I2C.c | 2 +- ports/stm32f4/common-hal/busio/UART.c | 3 +- .../stm32f4/common-hal/microcontroller/Pin.c | 9 +- .../common-hal/microcontroller/__init__.c | 12 +- ports/stm32f4/mpconfigport.mk | 4 +- ports/stm32f4/peripherals/stm32f4/pins.h | 4 +- .../peripherals/stm32f4/stm32f411xe/pins.c | 95 ++++++++++++- .../peripherals/stm32f4/stm32f411xe/pins.h | 99 +++++++++++++- .../peripherals/stm32f4/stm32f412zx/pins.c | 2 + .../peripherals/stm32f4/stm32f412zx/pins.h | 2 + 15 files changed, 289 insertions(+), 86 deletions(-) diff --git a/ports/stm32f4/Makefile b/ports/stm32f4/Makefile index 83ee59bf468e2..15c8ce1d712e7 100755 --- a/ports/stm32f4/Makefile +++ b/ports/stm32f4/Makefile @@ -98,10 +98,13 @@ endif ifeq ($(MCU_SUB_VARIANT), stm32f411xe) C_DEFS = \ + -DUSE_FULL_LL_DRIVER \ -DUSE_HAL_DRIVER \ -DSTM32F411xE endif +C_DEFS += -DMCU_PACKAGE=$(MCU_PACKAGE) + #TODO: Add ASM Flags? -Werror CFLAGS += $(INC) -Wall -std=gnu11 -nostdlib $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) @@ -184,6 +187,8 @@ SRC_C += \ mphalport.c \ tick.c \ boards/$(BOARD)/board.c \ + boards/$(BOARD)/pins.c \ + peripherals/stm32f4/$(MCU_SUB_VARIANT)/pins.c \ peripherals/stm32f4/$(MCU_SUB_VARIANT)/clocks.c \ peripherals/stm32f4/$(MCU_SUB_VARIANT)/gpio.c \ lib/libc/string0.c \ @@ -198,18 +203,11 @@ SRC_C += \ lib/utils/stdout_helpers.c \ lib/utils/sys_stdio_mphal.c \ supervisor/shared/memory.c - - #boards/$(BOARD)/pins.c \ ifneq ($(USB),FALSE) SRC_C += lib/tinyusb/src/portable/st/stm32f4/dcd_stm32f4.c endif -ifeq ($(MCU_SUB_VARIANT), stm32f412zx) -SRC_C += peripherals/stm32f4/stm32f412zx/pins.c -SRC_C += boards/$(BOARD)/pins.c -endif - SRC_S = \ supervisor/cpu.s \ boards/startup_$(MCU_SUB_VARIANT).s diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk index e0b4babf913ff..7c4e3be3a31f6 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk @@ -6,6 +6,7 @@ USB_MANUFACTURER = "Adafruit Industries LLC" MCU_SERIES = m4 MCU_VARIANT = stm32f4 MCU_SUB_VARIANT = stm32f411xe +MCU_PACKAGE = 100 CMSIS_MCU = STM32F411xE LD_FILE = boards/STM32F411VETx_FLASH.ld TEXT0_ADDR = 0x08000000 diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/pins.c b/ports/stm32f4/boards/stm32f411ve_discovery/pins.c index e3a4b5ed60d53..8a56ea94e5949 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/pins.c +++ b/ports/stm32f4/boards/stm32f411ve_discovery/pins.c @@ -1,19 +1,12 @@ #include "shared-bindings/board/__init__.h" STATIC const mp_rom_map_elem_t board_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR_PE02), MP_ROM_PTR(&pin_PE02) }, - { MP_ROM_QSTR(MP_QSTR_PE03), MP_ROM_PTR(&pin_PE03) }, - { MP_ROM_QSTR(MP_QSTR_PE04), MP_ROM_PTR(&pin_PE04) }, - { MP_ROM_QSTR(MP_QSTR_PE05), MP_ROM_PTR(&pin_PE05) }, - { MP_ROM_QSTR(MP_QSTR_PE06), MP_ROM_PTR(&pin_PE06) }, - { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) }, - { MP_ROM_QSTR(MP_QSTR_PF02), MP_ROM_PTR(&pin_PF02) }, - { MP_ROM_QSTR(MP_QSTR_PF03), MP_ROM_PTR(&pin_PF03) }, - { MP_ROM_QSTR(MP_QSTR_PF10), MP_ROM_PTR(&pin_PF10) }, + //P1 { MP_ROM_QSTR(MP_QSTR_PC00), MP_ROM_PTR(&pin_PC00) }, { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_PC01) }, { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_PC02) }, { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_PC03) }, + { MP_ROM_QSTR(MP_QSTR_PA00), MP_ROM_PTR(&pin_PA00) }, { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_PA01) }, { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_PA02) }, { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) }, @@ -25,66 +18,76 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_PC05) }, { MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_PB00) }, { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_PB01) }, - { MP_ROM_QSTR(MP_QSTR_PF11), MP_ROM_PTR(&pin_PF11) }, - { MP_ROM_QSTR(MP_QSTR_PF13), MP_ROM_PTR(&pin_PF13) }, + { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) }, + { MP_ROM_QSTR(MP_QSTR_PE07), MP_ROM_PTR(&pin_PE07) }, + { MP_ROM_QSTR(MP_QSTR_PE08), MP_ROM_PTR(&pin_PE08) }, + { MP_ROM_QSTR(MP_QSTR_PE09), MP_ROM_PTR(&pin_PE09) }, + { MP_ROM_QSTR(MP_QSTR_PE10), MP_ROM_PTR(&pin_PE10) }, + { MP_ROM_QSTR(MP_QSTR_PE11), MP_ROM_PTR(&pin_PE11) }, + { MP_ROM_QSTR(MP_QSTR_PE12), MP_ROM_PTR(&pin_PE12) }, + { MP_ROM_QSTR(MP_QSTR_PE13), MP_ROM_PTR(&pin_PE13) }, + { MP_ROM_QSTR(MP_QSTR_PE14), MP_ROM_PTR(&pin_PE14) }, + { MP_ROM_QSTR(MP_QSTR_PE15), MP_ROM_PTR(&pin_PE15) }, { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) }, - { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) }, { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) }, { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) }, { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) }, { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) }, + { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_PD08) }, + { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_PD09) }, + { MP_ROM_QSTR(MP_QSTR_PD10), MP_ROM_PTR(&pin_PD10) }, + { MP_ROM_QSTR(MP_QSTR_PD11), MP_ROM_PTR(&pin_PD11) }, { MP_ROM_QSTR(MP_QSTR_PD12), MP_ROM_PTR(&pin_PD12) }, { MP_ROM_QSTR(MP_QSTR_PD13), MP_ROM_PTR(&pin_PD13) }, - { MP_ROM_QSTR(MP_QSTR_PG02), MP_ROM_PTR(&pin_PG02) }, - { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) }, - { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) }, - { MP_ROM_QSTR(MP_QSTR_PC09), MP_ROM_PTR(&pin_PC09) }, - { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) }, - { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) }, - { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) }, - { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) }, - { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) }, - { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_PD06) }, - { MP_ROM_QSTR(MP_QSTR_PG09), MP_ROM_PTR(&pin_PG09) }, - { MP_ROM_QSTR(MP_QSTR_PG10), MP_ROM_PTR(&pin_PG10) }, - { MP_ROM_QSTR(MP_QSTR_PG11), MP_ROM_PTR(&pin_PG11) }, - { MP_ROM_QSTR(MP_QSTR_PG12), MP_ROM_PTR(&pin_PG12) }, - { MP_ROM_QSTR(MP_QSTR_PG13), MP_ROM_PTR(&pin_PG13) }, - { MP_ROM_QSTR(MP_QSTR_PG14), MP_ROM_PTR(&pin_PG14) }, - { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) }, - { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) }, - { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) }, - { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) }, - { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) }, - { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) }, - { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) }, - { MP_ROM_QSTR(MP_QSTR_PE00), MP_ROM_PTR(&pin_PE00) }, + { MP_ROM_QSTR(MP_QSTR_PD14), MP_ROM_PTR(&pin_PD14) }, + { MP_ROM_QSTR(MP_QSTR_PD15), MP_ROM_PTR(&pin_PD15) }, + //P2 + { MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_PC14) }, + { MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_PC15) }, + { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) }, + { MP_ROM_QSTR(MP_QSTR_PE06), MP_ROM_PTR(&pin_PE06) }, + { MP_ROM_QSTR(MP_QSTR_PE05), MP_ROM_PTR(&pin_PE05) }, + { MP_ROM_QSTR(MP_QSTR_PE04), MP_ROM_PTR(&pin_PE04) }, + { MP_ROM_QSTR(MP_QSTR_PE03), MP_ROM_PTR(&pin_PE03) }, + { MP_ROM_QSTR(MP_QSTR_PE02), MP_ROM_PTR(&pin_PE02) }, { MP_ROM_QSTR(MP_QSTR_PE01), MP_ROM_PTR(&pin_PE01) }, - { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PB10) }, - { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PB09) }, - { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA05) }, - { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA06) }, - { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA07) }, - { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA15) }, - { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PB08) }, - { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PG10) }, - { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PG11) }, - { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PF03) }, - { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PF10) }, - { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PG12) }, - { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PF04) }, - { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PG13) }, - { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PG14) }, - { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PG09) }, - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA01) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PC01) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PC03) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PC04) }, - { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PC05) }, //alt PB09, see F401ZG-DISCO manual - { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB00) }, //alt PB10, see F401ZG-DISCO manual - { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_PE00) }, - { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_PE01) }, - { MP_ROM_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_PE02) }, - { MP_ROM_QSTR(MP_QSTR_LED4), MP_ROM_PTR(&pin_PE03) }, + { MP_ROM_QSTR(MP_QSTR_PE00), MP_ROM_PTR(&pin_PE00) }, + { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) }, + { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) }, + { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) }, + { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) }, + { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) }, + { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) }, + { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) }, + { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_PD07) }, + { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_PD06) }, + { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_PD05) }, + { MP_ROM_QSTR(MP_QSTR_PD04), MP_ROM_PTR(&pin_PD04) }, + { MP_ROM_QSTR(MP_QSTR_PD03), MP_ROM_PTR(&pin_PD03) }, + { MP_ROM_QSTR(MP_QSTR_PD02), MP_ROM_PTR(&pin_PD02) }, + { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD01) }, + { MP_ROM_QSTR(MP_QSTR_PD00), MP_ROM_PTR(&pin_PD00) }, + { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_PC12) }, + { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_PC11) }, + { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_PC10) }, + { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) }, + { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) }, + { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_PC09), MP_ROM_PTR(&pin_PC09) }, + { MP_ROM_QSTR(MP_QSTR_PC08), MP_ROM_PTR(&pin_PC08) }, + { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) }, + { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) }, + //Names + { MP_ROM_QSTR(MP_QSTR_LD3), MP_ROM_PTR(&pin_PD13) }, + { MP_ROM_QSTR(MP_QSTR_LD4), MP_ROM_PTR(&pin_PD12) }, + { MP_ROM_QSTR(MP_QSTR_LD5), MP_ROM_PTR(&pin_PD14) }, + { MP_ROM_QSTR(MP_QSTR_LD6), MP_ROM_PTR(&pin_PD15) }, + { MP_ROM_QSTR(MP_QSTR_LED_ORANGE), MP_ROM_PTR(&pin_PD13) }, + { MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_PD12) }, + { MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_PD14) }, + { MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_PD15) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_msp.c b/ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_msp.c index 4989f9889b911..a892a8ff7e2b9 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_msp.c +++ b/ports/stm32f4/boards/stm32f411ve_discovery/stm32f4xx_hal_msp.c @@ -166,7 +166,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) PB6 ------> I2C1_SCL PB9 ------> I2C1_SDA */ - GPIO_InitStruct.Pin = Audio_SCL_Pin|Audio_SDA_Pin; + GPIO_InitStruct.Pin = Audio_SCL_Pin|GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; diff --git a/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk index 444795874bbfd..b6c27f9c04d17 100644 --- a/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk @@ -6,6 +6,7 @@ USB_MANUFACTURER = "STMicroelectronics" MCU_SERIES = m4 MCU_VARIANT = stm32f4 MCU_SUB_VARIANT = stm32f412zx +MCU_PACKAGE = 144 CMSIS_MCU = STM32F412xG LD_FILE = boards/STM32F412ZGTx_FLASH.ld TEXT0_ADDR = 0x08000000 diff --git a/ports/stm32f4/common-hal/busio/I2C.c b/ports/stm32f4/common-hal/busio/I2C.c index 8e1e57c36c7c7..1babe33a1da98 100644 --- a/ports/stm32f4/common-hal/busio/I2C.c +++ b/ports/stm32f4/common-hal/busio/I2C.c @@ -36,7 +36,7 @@ I2C_HandleTypeDef hi2c2; void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) { - hi2c2.Instance = I2C2; + hi2c2.Instance = I2C1; hi2c2.Init.ClockSpeed = 100000; hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c2.Init.OwnAddress1 = 0; diff --git a/ports/stm32f4/common-hal/busio/UART.c b/ports/stm32f4/common-hal/busio/UART.c index e9a49171500a3..86035c3bae38e 100644 --- a/ports/stm32f4/common-hal/busio/UART.c +++ b/ports/stm32f4/common-hal/busio/UART.c @@ -40,7 +40,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, - uint8_t receiver_buffer_size) { + uint16_t receiver_buffer_size) { + // Sercom* sercom = NULL; // uint8_t sercom_index = 255; // Unset index // uint32_t rx_pinmux = 0; diff --git a/ports/stm32f4/common-hal/microcontroller/Pin.c b/ports/stm32f4/common-hal/microcontroller/Pin.c index 6bfe56515e225..3450c935b6a01 100644 --- a/ports/stm32f4/common-hal/microcontroller/Pin.c +++ b/ports/stm32f4/common-hal/microcontroller/Pin.c @@ -31,11 +31,16 @@ #include "stm32f4/pins.h" #include "stm32f4xx_hal.h" -#define GPIO_PORT_COUNT 5 +#if MCU_PACKAGE == 144 + #define GPIO_PORT_COUNT 7 + GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG}; +#elif MCU_PACKAGE == 100 + #define GPIO_PORT_COUNT 5 + GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE}; +#endif STATIC uint16_t claimed_pins[GPIO_PORT_COUNT]; STATIC uint16_t never_reset_pins[GPIO_PORT_COUNT]; -GPIO_TypeDef * ports[GPIO_PORT_COUNT] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE}; void reset_all_pins(void) { // Reset claimed pins diff --git a/ports/stm32f4/common-hal/microcontroller/__init__.c b/ports/stm32f4/common-hal/microcontroller/__init__.c index 871caa018bf49..75f6550df6faa 100644 --- a/ports/stm32f4/common-hal/microcontroller/__init__.c +++ b/ports/stm32f4/common-hal/microcontroller/__init__.c @@ -83,6 +83,7 @@ STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PE05), MP_ROM_PTR(&pin_PE05) }, { MP_ROM_QSTR(MP_QSTR_PE06), MP_ROM_PTR(&pin_PE06) }, { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) }, +#if MCU_PACKAGE == LQFP144 { MP_ROM_QSTR(MP_QSTR_PF00), MP_ROM_PTR(&pin_PF00) }, { MP_ROM_QSTR(MP_QSTR_PF01), MP_ROM_PTR(&pin_PF01) }, { MP_ROM_QSTR(MP_QSTR_PF02), MP_ROM_PTR(&pin_PF02) }, @@ -94,6 +95,7 @@ STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PF08), MP_ROM_PTR(&pin_PF08) }, { MP_ROM_QSTR(MP_QSTR_PF09), MP_ROM_PTR(&pin_PF09) }, { MP_ROM_QSTR(MP_QSTR_PF10), MP_ROM_PTR(&pin_PF10) }, +#endif { MP_ROM_QSTR(MP_QSTR_PC00), MP_ROM_PTR(&pin_PC00) }, { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_PC01) }, { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_PC02) }, @@ -111,6 +113,7 @@ STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_PB00) }, { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_PB01) }, { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) }, +#if MCU_PACKAGE == LQFP144 { MP_ROM_QSTR(MP_QSTR_PF11), MP_ROM_PTR(&pin_PF11) }, { MP_ROM_QSTR(MP_QSTR_PF12), MP_ROM_PTR(&pin_PF12) }, { MP_ROM_QSTR(MP_QSTR_PF13), MP_ROM_PTR(&pin_PF13) }, @@ -118,6 +121,7 @@ STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PF15), MP_ROM_PTR(&pin_PF15) }, { MP_ROM_QSTR(MP_QSTR_PG00), MP_ROM_PTR(&pin_PG00) }, { MP_ROM_QSTR(MP_QSTR_PG01), MP_ROM_PTR(&pin_PG01) }, +#endif { MP_ROM_QSTR(MP_QSTR_PE07), MP_ROM_PTR(&pin_PE07) }, { MP_ROM_QSTR(MP_QSTR_PE08), MP_ROM_PTR(&pin_PE08) }, { MP_ROM_QSTR(MP_QSTR_PE09), MP_ROM_PTR(&pin_PE09) }, @@ -128,7 +132,9 @@ STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PE14), MP_ROM_PTR(&pin_PE14) }, { MP_ROM_QSTR(MP_QSTR_PE15), MP_ROM_PTR(&pin_PE15) }, { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) }, - { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) }, +#if MCU_PACKAGE == LQFP144 + { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) }, +#endif { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) }, { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) }, { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) }, @@ -141,6 +147,7 @@ STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PD13), MP_ROM_PTR(&pin_PD13) }, { MP_ROM_QSTR(MP_QSTR_PD14), MP_ROM_PTR(&pin_PD14) }, { MP_ROM_QSTR(MP_QSTR_PD15), MP_ROM_PTR(&pin_PD15) }, +#if MCU_PACKAGE == LQFP144 { MP_ROM_QSTR(MP_QSTR_PG02), MP_ROM_PTR(&pin_PG02) }, { MP_ROM_QSTR(MP_QSTR_PG03), MP_ROM_PTR(&pin_PG03) }, { MP_ROM_QSTR(MP_QSTR_PG04), MP_ROM_PTR(&pin_PG04) }, @@ -148,6 +155,7 @@ STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PG06), MP_ROM_PTR(&pin_PG06) }, { MP_ROM_QSTR(MP_QSTR_PG07), MP_ROM_PTR(&pin_PG07) }, { MP_ROM_QSTR(MP_QSTR_PG08), MP_ROM_PTR(&pin_PG08) }, +#endif { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) }, { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) }, { MP_ROM_QSTR(MP_QSTR_PC08), MP_ROM_PTR(&pin_PC08) }, @@ -171,6 +179,7 @@ STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_PD05) }, { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_PD06) }, { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_PD07) }, +#if MCU_PACKAGE == LQFP144 { MP_ROM_QSTR(MP_QSTR_PG09), MP_ROM_PTR(&pin_PG09) }, { MP_ROM_QSTR(MP_QSTR_PG10), MP_ROM_PTR(&pin_PG10) }, { MP_ROM_QSTR(MP_QSTR_PG11), MP_ROM_PTR(&pin_PG11) }, @@ -178,6 +187,7 @@ STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PG13), MP_ROM_PTR(&pin_PG13) }, { MP_ROM_QSTR(MP_QSTR_PG14), MP_ROM_PTR(&pin_PG14) }, { MP_ROM_QSTR(MP_QSTR_PG15), MP_ROM_PTR(&pin_PG15) }, +#endif { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) }, { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) }, { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) }, diff --git a/ports/stm32f4/mpconfigport.mk b/ports/stm32f4/mpconfigport.mk index 512469cfa8dd7..440d296f65999 100644 --- a/ports/stm32f4/mpconfigport.mk +++ b/ports/stm32f4/mpconfigport.mk @@ -15,9 +15,9 @@ LONGINT_IMPL = MPZ #Reduced feature set for early port CIRCUITPY_MINIMAL_BUILD = 1 -ifeq ($(MCU_SUB_VARIANT), stm32f412zx) +#ifeq ($(MCU_SUB_VARIANT), stm32f412zx) CIRCUITPY_BOARD = 1 CIRCUITPY_DIGITALIO = 1 CIRCUITPY_MICROCONTROLLER = 1 CIRCUITPY_BUSIO = 1 -endif \ No newline at end of file +#endif \ No newline at end of file diff --git a/ports/stm32f4/peripherals/stm32f4/pins.h b/ports/stm32f4/peripherals/stm32f4/pins.h index 1b48cc1921ad2..bf5abd5edcd49 100644 --- a/ports/stm32f4/peripherals/stm32f4/pins.h +++ b/ports/stm32f4/peripherals/stm32f4/pins.h @@ -69,5 +69,7 @@ extern const mp_obj_type_t mcu_pin_type; #ifdef STM32F412Zx #include "stm32f412zx/pins.h" #endif - +#ifdef STM32F411xE +#include "stm32f411xe/pins.h" +#endif #endif // __MICROPY_INCLUDED_STM32F4_PERIPHERALS_PINS_H__ diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.c b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.c index 04502d714c699..fca1c1df2c183 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.c +++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.c @@ -30,4 +30,97 @@ //TODO -//const mcu_pin_obj_t pin_PE02 = PIN(4, GPIOE, 2); \ No newline at end of file +//const mcu_pin_obj_t pin_PE02 = PIN(4, GPIOE, 2); +const mcu_pin_obj_t pin_PE02 = PIN(4, GPIOE, 2); +const mcu_pin_obj_t pin_PE03 = PIN(4, GPIOE, 3); +const mcu_pin_obj_t pin_PE04 = PIN(4, GPIOE, 4); +const mcu_pin_obj_t pin_PE05 = PIN(4, GPIOE, 5); +const mcu_pin_obj_t pin_PE06 = PIN(4, GPIOE, 6); + +const mcu_pin_obj_t pin_PC13 = PIN(2, GPIOC, 13); //anti-tamp +const mcu_pin_obj_t pin_PC14 = PIN(2, GPIOC, 14); //OSC32_IN +const mcu_pin_obj_t pin_PC15 = PIN(2, GPIOC, 15); //OSC32_OUT + +const mcu_pin_obj_t pin_PC00 = PIN(2, GPIOC, 0); +const mcu_pin_obj_t pin_PC01 = PIN(2, GPIOC, 1); +const mcu_pin_obj_t pin_PC02 = PIN(2, GPIOC, 2); +const mcu_pin_obj_t pin_PC03 = PIN(2, GPIOC, 3); + +const mcu_pin_obj_t pin_PA00 = PIN(0, GPIOA, 0); +const mcu_pin_obj_t pin_PA01 = PIN(0, GPIOA, 1); +const mcu_pin_obj_t pin_PA02 = PIN(0, GPIOA, 2); +const mcu_pin_obj_t pin_PA03 = PIN(0, GPIOA, 3); +const mcu_pin_obj_t pin_PA04 = PIN(0, GPIOA, 4); +const mcu_pin_obj_t pin_PA05 = PIN(0, GPIOA, 5); +const mcu_pin_obj_t pin_PA06 = PIN(0, GPIOA, 6); +const mcu_pin_obj_t pin_PA07 = PIN(0, GPIOA, 7); + +const mcu_pin_obj_t pin_PC04 = PIN(2, GPIOC, 4); +const mcu_pin_obj_t pin_PC05 = PIN(2, GPIOC, 5); + +const mcu_pin_obj_t pin_PB00 = PIN(1, GPIOB, 0); +const mcu_pin_obj_t pin_PB01 = PIN(1, GPIOB, 1); +const mcu_pin_obj_t pin_PB02 = PIN(1, GPIOB, 2); + +const mcu_pin_obj_t pin_PE07 = PIN(4, GPIOE, 7); +const mcu_pin_obj_t pin_PE08 = PIN(4, GPIOE, 8); +const mcu_pin_obj_t pin_PE09 = PIN(4, GPIOE, 9); +const mcu_pin_obj_t pin_PE10 = PIN(4, GPIOE, 10); +const mcu_pin_obj_t pin_PE11 = PIN(4, GPIOE, 11); +const mcu_pin_obj_t pin_PE12 = PIN(4, GPIOE, 12); +const mcu_pin_obj_t pin_PE13 = PIN(4, GPIOE, 13); +const mcu_pin_obj_t pin_PE14 = PIN(4, GPIOE, 14); +const mcu_pin_obj_t pin_PE15 = PIN(4, GPIOE, 15); + +const mcu_pin_obj_t pin_PB10 = PIN(1, GPIOB, 10); +const mcu_pin_obj_t pin_PB12 = PIN(1, GPIOB, 12); +const mcu_pin_obj_t pin_PB13 = PIN(1, GPIOB, 13); +const mcu_pin_obj_t pin_PB14 = PIN(1, GPIOB, 14); +const mcu_pin_obj_t pin_PB15 = PIN(1, GPIOB, 15); + +const mcu_pin_obj_t pin_PD08 = PIN(3, GPIOD, 8); +const mcu_pin_obj_t pin_PD09 = PIN(3, GPIOD, 9); +const mcu_pin_obj_t pin_PD10 = PIN(3, GPIOD, 10); +const mcu_pin_obj_t pin_PD11 = PIN(3, GPIOD, 11); +const mcu_pin_obj_t pin_PD12 = PIN(3, GPIOD, 12); +const mcu_pin_obj_t pin_PD13 = PIN(3, GPIOD, 13); +const mcu_pin_obj_t pin_PD14 = PIN(3, GPIOD, 14); +const mcu_pin_obj_t pin_PD15 = PIN(3, GPIOD, 15); + +const mcu_pin_obj_t pin_PC06 = PIN(2, GPIOC, 6); +const mcu_pin_obj_t pin_PC07 = PIN(2, GPIOC, 7); +const mcu_pin_obj_t pin_PC08 = PIN(2, GPIOC, 8); +const mcu_pin_obj_t pin_PC09 = PIN(2, GPIOC, 9); + +const mcu_pin_obj_t pin_PA08 = PIN(0, GPIOA, 8); +const mcu_pin_obj_t pin_PA09 = PIN(0, GPIOA, 9); +const mcu_pin_obj_t pin_PA10 = PIN(0, GPIOA, 10); +const mcu_pin_obj_t pin_PA11 = PIN(0, GPIOA, 11); +const mcu_pin_obj_t pin_PA12 = PIN(0, GPIOA, 12); +const mcu_pin_obj_t pin_PA13 = PIN(0, GPIOA, 13); +const mcu_pin_obj_t pin_PA14 = PIN(0, GPIOA, 14); +const mcu_pin_obj_t pin_PA15 = PIN(0, GPIOA, 15); + +const mcu_pin_obj_t pin_PC10 = PIN(2, GPIOC, 10); +const mcu_pin_obj_t pin_PC11 = PIN(2, GPIOC, 11); +const mcu_pin_obj_t pin_PC12 = PIN(2, GPIOC, 12); + +const mcu_pin_obj_t pin_PD00 = PIN(3, GPIOD, 0); +const mcu_pin_obj_t pin_PD01 = PIN(3, GPIOD, 1); +const mcu_pin_obj_t pin_PD02 = PIN(3, GPIOD, 2); +const mcu_pin_obj_t pin_PD03 = PIN(3, GPIOD, 3); +const mcu_pin_obj_t pin_PD04 = PIN(3, GPIOD, 4); +const mcu_pin_obj_t pin_PD05 = PIN(3, GPIOD, 5); +const mcu_pin_obj_t pin_PD06 = PIN(3, GPIOD, 6); +const mcu_pin_obj_t pin_PD07 = PIN(3, GPIOD, 7); + +const mcu_pin_obj_t pin_PB03 = PIN(1, GPIOB, 3); +const mcu_pin_obj_t pin_PB04 = PIN(1, GPIOB, 4); +const mcu_pin_obj_t pin_PB05 = PIN(1, GPIOB, 5); +const mcu_pin_obj_t pin_PB06 = PIN(1, GPIOB, 6); +const mcu_pin_obj_t pin_PB07 = PIN(1, GPIOB, 7); +const mcu_pin_obj_t pin_PB08 = PIN(1, GPIOB, 8); +const mcu_pin_obj_t pin_PB09 = PIN(1, GPIOB, 9); + +const mcu_pin_obj_t pin_PE00 = PIN(4, GPIOE, 0); +const mcu_pin_obj_t pin_PE01 = PIN(4, GPIOE, 1); \ No newline at end of file diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.h b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.h index b060d9ed0bdcd..37d3a5cf11953 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.h +++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.h @@ -24,13 +24,98 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F411RE_PINS_H -#define MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F411RE_PINS_H +#ifndef MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F411VE_PINS_H +#define MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F411VE_PINS_H -//TODO -//Pins in datasheet order: DocID028087 Rev 7 page 50. LQFP100 only -//pg 50 -//extern const mcu_pin_obj_t pin_PE02; +//Pins in datasheet order: DocID026289 Rev 7 page 38. LQFP100 only +//pg 38 +extern const mcu_pin_obj_t pin_PE02; +extern const mcu_pin_obj_t pin_PE03; +extern const mcu_pin_obj_t pin_PE04; +extern const mcu_pin_obj_t pin_PE05; +//pg 39 +extern const mcu_pin_obj_t pin_PE06; +extern const mcu_pin_obj_t pin_PC13; +extern const mcu_pin_obj_t pin_PC14; +extern const mcu_pin_obj_t pin_PC15; +extern const mcu_pin_obj_t pin_PC00; +extern const mcu_pin_obj_t pin_PC01; +extern const mcu_pin_obj_t pin_PC02; +extern const mcu_pin_obj_t pin_PC03; +//pg 40 +extern const mcu_pin_obj_t pin_PA00; +extern const mcu_pin_obj_t pin_PA01; +extern const mcu_pin_obj_t pin_PA02; +extern const mcu_pin_obj_t pin_PA03; +extern const mcu_pin_obj_t pin_PA04; +extern const mcu_pin_obj_t pin_PA05; +extern const mcu_pin_obj_t pin_PA06; +extern const mcu_pin_obj_t pin_PA07; +//pg 41 +extern const mcu_pin_obj_t pin_PC04; +extern const mcu_pin_obj_t pin_PC05; +extern const mcu_pin_obj_t pin_PB00; +extern const mcu_pin_obj_t pin_PB01; +extern const mcu_pin_obj_t pin_PB02; +extern const mcu_pin_obj_t pin_PE07; +extern const mcu_pin_obj_t pin_PE08; +extern const mcu_pin_obj_t pin_PE09; +extern const mcu_pin_obj_t pin_PE10; +extern const mcu_pin_obj_t pin_PE11; +extern const mcu_pin_obj_t pin_PE12; +extern const mcu_pin_obj_t pin_PE13; +extern const mcu_pin_obj_t pin_PE14; +extern const mcu_pin_obj_t pin_PE15; +//pg 42 +extern const mcu_pin_obj_t pin_PB10; +extern const mcu_pin_obj_t pin_PB12; +extern const mcu_pin_obj_t pin_PB13; +extern const mcu_pin_obj_t pin_PB14; +extern const mcu_pin_obj_t pin_PB15; +extern const mcu_pin_obj_t pin_PD08; +extern const mcu_pin_obj_t pin_PD09; +extern const mcu_pin_obj_t pin_PD10; +extern const mcu_pin_obj_t pin_PD11; +extern const mcu_pin_obj_t pin_PD12; +//pg 43 +extern const mcu_pin_obj_t pin_PD13; +extern const mcu_pin_obj_t pin_PD14; +extern const mcu_pin_obj_t pin_PD15; +extern const mcu_pin_obj_t pin_PC06; +extern const mcu_pin_obj_t pin_PC07; +extern const mcu_pin_obj_t pin_PC08; +extern const mcu_pin_obj_t pin_PC09; +extern const mcu_pin_obj_t pin_PA08; +extern const mcu_pin_obj_t pin_PA09; +//pg 44 +extern const mcu_pin_obj_t pin_PA10; +extern const mcu_pin_obj_t pin_PA11; +extern const mcu_pin_obj_t pin_PA12; +extern const mcu_pin_obj_t pin_PA13; +extern const mcu_pin_obj_t pin_PA14; +extern const mcu_pin_obj_t pin_PA15; +extern const mcu_pin_obj_t pin_PC10; +extern const mcu_pin_obj_t pin_PC11; +extern const mcu_pin_obj_t pin_PC12; +//pg 45 +extern const mcu_pin_obj_t pin_PD00; +extern const mcu_pin_obj_t pin_PD01; +extern const mcu_pin_obj_t pin_PD02; +extern const mcu_pin_obj_t pin_PD03; +extern const mcu_pin_obj_t pin_PD04; +extern const mcu_pin_obj_t pin_PD05; +extern const mcu_pin_obj_t pin_PD06; +extern const mcu_pin_obj_t pin_PD07; +extern const mcu_pin_obj_t pin_PB03; +extern const mcu_pin_obj_t pin_PB04; +extern const mcu_pin_obj_t pin_PB05; +extern const mcu_pin_obj_t pin_PB06; +//pg 46 +extern const mcu_pin_obj_t pin_PB07; +extern const mcu_pin_obj_t pin_PB08; +extern const mcu_pin_obj_t pin_PB09; +extern const mcu_pin_obj_t pin_PE00; +extern const mcu_pin_obj_t pin_PE01; -#endif // MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F411RE_PINS_H +#endif // MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F411VE_PINS_H diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f412zx/pins.c b/ports/stm32f4/peripherals/stm32f4/stm32f412zx/pins.c index 5a4703bea213c..1a556e1008983 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f412zx/pins.c +++ b/ports/stm32f4/peripherals/stm32f4/stm32f412zx/pins.c @@ -35,6 +35,8 @@ const mcu_pin_obj_t pin_PE05 = PIN(4, GPIOE, 5); const mcu_pin_obj_t pin_PE06 = PIN(4, GPIOE, 6); const mcu_pin_obj_t pin_PC13 = PIN(2, GPIOC, 13); +const mcu_pin_obj_t pin_PC14 = PIN(2, GPIOC, 14); //OSC32_IN +const mcu_pin_obj_t pin_PC15 = PIN(2, GPIOC, 15); //OSC32_OUT const mcu_pin_obj_t pin_PF00 = PIN(5, GPIOF, 0); // 144 only const mcu_pin_obj_t pin_PF01 = PIN(5, GPIOF, 1); // 144 only diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f412zx/pins.h b/ports/stm32f4/peripherals/stm32f4/stm32f412zx/pins.h index a74bf7c5d1fd3..180f5c316fa5e 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f412zx/pins.h +++ b/ports/stm32f4/peripherals/stm32f4/stm32f412zx/pins.h @@ -35,7 +35,9 @@ extern const mcu_pin_obj_t pin_PE04; extern const mcu_pin_obj_t pin_PE05; extern const mcu_pin_obj_t pin_PE06; extern const mcu_pin_obj_t pin_PC13; +extern const mcu_pin_obj_t pin_PC14; //pg 51 +extern const mcu_pin_obj_t pin_PC15; extern const mcu_pin_obj_t pin_PF00; // 144 only extern const mcu_pin_obj_t pin_PF01; // 144 only extern const mcu_pin_obj_t pin_PF02; // 144 only From 294d6dc8673d3c288033ac226ff1d695b8df1073 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Fri, 9 Aug 2019 19:58:54 -0400 Subject: [PATCH 13/27] Add flash functions and setup, fix msc descriptor bug --- .../stm32f411ve_discovery/mpconfigboard.h | 12 +- .../stm32f411ve_discovery/mpconfigboard.mk | 3 + ports/stm32f4/supervisor/internal_flash.c | 114 +++++++++++++++++- ports/stm32f4/supervisor/internal_flash.h | 19 ++- tools/gen_usb_descriptor.py | 4 +- 5 files changed, 139 insertions(+), 13 deletions(-) diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h index 1b1410aea23af..1bb5849afae7b 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h @@ -30,11 +30,13 @@ #define MICROPY_HW_BOARD_NAME "STM32F411E_DISCO" #define MICROPY_HW_MCU_NAME "STM32F411xE" -#define FLASH_SIZE (0x7D000) -#define FLASH_PAGE_SIZE (0x4000) +// #define FLASH_SIZE (0x7D000) +// #define FLASH_PAGE_SIZE (0x4000) #define CIRCUITPY_AUTORELOAD_DELAY_MS 500 -#define CIRCUITPY_INTERNAL_NVM_SIZE (4096) -#define AUTORESET_DELAY_MS 500 -#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) \ No newline at end of file +#define CIRCUITPY_INTERNAL_NVM_SIZE 256 + +#define BOARD_FLASH_SIZE (0x8080000 - 0x2000 - 0x019000 - CIRCUITPY_INTERNAL_NVM_SIZE) + +#define AUTORESET_DELAY_MS 500 \ No newline at end of file diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk index 7c4e3be3a31f6..747d34ebe440f 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk @@ -3,6 +3,9 @@ USB_PID = 0x802A USB_PRODUCT = "STM32F411VE Discovery Board - CPy" USB_MANUFACTURER = "Adafruit Industries LLC" +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE + MCU_SERIES = m4 MCU_VARIANT = stm32f4 MCU_SUB_VARIANT = stm32f411xe diff --git a/ports/stm32f4/supervisor/internal_flash.c b/ports/stm32f4/supervisor/internal_flash.c index e05236948158f..fab0678182cb0 100644 --- a/ports/stm32f4/supervisor/internal_flash.c +++ b/ports/stm32f4/supervisor/internal_flash.c @@ -23,7 +23,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include "supervisor/flash.h" +#include "supervisor/internal_flash.h" #include #include @@ -35,11 +35,56 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" +#include "stm32f4xx_hal.h" + +typedef struct { + uint32_t base_address; + uint32_t sector_size; + uint32_t sector_count; +} flash_layout_t; /*------------------------------------------------------------------*/ /* Internal Flash API *------------------------------------------------------------------*/ +static const flash_layout_t flash_layout[] = { + { 0x08000000, 0x04000, 4 }, + { 0x08010000, 0x10000, 1 }, + { 0x08020000, 0x20000, 3 }, + #if defined(FLASH_SECTOR_8) + { 0x08080000, 0x20000, 4 }, + #endif + #if defined(FLASH_SECTOR_12) + { 0x08100000, 0x04000, 4 }, + { 0x08110000, 0x10000, 1 }, + { 0x08120000, 0x20000, 7 }, + #endif +}; + +uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { + if (addr >= flash_layout[0].base_address) { + uint32_t sector_index = 0; + for (int i = 0; i < MP_ARRAY_SIZE(flash_layout); ++i) { + for (int j = 0; j < flash_layout[i].sector_count; ++j) { + uint32_t sector_start_next = flash_layout[i].base_address + + (j + 1) * flash_layout[i].sector_size; + if (addr < sector_start_next) { + if (start_addr != NULL) { + *start_addr = flash_layout[i].base_address + + j * flash_layout[i].sector_size; + } + if (size != NULL) { + *size = flash_layout[i].sector_size; + } + return sector_index; + } + ++sector_index; + } + } + } + return 0; +} + void supervisor_flash_init(void) { } @@ -48,21 +93,82 @@ uint32_t supervisor_flash_get_block_size(void) { } uint32_t supervisor_flash_get_block_count(void) { - return false; + return INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS; } void supervisor_flash_flush(void) { +} +static int32_t convert_block_to_flash_addr(uint32_t block) { + if (0 <= block && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { + // a block in partition 1 + return INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE; + } + // bad block + return -1; } mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { - + uint32_t src = convert_block_to_flash_addr(block); + if (src == -1) { + // bad block number + return false; + } + memcpy(dest, (uint8_t*) src, FILESYSTEM_BLOCK_SIZE*num_blocks); return 0; // success } -mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32_t num_blocks) { +bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { + int32_t dest = convert_block_to_flash_addr(block); + if (dest == -1) { + // bad block number + return false; + } + + // unlock + HAL_FLASH_Unlock(); + + FLASH_EraseInitTypeDef EraseInitStruct; + + // erase the sector(s) + EraseInitStruct.TypeErase = TYPEERASE_SECTORS; + EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V + //get the sector number + EraseInitStruct.Sector = flash_get_sector_info(dest, NULL, NULL); + //find end address, subtract for number of sectors + EraseInitStruct.NbSectors = flash_get_sector_info(dest + FILESYSTEM_BLOCK_SIZE - 1, NULL, NULL) - EraseInitStruct.Sector + 1; + + uint32_t SectorError = 0; + if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) { + // error occurred during sector erase + HAL_FLASH_Lock(); // lock the flash + return false; + } + + // program the flash word by word + for (int i = 0; i < (FILESYSTEM_BLOCK_SIZE / 4); i++) { + if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, dest, *src) != HAL_OK) { + // error occurred during flash write + HAL_FLASH_Lock(); // lock the flash + return false; + } + dest += 4; + src += 1; //src += 4; + } + + // lock the flash + HAL_FLASH_Lock(); + + return true; +} +mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { + for (size_t i = 0; i < num_blocks; i++) { + if (!supervisor_flash_write_block(src + i * FILESYSTEM_BLOCK_SIZE, block_num + i)) { + return 1; // error + } + } return 0; // success } diff --git a/ports/stm32f4/supervisor/internal_flash.h b/ports/stm32f4/supervisor/internal_flash.h index 8c015a3e46345..4d720913fd530 100644 --- a/ports/stm32f4/supervisor/internal_flash.h +++ b/ports/stm32f4/supervisor/internal_flash.h @@ -31,7 +31,22 @@ #include "py/mpconfig.h" -#define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms -#define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2) +#ifdef STM32F411xE +#define STM32_FLASH_SIZE 0x80000 //512KiB +#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x19000 //100KiB +#endif + +#ifdef STM32F412Zx +#define STM32_FLASH_SIZE 0x100000 //512KiB +#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x19000 //100KiB +#endif + +#define STM32_FLASH_OFFSET 0x8000000 //All STM32 chips map to this flash location + +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR ((STM32_FLASH_SIZE + STM32_FLASH_OFFSET) - INTERNAL_FLASH_FILESYSTEM_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE) +#define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) + +// #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/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index db17c97666595..a5667dd46e34e 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -131,7 +131,7 @@ def strings_in_order(cls): bInterval=0), standard.EndpointDescriptor( description="MSC out", - bEndpointAddress=0x1 | standard.EndpointDescriptor.DIRECTION_OUT, + bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_OUT, bmAttributes=standard.EndpointDescriptor.TYPE_BULK, bInterval=0) ] @@ -273,7 +273,7 @@ def strings_in_order(cls): descriptor_list = [] descriptor_list.append(cdc_iad) descriptor_list.extend(cdc_interfaces) -# descriptor_list.extend(msc_interfaces) +descriptor_list.extend(msc_interfaces) # Only add the control interface because other audio interfaces are managed by it to ensure the # correct ordering. # descriptor_list.append(audio_control_interface) From 300dc68955141ede186521e9fb1678d693c02fdf Mon Sep 17 00:00:00 2001 From: Hierophect Date: Sat, 10 Aug 2019 18:00:09 -0400 Subject: [PATCH 14/27] Further non-functional flash changes --- ports/stm32f4/boards/STM32F411VETx_FLASH.ld | 2 +- .../boards/stm32f411ve_discovery/mpconfigboard.h | 4 ++-- .../peripherals/stm32f4/stm32f411xe/clocks.c | 2 +- ports/stm32f4/supervisor/internal_flash.c | 13 +++++++++++++ ports/stm32f4/supervisor/internal_flash.h | 4 ++-- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ports/stm32f4/boards/STM32F411VETx_FLASH.ld b/ports/stm32f4/boards/STM32F411VETx_FLASH.ld index a3c3594a94149..763e7bcea9611 100644 --- a/ports/stm32f4/boards/STM32F411VETx_FLASH.ld +++ b/ports/stm32f4/boards/STM32F411VETx_FLASH.ld @@ -62,7 +62,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */ MEMORY { RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K +FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K - 256 - 100K } /* Define output sections */ diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h index 1bb5849afae7b..81e0f8790100b 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h @@ -30,8 +30,8 @@ #define MICROPY_HW_BOARD_NAME "STM32F411E_DISCO" #define MICROPY_HW_MCU_NAME "STM32F411xE" -// #define FLASH_SIZE (0x7D000) -// #define FLASH_PAGE_SIZE (0x4000) +#define FLASH_SIZE (0x80000) //512K +#define FLASH_PAGE_SIZE (0x4000) //16K #define CIRCUITPY_AUTORELOAD_DELAY_MS 500 diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c index f1ce6fef9f749..6d2a6fac9a937 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c +++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c @@ -57,5 +57,5 @@ void stm32f4_peripherals_clocks_init(void) { RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3); } diff --git a/ports/stm32f4/supervisor/internal_flash.c b/ports/stm32f4/supervisor/internal_flash.c index fab0678182cb0..70d9277e069ff 100644 --- a/ports/stm32f4/supervisor/internal_flash.c +++ b/ports/stm32f4/supervisor/internal_flash.c @@ -61,6 +61,7 @@ static const flash_layout_t flash_layout[] = { #endif }; +//Return the sector of a given flash address. uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { if (addr >= flash_layout[0].base_address) { uint32_t sector_index = 0; @@ -122,6 +123,7 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { int32_t dest = convert_block_to_flash_addr(block); if (dest == -1) { // bad block number + mp_printf(&mp_plat_print, "BAD FLASH BLOCK ERROR"); return false; } @@ -142,14 +144,25 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) { // error occurred during sector erase HAL_FLASH_Lock(); // lock the flash + mp_printf(&mp_plat_print, "FLASH SECTOR ERASE ERROR"); return false; } + __HAL_FLASH_DATA_CACHE_DISABLE(); + __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); + + __HAL_FLASH_DATA_CACHE_RESET(); + __HAL_FLASH_INSTRUCTION_CACHE_RESET(); + + __HAL_FLASH_INSTRUCTION_CACHE_ENABLE(); + __HAL_FLASH_DATA_CACHE_ENABLE(); + // program the flash word by word for (int i = 0; i < (FILESYSTEM_BLOCK_SIZE / 4); i++) { if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, dest, *src) != HAL_OK) { // error occurred during flash write HAL_FLASH_Lock(); // lock the flash + mp_printf(&mp_plat_print, "FLASH WRITE ERROR"); return false; } dest += 4; diff --git a/ports/stm32f4/supervisor/internal_flash.h b/ports/stm32f4/supervisor/internal_flash.h index 4d720913fd530..434281ed56982 100644 --- a/ports/stm32f4/supervisor/internal_flash.h +++ b/ports/stm32f4/supervisor/internal_flash.h @@ -46,7 +46,7 @@ #define INTERNAL_FLASH_FILESYSTEM_START_ADDR ((STM32_FLASH_SIZE + STM32_FLASH_OFFSET) - INTERNAL_FLASH_FILESYSTEM_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE) #define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) -// #define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms -// #define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2) +#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 From c4c55fffb193bb2fb6660f33651edaece4898dfd Mon Sep 17 00:00:00 2001 From: Hierophect Date: Tue, 13 Aug 2019 18:05:40 -0400 Subject: [PATCH 15/27] Fixed remaining issues with flash organization and writing --- ports/stm32f4/boards/STM32F411VETx_FLASH.ld | 272 +++++++----------- .../stm32f411ve_discovery/mpconfigboard.h | 2 +- ports/stm32f4/supervisor/internal_flash.c | 39 ++- ports/stm32f4/supervisor/internal_flash.h | 9 +- 4 files changed, 128 insertions(+), 194 deletions(-) diff --git a/ports/stm32f4/boards/STM32F411VETx_FLASH.ld b/ports/stm32f4/boards/STM32F411VETx_FLASH.ld index 763e7bcea9611..fc9ffdff56bd1 100644 --- a/ports/stm32f4/boards/STM32F411VETx_FLASH.ld +++ b/ports/stm32f4/boards/STM32F411VETx_FLASH.ld @@ -1,189 +1,109 @@ /* -****************************************************************************** -** - -** File : LinkerScript.ld -** -** Author : Auto-generated by Ac6 System Workbench -** -** Abstract : Linker script for STM32F411VETx series -** 512Kbytes FLASH and 128Kbytes RAM -** -** Set heap size, stack size and stack location according -** to application requirements. -** -** Set memory bank area and size if external memory is used. -** -** Target : STMicroelectronics STM32 -** -** Distribution: The file is distributed “as is,” without any warranty -** of any kind. -** -***************************************************************************** -** @attention -** -**

© COPYRIGHT(c) 2014 Ac6

-** -** Redistribution and use in source and binary forms, with or without modification, -** are permitted provided that the following conditions are met: -** 1. Redistributions of source code must retain the above copyright notice, -** this list of conditions and the following disclaimer. -** 2. Redistributions in binary form must reproduce the above copyright notice, -** this list of conditions and the following disclaimer in the documentation -** and/or other materials provided with the distribution. -** 3. Neither the name of Ac6 nor the names of its contributors -** may be used to endorse or promote products derived from this software -** without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -** -***************************************************************************** + GNU linker script for STM32F411 via Micropython */ -/* Entry Point */ -ENTRY(Reset_Handler) - -/* Highest address of the user mode stack */ -_estack = 0x20020000; /* end of RAM */ -/* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x200; /* required amount of heap */ -_Min_Stack_Size = 0x400; /* required amount of stack */ - /* Specify the memory areas */ MEMORY { -RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K - 256 - 100K + FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K /* entire flash */ + FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */ + FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 112K /* sectors 1,2,3 are 16K, 4 is 64K */ + FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* sectors 5,6,7 are 128K */ + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K } -/* Define output sections */ +/* produce a link error if there is not this amount of RAM for these sections */ +_minimum_stack_size = 2K; +_minimum_heap_size = 16K; + +/* Define tho top end of the stack. The stack is full descending so begins just + above last byte of RAM. Note that EABI requires the stack to be 8-byte + aligned for a call. */ +_estack = ORIGIN(RAM) + LENGTH(RAM); + +/* RAM extents for the garbage collector */ +_ram_start = ORIGIN(RAM); +_ram_end = ORIGIN(RAM) + LENGTH(RAM); +_heap_start = _ebss; /* heap starts just after statically allocated memory */ +_heap_end = 0x2001c000; /* tunable */ + +ENTRY(Reset_Handler) + +/* define output sections */ SECTIONS { - /* The startup code goes first into FLASH */ - .isr_vector : - { - . = ALIGN(4); - KEEP(*(.isr_vector)) /* Startup code */ - . = ALIGN(4); - } >FLASH - - /* The program code and other data goes into FLASH */ - .text : - { - . = ALIGN(4); - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.glue_7) /* glue arm to thumb code */ - *(.glue_7t) /* glue thumb to arm code */ - *(.eh_frame) - - KEEP (*(.init)) - KEEP (*(.fini)) - - . = ALIGN(4); - _etext = .; /* define a global symbols at end of code */ - } >FLASH - - /* Constant data goes into FLASH */ - .rodata : - { - . = ALIGN(4); - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - . = ALIGN(4); - } >FLASH - - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH - .ARM : { - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - } >FLASH - - .preinit_array : - { - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array*)) - PROVIDE_HIDDEN (__preinit_array_end = .); - } >FLASH - .init_array : - { - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array*)) - PROVIDE_HIDDEN (__init_array_end = .); - } >FLASH - .fini_array : - { - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array*)) - PROVIDE_HIDDEN (__fini_array_end = .); - } >FLASH - - /* used by the startup to initialize data */ - _sidata = LOADADDR(.data); - - /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : - { - . = ALIGN(4); - _sdata = .; /* create a global symbol at data start */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - - . = ALIGN(4); - _edata = .; /* define a global symbol at data end */ - } >RAM AT> FLASH - - - /* Uninitialized data section */ - . = ALIGN(4); - .bss : - { - /* This is used by the startup in order to initialize the .bss secion */ - _sbss = .; /* define a global symbol at bss start */ - __bss_start__ = _sbss; - *(.bss) - *(.bss*) - *(COMMON) - - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end */ - __bss_end__ = _ebss; - } >RAM - - /* User_heap_stack section, used to check that there is enough RAM left */ - ._user_heap_stack : - { - . = ALIGN(8); - PROVIDE ( end = . ); - PROVIDE ( _end = . ); - . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; - . = ALIGN(8); - } >RAM - - - - /* Remove information from the standard libraries */ - /DISCARD/ : - { - libc.a ( * ) - libm.a ( * ) - libgcc.a ( * ) - } - - .ARM.attributes 0 : { *(.ARM.attributes) } + /* The startup code goes first into FLASH */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + + /* This first flash block is 16K annd the isr vectors only take up + about 400 bytes. Micropython pads this with files, but this didn't + work with the size of Circuitpython's ff object. */ + + . = ALIGN(4); + } >FLASH_ISR + + /* The program code and other data goes into FLASH */ + .text : + { + . = ALIGN(4); + *(.text*) /* .text* sections (code) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + /* *(.glue_7) */ /* glue arm to thumb code */ + /* *(.glue_7t) */ /* glue thumb to arm code */ + + . = ALIGN(4); + _etext = .; /* define a global symbol at end of code */ + } >FLASH_TEXT + + /* used by the startup to initialize data */ + _sidata = LOADADDR(.data); + + /* This is the initialized data section + The program executes knowing that the data is in the RAM + but the loader puts the initial values in the FLASH (inidata). + It is one task of the startup to copy the initial values from FLASH to RAM. */ + .data : + { + . = ALIGN(4); + _sdata = .; /* create a global symbol at data start; used by startup code in order to initialise the .data section in RAM */ + *(.data*) /* .data* sections */ + + . = ALIGN(4); + _edata = .; /* define a global symbol at data end; used by startup code in order to initialise the .data section in RAM */ + } >RAM AT> FLASH_TEXT + + /* Uninitialized data section */ + .bss : + { + . = ALIGN(4); + _sbss = .; /* define a global symbol at bss start; used by startup code */ + *(.bss*) + *(COMMON) + + . = ALIGN(4); + _ebss = .; /* define a global symbol at bss end; used by startup code and GC */ + } >RAM + + /* this is to define the start of the heap, and make sure we have a minimum size */ + .heap : + { + . = ALIGN(4); + . = . + _minimum_heap_size; + . = ALIGN(4); + } >RAM + + /* this just checks there is enough RAM for the stack */ + .stack : + { + . = ALIGN(4); + . = . + _minimum_stack_size; + . = ALIGN(4); + } >RAM + + .ARM.attributes 0 : { *(.ARM.attributes) } } diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h index 81e0f8790100b..979b75b4c7463 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h @@ -37,6 +37,6 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 256 -#define BOARD_FLASH_SIZE (0x8080000 - 0x2000 - 0x019000 - CIRCUITPY_INTERNAL_NVM_SIZE) +#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0x01C000 - CIRCUITPY_INTERNAL_NVM_SIZE) #define AUTORESET_DELAY_MS 500 \ No newline at end of file diff --git a/ports/stm32f4/supervisor/internal_flash.c b/ports/stm32f4/supervisor/internal_flash.c index 70d9277e069ff..966b167d80134 100644 --- a/ports/stm32f4/supervisor/internal_flash.c +++ b/ports/stm32f4/supervisor/internal_flash.c @@ -1,4 +1,4 @@ -/* +/*f * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) @@ -61,6 +61,8 @@ static const flash_layout_t flash_layout[] = { #endif }; +static uint8_t sector_copy[0x4000] __attribute__((aligned(4))); + //Return the sector of a given flash address. uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { if (addr >= flash_layout[0].base_address) { @@ -127,19 +129,31 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { return false; } - // unlock + // unlock flash HAL_FLASH_Unlock(); + // set up for erase FLASH_EraseInitTypeDef EraseInitStruct; - - // erase the sector(s) EraseInitStruct.TypeErase = TYPEERASE_SECTORS; EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V - //get the sector number - EraseInitStruct.Sector = flash_get_sector_info(dest, NULL, NULL); - //find end address, subtract for number of sectors - EraseInitStruct.NbSectors = flash_get_sector_info(dest + FILESYSTEM_BLOCK_SIZE - 1, NULL, NULL) - EraseInitStruct.Sector + 1; + // get the sector information + uint32_t sector_size; + uint32_t sector_start_addr; + EraseInitStruct.Sector = flash_get_sector_info(dest, §or_start_addr, §or_size); + EraseInitStruct.NbSectors = 1; + if (sector_size>0x4000) return false; + + // copy the sector + memcpy(sector_copy,(void *)sector_start_addr,sector_size); + + // // overwrite sector data + memcpy(sector_copy+(dest-sector_start_addr),src,FILESYSTEM_BLOCK_SIZE); + + // find end address, subtract for number of sectors + // Shouldn't be required since blocks will always fit in a single sector, they should never overlap + //EraseInitStruct.NbSectors = flash_get_sector_info(dest + FILESYSTEM_BLOCK_SIZE - 1, NULL, NULL) - EraseInitStruct.Sector + 1; + // erase the sector uint32_t SectorError = 0; if (HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) != HAL_OK) { // error occurred during sector erase @@ -157,16 +171,15 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { __HAL_FLASH_INSTRUCTION_CACHE_ENABLE(); __HAL_FLASH_DATA_CACHE_ENABLE(); - // program the flash word by word - for (int i = 0; i < (FILESYSTEM_BLOCK_SIZE / 4); i++) { - if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, dest, *src) != HAL_OK) { + // reprogram the sector + for (int i = 0; i < sector_size; i++) { + if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, sector_start_addr, (uint64_t)sector_copy[i]) != HAL_OK) { // error occurred during flash write HAL_FLASH_Lock(); // lock the flash mp_printf(&mp_plat_print, "FLASH WRITE ERROR"); return false; } - dest += 4; - src += 1; //src += 4; + sector_start_addr += 1; } // lock the flash diff --git a/ports/stm32f4/supervisor/internal_flash.h b/ports/stm32f4/supervisor/internal_flash.h index 434281ed56982..c8a60cc557617 100644 --- a/ports/stm32f4/supervisor/internal_flash.h +++ b/ports/stm32f4/supervisor/internal_flash.h @@ -33,17 +33,18 @@ #ifdef STM32F411xE #define STM32_FLASH_SIZE 0x80000 //512KiB -#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x19000 //100KiB +#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x1C000 //112KiB #endif #ifdef STM32F412Zx -#define STM32_FLASH_SIZE 0x100000 //512KiB -#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x19000 //100KiB +#define STM32_FLASH_SIZE 0x100000 //1MB +#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x1C000 //112KiB #endif #define STM32_FLASH_OFFSET 0x8000000 //All STM32 chips map to this flash location -#define INTERNAL_FLASH_FILESYSTEM_START_ADDR ((STM32_FLASH_SIZE + STM32_FLASH_OFFSET) - INTERNAL_FLASH_FILESYSTEM_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE) +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x08004000 +//#define INTERNAL_FLASH_FILESYSTEM_START_ADDR ((STM32_FLASH_SIZE + STM32_FLASH_OFFSET) - INTERNAL_FLASH_FILESYSTEM_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE) #define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) #define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms From 1539dca7f0f6c70b5dda663cfc5d5a9d748e7d9b Mon Sep 17 00:00:00 2001 From: Hierophect Date: Wed, 14 Aug 2019 13:14:42 -0400 Subject: [PATCH 16/27] Add reset support, minor fixes --- ports/stm32f4/common-hal/microcontroller/__init__.c | 11 +++++++---- ports/stm32f4/mpconfigport.mk | 1 + ports/stm32f4/supervisor/port.c | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ports/stm32f4/common-hal/microcontroller/__init__.c b/ports/stm32f4/common-hal/microcontroller/__init__.c index 75f6550df6faa..08f8f28f80adf 100644 --- a/ports/stm32f4/common-hal/microcontroller/__init__.c +++ b/ports/stm32f4/common-hal/microcontroller/__init__.c @@ -37,11 +37,13 @@ #include "shared-bindings/microcontroller/Processor.h" #include "supervisor/filesystem.h" +#include "supervisor/shared/safe_mode.h" // This routine should work even when interrupts are disabled. Used by OneWire // for precise timing. void common_hal_mcu_delay_us(uint32_t delay) { - //NRFX_DELAY_US(delay); + //TODO: implement equivalent of mp_hal_delay_us(delay); + //this is fairly annoying in the STM32 HAL } void common_hal_mcu_disable_interrupts() { @@ -51,12 +53,13 @@ void common_hal_mcu_enable_interrupts() { } void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { - // TODO: see atmel-samd for functionality + if(runmode == RUNMODE_SAFE_MODE) + safe_mode_on_next_reset(PROGRAMMATIC_SAFE_MODE); } void common_hal_mcu_reset(void) { - // filesystem_flush(); - // NVIC_SystemReset(); + filesystem_flush(); + NVIC_SystemReset(); } // The singleton microcontroller.Processor object, bound to microcontroller.cpu diff --git a/ports/stm32f4/mpconfigport.mk b/ports/stm32f4/mpconfigport.mk index 440d296f65999..78c8e763008db 100644 --- a/ports/stm32f4/mpconfigport.mk +++ b/ports/stm32f4/mpconfigport.mk @@ -20,4 +20,5 @@ CIRCUITPY_MINIMAL_BUILD = 1 CIRCUITPY_DIGITALIO = 1 CIRCUITPY_MICROCONTROLLER = 1 CIRCUITPY_BUSIO = 1 + CIRCUITPY_TIME = 1 #endif \ No newline at end of file diff --git a/ports/stm32f4/supervisor/port.c b/ports/stm32f4/supervisor/port.c index 6030547acfd26..e981318c088c4 100644 --- a/ports/stm32f4/supervisor/port.c +++ b/ports/stm32f4/supervisor/port.c @@ -69,6 +69,6 @@ uint32_t port_get_saved_word(void) { return _ebss; } -// void HardFault_Handler(void) { +void HardFault_Handler(void) { -// } +} From 60b4cd64f1d9aad3d5265cf51f62889ea24cb560 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Wed, 14 Aug 2019 13:29:15 -0400 Subject: [PATCH 17/27] Fix desynchronized submodules --- frozen/Adafruit_CircuitPython_HID | 2 +- frozen/Adafruit_CircuitPython_LIS3DH | 2 +- frozen/Adafruit_CircuitPython_seesaw | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID index c9e07857dc10f..89faee0eb08a6 160000 --- a/frozen/Adafruit_CircuitPython_HID +++ b/frozen/Adafruit_CircuitPython_HID @@ -1 +1 @@ -Subproject commit c9e07857dc10ff5e6c743e5e8c00e9b049800d09 +Subproject commit 89faee0eb08a6855e14f117c514fecf2dd90769d diff --git a/frozen/Adafruit_CircuitPython_LIS3DH b/frozen/Adafruit_CircuitPython_LIS3DH index f5892e24f7235..de75d00f8b0ab 160000 --- a/frozen/Adafruit_CircuitPython_LIS3DH +++ b/frozen/Adafruit_CircuitPython_LIS3DH @@ -1 +1 @@ -Subproject commit f5892e24f7235c4bde2908cbb3cd0a3d6b34d421 +Subproject commit de75d00f8b0aba67bf6a3a8cc21489aa21e27e67 diff --git a/frozen/Adafruit_CircuitPython_seesaw b/frozen/Adafruit_CircuitPython_seesaw index 4b101f00320d3..a0fcd3f570a16 160000 --- a/frozen/Adafruit_CircuitPython_seesaw +++ b/frozen/Adafruit_CircuitPython_seesaw @@ -1 +1 @@ -Subproject commit 4b101f00320d36b23f8cc28cf3f12127085894c1 +Subproject commit a0fcd3f570a1698f25b389fcc32e27a459c2d6eb From e0a49532f02c1142dd9f37ee9d632b1467d56247 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Wed, 14 Aug 2019 13:38:31 -0400 Subject: [PATCH 18/27] more submodule fixes --- frozen/Adafruit_CircuitPython_LIS3DH | 2 +- frozen/Adafruit_CircuitPython_seesaw | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frozen/Adafruit_CircuitPython_LIS3DH b/frozen/Adafruit_CircuitPython_LIS3DH index de75d00f8b0ab..bd7ddc67dc86f 160000 --- a/frozen/Adafruit_CircuitPython_LIS3DH +++ b/frozen/Adafruit_CircuitPython_LIS3DH @@ -1 +1 @@ -Subproject commit de75d00f8b0aba67bf6a3a8cc21489aa21e27e67 +Subproject commit bd7ddc67dc86f7ad0115f58ab80d5605739c6482 diff --git a/frozen/Adafruit_CircuitPython_seesaw b/frozen/Adafruit_CircuitPython_seesaw index a0fcd3f570a16..f1171f94083ba 160000 --- a/frozen/Adafruit_CircuitPython_seesaw +++ b/frozen/Adafruit_CircuitPython_seesaw @@ -1 +1 @@ -Subproject commit a0fcd3f570a1698f25b389fcc32e27a459c2d6eb +Subproject commit f1171f94083ba64d153ff3f90eeb07500331d6e1 From 620d3d14ddd5ee39d256640719b3e10c927139f3 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Thu, 15 Aug 2019 13:41:51 -0400 Subject: [PATCH 19/27] Add conditional endpoints to descriptor script --- .../stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk | 1 + supervisor/supervisor.mk | 3 ++- tools/gen_usb_descriptor.py | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk index 747d34ebe440f..aa867c96f840b 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk @@ -2,6 +2,7 @@ USB_VID = 0x239A USB_PID = 0x802A USB_PRODUCT = "STM32F411VE Discovery Board - CPy" USB_MANUFACTURER = "Adafruit Industries LLC" +USB_REDUCED_ENDPOINT = 1 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 42a55243e068f..1022dd2a34dee 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -100,7 +100,8 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile --pid $(USB_PID)\ --serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\ --output_c_file $(BUILD)/autogen_usb_descriptor.c\ - --output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h + --output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h\ + --reduced_endpoint_mode $(USB_REDUCED_ENDPOINT) CIRCUITPY_DISPLAY_FONT ?= "../../tools/fonts/ter-u12n.bdf" diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index a5667dd46e34e..c23b413d257b8 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -21,6 +21,7 @@ help='length needed for the serial number in digits') parser.add_argument('--output_c_file', type=argparse.FileType('w'), required=True) parser.add_argument('--output_h_file', type=argparse.FileType('w'), required=True) +parser.add_argument('--reduced_endpoint_mode', nargs='?',const=0, type=int) args = parser.parse_args() @@ -276,14 +277,16 @@ def strings_in_order(cls): descriptor_list.extend(msc_interfaces) # Only add the control interface because other audio interfaces are managed by it to ensure the # correct ordering. -# descriptor_list.append(audio_control_interface) +if not args.reduced_endpoint_mode: + descriptor_list.append(audio_control_interface) # Put the CDC IAD just before the CDC interfaces. # There appears to be a bug in the Windows composite USB driver that requests the # HID report descriptor with the wrong interface number if the HID interface is not given # first. However, it still fetches the descriptor anyway. We could reorder the interfaces but # the Windows 7 Adafruit_usbser.inf file thinks CDC is at Interface 0, so we'll leave it # there for backwards compatibility. -# descriptor_list.extend(hid_interfaces) +if not args.reduced_endpoint_mode: + descriptor_list.extend(hid_interfaces) configuration = standard.ConfigurationDescriptor( description="Composite configuration", From 0fdb5a032f6686ab3f7d29fcf649a2f9f7480b41 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Thu, 15 Aug 2019 15:12:50 -0400 Subject: [PATCH 20/27] Text fixes --- ports/stm32f4/common-hal/busio/SPI.c | 244 +------------------- ports/stm32f4/common-hal/busio/UART.c | 309 +------------------------- 2 files changed, 12 insertions(+), 541 deletions(-) diff --git a/ports/stm32f4/common-hal/busio/SPI.c b/ports/stm32f4/common-hal/busio/SPI.c index a8b91998421af..dfb436fb935a2 100644 --- a/ports/stm32f4/common-hal/busio/SPI.c +++ b/ports/stm32f4/common-hal/busio/SPI.c @@ -34,215 +34,24 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi, const mcu_pin_obj_t * miso) { - // Sercom* sercom = NULL; - // uint8_t sercom_index; - // uint32_t clock_pinmux = 0; - // bool mosi_none = mosi == mp_const_none || mosi == NULL; - // bool miso_none = miso == mp_const_none || miso == NULL; - // uint32_t mosi_pinmux = 0; - // uint32_t miso_pinmux = 0; - // uint8_t clock_pad = 0; - // uint8_t mosi_pad = 0; - // uint8_t miso_pad = 0; - // uint8_t dopo = 255; - - // // Special case for SAMR boards. - // #ifdef PIN_PC19 - // if (miso == &pin_PC19) { - // if (mosi == &pin_PB30 && clock == &pin_PC18) { - // sercom = SERCOM4; - // sercom_index = 4; - // clock_pinmux = MUX_F; - // mosi_pinmux = MUX_F; - // miso_pinmux = MUX_F; - // clock_pad = 3; - // mosi_pad = 2; - // miso_pad = 0; - // dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad); - // } - // // Error, leave SERCOM unset to throw an exception later. - // } else { - // #endif - // for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) { - // sercom_index = clock->sercom[i].index; // 2 for SERCOM2, etc. - // if (sercom_index >= SERCOM_INST_NUM) { - // continue; - // } - // Sercom* potential_sercom = sercom_insts[sercom_index]; - // if ( - // #if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !defined(CIRCUITPY_BITBANG_APA102) - // (potential_sercom->SPI.CTRLA.bit.ENABLE != 0 && - // potential_sercom != status_apa102.spi_desc.dev.prvt && - // !apa102_sck_in_use)) { - // #else - // potential_sercom->SPI.CTRLA.bit.ENABLE != 0) { - // #endif - // continue; - // } - // clock_pinmux = PINMUX(clock->number, (i == 0) ? MUX_C : MUX_D); - // clock_pad = clock->sercom[i].pad; - // if (!samd_peripherals_valid_spi_clock_pad(clock_pad)) { - // continue; - // } - // for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { - // if (!mosi_none) { - // if (sercom_index == mosi->sercom[j].index) { - // mosi_pinmux = PINMUX(mosi->number, (j == 0) ? MUX_C : MUX_D); - // mosi_pad = mosi->sercom[j].pad; - // dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad); - // if (dopo > 0x3) { - // continue; // pad combination not possible - // } - // if (miso_none) { - // sercom = potential_sercom; - // break; - // } - // } else { - // continue; - // } - // } - // if (!miso_none) { - // for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) { - // if (sercom_index == miso->sercom[k].index) { - // miso_pinmux = PINMUX(miso->number, (k == 0) ? MUX_C : MUX_D); - // miso_pad = miso->sercom[k].pad; - // sercom = potential_sercom; - // break; - // } - // } - // } - // if (sercom != NULL) { - // break; - // } - // } - // if (sercom != NULL) { - // break; - // } - // } - // #ifdef PIN_PC19 - // } - // #endif - // if (sercom == NULL) { - // mp_raise_ValueError(translate("Invalid pins")); - // } - - // // Set up SPI clocks on SERCOM. - // samd_peripherals_sercom_clock_init(sercom, sercom_index); - - // #if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !defined(CIRCUITPY_BITBANG_APA102) - // // if we're re-using the dotstar sercom, make sure it is disabled or the init will fail out - // hri_sercomspi_clear_CTRLA_ENABLE_bit(sercom); - // #endif - // if (spi_m_sync_init(&self->spi_desc, sercom) != ERR_NONE) { - // mp_raise_OSError(MP_EIO); - // } - - // // Pads must be set after spi_m_sync_init(), which uses default values from - // // the prototypical SERCOM. - // hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo); - // hri_sercomspi_write_CTRLA_DIPO_bf(sercom, miso_pad); - - // // Always start at 250khz which is what SD cards need. They are sensitive to - // // SPI bus noise before they are put into SPI mode. - // uint8_t baud_value = samd_peripherals_spi_baudrate_to_baud_reg_value(250000); - // if (spi_m_sync_set_baudrate(&self->spi_desc, baud_value) != ERR_NONE) { - // // spi_m_sync_set_baudrate does not check for validity, just whether the device is - // // busy or not - // mp_raise_OSError(MP_EIO); - // } - - // gpio_set_pin_direction(clock->number, GPIO_DIRECTION_OUT); - // gpio_set_pin_pull_mode(clock->number, GPIO_PULL_OFF); - // gpio_set_pin_function(clock->number, clock_pinmux); - // claim_pin(clock); - // self->clock_pin = clock->number; - - // if (mosi_none) { - // self->MOSI_pin = NO_PIN; - // } else { - // gpio_set_pin_direction(mosi->number, GPIO_DIRECTION_OUT); - // gpio_set_pin_pull_mode(mosi->number, GPIO_PULL_OFF); - // gpio_set_pin_function(mosi->number, mosi_pinmux); - // self->MOSI_pin = mosi->number; - // claim_pin(mosi); - // } - - // if (miso_none) { - // self->MISO_pin = NO_PIN; - // } else { - // gpio_set_pin_direction(miso->number, GPIO_DIRECTION_IN); - // gpio_set_pin_pull_mode(miso->number, GPIO_PULL_OFF); - // gpio_set_pin_function(miso->number, miso_pinmux); - // self->MISO_pin = miso->number; - // claim_pin(miso); - // } - - // spi_m_sync_enable(&self->spi_desc); } void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) { - // never_reset_sercom(self->spi_desc.dev.prvt); - - // never_reset_pin_number(self->clock_pin); - // never_reset_pin_number(self->MOSI_pin); - // never_reset_pin_number(self->MISO_pin); } bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) { - //return self->clock_pin == NO_PIN; } void common_hal_busio_spi_deinit(busio_spi_obj_t *self) { - // if (common_hal_busio_spi_deinited(self)) { - // return; - // } - // allow_reset_sercom(self->spi_desc.dev.prvt); - - // spi_m_sync_disable(&self->spi_desc); - // spi_m_sync_deinit(&self->spi_desc); - // reset_pin_number(self->clock_pin); - // reset_pin_number(self->MOSI_pin); - // reset_pin_number(self->MISO_pin); - // self->clock_pin = NO_PIN; } bool common_hal_busio_spi_configure(busio_spi_obj_t *self, uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) { - // uint8_t baud_reg_value = samd_peripherals_spi_baudrate_to_baud_reg_value(baudrate); - - // void * hw = self->spi_desc.dev.prvt; - // // If the settings are already what we want then don't reset them. - // if (hri_sercomspi_get_CTRLA_CPHA_bit(hw) == phase && - // hri_sercomspi_get_CTRLA_CPOL_bit(hw) == polarity && - // hri_sercomspi_read_CTRLB_CHSIZE_bf(hw) == ((uint32_t)bits - 8) && - // hri_sercomspi_read_BAUD_BAUD_bf(hw) == baud_reg_value) { - // return true; - // } - - // // Disable, set values (most or all are enable-protected), and re-enable. - // spi_m_sync_disable(&self->spi_desc); - // hri_sercomspi_wait_for_sync(hw, SERCOM_SPI_SYNCBUSY_MASK); - - // hri_sercomspi_write_CTRLA_CPHA_bit(hw, phase); - // hri_sercomspi_write_CTRLA_CPOL_bit(hw, polarity); - // hri_sercomspi_write_CTRLB_CHSIZE_bf(hw, bits - 8); - // hri_sercomspi_write_BAUD_BAUD_bf(hw, baud_reg_value); - // hri_sercomspi_wait_for_sync(hw, SERCOM_SPI_SYNCBUSY_MASK); - - // spi_m_sync_enable(&self->spi_desc); - // hri_sercomspi_wait_for_sync(hw, SERCOM_SPI_SYNCBUSY_MASK); - return true; } bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) { bool grabbed_lock = false; - // CRITICAL_SECTION_ENTER() - // if (!self->has_lock) { - // grabbed_lock = true; - // self->has_lock = true; - // } - // CRITICAL_SECTION_LEAVE(); return grabbed_lock; } @@ -256,66 +65,25 @@ void common_hal_busio_spi_unlock(busio_spi_obj_t *self) { bool common_hal_busio_spi_write(busio_spi_obj_t *self, const uint8_t *data, size_t len) { - // if (len == 0) { - // return true; - // } - // int32_t status; - // if (len >= 16) { - // status = sercom_dma_write(self->spi_desc.dev.prvt, data, len); - // } else { - // struct io_descriptor *spi_io; - // spi_m_sync_get_io_descriptor(&self->spi_desc, &spi_io); - // status = spi_io->write(spi_io, data, len); - // } - return 0;//status >= 0; // Status is number of chars read or an error code < 0. + return 0; } bool common_hal_busio_spi_read(busio_spi_obj_t *self, uint8_t *data, size_t len, uint8_t write_value) { - // if (len == 0) { - // return true; - // } - // int32_t status; - // if (len >= 16) { - // status = sercom_dma_read(self->spi_desc.dev.prvt, data, len, write_value); - // } else { - // self->spi_desc.dev.dummy_byte = write_value; - - // struct io_descriptor *spi_io; - // spi_m_sync_get_io_descriptor(&self->spi_desc, &spi_io); - - // status = spi_io->read(spi_io, data, len); - // } - return 0;//status >= 0; // Status is number of chars read or an error code < 0. + return 0; } bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, uint8_t *data_out, uint8_t *data_in, size_t len) { - // if (len == 0) { - // return true; - // } - // int32_t status; - // if (len >= 16) { - // status = sercom_dma_transfer(self->spi_desc.dev.prvt, data_out, data_in, len); - // } else { - // struct spi_xfer xfer; - // xfer.txbuf = data_out; - // xfer.rxbuf = data_in; - // xfer.size = len; - // status = spi_m_sync_transfer(&self->spi_desc, &xfer); - // } - return 0;//status >= 0; // Status is number of chars read or an error code < 0. + return 0; } uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t* self) { - return 0;//samd_peripherals_spi_baud_reg_value_to_baudrate(hri_sercomspi_read_BAUD_reg(self->spi_desc.dev.prvt)); + return 0; } uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self) { - //void * hw = self->spi_desc.dev.prvt; - return 0;//hri_sercomspi_get_CTRLA_CPHA_bit(hw); + return 0; } uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self) { - //void * hw = self->spi_desc.dev.prvt; - return 0;//hri_sercomspi_get_CTRLA_CPOL_bit(hw); -} + return 0; diff --git a/ports/stm32f4/common-hal/busio/UART.c b/ports/stm32f4/common-hal/busio/UART.c index 86035c3bae38e..32653ab8b570b 100644 --- a/ports/stm32f4/common-hal/busio/UART.c +++ b/ports/stm32f4/common-hal/busio/UART.c @@ -41,336 +41,39 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, uint16_t receiver_buffer_size) { - - // Sercom* sercom = NULL; - // uint8_t sercom_index = 255; // Unset index - // uint32_t rx_pinmux = 0; - // uint8_t rx_pad = 255; // Unset pad - // uint32_t tx_pinmux = 0; - // uint8_t tx_pad = 255; // Unset pad - - // if (bits > 8) { - // mp_raise_NotImplementedError(translate("bytes > 8 bits not supported")); - // } - - // bool have_tx = tx != mp_const_none; - // bool have_rx = rx != mp_const_none; - // if (!have_tx && !have_rx) { - // mp_raise_ValueError(translate("tx and rx cannot both be None")); - // } - - // self->baudrate = baudrate; - // self->character_bits = bits; - // self->timeout_ms = timeout * 1000; - - // // This assignment is only here because the usart_async routines take a *const argument. - // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; - - // for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) { - // Sercom* potential_sercom = NULL; - // if (have_tx) { - // sercom_index = tx->sercom[i].index; - // if (sercom_index >= SERCOM_INST_NUM) { - // continue; - // } - // potential_sercom = sercom_insts[sercom_index]; - // if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 || - // !(tx->sercom[i].pad == 0 || - // tx->sercom[i].pad == 2)) { - // continue; - // } - // tx_pinmux = PINMUX(tx->number, (i == 0) ? MUX_C : MUX_D); - // tx_pad = tx->sercom[i].pad; - // if (rx == mp_const_none) { - // sercom = potential_sercom; - // break; - // } - // } - // for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) { - // if (((!have_tx && rx->sercom[j].index < SERCOM_INST_NUM && - // sercom_insts[rx->sercom[j].index]->USART.CTRLA.bit.ENABLE == 0) || - // sercom_index == rx->sercom[j].index) && - // rx->sercom[j].pad != tx_pad) { - // rx_pinmux = PINMUX(rx->number, (j == 0) ? MUX_C : MUX_D); - // rx_pad = rx->sercom[j].pad; - // sercom = sercom_insts[rx->sercom[j].index]; - // sercom_index = rx->sercom[j].index; - // break; - // } - // } - // if (sercom != NULL) { - // break; - // } - // } - // if (sercom == NULL) { - // mp_raise_ValueError(translate("Invalid pins")); - // } - // if (!have_tx) { - // tx_pad = 0; - // if (rx_pad == 0) { - // tx_pad = 2; - // } - // } - // if (!have_rx) { - // rx_pad = (tx_pad + 1) % 4; - // } - - // // Set up clocks on SERCOM. - // samd_peripherals_sercom_clock_init(sercom, sercom_index); - - // if (rx && receiver_buffer_size > 0) { - // self->buffer_length = receiver_buffer_size; - // // Initially allocate the UART's buffer in the long-lived part of the - // // heap. UARTs are generally long-lived objects, but the "make long- - // // lived" machinery is incapable of moving internal pointers like - // // self->buffer, so do it manually. (However, as long as internal - // // pointers like this are NOT moved, allocating the buffer - // // in the long-lived pool is not strictly necessary) - // self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, true); - // if (self->buffer == NULL) { - // common_hal_busio_uart_deinit(self); - // mp_raise_msg(&mp_type_MemoryError, translate("Failed to allocate RX buffer")); - // } - // } else { - // self->buffer_length = 0; - // self->buffer = NULL; - // } - - // if (usart_async_init(usart_desc_p, sercom, self->buffer, self->buffer_length, NULL) != ERR_NONE) { - // mp_raise_ValueError(translate("Could not initialize UART")); - // } - - // // usart_async_init() sets a number of defaults based on a prototypical SERCOM - // // which don't necessarily match what we need. After calling it, set the values - // // specific to this instantiation of UART. - - // // Set pads computed for this SERCOM. - // // TXPO: - // // 0x0: TX pad 0; no RTS/CTS - // // 0x1: TX pad 2; no RTS/CTS - // // 0x2: TX pad 0; RTS: pad 2, CTS: pad 3 (not used by us right now) - // // So divide by 2 to map pad to value. - // // RXPO: - // // 0x0: RX pad 0 - // // 0x1: RX pad 1 - // // 0x2: RX pad 2 - // // 0x3: RX pad 3 - - // // Doing a group mask and set of the registers saves 60 bytes over setting the bitfields individually. - - // sercom->USART.CTRLA.reg &= ~(SERCOM_USART_CTRLA_TXPO_Msk | - // SERCOM_USART_CTRLA_RXPO_Msk | - // SERCOM_USART_CTRLA_FORM_Msk); - // sercom->USART.CTRLA.reg |= SERCOM_USART_CTRLA_TXPO(tx_pad / 2) | - // SERCOM_USART_CTRLA_RXPO(rx_pad) | - // (parity == PARITY_NONE ? 0 : SERCOM_USART_CTRLA_FORM(1)); - - // // Enable tx and/or rx based on whether the pins were specified. - // // CHSIZE is 0 for 8 bits, 5, 6, 7 for 5, 6, 7 bits. 1 for 9 bits, but we don't support that. - // sercom->USART.CTRLB.reg &= ~(SERCOM_USART_CTRLB_TXEN | - // SERCOM_USART_CTRLB_RXEN | - // SERCOM_USART_CTRLB_PMODE | - // SERCOM_USART_CTRLB_SBMODE | - // SERCOM_USART_CTRLB_CHSIZE_Msk); - // sercom->USART.CTRLB.reg |= (have_tx ? SERCOM_USART_CTRLB_TXEN : 0) | - // (have_rx ? SERCOM_USART_CTRLB_RXEN : 0) | - // (parity == PARITY_ODD ? SERCOM_USART_CTRLB_PMODE : 0) | - // (stop > 1 ? SERCOM_USART_CTRLB_SBMODE : 0) | - // SERCOM_USART_CTRLB_CHSIZE(bits % 8); - - // // Set baud rate - // common_hal_busio_uart_set_baudrate(self, baudrate); - - // // Turn on rx interrupt handling. The UART async driver has its own set of internal callbacks, - // // which are set up by uart_async_init(). These in turn can call user-specified callbacks. - // // In fact, the actual interrupts are not enabled unless we set up a user-specified callback. - // // This is confusing. It's explained in the Atmel START User Guide -> Implementation Description -> - // // Different read function behavior in some asynchronous drivers. As of this writing: - // // http://start.atmel.com/static/help/index.html?GUID-79201A5A-226F-4FBB-B0B8-AB0BE0554836 - // // Look at the ASFv4 code example for async USART. - // usart_async_register_callback(usart_desc_p, USART_ASYNC_RXC_CB, usart_async_rxc_callback); - - - // if (have_tx) { - // gpio_set_pin_direction(tx->number, GPIO_DIRECTION_OUT); - // gpio_set_pin_pull_mode(tx->number, GPIO_PULL_OFF); - // gpio_set_pin_function(tx->number, tx_pinmux); - // self->tx_pin = tx->number; - // claim_pin(tx); - // } else { - // self->tx_pin = NO_PIN; - // } - - // if (have_rx) { - // gpio_set_pin_direction(rx->number, GPIO_DIRECTION_IN); - // gpio_set_pin_pull_mode(rx->number, GPIO_PULL_OFF); - // gpio_set_pin_function(rx->number, rx_pinmux); - // self->rx_pin = rx->number; - // claim_pin(rx); - // } else { - // self->rx_pin = NO_PIN; - // } - - // usart_async_enable(usart_desc_p); } bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { - return 0;//self->rx_pin == NO_PIN && self->tx_pin == NO_PIN; + return 0; } void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { - // if (common_hal_busio_uart_deinited(self)) { - // return; - // } - // // This assignment is only here because the usart_async routines take a *const argument. - // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; - // usart_async_disable(usart_desc_p); - // usart_async_deinit(usart_desc_p); - // reset_pin_number(self->rx_pin); - // reset_pin_number(self->tx_pin); - // self->rx_pin = NO_PIN; - // self->tx_pin = NO_PIN; } // Read characters. size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t len, int *errcode) { -// if (self->rx_pin == NO_PIN) { -// mp_raise_ValueError(translate("No RX pin")); -// } - -// // This assignment is only here because the usart_async routines take a *const argument. -// struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; - -// if (len == 0) { -// // Nothing to read. -// return 0; -// } - -// struct io_descriptor *io; -// usart_async_get_io_descriptor(usart_desc_p, &io); - -// size_t total_read = 0; -// uint64_t start_ticks = ticks_ms; - -// // Busy-wait until timeout or until we've read enough chars. -// while (ticks_ms - start_ticks <= self->timeout_ms) { -// // Read as many chars as we can right now, up to len. -// size_t num_read = io_read(io, data, len); - -// // Advance pointer in data buffer, and decrease how many chars left to read. -// data += num_read; -// len -= num_read; -// total_read += num_read; -// if (len == 0) { -// // Don't need to read any more: data buf is full. -// break; -// } -// if (num_read > 0) { -// // Reset the timeout on every character read. -// start_ticks = ticks_ms; -// } -// #ifdef MICROPY_VM_HOOK_LOOP -// MICROPY_VM_HOOK_LOOP ; -// // Allow user to break out of a timeout with a KeyboardInterrupt. -// if (mp_hal_is_interrupted()) { -// break; -// } -// #endif -// // If we are zero timeout, make sure we don't loop again (in the event -// // we read in under 1ms) -// if (self->timeout_ms == 0) { -// break; -// } -// } - -// if (total_read == 0) { -// *errcode = EAGAIN; -// return MP_STREAM_ERROR; -// } - - return 0;//total_read; + return 0; } // Write characters. size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data, size_t len, int *errcode) { - // if (self->tx_pin == NO_PIN) { - // mp_raise_ValueError(translate("No TX pin")); - // } - - // // This assignment is only here because the usart_async routines take a *const argument. - // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; - - // struct io_descriptor *io; - // usart_async_get_io_descriptor(usart_desc_p, &io); - - // if (io_write(io, data, len) < 0) { - // *errcode = MP_EAGAIN; - // return MP_STREAM_ERROR; - // } - - // // Wait until write is complete or timeout. - // bool done = false; - // uint64_t start_ticks = ticks_ms; - // // Busy-wait for timeout. - // while (ticks_ms - start_ticks < self->timeout_ms) { - // if (usart_async_is_tx_empty(usart_desc_p)) { - // done = true; - // break; - // } - // #ifdef MICROPY_VM_HOOK_LOOP - // MICROPY_VM_HOOK_LOOP - // #endif - // } - - // if (!done) { - // *errcode = MP_EAGAIN; - // return MP_STREAM_ERROR; - // } - - // // All the characters got written. - return 0;//len; + return 0; } uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) { - return 0;//self->baudrate; + return 0; } void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) { - // This assignment is only here because the usart_async routines take a *const argument. - // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; - // usart_async_set_baud_rate(usart_desc_p, - // // Samples and ARITHMETIC vs FRACTIONAL must correspond to USART_SAMPR in - // // hpl_sercom_config.h. - // _usart_async_calculate_baud_rate(baudrate, // e.g. 9600 baud - // PROTOTYPE_SERCOM_USART_ASYNC_CLOCK_FREQUENCY, - // 16, // samples - // USART_BAUDRATE_ASYNCH_ARITHMETIC, - // 0 // fraction - not used for ARITHMETIC - // )); - // self->baudrate = baudrate; } uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) { - // // This assignment is only here because the usart_async routines take a *const argument. - // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; - // struct usart_async_status async_status; - // usart_async_get_status(usart_desc_p, &async_status); - return 0;//async_status.rxcnt; + return 0; } void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) { - // This assignment is only here because the usart_async routines take a *const argument. - // struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; - // usart_async_flush_rx_buffer(usart_desc_p); - } bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) { - // if (self->tx_pin == NO_PIN) { - // return false; - // } - // // This assignment is only here because the usart_async routines take a *const argument. - // const struct _usart_async_device * const usart_device_p = - // (struct _usart_async_device * const) &self->usart_desc.device; - return 0;//_usart_async_is_byte_sent(usart_device_p); + return 0; } From a9d3ad86e5f400b9315fde58c9b8666a048956ca Mon Sep 17 00:00:00 2001 From: Hierophect Date: Thu, 15 Aug 2019 15:55:33 -0400 Subject: [PATCH 21/27] Fix flash size, add filesystem disable flag --- ports/stm32f4/boards/STM32F411VETx_FLASH.ld | 4 +- ports/stm32f4/boards/stm32f411.ld | 189 ------------------ .../stm32f411ve_discovery/mpconfigboard.h | 2 +- .../stm32f412zg_discovery/mpconfigboard.mk | 2 + ports/stm32f4/common-hal/busio/SPI.c | 1 + ports/stm32f4/supervisor/internal_flash.h | 5 +- supervisor/stub/internal_flash.c | 70 +++++++ supervisor/supervisor.mk | 8 +- 8 files changed, 84 insertions(+), 197 deletions(-) delete mode 100644 ports/stm32f4/boards/stm32f411.ld create mode 100644 supervisor/stub/internal_flash.c diff --git a/ports/stm32f4/boards/STM32F411VETx_FLASH.ld b/ports/stm32f4/boards/STM32F411VETx_FLASH.ld index fc9ffdff56bd1..ac1ba32408618 100644 --- a/ports/stm32f4/boards/STM32F411VETx_FLASH.ld +++ b/ports/stm32f4/boards/STM32F411VETx_FLASH.ld @@ -7,8 +7,8 @@ MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 512K /* entire flash */ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* sector 0 */ - FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 112K /* sectors 1,2,3 are 16K, 4 is 64K */ - FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 384K /* sectors 5,6,7 are 128K */ + FLASH_FS (rx) : ORIGIN = 0x08004000, LENGTH = 48K /* sectors 1,2,3 are 16K */ + FLASH_TEXT (rx) : ORIGIN = 0x08010000, LENGTH = 448K /* sector 4 is 64K, sectors 5,6,7 are 128K */ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K } diff --git a/ports/stm32f4/boards/stm32f411.ld b/ports/stm32f4/boards/stm32f411.ld deleted file mode 100644 index f0d4804f9390d..0000000000000 --- a/ports/stm32f4/boards/stm32f411.ld +++ /dev/null @@ -1,189 +0,0 @@ -/* -****************************************************************************** -** - -** File : LinkerScript.ld -** -** Author : Auto-generated by Ac6 System Workbench -** -** Abstract : Linker script for STM32F411RETx series -** 512Kbytes FLASH and 128Kbytes RAM -** -** Set heap size, stack size and stack location according -** to application requirements. -** -** Set memory bank area and size if external memory is used. -** -** Target : STMicroelectronics STM32 -** -** Distribution: The file is distributed “as is,” without any warranty -** of any kind. -** -***************************************************************************** -** @attention -** -**

© COPYRIGHT(c) 2014 Ac6

-** -** Redistribution and use in source and binary forms, with or without modification, -** are permitted provided that the following conditions are met: -** 1. Redistributions of source code must retain the above copyright notice, -** this list of conditions and the following disclaimer. -** 2. Redistributions in binary form must reproduce the above copyright notice, -** this list of conditions and the following disclaimer in the documentation -** and/or other materials provided with the distribution. -** 3. Neither the name of Ac6 nor the names of its contributors -** may be used to endorse or promote products derived from this software -** without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -** -***************************************************************************** -*/ - -/* Entry Point */ -ENTRY(Reset_Handler) - -/* Highest address of the user mode stack */ -_estack = 0x20020000; /* end of RAM */ -/* Generate a link error if heap and stack don't fit into RAM */ -_Min_Heap_Size = 0x200; /* required amount of heap */ -_Min_Stack_Size = 0x400; /* required amount of stack */ - -/* Specify the memory areas */ -MEMORY -{ -RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K -FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K -} - -/* Define output sections */ -SECTIONS -{ - /* The startup code goes first into FLASH */ - .isr_vector : - { - . = ALIGN(4); - KEEP(*(.isr_vector)) /* Startup code */ - . = ALIGN(4); - } >FLASH - - /* The program code and other data goes into FLASH */ - .text : - { - . = ALIGN(4); - *(.text) /* .text sections (code) */ - *(.text*) /* .text* sections (code) */ - *(.glue_7) /* glue arm to thumb code */ - *(.glue_7t) /* glue thumb to arm code */ - *(.eh_frame) - - KEEP (*(.init)) - KEEP (*(.fini)) - - . = ALIGN(4); - _etext = .; /* define a global symbols at end of code */ - } >FLASH - - /* Constant data goes into FLASH */ - .rodata : - { - . = ALIGN(4); - *(.rodata) /* .rodata sections (constants, strings, etc.) */ - *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ - . = ALIGN(4); - } >FLASH - - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH - .ARM : { - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - } >FLASH - - .preinit_array : - { - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP (*(.preinit_array*)) - PROVIDE_HIDDEN (__preinit_array_end = .); - } >FLASH - .init_array : - { - PROVIDE_HIDDEN (__init_array_start = .); - KEEP (*(SORT(.init_array.*))) - KEEP (*(.init_array*)) - PROVIDE_HIDDEN (__init_array_end = .); - } >FLASH - .fini_array : - { - PROVIDE_HIDDEN (__fini_array_start = .); - KEEP (*(SORT(.fini_array.*))) - KEEP (*(.fini_array*)) - PROVIDE_HIDDEN (__fini_array_end = .); - } >FLASH - - /* used by the startup to initialize data */ - _sidata = LOADADDR(.data); - - /* Initialized data sections goes into RAM, load LMA copy after code */ - .data : - { - . = ALIGN(4); - _sdata = .; /* create a global symbol at data start */ - *(.data) /* .data sections */ - *(.data*) /* .data* sections */ - - . = ALIGN(4); - _edata = .; /* define a global symbol at data end */ - } >RAM AT> FLASH - - - /* Uninitialized data section */ - . = ALIGN(4); - .bss : - { - /* This is used by the startup in order to initialize the .bss secion */ - _sbss = .; /* define a global symbol at bss start */ - __bss_start__ = _sbss; - *(.bss) - *(.bss*) - *(COMMON) - - . = ALIGN(4); - _ebss = .; /* define a global symbol at bss end */ - __bss_end__ = _ebss; - } >RAM - - /* User_heap_stack section, used to check that there is enough RAM left */ - ._user_heap_stack : - { - . = ALIGN(8); - PROVIDE ( end = . ); - PROVIDE ( _end = . ); - . = . + _Min_Heap_Size; - . = . + _Min_Stack_Size; - . = ALIGN(8); - } >RAM - - - - /* Remove information from the standard libraries */ - /DISCARD/ : - { - libc.a ( * ) - libm.a ( * ) - libgcc.a ( * ) - } - - .ARM.attributes 0 : { *(.ARM.attributes) } -} - - diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h index 979b75b4c7463..21466f4df988b 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h @@ -37,6 +37,6 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 256 -#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0x01C000 - CIRCUITPY_INTERNAL_NVM_SIZE) +#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000 - CIRCUITPY_INTERNAL_NVM_SIZE) #define AUTORESET_DELAY_MS 500 \ No newline at end of file diff --git a/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk index b6c27f9c04d17..3b3c7867fec3c 100644 --- a/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.mk @@ -3,6 +3,8 @@ USB_PID = 0x572B USB_PRODUCT = "STM32F412ZG Discovery Board - CPy" USB_MANUFACTURER = "STMicroelectronics" +DISABLE_FILESYSTEM = 1 + MCU_SERIES = m4 MCU_VARIANT = stm32f4 MCU_SUB_VARIANT = stm32f412zx diff --git a/ports/stm32f4/common-hal/busio/SPI.c b/ports/stm32f4/common-hal/busio/SPI.c index dfb436fb935a2..98faf7b3b871e 100644 --- a/ports/stm32f4/common-hal/busio/SPI.c +++ b/ports/stm32f4/common-hal/busio/SPI.c @@ -87,3 +87,4 @@ uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self) { uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self) { return 0; +} \ No newline at end of file diff --git a/ports/stm32f4/supervisor/internal_flash.h b/ports/stm32f4/supervisor/internal_flash.h index c8a60cc557617..83b35e03cbb75 100644 --- a/ports/stm32f4/supervisor/internal_flash.h +++ b/ports/stm32f4/supervisor/internal_flash.h @@ -33,18 +33,17 @@ #ifdef STM32F411xE #define STM32_FLASH_SIZE 0x80000 //512KiB -#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x1C000 //112KiB +#define INTERNAL_FLASH_FILESYSTEM_SIZE 0xC000 //112KiB #endif #ifdef STM32F412Zx #define STM32_FLASH_SIZE 0x100000 //1MB -#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x1C000 //112KiB +#define INTERNAL_FLASH_FILESYSTEM_SIZE 0xC000 //112KiB #endif #define STM32_FLASH_OFFSET 0x8000000 //All STM32 chips map to this flash location #define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x08004000 -//#define INTERNAL_FLASH_FILESYSTEM_START_ADDR ((STM32_FLASH_SIZE + STM32_FLASH_OFFSET) - INTERNAL_FLASH_FILESYSTEM_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE) #define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) #define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms diff --git a/supervisor/stub/internal_flash.c b/supervisor/stub/internal_flash.c new file mode 100644 index 0000000000000..334281e77f7a0 --- /dev/null +++ b/supervisor/stub/internal_flash.c @@ -0,0 +1,70 @@ +/*f + * 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/internal_flash.h" + +#include +#include + +#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" + +void supervisor_flash_init(void) { +} + +uint32_t supervisor_flash_get_block_size(void) { + return 0; +} + +uint32_t supervisor_flash_get_block_count(void) { + return 0; +} + +void supervisor_flash_flush(void) { +} + +static int32_t convert_block_to_flash_addr(uint32_t block) { + return -1; +} + +mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { + return 0; // success +} + +bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { + return true; +} + +mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { + return 0; // success +} + +void supervisor_flash_release_cache(void) { +} + diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 1022dd2a34dee..4870f15d83fa2 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -13,7 +13,7 @@ SRC_SUPERVISOR = \ supervisor/shared/translate.c ifndef $(NO_USB) -NO_USB = $(wildcard supervisor/usb.c) + NO_USB = $(wildcard supervisor/usb.c) endif ifneq ($(INTERNAL_FLASH_FILESYSTEM),) @@ -44,7 +44,11 @@ ifdef EXTERNAL_FLASH_DEVICES SRC_SUPERVISOR += supervisor/qspi_flash.c supervisor/shared/external_flash/qspi_flash.c endif else - SRC_SUPERVISOR += supervisor/internal_flash.c + ifneq ($(DISABLE_FILESYSTEM),1) + SRC_SUPERVISOR += supervisor/internal_flash.c + else + SRC_SUPERVISOR += supervisor/stub/internal_flash.c + endif endif ifeq ($(USB),FALSE) From bc7ba33892cae88ffd1b42dfa45868057a4934e8 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Thu, 15 Aug 2019 16:35:01 -0400 Subject: [PATCH 22/27] Add uid fetch, revert USB hacks --- .../boards/stm32f411ve_discovery/mpconfigboard.mk | 2 +- ports/stm32f4/common-hal/microcontroller/Processor.c | 9 ++++++--- ports/stm32f4/common-hal/microcontroller/Processor.h | 2 +- ports/stm32f4/mpconfigport.mk | 2 +- supervisor/shared/usb/usb.c | 3 +-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk index aa867c96f840b..bbc2a4a049454 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk @@ -1,7 +1,7 @@ USB_VID = 0x239A USB_PID = 0x802A USB_PRODUCT = "STM32F411VE Discovery Board - CPy" -USB_MANUFACTURER = "Adafruit Industries LLC" +USB_MANUFACTURER = "STMicroelectronics" USB_REDUCED_ENDPOINT = 1 INTERNAL_FLASH_FILESYSTEM = 1 diff --git a/ports/stm32f4/common-hal/microcontroller/Processor.c b/ports/stm32f4/common-hal/microcontroller/Processor.c index c59c340c09c84..7117945b39dcc 100644 --- a/ports/stm32f4/common-hal/microcontroller/Processor.c +++ b/ports/stm32f4/common-hal/microcontroller/Processor.c @@ -28,17 +28,20 @@ #include "py/runtime.h" #include "supervisor/shared/translate.h" +#include "stm32f4xx_hal.h" + +#define STM32_UUID ((uint32_t *)0x1FFF7A10) float common_hal_mcu_processor_get_temperature(void) { return 0; } uint32_t common_hal_mcu_processor_get_frequency(void) { - return 64000000ul; + return SystemCoreClock; } void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { - for (int i=0; i<2; i++) { - ((uint32_t*) raw_id)[i] = 0; + for (int i=0; i<3; i++) { + ((uint32_t*) raw_id)[i] = STM32_UUID[i]; } } diff --git a/ports/stm32f4/common-hal/microcontroller/Processor.h b/ports/stm32f4/common-hal/microcontroller/Processor.h index c3ca4efd5995b..311333e7de512 100644 --- a/ports/stm32f4/common-hal/microcontroller/Processor.h +++ b/ports/stm32f4/common-hal/microcontroller/Processor.h @@ -27,7 +27,7 @@ #ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H #define MICROPY_INCLUDED_STM32F4_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H -#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 8 +#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 12 #include "py/obj.h" diff --git a/ports/stm32f4/mpconfigport.mk b/ports/stm32f4/mpconfigport.mk index 78c8e763008db..3a8e6acc6f191 100644 --- a/ports/stm32f4/mpconfigport.mk +++ b/ports/stm32f4/mpconfigport.mk @@ -7,7 +7,7 @@ MPY_TOOL_LONGINT_IMPL = -mlongint-impl=mpz INTERNAL_LIBM = 1 # Chip supplied serial number, in bytes -USB_SERIAL_NUMBER_LENGTH = 16 +USB_SERIAL_NUMBER_LENGTH = 24 # Longints can be implemented as mpz, as longlong, or not LONGINT_IMPL = MPZ diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index cfb39d4bb5b66..b0880b1b62697 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -34,7 +34,6 @@ #include "tusb.h" -#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 8 // Serial number as hex characters. This writes directly to the USB // descriptor. @@ -43,7 +42,7 @@ extern uint16_t usb_serial_number[1 + COMMON_HAL_MCU_PROCESSOR_UID_LENGTH * 2]; void load_serial_number(void) { // create serial number based on device unique id uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; - //common_hal_mcu_processor_get_uid(raw_id); + common_hal_mcu_processor_get_uid(raw_id); for (int i=0; i<2; i++) { ((uint32_t*) raw_id)[i] = 0; } From 1f42ce5f4000d630da5cb744c2a61a69a8d7a0e8 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Thu, 15 Aug 2019 17:45:40 -0400 Subject: [PATCH 23/27] QOL fixes, compatibility fixes, attribution --- ports/stm32f4/background.c | 3 ++ ports/stm32f4/common-hal/busio/I2C.c | 3 ++ ports/stm32f4/common-hal/busio/I2C.h | 1 + ports/stm32f4/common-hal/busio/SPI.c | 1 + .../common-hal/microcontroller/Processor.c | 1 + .../common-hal/microcontroller/__init__.c | 1 + ports/stm32f4/peripherals/stm32f4/gpio.h | 1 + .../peripherals/stm32f4/stm32f411xe/gpio.c | 25 +++++++++++++--- .../peripherals/stm32f4/stm32f412zx/gpio.c | 30 ++++++++++++------- ports/stm32f4/supervisor/internal_flash.c | 9 +++--- ports/stm32f4/supervisor/internal_flash.h | 1 + ports/stm32f4/supervisor/serial.c | 6 ++-- ports/stm32f4/supervisor/usb.c | 1 + supervisor/shared/usb/tusb_config.h | 2 -- 14 files changed, 62 insertions(+), 23 deletions(-) diff --git a/ports/stm32f4/background.c b/ports/stm32f4/background.c index 9c4f3ab27e2f1..8e31efdc2c28f 100644 --- a/ports/stm32f4/background.c +++ b/ports/stm32f4/background.c @@ -46,7 +46,10 @@ void run_background_tasks(void) { } running_background_tasks = true; filesystem_background(); + + #if USB_AVAILABLE usb_background(); + #endif #if CIRCUITPY_DISPLAYIO displayio_refresh_displays(); diff --git a/ports/stm32f4/common-hal/busio/I2C.c b/ports/stm32f4/common-hal/busio/I2C.c index 1babe33a1da98..019465cccd422 100644 --- a/ports/stm32f4/common-hal/busio/I2C.c +++ b/ports/stm32f4/common-hal/busio/I2C.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2016 Scott Shawcroft + * 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 @@ -36,6 +37,8 @@ I2C_HandleTypeDef hi2c2; void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) { + //TODO: Rework this entire section to use LL, alongside MSP removal + hi2c2.Instance = I2C1; hi2c2.Init.ClockSpeed = 100000; hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2; diff --git a/ports/stm32f4/common-hal/busio/I2C.h b/ports/stm32f4/common-hal/busio/I2C.h index 9fe0258a1cba7..5c801ab321570 100644 --- a/ports/stm32f4/common-hal/busio/I2C.h +++ b/ports/stm32f4/common-hal/busio/I2C.h @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2016 Scott Shawcroft + * 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 diff --git a/ports/stm32f4/common-hal/busio/SPI.c b/ports/stm32f4/common-hal/busio/SPI.c index 98faf7b3b871e..a33581b64407a 100644 --- a/ports/stm32f4/common-hal/busio/SPI.c +++ b/ports/stm32f4/common-hal/busio/SPI.c @@ -40,6 +40,7 @@ void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) { } bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) { + return 0; } void common_hal_busio_spi_deinit(busio_spi_obj_t *self) { diff --git a/ports/stm32f4/common-hal/microcontroller/Processor.c b/ports/stm32f4/common-hal/microcontroller/Processor.c index 7117945b39dcc..c16bd312551e4 100644 --- a/ports/stm32f4/common-hal/microcontroller/Processor.c +++ b/ports/stm32f4/common-hal/microcontroller/Processor.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2017 Dan Halbert 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 diff --git a/ports/stm32f4/common-hal/microcontroller/__init__.c b/ports/stm32f4/common-hal/microcontroller/__init__.c index 08f8f28f80adf..4cbd6d66fdf6e 100644 --- a/ports/stm32f4/common-hal/microcontroller/__init__.c +++ b/ports/stm32f4/common-hal/microcontroller/__init__.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2016 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 diff --git a/ports/stm32f4/peripherals/stm32f4/gpio.h b/ports/stm32f4/peripherals/stm32f4/gpio.h index 251cdb814e071..34f89e79212c1 100644 --- a/ports/stm32f4/peripherals/stm32f4/gpio.h +++ b/ports/stm32f4/peripherals/stm32f4/gpio.h @@ -25,3 +25,4 @@ */ void stm32f4_peripherals_gpio_init(void); +void stm32f4_peripherals_status_led(uint8_t led, uint8_t state); diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c index a9ac97bae957c..3fd85c632970f 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c +++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c @@ -105,6 +105,7 @@ #define LD6_GPIO_Port GPIOD #include "stm32f4xx_hal.h" +#include "stm32f4/gpio.h" void stm32f4_peripherals_gpio_init(void) { //Enable all GPIO for now @@ -128,10 +129,26 @@ void stm32f4_peripherals_gpio_init(void) { HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); //Status LED chain - HAL_GPIO_WritePin(GPIOD, LD4_Pin, GPIO_PIN_RESET); //LED 1 - HAL_GPIO_WritePin(GPIOD, LD3_Pin, GPIO_PIN_SET); //LED 2 - HAL_GPIO_WritePin(GPIOD, LD5_Pin, GPIO_PIN_SET); //LED 3 - HAL_GPIO_WritePin(GPIOD, LD6_Pin, GPIO_PIN_SET); //LED 4 + stm32f4_peripherals_status_led(0,1); + stm32f4_peripherals_status_led(1,0); + stm32f4_peripherals_status_led(2,0); + stm32f4_peripherals_status_led(3,0); +} + +//LEDs are inverted on F411 DISCO +void stm32f4_peripherals_status_led(uint8_t led, uint8_t state) { + switch(led) + { + case 0: HAL_GPIO_WritePin(GPIOD, LD4_Pin, (state ^ 1)); + break; + case 1: HAL_GPIO_WritePin(GPIOD, LD3_Pin, (state ^ 1)); + break; + case 2: HAL_GPIO_WritePin(GPIOD, LD5_Pin, (state ^ 1)); + break; + case 3: HAL_GPIO_WritePin(GPIOD, LD6_Pin, (state ^ 1)); + break; + default: break; + } } diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f412zx/gpio.c b/ports/stm32f4/peripherals/stm32f4/stm32f412zx/gpio.c index de783bafecc9d..a22963a9c3a43 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f412zx/gpio.c +++ b/ports/stm32f4/peripherals/stm32f4/stm32f412zx/gpio.c @@ -178,6 +178,7 @@ */ #include "stm32f4xx_hal.h" +#include "stm32f4/gpio.h" void stm32f4_peripherals_gpio_init(void) { //Enable all GPIO for now @@ -202,17 +203,26 @@ void stm32f4_peripherals_gpio_init(void) { HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); //Status LED chain - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_0, GPIO_PIN_RESET); //LED 1 - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET); //LED 2 - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET); //LED 3 - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_SET); //LED 4 + stm32f4_peripherals_status_led(0,1); + stm32f4_peripherals_status_led(1,0); + stm32f4_peripherals_status_led(2,0); + stm32f4_peripherals_status_led(3,0); +} - //TBD, USB power - // GPIO_InitStruct.Pin = USB_OTGFS_PPWR_EN_Pin; - // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; - // GPIO_InitStruct.Pull = GPIO_NOPULL; - // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - // HAL_GPIO_Init(USB_OTGFS_PPWR_EN_GPIO_Port, &GPIO_InitStruct); +//LEDs are inverted on F411 DISCO +void stm32f4_peripherals_status_led(uint8_t led, uint8_t state) { + switch(led) + { + case 0: HAL_GPIO_WritePin(GPIOE, GPIO_PIN_0, (state ^ 1)); + break; + case 1: HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, (state ^ 1)); + break; + case 2: HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, (state ^ 1)); + break; + case 3: HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, (state ^ 1)); + break; + default: break; + } } diff --git a/ports/stm32f4/supervisor/internal_flash.c b/ports/stm32f4/supervisor/internal_flash.c index 966b167d80134..fd3241bd6a93f 100644 --- a/ports/stm32f4/supervisor/internal_flash.c +++ b/ports/stm32f4/supervisor/internal_flash.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2013, 2014 Damien P. George + * 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 @@ -67,8 +68,8 @@ static uint8_t sector_copy[0x4000] __attribute__((aligned(4))); uint32_t flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { if (addr >= flash_layout[0].base_address) { uint32_t sector_index = 0; - for (int i = 0; i < MP_ARRAY_SIZE(flash_layout); ++i) { - for (int j = 0; j < flash_layout[i].sector_count; ++j) { + for (uint8_t i = 0; i < MP_ARRAY_SIZE(flash_layout); ++i) { + for (uint8_t j = 0; j < flash_layout[i].sector_count; ++j) { uint32_t sector_start_next = flash_layout[i].base_address + (j + 1) * flash_layout[i].sector_size; if (addr < sector_start_next) { @@ -112,7 +113,7 @@ static int32_t convert_block_to_flash_addr(uint32_t block) { } mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { - uint32_t src = convert_block_to_flash_addr(block); + int32_t src = convert_block_to_flash_addr(block); if (src == -1) { // bad block number return false; @@ -172,7 +173,7 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { __HAL_FLASH_DATA_CACHE_ENABLE(); // reprogram the sector - for (int i = 0; i < sector_size; i++) { + for (uint32_t i = 0; i < sector_size; i++) { if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, sector_start_addr, (uint64_t)sector_copy[i]) != HAL_OK) { // error occurred during flash write HAL_FLASH_Lock(); // lock the flash diff --git a/ports/stm32f4/supervisor/internal_flash.h b/ports/stm32f4/supervisor/internal_flash.h index 83b35e03cbb75..4575cf1d7732f 100644 --- a/ports/stm32f4/supervisor/internal_flash.h +++ b/ports/stm32f4/supervisor/internal_flash.h @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2013, 2014 Damien P. George + * 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 diff --git a/ports/stm32f4/supervisor/serial.c b/ports/stm32f4/supervisor/serial.c index 1532a8ae88c4d..ce13660000041 100644 --- a/ports/stm32f4/supervisor/serial.c +++ b/ports/stm32f4/supervisor/serial.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2017, 2018 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 @@ -28,6 +29,7 @@ #include #include "supervisor/serial.h" #include "stm32f4xx_hal.h" +#include "stm32f4/gpio.h" UART_HandleTypeDef huart2; @@ -42,10 +44,8 @@ void serial_init(void) { huart2.Init.OverSampling = UART_OVERSAMPLING_16; if (HAL_UART_Init(&huart2) == HAL_OK) { - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET); + stm32f4_peripherals_status_led(1,1); } - HAL_UART_Transmit(&huart2, (uint8_t*)"Serial On", 9, 2); - HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_RESET); } bool serial_connected(void) { diff --git a/ports/stm32f4/supervisor/usb.c b/ports/stm32f4/supervisor/usb.c index 11885b3d927ef..4fa9045df32f0 100644 --- a/ports/stm32f4/supervisor/usb.c +++ b/ports/stm32f4/supervisor/usb.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2018 hathach 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 diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h index 2e85bc82035a8..ad5825b6c9361 100644 --- a/supervisor/shared/usb/tusb_config.h +++ b/supervisor/shared/usb/tusb_config.h @@ -107,11 +107,9 @@ // USB RAM PLACEMENT //--------------------------------------------------------------------+ #define CFG_TUSB_ATTR_USBRAM - #define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) - #ifdef __cplusplus } #endif From 7dbf1a8caaebf15a634930b1b3e7f3bdc559a180 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Thu, 15 Aug 2019 17:56:15 -0400 Subject: [PATCH 24/27] text fixes --- ports/stm32f4/supervisor/internal_flash.c | 2 +- supervisor/shared/usb/usb.c | 4 ---- supervisor/stub/internal_flash.c | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/ports/stm32f4/supervisor/internal_flash.c b/ports/stm32f4/supervisor/internal_flash.c index fd3241bd6a93f..953fa143934d5 100644 --- a/ports/stm32f4/supervisor/internal_flash.c +++ b/ports/stm32f4/supervisor/internal_flash.c @@ -1,4 +1,4 @@ -/*f +/* * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index b0880b1b62697..0678a3a3fcf97 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -34,7 +34,6 @@ #include "tusb.h" - // Serial number as hex characters. This writes directly to the USB // descriptor. extern uint16_t usb_serial_number[1 + COMMON_HAL_MCU_PROCESSOR_UID_LENGTH * 2]; @@ -43,9 +42,6 @@ void load_serial_number(void) { // create serial number based on device unique id uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; common_hal_mcu_processor_get_uid(raw_id); - for (int i=0; i<2; i++) { - ((uint32_t*) raw_id)[i] = 0; - } static const char nibble_to_hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; diff --git a/supervisor/stub/internal_flash.c b/supervisor/stub/internal_flash.c index 334281e77f7a0..eb1f4a106f363 100644 --- a/supervisor/stub/internal_flash.c +++ b/supervisor/stub/internal_flash.c @@ -1,4 +1,4 @@ -/*f +/* * This file is part of the MicroPython project, http://micropython.org/ * * The MIT License (MIT) From 95411a62b3bb2ae3c5a1912dc3d8f58a0988ec46 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Sun, 18 Aug 2019 19:08:27 -0400 Subject: [PATCH 25/27] Cosmetic fixes --- .../stm32f411ve_discovery/mpconfigboard.h | 2 +- ports/stm32f4/mpconfigport.mk | 2 +- .../peripherals/stm32f4/stm32f411xe/clocks.c | 52 +++++++------- .../peripherals/stm32f4/stm32f411xe/gpio.c | 68 +++++++++---------- ports/stm32f4/supervisor/internal_flash.c | 20 +++--- ports/stm32f4/supervisor/port.c | 2 +- 6 files changed, 73 insertions(+), 73 deletions(-) diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h index 21466f4df988b..5513fe9f37a0e 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h @@ -39,4 +39,4 @@ #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000 - CIRCUITPY_INTERNAL_NVM_SIZE) -#define AUTORESET_DELAY_MS 500 \ No newline at end of file +#define AUTORESET_DELAY_MS 500 diff --git a/ports/stm32f4/mpconfigport.mk b/ports/stm32f4/mpconfigport.mk index 3a8e6acc6f191..6ac477c93e1d6 100644 --- a/ports/stm32f4/mpconfigport.mk +++ b/ports/stm32f4/mpconfigport.mk @@ -21,4 +21,4 @@ CIRCUITPY_MINIMAL_BUILD = 1 CIRCUITPY_MICROCONTROLLER = 1 CIRCUITPY_BUSIO = 1 CIRCUITPY_TIME = 1 -#endif \ No newline at end of file +#endif diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c index 6d2a6fac9a937..883c252d51ea7 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c +++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/clocks.c @@ -28,34 +28,34 @@ void stm32f4_peripherals_clocks_init(void) { //System clock init - RCC_ClkInitTypeDef RCC_ClkInitStruct; - RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_OscInitTypeDef RCC_OscInitStruct; - /* Enable Power Control clock */ - __HAL_RCC_PWR_CLK_ENABLE(); + /* Enable Power Control clock */ + __HAL_RCC_PWR_CLK_ENABLE(); - /* The voltage scaling allows optimizing the power consumption when the device is - clocked below the maximum system frequency, to update the voltage scaling value - regarding system frequency refer to product datasheet. */ - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); + /* The voltage scaling allows optimizing the power consumption when the device is + clocked below the maximum system frequency, to update the voltage scaling value + regarding system frequency refer to product datasheet. */ + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); - /* Enable HSE Oscillator and activate PLL with HSE as source */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; - RCC_OscInitStruct.HSEState = RCC_HSE_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; - RCC_OscInitStruct.PLL.PLLM = 8; - RCC_OscInitStruct.PLL.PLLN = 336; - RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; - RCC_OscInitStruct.PLL.PLLQ = 7; - HAL_RCC_OscConfig(&RCC_OscInitStruct); + /* Enable HSE Oscillator and activate PLL with HSE as source */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = 8; + RCC_OscInitStruct.PLL.PLLN = 336; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; + RCC_OscInitStruct.PLL.PLLQ = 7; + HAL_RCC_OscConfig(&RCC_OscInitStruct); - /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 - clocks dividers */ - RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | 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; - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3); + /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 + clocks dividers */ + RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | 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; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3); } diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c index 3fd85c632970f..83a8b49095295 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c +++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/gpio.c @@ -108,47 +108,47 @@ #include "stm32f4/gpio.h" void stm32f4_peripherals_gpio_init(void) { - //Enable all GPIO for now - GPIO_InitTypeDef GPIO_InitStruct = {0}; - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOE_CLK_ENABLE(); - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOH_CLK_ENABLE(); - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOB_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); + //Enable all GPIO for now + GPIO_InitTypeDef GPIO_InitStruct = {0}; + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOE_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOH_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOD_CLK_ENABLE(); - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOD, LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin, GPIO_PIN_RESET); - /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin */ - GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + /*Configure GPIO pins : LD4_Pin LD3_Pin LD5_Pin LD6_Pin */ + GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin|LD5_Pin|LD6_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - //Status LED chain - stm32f4_peripherals_status_led(0,1); - stm32f4_peripherals_status_led(1,0); - stm32f4_peripherals_status_led(2,0); - stm32f4_peripherals_status_led(3,0); + //Status LED chain + stm32f4_peripherals_status_led(0,1); + stm32f4_peripherals_status_led(1,0); + stm32f4_peripherals_status_led(2,0); + stm32f4_peripherals_status_led(3,0); } //LEDs are inverted on F411 DISCO void stm32f4_peripherals_status_led(uint8_t led, uint8_t state) { - switch(led) - { - case 0: HAL_GPIO_WritePin(GPIOD, LD4_Pin, (state ^ 1)); - break; - case 1: HAL_GPIO_WritePin(GPIOD, LD3_Pin, (state ^ 1)); - break; - case 2: HAL_GPIO_WritePin(GPIOD, LD5_Pin, (state ^ 1)); - break; - case 3: HAL_GPIO_WritePin(GPIOD, LD6_Pin, (state ^ 1)); - break; - default: break; - } + switch(led) + { + case 0: HAL_GPIO_WritePin(GPIOD, LD4_Pin, (state ^ 1)); + break; + case 1: HAL_GPIO_WritePin(GPIOD, LD3_Pin, (state ^ 1)); + break; + case 2: HAL_GPIO_WritePin(GPIOD, LD5_Pin, (state ^ 1)); + break; + case 3: HAL_GPIO_WritePin(GPIOD, LD6_Pin, (state ^ 1)); + break; + default: break; + } } diff --git a/ports/stm32f4/supervisor/internal_flash.c b/ports/stm32f4/supervisor/internal_flash.c index 953fa143934d5..046b26baf2786 100644 --- a/ports/stm32f4/supervisor/internal_flash.c +++ b/ports/stm32f4/supervisor/internal_flash.c @@ -113,8 +113,8 @@ static int32_t convert_block_to_flash_addr(uint32_t block) { } mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { - int32_t src = convert_block_to_flash_addr(block); - if (src == -1) { + int32_t src = convert_block_to_flash_addr(block); + if (src == -1) { // bad block number return false; } @@ -163,14 +163,14 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { return false; } - __HAL_FLASH_DATA_CACHE_DISABLE(); - __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); + __HAL_FLASH_DATA_CACHE_DISABLE(); + __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); - __HAL_FLASH_DATA_CACHE_RESET(); - __HAL_FLASH_INSTRUCTION_CACHE_RESET(); + __HAL_FLASH_DATA_CACHE_RESET(); + __HAL_FLASH_INSTRUCTION_CACHE_RESET(); - __HAL_FLASH_INSTRUCTION_CACHE_ENABLE(); - __HAL_FLASH_DATA_CACHE_ENABLE(); + __HAL_FLASH_INSTRUCTION_CACHE_ENABLE(); + __HAL_FLASH_DATA_CACHE_ENABLE(); // reprogram the sector for (uint32_t i = 0; i < sector_size; i++) { @@ -183,7 +183,7 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { sector_start_addr += 1; } - // lock the flash + // lock the flash HAL_FLASH_Lock(); return true; @@ -191,7 +191,7 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { - for (size_t i = 0; i < num_blocks; i++) { + for (size_t i = 0; i < num_blocks; i++) { if (!supervisor_flash_write_block(src + i * FILESYSTEM_BLOCK_SIZE, block_num + i)) { return 1; // error } diff --git a/ports/stm32f4/supervisor/port.c b/ports/stm32f4/supervisor/port.c index e981318c088c4..0028f013bc2e9 100644 --- a/ports/stm32f4/supervisor/port.c +++ b/ports/stm32f4/supervisor/port.c @@ -70,5 +70,5 @@ uint32_t port_get_saved_word(void) { } void HardFault_Handler(void) { - + while(1) {} } From e490e6361fb695266d4ee46ca983cc86f17dafd5 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Sun, 18 Aug 2019 19:23:52 -0400 Subject: [PATCH 26/27] Add warnings, cosmetic fixes, remove vestigial modules --- .../stm32f411ve_discovery/mpconfigboard.h | 4 +- .../stm32f411ve_discovery/mpconfigboard.mk | 2 +- .../stm32f412zg_discovery/mpconfigboard.h | 3 +- ports/stm32f4/common-hal/busio/SPI.c | 1 + ports/stm32f4/common-hal/busio/UART.c | 1 + .../common-hal/microcontroller/__init__.c | 10 --- ports/stm32f4/common-hal/nvm/ByteArray.c | 81 ------------------- ports/stm32f4/common-hal/nvm/ByteArray.h | 36 --------- ports/stm32f4/common-hal/nvm/__init__.c | 27 ------- ports/stm32f4/mpconfigport.mk | 11 +-- .../peripherals/stm32f4/stm32f411xe/pins.c | 3 - supervisor/supervisor.mk | 8 +- tools/gen_usb_descriptor.py | 6 +- 13 files changed, 18 insertions(+), 175 deletions(-) delete mode 100644 ports/stm32f4/common-hal/nvm/ByteArray.c delete mode 100644 ports/stm32f4/common-hal/nvm/ByteArray.h delete mode 100644 ports/stm32f4/common-hal/nvm/__init__.c diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h index 5513fe9f37a0e..d5491fe3621d8 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.h @@ -35,8 +35,6 @@ #define CIRCUITPY_AUTORELOAD_DELAY_MS 500 -#define CIRCUITPY_INTERNAL_NVM_SIZE 256 - -#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000 - CIRCUITPY_INTERNAL_NVM_SIZE) +#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000) #define AUTORESET_DELAY_MS 500 diff --git a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk index bbc2a4a049454..725a12cf66ab8 100644 --- a/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk +++ b/ports/stm32f4/boards/stm32f411ve_discovery/mpconfigboard.mk @@ -2,7 +2,7 @@ USB_VID = 0x239A USB_PID = 0x802A USB_PRODUCT = "STM32F411VE Discovery Board - CPy" USB_MANUFACTURER = "STMicroelectronics" -USB_REDUCED_ENDPOINT = 1 +USB_CDC_AND_MSC_ONLY = 1 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE diff --git a/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.h b/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.h index 416944257b820..0a89d964654ed 100644 --- a/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.h +++ b/ports/stm32f4/boards/stm32f412zg_discovery/mpconfigboard.h @@ -33,6 +33,5 @@ #define FLASH_SIZE (0x100000) #define FLASH_PAGE_SIZE (0x4000) -#define CIRCUITPY_INTERNAL_NVM_SIZE (4096) #define AUTORESET_DELAY_MS 500 -#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) \ No newline at end of file +#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000) \ No newline at end of file diff --git a/ports/stm32f4/common-hal/busio/SPI.c b/ports/stm32f4/common-hal/busio/SPI.c index a33581b64407a..cde3e5372c309 100644 --- a/ports/stm32f4/common-hal/busio/SPI.c +++ b/ports/stm32f4/common-hal/busio/SPI.c @@ -34,6 +34,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi, const mcu_pin_obj_t * miso) { + mp_raise_NotImplementedError(translate("SPI not yet supported")); } void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) { diff --git a/ports/stm32f4/common-hal/busio/UART.c b/ports/stm32f4/common-hal/busio/UART.c index 32653ab8b570b..e1810b131ef86 100644 --- a/ports/stm32f4/common-hal/busio/UART.c +++ b/ports/stm32f4/common-hal/busio/UART.c @@ -41,6 +41,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout, uint16_t receiver_buffer_size) { + mp_raise_NotImplementedError(translate("UART not yet supported")); } bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { diff --git a/ports/stm32f4/common-hal/microcontroller/__init__.c b/ports/stm32f4/common-hal/microcontroller/__init__.c index 4cbd6d66fdf6e..efdecd2643c7d 100644 --- a/ports/stm32f4/common-hal/microcontroller/__init__.c +++ b/ports/stm32f4/common-hal/microcontroller/__init__.c @@ -32,7 +32,6 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/microcontroller/Processor.h" -#include "shared-bindings/nvm/ByteArray.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Processor.h" @@ -71,15 +70,6 @@ const mcu_processor_obj_t common_hal_mcu_processor_obj = { }, }; -#if CIRCUITPY_INTERNAL_NVM_SIZE > 0 -// The singleton nvm.ByteArray object. -const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { - .base = { - .type = &nvm_bytearray_type, - }, -}; -#endif - STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PE02), MP_ROM_PTR(&pin_PE02) }, { MP_ROM_QSTR(MP_QSTR_PE03), MP_ROM_PTR(&pin_PE03) }, diff --git a/ports/stm32f4/common-hal/nvm/ByteArray.c b/ports/stm32f4/common-hal/nvm/ByteArray.c deleted file mode 100644 index ef70744ad6a6e..0000000000000 --- a/ports/stm32f4/common-hal/nvm/ByteArray.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Nick Moore 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. - */ - -//TODO: Implement for STM32. File required by Microcontroller Init - -#include "common-hal/nvm/ByteArray.h" - -#include -#include - -// defined in linker -extern uint32_t __fatfs_flash_start_addr[]; -extern uint32_t __fatfs_flash_length[]; - -#define NVM_START_ADDR ((uint32_t)__fatfs_flash_start_addr + \ - (uint32_t)__fatfs_flash_length - CIRCUITPY_INTERNAL_NVM_SIZE) - -uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self) { - return CIRCUITPY_INTERNAL_NVM_SIZE; -} - -static void write_page(uint32_t page_addr, uint32_t offset, uint32_t len, uint8_t *bytes) { - // - // Write a whole page to flash, buffering it first and then erasing and rewriting - // it since we can only clear a whole page at a time. - - // if (offset == 0 && len == FLASH_PAGE_SIZE) { - // nrf_nvm_safe_flash_page_write(page_addr, bytes); - // } else { - // uint8_t buffer[FLASH_PAGE_SIZE]; - // memcpy(buffer, (uint8_t *)page_addr, FLASH_PAGE_SIZE); - // memcpy(buffer + offset, bytes, len); - // nrf_nvm_safe_flash_page_write(page_addr, buffer); - // } -} - -bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self, - // uint32_t start_index, uint8_t* values, uint32_t len) { - - // uint32_t address = NVM_START_ADDR + start_index; - // uint32_t offset = address % FLASH_PAGE_SIZE; - // uint32_t page_addr = address - offset; - - // while (len) { - // uint32_t write_len = MIN(len, FLASH_PAGE_SIZE - offset); - // write_page(page_addr, offset, write_len, values); - // len -= write_len; - // values += write_len; - // page_addr += FLASH_PAGE_SIZE; - // offset = 0; - // } - return true; -} - -void common_hal_nvm_bytearray_get_bytes(nvm_bytearray_obj_t *self, - uint32_t start_index, uint32_t len, uint8_t* values) { - memcpy(values, (uint8_t *)(NVM_START_ADDR + start_index), len); -} diff --git a/ports/stm32f4/common-hal/nvm/ByteArray.h b/ports/stm32f4/common-hal/nvm/ByteArray.h deleted file mode 100644 index ed00df9ffe966..0000000000000 --- a/ports/stm32f4/common-hal/nvm/ByteArray.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Nick Moore 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. - */ - -#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_NVM_BYTEARRAY_H -#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_NVM_BYTEARRAY_H - -#include "py/obj.h" - -typedef struct { - mp_obj_base_t base; -} nvm_bytearray_obj_t; - -#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_NVM_BYTEARRAY_H diff --git a/ports/stm32f4/common-hal/nvm/__init__.c b/ports/stm32f4/common-hal/nvm/__init__.c deleted file mode 100644 index 3cdc9d3a4c098..0000000000000 --- a/ports/stm32f4/common-hal/nvm/__init__.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2019 Nick Moore 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. - */ - -// No nvm module functions. diff --git a/ports/stm32f4/mpconfigport.mk b/ports/stm32f4/mpconfigport.mk index 6ac477c93e1d6..1d44feec9f392 100644 --- a/ports/stm32f4/mpconfigport.mk +++ b/ports/stm32f4/mpconfigport.mk @@ -15,10 +15,11 @@ LONGINT_IMPL = MPZ #Reduced feature set for early port CIRCUITPY_MINIMAL_BUILD = 1 +CIRCUITPY_BOARD = 1 +CIRCUITPY_DIGITALIO = 1 +CIRCUITPY_MICROCONTROLLER = 1 +CIRCUITPY_BUSIO = 1 +CIRCUITPY_TIME = 1 + #ifeq ($(MCU_SUB_VARIANT), stm32f412zx) - CIRCUITPY_BOARD = 1 - CIRCUITPY_DIGITALIO = 1 - CIRCUITPY_MICROCONTROLLER = 1 - CIRCUITPY_BUSIO = 1 - CIRCUITPY_TIME = 1 #endif diff --git a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.c b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.c index fca1c1df2c183..0f773961db35e 100644 --- a/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.c +++ b/ports/stm32f4/peripherals/stm32f4/stm32f411xe/pins.c @@ -28,9 +28,6 @@ #include "py/mphal.h" #include "stm32f4/pins.h" - -//TODO -//const mcu_pin_obj_t pin_PE02 = PIN(4, GPIOE, 2); const mcu_pin_obj_t pin_PE02 = PIN(4, GPIOE, 2); const mcu_pin_obj_t pin_PE03 = PIN(4, GPIOE, 3); const mcu_pin_obj_t pin_PE04 = PIN(4, GPIOE, 4); diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 4870f15d83fa2..19516a30ff676 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -44,10 +44,10 @@ ifdef EXTERNAL_FLASH_DEVICES SRC_SUPERVISOR += supervisor/qspi_flash.c supervisor/shared/external_flash/qspi_flash.c endif else - ifneq ($(DISABLE_FILESYSTEM),1) - SRC_SUPERVISOR += supervisor/internal_flash.c - else + ifeq ($(DISABLE_FILESYSTEM),1) SRC_SUPERVISOR += supervisor/stub/internal_flash.c + else + SRC_SUPERVISOR += supervisor/internal_flash.c endif endif @@ -105,7 +105,7 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile --serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\ --output_c_file $(BUILD)/autogen_usb_descriptor.c\ --output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h\ - --reduced_endpoint_mode $(USB_REDUCED_ENDPOINT) + --cdc_and_msc_only $(USB_CDC_AND_MSC_ONLY) CIRCUITPY_DISPLAY_FONT ?= "../../tools/fonts/ter-u12n.bdf" diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index c23b413d257b8..6fb33a77af0de 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -21,7 +21,7 @@ help='length needed for the serial number in digits') parser.add_argument('--output_c_file', type=argparse.FileType('w'), required=True) parser.add_argument('--output_h_file', type=argparse.FileType('w'), required=True) -parser.add_argument('--reduced_endpoint_mode', nargs='?',const=0, type=int) +parser.add_argument('--cdc_and_msc_only', nargs='?',const=0, type=int) args = parser.parse_args() @@ -277,7 +277,7 @@ def strings_in_order(cls): descriptor_list.extend(msc_interfaces) # Only add the control interface because other audio interfaces are managed by it to ensure the # correct ordering. -if not args.reduced_endpoint_mode: +if not args.cdc_and_msc_only: descriptor_list.append(audio_control_interface) # Put the CDC IAD just before the CDC interfaces. # There appears to be a bug in the Windows composite USB driver that requests the @@ -285,7 +285,7 @@ def strings_in_order(cls): # first. However, it still fetches the descriptor anyway. We could reorder the interfaces but # the Windows 7 Adafruit_usbser.inf file thinks CDC is at Interface 0, so we'll leave it # there for backwards compatibility. -if not args.reduced_endpoint_mode: +if not args.cdc_and_msc_only: descriptor_list.extend(hid_interfaces) configuration = standard.ConfigurationDescriptor( From 479b047618416495be1505c111859e385c51be48 Mon Sep 17 00:00:00 2001 From: Hierophect Date: Wed, 4 Sep 2019 13:58:18 -0400 Subject: [PATCH 27/27] Reverted descriptor changes pending HID restructuring --- ports/stm32f4/common-hal/busio/I2C.c | 4 ++-- supervisor/supervisor.mk | 3 +-- tools/gen_usb_descriptor.py | 9 +++------ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/ports/stm32f4/common-hal/busio/I2C.c b/ports/stm32f4/common-hal/busio/I2C.c index 019465cccd422..4d5675127ebe5 100644 --- a/ports/stm32f4/common-hal/busio/I2C.c +++ b/ports/stm32f4/common-hal/busio/I2C.c @@ -37,8 +37,8 @@ I2C_HandleTypeDef hi2c2; void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) { - //TODO: Rework this entire section to use LL, alongside MSP removal - + //TODO: Rework this entire section to use LL so we can properly assign pins + // This will also be bundled with MSP removal hi2c2.Instance = I2C1; hi2c2.Init.ClockSpeed = 100000; hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2; diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 19516a30ff676..0406dcf927207 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -104,8 +104,7 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile --pid $(USB_PID)\ --serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\ --output_c_file $(BUILD)/autogen_usb_descriptor.c\ - --output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h\ - --cdc_and_msc_only $(USB_CDC_AND_MSC_ONLY) + --output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h CIRCUITPY_DISPLAY_FONT ?= "../../tools/fonts/ter-u12n.bdf" diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index 6fb33a77af0de..10bbf5066343f 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -21,7 +21,6 @@ help='length needed for the serial number in digits') parser.add_argument('--output_c_file', type=argparse.FileType('w'), required=True) parser.add_argument('--output_h_file', type=argparse.FileType('w'), required=True) -parser.add_argument('--cdc_and_msc_only', nargs='?',const=0, type=int) args = parser.parse_args() @@ -132,7 +131,7 @@ def strings_in_order(cls): bInterval=0), standard.EndpointDescriptor( description="MSC out", - bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_OUT, + bEndpointAddress=0x1 | standard.EndpointDescriptor.DIRECTION_OUT, bmAttributes=standard.EndpointDescriptor.TYPE_BULK, bInterval=0) ] @@ -277,16 +276,14 @@ def strings_in_order(cls): descriptor_list.extend(msc_interfaces) # Only add the control interface because other audio interfaces are managed by it to ensure the # correct ordering. -if not args.cdc_and_msc_only: - descriptor_list.append(audio_control_interface) +descriptor_list.append(audio_control_interface) # Put the CDC IAD just before the CDC interfaces. # There appears to be a bug in the Windows composite USB driver that requests the # HID report descriptor with the wrong interface number if the HID interface is not given # first. However, it still fetches the descriptor anyway. We could reorder the interfaces but # the Windows 7 Adafruit_usbser.inf file thinks CDC is at Interface 0, so we'll leave it # there for backwards compatibility. -if not args.cdc_and_msc_only: - descriptor_list.extend(hid_interfaces) +descriptor_list.extend(hid_interfaces) configuration = standard.ConfigurationDescriptor( description="Composite configuration",