Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add Blues Cygnet Feather (STM32L433) board #10211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions ports/stm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ endif

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

Expand Down Expand Up @@ -197,9 +197,12 @@ ifneq ($(CIRCUITPY_AUDIOBUSIO_PDMIN),0)
endif

ifneq ($(CIRCUITPY_USB),0)
SRC_C += \
lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c \
lib/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c
ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32L433xx))
SRC_C += lib/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
else
SRC_C += lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c
SRC_C += lib/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c
endif
endif

SRC_S = \
Expand Down
27 changes: 27 additions & 0 deletions ports/stm/boards/STM32L433_boot.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
GNU linker script for STM32L433 with bootloader
*/

/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256k /* entire flash */
FLASH_ISR (rx) : ORIGIN = 0x08010000, LENGTH = 4K /* ISR vector. Kind of wasteful. */
FLASH_FIRMWARE (rx) : ORIGIN = 0x08011000, LENGTH = 192K-64K-4K
FLASH_FS (rw) : ORIGIN = 0x08030000, LENGTH = 60K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 640K
}


/* produce a link error if there is not this amount of RAM for these sections */
_minimum_stack_size = 24K;
_minimum_heap_size = 16K;

/* Define the 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);
29 changes: 29 additions & 0 deletions ports/stm/boards/STM32L433_default.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
GNU linker script for STM32L433 with filesystem
*/

/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K /* entire flash */
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 16K /* ISR vector. */
FLASH_FS (rw) : ORIGIN = 0x08004000, LENGTH = 48K
FLASH_FIRMWARE (rx) : ORIGIN = 0x08010000, LENGTH = 256K - 48K - 16K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
}

/* produce a link error if there is not this amount of RAM for these sections */
_minimum_stack_size = 24K;
_minimum_heap_size = 16K;

/* Define the 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);

/* ensure the firmware is within bounds */
ASSERT ( (ORIGIN(FLASH_FIRMWARE) + LENGTH(FLASH_FIRMWARE)) <= (ORIGIN(FLASH)+LENGTH(FLASH)), "FLASH_FIRMWARE out of bounds" );
79 changes: 79 additions & 0 deletions ports/stm/boards/blues_cygnet/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include "supervisor/board.h"
#include "mpconfigboard.h"

#include "stm32l4xx.h"
#include "stm32l433xx.h"

#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/digitalio/Direction.h"
#include "shared-bindings/digitalio/DriveMode.h"
#include "board.h"

digitalio_digitalinout_obj_t power_pin = { .base.type = &digitalio_digitalinout_type };
digitalio_digitalinout_obj_t discharge_pin = { .base.type = &digitalio_digitalinout_type };

void initialize_discharge_pin(void) {
/* Initialize the 3V3 discharge to be OFF and the output power to be ON */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();

common_hal_digitalio_digitalinout_construct(&power_pin, &pin_PH00);
common_hal_digitalio_digitalinout_construct(&discharge_pin, &pin_PH01);
common_hal_digitalio_digitalinout_never_reset(&power_pin);
common_hal_digitalio_digitalinout_never_reset(&discharge_pin);

GPIO_InitTypeDef GPIO_InitStruct;

/* Set DISCHARGE_3V3 as well as the pins we're not initially using to FLOAT */
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = GPIO_PIN_1;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); /* PH1 DISCHARGE_3V3 */
GPIO_InitStruct.Pin = GPIO_PIN_3;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* PB3 is USB_DETECT */
GPIO_InitStruct.Pin = GPIO_PIN_15;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* PA15 is CHARGE_DETECT */
GPIO_InitStruct.Pin = GPIO_PIN_4;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* PA4 is BAT_VOLTAGE */

/* Turn on the 3V3 regulator */
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Pin = GPIO_PIN_0;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOH, GPIO_InitStruct.Pin, GPIO_PIN_SET);
}

void board_init(void) {
// enable the debugger while sleeping. Todo move somewhere more central (kind of generally useful in a debug build)
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);

