查看: 4709|回复: 5

[求助] Flash元件

[复制链接]

该用户从未签到

11

主题

29

帖子

0

注册会员

Rank: 2

积分
138
最后登录
1970-1-1
发表于 2014-12-5 15:55:32 | 显示全部楼层 |阅读模式
KL25 Freedom 平台测试 Flash_LDD ,完全copy help 中的例子代码,在main函数中测试OK,拿到TASK1中就读不出正确的数据呢?

我知道答案 目前已有5人回答
回复

使用道具 举报

该用户从未签到

11

主题

29

帖子

0

注册会员

Rank: 2

积分
138
最后登录
1970-1-1
 楼主| 发表于 2014-12-5 15:57:44 | 显示全部楼层
我用的是codewarrier 10.6
回复 支持 反对

使用道具 举报

该用户从未签到

145

主题

4926

帖子

0

金牌会员

Rank: 6Rank: 6

积分
9267
最后登录
1970-1-1
发表于 2014-12-5 20:35:25 | 显示全部楼层
楼主你好!
请问你的TASK1是怎么写的?
最好贴出部分代码,便于我们定位问题。
回复 支持 反对

使用道具 举报

该用户从未签到

11

主题

29

帖子

0

注册会员

Rank: 2

积分
138
最后登录
1970-1-1
 楼主| 发表于 2014-12-8 08:53:21 | 显示全部楼层
就在TASK1 while(1)之前,连续初始化 、写、读FLASH, 最后DEBUG发现,写的时候,对应地址段数据是
FFFFFF20,不真确,我尝试过很多方法,始终不明白换了个位置,就写不真确是怎么回事。
回复 支持 反对

