#include #include #include #include #include "spi_flash.h" static struct spi_flash_if spif; static void clock_setup(void) { rcc_clock_setup_pll(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_168MHZ]); rcc_periph_clock_enable(RCC_GPIOA); rcc_periph_clock_enable(RCC_GPIOB); rcc_periph_clock_enable(RCC_SPI1); } static void led_setup(void) { gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO6 | GPIO7); } static void spi_flash_if_set_cs(bool val) { if (val) gpio_set(GPIOB, GPIO0); else gpio_clear(GPIOB, GPIO0); } static void spi_flash_setup(void) { gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO3 | GPIO4 | GPIO5); /* SPI flash SCK/MISO/MOSI */ gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO0); /* SPI flash CS */ gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO0 | GPIO3 | GPIO4 | GPIO5); gpio_set_af(GPIOB, 5, GPIO3 | GPIO4 | GPIO5); spif_init(&spif, 256, SPI1, &spi_flash_if_set_cs); } /* void spi_flash_test(void) { spif_clear_mem(&spif); uint32_t buf[1024]; for (size_t addr=0; addr<0x10000; addr += sizeof(buf)) { for (size_t i=0; i