cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 M7 to Update M4 flash area

urbito
Senior

Hello community!

 

I am developing an app that is running in an H7 MCU, the M7 core app is "turning on" the M4 and then is running to an external flash where is the actual M7 code.

I am looking to implement an update in this M7 "bootloader". As i understand, before "turning on" the M4, i can interact with the flash region where the M4 has its code to run, so my idea is in the M7 bootloader to start an USB port to detect an USB disk and if there is a .bin file for each core, to write the M7 in the external ram (using a code similar to the developed external loader for example?) and for the M4, just a write in the M4 memory location?

 

I look forward for your commends dear community :)

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
urbito
Senior

I have been able to write into the QSPI successfully but seems like i am writting wrong to the internal flash, the CM4 part. 

 

For somereason, my guess on the CM4 booting is kind wrong, because the led is turning ON but, when i am trying to connect to the CM4 in debugmode, as i am doing with the CM7 (without downloading new code, only connecting) i am being not able to connect and the stlink drops the connection.

 

Edit 1: Also, when having a look on memory through CubeProgrammer, the QSPI in both cases, through code(this usb code programmer) and through STLink/CubeIDE is the same. But when programming the CM4 area through this usb programmer or STLink/CubeIDE, is not the same.

 

Edit2: I have found a mistake in the original code, the "i" definition was an uint8_t and it has to be an uint32_t and then i had to "restart" the pointer after each write.

 

Edit3: I found also that i was increasing wrong the buffer_address. According to the DFU_StandAlone example, both the address and the buffer_address must be incremented by 32.

View solution in original post

7 REPLIES 7
FBL
ST Employee

For the USB part, you can use STM32CubeProgrammer to use DFU bootloader on dual core. You can download either CM7 program or CM4 program binaries with this manipulation. Check AN3156 for USB DFU protocol used in the STM32 bootloader

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!

Hello FBL, thanks for your quick reply, you mean, to connect an STLink and then use the STM32CubeProgrammer to do this part?

If so, is not my "goal" since i want to "dodge" the use of STLink. I want to directly take the .bin from the USB when the mcu turn on, if it detects the USB stick ofcourse. This because there would not have access to the PCB to connect the stlink but there is a USB port that i am using to export/import data and i want to use it also for this update. Not really looking  to "validate" or something kind of sophisticated, only to do something very rudimentary as a prove of concept.

Hope my words make sense. Thanks again for your commends. Look forward to hear from you soon :)

EDIT: I am having a look on an example form STM32CubeIDE for your suggestion! 

Elatewendy
Associate III

Hello,

I'm not sure where your difficulties lie? BootLoader only implements CODE writing and jumping. You can identify different .bin files and write them to the corresponding addresses. How to jump, you should also set the judgment criteria to jump to the corresponding APP address.

 

BW

Hello BW,

 

I was having a look on the DFU and my words were due to @FBL mention of STM32CubeProgrammer.

 

Now that i have seen that the DFU example shows part of what i need, i would try to adapt and give it a shoot. 

 

Greetings

TDK
Guru

> I am looking to implement an update in this M7 "bootloader". As i understand, before "turning on" the M4, i can interact with the flash region where the M4 has its code to run, so my idea is in the M7 bootloader to start an USB port to detect an USB disk and if there is a .bin file for each core, to write the M7 in the external ram (using a code similar to the developed external loader for example?) and for the M4, just a write in the M4 memory location?

Your assumptions here are correct. There are no issues with this approach. It can work. Good luck.

If you feel a post has answered your question, please click "Accept as Solution".

Hello,

I have been able to develop the idea, and i am being able to write to the flash area. When i start the M4 mcu, i see it works since some leds that i have are turning on, but i have an OPENAMP communication that is not starting until i rewrite the same code through STCubeIDE/Programmer.

 

I have also tryed erasing the full chip memory, to see if i was for sure programming the flash (by watching the led turning ON).

 

In my code i am doing something like:

 

HAL_FLASH_Unlock();

FLASH_EraseInitStruct.TypeErase     = FLASH_TYPEERASE_MASSERASE;
FLASH_EraseInitStruct.VoltageRange  = FLASH_VOLTAGE_RANGE_4;
FLASH_EraseInitStruct.Banks         = FLASH_BANK_2;

if(HAL_FLASHEx_Erase(&FLASH_EraseInitStruct, &SectorError) != HAL_OK)
return (1);

uint8_t readflag = TRUE;
uint16_t bytesread;

uint8_t RAM_Buf[BUFFER_SIZE] = { 0x00 };
uint32_t *buffer_adrress = (uint32_t *)RAM_Buf;
uint32_t Address = CM4_APPLICATION_STARTADDRESS;

while (readflag == TRUE)
{
   f_read(&usb_CM4_file, RAM_Buf, BUFFER_SIZE, (void *)&bytesread);
   TmpReadSize = bytesread;

   if (TmpReadSize < BUFFER_SIZE)
   {
       readflag = FALSE;
   }

   uint8_t i = (TmpReadSize/32)+1;

   while(i>0)
   {
         if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, Address, (uint32_t)buffer_adrress) == HAL_OK)
	{
             Address = Address + 32;
	     buffer_adrress = buffer_adrress + 8;
	     i--;
	}else
	{
	     usb_error_retry();
	}
   }
}

 

I have been based my implementation on the USB MSC DFU to do the read from the USB and also from FLASH_CoreConfiguration example for the flash program erase/program part.

 

Hope someone may suggest what can be going wrong. 

 

Thanks a lot

urbito
Senior

I have been able to write into the QSPI successfully but seems like i am writting wrong to the internal flash, the CM4 part. 

 

For somereason, my guess on the CM4 booting is kind wrong, because the led is turning ON but, when i am trying to connect to the CM4 in debugmode, as i am doing with the CM7 (without downloading new code, only connecting) i am being not able to connect and the stlink drops the connection.

 

Edit 1: Also, when having a look on memory through CubeProgrammer, the QSPI in both cases, through code(this usb code programmer) and through STLink/CubeIDE is the same. But when programming the CM4 area through this usb programmer or STLink/CubeIDE, is not the same.

 

Edit2: I have found a mistake in the original code, the "i" definition was an uint8_t and it has to be an uint32_t and then i had to "restart" the pointer after each write.

 

Edit3: I found also that i was increasing wrong the buffer_address. According to the DFU_StandAlone example, both the address and the buffer_address must be incremented by 32.