[MM32软件] 【MM32 eMiniBoard测评报告】

[复制链接]
 楼主| 一路向北lm 发表于 2020-4-21 17:09 | 显示全部楼层 |阅读模式
本帖最后由 一路向北lm 于 2020-5-3 22:32 编辑

汇总如下:0.  开箱,让你一次看个够
1.安装mm32_devkit_set
2.LED、串口2、ADC测试
3.移植RT-Thread 到MM32L0平台
4.测试RT-Thread 的kprintf




0.  开箱,让你一次看个够

1.jpg

2.jpg

3.jpg

4.jpg


 楼主| 一路向北lm 发表于 2020-4-21 17:11 | 显示全部楼层
本帖最后由 一路向北lm 于 2020-5-3 22:31 编辑

1.安装mm32_devkit_setup
为什么要安装mm32_devkit_setup?肯定是使用keil MDK的时候可以直接使用MM32-Link啊!
安装需要以管理员的身份运行(win7),据听说有的同学没有以管理员身份运行导致MM32-Link不可以使用。
1.jpg



 楼主| 一路向北lm 发表于 2020-4-21 17:12 | 显示全部楼层
本帖最后由 一路向北lm 于 2020-4-21 17:13 编辑

安装完成后,MM32-LinK轻松使用!
2.jpg

 楼主| 一路向北lm 发表于 2020-4-21 17:16 | 显示全部楼层
2. LED、串口、ADC测试
先来LED测试,不废话,直接上代码,官方也太不走心了,明明要点亮LED1LED2,为啥LED3LED4亮了,是不是PCB丝印打错了……………………
  1. int main(void)
  2. {
  3.     delay_init();
  4.     LED_Init();
  5. while(1)
  6. {
  7.                         LED1_ON();
  8.                         LED2_ON();
  9.     }
  10. }
复制代码
1.jpg


 楼主| 一路向北lm 发表于 2020-4-21 17:19 | 显示全部楼层
修改一下引脚,好了,这样才对嘛!
  1. //修改前:
  2. #define LED1_Port  GPIOB
  3. #define LED1_Pin   GPIO_Pin_5
  4. #define LED2_Port  GPIOB
  5. #define LED2_Pin   GPIO_Pin_4
  6. #define LED3_Port  GPIOB
  7. #define LED3_Pin   GPIO_Pin_3
  8. #define LED4_Port  GPIOA
  9. #define LED4_Pin   GPIO_Pin_15

  10. //修改后:
  11. #define LED1_Port  GPIOA
  12. #define LED1_Pin   GPIO_Pin_15
  13. #define LED2_Port  GPIOB
  14. #define LED2_Pin   GPIO_Pin_3
  15. #define LED3_Port  GPIOB
  16. #define LED3_Pin   GPIO_Pin_4
  17. #define LED4_Port  GPIOB
  18. #define LED4_Pin   GPIO_Pin_5
复制代码
2.jpg

 楼主| 一路向北lm 发表于 2020-4-22 11:47 | 显示全部楼层
再来串口测试,注意CN4引出的串口时串口2,初始化串口2代码如下:
  1. void UartInit_Loop(void)
  2. {
  3.     GPIO_InitTypeDef GPIO_InitStructure;
  4.     UART_InitTypeDef UART_InitStructure;

  5.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART2, ENABLE);
  6.     CFG_GPIO_Clock(GPIOA, ENABLE);

  7.     GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
  8.     GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
  9.     UART_StructInit(&UART_InitStructure);
  10.     UART_InitStructure.BaudRate = 115200;
  11.     //The word length is in 8-bit data format.
  12.     UART_InitStructure.WordLength = UART_WordLength_8b;
  13.     UART_InitStructure.StopBits = UART_StopBits_1;
  14.     //No even check bit.
  15.     UART_InitStructure.Parity = UART_Parity_No;
  16.     //No hardware data flow control.
  17.     UART_InitStructure.HWFlowControl = UART_HWFlowControl_None;
  18.     UART_InitStructure.Mode = UART_Mode_Rx | UART_Mode_Tx;

  19.     UART_Init(UART2, &UART_InitStructure);
  20.     UART_Cmd(UART2, ENABLE);

  21.     //UART2_TX   GPIOA.2
  22.     GPIO_StructInit(&GPIO_InitStructure);
  23.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  24.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  25.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  26.     GPIO_Init(GPIOA, &GPIO_InitStructure);

  27.     //UART2_RX    GPIOA.3
  28.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  29.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_FLOATING;
  30.     GPIO_Init(GPIOA, &GPIO_InitStructure);

  31.     UartSendGroup((u8*)printBuf, sprintf(printBuf, "UART OK!\r\n"));
  32. }
