完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
调试程序发现程序卡死在hParent=TREEVIEW_Getitem(hTree, hNode, TREEVIEW_GET_PARENT);里,直接进入
void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } 程序: /********************************************************************* * * * SEGGER Microcontroller GmbH & Co. KG * * Solutions for real time microcontroller applications * * * ********************************************************************** * * * C-file generated by: * * * * GUI_Builder for emWin version 5.22 * * Compiled Jul 4 2013, 15:16:01 * * (c) 2013 Segger Microcontroller GmbH & Co. KG * * * ********************************************************************** * * * Internet: www.segger.com Support: support@segger.com * * * ********************************************************************** */ // USER START (Optionally insert additional includes) // USER END #include "DIALOG.h" #include "MyTask.h" #define FILE_PATH_MAX _MAX_LFN + 1 //#define FileBrowerList "0:/SYSTEM/ConfigFile/FileBrowerList.txt" static WM_HWIN hWin_parent; /********************************************************************* * * Defines * ********************************************************************** */ #define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00) #define ID_TREEVIEW_0 (GUI_ID_USER + 0x01) /********************************************************************* * * Static data * ********************************************************************** */ /************************************************************************************ *函数: ScanFiles *作者: alan *日期: 2014.07.07 *参数: path:遍历路径名 hFile:记录文件路径的文件指针结构体 *返回: None *描述: 遍历此文件夹及子文件夹下所有文件 ************************************************************************************/ static FRESULT ScanFiles(char* path,WM_HWIN hTree, TREEVIEW_ITEM_Handle hNode,FILE_TYPE fileType,u32 *fileNum) { FRESULT res; FILINFO fno; DIR dir; UINT rw; int i; char *fn; /* This function is assuming non-Unicode cfg. */ char file_name[FILE_PATH_MAX]={0}; TREEVIEW_ITEM_Handle hItem; #if _USE_LFN static char lfn[FILE_PATH_MAX]={0}; /* Buffer to store the LFN */ fno.lfname = lfn; fno.lfsize = sizeof(lfn); #endif res = f_opendir(&dir, (const TCHAR*)path); /* Open the directory */ if (res == FR_OK) { i = strlen((const char*)path); for (;;) { res = f_readdir(&dir, &fno); /* Read a directory item */ if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ if (fno.fname[0] == '.') continue; /* Ignore dot entry */ //忽略上级目录 #if _USE_LFN fn = *fno.lfname ? fno.lfname : fno.fname; #else fn = fno.fname; #endif if (fno.fattrib & AM_DIR) /* It is a directory */ { if(hTree != NULL &&hNode != NULL) { //目录,创建结点 hItem = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE,fn,0); //把结点加入到目录树中 TREEVIEW_AttachItem(hTree,hItem,hNode,TREEVIEW_INSERT_FIRST_CHILD); } //在路径最后添加文件夹路径名 sprintf(&path, "/%s", fn); //遍历此新文件夹下的文件 res = ScanFiles(path,hTree,hItem,fileType,fileNum); if (res != FR_OK) break;//打开失败,跳出循环 path = 0;//末尾添加结束字符 } else /* It is a file. */ { if(fileType == TEXTFILE ) { //判断如果不是txt文件,跳出本函数 if(!(strstr(fn,".txt")||strstr(fn,".TXT") ||strstr(fn,".c")||strstr(fn,".c") ||strstr(fn,".cpp")||strstr(fn,".CPP") ||strstr(fn,".h")||strstr(fn,".h"))) { return res; } } //判断如果不是Image文件,跳出本函数 else if(fileType ==IMAGEFILE) { if(!(strstr(fn,".bmp")||strstr(fn,".BMP")|| strstr(fn,".jpg")||strstr(fn,".JPG")|| strstr(fn,".gif")||strstr(fn,".GIF")|| strstr(fn,".png")||strstr(fn,".PNG"))) { return res; } } /* 根据要求是否创建目录树 */ if(hTree != NULL &&hNode != NULL)//创建目录树 { hItem = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_LEAF,fn,0);//文件,创建树叶 TREEVIEW_AttachItem(hTree,hItem,hNode,TREEVIEW_INSERT_FIRST_CHILD);//把树叶添加到目录树 // (*fileNum)++;//记录文件数目 } else { (*fileNum)++;//记录文件数目 } } } f_closedir(&dir); } return res; } void Fill_FileList(char *path,WM_HWIN hTree, TREEVIEW_ITEM_Handle hNode,FILE_TYPE fileType,u32 *fileNum) { TREEVIEW_ITEM_Handle hTreeItem_Flash; TREEVIEW_ITEM_Handle hTreeItemCur; char p_path[FILE_PATH_MAX]={0}; //目录名 指针 //FILhFile; //文件句柄 FRESULT fres; //返回结果 hTreeItemCur=hNode; strcpy(p_path,path); //复制目录名到指针 fres = ScanFiles(p_path,hTree,hNode,fileType,fileNum); //递归扫描文件 hTreeItem_Flash = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "Flash[1:]", 0); TREEVIEW_AttachItem(hTree, hTreeItem_Flash, hTreeItemCur, TREEVIEW_INSERT_BELOW); strcpy(p_path,"1:"); //复制目录名到指针 fres = ScanFiles(p_path,hTree,hTreeItem_Flash,fileType,fileNum); //递归扫描文件 } /********************************************************************* * * _aDialogCreate */ static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { { FRAMEWIN_CreateIndirect, "FileBrower", ID_FRAMEWIN_0, 0, 0, 240, 320, 0, 0x64, 0 }, { TREEVIEW_CreateIndirect, "Treeview", ID_TREEVIEW_0, 0, 0, 230, 293, 0, 0x0, 0 }, }; /********************************************************************* * * Static code * ********************************************************************** */ // USER START (Optionally insert additional static code) void get_pathname(WM_HWIN hTree,TREEVIEW_ITEM_Handle hNode,u8* path) { u8 hItemname[100]={0}; u8 len=0; TREEVIEW_ITEM_Handle hParent; TREEVIEW_ITEM_GetText(hNode,hItemname,100);//当前句柄的文本 if((0!=strcmp((char*)hItemname,"SDCard[0:]"))&& (0!=strcmp((char*)hItemname,"Flash[1:]")))//不是根目录 { hParent=TREEVIEW_GetItem(hTree, hNode, TREEVIEW_GET_PARENT);//父句柄 get_pathname(hTree, hParent,path); } else { if(0==strcmp((char*)hItemname,"SDCard[0:]")) sprintf((char*)path,"%s","0:"); else if(0==strcmp((char*)hItemname,"Flash[1:]")) sprintf((char*)path,"%s","1:"); return; } len=strlen((char*)path); sprintf((char*)(path+len),"/%s",hItemname); } // USER END /********************************************************************* * * _cbDialog */ static void _cbDialog(WM_MESSAGE * pMsg) { TREEVIEW_ITEM_Handle hTreeItem_SDCard; TREEVIEW_ITEM_Handle hTreeItemCur; TREEVIEW_ITEM_INFO ItemInfo; TREEVIEW_ITEM_Handle hNode; WM_HWIN hItem; WM_HWIN hTree; int NCode; int Id; u32 FileNum=0; u8 *pathname; GUI_HMEM hMem_pathname; switch (pMsg->MsgId) { case WM_INIT_DIALOG: // // Initialization of 'FileBrower' // hItem = pMsg->hWin; FRAMEWIN_SetFont(hItem, &GUI_FontHZ16); FRAMEWIN_SetTitleHeight(hItem, 20); FRAMEWIN_SetText(hItem, "FileBrower"); FRAMEWIN_AddCloseButton(hItem, FRAMEWIN_BUTTON_RIGHT, 0); FRAMEWIN_AddMaxButton(hItem, FRAMEWIN_BUTTON_RIGHT, 1); FRAMEWIN_AddMinButton(hItem, FRAMEWIN_BUTTON_RIGHT, 2); FRAMEWIN_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER); FRAMEWIN_SetTextColor(hItem, 0x00000000); // // Initialization of 'Treeview' // hTree = WM_GetDialogItem(pMsg->hWin, ID_TREEVIEW_0); TREEVIEW_SetAutoScrollV(hTree, 1); //使用自动滑动条 TREEVIEW_SetAutoScrollH(hTree, 1); //使用自动滑动条 TREEVIEW_SetSelMode(hTree, TREEVIEW_SELMODE_ROW); TREEVIEW_SetFont(hTree,&GUI_FontHZ16); hTreeItemCur = TREEVIEW_GetItem(hTree, 0, TREEVIEW_GET_LAST); hTreeItem_SDCard = TREEVIEW_ITEM_Create(TREEVIEW_ITEM_TYPE_NODE, "SDCard[0:]", 0); TREEVIEW_AttachItem(hTree, hTreeItem_SDCard, hTreeItemCur, TREEVIEW_INSERT_BELOW); //FLASH Fill_FileList("0:",hTree,hTreeItem_SDCard,ALLFILE,&FileNum); break; case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; switch(Id) { case ID_TREEVIEW_0: // Notifications sent by 'Treeview' /* 查看选中了哪个项目 */ hNode = TREEVIEW_GetSel(pMsg->hWinSrc); /* 获取该项目的信息 */ TREEVIEW_ITEM_GetInfo(hNode,&ItemInfo); switch(NCode) { case WM_NOTIFICATION_CLICKED: break; case WM_NOTIFICATION_RELEASED: if(ItemInfo.IsNode == 0)//点击的是目录树的叶子(即文件) { hMem_pathname = GUI_ALLOC_AllocZero(256); pathname = GUI_ALLOC_h2p(hMem_pathname); get_pathname(hTree, hNode,pathname); printf("rn%srn",pathname); GUI_ALLOC_Free(hMem_pathname); } break; case WM_NOTIFICATION_MOVED_OUT: break; case WM_NOTIFICATION_SEL_CHANGED: break; } break; } break; default: WM_DefaultProc(pMsg); break; } } /********************************************************************* * * Public code * ********************************************************************** */ /********************************************************************* * * CreateFileBrower */ void CreateFileBrower(WM_HWIN hWin); void CreateFileBrower(WM_HWIN hWin) { hWin_parent=hWin; GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0); } // USER START (Optionally insert additional public code) // USER END /*************************** End of file ****************************/ |
|
相关推荐
10个回答
|
|
void CreateFileBrower(WM_HWIN hWin);
void CreateFileBrower(WM_HWIN hWin) { hWin_parent=hWin; GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0); } 此处传入的hWin是传入父窗口句柄, GUI_CreateDialogBox 创建时的父窗口是WM_HBKWIN(桌面),前面的代码没认真看,我觉得应该是这里有问题。 |
|
|
|
|
|
|
|
进入这个HardFault_Handler里面,一般都是因为内存溢出、爆栈之类的
你试着分配大一点的GUI_ALLOC_SIZE(μc/GUI上面这个表示存储空间的大小) 或者你让你那个目录的元素稍微少一些,应该就不会出问题了 |
|
|
|
我用的是外部1MB内存
|
|
|
|
如果循环边界处理不好,陷入死循环,一直不停申请存储空间的话,最终导致爆栈,从而也会进入HardFault_Handler
你芯片的堆栈大小修改了吗?由于GUI中经常就是递归,所以系统预设的堆栈大小一般是不够的,需要改大一些 |
|
|
|
堆栈好像没改过,现在板子不能下载了!要先解决下载的问题。郁闷;
http://www.openedv.com/posts/list/0/37649.htm?privmsg=16045&&sysid=4#212790 你看下谢谢 |
|
|
|
|
|
|
|
我把堆栈都改为3Kbyte了,还是有问题。我把函数里的变量申请为静态变量后就好了,但是还有个问题就是,有时候我关掉窗口时会死掉。
现在有项目要做,搞GUI只能回家有空再搞了。 |
|
|
|
哎,有的片子,就是这么个毛病,总是容易堆栈溢出;GUI太消耗资源了
|
|
|
|
记号,学习了。
|
|
|
|
只有小组成员才能发言,加入小组>>
722 浏览 0 评论
1123 浏览 1 评论
2502 浏览 5 评论
2840 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2683 浏览 6 评论
使用eim外接fpga可是端口一点反应都没有有没有大哥指点一下啊
664浏览 9评论
679浏览 7评论
请教大神怎样去解决iMX6Q在linux3.0.35内核上做AP失败的问题呢
794浏览 6评论
641浏览 5评论
682浏览 5评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 02:57 , Processed in 0.957848 second(s), Total 97, Slave 77 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号