Gcc STM32代码上载成功,但未';跑不动

Gcc STM32代码上载成功,但未';跑不动,gcc,arm,stm32,stm32f1,Gcc,Arm,Stm32,Stm32f1,我是STM32新手,我按照说明在Ubuntu中编程我的第一块stm32f103c8t6板 以下是我添加到源代码中的代码: int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initi

我是STM32新手,我按照说明在Ubuntu中编程我的第一块stm32f103c8t6板

以下是我添加到源代码中的代码:

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(GPIOA, GPIO_PIN_0);
   HAL_Delay(500);

  }
  /* USER CODE END 3 */

}
当然,我在
STM32CubeMX
中将
PA0
端口设置为
GPIO\u输出。
以下是函数
MX\u GPIO\u Init
的输出:

static void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

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

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);

  /*Configure GPIO pin : PA0 */
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}
代码构建并成功上传到电路板。以下是重建代码的输出,该代码生成并上载代码:

-------------- Clean: Release in sample1 (compiler: GNU GCC Compiler for ARM)---------------

Executing clean command: make -f Makefile cleanRelease
rm -fR .dep build
Cleaned "sample1 - Release"

-------------- Build: Release in sample1 (compiler: GNU GCC Compiler for ARM)---------------

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...
2018-06-21T10:32:46 INFO usb.c: -- exit_dfu_mode
C. Linking build/sample1.elf...
/usr/bin/arm-none-eabi-size build/sample1.elf
   text    data     bss     dec     hex filename
   3560      20    1572    5152    1420 build/sample1.elf
H. Linking build/sample1.hex...
B. Building build/sample1.bin...
Used gcc: 6.3.1
/usr/local/bin/st-flash erase
2018-06-21T10:32:46 INFO common.c: Loading device parameters....
2018-06-21T10:32:46 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2018-06-21T10:32:46 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
2018-06-21T10:32:46 INFO common.c: Loading device parameters....
2018-06-21T10:32:46 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2018-06-21T10:32:46 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
st-flash 1.4.0-39-g6db0fc2
Mass erasing
/usr/local/bin/st-flash --reset write build/sample1.bin 0x8000000
2018-06-21T10:32:46 INFO common.c: Attempting to write 3580 (0xdfc) bytes to stm32 address: 134217728 (0x8000000)
st-flash 1.4.0-39-g6db0fc2
Flash page at addr: 0x08000000 erased
Flash page at addr: 0x08000400 erased
Flash page at addr: 0x08000800 erased
2018-06-21T10:32:46 INFO common.c: Finished erasing 4 pages of 1024 (0x400) bytes
2018-06-21T10:32:46 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2018-06-21T10:32:46 INFO flash_loader.c: Successfully loaded flash loader in sram
Flash page at addr: 0x08000c00 erased
  1/4 pages written
  2/4 pages written
2018-06-21T10:32:46 INFO common.c: Starting verification of write complete
2018-06-21T10:32:46 INFO common.c: Flash written and verified! jolly good!
  3/4 pages written
  4/4 pages written
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
但是,LED并不像预期的那样开始闪烁。当我连接到5伏时,LED工作正常。我用AVO表检查了电路板的引脚,它们都与微控制器相连

经过几次研究,我认为它与
Boot0
Boot1
引脚有关,所以我尝试了不同的选项,但都不起作用

以下是我的董事会的图像:


如何修复它?

您的代码应该可以工作,但您只需切换未连接的µC引脚

如果您查看“黑色药丸”主页上的示意图,LED将连接到 PB12

如果您想运行固件(从闪存),BOOT0引脚应该连接到GND。BOOT1引脚无关紧要

在您的图像中有一件事:您的LED没有一个电阻器来限制电流,这取决于LED类型,这可能会损坏LED和/或µC引脚

也许你应该首先尝试从电路板上使用D2,如果可以的话,你可以切换到你的发光二极管

我不知道您是否对pin进行了正确的初始化:

PB12设置
时钟启用对每个外设都非常重要。

我认为HAL_延迟功能使用systick以毫秒为单位计算时间,systick必须设置为1ms才能获得正确的延迟,您配置了吗? 我不知道你是怎么做到的

如果输出切换之间的时间非常短,则输出将不会切换,因为您将GPIO_InitStruct.Speed=GPIO_Speed_FREQ_设置为low;,尝试GPIO_InitStruct.Speed=GPIO_Speed_FREQ_uu甚高;然后你可以用示波器检查它是否切换

如果您手边没有示波器,您可以尝试插入一个“while loop”(while循环)计数,而不是HAL_延迟功能

Counter=0;            
while (Counter<500000000)
  {
  Counter++;
  }
计数器=0;

(计数器我处理同样的问题已经一周了。一个在arduino环境下用stm32f103c8t6闪烁LED二极管的简单程序正在运行,stm32f103c8t6、stm32CubeMX、ubuntu的gcc arm(gcc arm none-eabi版本:15:6.3.1+SVN25303-1build1)和ubuntu 18.04的组合不起作用。 在我安装了Arm之后,这些东西就开始工作了。
GNU Arm Embedded Toolchain版本8-2018-q4-major Linux 64解决了我的问题。

您确定为正确的mcu/板配置了多维数据集吗?并且PA0对应于LED的引脚吗?也许您还可以查看函数MX_GPIO_Init,以确保生成的代码是预期的代码。您可以将你拥有的电路板上的墨水?是的,我使用的是STM32F103C8Tx库。我在问题中添加了
MX_GPIO_Init
内容。这是我的电路板链接:GPIO输出的电流足够高吗?我看到你使用的是NOPULL模式。可能尝试GPIO_上拉?如果你有逻辑分析仪或电压表,尝试将GPIO上下拉一个小时需要很长时间才能确认它是否真的存在changing@Stoogy我尝试了
GPIO_InitStruct.Pull=GPIO_PULLUP;
我已经设置了2秒的延迟,但似乎PA0的电压没有变化。它与B0-、B0+、B1-、B1+引脚有什么关系吗?如果将端口切换为push/Pull,则上下拉并不重要。PP驱动程序非常复杂强于弱上拉或下拉电阻我想你说的是电路板上的LED,但在我的场景中,我已将一个外部LED(在照片中可见)连接到电路板。你是对的,我尝试了D2,但它似乎也不起作用。下面是我为D2添加的代码:首先将PB12设置为GPIO_输出,然后将其设置为
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_12);HAL_Delay(500);
在main method中,我的PB12设置与您编写的相同。实际上,我并不是自己写的,它是由stm32cubemx生成的。实际上,我会先尝试设置/重置输出引脚,只是为了验证它是否工作。尝试:HAL_GPIO_WritePin(GPIOB,GPIO_PIN_12,GPIO_PIN_RESET);和HAL_GPIO_WritePin(GPIOB、GPIO_引脚_12、GPIO_引脚_设置);一个将打开LED,另一个将关闭LED,具体取决于LED的连接方式。
Counter=0;            
while (Counter<500000000)
  {
  Counter++;
  }