[N32G45x] [N32G45x] +突然烧录不了的解决方法

[复制链接]
2798|14
 楼主| gaoyang9992006 发表于 2022-3-3 16:55 | 显示全部楼层 |阅读模式
本帖最后由 gaoyang9992006 于 2022-4-12 17:24 编辑

@21小跑堂

收到开发板了,包装盒很漂亮,还送了一条非常给力的miniUSB数据线,然后就上级测试了。非常棒的板子,Lib库函数很好用。
开发板上自带三个LED,都标注了连接到了哪个IO引脚。
绿色LED----PB5
蓝色LED----PB4
红色LED----PA3
其中PB4引脚比较特殊,一定要记得看手册与提供的相关例子。
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/

  27. /**
  28. * [url=home.php?mod=space&uid=288409]@file[/url] main.c
  29. * [url=home.php?mod=space&uid=187600]@author[/url] Nations
  30. * [url=home.php?mod=space&uid=895143]@version[/url] v1.0.0
  31. *
  32. * [url=home.php?mod=space&uid=17282]@CopyRight[/url] Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #include "main.h"
  35. #include <stdio.h>
  36. #include <stdint.h>

  37. /**
  38. * [url=home.php?mod=space&uid=247401]@brief[/url]  Inserts a delay time.
  39. * @param count specifies the delay time length.
  40. */
  41. void Delay(uint32_t count)
  42. {
  43.     for (; count > 0; count--)
  44.         ;
  45. }
  46. /**
  47. * [url=home.php?mod=space&uid=247401]@brief[/url]  Configures LED GPIO.
  48. * @param GPIOx x can be A to G to select the GPIO port.
  49. * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
  50. */
  51. void LedInit(GPIO_Module* GPIOx, uint16_t Pin)
  52. {
  53.     GPIO_InitType GPIO_InitStructure;

  54.     /* Check the parameters */
  55.     assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
  56.         
  57.                         //使用PB4作为IO。
  58.                 GPIO_ConfigPinRemap(GPIO_RMP_SW_JTAG_SW_ENABLE,ENABLE);
  59.                 RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO, ENABLE);

  60.     /* Enable the GPIO Clock */
  61.     if (GPIOx == GPIOA)
  62.     {
  63.         RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
  64.     }
  65.     else if (GPIOx == GPIOB)
  66.     {
  67.         RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
  68.     }
  69.     else if (GPIOx == GPIOC)
  70.     {
  71.         RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOC, ENABLE);
  72.     }
  73.     else if (GPIOx == GPIOD)
  74.     {
  75.         RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOD, ENABLE);
  76.     }
  77.     else if (GPIOx == GPIOE)
  78.     {
  79.         RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOE, ENABLE);
  80.     }
  81.     else if (GPIOx == GPIOF)
  82.     {
  83.         RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOF, ENABLE);
  84.     }
  85.     else
  86.     {
  87.         if (GPIOx == GPIOG)
  88.         {
  89.             RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOG, ENABLE);
  90.         }
  91.     }

  92.     /* Configure the GPIO pin */
  93.     if (Pin <= GPIO_PIN_ALL)
  94.     {
  95.         GPIO_InitStructure.Pin        = Pin;
  96.         GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
  97.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  98.         GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
  99.     }
  100. }
  101. /**
  102. * [url=home.php?mod=space&uid=247401]@brief[/url]  Turns selected Led on.
  103. * @param GPIOx x can be A to G to select the GPIO port.
  104. * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
  105. */
  106. void LedOn(GPIO_Module* GPIOx, uint16_t Pin)
  107. {
  108.     GPIOx->PBSC = Pin;
  109. }
  110. /**
  111. * [url=home.php?mod=space&uid=247401]@brief[/url]  Turns selected Led Off.
  112. * @param GPIOx x can be A to G to select the GPIO port.
  113. * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
  114. */
  115. void LedOff(GPIO_Module* GPIOx, uint16_t Pin)
  116. {
  117.     GPIOx->PBC = Pin;
  118. }
  119. /**
  120. * @brief  Turns selected Led on or off.
  121. * @param GPIOx x can be A to G to select the GPIO port.
  122. * @param Pin This parameter can be one of the following values:
  123. *  [url=home.php?mod=space&uid=2817080]@ARG[/url] GPIO_PIN_0~GPIO_PIN_15: set related pin on
  124. *      [url=home.php?mod=space&uid=2817080]@ARG[/url] (GPIO_PIN_0<<16)~(GPIO_PIN_15<<16): clear related pin off
  125. */
  126. void LedOnOff(GPIO_Module* GPIOx, uint32_t Pin)
  127. {
  128.     GPIOx->PBSC = Pin;
  129. }
  130. /**
  131. * @brief  Toggles the selected Led.
  132. * @param GPIOx x can be A to G to select the GPIO port.
  133. * @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_15.
  134. */
  135. void LedBlink(GPIO_Module* GPIOx, uint16_t Pin)
  136. {
  137.     GPIOx->POD ^= Pin;
  138. }

  139. /**
  140. * @brief Assert failed function by user.
  141. * @param file The name of the call that failed.
  142. * @param line The source line number of the call that failed.
  143. */
  144. #ifdef USE_FULL_ASSERT
  145. void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line)
  146. {
  147.     while (1)
  148.     {
  149.     }
  150. }
  151. #endif // USE_FULL_ASSERT

  152. /**
  153. * @brief  Main program.
  154. */
  155. int main(void)
  156. {
  157.     /*SystemInit() function has been called by startup file startup_n32g45x.s*/

  158.     LedInit(GPIOB, GPIO_PIN_ALL);
  159.     LedInit(GPIOA, GPIO_PIN_ALL);
  160.                 LedOnOff(GPIOA, GPIO_PIN_ALL);
  161.                 LedOnOff(GPIOB, GPIO_PIN_ALL);        

  162.     while (1)
  163.     {
  164.                         LedBlink(GPIOB,GPIO_PIN_ALL);
  165.                         LedBlink(GPIOA,GPIO_PIN_ALL);
  166.                         Delay(0x28FFFF);
  167.     }
  168. }
  169. /**
  170. * @}
  171. */
