Debian Codegraph @

ports/stm32/boards/LEGO_HUB_NO6/bdev.c

raw
1 /*
2 * This file is part of the MicroPython project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2021-2022 Damien P. George
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
27 #include "py/obj.h"
28 #include "storage.h"
29 #include "spi.h"
30
31 #if BUILDING_MBOOT
32
33 // Mboot doesn't support hardware SPI, so use software SPI instead.
34
35 static const mp_soft_spi_obj_t soft_spi_bus = {
36 .delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
37 .polarity = 0,
38 .phase = 0,
39 .sck = MICROPY_HW_SPIFLASH_SCK,
40 .mosi = MICROPY_HW_SPIFLASH_MOSI,
41 .miso = MICROPY_HW_SPIFLASH_MISO,
42 };
43
44 const mp_spiflash_config_t board_mboot_spiflash_config = {
45 .bus_kind = MP_SPIFLASH_BUS_SPI,
46 .bus.u_spi.cs = MICROPY_HW_SPIFLASH_CS,
47 .bus.u_spi.data = (void *)&soft_spi_bus,
48 .bus.u_spi.proto = &mp_soft_spi_proto,
49 };
50
51 mp_spiflash_t board_mboot_spiflash;
52
53 #else
54
55 static const spi_proto_cfg_t spi_bus = {
56 .spi = &spi_obj[1], // SPI2 hardware peripheral
57 .baudrate = 25000000,
58 .polarity = 0,
59 .phase = 0,
60 .bits = 8,
61 .firstbit = SPI_FIRSTBIT_MSB,
62 };
63
64 static mp_spiflash_cache_t spi_bdev_cache;
65
66 const mp_spiflash_config_t spiflash_config = {
67 .bus_kind = MP_SPIFLASH_BUS_SPI,
68 .bus.u_spi.cs = MICROPY_HW_SPIFLASH_CS,
69 .bus.u_spi.data = (void *)&spi_bus,
70 .bus.u_spi.proto = &spi_proto,
71 .cache = &spi_bdev_cache,
72 };
73
74 spi_bdev_t spi_bdev;
75
76 #endif