复制代码


 楼主| 一路向北lm 发表于 2020-4-22 11:48 | 显示全部楼层
串口2的发送数据函数
  1. //发送字符串函数
  2. void UartSendGroup(u8* buf, u16 len)
  3. {
  4.     while(len--)
  5.         UartSendByte(*buf++);
  6. }

  7. //发送字节函数
  8. void UartSendByte(u8 dat)
  9. {
  10.     UART_SendData(UART2, dat);
  11.     while(!UART_GetFlagStatus(UART2, UART_FLAG_TXEPT));
  12. }
复制代码


 楼主| 一路向北lm 发表于 2020-4-22 11:49 | 显示全部楼层
接上串口线,开始测试
1.jpg
 楼主| 一路向北lm 发表于 2020-4-22 11:49 | 显示全部楼层
已经可以打印数据啦…..
2.jpg

 楼主| 一路向北lm 发表于 2020-4-27 14:28 | 显示全部楼层
本帖最后由 一路向北lm 于 2020-4-28 16:43 编辑

调试完串口,下面开始测试ADC 啦!
ADC初始化函数如下:
  1. //使能ADC1的时钟
  2. void ADC_RCC_ClockSet(ADC_TypeDef* ADCx, FunctionalState NewState)
  3. {

  4.     if(ADCx == ADC1)
  5.           {
  6.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);                  
  7.      }
  8. }
  9. //
  10. static void ADCxSampleTimeConfig(ADC_TypeDef* ADCn, ADCSAM_TypeDef sampleTime)
  11. {
  12.     ADCn->CFGR &= ~ADC_CFGR_SAMCTL;
  13.     ADCn->CFGR |= sampleTime;
  14. }
  15. //ADC1外设初始化
  16. void ADC1BasicConfigWithParameter(void)
  17. {
  18.     ADC_InitTypeDef  ADC_InitStructure;
  19.     ADC_TypeDef* ADCn;
  20.     ADCn = ADC1;
  21.     ADC_StructInit(&ADC_InitStructure);

  22.     ADC_RCC_ClockSet(ADCn,ENABLE);                                                

  23.     ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  24.     ADC_InitStructure.ADC_PRESCARE=ADC_PCLK2_PRESCARE_16;                     //ADC prescale factor
  25.     ADC_InitStructure.ADC_Mode=ADC_Mode_Continue;                             //Set ADC mode to continuous conversion mode
  26. ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;                     
  27. //AD data right-justified
  28.     ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
  29.     ADC_Init(ADCn, &ADC_InitStructure);
  30.     ADCxSampleTimeConfig(ADCn, ADC_Samctl_13_5);
  31.     ADC_Cmd(ADCn,ENABLE);                                                      //Enable AD conversion
  32. }

  33. void ADCxChannelEnable(ADC_TypeDef* ADCn, u32 channel)
  34. {
  35.     ADCn->CHSR &= ~(1 << channel);
  36.     ADCn->CHSR |=  (1 << channel);
  37. }

  38. void ADC1ChannelConfigWithParameter(void)
  39. {
  40.     ADC_TypeDef* ADCn;
  41.     ADCn = ADC1;
  42.     ADCxChannelEnable(ADCn, ADC_Channel_1);
  43. //    ADCxChannelEnable(ADCn,ADC_Channel_1);
  44. //    ADCxChannelEnable(ADCn,ADC_Channel_2);
  45. //    ADCxChannelEnable(ADCn,ADC_Channel_3);
  46. }


  47. void ADCxAssignPin(GPIO_TypeDef* GPIOx, u16 pin)
  48. {
  49.     GPIO_InitTypeDef GPIO_InitStructure;
  50.     GPIO_StructInit(&GPIO_InitStructure);
  51.     CFG_GPIO_Clock(GPIOx, ENABLE);
  52.     GPIO_InitStructure.GPIO_Pin  =  pin;
  53.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                           //Output speed
  54.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;                               //GPIO mode
  55.     GPIO_Init(GPIOx, &GPIO_InitStructure);
  56. }

  57. unsigned int ADC1_SingleChannel_Get(void)
  58. {
  59.     u16 puiADData;
  60.     ADC_SoftwareStartConvCmd(ADC1, ENABLE);                                     //Software start conversion
  61.     while(ADC_GetFlagStatus(ADC1, ADC_IT_EOC) == 0);
  62.     ADC_ClearFlag(ADC1, ADC_IT_EOC);
  63.     puiADData = ADC_GetConversionValue(ADC1);
  64.     return puiADData;
  65. }

  66. unsigned int Get_Adc_Average(uint8_t times)
  67. {
  68.     u32 temp_val = 0;
  69.     u8 t;
  70.     u8 delay;
  71.     for(t = 0; t < times; t++) {
  72.         temp_val += ADC1_SingleChannel_Get();
  73.         for(delay = 0; delay < 100; delay++);
  74.     }
  75.     return temp_val / times;
  76. }

  77. void ADC1PinConfigWithParameter(void)
  78. {
  79.     //customer can change below config based Pin assign
  80.     //sample No.1
  81.     ADCxAssignPin(GPIOA, GPIO_Pin_1);
  82.     //ADCxAssignPin(GPIOA, GPIO_Pin_4);
  83.     //ADCxAssignPin(GPIOA, GPIO_Pin_5);
  84.     //sample No.2
  85.     //ADCxAssignPin(GPIOA, GPIO_Pin_4);
  86.     //ADCxAssignPin(GPIOA, GPIO_Pin_5);
  87.     //ADCxAssignPin(GPIOA, GPIO_Pin_6);
  88. }
