cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5G strange UART bootloader behavior

logstream76
Associate

Hi all,

I'm using an STM32U5G7VJT6Q on a custom design PCB. From the application, I jump to the USART (UART1) system bootloader. I then try to connect to the bootloader via STM32CubeProgrammerCLI. The jump to the bootloader appears to be correct and the bootloader is starting ( connect and properly read chipID) . Unfortunately, communication with the bootloader shows some errors. Especially with some Flash locations like 0xBFA07A0.

 

RDP is set to AA ( Level 0 - no protection )
TZEN is not set

 

-------------------------------------------------------------------
STM32CubeProgrammer v2.20.0
-------------------------------------------------------------------

Serial Port COM3 is successfully opened.
Port configuration: parity = even, baudrate = 115200, data-bit = 8, stop-bit = 1.0, flow-control = off
No Init bits value is : 0

Sending init command:
#byte 0x7F sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 2
#ack Received response from target: 0x1f
Activating device: OK
Board : --
Sending GetID command and its XOR:
#byte 0x02 sent successfully to target
#byte 0xFD sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 0
#ack Received response from target: 0x79
#ack Received response from target: 0x01047679
Chip ID: 0x476
Sending Get command and its XOR:
#byte 0x00 sent successfully to target
#byte 0xFF sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 4
#ack Received response from target: 0x79
#ack Received response from target: 0x0b
size of bytes in the response: 11
#ack Received response from target: 0x310001021121314463735072de
Full received response: 0b310001021121314463735072de
BootLoader protocol version: 3.1
#byte 0x11 sent successfully to target
#byte 0xEE sent successfully to target
#data sent successfully to target: 0x0800000008
Sending GetID command and its XOR:
#byte 0x02 sent successfully to target
#byte 0xFD sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 2
#ack Received response from target: 0x1f

Response received from device: NACK
Error: GETID command not acknowledged!

Reemission of GetID command
Sending GetID command and its XOR:
#byte 0x02 sent successfully to target
#byte 0xFD sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 3
#ack Received response from target: 0x79
#ack Received response from target: 0x01047679
#byte 0x11 sent successfully to target
#byte 0xEE sent successfully to target
#data sent successfully to target: 0x0800000008
Sending Read command and its XOR:
#byte 0x11 sent successfully to target
#byte 0xEE sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 3
#ack Received response from target: 0x1f

Response received from device: NACK


Error: READ command not acknowledged at address: 0xBFA07A0
Sending Read command and its XOR:
#byte 0x11 sent successfully to target
#byte 0xEE sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 3
#ack Received response from target: 0x79
Sending Read address and its checksum:
#data sent successfully to target: 0x0bfa07a056
Wait ends after 1 loop, dataready = 1, delay = 3
#ack Received response from target: 0x1f

Response received from device: NACK


Error: Address not acknowledged: 0xBFA07A0
Sending Read command and its XOR:
#byte 0x11 sent successfully to target
#byte 0xEE sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 2
#ack Received response from target: 0x79
Sending Read address and its checksum:
#data sent successfully to target: 0x0bfa07a056
Wait ends after 1 loop, dataready = 1, delay = 3
#ack Received response from target: 0x1f

Response received from device: NACK


Error: Address not acknowledged: 0xBFA07A0
Sending Read command and its XOR:
#byte 0x11 sent successfully to target
#byte 0xEE sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 2
#ack Received response from target: 0x79
Sending Read address and its checksum:
#data sent successfully to target: 0x0bfa07a056
Wait ends after 1 loop, dataready = 1, delay = 3
#ack Received response from target: 0x1f

Response received from device: NACK


Error: Address not acknowledged: 0xBFA07A0
Sending Read command and its XOR:
#byte 0x11 sent successfully to target
#byte 0xEE sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 3
#ack Received response from target: 0x79
Sending Read address and its checksum:
#data sent successfully to target: 0x4002204022
Wait ends after 1 loop, dataready = 0, delay = 30003
Timeout error occured while waiting for acknowledgement.
No response from target received


Error: Address not acknowledged: 0x40022040
Sending Read command and its XOR:
#byte 0x11 sent successfully to target
#byte 0xEE sent successfully to target
Wait ends after 1 loop, dataready = 1, delay = 2
#ack Received response from target: 0x1f

Response received from device: NACK


Error: READ command not acknowledged at address: 0x40022040
Database: Config 9 is active.
#byte 0x11 sent successfully to target
#byte 0xEE sent successfully to target
getDeviceInfo Failed

UART PORT CLOSE

 

I don't understand what could be the cause of such errors because it seems that the bootloader is working and that initially the communication with STM32CubeProgrammer is working correctly.

I previously checked communication on this USART1 port from the application level and everything was OK.

 

Jump to bootloader  code:

void jumpToBootloader_2() {
 void (*SysMemBootJump)(void);
 volatile uint32_t addr = 0x0BF90000;

 /* Disable all interrupts */
 __disable_irq();

 /* Disable Systick timer */
 SysTick->CTRL = 0;

 /* Set the clock to the default state */
 HAL_RCC_DeInit();

 /* Clear Interrupt Enable Register & Interrupt Pending Register */
 for (uint8_t i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) {
  NVIC->ICER[i] = 0xFFFFFFFF;
  NVIC->ICPR[i] = 0xFFFFFFFF;
 }

 /* Re-enable all interrupts */
 __enable_irq();


 SysMemBootJump = (void (*)(void)) (*((uint32_t*)(addr + 4)));
 __set_MSP(*(uint32_t*)addr);
 SysMemBootJump();
}

 

1 REPLY 1
gbm
Principal

Check the operation with boot mode forced by BOOT0 pin. If it's correct, then there is a problem with your code.

If you invoke the built-in bootloader from the application, it should be invoked with clean, initial MCU configuration, including the default clack settings and caches being disabled. The safest and easiest way of acieving this is to go through reset with some magic value stored in non-volatile registers (backup RAM, RTC). The decision to call the bootloader should be taken before clock and HAL initialization.

Search for other threads on bootloaders in this forum - you will find some interesting details.

One of such threads:

https://community.st.com/t5/stm32-mcus/how-to-jump-to-system-bootloader-from-application-code-on-stm32/ta-p/49424

Another item to check is the disassembly of the code used for setting the MSP and invoking the bootloader (project's .list file). With optimization level < 2, the code may incorrectly use the already-reloaded MSP for calling the application.

 

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice