Skip to content
Open
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
3 changes: 3 additions & 0 deletions drivers/dht/dht.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef MICROPY_HW_ENABLE_DHT
/*
* This file is part of the MicroPython project, http://micropython.org/
*
Expand Down Expand Up @@ -97,3 +98,5 @@ static mp_obj_t dht_readinto(mp_obj_t pin_in, mp_obj_t buf_in) {
MP_DEFINE_CONST_FUN_OBJ_2(dht_readinto_obj, dht_readinto);

#endif // MICROPY_PY_MACHINE_PULSE

#endif // MICROPY_HW_ENABLE_DHT
10 changes: 6 additions & 4 deletions extmod/modhashlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ static mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
static mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) {
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
hashlib_ensure_not_final(self);
self->final = true;
vstr_t vstr;
vstr_init_len(&vstr, 32);
mbedtls_sha256_finish_ret((mbedtls_sha256_context *)&self->state, (unsigned char *)vstr.buf);
mbedtls_sha256_context tmp_ctx;
memcpy(&tmp_ctx, &self->state, sizeof(tmp_ctx));
mbedtls_sha256_finish_ret(&tmp_ctx, (unsigned char *)vstr.buf);
return mp_obj_new_bytes_from_vstr(&vstr);
}

Expand Down Expand Up @@ -139,10 +140,11 @@ static mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
static mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) {
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
hashlib_ensure_not_final(self);
self->final = true;
vstr_t vstr;
vstr_init_len(&vstr, SHA256_BLOCK_SIZE);
sha256_final((CRYAL_SHA256_CTX *)self->state, (byte *)vstr.buf);
CRYAL_SHA256_CTX tmp_ctx;
memcpy(&tmp_ctx, self->state, sizeof(tmp_ctx));
sha256_final(&tmp_ctx, (byte *)vstr.buf);
return mp_obj_new_bytes_from_vstr(&vstr);
}
#endif
Expand Down
3 changes: 3 additions & 0 deletions extmod/vfs_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ static mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs
if (res == FR_NO_FILESYSTEM && mp_obj_is_true(mkfs)) {
uint8_t working_buf[FF_MAX_SS];
res = f_mkfs(&self->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
if (res == FR_MKFS_ABORTED) { // Probably doesn't support FAT16
res = f_mkfs(&self->fatfs, FM_FAT32, 0, working_buf, sizeof(working_buf));
}
}
if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]);
Expand Down
2 changes: 2 additions & 0 deletions lib/oofatfs/ffconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */


#ifndef FF_USE_FASTSEEK
#define FF_USE_FASTSEEK 0
#endif
/* This option switches fast seek function. (0:Disable or 1:Enable) */


