[N32G430] N32G430 评测

[复制链接]
 楼主| 一路向北lm 发表于 2024-4-23 08:48 | 显示全部楼层 |阅读模式
本帖最后由 一路向北lm 于 2024-4-24 18:54 编辑

拿到了N32G430开发板已经有一段时间了,由于最近一段时间经历离职/换工作,一直没有开箱评测,最近几天有空,给大家做一个分享汇报。

1.芯片功能:
       N32G430系列采用32-bit Arm® Cortex®-M4F内核,最高工作主频128MHz,支持浮点运算和DSP指令,集成高达 64KB嵌入式加密Flash,16KB SRAM,集成丰富的高性能模拟器件,内置1个12bit 4.7Msps ADC,3个高速比较 器,集成多路U(S)ART、I²C、SPI、CAN等数字通信接口。

2.资料下载:
国民技术官网:https://www.nationstech.com/zlxz369/

3.gpio-led 测试
  1. void LED_Initialize(GPIO_Module* GPIOx, uint16_t pin)
  2. {
  3.         GPIO_InitType GPIO_InitStructure;
  4.         if(GPIOx == GPIOA)
  5.         {
  6.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOA);
  7.         }
  8.         else if(GPIOx == GPIOB)
  9.         {
  10.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOB);
  11.         }
  12.         else if(GPIOx == GPIOC)
  13.         {
  14.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOC);
  15.         }
  16.         else
  17.         {
  18.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOD);
  19.         }
  20.         
  21.         if(pin < GPIO_PIN_ALL)
  22.         {
  23.                 GPIO_Structure_Initialize(&GPIO_InitStructure);
  24.                 GPIO_InitStructure.Pin          = pin;
  25.                 GPIO_InitStructure.GPIO_Mode    = GPIO_MODE_OUT_PP;
  26.                 GPIO_InitStructure.GPIO_Current = GPIO_DS_4MA;
  27.                 GPIO_Peripheral_Initialize(GPIOx, &GPIO_InitStructure);
  28.         }
  29. }

  30. void LED_Toggle(GPIO_Module* GPIOx, uint16_t pin)
  31. {
  32.     GPIO_Pin_Toggle(GPIOx, pin);;
  33. }

  34. {
  35.     GPIO_Pins_Set(GPIOx, pin);
  36. }

  37. void LED_Off(GPIO_Module* GPIOx,uint16_t pin)
  38. {
  39.     GPIO_Pins_Reset(GPIOx, pin);
  40. }


  41. // mian test
  42. int main(void)
  43. {
  44.         LED_Initialize(LED1_GPIO_PORT, LED1_GPIO_PIN | LED2_GPIO_PIN | LED3_GPIO_PIN);
  45.         LED_Off(LED1_GPIO_PORT, LED1_GPIO_PIN | LED2_GPIO_PIN | LED3_GPIO_PIN);     
  46.         while(1)
  47.         {
  48.                 LED_Toggle(LED1_GPIO_PORT, LED1_GPIO_PIN);   
  49.                 LED_Toggle(LED2_GPIO_PORT, LED2_GPIO_PIN);
  50.                 LED_Toggle(LED3_GPIO_PORT, LED3_GPIO_PIN);
  51.                 SysTick_Delay_Ms(1000);
  52.         }
  53. }
