顯示具有 ARM Bare metal 標籤的文章。 顯示所有文章
顯示具有 ARM Bare metal 標籤的文章。 顯示所有文章

2019年8月16日 星期五

Raspberry Pi Mail Box--tag buffer


Raspberry Pi Mailbox的機制是你CPU 送出Request所用的buffer , 在GPU Response 回來時是會被修改的.因為使用的是同一塊Buffer, 所以Request傳送的資料佔了幾個byte (bit 30:0 Value Length)及 Response回來有多少個byte ,在送出Request就要決定了
 value buffer 的大小一定是max(Request data length, Response data length)




value buffer size in bytes 是指value buffer的大小;
  value length in bytes 是請求欄位佔幾個Byte



ARM Bare metal 開發課程連結

2018年2月26日 星期一

ARM Alignment



On ARM-based systems you cannot address a 32-bit word that is not aligned to a 4-byte boundary 


LDR r0, = 0x1001
LDR r1, [r0]
The second line in the above code will give hard fault since are trying to read 4 bytes but the memory address is not divisible by 4
If we change the second line in above code to the following
LDRB r1, [r0];//Load 1 byte from address
The above line will not produce a hard fault, since we are trying to access 1 byte(1 byte can be accessed from any memory location)
Also notice the following example;
LDR r0,= 0x1002
LDRH r1,[r0];   //Load half word from 0x1002


References:





2017年5月11日 星期四

VM 虛擬化概念(一)



只有一顆 CPU,同時執行多個作業系統, 而讓每一個作業系統以為他使用到全部CPU資源,然而這是 CPU 虛擬化得來的結果。(類似Multi-thread, 每個thread以為自己是CPU唯一的使用者,然而這是OS 進行排程scheduling的結果 ,使得每一個 thread 感覺同時執行中)\

實現VM的軟體稱之VMM (Virtual Machine Monitor),它伴演一個Virtual Machine Manager 的角色。它是虛擬化技術的實踐者,對Guest OS 作出一個抽象化(虛擬化)的架構,使得Guest OS 看不到真正的硬體,只看得到VMM,而把CPU、Memory、I/O全部抽象化。


虛擬化CPU:

  • 讓每一個Guest OS 以為只有一個CPU, 並且完全擁有系統所有資源。 這須要存在一個Virtual Machine Monitor (Hypervisor) 來實現,讓 Guest OS 跑Hypervisor上。所有 Guest OS 產生的Exception 都送到Hypervisor上來處理。

2016年9月29日 星期四

認識ARM-based SoC 原廠開發工具


Bare Metal 開發或Boot loader設計, 若有一個好的開發工具,可以加速開發速度。