复制代码


wziyi 发表于 2020-4-27 18:05 | 显示全部楼层
不是丝印错了,是官方提供的软件是别的片子的
 楼主| 一路向北lm 发表于 2020-4-27 21:33 | 显示全部楼层
wziyi 发表于 2020-4-27 18:05
不是丝印错了,是官方提供的软件是别的片子的

应该是的哈
 楼主| 一路向北lm 发表于 2020-4-28 16:43 | 显示全部楼层
读取板卡上Ain0 RV1电位器ADC数据,具体·函数如下:
  1. int main(void)
  2. {
  3.         unsigned int ADCVAL;
  4.         float fValue;
  5.     delay_init();
  6.     LED_Init();
  7.     UartInit_Loop();
  8.         ADC1BasicConfigWithParameter();
  9.     ADC1ChannelConfigWithParameter();
  10.     ADC1PinConfigWithParameter();
  11.     while(1)
  12.                 {
  13.                         delay_ms(300);
  14.             LED1_TOGGLE();
  15.                         ADCVAL = Get_Adc_Average(5);
  16.                         UartSendGroup((u8*)printBuf, sprintf(printBuf, "The AD value:"));
  17.                         UartSendByte(ADCVAL%10000/1000+0x30);
  18.                         UartSendByte(ADCVAL%1000/100+0x30);
  19.                         UartSendByte(ADCVAL%100/10+0x30);
  20.                         UartSendByte(ADCVAL%10+0x30);
  21.                         UartSendByte('\n');
  22.     }
  23. }
复制代码


 楼主| 一路向北lm 发表于 2020-4-28 16:45 | 显示全部楼层
串口ADC的打印结果:
1.png

 楼主| 一路向北lm 发表于 2020-5-3 17:55 | 显示全部楼层
3.移植RT-Thread到MM32L0平台
准备工作:RT-Thread 源码 MM32串口工程。
RT-Thread Nano 源码获取, Nano 去除了各种开发板的 BSP,保留了 OS 核心功能。下载地址:https://www.rt-thread.org/download/nano/rt-thread-3.1.3.zip下载好的 RT-Thread PackageRT-Thread Package 容量很小,我们直接将安装在 KEILPACK 目录下,然后将整个 RT-Thread 文件夹拷贝到我们的MM32串口工程里面。RT-Thread 文件夹目录如下:
1.png




 楼主| 一路向北lm 发表于 2020-5-3 17:55 | 显示全部楼层
BSP:板级支持包;
components/finsh: RT-Thread 组件;
include: 头文件;
libcpu: 与处理器相关的接口文件;
src: RT-Thread 内核源码
 楼主| 一路向北lm 发表于 2020-5-3 17:56 | 显示全部楼层
MM32串口工程上新建 RT-Thread 文件夹,并在该文件夹下新建 RT-Thread-Port、
RT-Thread-Source和 RT-Thread-Include 文件夹。
2.png

 楼主| 一路向北lm 发表于 2020-5-3 17:57 | 显示全部楼层
将RT-Thread/3.1.3/src文件夹下的所有文件复制到新建的 RT-Thread-Source文件夹中。
3.png

 楼主| 一路向北lm 发表于 2020-5-3 17:58 | 显示全部楼层
将路径 RT-Thread/3.1.3/libcpu/arm/cortex-m0/文件夹下的 context_rvds.S 文件和cpuport.c 文件复制到新建的 RT-Thread-Port 文件夹中。
4.png

 楼主| 一路向北lm 发表于 2020-5-3 17:59 | 显示全部楼层
将路径RT-Thread\3.1.3\components\finsh 文件夹复制到新建的RT-Thread-Include 文件夹中,将路径 RT-Thread\3.1.3\include文件夹下的内容复制到新建的 RT-Thread-Include文件夹中。
5.png

您需要登录后才可以回帖 登录 | 注册

本版积分规则

293

主题

3837

帖子

81

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