cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble writing External Loader for QSPI Flash for ST-Link utility

Job Menue
Associate II

Posted on October 04, 2017 at 11:32

Hello,

I am having problems writing my own External Loader for the ST-Link utility. In a previous version of our custom board, we used the same QSPI chip as the one on the

http://www.st.com/en/evaluation-tools/stm32746g-eval.html

, the

https://www.micron.com/~/media/documents/products/data-sheet/nor-flash/serial-nor/mt25q/die-rev-a/mt25q_qljs_l_256_aba_0.pdf

. In a new version of our custom board however, we use the

http://www.mouser.com/ds/2/198/25LP-WP256D_128D-1003201.pdf

.

After reading both of the datasheets, I see that most of the commands are exactly the same. I also found out that the source code for the F7 Demo Project uses the header file for the N25Q512A, which has exactly the same hex commands as the other Micron chip used in the Evaluation board. This means that I would only have to edit and append the header file for the N25Q512. And even then, only a couple of commands are used.

I used the demo project N25Q256A_STM32L476-EVAL located in the folder of the ST-Link utility. Because the F7 Demo project uses certain BSP functions for the N25Q512 (or MT25QL256 apparently, because the source code works on this chip as well), I surmise that I can use the same BSP functions in my own External Loader and maybe only change the instruction code.

So far, I have the following Initialization code:

int Init (void)

{

// System init

SystemInit();

// Clock Init

SystemClock_Config();

// STM32F746 BSP init

BSP_QSPI_Init();

BSP_QSPI_MemoryMappedMode();

return 1;

}

The SystemInit is a standard function in the system_stm32f7xx.c source file. I use exactly the same SystemClock_Config as I use in my project which worked on the previous QSPI chip. (200 MHz SYSCLK, 50 MHz APB1, 100 MHz APB2)

uint8_t BSP_QSPI_Init(void)

{

QSPIHandle.Instance = QUADSPI;

/* Call the DeInit function to reset the driver */

if (HAL_QSPI_DeInit(&QSPIHandle) != HAL_OK)

{

return QSPI_ERROR;

}

/* System level initialization */

BSP_QSPI_MspInit(&QSPIHandle, NULL);

/* QSPI initialization */

/* QSPI freq = SYSCLK /(1 + ClockPrescaler) = 200 MHz/(1+1) = 100 Mhz */

QSPIHandle.Init.ClockPrescaler = 1;

QSPIHandle.Init.FifoThreshold = 4;

QSPIHandle.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;

QSPIHandle.Init.FlashSize = POSITION_VAL(N25Q512A_FLASH_SIZE) - 1;

QSPIHandle.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_6_CYCLE; /* Min 50ns for nonRead */

QSPIHandle.Init.ClockMode = QSPI_CLOCK_MODE_0;

QSPIHandle.Init.FlashID = QSPI_FLASH_ID_1;

QSPIHandle.Init.DualFlash = QSPI_DUALFLASH_DISABLE;

if (HAL_QSPI_Init(&QSPIHandle) != HAL_OK)

{

return QSPI_ERROR;

}

/* QSPI memory reset */

if (QSPI_ResetMemory(&QSPIHandle) != QSPI_OK)

{

return QSPI_NOT_SUPPORTED;

}

/* Set the QSPI memory in 4-bytes address mode */

// After this, EXTADD = 1

if (QSPI_EnterFourBytesAddressMode(&QSPIHandle) != QSPI_OK)

return QSPI_NOT_SUPPORTED;

// Enter QE bit

if(QSPI_EnterQuadEnableBit(&QSPIHandle) != QSPI_OK)

return QSPI_NOT_SUPPORTED;

/* Configuration of the dummy cycles on QSPI memory side */

if (QSPI_DummyCyclesCfg(&QSPIHandle) != QSPI_OK)

return QSPI_NOT_SUPPORTED;

return QSPI_OK;

}

Currently, I use 8 dummy cycles, which should be enough.

Again, I use the same BSP functions as are available in the BSP for my evaluation board. These worked on the previous chip, and not a lot has changed, so I cannot for the life of me figure out what is going wrong.

Can anyone help me out?

1 REPLY 1
Roland Hoesch
Associate II
Posted on February 20, 2018 at 13:15

Hello,

did you manage to fix this and to finish the external loader?