針對ARM Cortex-A系列, ARM 原廠提供的是DS-5 (Download ARM Development Studio 5 (DS-5)。Note: 針對ARM Cortex-M系列 , 原廠開發工具, 則是MDK-ARM

若只是針對ARM Classic , 即ARM7、ARM9、ARM11 這類的, 也可以使用先前的 RVDS (Real View Development Suite) 開發工具或更早的ADS (ARM Development Suite) 來開發,但目前ARM已不再更新這些軟體了。

DS-5 是Eclipse-based IDE,加入C/C++編輯器及ARM編譯器5或6(Ultimate edition only)及Debugger、ICE工具 及profiling 分析。(下載30天試用版)

ARM DS-5 包含免費的community Edition(使用gcc compiler), Profession Edition, Ultimate Edition。Ultimate Edition 主要針對64位元 ARMv8 架構且具備Fixed Virtual Platform (FVP), 如果沒有Target Board的話也可以模擬。

2016年3月13日 星期日

Raspberry Pi 移植即時作業系統FreeRTOS




在本次專題研究探討中, 我們以 Rasberry Pi 2 為硬體平台, 一開始先經由移植開源 U-boot 以了解CPU初始化程序及硬體初始化程序,接著以bare-metal 方式來開發Raspberry Pi 週邊界面的驅動程式,如 GPIO、UART及I2C 。

從 U-boot 移植的經驗, 我們不僅熟悉了ARM 組合語言,也了解到ARM 開機程序為何? 初始化中斷向量表為何意? Assembly Code要如何進入到C Code ? Startup Code 為何意 ? Linker Script 角色為何?

接著我們研究FreeRTOS 這套即時作業系統架構及如何將FreeRTOS移稙到各種不同硬體平台上。經由code的層層剖析,了解到任何平台都必須促使FreeRTOS在timer ticker中斷處理函式能正確被觸發, 如此FreeRTOS中的context switch 機制才可正確運作,以達到其Multi-tasking 多工的角色。

我們成功了移植FreeRTOS 到Raspberry Pi 上, 我們也藉由執行FreeRTOS 的API,如xTaskCreate(), vTaskDelay(),xSemaphoreCreateBinary() , 來實測FreeRTOS 的多工與排程等功能。

關鍵詞: Raspberry Pi, FreeRTOS, ARM Cortex-A7,uboot, Bare-metal 閞發, I2C, UART, SPI

 arm bootloader



2016年1月16日 星期六

什麼是Bare Metal 開發 ?


Bare Metal or Bare Machine 開發指的是在沒有OS作業系統的環境下來開發程式, 在這種環境下所開發出來的產物, 像是BIOS程式, Boot Loader 這類的程式。

藉由Bare Metal 開發, 我們可以學些什麼? 
  1. ARM 的CPU架構及組合語言
  2. ARM例外處理機制
  3. 從何處位址開機 ?  CPU initialize & DRAM controller initialize 
  4. How to Execute Code ? 如何撰寫Linker Script 
  5. SoC 與ARM 的關聯性, 
  6. 在沒有OS情況下要如何撰寫程式, 包含Application或 Chip Driver

相關文章:


arm bootloader







2015年9月10日 星期四

Raspberry Pi mini UART


mini UART 規格如下:

The mini Uart has the following features:
• 7 or 8 bit operation.
• 1 start and 1 stop bit.
• No parities.
• Break generation.
8 symbols deep FIFOs for receive and transmit.
• SW controlled RTS, SW readable CTS.
• Auto flow control with programmable FIFO level.
• 16550 like registers.
• Baudrate derived from system clock.


mini UART 暫存器控制整理如下: 


AUX BaseAddr 0x7E210000

0x7E21 5000 AUX_IRQ Auxiliary Interrupt status
0x7E21 5004 AUX_ENABLES Auxiliary enables
0x7E21 5040 AUX_MU_IO_REG Mini Uart I/O Data
0x7E21 5044 AUX_MU_IER_REG Mini Uart Interrupt Enable
0x7E21 5048 AUX_MU_IIR_REG Mini Uart Interrupt Identify
0x7E21 504C AUX_MU_LCR_REG Mini Uart Line Control
0x7E21 5050 AUX_MU_MCR_REG Mini Uart Modem Control
0x7E21 5054 AUX_MU_LSR_REG Mini Uart Line Status
0x7E21 5058 AUX_MU_MSR_REG Mini Uart Modem Status
0x7E21 505C AUX_MU_SCRATCH Mini Uart Scratch
0x7E21 5060 AUX_MU_CNTL_REG Mini Uart Extra Control
0x7E21 5064 AUX_MU_STAT_REG Mini Uart Status
0x7E21 5068 AUX_MU_BAUD_REG Mini UART Baud Rate

  • AUXIRQ : the mini UART has an interrupt pending  if bit 0 is set
  • AUXENB : used to enable miniUART function
  • AUX_MU_CNTL_REG : used to enable RX & TX operation on miniUART
  • AUX_MU_IO_REG : used to write data (1 byte) to and read data (1 byte) from the RX/TX FIFO (8 byte buffer).
  • AUX_MU_IER_REG:  used to enable interrupts and to clear RX/TX FIFO
  • AUX_MU_IIR_REG: used to identify/determine TX or RX interrupt and to clear interrupt pending bit
  • AUX_MU_LCR_REG : used to set data bit length (8 bit or 7 bit)  and gives access to the baudrate register (DLAB access=1)
  • AUX_MU_BAUD : set the 16-bit wide baudrate counter.
  • AUX_MU_STAT_REG: Some information about the internal status of the miniUART.
    bit[27:24] Transmit FIFO fill level: TX FIFO有多少資料 (範圍:0~8 byte)
    bit[19:16] Receive FIFO fill level : RX FIFO有多少資料 (範圍:0~8 byte)
Note: 

  1. AUXENB : If the enable bits are clear you will have no access to a peripheral. You can not even read or write the registers! 
  2. GPIO pins should be set up first the before enabling the UART.  So when it is enabled any data at the inputs will immediately be received . If the UART1_RX line is low (because the GPIO pins have not been set-up yet)  that will be seen as a start bit and the UART will start receiving 0x00-characters. 
  3. After a reset: the baudrate will be zero and the system clock will be 250 MHz
  4. Baud Rate:

Figure 2. UART receive frame synchronization and data sampling points.

Figure  shows a common method used by a UART receiver to synchronize itself to a received frame. The receive UART uses a clock that is 16 times the data rate. A new frame is recognized by the falling edge at the beginning of the active-low START bit. This occurs when the signal changes from the active-high STOP bit or bus idle condition. The receive UART resets its counters on this falling edge, expects the mid-START bit to occur after 8 clock cycles, and anticipates the midpoint of each subsequent bit to appear every 16 clock cycles thereafter. The START bit is typically sampled at the middle of bit time to check that the level is still low and ensure that the detected falling edge was a START bit, not a noise spike. Another improvement is to sample the START bit three times (clock counts 7, 8, and 9, out of 16) instead of sampling it only at the midbit position (clock count 8 out of 16).

 arm bootloader

BCM2835設定BaudRate counter兩種方式






void rpi_aux_mu_init() {
    volatile uint32_t reg_val;
    uint32_t t;

    /* Enable aux uart */
    RPI_AUX->ENABLES = RPI_AUX_MU_ENABLE;

    RPI_AUX->MU_IER = 0;

    /* Disable flow control */
    RPI_AUX->MU_CNTL = 0;

    RPI_AUX->MU_LCR = RPI_AUX_MU_LCR_8BIT_MODE;

    RPI_AUX->MU_MCR = 0;

    /* Diable all interrupts from mu and clear the fifos */
    RPI_AUX->MU_IER = 0;
    RPI_AUX->MU_IIR = 0xC6;


    //#define bits 8
  //RPI_AUX->MU_BAUD = ( _RPI_SYS_FREQ / ( 8 * bits )) - 1;
    RPI_AUX->MU_BAUD = 270;

    /* Setup GPIO 14 and 15 as alternative function 5 which is
     UART 1 TXD/RXD. These need to be set before enabling the UART */

    reg_val = memio_read32(_GPIO_FSEL1);
    reg_val &= ~(7 << 12); // GPIO 14
    reg_val |= 2 << 12;      // ALT5
    reg_val &= ~(7 << 15); // GPIO 15
    reg_val |= 2 << 15;      // ALT5

    memio_write32(_GPIO_FSEL1, reg_val);
    memio_write32(_GPIO_PUD, 0);
    dummy(150);
    memio_write32(_GPIO_PUD_CLK0, (1 << 14) | (1 << 15));
    dummy(150);
    memio_write32(_GPIO_PUD_CLK0, 0);

    RPI_AUX->MU_CNTL = RPI_AUX_MU_CNTL_TX_ENABLE |            RPI_AUX_MU_CNTL_RX_ENABLE;
}

其他相關文件:

  1. 關於 Raspberry Pi 的UART
  2. Determining Clock Accuracy Requirements for UART Communications
  3. 程式範例  https://github.com/dwelch67/raspberrypi



2015年3月6日 星期五

ARM Development Suite (ADS)使用



利用ARM Development Suite (ADS)了解ARM 組合語言


安裝ADS (ver 1.2) 後, 可以進入AXD,在options下 "Configure Target"為 ARMUL, 就可以設定ARM Emulator 環境, 開始去學習ARM 組語與了解ARM 架構。








 arm bootloader

按F8 可以Step In單步執行, 看見程式執行時ARM Register r0~r15及CPSR的變化, 並可看到不同運作模式下 FIQ, IRQ,SVC等的Register值變化。也可以看記憶體的變化。


反組譯


該如何從Assembly 跳到C

ARM 初始化程序 ,即一開始設定Exception Vector 並設定好對應的處理函式 (Exception Handler), 初始化 DRAM (即設定DRAM Controller), 指定ARM Stack Pointer (r13) 於DRAM Address, 以進入C 程式

在進入C之前, 尚須了解一個object code的結構,如 Code Section (.text), RW section, ZI  section(.bss)等。接著了解Linker的功能及Linker script 的意義及包含 Load Address (LMA)及Run address (VMA)的不同。一個程式的啓動順序, 包含copy from Load address to Run address), 配置程式執行記憶體空間 及初始化 .bss 區塊為零。最後執行Branch 指令跳到 C 函式, 此函式即為C的進入點。



待續...