4.gpio-key 测试
  1. void Key_Input_Initialize(GPIO_Module* GPIOx, uint16_t pin)
  2. {
  3.         GPIO_InitType GPIO_InitStructure;
  4.         if(GPIOx == GPIOA)
  5.         {
  6.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOA);
  7.         }
  8.         else if(GPIOx == GPIOB)
  9.         {
  10.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOB);
  11.         }
  12.         else if(GPIOx == GPIOC)
  13.         {
  14.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOC);
  15.         }
  16.         else
  17.         {
  18.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOD);
  19.         }
  20.         
  21.         if(pin < GPIO_PIN_ALL)
  22.         {
  23.                 GPIO_Structure_Initialize(&GPIO_InitStructure);
  24.                 GPIO_InitStructure.Pin       = pin;
  25.                 GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT;
  26.                 GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP;
  27.                 /* Initialize GPIO */
  28.                 GPIO_Peripheral_Initialize(GPIOx, &GPIO_InitStructure);
  29.         }
  30. }

  31. void Key_Input_Initialize(GPIO_Module* GPIOx, uint16_t pin)
  32. {
  33.         /* Define a structure of type GPIO_InitType */
  34.         GPIO_InitType GPIO_InitStructure;
  35.         
  36.         /* Enable KEY related GPIO peripheral clock */
  37.         if(GPIOx == GPIOA)
  38.         {
  39.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOA);
  40.         }
  41.         else if(GPIOx == GPIOB)
  42.         {
  43.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOB);
  44.         }
  45.         else if(GPIOx == GPIOC)
  46.         {
  47.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOC);
  48.         }
  49.         else
  50.         {
  51.                 RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOD);
  52.         }
  53.         
  54.         if(pin < GPIO_PIN_ALL)
  55.         {
  56.                 GPIO_Structure_Initialize(&GPIO_InitStructure);
  57.                 GPIO_InitStructure.Pin       = pin;
  58.                 GPIO_InitStructure.GPIO_Mode = GPIO_MODE_INPUT;
  59.                 GPIO_InitStructure.GPIO_Pull = GPIO_PULL_UP;
  60.                 GPIO_Peripheral_Initialize(GPIOx, &GPIO_InitStructure);
  61.         }
  62. }

  63. // main test
  64. int main(void)
  65. {
  66.         LED_Initialize(LED1_GPIO_PORT, LED1_GPIO_PIN | LED2_GPIO_PIN);
  67.         Key_Input_Initialize(KEY3_PORT, KEY3_PIN);
  68.         while(1)
  69.         {
  70.                 if(GPIO_Input_Pin_Data_Get(KEY3_PORT, KEY3_PIN) == PIN_RESET)
  71.                 {
  72.                         LED_On(LED1_GPIO_PORT, LED1_GPIO_PIN);
  73.                         LED_Off(LED2_GPIO_PORT, LED2_GPIO_PIN);
  74.                         LED_Off(LED3_GPIO_PORT, LED3_GPIO_PIN);
  75.                 }  
  76. }
5.timer-gpio-toggle 测试
  1. uint32_t BSTIMClockFrequency = 0;

  2. void GPIO_Config(void)
  3. {
  4.     GPIO_InitType GPIO_InitStructure;
  5.     GPIO_Structure_Initialize(&GPIO_InitStructure);
  6.     GPIO_InitStructure.Pin = GPIO_PIN_6;
  7.     GPIO_InitStructure.GPIO_Mode  = GPIO_MODE_OUT_PP;
  8.     GPIO_InitStructure.GPIO_Slew_Rate = GPIO_SLEW_RATE_FAST;
  9.     GPIO_Peripheral_Initialize(GPIOB, &GPIO_InitStructure);
  10. }


  11. int main(void)
  12. {
  13.     GPIO_Config();
  14.     BSTIMClockFrequency = Common_BSTIM_RCC_Initialize(TIM6, RCC_HCLK_DIV4);
  15.     Common_TIM_NVIC_Initialize(TIM6_IRQn, ENABLE);
  16.     Common_TIM_Base_Initialize(TIM6, 65535, 0);
  17.     TIM_Base_Reload_Mode_Set(TIM6, TIM_PSC_RELOAD_MODE_IMMEDIATE);
  18.     TIM_Interrupt_Enable(TIM6, TIM_INT_UPDATE);
  19.     TIM_On(TIM6);
  20. }


  21. void TIM6_IRQHandler(void)
  22. {
  23.     if (TIM_Interrupt_Status_Get(TIM6, TIM_INT_UPDATE) != RESET)
  24.     {
  25.         TIM_Interrupt_Status_Clear(TIM6, TIM_INT_UPDATE);
  26.         GPIO_Pin_Toggle(GPIOB, GPIO_PIN_6);
  27.     }
  28. }
6.uart-printf 测试
  1. void GPIO_Configuration(void)
  2. {
  3.     GPIO_InitType GPIO_InitStructure;
  4.     GPIO_Structure_Initialize(&GPIO_InitStructure);   

  5.     GPIO_InitStructure.Pin            = USARTx_TxPin;
  6.     GPIO_InitStructure.GPIO_Mode      = GPIO_MODE_AF_PP;
  7.     GPIO_InitStructure.GPIO_Alternate = USARTx_Tx_GPIO_AF;
  8.     GPIO_Peripheral_Initialize(USARTx_GPIO, &GPIO_InitStructure);   

  9.     GPIO_InitStructure.Pin            = USARTx_RxPin;
  10.     GPIO_InitStructure.GPIO_Alternate = USARTx_Rx_GPIO_AF;
  11.     GPIO_Peripheral_Initialize(USARTx_GPIO, &GPIO_InitStructure);
  12. }

  13. void RCC_Configuration(void)
  14. {
  15.     GPIO_AHBClkCmd(USARTx_GPIO_CLK);
  16.     USART_APBxClkCmd(USARTx_CLK);
  17. }

  18. void  UART_Configuration(void)
  19. {
  20.    USART_InitType USART_InitStructure;
  21.     USART_InitStructure.BaudRate            = 115200;
  22.     USART_InitStructure.WordLength          = USART_WL_8B;
  23.     USART_InitStructure.StopBits            = USART_STPB_1;
  24.     USART_InitStructure.Parity              = USART_PE_NO;
  25.     USART_InitStructure.HardwareFlowControl = USART_HFCTRL_NONE;
  26.     USART_InitStructure.Mode                = USART_MODE_RX | USART_MODE_TX;

  27.     /* Configure USARTx */
  28.     USART_Initializes(USARTx, &USART_InitStructure);
  29.     /* Enable the USARTx */
  30.     USART_Enable(USARTx);
  31. }

  32. int main(void)
  33. {
  34.     RCC_ClocksType RCC_ClocksStatus;
  35.     RCC_Configuration();
  36.     GPIO_Configuration();
  37.     UART_Configuration(void);
  38.     RCC_Clocks_Frequencies_Value_Get(&RCC_ClocksStatus);
  39.     printf("\n\rUSART Printf Example: retarget the C library printf function to the USART\n\r");

  40.     while (1)
  41.     {
  42.     }
  43. }

  44. int fputc(int ch, FILE* f)
  45. {
  46.     USART_Data_Send(USARTx, (uint8_t)ch);
  47.     while (USART_Flag_Status_Get(USARTx, USART_FLAG_TXDE) == RESET);
  48.     return (ch);
  49. }

  50. #ifdef USE_FULL_ASSERT
  51. void assert_failed(const uint8_t* expr, const uint8_t* file, uint32_t line)
  52. {
  53.     /* User can add his own implementation to report the file name and line number,
  54.        ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  55.     /* Infinite loop */
  56.     while (1)
  57.     {
  58.     }
  59. }

  60. #endif
7.can-loop测试,N32G430集成了can外设,也就意味着它具备胜任工业网络canopen协议的可能,can迈出大门第一步,回环自测
  1. void CAN_CONFIG(void)
  2. {
  3.     RCC_APB1_Peripheral_Clock_Enable(RCC_APB1_PERIPH_CAN);
  4.     CAN_NVIC_Configuration();
  5.     CAN_GPIO_Configuration();
  6.    
  7.     CAN_Reset(CAN);
  8.     CAN_Structure_Initializes(&CAN_InitStructure);
  9.     CAN_InitStructure.TTCM          = DISABLE;
  10.     CAN_InitStructure.ABOM          = DISABLE;
  11.     CAN_InitStructure.AWKUM         = DISABLE;
  12.     CAN_InitStructure.NART          = DISABLE;
  13.     CAN_InitStructure.RFLM          = DISABLE;
  14.     CAN_InitStructure.TXFP          = ENABLE;
  15.     CAN_InitStructure.OperatingMode = CAN_LOOPBACK_MODE;
  16.     CAN_InitStructure.RSJW          = CAN_RSJW_1TQ;
  17.     CAN_InitStructure.TBS1          = CAN_TBS1_8TQ;
  18.     CAN_InitStructure.TBS2          = CAN_TBS2_7TQ;   
  19.     CAN_InitStructure.BaudRatePrescaler = 4;
  20.     CAN_Initializes(CAN, &CAN_InitStructure);
  21.     CAN_FilterInitStructure.Filter_Num            = 0;
  22.     CAN_FilterInitStructure.Filter_Mode           = CAN_FILTER_IDLISTMODE;
  23.     CAN_FilterInitStructure.Filter_Scale          = CAN_FILTER_32BITSCALE;
  24.     CAN_FilterInitStructure.Filter_HighId         = 0x8000;
  25.     CAN_FilterInitStructure.Filter_LowId          = 0x0000;
  26.     CAN_FilterInitStructure.FilterMask_HighId     = 0x4000;
  27.     CAN_FilterInitStructure.FilterMask_LowId      = 0x0000;
  28.     CAN_FilterInitStructure.Filter_FIFOAssignment = CAN_FIFO0;
  29.     CAN_FilterInitStructure.Filter_Act            = ENABLE;
  30.     CAN_Filter_Initializes(&CAN_FilterInitStructure);
  31.     CAN_Config_Interrupt_Enable(CAN, CAN_INT_FMP0);
  32. }


  33. void CAN_NVIC_Configuration(void)
  34. {
  35.     NVIC_InitType NVIC_InitStructure;
  36.     NVIC_Initializes(&NVIC_InitStructure);
  37.     NVIC_InitStructure.NVIC_IRQChannel                   = CAN_RX0_IRQn;
  38.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
  39.     NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0x1;
  40.     NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
  41.     NVIC_Initializes(&NVIC_InitStructure);
  42. }



  43. void CAN_GPIO_Configuration(void)
  44. {
  45.     GPIO_InitType GPIO_InitStructure;
  46.     GPIO_Structure_Initialize(&GPIO_InitStructure);
  47.    
  48.         RCC_AHB_Peripheral_Clock_Enable(RCC_AHB_PERIPH_GPIOB);
  49.         RCC_APB2_Peripheral_Clock_Enable(RCC_APB2_PERIPH_AFIO);

  50.     GPIO_InitStructure.Pin            = GPIO_PIN_8;
  51.     GPIO_InitStructure.GPIO_Mode      = GPIO_MODE_AF_PP;
  52.     GPIO_InitStructure.GPIO_Alternate = GPIO_AF6_CAN;
  53.     GPIO_Peripheral_Initialize(GPIOB, &GPIO_InitStructure);
  54.     GPIO_InitStructure.Pin             = GPIO_PIN_9;
  55.     GPIO_InitStructure.GPIO_Alternate  = GPIO_AF6_CAN;
  56.     GPIO_Peripheral_Initialize(GPIOB, &GPIO_InitStructure);
  57. }



  58. uint8_t Check_CanRecData(CanRxMessage* RxMessage, uint32_t StdId, uint32_t ExtId, uint8_t IDE, uint8_t RTR, uint8_t DLC,
  59.                          uint8_t Data0, uint8_t Data1, uint8_t Data2, uint8_t Data3,
  60.                          uint8_t Data4, uint8_t Data5, uint8_t Data6, uint8_t Data7, uint8_t FMI)
  61. {
  62.     if(IDE == CAN_EXTENDED_ID)
  63.     {
  64.         if(RxMessage->ExtId   != ExtId)         
  65.         {
  66.             return Fail;
  67.         }
  68.     }
  69.     else if(IDE == CAN_STANDARD_ID)
  70.     {
  71.         if(RxMessage->StdId   != StdId)  
  72.         {
  73.             return Fail;
  74.         }
  75.     }
  76.     if( (RxMessage->IDE     != IDE)   ||         /* CAN_ID_STD / CAN_ID_EXT */
  77.         (RxMessage->RTR     != RTR)   ||         /* CAN_RTR_DATA / CAN_RTR_REMOTE */
  78.         (RxMessage->DLC     != DLC)              /* 0 to 8 */
  79.     )
  80.     {
  81.         return Fail;
  82.     }
  83.     if(RTR == CAN_RTRQ_DATA)
  84.     {
  85.         if(DLC >= 1)
  86.         {
  87.             if(RxMessage->Data[0] != Data0)
  88.             {
  89.                 return Fail;
  90.             }
  91.         }
  92.         if(DLC >= 2)
  93.         {
  94.             if(RxMessage->Data[1] != Data1)
  95.             {
  96.                 return Fail;
  97.             }
  98.         }
  99.         if(DLC >= 3)
  100.         {
  101.             if(RxMessage->Data[2] != Data2)
  102.             {
  103.                 return Fail;
  104.             }
  105.         }
  106.         if(DLC >= 4)
  107.         {
  108.             if(RxMessage->Data[3] != Data3)
  109.             {
  110.                 return Fail;
  111.             }
  112.         }
  113.         if(DLC >= 5)
  114.         {
  115.             if(RxMessage->Data[4] != Data4)
  116.             {
  117.                 return Fail;
  118.             }
  119.         }
  120.         if(DLC >= 6)
  121.         {
  122.             if(RxMessage->Data[5] != Data5)
  123.             {
  124.                 return Fail;
  125.             }
  126.         }
  127.         if(DLC >= 7)
  128.         {
  129.             if(RxMessage->Data[6] != Data6)
  130.             {
  131.                 return Fail;
  132.             }
  133.         }
  134.         if(DLC == 8)
  135.         {
  136.             if(RxMessage->Data[7] != Data7)
  137.             {
  138.                 return Fail;
  139.             }
  140.         }
  141.         if(DLC > 8)
  142.         {
  143.             return Fail;
  144.         }
  145.     }
  146.     else if(RTR == CAN_RTRQ_REMOTE)
  147.     {
  148.         
  149.     }
  150.     if(RxMessage->FMI != FMI)           
  151.     {
  152.         return Fail;
  153.     }

  154.     return Pass;
  155. }

  156. uint16_t Rx_Flag = DISABLE;
  157. int main(void)
  158. {
  159.     uint32_t wait_slak;
  160.     NVIC_Priority_Group_Set(NVIC_PER2_SUB2_PRIORITYGROUP);

  161.     CAN_CONFIG();
  162.    
  163.     CAN_TxMessage.StdId   = 0x0400;        
  164.     CAN_TxMessage.ExtId   = 0x00;        
  165.     CAN_TxMessage.IDE     = CAN_STANDARD_ID;           /* CAN_ID_STD / CAN_ID_EXT */
  166.     CAN_TxMessage.RTR     = CAN_RTRQ_DATA;           /* CAN_RTR_DATA / CAN_RTR_REMOTE */
  167.     CAN_TxMessage.DLC     = 8;           /* 0 to 8 */
  168.     CAN_TxMessage.Data[0] = 0x00;
  169.     CAN_TxMessage.Data[1] = 0x01;
  170.     CAN_TxMessage.Data[2] = 0x02;
  171.     CAN_TxMessage.Data[3] = 0x03;
  172.     CAN_TxMessage.Data[4] = 0x04;
  173.     CAN_TxMessage.Data[5] = 0x05;
  174.     CAN_TxMessage.Data[6] = 0x06;
  175.     CAN_TxMessage.Data[7] = 0x07;
  176.     while(1)
  177.     {
  178.         CAN_Transmit_Message_initializes(CAN,&CAN_TxMessage);
  179.         while(Rx_Flag == DISABLE)
  180.         {
  181.             Rx_Flag = Check_CanRecData(&CAN_RxMessage, 0x0400, 0x00, CAN_STANDARD_ID, CAN_RTRQ_DATA, 8,
  182.                          0x00,0x01, 0x02, 0x03,
  183.                          0x04,0x05, 0x06, 0x07, 0);
  184.         }
  185.         
  186.         wait_slak = 0xFFFF;
  187.         while(wait_slak>0)
  188.         {
  189.             wait_slak--;
  190.         }
  191.         Rx_Flag = DISABLE;
  192.     }
  193. }

8.内置boot-loader测试,测试内部的boot,是我这次测试的重点,在汇川工作的时候,遇到过国民其它系列芯片内置boot的bug问题,本次再来体验一下,看国民官方是否修复。

8.1 N32G430内置boot功能强大,具体支持功能如下:
1.png
8.2
N32G430 系列芯片的固件程序 BOOT,支持通过 USART 接口下载用户程序和数据。 相关命令格式如下:


上下层指令数据结构

1、上层指令结构:
<CMD_H + CMD_L + LEN + Par> + (DAT)。
CMD_H 代表一级命令字段, CMD_L 代表二级命令字段; LEN 代表发送数据长度; Par代表 4 个字节命令参数; DAT 代表上层指令往下层发送的具体数据;
2、下层应答结构:
< CMD_H + CMD_L + LEN > + (DAT) + <CR1+CR2>。
CMD_H 代表一级命令字段, CMD_L 代表二级命令字段,下层的命令字段和对应上层的命令字段相同; LEN 代表发送数据长度; DAT 代表下层向上层应答的具体数据; CR1+CR2代表向上层返回的指令执行结果,若上层发送命令一级、二级命令字段不属于任何命令, BOOT 回复 CR1=0xBB, CR2 = 0xCC。



串口支持的命令数据结构:
1、 上位机下发上层指令:
STA1 + STA2 + {上层指令结构} + XOR。
STA1 和 STA2 是串口发送命令的起始字节, STA1=0xAA, STA2=0x55。用于芯片识别上位机发送串口数据流。
XOR 代表之前命令字节的异或运算值(STA1 + STA2 + {上层指令结构})。
2、 上位机接收下层应答:
STA1 + STA2 + {下层应答结构} + XOR。
STA1 和 STA2 是串口发送命令的起始字节, STA1=0xAA, STA2=0x55。用于上位机识别芯片发送串口数据流
XOR 代表之前命令字节的异或运算值(STA1 + STA2 + {下层应答结构})。

8.3 命令列表 2.png


8.4 命令说明和实例修改串口波特率
3.png
Par[0~3],串口波特率协商设置值可以设定最大,设定范围为 2.4Kbps ~ 4Mbps,默认波特率为 9600bps

状态字节(CR1CR2)根据命令执行情况分为:
1. 返回成功:状态标志位(0xA00x00)
2. 返回失败:状态标志位(0xB00x00)

4.png
呐咯密密 发表于 2024-4-24 13:52 | 显示全部楼层
n32g430的性价比真的高
 楼主| 一路向北lm 发表于 2024-4-24 18:29 | 显示全部楼层
呐咯密密 发表于 2024-4-24 13:52
n32g430的性价比真的高

是的,拿来做canopen设备一点问题没有的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

293

主题

3837

帖子

81

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