打印
[STM32F2]

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

[复制链接]
1063|15
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
STM32, se, pi, TE, IO
本帖最后由 yinwuqing110 于 2019-3-22 21:18 编辑

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

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

                GPIO_InitTypeDef GPIO_InitStructure;
                RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
                GPIO_InitStructure.GPIO_Pin         = GPIO_Pin_6 | GPIO_Pin_9;                                                           
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                  
                GPIO_InitStructure.GPIO_Mode         = GPIO_Mode_OUT;                                          
                GPIO_InitStructure.GPIO_PuPd         = GPIO_PuPd_NOPULL;
                GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
                GPIO_Init(GPIOB, &GPIO_InitStructure);                                                         
                GPIO_SetBits(GPIOB, GPIO_Pin_6 | GPIO_Pin_9);
                SystemInit();
               
                Init_Delay(16000);
                NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
                Get_ChipID();
                RNG_Init();               
                Serial_Init(9600);
                Gate_Init();
                TIM2_Init();
                TIM5_Init();
                Motor_Init();
                SX1505_Init();
                Keyboard_Init();
                lis3dh_init();
                RTCInit();
   
                read_config_info();
                Init_Delay(1000);
                check_read_config_info();
                IWDG_Configuration();
                gcIButton_Mode=0;
               
                if ( (1 != fDataBase.userD.mode) && (2 != fDataBase.userD.mode) )
                {
                                lockKeyboardTime       = fDataBase.errTime.time;
                                lock_Journal_count     = fDataBase.Journal.count;
                                g_cInputCodeLimitTimes = fDataBase.errTime.error;
                                
                                if((uint8_t)fDataBase.Door_Enable_flag == 0xFF)
                                {
                                                door_enable_temp = 0;
                                }
                                else
                                {
                                                door_enable_temp = fDataBase.Door_Enable_flag;
                                }
                                
                                if((uint8_t)fDataBase.Alarm_Number == 0xFF)
                                {
                                                alarm_num = 5;
                                }
                                else
                                {
                                                alarm_num = fDataBase.Alarm_Number;
                                }
                                
                                if(strlen(fDataBase.static_password) !=6 && (uint8_t)fDataBase.static_password[1] == 0xFF)
                                {
                                                strcpy(password_temp,"123456");
                                }
                                else        
                                {
                                                strcpy(password_temp,fDataBase.static_password);
                                }
                                
                                memset(lock_serial_temp,0,sizeof(lock_serial_temp));
                                memcpy(lock_serial_temp,fDataBase.FactoryD.Lock_Serial,12);
                                if(strlen(lock_serial_temp) != 12 || (uint8_t)lock_serial_temp[0] == 0xFF)         
                                {
                                                memset(lock_serial_temp,0,sizeof(lock_serial_temp));
                                                strcpy(lock_serial_temp,DEFAULT_LOCK_SERIAL);
                                }                                                                                       
                                
                                if(fDataBase.FactoryD.TempAlarmThreshold==0xFF)
                                {        
                                                gcTemperatureThreshold = 60;
                                }
                                else
                                {
                                                gcTemperatureThreshold = fDataBase.FactoryD.TempAlarmThreshold;
                                }
                                
                                if(fDataBase.FactoryD.ShakeAlarmThreshold==0xFF)
                                {
                                                gcShakeAlarmThreshold = 2;
                                }
                                else
                                {
                                                gcShakeAlarmThreshold = fDataBase.FactoryD.ShakeAlarmThreshold;
                                }
                                
                                for(i=0; i<FINGERPRINT_TOTAL; i++)
                                {
                                                fingerprintf_library[i] = fDataBase.fingerprint_library[i];
                                }
                                
                                if(0 == strncmp((char *)&fDataBase.EthD.local_ip,(char *)eth_lip_tempstore,4))
                                {
                                                eth_lip_tempstore[0] = 192;
                                                eth_lip_tempstore[1] = 168;
                                                eth_lip_tempstore[2] = 1;
                                                eth_lip_tempstore[3] = 100;
                                                
                                                eth_lnm_tempstore[0] = 255;
                                                eth_lnm_tempstore[1] = 255;
                                                eth_lnm_tempstore[2] = 255;
                                                eth_lnm_tempstore[3] = 0;
                                                
                                                eth_lgw_tempstore[0] = 192;
                                                eth_lgw_tempstore[1] = 168;
                                                eth_lgw_tempstore[2] = 1;
                                                eth_lgw_tempstore[3] = 1;
                                                
                                                eth_sip_tempstore[0] = 192;
                                                eth_sip_tempstore[1] = 168;
                                                eth_sip_tempstore[2] = 1;
                                                eth_sip_tempstore[3] = 113;
                                                
                                                dhcp_tempflag=0;
                                                l_tempport=1000;
                                                s_tempport=6000;
                                }
                                else
                                {
                                                eth_lip_tempstore[0] = fDataBase.EthD.local_ip[0];
                                                eth_lip_tempstore[1] = fDataBase.EthD.local_ip[1];
                                                eth_lip_tempstore[2] = fDataBase.EthD.local_ip[2];
                                                eth_lip_tempstore[3] = fDataBase.EthD.local_ip[3];
                                                
                                                eth_lnm_tempstore[0] = fDataBase.EthD.local_netmask[0];
                                                eth_lnm_tempstore[1] = fDataBase.EthD.local_netmask[1];
                                                eth_lnm_tempstore[2] = fDataBase.EthD.local_netmask[2];
                                                eth_lnm_tempstore[3] = fDataBase.EthD.local_netmask[3];
                                                
                                                eth_lgw_tempstore[0] = fDataBase.EthD.local_gw[0];
                                                eth_lgw_tempstore[1] = fDataBase.EthD.local_gw[1];
                                                eth_lgw_tempstore[2] = fDataBase.EthD.local_gw[2];
                                                eth_lgw_tempstore[3] = fDataBase.EthD.local_gw[3];
                                                
                                                eth_sip_tempstore[0] = fDataBase.EthD.server_ip[0];
                                                eth_sip_tempstore[1] = fDataBase.EthD.server_ip[1];
                                                eth_sip_tempstore[2] = fDataBase.EthD.server_ip[2];
                                                eth_sip_tempstore[3] = fDataBase.EthD.server_ip[3];
                                                
                                                dhcp_tempflag = fDataBase.EthD.dhcp_enable_flag;
                                                l_tempport    = fDataBase.EthD.local_port;
                                                s_tempport    = fDataBase.EthD.server_port;
                                }
                                
                                
                                memset(&fDataBase,0,sizeof(fDataBase));
                                Init_Delay(4000);
                                
                                memcpy(fDataBase.static_password,password_temp,6);
                                strcpy(fDataBase.FactoryD.Lock_Serial,lock_serial_temp);                                                                                                                                                                                                        
                                Init_Delay(100);
                                
                                fDataBase.errTime.time                                     = lockKeyboardTime;
                                fDataBase.errTime.error                                    = g_cInputCodeLimitTimes;
                                fDataBase.Journal.count                                    = lock_Journal_count;
                                fDataBase.Door_Enable_flag                              = door_enable_temp;
                                fDataBase.Alarm_Number                                 = alarm_num;
                                fDataBase.FactoryD.TempAlarmThreshold           = gcTemperatureThreshold;
                                fDataBase.FactoryD.ShakeAlarmThreshold           = gcShakeAlarmThreshold;

                                for(i=0; i<FINGERPRINT_TOTAL; i++)
                                {
                                    fDataBase.fingerprint_library[i] = fingerprintf_library[i];
                                }
                                
                                fDataBase.EthD.local_ip[0] = eth_lip_tempstore[0];
                                fDataBase.EthD.local_ip[1] = eth_lip_tempstore[1];
                                fDataBase.EthD.local_ip[2] = eth_lip_tempstore[2];
                                fDataBase.EthD.local_ip[3] = eth_lip_tempstore[3];
                                
                                fDataBase.EthD.local_netmask[0] = eth_lnm_tempstore[0];
                                fDataBase.EthD.local_netmask[1] = eth_lnm_tempstore[1];
                                fDataBase.EthD.local_netmask[2] = eth_lnm_tempstore[2];
                                fDataBase.EthD.local_netmask[3] = eth_lnm_tempstore[3];
                                
                                fDataBase.EthD.local_gw[0] = eth_lgw_tempstore[0];
                                fDataBase.EthD.local_gw[1] = eth_lgw_tempstore[1];
                                fDataBase.EthD.local_gw[2] = eth_lgw_tempstore[2];
                                fDataBase.EthD.local_gw[3] = eth_lgw_tempstore[3];
                                
                                fDataBase.EthD.server_ip[0] = eth_sip_tempstore[0];
                                fDataBase.EthD.server_ip[1] = eth_sip_tempstore[1];
                                fDataBase.EthD.server_ip[2] = eth_sip_tempstore[2];
                                fDataBase.EthD.server_ip[3] = eth_sip_tempstore[3];
                                
                                fDataBase.EthD.local_port       = l_tempport;
                                fDataBase.EthD.server_port      = s_tempport;
                                fDataBase.EthD.dhcp_enable_flag = dhcp_tempflag;

                }
                else
                {
                      uint32_t CRC32_temp=CRC32_ForBytes(fDataBase.FactoryD.Lock_Psk,LOCK_PSK_LEN);
                      if (CRC32_temp != fDataBase.FactoryD.Psk_CRC32)
                     {
                         gcPSK_flag=1;
                      }
                }
        
                gcTemperatureThreshold = fDataBase.FactoryD.TempAlarmThreshold;
                gcShakeAlarmThreshold  = fDataBase.FactoryD.ShakeAlarmThreshold;

               vSemaphoreCreateBinary(IR2AppSemaphore);
               vSemaphoreCreateBinary(DataSemaphore);
               vSemaphoreCreateBinary(LedAndBuzzerSemaphore);
               vSemaphoreCreateBinary(TcpRecvData_Sem);
               xSemaphoreTake(IR2AppSemaphore,0);
               xSemaphoreTake(DataSemaphore,0);
               xSemaphoreTake(LedAndBuzzerSemaphore,0);
               xSemaphoreTake(TcpRecvData_Sem,0);
               
              xTaskCreate(HTS221_Task, (const signed char *)"FGRD_Task", 200, NULL, 5, NULL);
   
              xTaskCreate(LIS3DH_Task, (const signed char *)"SAEF_Task", 200, NULL, 5, NULL);
   
             xTaskCreate(LIS3DH_Read_Task, (const signed char *)"HTDDR_Read_Task", 200, NULL, 5, NULL);
   
             xTaskCreate(TCP_RX_Data, (const signed char *)"INT_RX_Data", 2000, NULL, 5, NULL);
   
            xTaskCreate(ETH_RX_Data, (const signed char *)"EXT_RX_Data", 1200, NULL, 5, NULL);
   
             xTaskCreate(ElockMain,(const signed char *)"TOMain",1080,NULL,7,NULL);

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

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

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

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

            vTaskStartScheduler();
   
            for( ;; );
               
}



