cancel
Showing results for 
Search instead for 
Did you mean: 

How to select Key I/O for In-application program(IAP) through UART for STM32F407VGT6TR?

JieShen_Jason
Associate

Hi,

I would like to in-live upgrade firmware of STM32F407 through USART1, that means  in-application program(IAP) . If I remember right, there need a trigger signal from key meanwhile NRST is low.

My question is that the Key signal could be connected to any GPIO I/O of STM32F407 except those dedicated pin, right?  Is there special point to care about selection of  Key I/O pin?

 

Thanks in advance!

Best regards!

Jason

1 ACCEPTED SOLUTION

Accepted Solutions
mƎALLEm
ST Employee

Hello,

IAP is more related to the application note: AN4657 "STM32 in-application programming (IAP) using the USART" and the X Cube package: X-CUBE-IAP-USART.

So in the firmware check what was implemented for that "Key" and find how it could be changed.

mALLEm_0-1757414983906.png

Edit (After downloading the package and checked the code):

This is the code of the button (Tamper pin is used here) initialization in \IAP_Main\Src\main.c:

  /* Initialize Key Button mounted on STM32L476G-EVAL board */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);

  /* Test if Key push-button on STM32L476G-EVAL Board is pressed */
  if (BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET)
  { 
  	/* Initialise Flash */
  	FLASH_If_Init();
  	/* Execute the IAP driver in order to reprogram the Flash */
    IAP_Init();
    /* Display main menu */
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */
    if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
    {
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
      JumpToApplication = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
      JumpToApplication();
    }
  }

This confirms my saying: You don't have to keep the key pressed during the programming. Just ensure the key is pressed for a moment after Reset then release it.

You can modify the code to use any other available pin.

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.

View solution in original post

11 REPLIES 11
Andrew Neil
Super User

@JieShen_Jason wrote:

If I remember right, there need a trigger signal from key meanwhile NRST is low.


That depends on what IAP method you're using.

If you're using the built-in ROM bootloader, that requires a reset & specific BOOT settings - see the datasheet for details.

See also Application note AN2606Introduction to system memory boot mode on STM32 MCUs

 

If you're using some other method (some other bootloader), its requirements will differ - see the documentation for whatever you're using.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
mƎALLEm
ST Employee

Hello,

IAP is more related to the application note: AN4657 "STM32 in-application programming (IAP) using the USART" and the X Cube package: X-CUBE-IAP-USART.

So in the firmware check what was implemented for that "Key" and find how it could be changed.

mALLEm_0-1757414983906.png

Edit (After downloading the package and checked the code):

This is the code of the button (Tamper pin is used here) initialization in \IAP_Main\Src\main.c:

  /* Initialize Key Button mounted on STM32L476G-EVAL board */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);

  /* Test if Key push-button on STM32L476G-EVAL Board is pressed */
  if (BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET)
  { 
  	/* Initialise Flash */
  	FLASH_If_Init();
  	/* Execute the IAP driver in order to reprogram the Flash */
    IAP_Init();
    /* Display main menu */
    Main_Menu ();
  }
  /* Keep the user application running */
  else
  {
    /* Test if user code is programmed starting from address "APPLICATION_ADDRESS" */
    if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
    {
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
      JumpToApplication = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
      JumpToApplication();
    }
  }

This confirms my saying: You don't have to keep the key pressed during the programming. Just ensure the key is pressed for a moment after Reset then release it.

You can modify the code to use any other available pin.

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.

Hi,

Thank for your response in the time!

I checked AN4657, and want to know if push-button must be pressed all the time until user application have been download to flash memory, or just pressed then release which generate time-limited negative pulse?

JieShen_Jason_0-1757424704103.png

Thanks in advance!

Best regards!

Jason

It seems highly unlikely that the user would have to keep the button pressed for the entire time - that would be a nightmare UX!

But the source code is available - take a look!

Or build it and try it out.

You can modify it as required ...

 

PS:

Look at the flowchart @mƎALLEm shared:

AndrewNeil_0-1757427182129.png

The switch is only used to decide whether to 'Jump to user program' or to 'Initialise IAP'.

Once that decision has been made, the key can be released.

Again, the code presented is just an example - you can do whatever suits in your own implementation...

AndrewNeil_1-1757427383840.png

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

I can't download the package for now to check but based on the organigram shared above from the AN4657, the button state is sampled at the beginning of the IAP application and then no matter its state after. So I think no need to keep that button pressed during the application upload.

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.

Hi,

Get it!

Thanks a lot!

 

Best regards!

Jason

 

 

 

you're welcome.

If your question is now answered, please mark the solution.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
JieShen_Jason
Associate

Hi,

Thanks again!

So, the pin for key could be  any GPIO I/O of STM32F407 only if the input of this pin is judged in below switch ,right?

JieShen_Jason_1-1757467949179.png

 

Suddenly I notice that reset must occur at the same time with the Key signal, so the reset brought by NRST pin also is not kept pressed all the time, right?

JieShen_Jason_0-1757467411037.png

 

Many thanks to you!

Best regards!

Jason

 

You're causing a Reset, so a brief press of the reset button, then in the Reset_Handler path you're checking a GPIO state to decide what code to execute. Any available GPIO that's free will suit. Avoid debug pins.

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