[N32G45x] 【N32G45XVL-STB_V1.1】开发板评测之LED灯

[复制链接]
1290|9
 楼主| binoo7 发表于 2022-3-4 22:44 | 显示全部楼层 |阅读模式
AD, AC
本帖最后由 binoo7 于 2022-3-4 23:00 编辑

b3b2d0211bc32c32e7dbc23dab0d01f.jpg 学习第一步,点灯来开路。
上一篇帖子,我讲了一下开发板的拆箱和资料的下载,刚才我在测试LED的时候发现了一个问题,我发现我下载的例程不是这个开发板,下面跟大家分享一下,避免大家踩坑。
我这个开发板的板号是:N32G45XVL-STB_V1.1而我下载的例程对应的板号是:N32G457QE_EVB V1.0
不过没关系了,主芯片一样就行了,首先我们要下载一下PACK包,也就是用keil开发的话,需要支持一下这个芯片的型号和FLM算法。这样的话下载和调试的时候,编译器好操作对应的寄存器。
Nationstech.N32G45x_DFP.1.0.4.pack我下载的是这个版本的。安装的话就是无脑下一步,最后安装结束。
然后打开示例配置芯片型号,示例默认的型号和我们开发板上是不一样的,所以要记得重新修改一下。
配置C99模式,示例默认没有勾选。如果不配置的话,所有的函数声明都要放到开头,所以记得勾选一下。
初始化引脚我这里用了三个LED灯,通过看板子上的丝印来修改对应的IO口。
然后就是点亮LED灯了,让他闪动起来。
这里我要感谢一下咱们的版主,我用了他提供的两个延时函数。


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

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

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



  148. void simple_delay_us(uint32_t x)
  149. {
  150.   for (uint32_t i = 0; i < x; ++i)
  151.         {
  152.     for (uint32_t j = 0; j < 40; ++j)
  153.                 {
  154.       __nop();
  155.     }
  156.   }
  157. }

  158. void simple_delay_ms(uint32_t x)
  159. {
  160.   for(uint32_t i = 0; i < x; ++i)
  161.         {
  162.     simple_delay_us(1000);
  163.   }
  164. }





  165. /**
  166. * @brief  Main program.
  167. */
  168. uint32_t time_delay=0;
  169. int main(void)
  170. {
  171.     /*SystemInit() function has been called by startup file startup_n32g45x.s*/

  172.     LedInit(GPIOA, GPIO_PIN_8);

  173.           LedInit(GPIOB, GPIO_PIN_5);




  174.     while (1)
  175.     {

  176.                                         LedBlink(GPIOA,GPIO_PIN_8);

  177.                                         LedBlink(GPIOB,GPIO_PIN_5);

  178.                                 
  179.                                         simple_delay_ms(100);

  180.     }
  181. }
  182. /**
  183. * @}
  184. */

跑完了这个流程以后,基本上简单的程序大家应该可以写了,我看了一下他们提供的库,跟某32的标准库很像,嘿嘿,大家用起来应该问题不大。
   
mintspring 发表于 2022-3-6 21:06 | 显示全部楼层
代码里只看到2给LED的配置啊,文字中说是3个,啥情况

评论

有一个LED灯坏了,在代码里就去掉了  发表于 2022-3-7 16:58
guijial511 发表于 2022-3-7 07:58 来自手机 | 显示全部楼层
貌似第一部都是点灯,哈哈。
两只袜子 发表于 2022-3-7 09:12 | 显示全部楼层
感觉楼主分享的闭坑宝典,一大早学习一下
单片小菜 发表于 2022-3-7 10:37 | 显示全部楼层
所有的例程都是从跑马灯开始的,没有别的了。
 楼主| binoo7 发表于 2022-3-7 16:59 | 显示全部楼层
guijial511 发表于 2022-3-7 07:58
貌似第一部都是点灯,哈哈。

因为LED灯只是简单的输出控制,其他的话就比较复杂了
mintspring 发表于 2022-5-12 14:49 | 显示全部楼层
binoo7 发表于 2022-3-7 16:59
因为LED灯只是简单的输出控制,其他的话就比较复杂了

是的,这个说明工程能跑起来了
lidi911 发表于 2022-5-14 19:07 来自手机 | 显示全部楼层
一次都没有申请成功过

评论

你们是有实际项目在做吗?可以联系代理商去申请  发表于 2022-5-15 12:29
您需要登录后才可以回帖 登录 | 注册

本版积分规则

49

主题

457

帖子

10

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