问什么数据读出正常,,而写入不正常总是死机。用的是原子哥的stmflash.c文件没有经过修改
[mw_shl_code=cpp,true]/*********************************************************************
* *
* 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 "GUIB.h"
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "GUI.h"
#include "WM.h"
#include "DIALOG.h"
#include "ds18b20.h"
#include "stmflash.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
#define ID_BUTTON_1 (GUI_ID_USER + 0x02)
#define ID_EDIT_0 (GUI_ID_USER + 0x03)
#define ID_BUTTON_2 (GUI_ID_USER + 0x04)
#define ID_EDIT_1 (GUI_ID_USER + 0x05)
#define ID_BUTTON_3 (GUI_ID_USER + 0x06)
#define ID_TEXT_0 (GUI_ID_USER + 0x07)
#define ID_TEXT_1 (GUI_ID_USER + 0x08)
#define ID_TEXT_2 (GUI_ID_USER + 0x09)
#define ID_BUTTON_4 (GUI_ID_USER + 0x0A)
#define ID_EDIT_2 (GUI_ID_USER + 0x0D)
#define ID_BUTTON_5 (GUI_ID_USER + 0x0E)
int qd;
int tz;
int gw;
int sj;
//开机FLASH数据读出
void sjdq (void)
{
static int i=1;
if (i)
{
STMFLASH_Read(xhqd,(u32*)&qd,1);
STMFLASH_Read(xhtz,(u32*)&tz,1);
STMFLASH_Read(xhgw,(u32*)&gw,1);
i++;
}
if (qd>=1000)
{
qd=1;
}
if (tz>=1000)
{
tz=2;
}
// if(gw>=1000)
//{
// gw=3;
//}
return ;
}
//数据写入FLSAH
void sjxr (void)
{
static int z=1;
int qdf;
int tzf;
int gwf;
qdf=1;
tzf=tzx();
gwf=gwx();
if(z)
{
STMFLASH_Write(xhqd,(u32*)&qdf,1);
//STMFLASH_Write(xhtz,(u32*)&tzf,1);
// STMFLASH_Write(xhgw,(u32*)&gwf,1);
//
z++;
}
return ;
}
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, -1, 1, 800, 480, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 301, 175, 40, 30, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_1, 419, 177, 40, 30, 0, 0x0, 0 },
{ EDIT_CreateIndirect, "Edit", ID_EDIT_0, 353, 175, 50, 30, 0, 0x64, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_2, 481, 181, 40, 30, 0, 0x0, 0 },
{ EDIT_CreateIndirect, "Edit", ID_EDIT_1, 537, 179, 50, 30, 0, 0x64, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_3, 598, 181, 40, 30, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "Text", ID_TEXT_0, 335, 95, 222, 44, 0, 0x64, 0 },
{ TEXT_CreateIndirect, "Text", ID_TEXT_1, 64, 172, 230, 39, 0, 0x64, 0 },
{ TEXT_CreateIndirect, "Text", ID_TEXT_2, 73, 238, 177, 32, 0, 0x64, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_4, 300, 236, 40, 30, 0, 0x0, 0 },
{ EDIT_CreateIndirect, "Edit", ID_EDIT_2, 353, 235, 50, 30, 0, 0x1e, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_5, 419, 232, 40, 30, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
// USER START (Optionally insert additional static code)
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _BkCallback(WM_MESSAGE *pMsg)
{
static WM_HWIN hWin;
static WM_HWIN hEdit;
static U8 text;
WM_HWIN hItem;
static char wang[5];
switch(pMsg->MsgId)
{
case WM_PAINT:
hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
EDIT_SetDecMode(hItem,qdx(),0,100,0,0);
hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_1);
EDIT_SetDecMode(hItem,tzx(),0,100,0,0);
hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_2);
EDIT_SetDecMode(hItem,gwx(),0,100,0,0);
}
}
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
int NCode;
int Id;
static char wang[5];
// USER START (Optionally insert additional variables)
// USER END
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetText(hItem, "+1");
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
BUTTON_SetText(hItem, "-1");
//
// Initialization of 'Edit'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
EDIT_SetDecMode(hItem,qd,0,999,0,0);
EDIT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
EDIT_SetTextColor(hItem, EDIT_CI_ENABLED, 0x00000000);
EDIT_SetFont(hItem, GUI_FONT_24_1);
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
BUTTON_SetText(hItem, "+1");
//
// Initialization of 'Edit'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_1);
EDIT_SetDecMode(hItem,tz,0,100,0,0);
EDIT_SetFont(hItem, GUI_FONT_24_1);
EDIT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_3);
BUTTON_SetText(hItem, "-1");
//
// Initialization of 'Text'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
TEXT_SetText(hItem, "ji re she zhi");
TEXT_SetFont(hItem, GUI_FONT_32_1);
//
// Initialization of 'Text'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
TEXT_SetTextColor(hItem, 0x00000000);
TEXT_SetFont(hItem, GUI_FONT_32_1);
TEXT_SetText(hItem, "wen cha xun huan");
//
// Initialization of 'Text'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
sprintf(wang,"%d",gw);
TEXT_SetFont(hItem, GUI_FONT_24_1);
TEXT_SetText(hItem, wang);
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_4);
BUTTON_SetText(hItem, "+1");
//
// Initialization of 'Edit'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_2);
EDIT_SetDecMode(hItem,gw,0,100,0,0);
EDIT_SetFont(hItem, GUI_FONT_24_1);
EDIT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_5);
BUTTON_SetText(hItem, "-1");
// USER START (Optionally insert additional code for further widget initialization)
// USER END
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_BUTTON_0: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
qd++;
//sj=1;
break;
case WM_NOTIFICATION_RELEASED:
sjxr(); //调用数据写入函数 就在这个地方进去就出不来了,死机。
WM_InvalidateWindow(WM_HBKWIN);
break;
}
break;
case ID_BUTTON_1: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
qd--;
sjxr();
break;
case WM_NOTIFICATION_RELEASED:
//sj=1;
WM_InvalidateWindow(WM_HBKWIN);
break;
}
break;
case ID_EDIT_0: // Notifications sent by 'Edit'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
break;
case WM_NOTIFICATION_VALUE_CHANGED:
break;
}
break;
case ID_BUTTON_2: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
tz++;
//sjxr();
break;
case WM_NOTIFICATION_RELEASED:
WM_InvalidateWindow(WM_HBKWIN);
break;
}
break;
case ID_EDIT_1: // Notifications sent by 'Edit'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
break;
case WM_NOTIFICATION_VALUE_CHANGED:
break;
}
break;
case ID_BUTTON_3: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
tz--;
// sjxr();
break;
case WM_NOTIFICATION_RELEASED:
WM_InvalidateWindow(WM_HBKWIN);
break;
}
break;
case ID_BUTTON_4: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
gw++;
break;
case WM_NOTIFICATION_RELEASED:
// sjxr();
WM_InvalidateWindow(WM_HBKWIN);
break;
}
break;
case ID_EDIT_2: // Notifications sent by 'Edit'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
break;
case WM_NOTIFICATION_VALUE_CHANGED:
break;
}
break;
case ID_BUTTON_5: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
gw--;
break;
case WM_NOTIFICATION_RELEASED:
// sjxr();
WM_InvalidateWindow(WM_HBKWIN);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateFramewin
*/
WM_HWIN xunhuanshezhi(void)
{
WM_HWIN hWin;
WM_SetCallback(WM_HBKWIN,_BkCallback);
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
return hWin;
}
// USER START (Optionally insert additional public code)
// USER END
/*************************** End of file ****************************/
int qdx (void)
{
return qd;
}
int tzx (void)
{
return tz;
}
int gwx (void)
{
return gw;
}
int sjx (void)
{
return sj;
}
[/mw_shl_code]
调用数据写入函数时通过一步一步的调试好像是死机到 stm32f4xx_flash.c 的第507行函数 status = FLASH_WaitForLastOperation();
这是怎么回事啊!
if(status == FLASH_COMPLETE)
{
/* if the previous operation is completed, proceed to erase the sector */
FLASH->CR &= CR_PSIZE_MASK;
FLASH->CR |= tmp_psize;
FLASH->CR &= SECTOR_MASK;
FLASH->CR |= FLASH_CR_SER | FLASH_Sector;
FLASH->CR |= FLASH_CR_STRT;
/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(); // 就死在这一行里
/* if the erase operation is completed, disable the SER Bit */
FLASH->CR &= (~FLASH_CR_SER);
FLASH->CR &= SECTOR_MASK;
}
/* Return the Erase Status */
return status;
}
我看了好长时间书,不知道操作系统怎么上锁。请教大师一下用哪个函数
一周热门 更多>