8000 feat: add cygnet to ports/stm · carlossless/circuitpython@5123f3d · GitHub
[go: up one dir, main page]

Skip to content

Commit 5123f3d

Browse files
committed
feat: add cygnet to ports/stm
1 parent 25216c8 commit 5123f3d

File tree

24 files changed

+842
-27
lines changed

24 files changed

+842
-27
lines changed

ports/stm/Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ endif
165165

166166
# Need this to avoid UART linker problems. TODO: rewrite to use registered callbacks.
167167
# Does not exist for F4 and lower
168-
ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32F765xx STM32F767xx STM32F769xx STM32H743xx STM32H750xx STM32L4R5xx))
168+
ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32F765xx STM32F767xx STM32F769xx STM32H743xx STM32H750xx STM32L4R5xx STM32L433xx))
169169
SRC_STM32 += $(HAL_DIR)/Src/stm32$(MCU_SERIES_LOWER)xx_hal_uart_ex.c
170170
endif
171171

@@ -197,9 +197,12 @@ ifneq ($(CIRCUITPY_AUDIOBUSIO_PDMIN),0)
197197
endif
198198

199199
ifneq ($(CIRCUITPY_USB),0)
200-
SRC_C += \
201-
lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c \
202-
lib/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c
200+
ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32L433xx))
201+
SRC_C += lib/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
202+
else
203+
SRC_C += lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c
204+
SRC_C += lib/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c
205+
endif
203206
endif
204207

205208
SRC_S = \

ports/stm/boards/STM32L433_boot.ld

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
GNU linker script for STM32L433 with bootloader
3+
*/
4+
5+
/* Specify the memory areas */
6+
MEMORY
7+
{
8+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256k /* entire flash */
9+
FLASH_ISR (rx) : ORIGIN = 0x08010000, LENGTH = 4K /* ISR vector. Kind of wasteful. */
10+
FLASH_FIRMWARE (rx) : ORIGIN = 0x08011000, LENGTH = 192K-64K-4K
11+
FLASH_FS (rw) : ORIGIN = 0x08030000, LENGTH = 60K
12+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 640K
13+
}
14+
15+
16+
/* produce a link error if there is not this amount of RAM for these sections */
17+
_minimum_stack_size = 24K;
18+
_minimum_heap_size = 16K;
19+
20+
/* Define the top end of the stack. The stack is full descending so begins just
21+
above last byte of RAM. Note that EABI requires the stack to be 8-byte
22+
aligned for a call. */
23+
_estack = ORIGIN(RAM) + LENGTH(RAM);
24+
25+
/* RAM extents for the garbage collector */
26+
_ram_start = ORIGIN(RAM);
27+
_ram_end = ORIGIN(RAM) + LENGTH(RAM);

ports/stm/boards/STM32L433_default.ld

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
GNU linker script for STM32L433 with filesystem
3+
*/
4+
5+
/* Specify the memory areas */
6+
MEMORY
7+
{
8+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K /* entire flash */
9+
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* ISR vector. */
10+
FLASH_FS (rw) : ORIGIN = 0x08004000, LENGTH = 48K
11+
FLASH_FIRMWARE (rx) : ORIGIN = 0x08010000, LENGTH = 256K - 48K - 16K
12+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
13+
}
14+
15+
/* produce a link error if there is not this amount of RAM for these sections */
16+
_minimum_stack_size = 24K;
17+
_minimum_heap_size = 16K;
18+
19+
/* Define the top end of the stack. The stack is full descending so begins just
20+
above last byte of RAM. Note that EABI requires the stack to be 8-byte
21+
aligned for a call. */
22+
_estack = ORIGIN(RAM) + LENGTH(RAM);
23+
24+
/* RAM extents for the garbage collector */
25+
_ram_start = ORIGIN(RAM);
26+
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
27+
28+
/* ensure the firmware is within bounds */
29+
ASSERT ( (ORIGIN(FLASH_FIRMWARE) + LENGTH(FLASH_FIRMWARE)) <= (ORIGIN(FLASH)+LENGTH(FLASH)), "FLASH_FIRMWARE out of bounds" );

