--- SPI_Flash.c.orig 2022-02-28 16:36:53.000000000 +0900 +++ SPI_Flash.c 2023-01-12 17:16:23.097970598 +0900 @@ -69,11 +69,13 @@ static inline void spi_flash_enable(void GPIO_PinInit(GPIO_SPI_FLASH_DO_U, Pin_SPI_FLASH_DO_U, &pin_config_output); GPIO_PinInit(GPIO_SPI_FLASH_CS_U, Pin_SPI_FLASH_CS_U, &pin_config_output); GPIO_SPI_FLASH_CS_U->PCOR = 1U << Pin_SPI_FLASH_CS_U; + __DSB(); } static inline void spi_flash_disable(void) { GPIO_SPI_FLASH_CS_U->PSOR = 1U << Pin_SPI_FLASH_CS_U; + __DSB(); GPIO_PinInit(GPIO_SPI_FLASH_CS_U, Pin_SPI_FLASH_CS_U, &pin_config_input); GPIO_PinInit(GPIO_SPI_FLASH_DO_U, Pin_SPI_FLASH_DO_U, &pin_config_input); } @@ -83,7 +85,7 @@ static inline uint8_t spi_flash_transfer for (uint8_t bit = 0; bit < 8; bit++) { GPIO_SPI_FLASH_CLK_U->PCOR = 1U << Pin_SPI_FLASH_CLK_U; - // __asm volatile( "nop" ); + __DSB(); if ((c & 0x80) == 0U) { GPIO_SPI_FLASH_DO_U->PCOR = 1U << Pin_SPI_FLASH_DO_U;// Hopefully the compiler will optimise this to a value rather than using a shift @@ -92,13 +94,12 @@ static inline uint8_t spi_flash_transfer { GPIO_SPI_FLASH_DO_U->PSOR = 1U << Pin_SPI_FLASH_DO_U;// Hopefully the compiler will optimise this to a value rather than using a shift } - // __asm volatile( "nop" ); + __DSB(); c <<= 1; c |= (GPIO_SPI_FLASH_DI_U->PDIR >> Pin_SPI_FLASH_DI_U) & 0x01U; // toggle the clock GPIO_SPI_FLASH_CLK_U->PSOR = 1U << Pin_SPI_FLASH_CLK_U; - // __asm volatile( "nop" ); - + __DSB(); } return c; }