Как прошить на STM32f103c8 с помощью кодовых блоков? - PullRequest
0 голосов
/ 28 января 2019

Я пытаюсь запрограммировать мой STM32f103c8, используя STM32Cubemx, code :: blocks и CubeMXMakefile.py.Результат компиляции показывает 0 ошибок и 0 предупреждений, и что перепрошивка прошла успешно, но код (мигающий PC13) не работает на плате.

Я установил Stlink путем клонирования "https://github.com/texane/stlink" repo, изапустив на нем make, проверил, работает ли он, запустив lsusb, и подтвердил обнаружение «STMicroelectronics ST-LINK / V2».

Я также уже установил компиляторы arm для кодовых блоков, и они, похоже, тоже работают.

Сначала я столкнулся с тем, что код не будет мигать на плате, а при запуске "CubeMXMakefile.py.«я получаю предупреждение о том, что st-flash не установлен, хотя он был создан при запуске Make на клоне, и при попытке« сделать flash »я получаю сообщение об ошибке, что st-flash не может быть найден в» / usr/ local / bin ". Я решил эту проблему (я думаю), вручную скопировав файл st-flash из каталога build / release в репозитории clone по указанному пути. Теперь код компилируется без ошибок при компиляции или перепрошивке, нокод не работает до сих пор.

это код, весь цикл, сгенерированный cubemx, за исключением блока while:

/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  ** This notice applies to any and all portions of this file
  * that are not between comment pairs USER CODE BEGIN and
  * USER CODE END. Other portions of this file, whether
  * inserted by the user or by software development tools
  * are owned by their respective copyright owners.
  *
  * COPYRIGHT(c) 2019 STMicroelectronics
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f1xx_hal.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

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

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);

/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  *
  * @retval None
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* 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();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

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

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
  HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
  HAL_Delay(500);

  }
  /* USER CODE END 3 */

}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;

    /**Initializes the CPU, AHB and APB busses clocks
    */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 16;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Initializes the CPU, AHB and APB busses clocks
    */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Configure the Systick interrupt time
    */
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    /**Configure the Systick
    */
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

/** Configure pins as
        * Analog
        * Input
        * Output
        * EVENT_OUT
        * EXTI
*/
static void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

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

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);

  /*Configure GPIO pin : PC13 */
  GPIO_InitStruct.Pin = GPIO_PIN_13;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @param  file: The file name as string.
  * @param  line: The line in file as a number.
  * @retval None
  */
void _Error_Handler(char *file, int line)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  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,
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

это вывод компиляции:

CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
-------------- Clean: Release in testagain (compiler: GNU GCC Compiler for ARM)---------------
Executing clean command: make -f Makefile cleanRelease
rm -fR .dep build
Cleaned "testagain - Release"
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
-------------- Build: Release in testagain (compiler: GNU GCC Compiler for ARM)---------------
Scanned 0 files for #includes, cache used 0, cache updated 0
Checking if target is up-to-date: make -q -f Makefile Release
Running command: make -f Makefile Release
mkdir -p build      
C. Compiling build/system_stm32f1xx.o...
C. Compiling build/stm32f1xx_hal.o...
C. Compiling build/stm32f1xx_hal_cortex.o...
C. Compiling build/stm32f1xx_hal_dma.o...
C. Compiling build/stm32f1xx_hal_flash.o...
C. Compiling build/stm32f1xx_hal_flash_ex.o...
C. Compiling build/stm32f1xx_hal_gpio.o...
C. Compiling build/stm32f1xx_hal_gpio_ex.o...
C. Compiling build/stm32f1xx_hal_pwr.o...
C. Compiling build/stm32f1xx_hal_rcc.o...
C. Compiling build/stm32f1xx_hal_rcc_ex.o...
C. Compiling build/stm32f1xx_hal_tim.o...
C. Compiling build/stm32f1xx_hal_tim_ex.o...
C. Compiling build/main.o...
C. Compiling build/stm32f1xx_hal_msp.o...
C. Compiling build/stm32f1xx_it.o...
S. Compiling build/startup_stm32f103xb.o...
2019-01-27T23:17:52 INFO common.c: Loading device parameters....
2019-01-27T23:17:52 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-01-27T23:17:52 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
C. Linking build/testagain.elf...
/usr/bin/arm-none-eabi-size build/testagain.elf
   text    data     bss     dec     hex filename
   3560      12    1572    5144    1418 build/testagain.elf
H. Linking build/testagain.hex...
B. Building build/testagain.bin...
Used gcc: 6.3.1
/usr/local/bin/st-flash erase
st-flash 1.5.1-12-g30de1b3
Mass erasing
/usr/local/bin/st-flash --reset write build/testagain.bin 0x8000000
2019-01-27T23:17:52 INFO common.c: Loading device parameters....
2019-01-27T23:17:52 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-01-27T23:17:52 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
2019-01-27T23:17:52 INFO common.c: Attempting to write 3572 (0xdf4) bytes to stm32 address: 134217728 (0x8000000)
st-flash 1.5.1-12-g30de1b3
Flash page at addr: 0x08000000 erased
Flash page at addr: 0x08000400 erased
Flash page at addr: 0x08000800 erased
2019-01-27T23:17:52 INFO common.c: Finished erasing 4 pages of 1024 (0x400) bytes
2019-01-27T23:17:52 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2019-01-27T23:17:52 INFO flash_loader.c: Successfully loaded flash loader in sram
Flash page at addr: 0x08000c00 erased
  1/4 pages written
  2/4 pages written
2019-01-27T23:17:52 INFO common.c: Starting verification of write complete
2019-01-27T23:17:52 INFO common.c: Flash written and verified! jolly good!
  3/4 pages written
  4/4 pages written
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /home/ubunzer/Documents/CBARM/testagain.
CWD for depslib is: /home/ubunzer/Documents/CBARM/testagain.
Scanned 0 files for #includes, cache used 0, cache updated 0
Process terminated with status 0 (0 minute(s), 2 second(s))
0 error(s), 0 warning(s) (0 minute(s), 2 second(s))

1 Ответ

0 голосов
/ 28 января 2019

try

st-flash reset

Я обнаружил, что мой MCU не выполняет код после перепрошивки.Он работал после сброса вручную.

Если у вас это не работает, попробуйте это с openOCD.

Попробовал с OpenOCD, не перепрошивал устройство, просто "сбросил"run "- и устройство начало работать.

https://github.com/texane/stlink/issues/532#issuecomment-286882627

...