cancel
Showing results for 
Search instead for 
Did you mean: 

Bootloader and distance reprogramming

Steven Bébin
Associate III

Hello,

I program on the NUCLEO-144 STM32F767ZI board and I have been facing a problem for over a week.

In FLASH memory, I have 3 programs located at specific addresses:

- A bootloader which allows to start on the main programmer or reprogramming program.

- A main program that has several functions like http server, tcp server, usart ...

- A reprogramming program that distance reprograms the stm32 card. The operation is basic, I send a binary file to an http server, then I put at the place of the main program.

When I reprogram with a basic program (for example: to light an LED) everything works. on the other side when I reprogram with a big program (for example: my actual main program) it does not work. The stm32 seems to hang somewhere and I do not know where. I have already tried to remove all the interruptions before jump, it does not change anything.

On the front line of all my programs, I have the "SCB-> VTOR" which points to current address.

Here my bootloader code :

#include "stm32f7xx_hal.h"
 
	#define REPROGRAMMATION_ADDRESS  0x08020000
 
	#define FLASH_MEM1_FIRST_ADDRESS	  0x08040000
 
	void JumpInProgram(uint32_t address);
	
	typedef  void (*pFunction)(void);
 
	pFunction Jump_To_Application;
 
int main(void) 
{
	SCB->VTOR = 0x8000000;
	if((*(uint32_t*)0x80C0000 == 1) JumpInProgram(REPROGRAMMATION_ADDRESS); // if variable locaded "0x80C0000" is equal to 1 go to reprogrammation program
	else JumpInProgram(FLASH_MEM1_FIRST_ADDRESS); // else principal program
}
 
void JumpInProgram(uint32_t address) 
{
	uint32_t JumpAddress = *(__IO uint32_t*)(address + 4);
	pFunction Jump = (pFunction)JumpAddress;
	__set_MSP(*(__IO uint32_t*)address);
	Jump();
}

Here my main fonction in principal program for example :

int main(void)
{
	SCB->VTOR = 0x8040000;
  HAL_Init(); 
  SystemClock_Config();
	
	MX_GPIO_Init();
	
	MX_TIM4_Init();
	
  MX_USART1_UART_Init();
	MX_USART2_UART_Init();
	MX_USART3_UART_Init();	
	
	HAL_TIM_Base_Start_IT(&htim4);
	HAL_UART_Receive_IT(&huart3, donneetic, 1); 
	HAL_UART_Receive_IT(&huart1, donneerf, 1); 
	
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, configMINIMAL_STACK_SIZE); 
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
	
  osKernelStart(); 
}

Hoping you can help me, thank you

16 REPLIES 16

Hello, thank you for your answer !

My reprogramming program is quite large, it manages an LCD, a webserver, threads .. It's quite large that's why I really wanted to insist on having a bootloader and 2 separate programs.

What you told me is very interesting. I had never thought about it. I may not be including it in the program at the moment as this will not solve the problem, but I would see it in the future. Thank you

Hello, thank you for your answer !

I do not know if "Linker" means the start address of the app, but if it does, I'm good. What I do not understand is that normally with a wrong starting address, no matter the application it would not work. So I must be wrong.

I use Keil as programming software. To change the starting address of the application, I modify the position of IROM1 and the size.

0690X000009YwYtQAK.png0690X000009YwYoQAK.png

In any case what you tell me is interesting, I may be a small mistake from the beginning. Thank you

The GUI settings build you a scatter file (linker script) doing what you need.

The Size here is a total, not an end point, so 0xC0000 is more appropriate than 0xBFFFF

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

Hello everyone,

Well I advance on the problem, but I'm pretty lost. I manage to run the program download by TCP IAP. The problem is therefore "solved". However, for this to work, I have a need to boot the zone.

Let me explain, when I transmit my program under TCP IAP, it is transferred to sectors 8, 9 and 10. When I restart, it does not work.

However, when I transmit the program with the software (classic transfer), then I delete sectors 8, 9 and 10 and after I transmit my program by TCP IPA, it works!

It's very weird, I'm lost but I will continue to find the problem. Help is welcome, thank you very much.

I specify that with a normal download with the KEIL software, the same program is totally working!

Steven Bébin
Associate III

When I send program by TCP IAP. The program starts.

I have an LCD screen with several menus. I can move in the menus, but as soon as I go in some menu, the card block.

At one point, going into a menu, I saw another menu appear, it was not the right one. So I think sometimes, instead of going to the right address of flash memory, it goes to another. I can not explain why or how. But it seems to happen.

What's odd is that I configure the SCB-VTOR well at the beginning of the program. And the program works until a moment when we come to a bug.

Steven Bébin
Associate III

My problem is the same as the one at the beginning. When I start the download of the program by TCP IAP, the program starts and at some point, the address is totally incorrect ==> HardFault. I do not know what I'm doing wrong, but I'm starting to lose hope.

Steven Bébin
Associate III

I finally found the problem! The program I download with IAP seems corrupted, on 240,000 bytes, approximately 10 bytes are wrong. I do not know why, I will check the IAP TCP program