这是让3个LED一起闪烁的Blink程序。
当我测试完这个跑马灯后,就因为忙,先放一边了。今天下午突然来用,发现烧录不进去了,报错如下:
00000000000000000000000.png

000000000001111.png
刚开始我以为板子坏了呢,找了好多原因没找到。。。
终于找到了可能的原因,测试一下,OK,好了。
方法:
  1. 1.板子上电之前先将BOOT0引脚接到3.3V高电平
  2. 2.板子上电
  3. 3.BOOT0置低电平
  4. 4.重新烧录程序
开发板上对应针脚位置如下图所示。
0000001122.png
这属于把SWD和JTAG都给关了,程序下载不进去了。
如果你遇到突然下载不进去的时候,可以试试这个方法,看看是不是在自己不经意的时候关闭了下载端口功能。
   
598330983 发表于 2022-3-3 17:09 来自手机 | 显示全部楼层
感谢分享经验啊,我有个其他厂家板子也是这个问题,我去试试看
hayden0 发表于 2022-3-3 17:36 | 显示全部楼层
我的N32L436板子PB4没这问题,不会关掉SWD
单片小菜 发表于 2022-3-7 10:38 | 显示全部楼层
主要看看电压是否正确,如果电压没有问题的话,都好说了。
两只袜子 发表于 2022-3-9 15:27 来自手机 | 显示全部楼层
关键在于电压把
一路向东 发表于 2022-4-19 19:00 | 显示全部楼层
本帖最后由 一路向东 于 2022-4-19 19:03 编辑

无法烧录的情况,可能原因
1)SWD口配置了读写保护L1和L2  2)SWD口的PA13和PA14脚IO口配置被更改 3)IO驱动能力不足,SWD接线过长等
解决方法:
1)读保护L1,可以上拉boot0脚,连接SWD口或者使用国民download tool连接PA9和PA10串口,解除读保护后恢复2)IO配置被更改,可以 上拉boot0脚,芯片复位,重新连接SWD口,全擦除后恢复
3)写保护L2配置后,SWD口被锁死,不可恢复。
4)IO驱动能力不足:线尽量短;仿真速率调低;SWDIO接10K上拉,SWDCLK接10K下拉;IO配置提高驱动能力,内部上下拉等

有其他的大家可以一起补充
 楼主| gaoyang9992006 发表于 2022-4-20 08:45 | 显示全部楼层
一路向东 发表于 2022-4-19 19:00
无法烧录的情况,可能原因
1)SWD口配置了读写保护L1和L2  2)SWD口的PA13和PA14脚IO口配置被更改 3)IO驱 ...

总结的很全面。
麻花油条 发表于 2022-4-20 11:04 来自手机 | 显示全部楼层
七楼的问题解决思路很不错
 楼主| gaoyang9992006 发表于 2022-4-20 11:48 | 显示全部楼层
麻花油条 发表于 2022-4-20 11:04
七楼的问题解决思路很不错

是的,他总结的很全面,我只是发了一下,我这次遇到的那种问题的。
jiekou001 发表于 2022-4-26 18:50 | 显示全部楼层
感谢分享,我的那个板子可能也是这个问题。
zhuomuniao110 发表于 2022-11-16 22:12 | 显示全部楼层
PB4这个端口有 特别的吗,我看有人说点不亮。
WQ@nations 发表于 2022-11-29 16:04 | 显示全部楼层
zhuomuniao110 发表于 2022-11-16 22:12
PB4这个端口有 特别的吗,我看有人说点不亮。

PB4复位后默认是JTAG功能口,需要remap配置关闭JTAG,只打开SWD功能,之后再按照GPIO配置即可
klbyf 发表于 2024-4-15 16:50 | 显示全部楼层
谢谢!
dongnanxibei 发表于 2024-4-18 16:34 | 显示全部楼层
很有用的方法。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:如果你觉得我的分享或者答复还可以,请给我点赞,谢谢。

2052

主题

16403

帖子

222

粉丝
快速回复 在线客服 返回列表 返回顶部