Expand Down
3 changes: 3 additions & 0 deletions ports/stm32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\
ll_sdmmc.c \
ll_fmc.c \
)
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),h7 l4))
HAL_SRC_C += $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_hal_sd_ex.c
endif
ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),h5))
# HAL H5-1.0.0 has a bug with uninitialised variable in HAL_SD_ConfigWideBusOperation.
$(BUILD)/$(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_hal_sd.o: CFLAGS += -Wno-error=maybe-uninitialized
Expand Down
2 changes: 1 addition & 1 deletion ports/stm32/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern const mp_obj_type_t pyb_adc_all_type;
void adc_config(ADC_TypeDef *adc, uint32_t bits);
uint32_t adc_config_and_read_u16(ADC_TypeDef *adc, uint32_t channel, uint32_t sample_time);

#if defined(ADC_CHANNEL_VBAT)
#if defined(ADC_CHANNEL_VBAT) && MICROPY_HW_ENABLE_ADC

static inline void adc_deselect_vbat(ADC_TypeDef *adc, uint32_t channel) {
(void)adc;
Expand Down
48 changes: 47 additions & 1 deletion ports/stm32/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,48 @@ static const uint8_t dma_irqn[NSTREAM] = {
0
};

#elif defined(STM32L4) && defined(DMAMUX1)

// newer L4+ series parts have a DMAMUX unit
#define NCONTROLLERS (2)
#define NSTREAMS_PER_CONTROLLER (7)
#define NSTREAM (NCONTROLLERS * NSTREAMS_PER_CONTROLLER)

#define DMA_SUB_INSTANCE_AS_UINT8(dma_request) (dma_request)

#define DMA1_ENABLE_MASK (0x007f) // Bits in dma_enable_mask corresponding to DMA1
#define DMA2_ENABLE_MASK (0x3f80) // Bits in dma_enable_mask corresponding to DMA2

// DMA1 streams
const dma_descr_t dma_SPI_1_RX = { DMA1_Channel1, DMA_REQUEST_SPI1_RX, dma_id_0, &dma_init_struct_spi_i2c };
const dma_descr_t dma_SPI_1_TX = { DMA1_Channel2, DMA_REQUEST_SPI1_TX, dma_id_1, &dma_init_struct_spi_i2c };
const dma_descr_t dma_SPI_2_RX = { DMA1_Channel3, DMA_REQUEST_SPI2_RX, dma_id_2, &dma_init_struct_spi_i2c };
const dma_descr_t dma_SPI_2_TX = { DMA1_Channel4, DMA_REQUEST_SPI2_TX, dma_id_3, &dma_init_struct_spi_i2c };
const dma_descr_t dma_I2C_2_RX = { DMA1_Channel5, DMA_REQUEST_I2C2_RX, dma_id_4, &dma_init_struct_spi_i2c };
const dma_descr_t dma_I2C_2_TX = { DMA1_Channel6, DMA_REQUEST_I2C2_TX, dma_id_5, &dma_init_struct_spi_i2c };
const dma_descr_t dma_I2C_1_RX = { DMA1_Channel5, DMA_REQUEST_I2C1_RX, dma_id_4, &dma_init_struct_spi_i2c };
const dma_descr_t dma_I2C_1_TX = { DMA1_Channel6, DMA_REQUEST_I2C1_TX, dma_id_5, &dma_init_struct_spi_i2c };

static const uint8_t dma_irqn[NSTREAM] = {
DMA1_Channel1_IRQn,
DMA1_Channel2_IRQn,
DMA1_Channel3_IRQn,
DMA1_Channel4_IRQn,
DMA1_Channel5_IRQn,
DMA1_Channel6_IRQn,
DMA1_Channel7_IRQn,
DMA2_Channel1_IRQn,
DMA2_Channel2_IRQn,
DMA2_Channel3_IRQn,
DMA2_Channel4_IRQn,
DMA2_Channel5_IRQn,
DMA2_Channel6_IRQn,
DMA2_Channel7_IRQn,
};

// chip has some special DMA between SDMMC and system
#undef ENABLE_SDIO

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surprised DMA code in master hasn't caught up to us yet? sure we need this still?

#elif defined(STM32L4)

#define NCONTROLLERS (2)
Expand Down Expand Up @@ -1704,7 +1746,11 @@ static void dma_idle_handler(uint32_t tick) {
}
#endif

#if defined(STM32F0) || defined(STM32G0) || defined(STM32G4) || defined(STM32L0) || defined(STM32L1) || defined(STM32L4)
#if defined(STM32L4) && defined(DMAMUX1)

// not required on L4+?

#elif defined(STM32F0) || defined(STM32G0) || defined(STM32G4) || defined(STM32L0) || defined(STM32L1) || defined(STM32L4)

void dma_nohal_init(const dma_descr_t *descr, uint32_t config) {
DMA_Channel_TypeDef *dma = descr->instance;
Expand Down
20 changes: 20 additions & 0 deletions ports/stm32/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,26 @@ static const flash_layout_t flash_layout[] = {
};
#endif

#elif defined(STM32L4S5xx)

// STM32L4S5xx: 2 MB total, dual-bank (DBANK=1) with 4 KB pages.
// Verified at runtime via FLASH->OPTR bit 22 (DBANK) = 1 on Q1/Mk4.
// In dual-bank mode the HAL macros agree:
// FLASH_BANK_SIZE = FLASH_SIZE >> 1 = 1 MB
// FLASH_PAGE_SIZE = 0x1000 (per stm32l4xx_hal_flash.h)
// The flash_get_sector_info() / get_bank() / get_page() math (selected by
// the STM32L4 + SYSCFG_MEMRMP_FB_MODE branch below) then produces correct
// physical addresses for both banks.
//
// NOTE: an earlier revision of this case used 0x2000 sectors (single-bank
// DBANK=0 assumption). That made get_page() return half the page index it
// should, so the flash_bdev cache committed to the wrong physical sector
// and settings did not survive reboot.
#define FLASH_LAYOUT_IS_HOMOGENEOUS (1)
#define FLASH_LAYOUT_START_ADDR (FLASH_BASE)
#define FLASH_LAYOUT_SECTOR_SIZE (0x1000)
#define FLASH_LAYOUT_NUM_SECTORS ((2 << 20) / 0x1000)

#elif defined(STM32G0) || defined(STM32G4) || defined(STM32L0) || defined(STM32L4) || defined(STM32WB) || defined(STM32WL)

#define FLASH_LAYOUT_IS_HOMOGENEOUS (1)
Expand Down
60 changes: 1 addition & 59 deletions ports/stm32/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,62 +26,4 @@

#include "py/builtin.h"

const char stm32_help_text[] =
"Welcome to MicroPython!\n"
"\n"
"For online docs please visit http://docs.micropython.org/\n"
"\n"
"Quick overview of commands for the board:\n"
#if MICROPY_PY_PYB_LEGACY
" pyb.info() -- print some general information\n"
" pyb.delay(n) -- wait for n milliseconds\n"
" pyb.millis() -- get number of milliseconds since hard reset\n"
#endif
#if MICROPY_HW_HAS_SWITCH
" pyb.Switch() -- create a switch object\n"
" Switch methods: (), callback(f)\n"
#endif
" pyb.LED(n) -- create an LED object for LED n (n=1,2,3,4)\n"
" LED methods: on(), off(), toggle(), intensity(<n>)\n"
" pyb.Pin(pin) -- get a pin, eg pyb.Pin('X1')\n"
" pyb.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p\n"
" Pin methods: init(..), value([v]), high(), low()\n"
" pyb.ExtInt(pin, m, p, callback) -- create an external interrupt object\n"
#if MICROPY_HW_ENABLE_ADC
" pyb.ADC(pin) -- make an analog object from a pin\n"
" ADC methods: read(), read_timed(buf, freq)\n"
#endif
#if MICROPY_HW_ENABLE_DAC
" pyb.DAC(port) -- make a DAC object\n"
" DAC methods: triangle(freq), write(n), write_timed(buf, freq)\n"
#endif
#if MICROPY_HW_ENABLE_RTC
" pyb.RTC() -- make an RTC object; methods: datetime([val])\n"
#endif
#if MICROPY_HW_ENABLE_RNG
" pyb.rng() -- get a 30-bit hardware random number\n"
#endif
#if MICROPY_HW_ENABLE_SERVO
" pyb.Servo(n) -- create Servo object for servo n (n=1,2,3,4)\n"
" Servo methods: calibration(..), angle([x, [t]]), speed([x, [t]])\n"
#endif
#if MICROPY_HW_HAS_MMA7660
" pyb.Accel() -- create an Accelerometer object\n"
" Accelerometer methods: x(), y(), z(), tilt(), filtered_xyz()\n"
#endif
"\n"
"Pins are numbered X1-X12, X17-X22, Y1-Y12, or by their MCU name\n"
"Pin IO modes are: pyb.Pin.IN, pyb.Pin.OUT, pyb.Pin.OPEN_DRAIN\n"
"Pin pull modes are: None, pyb.Pin.PULL_UP, pyb.Pin.PULL_DOWN\n"
"Additional serial bus objects: pyb.I2C(n), pyb.SPI(n), pyb.UART(n)\n"
"\n"
"Control commands:\n"
" CTRL-A -- on a blank line, enter raw REPL mode\n"
" CTRL-B -- on a blank line, enter normal REPL mode\n"
" CTRL-C -- interrupt a running program\n"
" CTRL-D -- on a blank line, do a soft reset of the board\n"
" CTRL-E -- on a blank line, enter paste mode\n"
"\n"
"For further help on a specific object, type help(obj)\n"
"For a list of available modules, type help('modules')\n"
;
const char stm32_help_text[] = "";
2 changes: 2 additions & 0 deletions ports/stm32/machine_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#define ADCx_COMMON ADC_COMMON_REGISTER(0)
#elif defined(STM32F7)
#define ADCx_COMMON ADC123_COMMON
#elif defined(STM32L4S5xx)
#define ADCx_COMMON ADC1_COMMON
#elif defined(STM32L4)
#define ADCx_COMMON __LL_ADC_COMMON_INSTANCE(0)
#endif
Expand Down
2 changes: 2 additions & 0 deletions ports/stm32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,11 @@ void stm32_main(uint32_t reset_mode) {
SCB->CCR |= SCB_CCR_STKALIGN_Msk;
#endif

#if 0
// Hook for a board to run code at start up, for example check if a
// bootloader should be entered instead of the main application.
MICROPY_BOARD_STARTUP();
#endif
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our port should just nop MICROPY_BOARD_STARTUP


// Enable caches and prefetch buffers

Expand Down
10 changes: 10 additions & 0 deletions ports/stm32/mpconfigboard_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,16 @@ void mp_usbd_ll_init(void);

#define MICROPY_HW_USES_BOOTLOADER (MICROPY_HW_VTOR != 0x08000000)

// Expose the CSD and CID values from the card inserted, via pyb.SDCard.ident() function
#ifndef MICROPY_HW_ENABLE_CARD_IDENT
#define MICROPY_HW_ENABLE_CARD_IDENT (0)
#endif

// drivers/dht ... a specific enviro sensor of some sort
#ifndef MICROPY_HW_ENABLE_DHT
#define MICROPY_HW_ENABLE_DHT (1)
#endif

#ifndef MICROPY_HW_ETH_DMA_ATTRIBUTE
#define MICROPY_HW_ETH_DMA_ATTRIBUTE __attribute__((aligned(16384)));
#endif
2 changes: 1 addition & 1 deletion ports/stm32/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
#endif
#endif
#define MICROPY_PY_MACHINE_CAN_INCLUDEFILE "ports/stm32/machine_can.c"
#define MICROPY_PY_MACHINE_DHT_READINTO (1)
#define MICROPY_PY_MACHINE_DHT_READINTO (MICROPY_HW_ENABLE_DHT)
#define MICROPY_PY_MACHINE_PULSE (1)
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
#define MICROPY_PY_MACHINE_I2C (MICROPY_HW_ENABLE_HW_I2C)
Expand Down
40 changes: 37 additions & 3 deletions ports/stm32/sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
#if defined(STM32H5) || defined(STM32H7) || defined(STM32N6)
#define SDIO_TRANSFER_CLK_DIV SDMMC_HSPEED_CLK_DIV
#define SDIO_USE_GPDMA 0
#elif defined(STM32L4P5xx) || defined(STM32L4Q5xx) || defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
// L4+ family: SDMMC has internal DMA, no external DMA controller needed
#define SDIO_USE_GPDMA 0
#define SDIO_TRANSFER_CLK_DIV SDMMC_TRANSFER_CLK_DIV
#else
#define SDIO_TRANSFER_CLK_DIV SDMMC_TRANSFER_CLK_DIV
#define SDIO_USE_GPDMA 1
Expand Down Expand Up @@ -270,7 +274,7 @@ static HAL_StatusTypeDef sdmmc_init_sd(void) {
// SD device interface configuration
sdmmc_handle.sd.Instance = SDIO;
sdmmc_handle.sd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
#if !defined(STM32H5) && !defined(STM32H7) && !defined(STM32N6)
#if !defined(STM32H5) && !defined(STM32H7) && !defined(STM32N6) && !defined(STM32L4S5xx)
sdmmc_handle.sd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
#endif
sdmmc_handle.sd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_ENABLE;
Expand Down Expand Up @@ -794,6 +798,35 @@ static mp_obj_t sd_info(mp_obj_t self) {
}
static MP_DEFINE_CONST_FUN_OBJ_1(sd_info_obj, sd_info);

#if MICROPY_HW_ENABLE_CARD_IDENT
static mp_obj_t sd_card_ident(mp_obj_t self) {
if (!(pyb_sdmmc_flags & PYB_SDMMC_FLAG_ACTIVE)) {
mp_raise_ValueError(MP_ERROR_TEXT("no card"));
}

uint32_t *CSD;
uint32_t *CID;

#if MICROPY_HW_ENABLE_MMCARD
if (pyb_sdmmc_flags & PYB_SDMMC_FLAG_MMC) {
CSD = sdmmc_handle.mmc.CSD;
CID = sdmmc_handle.mmc.CID;
} else
#endif
{
CSD = sdmmc_handle.sd.CSD;
CID = sdmmc_handle.sd.CID;
}

mp_obj_t tuple[2] = {
mp_obj_new_bytes((const uint8_t *)CSD, 16),
mp_obj_new_bytes((const uint8_t *)CID, 16),
};
return mp_obj_new_tuple(2, tuple);
}
static MP_DEFINE_CONST_FUN_OBJ_1(sd_ident_obj, sd_card_ident);
#endif

// now obsolete, kept for backwards compatibility
static mp_obj_t sd_read(mp_obj_t self, mp_obj_t block_num) {
uint8_t *dest = m_new(uint8_t, SDCARD_BLOCK_SIZE);
Expand Down Expand Up @@ -875,6 +908,9 @@ static const mp_rom_map_elem_t pyb_sdcard_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_present), MP_ROM_PTR(&sd_present_obj) },
{ MP_ROM_QSTR(MP_QSTR_power), MP_ROM_PTR(&sd_power_obj) },
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&sd_info_obj) },
#if MICROPY_HW_ENABLE_CARD_IDENT
{ MP_ROM_QSTR(MP_QSTR_ident), MP_ROM_PTR(&sd_ident_obj) },
#endif
{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&sd_read_obj) },
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&sd_write_obj) },
// block device protocol
Expand Down Expand Up @@ -910,9 +946,7 @@ void sdcard_init_vfs(fs_user_mount_t *vfs, int part) {
vfs->base.type = &mp_fat_vfs_type;
vfs->blockdev.flags |= MP_BLOCKDEV_FLAG_NATIVE | MP_BLOCKDEV_FLAG_HAVE_IOCTL;
vfs->fatfs.drv = vfs;
#if MICROPY_FATFS_MULTI_PARTITION
vfs->fatfs.part = part;
#endif
vfs->blockdev.readblocks[0] = MP_OBJ_FROM_PTR(&pyb_sdcard_readblocks_obj);
vfs->blockdev.readblocks[1] = MP_OBJ_FROM_PTR(&pyb_sdcard_obj);
vfs->blockdev.readblocks[2] = MP_OBJ_FROM_PTR(sdcard_read_blocks); // native version
Expand Down
Loading
Loading