Skip to main content
Associate III
May 6, 2026
Solved

is there any X-cube-SBSFU examples that are compatible with STM32-H755 series

  • May 6, 2026
  • 4 replies
  • 465 views

this thread is split from this thread 
hello

Last question, I just saw the example but it's not for the STM32H755ZI-Q series, are the examples still compatible with this STM32H755 series? Thanks

Best answer by Onizuka09

hello @Domy_ST 
After setting PCROP for your desired memory area and ensuring both DMEP bits are cleared, the software in that area will continue to execute for the user during and after RDP regression. Only instruction fetches are allowed; all other access types are blocked, maintaining the security of your proprietary code.
the workflow to configure PCROP region: 

  1. Define a dedicated executable section in the linker script.
  2. Place the code you want to protect into that section.
  3. Compile with the required flag: -mslow-flash-data
  4. Program the firmware.
  5. Activate the PCROP region using the flash protection configuration (STM32CubeProgrammer).
  6. make sure the DMEP bit is configured to 0 (unchecked)

PCROP Activation Rules

  • If START > END, PCROP is deactivated
  • If START < END, PCROP is activated

I would sugget to you to take a look at these references: 

  • Security Part 3: STM32 security features MOOC: link
  • ST provides an expansion package for PCROP (X-CUBE_PCROP): link


B.R

4 replies

ST Employee
May 6, 2026

Hello @Domy_ST , 

You need to port the project to match the device hardware requirements. Compatibility also depends on the security features supported by the device.

Unfortunately, in SBSFU there is no template project that supports dual-core capability on the H7 out of the box.

I suggest you start with the NUCLEO-H753ZI project and adapt it from there.

If you will be working with SBSFU Legacy, I suggest you take a look at these resources:

  • UM2262 Getting started with the X-CUBE-SBSFU STM32Cube Expansion Package : link
  • AN5056 How to integrate the X-CUBE-SBSFU STM32Cube Expansion Package : link
  • Security Part 6: STM32 security ecosystem, from theory to practice MOOC : link

This is for further reading, to get you familiar with stm32 security features: 

  • AN5156 Introduction to security for STM32 MCUs: Link

Thank you

ST Employee
May 12, 2026

Hello @Domy_ST

Actually, there is an ST project that supports SBSFU on the NUCLEO-H755 with a demo application. However, it is somewhat old, and the last update was on 22-Dec-2021. You may need to port the changes yourself.

You can find it in the x-cube-aws version2.2.1: link

Onizuka09_0-1778577299645.png

Onizuka09_1-1778577538220.png

sorry for the confusion. 
Best regards, 

 

Domy_STAuthor
Associate III
May 12, 2026

Hello @Onizuka09,

Thanks for the helpful support. I've recently been working on integrating SBSFU into my project and testing whether it works as I wanted, protecting flash memory from reading/writing without mass erasing.

I'll also check out this link as suggested.

Thanks

ST Employee
May 14, 2026

Hello @Domy_ST , 

Try to run that prepareimage.exe from the Powershell windows terminal and see if that issue persists. 

 First some modification to the postbuild.sh script needs to be made, locate the file  

BootLoader_OSC\2_Images_SECoreBin\STM32CubeIDE\postbuild.sh

go to the bottom of the file and comment these lines

if [ $ret -eq 0 ]; then
 rm $sign
 rm $sfu
 rm $headerbin
 if [ -e "$ref_userapp" ]; then
 rm $partialbin
 rm $partialsfu
 rm $partialsign
 rm $partialoffset
 fi 
 exit 0
else 
 echo "$command : failed" >> $projectdir"/output.txt"
 # comment start here 
 # if [ -e "$elf" ]; then
 # # rm $elf
 # fi
 # if [ -e "$elfbackup" ]; then 
 # # rm $elfbackup
 # fi
 # comment ends here
 echo $command : failed
 read -n 1 -s
 exit 1
fi

 and rebuild the aws_tests  project 

