본문 바로가기

Firmware/stm32

STM32 IAP (Ymodem 프로토콜) Bootloader - 2

cubeMX : 5.6.1
cubeIDE : 1.3.1

Code Lib Version : STM32Cube_FW_F1_V1.8.0

MCU:STM32F103VBTx

 

https://kjt9109.tistory.com/entry/STM32-IAP-Ymodem-%ED%94%84%EB%A1%9C%ED%86%A0%EC%BD%9C-Bootloader-1

의 이어서 작업..

 

이전작업에서 Bootloader 코드를 만들었으므로 이번에는 Application 코드를 만들어 본다.

 

기존의 메모리를 확인해보면 Bootloader 코드는 0x0800 0000에 올라가 있고

Application Code는 0x0800 4000 에 올리기로 했다.

 

Application은 임의의 프로젝트로 만든다 

이때 Application은 코드가 정상적으로 출력되는지 확인하기 위해 UART를 집어 넣는다.

 

Application

 

main.c

int main(void)
{
  /* USER CODE BEGIN 1 */
  dummy = CRC_Code;
  /* USER CODE END 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 SysInit */

  /* USER CODE END SysInit */

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

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
    Serial_PutString((uint8_t*) "\n\n\r hello boot loader_v1 \n\r");
    Serial_PutString((uint8_t*) "\n\n\r application Start Address: 0x0800A000 \n\r");
    HAL_Delay(1000);
    /* USER CODE END 3 */
  }
}

Test할 Application Code는 0x0800 A000으로 되어있다. (0x0800 4000 -> 0x0800 A000)

 

Application Code 작성 후 stm32cubeide에서는 2군데만 수정하면 된다.

 

1. STM32F103VBTX_FLASH.ld

 

2. system_stm32f1xx.c

 

1번 같은 경우 메모리구역을 정해주는 링커 스크립트란 파일인데

시작파일이 0x0800 0000으로 되어 있으므로  0x0800 A000으로 수정해줘야 한다.

 

MEMORY
{
  RAM   	     (xrw)    : ORIGIN = 0x20000000,   LENGTH = 20K  
  FLASH   		 (rx)    : ORIGIN = 0x800a000,   LENGTH = 128K   <-- 수정
}

2번 경우는 system_stm32f1xx.c 에 offset이 있는데 Application Address가 Jump 한 만큼 offset 역시 Jump 해줘야 한다.

 

#if !defined  (HSE_VALUE) 
  #define HSE_VALUE               8000000U /*!< Default value of the External oscillator in Hz.
                                                This value can be provided and adapted by the user application. */
#endif /* HSE_VALUE */

#if !defined  (HSI_VALUE)
  #define HSI_VALUE               8000000U /*!< Default value of the Internal oscillator in Hz.
                                                This value can be provided and adapted by the user application. */
#endif /* HSI_VALUE */

/*!< Uncomment the following line if you need to use external SRAM  */ 
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
/* #define DATA_IN_ExtSRAM */
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */

/*!< Uncomment the following line if you need to relocate your vector Table in
     Internal SRAM. */ 
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET  0x0000a000U /*!< Vector Table base offset field.
                                  This value must be a multiple of 0x200. */

 

마지막으로 Bootloader에 파일을 올리기 위해서는  .bin 파일이 필요하다

다음과 같이 설정하여 bin 파일이 생성되게 한다.

 

 

 

(프로젝트 진행 중 Application File을 2개 올리 수 있게 변경 되었고 Application Address는 4000에서 a0000과 6000으로 변경되었다.)

 

Build 후 ~~~.bin 파일 생성 확인.

 

필요한건 완성하였으니 아래와 같은 순서로 구동해보자.

 

1. Bootloader  실행

1번 클릭

 

 

2. Teraterm 에서 file - YMODEM - SEND 클릭

 

3.  파일 선택 ( Application 에서 생성한 파일을 선택)

 

4. 정상적으로 업로드가 되었으면 다음과 같이  Programming Completed Successfully가 출력 된다.

 

5.  3번을 눌러 정상 실행 확인.