ports/stm/boards/blues_cygnet/board.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "supervisor/board.h"
8+
#include "mpconfigboard.h"
9+
10+
#include "stm32l4xx.h"
11+
#include "stm32l433xx.h"
12+
13+
#include "shared-bindings/microcontroller/Pin.h"
14+
#include "shared-bindings/digitalio/DigitalInOut.h"
15+
#include "shared-bindings/digitalio/Direction.h"
16+
#include "shared-bindings/digitalio/DriveMode.h"
17+
#include "board.h"
18+
19+
digitalio_digitalinout_obj_t power_pin = { .base.type = &digitalio_digitalinout_type };
20+
digitalio_digitalinout_obj_t discharge_pin = { .base.type = &digitalio_digitalinout_type };
21+
22+
void initialize_discharge_pin(void) {
23+
/* Initialize the 3V3 discharge to be OFF and the output power to be ON */
24+
__HAL_RCC_GPIOA_CLK_ENABLE();
25+
__HAL_RCC_GPIOH_CLK_ENABLE();
26+
__HAL_RCC_GPIOB_CLK_ENABLE();
27+
28+
common_hal_digitalio_digitalinout_construct(&power_pin, &pin_PH00);
29+
common_hal_digitalio_digitalinout_construct(&discharge_pin, &pin_PH01);
30+
common_hal_digitalio_digitalinout_never_reset(&power_pin);
31+
common_hal_digitalio_digitalinout_never_reset(&discharge_pin);
32+
33+
GPIO_InitTypeDef GPIO_InitStruct;
34+
35+
/* Set DISCHARGE_3V3 as well as the pins we're not initially using to FLOAT */
36+
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
37+
GPIO_InitStruct.Pull = GPIO_NOPULL;
38+
GPIO_InitStruct.Pin = GPIO_PIN_1;
39+
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); /* PH1 DISCHARGE_3V3 */
40+
GPIO_InitStruct.Pin = GPIO_PIN_3;
41+
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* PB3 is USB_DETECT */
42+
GPIO_InitStruct.Pin = GPIO_PIN_15;
43+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* PA15 is CHARGE_DETECT */
44+
GPIO_InitStruct.Pin = GPIO_PIN_4;
45+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* PA4 is BAT_VOLTAGE */
46+
47+
/* Turn on the 3V3 regulator */
48+
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
49+
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
50+
GPIO_InitStruct.Pin = GPIO_PIN_0;
51+
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
52+
HAL_GPIO_WritePin(GPIOH, GPIO_InitStruct.Pin, GPIO_PIN_SET);
53+
}
54+
55+
void board_init(void) {
56+
// enable the debugger while sleeping. Todo move somewhere more central (kind of generally useful in a debug build)
57+
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
58+
59+
// Set tick interrupt priority, default HAL value is intentionally invalid
60+
// Without this, USB does not function.
61+
HAL_InitTick((1UL << __NVIC_PRIO_BITS) - 1UL);
62+
63+
__HAL_RCC_GPIOA_CLK_ENABLE();
64+
GPIO_InitTypeDef GPIO_InitStruct;
65+
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
66+
GPIO_InitStruct.Pull = GPIO_NOPULL;
67+
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
68+
GPIO_InitStruct.Pin = GPIO_PIN_8;
69+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
70+
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
71+
HAL_Delay(50);
72+
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
73+
}
74+
75+
void reset_board(void) {
76+
initialize_discharge_pin();
77+
}
78+
79+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/stm/boards/blues_cygnet/board.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
#include "common-hal/digitalio/DigitalInOut.h"
10+
11+
extern digitalio_digitalinout_obj_t power_pin;
12+
extern digitalio_digitalinout_obj_t discharge_pin;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2024 Blues Wireless Contributors.
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
// Micropython setup
10+
11+
#define MICROPY_HW_BOARD_NAME "Cygnet"
12+
#define MICROPY_HW_MCU_NAME "STM32L433CCT6"
13+
14+
#define MICROPY_PY_SYS_PLATFORM MICROPY_HW_BOARD_NAME
15+
16+
#define STM32L433XX
17+
#define BOARD_CYGNET
18+
19+
#define LSE_VALUE ((uint32_t)32768)
20+
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
21+
#define BOARD_HAS_HIGH_SPEED_CRYSTAL (0)
22+
23+
// Increase drive strength of 32kHz external crystal, in line with calculations specified in ST AN2867 sections 3.3, 3.4, and STM32L4 datasheet DS12023 Table 58. LSE oscillator characteristics.
24+
// The drive strength RCC_LSEDRIVE_LOW is marginal for the 32kHz crystal oscillator stability, and RCC_LSEDRIVE_MEDIUMLOW meets the calculated drive strength with a small margin for parasitic capacitance.
25+
#define BOARD_LSE_DRIVE_LEVEL RCC_LSEDRIVE_MEDIUMLOW
26+
27+
// Bootloader only
28+
#ifdef UF2_BOOTLOADER_ENABLED
29+
#define BOARD_VTOR_DEFER (1) // Leave VTOR relocation to bootloader
30+
#endif
31+
32+
#define BOARD_NO_VBUS_SENSE (1)
33+
#define BOARD_NO_USB_OTG_ID_SENSE (1)
34+
35+
#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
36+
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)
37+
38+
#define DEFAULT_SPI_BUS_SS (&pin_PB08)
39+
#define DEFAULT_SPI_BUS_SCK (&pin_PA05)
40+
#define DEFAULT_SPI_BUS_MOSI (&pin_PB05)
41+
#define DEFAULT_SPI_BUS_MISO (&pin_PB06)
42+
43+
#define DEFAULT_UART_BUS_RX (&pin_PA10)
44+
#define DEFAULT_UART_BUS_TX (&pin_PA09)
45+
46+
#define CYGNET_DISCHARGE_3V3 (&pin_PH01)
47+
#define CYGNET_ENABLE_3V3 (&pin_PH00)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
USB_VID = 0x30A4
2+
USB_PID = 0x03
3+
USB_PRODUCT = "Cygnet"
4+
USB_MANUFACTURER = "Blues Inc."
5+
6+
MCU_SERIES = L4
7+
MCU_VARIANT = STM32L433xx
8+
MCU_PACKAGE = LQFP48
9+
10+
LD_COMMON = boards/common_default.ld
11+
LD_DEFAULT = boards/STM32L433_default.ld
12+
UF2_OFFSET = 0x8000000
13+
UF2_BOOTLOADER ?= 0
14+
CIRCUITPY_BUILD_EXTENSIONS = bin
15+
16+
INTERNAL_FLASH_FILESYSTEM = 1
17+
LONGINT_IMPL = NONE
18+
CIRCUITPY_FULL_BUILD = 0
19+
20+
CIRCUITPY_AESIO = 0
21+
CIRCUITPY_ALARM = 0
22+
CIRCUITPY_ANALOGIO = 1
23+
CIRCUITPY_ATEXIT = 0
24+
CIRCUITPY_AUDIOBUSIO = 0
25+
CIRCUITPY_AUDIOBUSIO_I2SOUT = 0
26+
CIRCUITPY_AUDIOBUSIO_PDMIN = 0
27+
CIRCUITPY_AUDIOMIXER = 0
28+
CIRCUITPY_AUDIOMP3 = 0
29+
CIRCUITPY_AUDIOPWMIO = 0
30+
CIRCUITPY_BITBANGIO = 1
31+
CIRCUITPY_BLEIO = 0
32+
CIRCUITPY_BLEIO_HCI = 0
33+
CIRCUITPY_BINASCII = 0
34+
CIRCUITPY_BITMAPFILTER = 0
35+
CIRCUITPY_BITMAPTOOLS = 0
36+
CIRCUITPY_BUILTINS_POW3 = 0
37+
CIRCUITPY_BUSDEVICE = 0
38+
CIRCUITPY_BUSIO = 1
39+
CIRCUITPY_CANIO = 0
40+
CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE = 1
41+
CIRCUITPY_COUNTIO = 0
42+
CIRCUITPY_DIGITALIO = 1
43+
CIRCUITPY_DISPLAYIO = 0
44+
CIRCUITPY_ENABLE_MPY_NATIVE = 0
45+
CIRCUITPY_FRAMEBUFFERIO = 0
46+
CIRCUITPY_FREQUENCYIO = 0
47+
CIRCUITPY_FUTURE= 0
48+
CIRCUITPY_GETPASS = 0
49+
CIRCUITPY_GIFIO = 0
50+
CIRCUITPY_I2CTARGET = 0
51+
CIRCUITPY_JSON = 0
52+
CIRCUITPY_KEYPAD = 0
53+
CIRCUITPY_KEYPAD_DEMUX = 0
54+
CIRCUITPY_LTO = 1
55+
CIRCUITPY_MICROCONTROLLER = 1
56+
CIRCUITPY_MSGPACK = 0
57+
CIRCUITPY_NEOPIXEL_WRITE = 0
58+
CIRCUITPY_NVM = 0
59+
CIRCUITPY_ONEWIREIO = 0
60+
CIRCUITPY_OS = 1
61+
CIRCUITPY_PIXELBUF = 0
62+
CIRCUITPY_PIXELMAP = 0
63+
CIRCUITPY_PULSEIO = 1
64+
CIRCUITPY_PWMIO = 1
65+
CIRCUITPY_RANDOM = 0
66+
CIRCUITPY_RAINBOWIO = 0
67+
CIRCUITPY_RE = 0
68+
CIRCUITPY_REQUIRE_I2C_PULLUPS = 0
69+
CIRCUITPY_ROTARYIO_SOFTENCODER = 1
70+
CIRCUITPY_RGBMATRIX = 0
71+
CIRCUITPY_RTC = 0
72+
CIRCUITPY_SAFEMODE_PY = 0
73+
CIRCUITPY_SDCARDIO = 0
74+
CIRCUITPY_STATUS_BAR= 0
75+
CIRCUITPY_STORAGE = 1
76+
CIRCUITPY_SUPERVISOR = 1
77+
CIRCUITPY_SYNTHIO = 0
78+
CIRCUITPY_TERMINALIO = 0
79+
CIRCUITPY_TOUCHIO = 0
80+
CIRCUITPY_TOUCHIO_USE_NATIVE = 1
81+
CIRCUITPY_TRACEBACK = 0
82+
CIRCUITPY_ULAB = 0
83+
CIRCUITPY_USB_CDC = 1
84+
CIRCUITPY_USB_HID = 0
85+
CIRCUITPY_USB_IDENTIFICATION = 1
86+
CIRCUITPY_USB_MIDI = 0
87+
CIRCUITPY_USB_MIDI_ENABLED_DEFAULT= 0
88+
CIRCUITPY_USB_MSC = 1
89+
CIRCUITPY_USB_VENDOR = 0
90+
CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS= 0
91+
CIRCUITPY_ E870 VECTORIO = 0
92+
CIRCUITPY_ZLIB = 0
93+
94+
MICROPY_PY_ASYNC_AWAIT = 0
95+
96+
RELEASE_NEEDS_CLEAN_BUILD = 0
97+
98+
SUPEROPT_GC = 0
99+
SUPEROPT_VM = 0
100+
101+
CIRCUITPY_LTO_PARTITION = one
102+
103+
OPTIMIZATION_FLAGS = -Os
104+
105+
CFLAGS_BOARD = -fweb -frename-registers

