W25X20CL FLASH bring up with STM32H743 issue
Seeing issue while brining-up Winbond W25X20L FLASH with STM32, Write and read a byte in a loop does not work.
Tried to see the signal's using the scope and seems like clock has some issue, appreciate any help. Please let mw know if more information is needed here.

CubeMx Settings and code I am using is provided below
STM32CubeMX Settings for SPI1 after going through blog post like this Getting Started with STM32 - How to Use SPI (digikey.com)

Basically updated.
1. data_size from 4 to 8, 2. baud_rate to 1.5Mbps using 64 as Prescaler, 3. Disabled NSSP Mode
Here is the Code i am using to read/write a byte in a loop
- #include "main.h"
- #include "stm32h7xx_hal.h"
- // Define the SPI handle
- extern SPI_HandleTypeDef hspi1;
- #define TEST_BYTE0 0xAB
- #define SPI_ADDRESS 0x0005
- #define SPI1_CS GPIO_PIN_0
- // W25X20CL instructions
- const uint8_t EEPROM_READ = 0b00000011;
- const uint8_t EEPROM_WRITE = 0b00000010;
- const uint8_t EEPROM_WRDI = 0b00000100;
- const uint8_t EEPROM_WREN = 0b00000110;
- const uint8_t EEPROM_RDSR = 0b00000101;
- const uint8_t EEPROM_WRSR = 0b00000001;
- // Function prototypes
- void SPI_NOR_WriteByte(uint8_t data, uint32_t address);
- uint8_t SPI_NOR_ReadByte(uint32_t address);
- void EEPROM_test(void) {
- // Initialize the SPI peripheral
- printf("W25X20CL NOR FLASH - SPI1 Test\r\n"); // going to serial port
- // Read and write data to SPI NOR flash
- uint32_t address = SPI_ADDRESS; // Address in the flash memory
- uint8_t write_data = TEST_BYTE0;
- uint8_t read_data;
- // CS pin should default high
- while(1) { // Writing forever same pattern all the time
- SPI_NOR_WriteByte(write_data, address); // Write data to SPI NOR flash
- read_data = SPI_NOR_ReadByte(address); // Read data from SPI NOR flash
- if(read_data != TEST_BYTE0) {
- printf("SPI Test FAILED\r\n");
- printf("0x%x!=0x%x \r\n", read_data, TEST_BYTE0);
- }
- else {
- printf("SPI Test PASSED\r\n");
- printf("0x%x \r\n", read_data);
- }
- HAL_Delay (50); // Write cycle delay (5ms)
- }
- }
- void SPI_NOR_WriteByte(uint8_t data, uint32_t address) {
- // Send the Write Enable (WREN) command
- // This command is specific to the flash memory manufacturer (Winbond)
- // Refer to the flash memory datasheet for the correct command code
- uint8_t cmd_wren = EEPROM_WREN;
- // Enable the chip select (CS) for the SPI NOR flash
- HAL_GPIO_WritePin(GPIOB, SPI1_CS, GPIO_PIN_RESET);
- HAL_SPI_Transmit(&hspi1, &cmd_wren, 1, HAL_MAX_DELAY);
- // Send the Write (WRITE) command
- // Also, send the 3-byte address
- uint8_t cmd_write = EEPROM_WRITE;
- HAL_SPI_Transmit(&hspi1, &cmd_write, 1, HAL_MAX_DELAY);
- HAL_SPI_Transmit(&hspi1, (uint8_t*)&address, 3, HAL_MAX_DELAY);
- HAL_SPI_Transmit(&hspi1, &data, 1, HAL_MAX_DELAY); // Send the data byte to be written
- HAL_Delay (3); // Write cycle delay (3ms)
- HAL_GPIO_WritePin(GPIOB, SPI1_CS, GPIO_PIN_SET); // Disable the chip select (CS)
- }
- uint8_t SPI_NOR_ReadByte(uint32_t address) {
- // Enable the chip select (CS) for the SPI NOR flash
- HAL_GPIO_WritePin(GPIOB, SPI1_CS, GPIO_PIN_RESET);
- // Send the Read (READ) command
- // Also, send the 3-byte address
- uint8_t cmd_read = EEPROM_READ;
- HAL_SPI_Transmit(&hspi1, &cmd_read, 1, HAL_MAX_DELAY);
- HAL_SPI_Transmit(&hspi1, (uint8_t*)&address, 3, HAL_MAX_DELAY);
- // Receive the data byte
- uint8_t read_data;
- HAL_SPI_Receive(&hspi1, &read_data, 1, HAL_MAX_DELAY);
- HAL_Delay (3); // Write cycle delay (3ms)
- HAL_GPIO_WritePin(GPIOB, SPI1_CS, GPIO_PIN_SET); // Disable the chip select (CS)
- return read_data;
- }
static void MX_SPI1_Init(void) {
/* SPI1 parameter configuration*/
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 0x0;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
hspi1.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi1.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK) {
Error_Handler();
}
}