// Set tick interrupt priority, default HAL value is intentionally invalid
// Without this, USB does not function.
HAL_InitTick((1UL << __NVIC_PRIO_BITS) - 1UL);

__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Pin = GPIO_PIN_8;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
HAL_Delay(50);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
}

void reset_board(void) {
initialize_discharge_pin();
}

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
12 changes: 12 additions & 0 deletions ports/stm/boards/blues_cygnet/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#pragma once

#include "common-hal/digitalio/DigitalInOut.h"

extern digitalio_digitalinout_obj_t power_pin;
extern digitalio_digitalinout_obj_t discharge_pin;
47 changes: 47 additions & 0 deletions ports/stm/boards/blues_cygnet/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2024 Blues Wireless Contributors.
//
// SPDX-License-Identifier: MIT

#pragma once

// Micropython setup

#define MICROPY_HW_BOARD_NAME "Cygnet"
#define MICROPY_HW_MCU_NAME "STM32L433CCT6"

#define MICROPY_PY_SYS_PLATFORM MICROPY_HW_BOARD_NAME

#define STM32L433XX
#define BOARD_CYGNET

#define LSE_VALUE ((uint32_t)32768)
#define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
#define BOARD_HAS_HIGH_SPEED_CRYSTAL (0)

// 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.
// 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.
#define BOARD_LSE_DRIVE_LEVEL RCC_LSEDRIVE_MEDIUMLOW

// Bootloader only
#ifdef UF2_BOOTLOADER_ENABLED
#define BOARD_VTOR_DEFER (1) // Leave VTOR relocation to bootloader
#endif

#define BOARD_NO_VBUS_SENSE (1)
#define BOARD_NO_USB_OTG_ID_SENSE (1)

#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)

#define DEFAULT_SPI_BUS_SS (&pin_PB08)
#define DEFAULT_SPI_BUS_SCK (&pin_PA05)
#define DEFAULT_SPI_BUS_MOSI (&pin_PB05)
#define DEFAULT_SPI_BUS_MISO (&pin_PB06)

#define DEFAULT_UART_BUS_RX (&pin_PA10)
#define DEFAULT_UART_BUS_TX (&pin_PA09)

#define CYGNET_DISCHARGE_3V3 (&pin_PH01)
#define CYGNET_ENABLE_3V3 (&pin_PH00)
105 changes: 105 additions & 0 deletions ports/stm/boards/blues_cygnet/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
USB_VID = 0x30A4
USB_PID = 0x03
USB_PRODUCT = "Cygnet"
USB_MANUFACTURER = "Blues Inc."

MCU_SERIES = L4
MCU_VARIANT = STM32L433xx
MCU_PACKAGE = LQFP48

LD_COMMON = boards/common_default.ld
LD_DEFAULT = boards/STM32L433_default.ld
UF2_OFFSET = 0x8000000
UF2_BOOTLOADER ?= 0
CIRCUITPY_BUILD_EXTENSIONS = bin

INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0

CIRCUITPY_AESIO = 0
CIRCUITPY_ALARM = 0
CIRCUITPY_ANALOGIO = 1
CIRCUITPY_ATEXIT = 0
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOBUSIO_I2SOUT = 0
CIRCUITPY_AUDIOBUSIO_PDMIN = 0
CIRCUITPY_AUDIOMIXER = 0
CIRCUITPY_AUDIOMP3 = 0
CIRCUITPY_AUDIOPWMIO = 0
CIRCUITPY_BITBANGIO = 1
CIRCUITPY_BLEIO = 0
CIRCUITPY_BLEIO_HCI = 0
CIRCUITPY_BINASCII = 0
CIRCUITPY_BITMAPFILTER = 0
CIRCUITPY_BITMAPTOOLS = 0
CIRCUITPY_BUILTINS_POW3 = 0
CIRCUITPY_BUSDEVICE = 0
CIRCUITPY_BUSIO = 1
CIRCUITPY_CANIO = 0
CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE = 1
CIRCUITPY_COUNTIO = 0
CIRCUITPY_DIGITALIO = 1
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_ENABLE_MPY_NATIVE = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_FUTURE= 0
CIRCUITPY_GETPASS = 0
CIRCUITPY_GIFIO = 0
CIRCUITPY_I2CTARGET = 0
CIRCUITPY_JSON = 0
CIRCUITPY_KEYPAD = 0
CIRCUITPY_KEYPAD_DEMUX = 0
CIRCUITPY_LTO = 1
CIRCUITPY_MICROCONTROLLER = 1
CIRCUITPY_MSGPACK = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0
CIRCUITPY_ONEWIREIO = 0
CIRCUITPY_OS = 1
CIRCUITPY_PIXELBUF = 0
CIRCUITPY_PIXELMAP = 0
CIRCUITPY_PULSEIO = 1
CIRCUITPY_PWMIO = 1
CIRCUITPY_RANDOM = 0
CIRCUITPY_RAINBOWIO = 0
CIRCUITPY_RE = 0
CIRCUITPY_REQUIRE_I2C_PULLUPS = 0
CIRCUITPY_ROTARYIO_SOFTENCODER = 1
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_RTC = 0
CIRCUITPY_SAFEMODE_PY = 0
CIRCUITPY_SDCARDIO = 0
CIRCUITPY_STATUS_BAR= 0
CIRCUITPY_STORAGE = 1
CIRCUITPY_SUPERVISOR = 1
CIRCUITPY_SYNTHIO = 0
CIRCUITPY_TERMINALIO = 0
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_TOUCHIO_USE_NATIVE = 1
CIRCUITPY_TRACEBACK = 0
CIRCUITPY_ULAB = 0
CIRCUITPY_USB_CDC = 1
CIRCUITPY_USB_HID = 0
CIRCUITPY_USB_IDENTIFICATION = 1
CIRCUITPY_USB_MIDI = 0
CIRCUITPY_USB_MIDI_ENABLED_DEFAULT= 0
CIRCUITPY_USB_MSC = 1
CIRCUITPY_USB_VENDOR = 0
CIRCUITPY_WIFI_RADIO_SETTABLE_MAC_ADDRESS= 0
CIRCUITPY_VECTORIO = 0
CIRCUITPY_ZLIB = 0

MICROPY_PY_ASYNC_AWAIT = 0

RELEASE_NEEDS_CLEAN_BUILD = 0

SUPEROPT_GC = 0
SUPEROPT_VM = 0

CIRCUITPY_LTO_PARTITION = one

OPTIMIZATION_FLAGS = -Os

CFLAGS_BOARD = -fweb -frename-registers
52 changes: 52 additions & 0 deletions ports/stm/boards/blues_cygnet/pins.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT

// #include "py/objtuple.h"
#include "shared-bindings/board/__init__.h"
#include "board.h"

// Core Feather Pins
static const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS

{ MP_ROM_QSTR(MP_QSTR_ENABLE_3V3), &power_pin },
{ MP_ROM_QSTR(MP_QSTR_DISCHARGE_3V3), &discharge_pin },

{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PB01) },
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA07) },

{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_PA04) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_USR), MP_ROM_PTR(&pin_PC13) },

{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PB08) },
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PB09) },
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PB14) },
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PB15) },

{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PB04) }, // ADC, PWM, DAC2 output also

{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PB07) }, // PWM
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PB06) }, // PWM

{ MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_PB08) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA14) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA13) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB05) },

{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA09) }, // ADC, PWM
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA10) }, // PWM

{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
};

MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
2 changes: 2 additions & 0 deletions ports/stm/common-hal/microcontroller/Pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC, GPIOD, GPIOE};
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC, GPIOD};
#elif defined(UFQFPN48)
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC};
#elif defined(LQFP48)
GPIO_TypeDef *ports[] = {GPIOA, GPIOB, GPIOC};
#else
#error Unknown package type
#endif
Expand Down
Loading