[STM32F2] 【ST春季狂晒+当前项目开发中用的STM32】

[复制链接]
1927|15
 楼主| yinwuqing110 发表于 2019-3-22 21:02 | 显示全部楼层 |阅读模式
STM32, se, pi, TE, IO
本帖最后由 yinwuqing110 于 2019-3-22 21:18 编辑

       最近工作比较忙的,也挤点时间来支持支持活动。我现在在从事智能门锁的项目开发,用到的STM32型号是STM32F215RGT6,STM32作为主控,实现网络远程控制电机的开启与关闭。晒张图片如下:  
STM32F215RGT6.jpg    
       我们在这个项目中也用到W5500作为连接远程服务器的外设,还有划时代特色的指静脉仪设备。

       我们来看看main函数吧,这个是运行在freeRTOS操作系统的,希望早日能够熟练掌握STM32的应用开发。祝福ST在深举办的峰会红红火火,希望ST举办越来越多的优惠活动!
  1. int main(int argc,char *argv[])
  2. {
  3.                 char lock_serial_temp[16]={0};
  4.                 char password_temp[8]={0};
  5.                 char door_enable_temp=0,alarm_num=0,i=0;
  6.                 uint8_t fingerprintf_library[FINGERPRINT_TOTAL]={0};
  7.                 uint8_t  dhcp_tempflag=0;               
  8.                 uint8_t eth_lip_tempstore[4]={0xFF,0xFF,0xFF,0xFF};
  9.                 uint8_t eth_lnm_tempstore[4]={0xFF,0xFF,0xFF,0xFF};
  10.                 uint8_t eth_lgw_tempstore[4]={0xFF,0xFF,0xFF,0xFF};
  11.                 uint8_t eth_sip_tempstore[4]={0xFF,0xFF,0xFF,0xFF};
  12.                 uint16_t l_tempport=0;
  13.                 uint16_t s_tempport=0;
  14.                 uint32_t lockKeyboardTime = 0;
  15.                 uint32_t lock_Journal_count=0;

  16.                 GPIO_InitTypeDef GPIO_InitStructure;
  17.                 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  18.                 GPIO_InitStructure.GPIO_Pin         = GPIO_Pin_6 | GPIO_Pin_9;                                                           
  19.                 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                  
  20.                 GPIO_InitStructure.GPIO_Mode         = GPIO_Mode_OUT;                                          
  21.                 GPIO_InitStructure.GPIO_PuPd         = GPIO_PuPd_NOPULL;
  22.                 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  23.                 GPIO_Init(GPIOB, &GPIO_InitStructure);                                                         
  24.                 GPIO_SetBits(GPIOB, GPIO_Pin_6 | GPIO_Pin_9);
  25.                 SystemInit();
  26.                
  27.                 Init_Delay(16000);
  28.                 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
  29.                 Get_ChipID();
  30.                 RNG_Init();               
  31.                 Serial_Init(9600);
  32.                 Gate_Init();
  33.                 TIM2_Init();
  34.                 TIM5_Init();
  35.                 Motor_Init();
  36.                 SX1505_Init();
  37.                 Keyboard_Init();
  38.                 lis3dh_init();
  39.                 RTCInit();
  40.    
  41.                 read_config_info();
  42.                 Init_Delay(1000);
  43.                 check_read_config_info();
  44.                 IWDG_Configuration();
  45.                 gcIButton_Mode=0;
  46.                
  47.                 if ( (1 != fDataBase.userD.mode) && (2 != fDataBase.userD.mode) )
  48.                 {
  49.                                 lockKeyboardTime       = fDataBase.errTime.time;
  50.                                 lock_Journal_count     = fDataBase.Journal.count;
  51.                                 g_cInputCodeLimitTimes = fDataBase.errTime.error;
  52.                                 
  53.                                 if((uint8_t)fDataBase.Door_Enable_flag == 0xFF)
  54.                                 {
  55.                                                 door_enable_temp = 0;
  56.                                 }
  57.                                 else
  58.                                 {
  59.                                                 door_enable_temp = fDataBase.Door_Enable_flag;
  60.                                 }
  61.                                 
  62.                                 if((uint8_t)fDataBase.Alarm_Number == 0xFF)
  63.                                 {
  64.                                                 alarm_num = 5;
  65.                                 }
  66.                                 else
  67.                                 {
  68.                                                 alarm_num = fDataBase.Alarm_Number;
  69.                                 }
  70.                                 
  71.                                 if(strlen(fDataBase.static_password) !=6 && (uint8_t)fDataBase.static_password[1] == 0xFF)
  72.                                 {
  73.                                                 strcpy(password_temp,"123456");
  74.                                 }
  75.                                 else        
  76.                                 {
  77.                                                 strcpy(password_temp,fDataBase.static_password);
  78.                                 }
  79.                                 
  80.                                 memset(lock_serial_temp,0,sizeof(lock_serial_temp));
  81.                                 memcpy(lock_serial_temp,fDataBase.FactoryD.Lock_Serial,12);
  82.                                 if(strlen(lock_serial_temp) != 12 || (uint8_t)lock_serial_temp[0] == 0xFF)         
  83.                                 {
  84.                                                 memset(lock_serial_temp,0,sizeof(lock_serial_temp));
  85.                                                 strcpy(lock_serial_temp,DEFAULT_LOCK_SERIAL);
  86.                                 }                                                                                       
  87.                                 
  88.                                 if(fDataBase.FactoryD.TempAlarmThreshold==0xFF)
  89.                                 {        
  90.                                                 gcTemperatureThreshold = 60;
  91.                                 }
  92.                                 else
  93.                                 {
  94.                                                 gcTemperatureThreshold = fDataBase.FactoryD.TempAlarmThreshold;
  95.                                 }
  96.                                 
  97.                                 if(fDataBase.FactoryD.ShakeAlarmThreshold==0xFF)
  98.                                 {
  99.                                                 gcShakeAlarmThreshold = 2;
  100.                                 }
  101.                                 else
  102.                                 {
  103.                                                 gcShakeAlarmThreshold = fDataBase.FactoryD.ShakeAlarmThreshold;
  104.                                 }
  105.                                 
  106.                                 for(i=0; i<FINGERPRINT_TOTAL; i++)
  107.                                 {
  108.                                                 fingerprintf_library[i] = fDataBase.fingerprint_library[i];
  109.                                 }
  110.                                 
  111.                                 if(0 == strncmp((char *)&fDataBase.EthD.local_ip,(char *)eth_lip_tempstore,4))
  112.                                 {
  113.                                                 eth_lip_tempstore[0] = 192;
  114.                                                 eth_lip_tempstore[1] = 168;
  115.                                                 eth_lip_tempstore[2] = 1;
  116.                                                 eth_lip_tempstore[3] = 100;
  117.                                                 
  118.                                                 eth_lnm_tempstore[0] = 255;
  119.                                                 eth_lnm_tempstore[1] = 255;
  120.                                                 eth_lnm_tempstore[2] = 255;
  121.                                                 eth_lnm_tempstore[3] = 0;
  122.                                                 
  123.                                                 eth_lgw_tempstore[0] = 192;
  124.                                                 eth_lgw_tempstore[1] = 168;
  125.                                                 eth_lgw_tempstore[2] = 1;
  126.                                                 eth_lgw_tempstore[3] = 1;
  127.                                                 
  128.                                                 eth_sip_tempstore[0] = 192;
  129.                                                 eth_sip_tempstore[1] = 168;
  130.                                                 eth_sip_tempstore[2] = 1;
  131.                                                 eth_sip_tempstore[3] = 113;
  132.                                                 
  133.                                                 dhcp_tempflag=0;
  134.                                                 l_tempport=1000;
  135.                                                 s_tempport=6000;
  136.                                 }
  137.                                 else
  138.                                 {
  139.                                                 eth_lip_tempstore[0] = fDataBase.EthD.local_ip[0];
  140.                                                 eth_lip_tempstore[1] = fDataBase.EthD.local_ip[1];
  141.                                                 eth_lip_tempstore[2] = fDataBase.EthD.local_ip[2];
  142.                                                 eth_lip_tempstore[3] = fDataBase.EthD.local_ip[3];
  143.                                                 
  144.                                                 eth_lnm_tempstore[0] = fDataBase.EthD.local_netmask[0];
  145.                                                 eth_lnm_tempstore[1] = fDataBase.EthD.local_netmask[1];
  146.                                                 eth_lnm_tempstore[2] = fDataBase.EthD.local_netmask[2];
  147.                                                 eth_lnm_tempstore[3] = fDataBase.EthD.local_netmask[3];
  148.                                                 
  149.                                                 eth_lgw_tempstore[0] = fDataBase.EthD.local_gw[0];
  150.                                                 eth_lgw_tempstore[1] = fDataBase.EthD.local_gw[1];
  151.                                                 eth_lgw_tempstore[2] = fDataBase.EthD.local_gw[2];
  152.                                                 eth_lgw_tempstore[3] = fDataBase.EthD.local_gw[3];
  153.                                                 
  154.                                                 eth_sip_tempstore[0] = fDataBase.EthD.server_ip[0];
  155.                                                 eth_sip_tempstore[1] = fDataBase.EthD.server_ip[1];
  156.                                                 eth_sip_tempstore[2] = fDataBase.EthD.server_ip[2];
  157.                                                 eth_sip_tempstore[3] = fDataBase.EthD.server_ip[3];
  158.                                                 
  159.                                                 dhcp_tempflag = fDataBase.EthD.dhcp_enable_flag;
  160.                                                 l_tempport    = fDataBase.EthD.local_port;
  161.                                                 s_tempport    = fDataBase.EthD.server_port;
  162.                                 }
  163.                                 
  164.                                 
  165.                                 memset(&fDataBase,0,sizeof(fDataBase));
  166.                                 Init_Delay(4000);
  167.                                 
  168.                                 memcpy(fDataBase.static_password,password_temp,6);
  169.                                 strcpy(fDataBase.FactoryD.Lock_Serial,lock_serial_temp);                                                                                                                                                                                                        
  170.                                 Init_Delay(100);
  171.                                 
  172.                                 fDataBase.errTime.time                                     = lockKeyboardTime;
  173.                                 fDataBase.errTime.error                                    = g_cInputCodeLimitTimes;
  174.                                 fDataBase.Journal.count                                    = lock_Journal_count;
  175.                                 fDataBase.Door_Enable_flag                              = door_enable_temp;
  176.                                 fDataBase.Alarm_Number                                 = alarm_num;
  177.                                 fDataBase.FactoryD.TempAlarmThreshold           = gcTemperatureThreshold;
  178.                                 fDataBase.FactoryD.ShakeAlarmThreshold           = gcShakeAlarmThreshold;

  179.                                 for(i=0; i<FINGERPRINT_TOTAL; i++)
  180.                                 {
  181.                                     fDataBase.fingerprint_library[i] = fingerprintf_library[i];
  182.                                 }
  183.                                 
  184.                                 fDataBase.EthD.local_ip[0] = eth_lip_tempstore[0];
  185.                                 fDataBase.EthD.local_ip[1] = eth_lip_tempstore[1];
  186.                                 fDataBase.EthD.local_ip[2] = eth_lip_tempstore[2];
  187.                                 fDataBase.EthD.local_ip[3] = eth_lip_tempstore[3];
  188.                                 
  189.                                 fDataBase.EthD.local_netmask[0] = eth_lnm_tempstore[0];
  190.                                 fDataBase.EthD.local_netmask[1] = eth_lnm_tempstore[1];
  191.                                 fDataBase.EthD.local_netmask[2] = eth_lnm_tempstore[2];
  192.                                 fDataBase.EthD.local_netmask[3] = eth_lnm_tempstore[3];
  193.                                 
  194.                                 fDataBase.EthD.local_gw[0] = eth_lgw_tempstore[0];
  195.                                 fDataBase.EthD.local_gw[1] = eth_lgw_tempstore[1];
  196.                                 fDataBase.EthD.local_gw[2] = eth_lgw_tempstore[2];
  197.                                 fDataBase.EthD.local_gw[3] = eth_lgw_tempstore[3];
  198.                                 
  199.                                 fDataBase.EthD.server_ip[0] = eth_sip_tempstore[0];
  200.                                 fDataBase.EthD.server_ip[1] = eth_sip_tempstore[1];
  201.                                 fDataBase.EthD.server_ip[2] = eth_sip_tempstore[2];
  202.                                 fDataBase.EthD.server_ip[3] = eth_sip_tempstore[3];
  203.                                 
  204.                                 fDataBase.EthD.local_port       = l_tempport;
  205.                                 fDataBase.EthD.server_port      = s_tempport;
  206.                                 fDataBase.EthD.dhcp_enable_flag = dhcp_tempflag;

  207.                 }
  208.                 else
  209.                 {
  210.                       uint32_t CRC32_temp=CRC32_ForBytes(fDataBase.FactoryD.Lock_Psk,LOCK_PSK_LEN);
  211.                       if (CRC32_temp != fDataBase.FactoryD.Psk_CRC32)
  212.                      {
  213.                          gcPSK_flag=1;
  214.                       }
  215.                 }
  216.         
  217.                 gcTemperatureThreshold = fDataBase.FactoryD.TempAlarmThreshold;
  218.                 gcShakeAlarmThreshold  = fDataBase.FactoryD.ShakeAlarmThreshold;

  219.                vSemaphoreCreateBinary(IR2AppSemaphore);
  220.                vSemaphoreCreateBinary(DataSemaphore);
  221.                vSemaphoreCreateBinary(LedAndBuzzerSemaphore);
  222.                vSemaphoreCreateBinary(TcpRecvData_Sem);
  223.                xSemaphoreTake(IR2AppSemaphore,0);
  224.                xSemaphoreTake(DataSemaphore,0);
  225.                xSemaphoreTake(LedAndBuzzerSemaphore,0);
  226.                xSemaphoreTake(TcpRecvData_Sem,0);
  227.                
  228.               xTaskCreate(HTS221_Task, (const signed char *)"FGRD_Task", 200, NULL, 5, NULL);
  229.    
  230.               xTaskCreate(LIS3DH_Task, (const signed char *)"SAEF_Task", 200, NULL, 5, NULL);
  231.    
  232.              xTaskCreate(LIS3DH_Read_Task, (const signed char *)"HTDDR_Read_Task", 200, NULL, 5, NULL);
  233.    
  234.              xTaskCreate(TCP_RX_Data, (const signed char *)"INT_RX_Data", 2000, NULL, 5, NULL);
  235.    
  236.             xTaskCreate(ETH_RX_Data, (const signed char *)"EXT_RX_Data", 1200, NULL, 5, NULL);
  237.    
  238.              xTaskCreate(ElockMain,(const signed char *)"TOMain",1080,NULL,7,NULL);

  239.              xTaskCreate(AlarmTask,(const signed char *)"CLOCKTask",1200,NULL,5,NULL);

  240.             xTaskCreate(GetKeyboardKeypressValueTask, (const signed char *)"KeyboardValueTask", 520, NULL, 5, NULL);

  241.             xTaskCreate(DispalyAndPromptControlTask, (const signed char *)"DispalyTask", 128, NULL, 5, NULL);

  242.             xTaskCreate(BuzzerAndLedCycleTask, (const signed char *)"BuzzerAndLedTask", 200, NULL, 6, NULL);

  243.             vTaskStartScheduler();
  244.    
  245.             for( ;; );
  246.                
  247. }