Now open Powershell terminal and follow these steps 
1- open Powershell and then, change this {YOUR BASE BATH} with your base path

cd {YOUR BASE BATH}\x-cube-aws\STM32CubeExpansion_Cloud_AWS_V2.2.1\Projects\NUCLEO-H755ZI\Applications\Cloud\aws_tests\STM32CubeIDE\Debug_CM7

2- then export the path of the executable  prepareimage.exe, 

$env:PATH +=";{YOUR BASE BATH}\x-cube-aws\STM32CubeExpansion_Cloud_AWS_V2.2.1\Middlewares\ST\STM32_Secure_Engine\Utilities\KeysAndImages\win\prepareimage"

3- run the command 

prepareimage.exe enc -k ../../../../BootLoader_OSC/2_Images_SECoreBin/STM32CubeIDE/../Binary/OEM_KEY_COMPANY1_key_AES_CBC.bin -i ../../../../BootLoader_OSC/2_Images_SECoreBin/STM32CubeIDE/../Binary/iv.bin ./NUCLEO-H755ZI_aws_tests_CM7.bin ../PostBuild/NUCLEO-H755ZI_aws_tests_CM7.sfu

 

Domy_STAuthor
Associate III
May 14, 2026

Hello @Onizuka09,

I followed the steps as you suggested. Now it compiles without errors. Your support was very helpful and sensible. Thank you very much.

I've done a thorough study of SBSFU as described in this package. It's very useful for writing data to flash memory from a binary file with an encryption key, just to ensure a certain level of security against data tampering. For me, it works well for my purpose at a certain point after bootloading with SBSFU and setting RDP = 1. What I don't like is that after the regression from RDP = 1 to RDP = 0, the entire flash memory is erased, and this is the point that wouldn't work for my purpose, which must never erase the area from 0x08000000 to 0x08020000 (where the first software is located), and the rest of flash memory bank1 (where the second software is located) can also be erased. This is the disadvantage for me.

After various developments, there's no way to avoid deleting just the area from 0x08000000 to 0x08020000 during the regression from RDP = 1 to RDP = 0, not even the PCROP option.

I'm confident you have more experience than I. Is there any way to avoid deleting just that memory area during the RDP regression from 1 to 0?

ST Employee
May 14, 2026

hello @Domy_ST , 

It is possible to avoid erasing a specific flash memory area (such as 0x08000000 to 0x08020000) during RDP regression from level 1 to level 0 on STM32 devices, but only under certain conditions. You must:

  • Configure the PCROP (Proprietary Code ReadOut Protection) area to cover your desired region.
  • Ensure that the corresponding DMEP bits are both cleared to 0 in the FLASH_PRAR_CUR and FLASH_PRAR_PRG registers.
    • DMEP = 1  (checked) the PCROP region is erased when an RDP regression is performed. 
    • DMEP = 0 (unchecked) the PCROP region is kept when RDP regression is performed. 

If both DMEP bits are set to 0, the PCROP area content is preserved during RDP regression. If either is set to 1, the area will be erased.
B.R

ST Employee
May 21, 2026

hello @Domy_ST 

can you provide the bootloader code ?  

B.R

Domy_STAuthor
Associate III
May 21, 2026

Hi @Onizuka09,

Here's the main Bootloader software:

Note: In the while loop, I've commented out the functions that allow you to run the bootloader, but it simply needs to print that string of characters.

 

/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file : main.c
 * @brief : Main program body
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2026 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "common.h"
#include "flash.h"
#include "ymodem.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
typedef void (*pFunction)(void);
#define APPLICATION_ADDRESS 0x08020000
/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* DUAL_CORE_BOOT_SYNC_SEQUENCE: Define for dual core boot synchronization */
/* demonstration code based on hardware semaphore */
/* This define is present in both CM7/CM4 projects */
/* To comment when developping/debugging on a single core */
#define DUAL_CORE_BOOT_SYNC_SEQUENCE

