This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于fft例程固化到28335flash问题

采用ti官方的fft代码来进行傅里叶计算,在ram中能够正常运行,但是移植到flash中后会出现和运算错误,所有的运算结果都是NaN,请问是不是哪里出了问题?应该如何解决呢?

  • RAM中运行正常,烧录flash中计算结果不正确,没有遇到过这样的问题,还是要检查下看是否存在非法计算,比如负数开偶次方,

    http://www.cnblogs.com/dosrun/p/3908617.html

  • 问题解决了,将fft计算过程中用到的数组通过#pragma DATA_SECTION(RFFToutBuff,"RFFTdata2");复制在固定的ram位置,就解决了,具体的原因现在还尚不清楚。总之谢谢你的解答

  • 原因一般是这段代码需要一个ram空间,默认代码和cmd的设置里是在ram里。当移植到flash时,除了需要把关键代码加载到指定的ram里,也需要在代码里指定那段应用函数的空间的位置,然后在cmd里分配。cmd里不指定的话,boot起来后,运行你的那段应用函数时就都不知道跑到哪儿了
  • 你好,你的意思是不是代码运行时并不会自动在芯片的RAM 中分配函数的空间,这个空间需要自己定义?可是我程序中除了FFT部分,其他定义的数组都是可以使用的。

  • 我没有用过fft,看了下例程代码,其实我之前说的和你这个情形还不一样。

    不过,对于你的问题和你的解决方案,例程里,rfft 的应用c文件里本来就有这句数据空间的指定,你之前可能没有注意到。

    “ #pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1"); //Buffer alignment for the input array,

    float RFFTin1Buff[RFFT_SIZE]; //RFFT_f32u(optional), RFFT_f32(required)
    //Output of FFT overwrites input if
    //RFFT_STAGES is ODD
    #pragma DATA_SECTION(RFFToutBuff,"RFFTdata2");
    float RFFToutBuff[RFFT_SIZE]; //Output of FFT here if RFFT_STAGES is EVEN

    因为cmd里,本来也已经给出了该数据空间的内存分配。

    RFFTdata1 : > RAML4, PAGE = 1, ALIGN(512)
    RFFTdata2 : > RAML5, PAGE = 1
    RFFTdata3 : > RAML6, PAGE = 1
    RFFTdata4 : > RAML7, PAGE = 1

    我理解之所以cmd需要单独给用户定义该fft 的数据内存分配是因为:

    1. 如果你直接用默认的数组定义 float32 xxx, 编译器会把数据放在.cint 和.ebss 里 (见下表)。而这样子,cmd文件里,对这些基本section的内存分配起始地址和技术地址比较随意,也有好些section 复用在某些ram里。(当然你也可以指定,根据数组需求的大小)

    Section Name

    Description

    Section Type

    Link Location

    .text

    Executable code and constants

    Initalized

    Load into non-volatile memory: Flash

    Run time critical code in SARAM

    Note (1)

    .cinit

    Initalized global and static variables

    Initalized

    Non volatile memory: Flash

    .econst

    Constant data (e.g. const int k = 3;)

    Initalized

    Non volatile memory: Flash

    .switch

    Tables for switch statements

    Initalized

    Non volatile memory: Flash

    .ebss

    Global and static variables

    Uninitalized

    Volatile memory: SARAM

    2. 而 fft出错的主要原因是,rfft的asm 代码里,强调了开始的数据地址要对齐到 包含 整数倍的 FFT size 的内存大小。这里给的是512.  所以,cmd里直接给你做好了。否则, 随意分配的结果 会导致出错。 但是: “If you do not wish to align the input buffer ; then use the RFFT_f32u function. Using this function will reduce cycle performance of the algorithm”

    ; FILE: RFFT_f32.asm
    ;
    ; TITLE: Real FFT
    ;
    ; DESCRIPTION:
    ;
    ; This function computes a real FFT. The input buffer must be aligned to
    ; a multiple of the FFT size. If it is not aligned then the output buffer
    ; will yield invalid results. If you do not wish to align the input buffer
    ; then use the RFFT_f32u function. Using this function will reduce cycle
    ; performance of the algorithm.
    ;

  • 谢谢大神解答,明白了,这个是FFT的代码要求要有一个固定地址空间。

  • 请问您是如何修改的?只是把cmd换成F28335.cmd并在cmd中定义段吗?