沙发
colin2135| | 2019-3-23 09:53 | 只看该作者
直接上代码太刚了哈,想多看看项目介绍。

使用特权

评论回复
板凳
yinwuqing110|  楼主 | 2019-3-23 10:41 | 只看该作者
colin2135 发表于 2019-3-23 09:53
直接上代码太刚了哈,想多看看项目介绍。

这个属于公司内部资源信息的,项目还在如火如荼的开展当中,项目其实就是跟我们的指纹锁差不多。附个主控原理图给你瞧瞧。

主控原理图.png (219.7 KB )

主控原理图.png

使用特权

评论回复
地板
21mengnan| | 2019-3-23 16:23 | 只看该作者
用32的很多

使用特权

评论回复
5
yinwuqing110|  楼主 | 2019-3-23 21:58 | 只看该作者

是啊,整个创新型行业都能看到STM32的影子,跟着时代的步伐走。我们开发也要求多了解使用STM32,创新产品驱动力,才能不被时代所淘汰嘛。

使用特权

评论回复
6
小灵通2018| | 2019-3-23 23:15 | 只看该作者
32市场占有率很高的

使用特权

评论回复
7
heimaojingzhang| | 2019-4-9 11:28 | 只看该作者
医疗器械使用的吗

使用特权

评论回复
8
guanjiaer| | 2019-4-9 11:29 | 只看该作者
着实不错啊

