• AVR Freaks

PIC32MZ EF Harmony3 SQI issue with odd size buffer

Author
Luca Pascarella
Starting Member
  • Total Posts : 69
  • Reward points : 0
  • Joined: 2007/05/28 00:53:17
  • Location: The Netherlands
  • Status: offline
2019/09/10 08:42:18 (permalink)
0

PIC32MZ EF Harmony3 SQI issue with odd size buffer

I am porting my working project based on a PIC32MZ EF from Harmony2 to Harmony3 and I am struggling with the SST26 driver.
 
The project implements a web server that includes the MPFS driver to access an SST26VF064B through a SQI peripheral.
I fixed the cache handling in mpfs.c (since SQI DMA writes in not cachable space) but a strange problem is present in the submodule sys_fs_media_manager.c.
 
After a while a discovered that SYS_FS_MEDIA_MANAGER_Read(diskNum, buffer, source, nBytes) works properly only when nBytes is an even number. For odd numbers, instead, the buffer is filled with a progressive shifted data.
 
// Three consecutive calls to SYS_FS_MEDIA_MANAGER_Read create these pattern
 
// nBytes is 15, and for every call, the 0x4D byte is rotated of a position
0x4D 50 46 53 02 01 91 00 0A 90 AC CE F0 94 2C 00
0x2C 4D 50 46 53 02 01 91 00 0A 90 AC CE F0 94 00
0x94 2C 4D 50 46 53 02 01 91 00 0A 90 AC CE F0 00

// If nBytes is 14 it returns the correct results for every call
0x4D 50 46 53 02 01 91 00 0A 90 AC CE F0 94 00 00
0x4D 50 46 53 02 01 91 00 0A 90 AC CE F0 94 00 00
0x4D 50 46 53 02 01 91 00 0A 90 AC CE F0 94 00 00

 
At the moment I don't have a clue on what to check. Perhaps it may be an issue with the drv_sst26.c.
Does someone have the same issue?
 
Luca
post edited by Luca Pascarella - 2019/09/10 08:45:12
#1

3 Replies Related Threads

    optimus_jack
    Starting Member
    • Total Posts : 54
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF Harmony3 SQI issue with odd size buffer 2019/09/10 19:55:43 (permalink)
    0
    Hi Luca,
    In Harmony 3 if you want to perform File operation or interact with memory media's like NVM, SST26(SQI) using the file system layer you need to use Memory Driver.
    Refer to https://github.com/Microchip-MPLAB-Harmony/core/tree/master/apps/fs/sqi_flash_fat/firmware/pic32mz_ef_sk.X for understanding the configurations
     
    Can you share the project? to better understand the problem
    #2
    Luca Pascarella
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2007/05/28 00:53:17
    • Location: The Netherlands
    • Status: offline
    Re: PIC32MZ EF Harmony3 SQI issue with odd size buffer 2019/09/10 22:55:36 (permalink)
    0
    In my project, the SYS_FS_MEDIA_MANAGER_Read is used by MPFS module in a web server application. I do not need to access MPFS File Systems from userspace, at least the SST26, userspace accesses FAT through mass storage but it is not implemented now.
    I arrived at that odd size buffer by debugging why web pages are not always loaded properly into the browser.

    I discovered that sometimes it works and others do not and this condition depends on the length of the filename.
     
    When the request is an odd length SYS_FS_MEDIA_MANAGER_Read returns incorrect data. Then, I just added a simple check to recall SYS_FS_MEDIA_MANAGER_Read several times discovering this strange behaviour for odd size.
     
    I build this project by combining Harmony 3 examples on apps/fs/sqi_flash_fat, web_net_server_qspi_mpfs, and web_net_server_nvm_mpfs. I am positive about the hardware because loading my old project developed with Harmony 2 it works properly.
     
     
    To be more specific, I found the issue in mpfs.c when temp is odd.

    // SQI_CACHE_WORKAROUND defines a temporary workaround to force non cachable space. hashBuffer and fileName must be moved back on the stack to allows reentrant calls.
     
    #if defined (SQI_CACHE_WORKAROUND)
    static uint16_t __ALIGNED(16) __COHERENT hashBuffer[16] = {0};
    static uint8_t __ALIGNED(16) __COHERENT fileName[FAT_FS_MAX_LFN];
    #endif
    static int MPFSFindFile
    (
        uint8_t diskNum,
        uint8_t *file,
        MPFS_FILE_RECORD *fileRecord
    )
    {
        uint32_t address = 0;
        uint32_t temp = 0;
        uint8_t *ptr = NULL;
        int32_t index = 0;
        uint16_t hash = 0;
    #if !defined (SQI_CACHE_WORKAROUND)
        uint16_t hashBuffer[16] = {0};
        uint8_t fileName[FAT_FS_MAX_LFN];
    #endif
        
        /* Calculate the hash value for the file name. */
        ptr = file;
        while (*ptr != '\0')
        {
            hash += *ptr++;
            hash <<= 1;
        }

        /* Read in hashes, and check remainder on a match. Store 8 in cache for
         * performance. */
        for (index = 0; index < gSysMpfsObj.numFiles; index++)
        {
            if ((index & 0x07) == 0u)
            {
                /* Address of the hash location. */
                address = 8 + (index << 1);
                temp = gSysMpfsObj.numFiles - index;
                if (temp > 8)
                {
                    temp = 8;
                }
                if (MPFSGetArray (diskNum, address, temp << 1, (uint8_t *)hashBuffer) == false)
                {
                    return -1;
                }
            }

            /* If the hash matches, compare the full filename. */
            if (hashBuffer[index & 0x07] == hash)
            {
                address = 8 + (gSysMpfsObj.numFiles * 2) + (index * 22);
                MPFSGetArray (diskNum, address, 22, (uint8_t *)fileRecord);
                temp = strlen ((const char *)file);

                if (MPFSGetArray (diskNum, fileRecord->fileNameOffset, temp, (uint8_t *)fileName) == false)
                {
                    return -1;
                }

                if (strncmp ((const char *)fileName, (const char *)file, temp) == 0)
                {
                    /* Found the matching file. */
                    return index;
                }
            }
        }

        return -1;
    }

    post edited by Luca Pascarella - 2019/09/10 23:12:10

    Attached Image(s)

    #3
    optimus_jack
    Starting Member
    • Total Posts : 54
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: PIC32MZ EF Harmony3 SQI issue with odd size buffer 2019/09/10 23:58:04 (permalink)
    0
    Hi Luca,
     
    Will look into the project and see if i can help you out.
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5