Git Product home page Git Product logo

Comments (20)

zhao-dddw avatar zhao-dddw commented on July 18, 2024 1

@rawsample When i try replacing the import, it works normally. I think your guess is correct, Thank you for your answer.

2022-07-12 03:33:09,533 | avatar.INFO | Initialized Avatar. Output directory is ./tmp1/avatar
2022-07-12 03:33:09,535 | avatar.targets.QemuTarget0.WARNING | No cpu_model specified - are you sure?
2022-07-12 03:33:09,540 | avatar.targets.QemuTarget0.INFO | QEMU process running
2022-07-12 03:33:09,753 | avatar.targets.QemuTarget0.INFO | State changed to TargetStates.STOPPED
2022-07-12 03:33:09,754 | avatar.INFO | Received state update of target QemuTarget0 to TargetStates.STOPPED
2022-07-12 03:33:09,769 | avatar.targets.QemuTarget0.QMPProtocol.INFO | b'{"return": {}, "id": 0}\r\n'
2022-07-12 03:33:09,771 | avatar.targets.QemuTarget0.INFO | Connected to remote target
2022-07-12 03:33:09,774 | avatar.targets.QemuTarget0.RemoteMemoryProtocol.INFO | Successfully connected rmp
2022-07-12 03:33:10,275 | avatar.targets.QemuTarget0.RemoteMemoryProtocol.WARNING | Tried to close/unlink non existent rx_queue
2022-07-12 03:33:10,275 | avatar.targets.QemuTarget0.RemoteMemoryProtocol.WARNING | Tried to close/unlink non existent tx_queue

from avatar2.

aurelf avatar aurelf commented on July 18, 2024

Hi,
that's a good point. We could make this a complete example. In the mean time, did you look at the examples repository ? Probably this can help.

https://github.com/avatartwo/avatar2-examples

from avatar2.

mariusmue avatar mariusmue commented on July 18, 2024

Besides this, you can also find examples implementation for the nucleo_usart or max32-uart in the avatar2 pyperipheral directory.

Hope this helps!

from avatar2.

zhao-dddw avatar zhao-dddw commented on July 18, 2024

Hi, that's a good point. We could make this a complete example. In the mean time, did you look at the examples repository ? Probably this can help.

https://github.com/avatartwo/avatar2-examples

Thank you for your reply. I have seen the examples repository, but I still don't understand it. I will take a closer look. Thank you again for your reply.

from avatar2.

zhao-dddw avatar zhao-dddw commented on July 18, 2024

Besides this, you can also find examples implementation for the nucleo_usart or max32-uart in the avatar2 pyperipheral directory.

Hope this helps!

Ok, I'll take a closer look, thanks for your reply and suggestion. : )

from avatar2.

zhao-dddw avatar zhao-dddw commented on July 18, 2024

Besides this, you can also find examples implementation for the nucleo_usart or max32-uart in the avatar2 pyperipheral directory.

Hope this helps!

Hi, when i run

from avatar2 import *
import struct

from avatar_peripheral import AvatarPeripheral

class HelloWorldPeripheral(AvatarPeripheral):

    def hw_read(self, offset, size):
        ret = self.hello_world[:size]
        self.hello_world = self.hello_world[size:] + self.hello_world[:size]

        # Convert the return value to an integer (py2/py3-compatible)
        # Python >3.2 could just call int.from_bytes(ret, byteorder='little')
        s2fmt = {1: 'B', 2: 'H', 4: 'I', 8: 'Q'}
        ret = struct.unpack('<' + s2fmt[size], ret)[0]

        return ret

    def nop_write(self, offset, size, value):
        return True

    def __init__(self, name, address, size, **kwargs):
        AvatarPeripheral.__init__(self, name, address, size)

        self.hello_world=b'Hello World'

        self.read_handler[0:size] = self.hw_read
        self.write_handler[0:size] = self.nop_write

avatar = Avatar(arch=ARM,output_directory='./tmp1/avatar')

qemu = avatar.add_target(QemuTarget)

hw = avatar.add_memory_range(0x40004c00, 0x100, name='hello_world',
                                                    emulate=HelloWorldPeripheral, permissions='rw-')
avatar.init_targets()

it will have this problem

root@avatar2-exp:~# python3 hello_world.py 
2022-07-05 13:44:28,842 | avatar.INFO | Initialized Avatar. Output directory is ./tmp1/avatar
2022-07-05 13:44:28,844 | avatar.targets.QemuTarget0.WARNING | No cpu_model specified - are you sure?
Traceback (most recent call last):
  File "hello_world.py", line 36, in <module>
    avatar.init_targets()
  File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/avatar2.py", line 233, in init_targets
    t[1].init()
  File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/watchmen.py", line 78, in watchtrigger
    ret = func(self, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/targets/qemu_target.py", line 263, in init
    file_name=self.qemu_config_file, config=self.generate_qemu_config()
  File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/targets/qemu_target.py", line 174, in generate_qemu_config
    conf_dict = self.avatar.generate_config()
  File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/avatar2.py", line 153, in generate_config
    conf_dict["memory_mapping"].append(mr.data.dictify())
  File "/usr/local/lib/python3.8/dist-packages/avatar2-1.4.7-py3.8.egg/avatar2/memory_range.py", line 65, in dictify
    raise Exception(
Exception: Unsupported type <class '__main__.HelloWorldPeripheral'> for dictifying python_peripheral for mem_range at 0x40004c00

Did I write something wrong?Can you take a look at it.Thanks!

from avatar2.

zhao-dddw avatar zhao-dddw commented on July 18, 2024

@mariusmue

from avatar2.

zhao-dddw avatar zhao-dddw commented on July 18, 2024

@aurelf

from avatar2.

rawsample avatar rawsample commented on July 18, 2024

Hello @zhao-dddw , I'm going to look at it but i need to finish other tasks before.

from avatar2.

zhao-dddw avatar zhao-dddw commented on July 18, 2024

@rawsample Ok, you go to work first.

from avatar2.

rawsample avatar rawsample commented on July 18, 2024

Could you try replacing the import with from avatar2.peripherals.avatar_peripheral import AvatarPeripheral?
My guess is that HelloWorldPeripheral doesn't inherit from the correct AvatarPeripheral class and therefore fail the check on the expected_types

from avatar2.

mariusmue avatar mariusmue commented on July 18, 2024

Can we maybe update the handbook to reflect this pitfall?

from avatar2.

rawsample avatar rawsample commented on July 18, 2024

Changes added in 974c6b3

from avatar2.

zhao-dddw avatar zhao-dddw commented on July 18, 2024

@rawsample
Excuse me, do you have the source code of this binary file? I tried to compile it, but it couldn't run.
https://github.com/avatartwo/avatar2/tree/main/tests/pyperipheral
image

from avatar2.

rawsample avatar rawsample commented on July 18, 2024

I'm afraid not, maybe @mariusmue has?
Be aware in the case you recompile it, you may need to update the different addresses used in test_pyperipheral.py.

from avatar2.

zhao-dddw avatar zhao-dddw commented on July 18, 2024

@mariusmue Hi,do you have the source code of this binary file.
image

from avatar2.

zhao-dddw avatar zhao-dddw commented on July 18, 2024

@rawsample Ok,thank you for your advice.

from avatar2.

mariusmue avatar mariusmue commented on July 18, 2024

Hi, sorry for the delay.

The source code should be:

#include "mbed.h"

//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut myled(LED1);

int main()
{
    int i = 1;
    pc.printf("Hello World !\n");
    while(1) {
        wait(1);
        pc.printf("This program runs since %d seconds.\n", i++);
        myled = !myled;
    }
}

The example was build with mbed-os2, also known as libmbed. In comparison to more recent version of mbedOS, that version linked everything into a monoloithic application. If I recall correctly, I either built this example using the mbed online compiler, or using the linux mbed toolchain.

Hope that helps!

from avatar2.

zhao-dddw avatar zhao-dddw commented on July 18, 2024

@mariusmue Thank you for your answer.But I have one more question, do the other two bin files have any specific purpose?
rcc_dump.bin
sram_dump.bin
Sorry to bother you again.

from avatar2.

mariusmue avatar mariusmue commented on July 18, 2024

No worries! Yes, these are dumps of the memory regions of the device in the right state. They are defined here in the according script.

The "right state" here, means that there was a breakpoint set on the device on the entry of the main-loop (which matches the entry-address for the qemu object.

This allows to emulate the firmware without the need of having the physical device to transfer the state from at this point.

from avatar2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.