Pieapplej
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Save as template
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    2
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Tutorial: DMA 實現 with PYNQ on ZedBoard 此專案將展示如何在zedboard平台上實現DMA,並透過Jupyter控制PS來使用DMA,實現PS與PL之間互動。 ## DMA簡介 ![](https://i.imgur.com/foxWtuq.png) 傳統外部存取記憶體,需要透過CPU中繼後才能進去RAM。實際上中繼這步驟, CPU收到存儲Interrupt後,會將資料複製進cache,再寫入新位置。而這些存取要求對CPU來說將會是個負擔,理由為 1.外部設備可能操作時脈異於CPU。 2.CPU本身不用介入傳送,無須取指,取值,除存等動作。 3.Interrupt令CPU需要停下當前動作。 Direct Memory Access(DMA)為硬體對硬體,令外部設備得以直接存取RAM而不用透過CPU之技術。為此我們會需要DMA控制器(它本身就是一個硬體) ## DMA 控制器 PYNQ 提供並支援DMA IP以及相關函式庫。我們可以直接使用vivado中的DMA IP並使用PYNQ於軟體端應用。值得一提的是PYNQ內建的DMA api只支援簡易模式。 下圖為DMA block diagram。 ![](https://i.imgur.com/3pCIb4Q.png) 此DMA具有一組AXI lite界面作為控制,以及一對介於PS及Overlay IP間的讀寫通道。可以理解成DMA controller本身具有AXI master端口,去對PS中DRAM讀寫,將stream提供給PL端的IP。 值得一提的是DMA預設所有連接DMA的串流IP在寫入完成後,提供AXI TLAST訊號。如果沒有正確提供此訊號,DMA將不會完成資料轉接。 ## 系統摘要 詳細參閱 http://www.pynq.io/ 總之PYNQ是一套可以部屬Jupyter的linux平台。 ![](https://i.imgur.com/ACkdVi7.png) ZYNQ是一塊集合arm跟fpga的晶片,可以理解成裡面有一顆手機那種處理器以及一塊可以自己編寫的邏輯閘。 ![](https://i.imgur.com/5GrtLQd.png) 我們使用arm processor 執行Jupyter,讓我們可以使用網頁瀏覽器進入Jupyter直接控制arm processor。 以下實做DMA自傳自收,使用Jupyter控制arm processor,連接PL中的DMA控制器做存儲。 ## DMA自傳自收 with Jupyter ### Step1 Hardware + 打開Block Diagram,加入zynq7 processor, dma, axi4-fifo, gpio等,其他模組使用自動生成。 ![](https://i.imgur.com/cBpcTY3.png) 此專案不使用fifo,如下圖直接將dma中MM2S<->S2MM直連也行。 ![](https://i.imgur.com/2BHkYLz.png) 記得以下重點設定 + dma要將Scatter Gather Engine disable + processing 將HP0 enable 此系統 :::info 如果遇到 >[BD 41-703] Slave segment </processing_system7_0/S_AXI_HP0/HP0_DDR_LOWOCM> is mapped into master segment </processing_system7_0/Data/SEG_processing_system7_0_HP0_DDR_LOWOCM>, but there is no path between them. Please delete the master segment or check your design to ensure a valid path can be created. 檢查Address Editor中processing_system7_0欄目是否有processing_system7_0,如有則將其刪除。 ::: 完成後驗證並生成bit file. ### Step2 將硬體描述檔及驅動複製進Jupyter 複製以下檔案進Jyputer目錄下,建議新開一個資料夾並一同放入,注意兩者除附檔名,檔名要相同。 + ./*.runs/impl_1/***.bit + ./*.srcs/source_1/bd/design_1/hw/handoff/***.hwh :::info 可以使用```http://192.168.2.99:9090/lab``` 在瀏覽器存儲Jupyter目錄 IP位置可能因使用環境不同而改變,建議進入router查看DCHP分配 ::: ### Step3 在Jupyter使用硬體 在Step2資料夾之位置新開一個python3 file, 輸入以下code ```shell=python from pynq import Overlay import time import numpy as np from pynq.lib import AxiGPIO ol = Overlay("./design_1.bit") led_ip = ol.ip_dict['axi_gpio_0'] leds = AxiGPIO(led_ip).channel1 mask = 0xffffffff leds.write(0xee, mask) ``` 以上為載入image file(bit file)並控制LED之流程,其中overlay即為該image file. 這邊可以使用ol?來確認有正確載入image,並確認bit file內部IP正確。 ![](https://i.imgur.com/DssXT7I.png) 接著輸入以下code ```shell=python import pynq.lib.dma from pynq import Xlnk import numpy as np xlnk = Xlnk() dma = ol.axi_dma_0 input_buffer = xlnk.cma_array(shape=(5,), dtype=np.uint32) output_buffer = xlnk.cma_array(shape=(5,), dtype=np.uint32) for i in range(5): input_buffer[i] = i + 10 print(input_buffer) dma.sendchannel.transfer(input_buffer) #memory to stream dma.recvchannel.transfer(output_buffer) dma.sendchannel.wait() dma.recvchannel.wait() print(output_buffer) ``` 按下執行後需要稍等結果,點擊哪一個In模組並執行為僅執行該cell。未執行模組為In[],執行中為In[*],正確執行後In[]中方框將出現數字。 因為此設計是blocking(sequential),wait()就是在等interrrupt。 ### Result ![](https://i.imgur.com/NyKA2EY.png) Jupyter 印出準備輸入DMA資料,並印出從DMA讀回的資料。 ## Reference + NCU-CE, SDR LAB + http://www.pynq.io/ + https://pynq.readthedocs.io/en/latest/pynq_libraries/dma.html + Vivado Design Suite Tutorial - Embedded Processor Hardware Design(UG940) ###### tags: `Zedboard`,`DMA`, `Tutorial`,`PYNQ`,`zynq7000` >jessest94106@g.ncu.edu.tw Department of Space Science & Engineering Center for Astronautical Physics & Engineering National Central University, Taiwan [name=PieappleJ ]

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully