Jump to content
    

C-SPY - сохранение данных в файл

Добрый день.

Начал сегодня знакомиться с макросами C-SPY IAR. Нужно сохранить некие данные из памяти МК в файл.
В принципе практически на 90% представляю что и как нужно, с т.з. написания макроса расстановки брейкпоинтов и т.п.
Вопрс принципиальный в том, что у меня даные в основной программе - это строка длиной 100. (char[100])
В принципе надо просто ее "слить" в файл. Как макрос "увидит" переменную основного проекта? Как осуществить доступ макросу к этой переменной? Вот это не доконца понимаю.

С уважением.

 

Share this post


Link to post
Share on other sites

s  

C-SPY macros to save and restore memory and registers

Additional macros
There is an additional example with macros where you can specify the name of the file, i.e. no need to update the macro source.

Example of a command to enter in the QuickWatch command line to dump the contents of a variable in a binary format:

DumpMem("dumpmem.bin", &trace_buffer, sizeof(trace_buffer))
Example of a command to enter in the QuickWatch command line to dump the contents of ARM registers in a readable format:

DumpReg("dumpreg.txt")

https://www.iar.com/knowledge/support/technical-notes/debugger/c-spy-macros-to-save--restore-memory-and-registers/

попробуйте так, вообще эти макросы для IAR платформо-отладчиково-зависимы

Спойлер
// Example of command to enter in QuickWatch command line:
// DumpInt16("dumpint16.txt", &trace_buffer, sizeof(trace_buffer))

DumpInt16(aFileName, aAddress, aSize)
{
    __var fileHandle;
    __var memoryByte;

    __message "--- macro DumpMem(file: ", aFileName, ", address: 0x", aAddress:%X, ", size: ", aSize:%d, ")";

    fileHandle = __openFile(aFileName, "wb");

    if (fileHandle)
    {
        while ((int)aSize > 0)
        {
            memoryByte = __readMemory16((int)aAddress, "Memory");
 
            __fmessage fileHandle, " ", memoryByte, "\n";

            aAddress = (int)aAddress + 2;
            aSize    = (int)aSize    - 2;
        }
    }
    else
    {
        __message "*** Could not open file '", aFileName, "'\n";
    }
    __message "--- macro Done";
 }

 

Share this post


Link to post
Share on other sites

Добрый день.

Есть строка char s[100].

100 - максимальный размер.

Нужных символов может быть меньше. Если их меньше, то после нужных даных в конце у нее символы CR LF и далее все \0 до размера 100. В памяти именно так.

делаю

__var MStr;

MStr = __toString(str,100);

__fmessage FileHandle,MStr;

где FileHandle - файл (результат операции __openFile() )

В результате в принципе все нормально, "читабельно", но появляется везде в конце лишний символ. В итоге имеем в файле

не CR LF, как было изначально,

а CR CR LF. 

1. Можно ли как-то отлаживать макросы?

2. какая из двух функций добавляет символ в строчку?

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...