2025-02-05 05:25 AM
Hi, I'm trying to do an external loader according ST's MOOC and this forum https://community.st.com/t5/stm32-mcus-products/stm32h5-external-loader/td-p/601134.
My code pass on all ST's tests of memory, but when I generate a stldr it does not read on cubeprog.
I attached my project and log of cubeprog.
I already do the same with a G474 without problems.
BR
2025-02-05 09:01 AM - edited 2025-02-05 02:42 PM
The log implies Init() failed, so might want to instrument that
I'd expect Write() needs to leave with memory mapping, depends what STM32 Cube Programmers expectations are to be able to read the memory directly, as NOR_FLASH does not use Read() function.
/**
* @brief Program memory.
* Address: page address
* Size : size of data
* buffer : pointer to data buffer
* @retval LOADER_OK = 1 : Operation succeeded
* @retval LOADER_FAIL = 0 : Operation failed
*/
int Write(uint32_t Address, uint32_t Size, uint8_t* buffer) {
__set_PRIMASK(0); //enable interrupts
// Abort out of memory mapped
if (HAL_XSPI_GetState(&hospi1) != HAL_XSPI_STATE_READY) {
if (HAL_XSPI_Abort(&hospi1) != HAL_OK) {
//console(consoleDefault,"WRITE abort err\r\n");
__set_PRIMASK(1); //disable interrupts
return LOADER_FAIL;
}
}
if (CSP_QSPI_WriteMemory((uint8_t*) buffer, (Address & (0x0fffffff)), Size) != HAL_OK) {
__set_PRIMASK(1); //disable interrupts
return LOADER_FAIL;
}
#if 1 // re-enable memory mapped
if (CSP_QSPI_EnableMemoryMappedMode() != HAL_OK) {
__set_PRIMASK(1); //disable interrupts
return LOADER_FAIL;
}
#endif
__set_PRIMASK(1); //disable interrupts
return LOADER_OK;
}
STM32H523 / WINBOND W25Q64
PB2:AF9 CLK
PA15:AF9 NCS
PB1:AF6 IO0
PB0:AF6 IO1
PA7:AF10 IO2
PA6:AF6 IO3
DEV_ID[11:0]: Device identification
0x484: STM32H562/563/573
0x478: STM32H523/533
2025-02-05 02:11 PM
I wrote LED_ON in all points of Init, but LED is not turning on, like stldr not calling Init()
int Init(void) {
*(uint32_t*)0xE000EDF0 = 0xA05F0000; //enable interrupts in debug
SystemInit();
/* ADAPTATION TO THE DEVICE
*
* change VTOR setting for H7 device
* SCB->VTOR = 0x24000000 | 0x200;
*
* change VTOR setting for H5 devices
* SCB->VTOR = 0x20003000 | 0x200;
*
* change VTOR setting for other devices
* SCB->VTOR = 0x20000000 | 0x200;
*
* */
SCB->VTOR = 0x20003000 | 0x200;
__set_PRIMASK(0); //enable interrupts
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
LED_ON();
__HAL_RCC_OSPI1_FORCE_RESET(); //completely reset peripheral
__HAL_RCC_OSPI1_RELEASE_RESET();
if (CSP_QUADSPI_Init() != HAL_OK) {
__set_PRIMASK(1); //disable interrupts
LED_ON();
return LOADER_FAIL;
}
if (CSP_QSPI_EnableMemoryMappedMode() != HAL_OK) {
__set_PRIMASK(1); //disable interrupts
LED_ON();
return LOADER_FAIL;
}
LED_ON();
__set_PRIMASK(1); //disable interrupts
LED_ON();
return LOADER_OK;
}
2025-02-05 07:14 PM
Tentative for the H523, different AF for them vs earlier H56x
2025-02-06 04:40 AM
Hi Clive,
It worked very well, amazing! Why your stldr's have a very small size?
I will continuing try to make my code works :)
2025-02-06 08:40 AM
>>Why your stldr's have a very small size?
Well I'm using GNU/GCC w/MAKE, keeping a relatively small HAL foot-print, not interrupts/callbacks, and I built a tool to remove a lot of clutter from the .ELF object file
>>I will continuing try to make my code works :)
I think it calls Init(), you need to watch that no static initialization is done, so Reset_Handler / main() are not executed. Perhaps it gets stuck in a loop or Error_Handler(), but doesn't time out. For debugging / diagnostics I tend to use one of the available UART's
2025-02-06 10:10 AM
Is It possible to use SWV instead UART? My board is prepared with SWO, but I can do some modifications to take uart.
2025-02-18 05:43 AM
UPDATE:
I toke a USART3 to debug instead SWV. I'coded at Init function this:
SCB->VTOR = 0x20003000 | 0x200;
__set_PRIMASK(0); //enable interrupts
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART3_UART_Init();
uint8_t TxBuffer[] = "Ola\n";
HAL_UART_Transmit(&huart3, TxBuffer, strlen((char*)TxBuffer), 100U);
but It does not print anything