#if defined(DUAL_CORE_BOOT_SYNC_SEQUENCE)
#ifndef HSEM_ID_0
#define HSEM_ID_0 (0U) /* HW semaphore 0*/
#endif
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
#define UART_BOOT_FLAG 0xDEADBEEF
uint8_t aFileName[FILE_NAME_LENGTH];
void SerialDownload(void);
/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

CRC_HandleTypeDef hcrc;

UART_HandleTypeDef huart3;

/* USER CODE BEGIN PV */
extern int _bflag;
uint32_t *uart_boot_flag;
pFunction JumpToApplication;
uint32_t JumpAddress;
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_CRC_Init(void);
static void MX_USART3_UART_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
 * @brief The application entry point.
 * @retval int
 */
int main(void)
{

 /* USER CODE BEGIN 1 */
	uart_boot_flag = (uint32_t*) (&_bflag); // set in linker script
	if(*uart_boot_flag == UART_BOOT_FLAG) {
		/* Jump To user Application */
		JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
		JumpToApplication = (pFunction) JumpAddress;

		/* Initialize user application's to stack pointer */
		__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
		JumpToApplication();
	}
	*uart_boot_flag = 0; //so next boot won't be affected
 /* USER CODE END 1 */
/* USER CODE BEGIN Boot_Mode_Sequence_0 */
#if defined(DUAL_CORE_BOOT_SYNC_SEQUENCE)
 int32_t timeout;
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
/* USER CODE END Boot_Mode_Sequence_0 */

/* USER CODE BEGIN Boot_Mode_Sequence_1 */
#if defined(DUAL_CORE_BOOT_SYNC_SEQUENCE)
 /* Wait until CPU2 boots and enters in stop mode or timeout*/
 timeout = 0xFFFF;
 while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0));
 if ( timeout < 0 )
 {
 Error_Handler();
 }
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
/* USER CODE END Boot_Mode_Sequence_1 */
 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */
 SystemClock_Config();
/* USER CODE BEGIN Boot_Mode_Sequence_2 */
#if defined(DUAL_CORE_BOOT_SYNC_SEQUENCE)
/* When system initialization is finished, Cortex-M7 will release Cortex-M4 by means of
HSEM notification */
/*HW semaphore Clock enable*/
__HAL_RCC_HSEM_CLK_ENABLE();
/*Take HSEM */
HAL_HSEM_FastTake(HSEM_ID_0);
/*Release HSEM in order to notify the CPU2(CM4)*/
HAL_HSEM_Release(HSEM_ID_0,0);
/* wait until CPU2 wakes up from stop mode */
timeout = 0xFFFF;
while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) == RESET) && (timeout-- > 0));
if ( timeout < 0 )
{
Error_Handler();
}
#endif /* DUAL_CORE_BOOT_SYNC_SEQUENCE */
/* USER CODE END Boot_Mode_Sequence_2 */

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_CRC_Init();
 MX_USART3_UART_Init();
 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Initialize leds */
 BSP_LED_Init(LED_GREEN);
 BSP_LED_Init(LED_YELLOW);
 BSP_LED_Init(LED_RED);

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
	Serial_PutString((uint8_t *)"\r\n======================================================================");
	Serial_PutString((uint8_t *)"\r\n= =");
	Serial_PutString((uint8_t *)"\r\n= UART Bootloader =");
	Serial_PutString((uint8_t *)"\r\n= =");
	Serial_PutString((uint8_t *)"\r\n======================================================================");
	Serial_PutString((uint8_t *)"\r\n\r\n");
 while (1)
 {
	 BSP_LED_Toggle(LED_YELLOW);
	Serial_PutString((uint8_t *)"==========================================================\r\n\n");
	Serial_PutString((uint8_t *)" Download Application SW to the internal Flash --------\r\n\n");
	Serial_PutString((uint8_t *)"==========================================================\r\n\n");
	/* Clean the input path */
	HAL_Delay(2000);
//	__HAL_UART_FLUSH_DRREGISTER(&huart3);
//
//	FLASH_RDP_Level0();
//	FLASH_Init();
// SerialDownload();	
//	Serial_PutString((uint8_t *)"\r\n......Start SW Application......\r\n\n");
//	FLASH_RDP_Level1();
//	flash_jump_to_app();
 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}

