Debian Codegraph @

ports/stm32/boards/LEGO_HUB_NO7/mpconfigboard.h

raw
1 /*
2 * This file is part of the MicroPython project, http://micropython.org/
3 * The MIT License (MIT)
4 * Copyright (c) 2021 Damien P. George
5 */
6
7 #include <stdint.h>
8
9 #define MICROPY_HW_BOARD_NAME "LEGO Technic Hub No.7"
10 #define MICROPY_HW_MCU_NAME "STM32F413"
11
12 #define MICROPY_HW_HAS_SWITCH (0)
13 #define MICROPY_HW_HAS_FLASH (1)
14 #define MICROPY_PY_PYB_LEGACY (0)
15 #define MICROPY_HW_ENTER_BOOTLOADER_VIA_RESET (0)
16 #define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
17 #define MICROPY_HW_ENABLE_RTC (1)
18 #define MICROPY_HW_ENABLE_RNG (1)
19 #define MICROPY_HW_ENABLE_DAC (1)
20 #define MICROPY_HW_ENABLE_USB (1)
21 #define MICROPY_HW_FLASH_FS_LABEL "HUB_NO7"
22
23 // HSE is 16MHz, CPU freq set to 100MHz, buses at maximum freq
24 #define MICROPY_HW_CLK_PLLM (16)
25 #define MICROPY_HW_CLK_PLLN (200)
26 #define MICROPY_HW_CLK_PLLP (RCC_PLLP_DIV2)
27 #define MICROPY_HW_CLK_PLLQ (4)
28 #define MICROPY_HW_CLK_AHB_DIV (RCC_SYSCLK_DIV1)
29 #define MICROPY_HW_CLK_APB1_DIV (RCC_HCLK_DIV2)
30 #define MICROPY_HW_CLK_APB2_DIV (RCC_HCLK_DIV1)
31
32 // For 2.7 to 3.6 V, 75 to 100 MHz: 3 wait states.
33 #define MICROPY_HW_FLASH_LATENCY FLASH_LATENCY_3
34
35 // UART buses
36 // Bluetooth HCI
37 #define MICROPY_HW_UART2_CTS (pyb_pin_BT_CTS)
38 #define MICROPY_HW_UART2_RTS (pyb_pin_BT_RTS)
39 #define MICROPY_HW_UART2_TX (pyb_pin_BT_TX)
40 #define MICROPY_HW_UART2_RX (pyb_pin_BT_RX)
41 // Port B
42 #define MICROPY_HW_UART3_TX (pyb_pin_PORTB_TX)
43 #define MICROPY_HW_UART3_RX (pyb_pin_PORTB_RX)
44 // Port A
45 #define MICROPY_HW_UART5_TX (pyb_pin_PORTA_TX)
46 #define MICROPY_HW_UART5_RX (pyb_pin_PORTA_RX)
47
48 // SPI buses
49 #define MICROPY_HW_SPI2_NSS (pyb_pin_FLASH_NSS)
50 #define MICROPY_HW_SPI2_SCK (pyb_pin_FLASH_SCK)
51 #define MICROPY_HW_SPI2_MISO (pyb_pin_FLASH_MISO)
52 #define MICROPY_HW_SPI2_MOSI (pyb_pin_FLASH_MOSI)
53
54 // USB config
55 #define MICROPY_HW_USB_VBUS_DETECT_PIN (pyb_pin_USB_VBUS)
56 #define MICROPY_HW_USB_FS (1)
57 #define MICROPY_HW_USB_MSC (1)
58
59 // Bluetooth config
60 #define MICROPY_HW_BLE_UART_ID (PYB_UART_2)
61 #define MICROPY_HW_BLE_UART_BAUDRATE (115200)
62 #define MICROPY_HW_BLE_UART_BAUDRATE_SECONDARY (921600)
63 #define MICROPY_HW_BLE_BTSTACK_CHIPSET_INSTANCE btstack_chipset_cc256x_instance()
64
65 // SPI flash, for R/W storage
66 // The first 1MiB is skipped because it's used by the built-in bootloader
67 // Note: MICROPY_HW_SPIFLASH_OFFSET_BYTES must be a multiple of MP_SPIFLASH_ERASE_BLOCK_SIZE
68 #define MICROPY_HW_SPIFLASH_OFFSET_BYTES (1024 * 1024)
69 #define MICROPY_HW_SPIFLASH_BLOCKMAP(bl) ((bl) + MICROPY_HW_SPIFLASH_OFFSET_BYTES / FLASH_BLOCK_SIZE)
70 #define MICROPY_HW_SPIFLASH_BLOCKMAP_EXT(bl) ((bl) + MICROPY_HW_SPIFLASH_OFFSET_BYTES / MP_SPIFLASH_ERASE_BLOCK_SIZE)
71 #define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1)
72 #define MICROPY_HW_SPIFLASH_SIZE_BITS (32 * 1024 * 1024 - MICROPY_HW_SPIFLASH_OFFSET_BYTES * 8)
73 #define MICROPY_HW_SPIFLASH_CS (MICROPY_HW_SPI2_NSS)
74 #define MICROPY_HW_SPIFLASH_SCK (MICROPY_HW_SPI2_SCK)
75 #define MICROPY_HW_SPIFLASH_MISO (MICROPY_HW_SPI2_MISO)
76 #define MICROPY_HW_SPIFLASH_MOSI (MICROPY_HW_SPI2_MOSI)
77
78 // SPI flash, block device config
79 #define MICROPY_HW_BDEV_IOCTL(op, arg) ( \
80 (op) == BDEV_IOCTL_NUM_BLOCKS ? (MICROPY_HW_SPIFLASH_SIZE_BITS / 8 / FLASH_BLOCK_SIZE) : \
81 (op) == BDEV_IOCTL_INIT ? spi_bdev_ioctl(&spi_bdev, (op), (uint32_t)&spiflash_config) : \
82 spi_bdev_ioctl(&spi_bdev, (op), (arg)) \
83 )
84
85 // Configuration for standard block protocol (block size FLASH_BLOCK_SIZE).
86 #define MICROPY_HW_BDEV_READBLOCKS(dest, bl, n) \
87 spi_bdev_readblocks(&spi_bdev, (dest), MICROPY_HW_SPIFLASH_BLOCKMAP(bl), (n))
88 #define MICROPY_HW_BDEV_WRITEBLOCKS(src, bl, n) \
89 spi_bdev_writeblocks(&spi_bdev, (src), MICROPY_HW_SPIFLASH_BLOCKMAP(bl), (n))
90
91 // Configuration for extended block protocol (block size MP_SPIFLASH_ERASE_BLOCK_SIZE).
92 #define MICROPY_HW_BDEV_BLOCKSIZE_EXT (MP_SPIFLASH_ERASE_BLOCK_SIZE)
93 #define MICROPY_HW_BDEV_READBLOCKS_EXT(dest, bl, off, len) \
94 (spi_bdev_readblocks_raw(&spi_bdev, (dest), MICROPY_HW_SPIFLASH_BLOCKMAP_EXT(bl), (off), (len)))
95 #define MICROPY_HW_BDEV_WRITEBLOCKS_EXT(src, bl, off, len) \
96 (spi_bdev_writeblocks_raw(&spi_bdev, (src), MICROPY_HW_SPIFLASH_BLOCKMAP_EXT(bl), (off), (len)))
97 #define MICROPY_HW_BDEV_ERASEBLOCKS_EXT(bl, len) \
98 (spi_bdev_eraseblocks_raw(&spi_bdev, MICROPY_HW_SPIFLASH_BLOCKMAP_EXT(bl), (len)))
99
100 // Board control config
101 #define MICROPY_BOARD_STARTUP board_init
102
103 /******************************************************************************/
104 // Bootloader configuration
105
106 // Configure CPU frequency to 96MHz, to make updates from SPI flash faster
107 #define MBOOT_CLK_PLLM (MICROPY_HW_CLK_VALUE / 1000000)
108 #define MBOOT_CLK_PLLN (192)
109 #define MBOOT_CLK_PLLP (RCC_PLLP_DIV2)
110 #define MBOOT_CLK_PLLQ (4)
111 #define MBOOT_CLK_AHB_DIV (RCC_SYSCLK_DIV1)
112 #define MBOOT_CLK_APB1_DIV (RCC_HCLK_DIV4)
113 #define MBOOT_CLK_APB2_DIV (RCC_HCLK_DIV2)
114 #define MBOOT_FLASH_LATENCY FLASH_LATENCY_3
115
116 #define MBOOT_FSLOAD (1)
117 #define MBOOT_VFS_FAT (1)
118 #define MBOOT_LEAVE_BOOTLOADER_VIA_RESET (0)
119
120 #define MBOOT_SPIFLASH_ADDR (0x80000000)
121 #define MBOOT_SPIFLASH_BYTE_SIZE (4 * 1024 * 1024)
122 #define MBOOT_SPIFLASH_LAYOUT "/0x80000000/1024*4Kg"
123 #define MBOOT_SPIFLASH_ERASE_BLOCKS_PER_PAGE (1)
124 #define MBOOT_SPIFLASH_SPIFLASH (&board_mboot_spiflash)
125 #define MBOOT_SPIFLASH_CONFIG (&board_mboot_spiflash_config)
126
127 #define MBOOT_LED1 0
128 #define MBOOT_LED2 1
129 #define MBOOT_LED3 2
130 #define MBOOT_BOARD_LED_INIT board_mboot_led_init
131 #define MBOOT_BOARD_LED_STATE board_mboot_led_state
132
133 #define MBOOT_BOARD_EARLY_INIT(initial_r0) board_init()
134 #define MBOOT_BOARD_CLEANUP board_mboot_cleanup
135 #define MBOOT_BOARD_GET_RESET_MODE board_mboot_get_reset_mode
136 #define MBOOT_BOARD_STATE_CHANGE board_mboot_state_change
137
138 /******************************************************************************/
139 // Function declarations
140
141 extern const struct _mp_spiflash_config_t spiflash_config;
142 extern struct _spi_bdev_t spi_bdev;
143 extern const struct _mp_spiflash_config_t board_mboot_spiflash_config;
144 extern struct _mp_spiflash_t board_mboot_spiflash;
145
146 void board_init(void);
147 void board_mboot_cleanup(int reset_mode);
148 void board_mboot_led_init(void);
149 void board_mboot_led_state(int led, int state);
150 int board_mboot_get_reset_mode(uint32_t *initial_r0);
151 void board_mboot_state_change(int state, uint32_t arg);
152 void *btstack_chipset_cc256x_instance(void);