cancel
Showing results for 
Search instead for 
Did you mean: 

winbond W25Q128JVSIQ external loader problem

AhmedSayed
Associate II

i am working with stm32 h750vb and i successfully wrote a winbond W25Q128JVSIQ external loader and it works fine on the cube programmer but when i use the cube ide i found that it successfully erase the external flash before file download and fails to write sector 0 so i found the problem was that i am using the time base source on the external loader was TIM2 and after changing it to systick the cube ide succussed to start writing to the external flash but now i get data mismatch at 0x90008900 on both cube programmer and on the cube ide with the edited external loader unlike the one before and all  the data after this address is corrupted  . i tried many things but didn't manage to make it upload the data successfully, any help will be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

What is your pin configuration? Perhaps a loader here would suit? I'm not using interrupts.

https://github.com/cturvey/stm32extldr/tree/main/h7_w25q128

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

8 REPLIES 8

Instrument the loader via an available UART so you can understand the interactions from STM32 Cube Programmer. 

Check the data as you go.

Make sure you're masking the address as the memory is Zero based, it doesn't understand the 0x90000000 address space the STM32 decodes.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

thank you i managed to make it work but now i face another problem whenever i enable the external loader in the debug tab of the cube ide i found that the interrupts are not working anymore even though i didn't put anything in the external flash yet and when i disable it the interrupts start to work again what could be the reason?

 

Make sure that SCB->VTOR points to your vector table, wherever that is now situated in memory. Check SystemInit()

Make sure you dont' leave disableint(), or similar in your code. Or alternatively explicitly enable them in Reset_Handler or SystemInit()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

sorry for bothering you but know i know what is the problem when i enable  the external loader my code stuck here :

static void prvPortStartFirstTask( void )
{
/* Start the first task.  This also clears the bit that indicates the FPU is
in use in case the FPU was used before the scheduler was started - which
would otherwise result in the unnecessary leaving of space in the SVC stack
for lazy saving of FPU registers. */
 
  uint32_t r0_val, msp_val, control_val;
 
    // Manually set the VTOR to the RAM address where the vector table is expected
    SCB->VTOR = 0x24000004; // Adjust this if your vector table starts at a different address
    printf("Manually setting VTOR to: %08X\n", SCB->VTOR);
 
    // Read the first entry of the vector table to get the initial MSP value
    r0_val = *(volatile uint32_t *)(SCB->VTOR);
    printf("Initial MSP Value from Vector Table: %08X\n", r0_val);
 
    if (r0_val == 0 || r0_val == 0xFFFFFFFF) {
        // Fallback to a default stack address within RAM
        printf("Invalid MSP value, manually setting to a safe address.\n");
        r0_val = 0x24080000; // Example: Adjust to a valid address in your RAM.
    }
 
    msp_val = r0_val;  // Use this value as the initial MSP
    __asm volatile("msr msp, %0" : : "r" (msp_val));
 
    // Clear CONTROL register to switch to Main Stack Pointer
    control_val = 0;
    __asm volatile("msr control, %0" : : "r" (control_val));
    printf("Control Register Set to: %08X\n", control_val);
 
    // Enable interrupts and make a system call to start the first task
    __asm volatile(
        "cpsie i \n"  // Globally enable interrupts.
        "cpsie f \n"
        "dsb     \n"
        "isb     \n"
        "svc 0   \n"  // System call to start first task.
        "nop     \n"
    );
// __asm volatile(
// " ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */
// " ldr r0, [r0] \n"
// " ldr r0, [r0] \n"
// " msr msp, r0 \n" /* Set the msp back to the start of the stack. */
// " mov r0, #0 \n" /* Clear the bit that indicates the FPU is in use, see comment above. */
// " msr control, r0 \n"
// " cpsie i \n" /* Globally enable interrupts. */
// " cpsie f \n"
// " dsb \n"
// " isb \n"
// " svc 0 \n" /* System call to start first task. */
// " nop \n"
// );
}
this is from freertos code and i ask chat gpt to make me some printfs on it to determine the problem and i commented the original code at the bottom of the funciton and this is what i get  when the external loader is
enabled :
Initial NVIC VTOR Address: 24000200
Initial MSP Value from Vector Table: 00000000
Invalid MSP value, manually setting to a safe address.

and if i disable the external loader the code runs normally and this is what i get from the printfs :
Initial NVIC VTOR Address: 08000000
Initial MSP Value from Vector Table: 24080000
Control Register Set to: 00000000


it seems like that when i enable the external loader it corrupts the stack pointer, and the vector table  even without uploading any code to the external flash ,thanks in advance.

You can't use an RTOS in the External Loader (.STLDR). Really shouldn't be using/needing interrupts.

The Vector Table can't be at 0x24000004, needs to be on a 512-byte alignment for most STM32

Your Boot Loader to bring up the QSPI at 0x90000000 needs to live in the front of Internal Flash at 0x08000000

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

What is your pin configuration? Perhaps a loader here would suit? I'm not using interrupts.

https://github.com/cturvey/stm32extldr/tree/main/h7_w25q128

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

PB2,PC11 PE7,PE8,PE9,PE10
there is one  but it is flm not stldr so it won't  work. 

 

i didn't use rtos in the code used to generate the external loader but i use it in the code that will be running in the external flash can i do that or not ? and when i enable  the external loader  in cube ide like the photo the problem above start to happen  when running the code even though i didn't specifiy any code to be uploded in external flash in linker script  yet and even the all the code sections is running from my stm32 h750 internal flash ,just enabling it dose this problem and i think the initialize option that marked in the photo is the reason because it make the startup code change the address of vector table or something don't know really why is this happening

AhmedSayed_0-1714930628084.png