/**
 * @brief System Clock Configuration
 * @retval None
 */
void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Supply configuration update enable
 */
 HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY);

 /** Configure the main internal regulator output voltage
 */
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);

 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}

 /** Initializes the RCC Oscillators according to the specified parameters
 * in the RCC_OscInitTypeDef structure.
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
 RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
 RCC_OscInitStruct.PLL.PLLM = 4;
 RCC_OscInitStruct.PLL.PLLN = 12;
 RCC_OscInitStruct.PLL.PLLP = 2;
 RCC_OscInitStruct.PLL.PLLQ = 5;
 RCC_OscInitStruct.PLL.PLLR = 2;
 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
 RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
 RCC_OscInitStruct.PLL.PLLFRACN = 0;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }

 /** Initializes the CPU, AHB and APB buses clocks
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
 {
 Error_Handler();
 }
}

/**
 * @brief CRC Initialization Function
 * @param None
 * @retval None
 */
static void MX_CRC_Init(void)
{

 /* USER CODE BEGIN CRC_Init 0 */

 /* USER CODE END CRC_Init 0 */

 /* USER CODE BEGIN CRC_Init 1 */

 /* USER CODE END CRC_Init 1 */

 /* USER CODE BEGIN CRC_Init 2 */
 __HAL_RCC_CRC_CLK_ENABLE();

 	hcrc.Instance = CRC;
 	/* The CRC-16-CCIT polynomial is used */
 	hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_DISABLE;
 	hcrc.Init.GeneratingPolynomial = 0x1021;
 	hcrc.Init.CRCLength = CRC_POLYLENGTH_16B;

 	/* The zero init value is used */
 	hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_DISABLE;
 	hcrc.Init.InitValue = 0;

 	/* The input data are not inverted */
 	hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;

 	/* The output data are not inverted */
 	hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;

 	/* The input data are 32-bit long words */
 	hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;

 	if (HAL_CRC_Init(&hcrc) != HAL_OK)
 	{
 	 /* Initialization Error */
 	 while (1)
 	 {}
 	}
 /* USER CODE END CRC_Init 2 */

}

/**
 * @brief USART3 Initialization Function
 * @param None
 * @retval None
 */
static void MX_USART3_UART_Init(void)
{

 /* USER CODE BEGIN USART3_Init 0 */

 /* USER CODE END USART3_Init 0 */

 /* USER CODE BEGIN USART3_Init 1 */

 /* USER CODE END USART3_Init 1 */
// huart3.Instance = USART3;
// huart3.Init.BaudRate = 115200;
// huart3.Init.WordLength = UART_WORDLENGTH_8B;
// huart3.Init.StopBits = UART_STOPBITS_1;
// huart3.Init.Parity = UART_PARITY_NONE;
// huart3.Init.Mode = UART_MODE_TX_RX;
// huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
// huart3.Init.OverSampling = UART_OVERSAMPLING_16;
// huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
// huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1;
// huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
// if (HAL_UART_Init(&huart3) != HAL_OK)
// {
// Error_Handler();
// }
// if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
// {
// Error_Handler();
// }
// if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
// {
// Error_Handler();
// }
// if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK)
// {
// Error_Handler();
// }
 /* USER CODE BEGIN USART3_Init 2 */
	huart3.Instance = USART3;
	huart3.Init.BaudRate = 115200;
	huart3.Init.WordLength = UART_WORDLENGTH_8B;
	huart3.Init.StopBits = UART_STOPBITS_1;
	huart3.Init.Parity = UART_PARITY_NONE;
	huart3.Init.Mode = UART_MODE_RX | UART_MODE_TX;//UART_MODE_TX_RX;
	huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
	huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT;//UART_ADVFEATURE_NO_INIT;
	huart3.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
	if (HAL_UART_Init(&huart3) != HAL_OK)
	{
	Error_Handler();
	}
 /* USER CODE END USART3_Init 2 */

}