colin2135 发表于 2019-3-23 09:53 | 显示全部楼层
直接上代码太刚了哈,想多看看项目介绍。
 楼主| yinwuqing110 发表于 2019-3-23 10:41 | 显示全部楼层
colin2135 发表于 2019-3-23 09:53
直接上代码太刚了哈,想多看看项目介绍。

这个属于公司内部资源信息的,项目还在如火如荼的开展当中,项目其实就是跟我们的指纹锁差不多。附个主控原理图给你瞧瞧。
主控原理图.png
21mengnan 发表于 2019-3-23 16:23 | 显示全部楼层
用32的很多
 楼主| yinwuqing110 发表于 2019-3-23 21:58 | 显示全部楼层

是啊,整个创新型行业都能看到STM32的影子,跟着时代的步伐走。我们开发也要求多了解使用STM32,创新产品驱动力,才能不被时代所淘汰嘛。
小灵通2018 发表于 2019-3-23 23:15 | 显示全部楼层
32市场占有率很高的
heimaojingzhang 发表于 2019-4-9 11:28 | 显示全部楼层
医疗器械使用的吗
guanjiaer 发表于 2019-4-9 11:29 | 显示全部楼层
着实不错啊
观海 发表于 2019-4-9 11:44 | 显示全部楼层
现在智能门锁成熟吗
八层楼 发表于 2019-4-9 11:52 | 显示全部楼层
相当不错的项目
jstiger 发表于 2019-4-11 11:01 | 显示全部楼层
为啥要用STM32F2系列?现在一般用F4比较多。
 楼主| yinwuqing110 发表于 2019-4-11 15:52 | 显示全部楼层
jstiger 发表于 2019-4-11 11:01
为啥要用STM32F2系列?现在一般用F4比较多。

产品还是比较抵挡一点,用F4系列的成本相对高一些。
pklong 发表于 2019-4-11 22:43 | 显示全部楼层
这个是摄像头的设计吗?            
htmlme 发表于 2019-4-11 22:43 | 显示全部楼层
网络远程控制电机需要什么驱动吗?  
 楼主| yinwuqing110 发表于 2019-4-12 08:53 | 显示全部楼层
htmlme 发表于 2019-4-11 22:43
网络远程控制电机需要什么驱动吗?

不需要的,只要密码匹配,控制GPIO口就可以啦的!
xiaoliusheng 发表于 2019-4-12 09:26 | 显示全部楼层
32用的多,应该是他有库,容易上手,可以缩短开发周期短。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

107

主题

1102

帖子

7

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