26
26
27
27
#include "py/obj.h"
28
28
#include "storage.h"
29
+ #include "spi.h"
29
30
30
31
#define CMD_EXIT_4_BYTE_ADDRESS_MODE (0xE9)
31
32
32
- STATIC const mp_soft_spi_obj_t soft_spi_bus = {
33
- .delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY ,
33
+ STATIC const spi_proto_cfg_t spi_bus = {
34
+ .spi = & spi_obj [1 ], // SPI2 hardware peripheral
35
+ .baudrate = 25000000 ,
34
36
.polarity = 0 ,
35
37
.phase = 0 ,
36
- .sck = MICROPY_HW_SPIFLASH_SCK ,
37
- .mosi = MICROPY_HW_SPIFLASH_MOSI ,
38
- .miso = MICROPY_HW_SPIFLASH_MISO ,
38
+ .bits = 8 ,
39
+ .firstbit = SPI_FIRSTBIT_MSB ,
39
40
};
40
41
41
42
STATIC mp_spiflash_cache_t spi_bdev_cache ;
42
43
43
44
const mp_spiflash_config_t spiflash_config = {
44
45
.bus_kind = MP_SPIFLASH_BUS_SPI ,
45
- .bus .u_spi .cs = MICROPY_HW_SPIFLASH_NSS ,
46
- .bus .u_spi .data = (void * )& soft_spi_bus ,
47
- .bus .u_spi .proto = & mp_soft_spi_proto ,
46
+ .bus .u_spi .cs = MICROPY_HW_SPIFLASH_CS ,
47
+ .bus .u_spi .data = (void * )& spi_bus ,
48
+ .bus .u_spi .proto = & spi_proto ,
48
49
.cache = & spi_bdev_cache ,
49
50
};
50
51
@@ -55,9 +56,9 @@ int32_t board_bdev_ioctl(void) {
55
56
56
57
// Exit 4-byte address mode
57
58
uint8_t cmd = CMD_EXIT_4_BYTE_ADDRESS_MODE ;
58
- mp_hal_pin_write (MICROPY_HW_SPIFLASH_NSS , 0 );
59
- mp_soft_spi_proto .transfer (MP_OBJ_FROM_PTR (& soft_spi_bus ), 1 , & cmd , NULL );
60
- mp_hal_pin_write (MICROPY_HW_SPIFLASH_NSS , 1 );
59
+ mp_hal_pin_write (MICROPY_HW_SPIFLASH_CS , 0 );
60
+ spi_proto .transfer (MP_OBJ_FROM_PTR (& spi_bus ), 1 , & cmd , NULL );
61
+ mp_hal_pin_write (MICROPY_HW_SPIFLASH_CS , 1 );
61
62
62
63
return ret ;
63
64
}
0 commit comments