/**
 * @brief GPIO Initialization Function
 * @param None
 * @retval None
 */
static void MX_GPIO_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 /* USER CODE BEGIN MX_GPIO_Init_1 */

 /* USER CODE END MX_GPIO_Init_1 */

 /* GPIO Ports Clock Enable */
 __HAL_RCC_GPIOC_CLK_ENABLE();
 __HAL_RCC_GPIOA_CLK_ENABLE();
 __HAL_RCC_GPIOB_CLK_ENABLE();
 __HAL_RCC_GPIOD_CLK_ENABLE();
 __HAL_RCC_GPIOG_CLK_ENABLE();

 /*Configure GPIO pin : BTN_Pin */
 GPIO_InitStruct.Pin = BTN_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
 GPIO_InitStruct.Pull = GPIO_PULLUP;
 HAL_GPIO_Init(BTN_GPIO_Port, &GPIO_InitStruct);

 /*Configure GPIO pins : PC1 PC4 PC5 */
 GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

 /*Configure GPIO pins : PA1 PA2 PA7 */
 GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /*Configure GPIO pin : PB13 */
 GPIO_InitStruct.Pin = GPIO_PIN_13;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 /*Configure GPIO pins : PA8 PA11 PA12 */
 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_11|GPIO_PIN_12;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /*Configure GPIO pins : PD5 PD6 */
 GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

 /*Configure GPIO pins : PG11 PG13 */
 GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_13;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
 HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

 /* EXTI interrupt init*/
 HAL_NVIC_SetPriority(BTN_EXTI_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(BTN_EXTI_IRQn);

 /* USER CODE BEGIN MX_GPIO_Init_2 */

 /* USER CODE END MX_GPIO_Init_2 */
}

/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
	if (GPIO_Pin == BTN_Pin)
	{
		HAL_NVIC_SystemReset();
	}
}

void SerialDownload(void)
{
 uint8_t number[11] = {0};
 uint32_t size = 0;
 COM_StatusTypeDef result;

 Serial_PutString((uint8_t *)"Waiting for the file to be sent ... (press 'a' to abort)\n\r");
 result = Ymodem_Receive( &size );
 if (result == COM_OK)
 {
 Serial_PutString((uint8_t *)"\n\n\r Programming Completed Successfully!\n\r--------------------------------\r\n Name: ");
 Serial_PutString(aFileName);
 Int2Str(number, size);
 Serial_PutString((uint8_t *)"\n\r Size: ");
 Serial_PutString(number);
 Serial_PutString((uint8_t *)" Bytes\r\n");
 Serial_PutString((uint8_t *)"--------------------------------\n");
 }
 else if (result == COM_LIMIT)
 {
 Serial_PutString((uint8_t *)"\n\n\rThe image size is higher than the allowed space memory!\n\r");
 }
 else if (result == COM_DATA)
 {
 Serial_PutString((uint8_t *)"\n\n\rVerification failed!\n\r");
 }
 else if (result == COM_ABORT)
 {
 Serial_PutString((uint8_t *)"\r\n\nAborted by user.\n\r");
 }
 else
 {
 Serial_PutString((uint8_t *)"\n\rFailed to receive the file!\n\r");
 }
}
/* USER CODE END 4 */

/**
 * @brief This function is executed in case of error occurrence.
 * @retval None
 */
void Error_Handler(void)
{
 /* USER CODE BEGIN Error_Handler_Debug */
 /* User can add his own implementation to report the HAL error return state */
 __disable_irq();
 while (1)
 {
 }
 /* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
 * @brief Reports the name of the source file and the source line number
 * where the assert_param error has occurred.
 * @param file: pointer to the source file name
 * @param line: assert_param error line source number
 * @retval None
 */
void assert_failed(uint8_t *file, uint32_t line)
{
 /* USER CODE BEGIN 6 */
 /* User can add his own implementation to report the file name and line number,
 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */