在测试C code的误差SEGV上的ARM Cortex M4处理器经过时间 [英] Error SEGV in test C code on elapsed time in ARM Cortex M4 processor

查看:308
本文介绍了在测试C code的误差SEGV上的ARM Cortex M4处理器经过时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个code用于嵌入式操作系统为我stm32f429板。我测试这个code表示经过时间:

I'm writing a code for embedded OS for my stm32f429 board. I'm testing this code for elapsed time:

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h> 
#include <fcntl.h>
#include <time.h>
#include <stdint.h>


#define DEFAULT_DELAY   1

uint32_t m_nStart;               //DEBUG Stopwatch start cycle counter value
uint32_t m_nStop;   //DEBUG Stopwatch stop cycle counter value             
#define DEMCR_TRCENA    0x01000000

/* Core Debug registers */
#define DEMCR           (*((volatile uint32_t *)0xE000EDFC))
#define DWT_CTRL        (*(volatile uint32_t *)0xE0001000)
#define CYCCNTENA       (1<<0)
#define DWT_CYCCNT      ((volatile uint32_t *)0xE0001004)
#define CPU_CYCLES      *DWT_CYCCNT



#define STOPWATCH_START { m_nStart = *(*(volatile unsigned int*)0xE0001004);}//DWT_CYCCNT;}
#define STOPWATCH_STOP  { m_nStop = *(*(volatile unsigned int *)0xE0001004);}




static inline void stopwatch_reset(void)
{
    /* Enable DWT */
    DEMCR |= DEMCR_TRCENA; 
    *DWT_CYCCNT = 0;             
    /* Enable CPU cycle counter */
    DWT_CTRL |= CYCCNTENA;
}

static inline uint32_t stopwatch_getticks()
{
    return CPU_CYCLES;
}

static inline void stopwatch_delay(uint32_t ticks)
{
    stopwatch_reset();
    while(1)
    {
        if (stopwatch_getticks() >= ticks)
                break;
    }
}

uint32_t CalcNanosecondsFromStopwatch(uint32_t nStart, uint32_t nStop)
{
    uint32_t nTemp;
    uint32_t n;
    uint32_t SystemCoreClock = 180000000;
    nTemp = nStop - nStart;

    nTemp *= 1000;                          // Scale cycles by 1000.
    n = SystemCoreClock / 1000000;          // Convert Hz to MHz
   nTemp = nTemp / n;                      // nanosec = (Cycles * 1000) / (Cycles/microsec)

   return nTemp;
} 



int main( int argc, char **argv )
{
    int delay = DEFAULT_DELAY;  // Initial value for the delay

    int timeDiff = 0;

    STOPWATCH_START;
    printf("Try\n\n");
    STOPWATCH_STOP;
    timeDiff = CalcNanosecondsFromStopwatch(m_nStart, m_nStop);
    printf("My function took %d nanoseconds\n", timeDiff);  


   return( 0 );
}

它编译没有错误,但是当我在我的stm32f429运行这个程序,我获得SEGV错误,大概在的#define STOPWATCH_START。也许我对寄存器的问题(?)。

It compiles without errors, but when I run this program on my stm32f429, I obtain a SEGV error, probably in the #define STOPWATCH_START. Maybe I have problems on registers (?).

在code是 http://pastebin.com/qr6sF9eU (它删除呼叫系统叫我用)

The code is http://pastebin.com/qr6sF9eU (It deleted the calling to system call that I use)

请的输出是: http://pastebin.com/Q14xTaXH

当我在船上stm32f429运行我的测试的输出是: http://pastebin.com/sGmjZjxj

The output when I run my test on stm32f429 board is: http://pastebin.com/sGmjZjxj

你能帮助我吗?

推荐答案

NVIC寄存器最有可能是由主机保护,用户code无法访问。你不能乱用一切使用的操作系统的时候。

NVIC registers are most likely protected by MPU and not accessible to user code. You cannot mess with everything when using an operating system.

这篇关于在测试C code的误差SEGV上的ARM Cortex M4处理器经过时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