使用特权

评论回复
9
观海| | 2019-4-9 11:44 | 只看该作者
现在智能门锁成熟吗

使用特权

评论回复
10
八层楼| | 2019-4-9 11:52 | 只看该作者
相当不错的项目

使用特权

评论回复
11
jstiger| | 2019-4-11 11:01 | 只看该作者
为啥要用STM32F2系列?现在一般用F4比较多。

使用特权

评论回复
12
yinwuqing110|  楼主 | 2019-4-11 15:52 | 只看该作者
jstiger 发表于 2019-4-11 11:01
为啥要用STM32F2系列?现在一般用F4比较多。

产品还是比较抵挡一点,用F4系列的成本相对高一些。

使用特权

评论回复
13
pklong| | 2019-4-11 22:43 | 只看该作者
这个是摄像头的设计吗?            

使用特权

评论回复
14
htmlme| | 2019-4-11 22:43 | 只看该作者
网络远程控制电机需要什么驱动吗?  

使用特权

评论回复
15
yinwuqing110|  楼主 | 2019-4-12 08:53 | 只看该作者
htmlme 发表于 2019-4-11 22:43
网络远程控制电机需要什么驱动吗?

不需要的,只要密码匹配,控制GPIO口就可以啦的!

使用特权

评论回复
16
xiaoliusheng| | 2019-4-12 09:26 | 只看该作者
32用的多,应该是他有库,容易上手,可以缩短开发周期短。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

94

主题

1005

帖子

6

粉丝