使用道具 举报

  • TA的每日心情
    难过
    2021-12-15 16:01
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    305

    主题

    4701

    帖子

    0

    中级会员

    Rank: 3Rank: 3

    积分
    377
    最后登录
    2023-8-16
    发表于 2014-12-8 10:42:32 | 显示全部楼层
    楼主,代码发一下吧。
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    11

    主题

    29

    帖子

    0

    注册会员

    Rank: 2

    积分
    138
    最后登录
    1970-1-1
     楼主| 发表于 2014-12-9 10:33:39 | 显示全部楼层
    /** ###################################################################
    ** Filename : mqx_tasks.c
    ** Project : ProcessorExpert
    ** Processor : MKL25Z128VLK4
    ** Component : Events
    ** Version : Driver 01.00
    ** Compiler : GNU C Compiler
    ** Date/Time : 2012-09-12, 23:41, # CodeGen: 3
    ** Abstract :
    ** This is user's event module.
    ** Put your event handler code here.
    ** Settings :
    ** Contents :
    ** Task1_task - void Task1_task(uint32_t task_init_data);
    **
    ** ###################################################################*/
    /* MODULE mqx_tasks */
    #include "Cpu.h"
    #include "Events.h"
    #include "mqx_tasks.h"
    #include "lwtimer.h"
    /* User includes (#include below this line is not maintained by Processor Expert) */
    /* MMA8451Q IOMap */
    /* External 3-axis accelerometer data register addresses */
    #define OUT_X_MSB 0x01
    #define OUT_X_LSB 0x02
    #define OUT_Y_MSB 0x03
    #define OUT_Y_LSB 0x04
    #define OUT_Z_MSB 0x05
    #define OUT_Z_LSB 0x06
    /* External 3-axis accelerometer control register addresses */
    #define CTRL_REG_1 0x2A
    /* External 3-axis accelerometer control register bit masks */
    #define ACTIVE_BIT_MASK 0x01
    #define F_READ_BIT_MASK 0x02
    #define ACC_REG_SIZE 1U
    #define READ_COUNT 5U
    LDD_TDeviceData *I2C_DeviceData = NULL;
    TDataState DataState;
    LDD_TDeviceData *PWMTimerRG_DeviceData = NULL;
    LDD_TDeviceData *PWMTimerB_DeviceData = NULL;


    MUTEX_STRUCT   print_mutex;
    LWSEM_STRUCT TEST_SEM;

    LWEVENT_STRUCT my_event;

    LWTIMER_PERIOD_STRUCT mytimer_queue;
    LWTIMER_STRUCT mytimer1;
    LWTIMER_STRUCT mytimer2;

    #define NUM_MESSAGES 4
    #define MSG_SIZE     1

    uint32 mymsg_queue[sizeof(LWMSGQ_STRUCT)/sizeof(uint_32) + NUM_MESSAGES * MSG_SIZE];




    char                        Buffer[] = "           ";

    volatile bool               DataWrittenFlg = FALSE;
    char                        Data[] = "Hello1world";
    LDD_TError                  Error;
    LDD_FLASH_TOperationStatus  OpStatus;
    extern LDD_TDeviceData            *MyFLASH_Ptr;


    void ReadAccRegs(LDD_TDeviceData *DeviceDataPtr,TDataState *UserData,uint8 Address,uint8 ByteNum,uint8 *Buffer)
    {
            LDD_I2C_TBusState BusState;
            UserData->Sent = 0;
        I2C_MasterSendBlock(DeviceDataPtr, &Address, sizeof(Address), LDD_I2C_NO_SEND_STOP);
        while(!UserData->Sent); //等待发送
        UserData->Received = 0;
        I2C_MasterReceiveBlock(DeviceDataPtr,  Buffer,  ByteNum,  LDD_I2C_SEND_STOP);
        while(!UserData->Received); //等待接受
        do{
                I2C_CheckBus(DeviceDataPtr, &BusState);
        }while(BusState != LDD_I2C_IDLE); //等待接受完成
    }




    void WriteAccRegs(LDD_TDeviceData *DeviceDataPtr,TDataState *UserData,uint8 Address,uint8 ByteNum,uint8 *Buffer)
    {
            LDD_I2C_TBusState BusState;
           
            UserData->Sent = 0;
            I2C_MasterSendBlock(DeviceDataPtr, Buffer, ByteNum+1 , LDD_I2C_SEND_STOP);
            while(!UserData->Sent);
        do{
                I2C_CheckBus(DeviceDataPtr, &BusState);
        }while(BusState != LDD_I2C_IDLE); //等待发送完成
    }




    void Myprint1()
    {
            printf("Test LWTIMER OK!\n");
    }

    void Myprint2()
    {
           
            printf("%s\n",Buffer);
    }

    uint16 Led_Brightness = 10000;

    void Task1_task(uint32_t task_init_data)
    {

            int counter = 0;
            _mqx_uint result;
            uint8 Data = (ACTIVE_BIT_MASK | F_READ_BIT_MASK);

            signed char Accbuffer[3] = {0,127,127}; // initialize to turqoise

            I2C_DeviceData = I2C_Init(&DataState);
            WriteAccRegs(I2C_DeviceData, &DataState, CTRL_REG_1,ACC_REG_SIZE, &Data);//
           
            PWMTimerRG_DeviceData = PWMTimerRG_Init(NULL);
            PWMTimerB_DeviceData = PWMTimerB_Init(NULL);
       
            //MyFLASH_Ptr = FLASH1_Init(NULL);  /* Initialization of FLASH1 component */   
            /* Initialize the mutex */
           
            result = _lwsem_create(&TEST_SEM, 0);
            if(result != MQX_OK)
            {
                    printf("Error: semaphore component could not be created\n");       
            }
        result = _lwevent_create(&my_event, 0);
       
        if (result != MQX_OK)
        {
                    printf("Error: event component could not be created\n");                   
        }
       
        _lwmsgq_init((pointer) mymsg_queue, NUM_MESSAGES, MSG_SIZE);

        _lwtimer_create_periodic_queue(&mytimer_queue,100,0);
        _lwtimer_add_timer_to_queue(&mytimer_queue,&mytimer1,50,Myprint1,0);
        _lwtimer_add_timer_to_queue(&mytimer_queue,&mytimer2,99,Myprint2,0);   
       
            printf("I'm in Task1!\n");       
           
            PWMTimerRG_Enable(PWMTimerRG_DeviceData);
            PWMTimerB_Enable(PWMTimerB_DeviceData);       
           
           
           
    /************************************/
              DataWrittenFlg = FALSE;          
              Error = FLASH1_Write(MyFLASH_Ptr, Data, MY_FLASH_LOCATION, sizeof(Data));   /* Start writing to the flash memory */
                /* Here some other application code can be placed */
                while (!DataWrittenFlg) {                                                   /* Wait until the data are written */
                  FLASH1_Main(MyFLASH_Ptr);                                                 /* Run the main method */
                }
                DataWrittenFlg = FALSE;
                if (FLASH1_GetOperationStatus(MyFLASH_Ptr) == LDD_FLASH_FAILED) {           /* Check if the operation has successfully ended */
                  /* Error state solution */
                }

    //    Error = FLASH1_Read(MyFLASH_Ptr, MY_FLASH_LOCATION, Buffer, sizeof(Buffer));    /* Start reading from the flash memory */
    //    do {
    //      FLASH1_Main(MyFLASH_Ptr);
    //      OpStatus = FLASH1_GetOperationStatus(MyFLASH_Ptr);
    //    } while (!((OpStatus == LDD_FLASH_IDLE) | (OpStatus == LDD_FLASH_FAILED)));
    //
    //    if (OpStatus == LDD_FLASH_FAILED) {                                         /* Check if the operation has successfully ended */
    //      /* Error state solution */
    //    }
    /************************************/

            while(1)
            {
                    counter++;
                   
                    ReadAccRegs(I2C_DeviceData, &DataState, OUT_X_MSB, 3 * ACC_REG_SIZE, (uint8_t*)Accbuffer);
                    //printf("ACC:%d\n",Accbuffer[1]);
                   

                    PWMTimerRG_SetOffsetTicks(PWMTimerRG_DeviceData, 0,Led_Brightness); //x axis - red LED
                    PWMTimerRG_SetOffsetTicks(PWMTimerRG_DeviceData, 1, 0); // y axis - green LED
                    PWMTimerB_SetOffsetTicks(PWMTimerB_DeviceData, 0, 0); //z axis - blue LED
                    _time_delay_ticks(20);
                    Led_Brightness += 1000;
                    if (Led_Brightness > 5000) Led_Brightness = 0;
            }

    }


    /*
    ** ===================================================================
    **     Event       :  Task2_task (module mqx_tasks)
    **
    **     Component   :  Task2 [MQXLite_task]
    **     Description :
    **         MQX task routine. The routine is generated into mqx_tasks.c
    **         file.
    **     Parameters  :
    **         NAME            - DESCRIPTION
    **         task_init_data  -
    **     Returns     : Nothing
    ** ===================================================================
    */
    void Task2_task(uint32_t task_init_data)
    {
      _mqx_uint   msg[MSG_SIZE];
      int counter1 = 0,counter2 = 0;

      while(1) {
        counter1++;
       
        _lwmsgq_receive((pointer) mymsg_queue, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 0, 0);
       
        printf("Erase!\n");
    //    Error = FLASH1_Erase(MyFLASH_Ptr,MY_FLASH_LOCATION,1024);
    //    /* Here some other application code can be placed */
    //    while (!DataWrittenFlg) {                                                   /* Wait until the data are written */
    //      FLASH1_Main(MyFLASH_Ptr);                                                 /* Run the main method */
    //    }
    //    DataWrittenFlg = FALSE;
    //    if (FLASH1_GetOperationStatus(MyFLASH_Ptr) == LDD_FLASH_FAILED) {           /* Check if the operation has successfully ended */
    //      /* Error state solution */
    //    }
    //   
        _lwevent_clear(&my_event, 1);
        _time_delay_ticks(100);
       

    //    _mutex_unlock(&print_mutex);
      }
    }

    /*
    ** ===================================================================
    **     Event       :  Task3_task (module mqx_tasks)
    **
    **     Component   :  Task3 [MQXLite_task]
    **     Description :
    **         MQX task routine. The routine is generated into mqx_tasks.c
    **         file.
    **     Parameters  :
    **         NAME            - DESCRIPTION
    **         task_init_data  -
    **     Returns     : Nothing
    ** ===================================================================
    */
    void Task3_task(uint32_t task_init_data)
    {
      _mqx_uint   msg[MSG_SIZE] = {5000};
      int counter1 = 0;
      static bool Key_Press = FALSE;
      
      while(1) {
        counter1++;
        if (KEY_GetVal(NULL) == FALSE)
        {
                _time_delay_ticks(2);           
            if (KEY_GetVal(NULL) == FALSE)
            {         
                   
                    Key_Press = TRUE;

            }
        }
        if (KEY_GetVal(NULL) == TRUE && Key_Press == TRUE)
        {
                   
                Key_Press = FALSE;
                    //_lwsem_post(&TEST_SEM);
                _lwevent_set(&my_event,1);
                    printf("You have pressed the key!\n");
                    _lwtimer_cancel_timer(&mytimer2);
            _lwmsgq_send((pointer) mymsg_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL);

        }   
        _time_delay_ticks(2);

      }
    }

    /* END mqx_tasks */
    /*
    ** ###################################################################
    **
    ** This file was created by Processor Expert 10.0 [05.02]
    ** for the Freescale Kinetis series of microcontrollers.
    **
    ** ###################################################################
    */
    回复 支持 反对

    使用道具 举报

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

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-20 13:27 , Processed in 0.099447 second(s), 26 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表