简体   繁体   中英

stm32 and external flash (w25q) connection problem

I want to read/write from external flash (Winbond W25Q16BV) with STM32 micro (stm32F030F4). but running process halt on 'HAL_SPI_Init()' function.

I checked the debug process, and found HAL_SPI_STATE_BUSY. but i don't know why?

I am using STM32CubeMX to generate main project and Keil IDE to write and debug.

SPI_HandleTypeDef hspi1;


void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);


uint8_t spiData[2];

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_SPI1_Init();
  MX_FATFS_Init();


  SPI_HandleTypeDef my_hspi;
  HAL_SPI_Init(&my_hspi);

  HAL_FLASH_Unlock();


  HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_SET); // CS to HIGH
  HAL_Delay(10);


  //Read data
  HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_RESET); // CS to low

  spiData[0]=0x05;

  //transmit register address
  HAL_SPI_Transmit(&my_hspi,spiData,1,10);

 //read
  HAL_SPI_Receive(&my_hspi,&spiData[1],1,10);

  ...

Here is our schematic: 在此处输入图片说明

Unfortunately, I did not find a good example/instruction of how to use external SPI libraries. Any help in this problem is highly appreciated.

I am not able to comment on the software, but according to your comment you want to enable the reading and writing of the flash.

The Write Protect (/WP) pin can be used to prevent the Status Register from being written.

The /WP pin is active low (GND). (Write disable)

The /WP pin is inactive high (VCC). (Write enable)

Its design only allows reading data.

If you want to read and write data, /WP must be connected to Vcc.

You have not set any parameters for the my_hspi struct so your HAL driver doesn't know what he has to do.

Look at the definition of the struct. There are a lot of comments what the different struct elements are used for. For initialization the my_hspi.init part will be most interesting. Also you have to the the my_hspi.Instance to the desired SPI Channel.

You can generate an example configuration using the free STM32 Cube Mx Software.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM