kendryte / k510_buildroot

Kendryte K510 SDK
BSD 2-Clause "Simplified" License
118 stars 57 forks source link

[Bug]: dsp write share memory, but cpu reads wrong data! #431

Open xulan007 opened 1 year ago

xulan007 commented 1 year ago

What happened

when cpu(dsp_log) reads share memory written by DSP, the result is partially wrong!

Reproduction steps

step1, memcpy data to share memory in DSP, and set fft_share_memory->dsp_input_end=0xff:

        for(int j=0;j<(fft_n/2+1);j++){
            i_real[j]=j;
            i_imag[j]=j;
        }
        memcpy(fft_share_memory->dsp_input_data, i_real, (fft_n/2+1)*sizeof(float));
        memcpy(fft_share_memory->dsp_input_data + (fft_n/2+1)*sizeof(float), i_imag, (fft_n/2+1)*sizeof(float));
        fft_share_memory->dsp_input_end = 0xff;

step2,When dsp log detected fft_share_memory->dsp_input_end==0xff, read the data from the fft_share_memory->dsp_input_data and print:

    float * ret = (float*)fft_share_memory->dsp_input_data;
    for(int j=0;j<n_fft+2;j++){
        printf("%14.8f  ", ret[j]);
        if(j%8==0){
            printf("\r\n");
        }
    }

step3: the ret print goes "0. 0. 0. ...0.", but the dsp input is "0. 1. 2. 3. ... "

Hardware board

k510 crb kit

Software version

No response

Bug frequency

everytime

Anything else

No response

wangjianxin-canaan commented 10 months ago

volatile struct share_memory *fft_share_memory; Please check if fft_share_memory define have volatile .