ports/stm/boards/blues_cygnet/pins.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
// #include "py/objtuple.h"
8+
#include "shared-bindings/board/__init__.h"
9+
#include "board.h"
10+
11+
// Core Feather Pins
12+
static const mp_rom_map_elem_t board_module_globals_table[] = {
13+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
14+
15+
{ MP_ROM_QSTR(MP_QSTR_ENABLE_3V3), &power_pin },
16+
{ MP_ROM_QSTR(MP_QSTR_DISCHARGE_3V3), &discharge_pin },
17+
18+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA00) },
19+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA01) },
20+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA02) },
21+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA03) },
22+
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PB01) },
23+
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA07) },
24+
25+
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_PA04) },
26+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_USR), MP_ROM_PTR(&pin_PC13) },
27+
28+
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PB08) },
29+
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PB09) },
30+
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PB14) },
31+
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PB15) },
32+
33+
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PA08) },
34+
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PB04) }, // ADC, PWM, DAC2 output also
35+
36+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB07) }, // PWM
37+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB06) }, // PWM
38+
39+
{ MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_PB08) },
40+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA14) },
41+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA13) },
42+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB05) },
43+
44+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA09) }, // ADC, PWM
45+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA10) }, // PWM
46+
47+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
48+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
49+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
50+
};
51+
52+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

ports/stm/common-hal/microcontroller/Pin.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE};
2121
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC, GPIOD};
2222
#elif defined(UFQFPN48)
2323
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC};
24+
#elif defined(LQFP48)
25+
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC};
2426
#else
2527
#error Unknown package type
2628
#endif

0 commit comments

Comments
 (0)
0