Skip to content

Commit a739b35

Browse files
committed
drivers/memory/spiflash: Change to use low-level SPI object not uPy one.
This patch alters the SPI-flash memory driver so that it uses the new low-level C SPI protocol (from drivers/bus/spi.h) instead of the uPy SPI protocol (from extmod/machine_spi.h). This allows the SPI-flash driver to be used independently from the uPy runtime.
1 parent 58ebeca commit a739b35

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

drivers/memory/spiflash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void mp_spiflash_init(mp_spiflash_t *self) {
162162
if (self->config->bus_kind == MP_SPIFLASH_BUS_SPI) {
163163
mp_hal_pin_write(self->config->bus.u_spi.cs, 1);
164164
mp_hal_pin_output(self->config->bus.u_spi.cs);
165-
self->config->bus.u_spi.proto->init(self->config->bus.u_spi.data, 0, NULL, (mp_map_t*)&mp_const_empty_map);
165+
self->config->bus.u_spi.proto->ioctl(self->config->bus.u_spi.data, MP_SPI_IOCTL_INIT);
166166
} else {
167167
self->config->bus.u_qspi.proto->ioctl(self->config->bus.u_qspi.data, MP_QSPI_IOCTL_INIT);
168168
}

drivers/memory/spiflash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#ifndef MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H
2727
#define MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H
2828

29+
#include "drivers/bus/spi.h"
2930
#include "drivers/bus/qspi.h"
30-
#include "extmod/machine_spi.h"
3131

3232
enum {
3333
MP_SPIFLASH_BUS_SPI,
@@ -40,7 +40,7 @@ typedef struct _mp_spiflash_config_t {
4040
struct {
4141
mp_hal_pin_obj_t cs;
4242
void *data;
43-
const mp_machine_spi_p_t *proto;
43+
const mp_spi_proto_t *proto;
4444
} u_spi;
4545
struct {
4646
void *data;

ports/stm32/spibdev.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,20 @@ static uint32_t flash_tick_counter_last_write;
4040

4141
// External SPI flash uses standard SPI interface
4242

43-
STATIC const mp_machine_soft_spi_obj_t spiflash_spi_bus = {
44-
.base = {&mp_machine_soft_spi_type},
45-
.spi = {
43+
STATIC const mp_soft_spi_obj_t soft_spi_bus = {
4644
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
4745
.polarity = 0,
4846
.phase = 0,
4947
.sck = &MICROPY_HW_SPIFLASH_SCK,
5048
.mosi = &MICROPY_HW_SPIFLASH_MOSI,
5149
.miso = &MICROPY_HW_SPIFLASH_MISO,
52-
}
5350
};
5451

5552
STATIC const mp_spiflash_config_t spiflash_config = {
5653
.bus_kind = MP_SPIFLASH_BUS_SPI,
5754
.bus.u_spi.cs = &MICROPY_HW_SPIFLASH_CS,
58-
.bus.u_spi.data = (void*)&spiflash_spi_bus,
59-
.bus.u_spi.proto = &mp_machine_soft_spi_p,
55+
.bus.u_spi.data = (void*)&soft_spi_bus,
56+
.bus.u_spi.proto = &mp_soft_spi_proto,
6057
};
6158

6259
#elif defined(MICROPY_HW_SPIFLASH_IO0)

0 commit comments

Comments
 (0)