0

我正在尝试使用 STM32Cubemx、code::blocks 和 CubeMXMakefile.py 对我的 STM32f103c8 进行编程。编译结果显示 0 个错误和 0 个警告,并且闪烁成功,但代码(闪烁 PC13)未在板上运行。

我通过克隆“ https://github.com/texane/stlink ” repo安装了 Stlink ,并在其上运行 make 并通过运行 lsusb 检查它是否工作,并确认检测到“STMicroelectronics ST-LINK/V2”。

我也已经为代码块安装了 arm 编译器,它们似乎也能正常工作。

我的问题主要是一开始代码不会闪到板子上,当运行“CubeMXMakefile.py”时,我会收到一个警告,说 st-flash 没有安装,尽管它是通过在克隆上运行 Make 而构建的,当试图“制作闪存”我会得到一个错误,即在“/usr/local/bin”中找不到 st-flash。我通过手动将 st-flash 文件从克隆存储库中的 build/release 目录复制到提到的路径来解决了这个问题(我认为)。现在代码在编译或闪烁时编译没有错误,但代码仍然无法工作。

这是代码,当然是由 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))
4

1 回答 1

0

尝试

st-flash reset

我发现我的 MCU 在闪烁后没有运行代码。它在手动重置后工作。

如果它不适合您,请尝试使用 openOCD。

尝试使用 OpenOCD,没有重新刷新设备,只是“重置运行”-设备开始工作。

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

于 2019-01-28T03:36:43.747 回答