1 \documentclass[a4paper,11pt]{article}
3 \usepackage[latin1]{inputenc}
4 \usepackage[T1]{fontenc}
5 \usepackage[normalem]{ulem}
6 \usepackage[english]{babel}
7 \usepackage{listings,babel}
8 \lstset{breaklines=true,basicstyle=\ttfamily}
15 \title{Milkymist system reference manual}
16 \author{S\'ebastien Bourdeauducq}
20 \section{What is Milkymist}
21 The goal of the project is to develop a small stand-alone board that is capable of rendering MilkDrop presets in real time from an audio input (analog or digital), and displaying them on a VGA screen.
23 Open source components have been used as much as possible, and therefore a system-on-chip implemented in a FPGA has been chosen for meeting this goal as well as simplifying the PCB. Only a few components need to be added for a minimal video synthesis board:
27 \item Microphone and audio ADC
31 \section{Supported boards}
32 \subsection{Milkymist One}
34 \subsection{Xilinx ML401 development board}
35 This board is equipped with a Virtex-4 FPGA (XC4VLX25). Milkymist can use the on-board peripherals of the ML401:
37 \item VGA output (Analog Devices ADV7125KST50 3x8-bit D/A converter)
38 \item AC'97 audio codec (National Semiconductor LM4550)
39 \item CF card slot (through Xilinx SystemACE)
41 \item LCD screen (Lumex LCM-S01602DTR/M, HD44780-compatible)
46 \item DDRAM (two Infineon HYB25D256160BT-7 chips)
49 \subsection{Avnet Spartan-3A evaluation kit}
50 This board is equipped with a Spartan-3A XC3S400A chip. Because of the limited FPGA capacity and the small number of on-board peripherals, support for this board is only for educational and evaluation purposes.
52 The following peripherals are supported:
60 \section{Components and bus architecture}
64 \includegraphics[height=170mm]{soc_architecture.eps}
65 \caption{SoC block diagram}
68 \subsection{Softcore CPU}
69 The system is equipped with a small general-purpose CPU that drives the hardware acceleration units and performs software-friendly tasks such as GUI and filesystem handling.
71 Mico32 from Lattice Semiconductor has been chosen for this purpose. It can run a special MMU-less version of Linux, and the Milkymist BIOS supports direct loading and booting of Linux kernels.
73 \subsection{System memory}
74 \subsubsection{NOR flash}
75 The Milkymist BIOS is stored in an external NOR flash chip. The NOR flash controller in Milkymist has been designed to prioritize hardware simplicity over performance and functionality. It only supports reading from the flash; storing the boot image must be done using another tool.
77 \subsubsection{On-chip SRAM}
78 The SoC is equipped with a 4KB on-chip RAM, which is mainly used for the initial execution environment, before SDRAM is initialized and functional.
80 The choice has been made to include this on-chip RAM so that advanced debug programs that do not rely on SDRAM can easily be developed and run. Those programs are very useful for debugging the SDRAM, which is often prone to problems.
83 For large volatile data storage, Milkymist is designed to use affordable and industry-standard DDR SDRAM chips. A custom memory controller (HPDMC) has been designed as part of the project, as all other free cores were either non-functional or slow.
85 The memory controller implements the proprietary high-performance FML bus to deliver low-latency and high-bandwidth memory access while using few FPGA resources. FML has been designed as part of the Milkymist project.
88 A simple UART is included, intended to implement a debug console. The UART parameters are fixed: 115200 bps, 8 bits per character, no parity, 1 stop bit.
90 \subsection{System controller}
91 The design uses a ``system controller'' core which includes the interrupt controller, GPIO, two timers, and a 32-bit identification number for the board.
93 See the ``GPIO maps'' and ``IRQ maps'' sections for GPIO and IRQ assignments.
95 \subsection{Memory card}
96 On the ML401, the CF card is accessed through the Xilinx SystemACE chip. The registers of this chip are mapped in the softcore CPU address space using the WISHBONE bus.
98 \subsection{VGA controller}
99 Milkymist uses a VGA signal generator which reads from a RGB565 framebuffer, and implements an FML master to fetch data from the memory. The VGA generator is controlled using a CSR interface.
102 Milkymist can record and play audio through an AC'97 codec. The core that drives the codec is controlled via a CSR interface and supports DMA reads and writes of the PCM data over Wishbone.
104 \subsection{Programmable Floating Point Unit (PFPU)}
105 The PFPU is a simple and high-speed floating point microprocessor, designed to do the bulk vertex data generation for each frame in little time.
107 It has a WISHBONE master for writing the output buffer, and a CSR interface for control.
109 \subsection{Texture Mapping Unit (TMU)}
110 The engine performs texture mapping on a triangle strip. It is a central component of MilkDrop acceleration.
112 It has two FML master interfaces for fetching pixel data, a WISHBONE master to fetch the vertex data, and a CSR slave for control.
114 \subsection{PS/2 controller}
115 Milkymist supports standard PS/2 keyboard/mouse port in read-only mode. This is only implemented on the ML401 board.
119 \subsubsection{Inputs}
121 \begin{tabularx}{\textwidth}{|l|l|X|}
123 \bf{PIO bit} & \bf{Direction} & \bf{Description} \\
125 0 & Input & Pushbutton North (ML401 only) \\
127 1 & Input & Pushbutton West \\
129 2 & Input & Pushbutton South (ML401 only) \\
131 3 & Input & Pushbutton East \\
133 4 & Input & Pushbutton Center \\
135 5 & Input & DIP switch 1 \\
137 6 & Input & DIP switch 2 \\
139 7 & Input & DIP switch 3 \\
141 8 & Input & DIP switch 4 \\
143 9 & Input & DIP switch 5 (ML401 only) \\
145 10 & Input & DIP switch 6 (ML401 only) \\
147 11 & Input & DIP switch 7 (ML401 only) \\
149 12 & Input & DIP switch 8 (ML401 only) \\
153 \subsubsection{Outputs}
155 \begin{tabularx}{\textwidth}{|l|l|X|}
157 \bf{PIO bit} & \bf{Direction} & \bf{Description} \\
159 0 & Output & LED 2 (NB. ML401's LED 0 and LED 1 respectively monitor UART transmission and reception) \\
161 1 & Output & LED 3 \\
163 2 & Output & LED North (ML401 only) \\
165 3 & Output & LED West (ML401 only) \\
167 4 & Output & LED South (ML401 only) \\
169 5 & Output & LED East (ML401 only) \\
171 6 & Output & LED Center (ML401 only) \\
173 7 & Output & HD44780-compatible LCD (ML401 only) -- E pin \\
175 8 & Output & HD44780-compatible LCD (ML401 only) -- RS pin \\
177 9 & Output & HD44780-compatible LCD (ML401 only) -- RW pin \\
179 10 & Output & HD44780-compatible LCD (ML401 only) -- D4 pin \\
181 11 & Output & HD44780-compatible LCD (ML401 only) -- D5 pin \\
183 12 & Output & HD44780-compatible LCD (ML401 only) -- D6 pin \\
185 13 & Output & HD44780-compatible LCD (ML401 only) -- D7 pin \\
189 \section{Address map}
191 \begin{tabularx}{\textwidth}{|l|l|X|}
193 \bf{Base address} & \bf{Cacheable} & \bf{Peripheral} \\
195 0x00000000 & Yes & Boot ROM (NOR Flash) \\
197 0x20000000 & Yes & On-chip SRAM \\
199 0x40000000 & Yes & \textit{FastMemoryLink bridge} \\
201 \hspace{5mm} 0x40000000 & Yes & \hspace{5mm} DDR SDRAM data \\
203 \hspace{5mm} 0x44000000 & Yes (write-through) & \hspace{5mm} L2 cache line flush \\
205 0x80000000 & No & \textit{CSR bridge} \\
207 \hspace{5mm} 0x80000000 & No & \hspace{5mm} UART \\
209 \hspace{5mm} 0x80001000 & No & \hspace{5mm} System controller \\
211 \hspace{5mm} 0x80002000 & No & \hspace{5mm} DDR SDRAM control \\
213 \hspace{5mm} 0x80003000 & No & \hspace{5mm} VGA \\
215 \hspace{5mm} 0x80004000 & No & \hspace{5mm} AC'97 \\
217 \hspace{5mm} 0x80005000 & No & \hspace{5mm} PFPU \\
219 \hspace{5mm} 0x80006000 & No & \hspace{5mm} TMU \\
221 \hspace{5mm} 0x80007000 & No & \hspace{5mm} PS/2 (ML401 only) \\
223 0xa0000000 & No & SystemACE (ML401 only) \\
228 \begin{tabularx}{\textwidth}{|l|X|}
230 \bf{IRQ} & \bf{Peripheral} \\
242 5 & AC'97 (codec configuration registers, request sent)\\
244 6 & AC'97 (codec configuration registers, reply received)\\
246 7 & AC'97 (DMA read)\\
248 8 & AC'97 (DMA write)\\
250 9 & Programmable Floating Point Unit\\
252 10 & Texture Mapping Unit\\
254 11 & PS/2 (ML401 only)\\
258 \section{BIOS and boot process}
259 Using an ``execute-in-place'' schema, the system boots from the NOR flash, mapped at address 0x00000000 (the reset vector for the softcore CPU). It contains a BIOS which is in charge of booting the board as well as providing debugging features.
261 The Milkymist BIOS is based on FreeMAC (\url{http://lekernel.net/prism54/freemac.html}), originally written for running on the ARM embedded processors of Prism54 Wi-Fi cards. It has undergone major modifications since then.
263 The BIOS loads firmware from an external source (CF card or UART). The BIOS supports direct booting of Linux kernels. If no suitable boot medium is found, it starts a debug shell on the UART, which allows to do basic system operations such as writing to registers. The \verb!help! command lists the commands available with the BIOS release you are currently using.
265 All transmissions over the UART are made at 115200 bps or 230400 bps, with 8 bits per character, without parity, and with 1 stop bit. The second DIP switch on the board enables the 230400 bps rate when it is set, which is convenient when transferring large firmware images such as Linux kernels.
267 \subsection{Starting Linux}
268 The BIOS can directly start versions of Linux specifically made for running on Milkymist boards. Such modified Linux kernels are distributed separately.
271 \item \textbf{The Linux kernel itself} is always loaded at the beginning of the SDRAM (0x40000000) and executed from there.
272 \item \textbf{Kernel command line parameters} are written to SDRAM and their address is set in CPU register \verb!r1! before the kernel is started.
273 \item \textbf{Initial ramdisk (initrd)} is optionally loaded into SDRAM and its start and end addresses are set in CPU registers \verb!r2! and \verb!r3!, respectively.
276 \subsection{Boot from the UART}
277 The first boot medium tried by the BIOS is the UART, using a special protocol. This enables firmware replacement during development by just connecting the serial cable and not switching a memory card between a computer and the device.
279 The device initiates an UART boot session by sending the ASCII string \verb!sL5DdSMmkekro! followed by a carriage return. This string is completely random, but has been encoded in ASCII so it does not garble the output of terminals which are not aware of the boot protocol.
281 Upon reception of this magic string, the UART boot program running on the host computer acknowledges it by returning the ASCII string \verb!z6IHG7cYDID6o! followed by a carriage return. This puts the device in firmware reception mode, and further commands are sent in binary using the protocol described below.
283 The host sends command to the device, which acknowledges them or reports errors by sending one ASCII character after each command. Those characters and their meanings are listed in the table below:\\
285 \begin{tabular}{|l|l|}
287 \verb!K! & Command successful \\
289 \verb!C! & CRC error, retry the command \\
291 \verb!U! & Unknown command ID \\
293 \verb!E! & Generic error \\
297 The host must wait for a reply from the device before sending the next command. However, it can retry the command after a timeout.
299 All the commands sent by the host are frames using this common format:\\
301 \begin{tabular}{|l|l|l|l|}
303 \textbf{Length} & \textbf{CRC16} & \textbf{Command ID} & \textbf{Payload} \\
305 1 byte & 2 bytes & 1 byte & 0-255 bytes \\
309 (As in the whole document, all multi-byte numbers are big-endian unless otherwise specified)
311 The length field is the length of the payload. The CRC16 is computed on the command ID followed by the payload.
313 The following commands are implemented:\\
315 \begin{tabularx}{\textwidth}{|l|X|}
317 \textbf{Command ID} & \textbf{Description} \\
319 0x00 & Abort session. No payload. The BIOS continues to the next boot medium. \\
321 0x01 & Load to memory. The payload is a 32-bit start address followed by the data. \\
323 0x02 & Jump. The payload is the 32-bit jump address. \\
325 \multicolumn{2}{|c|}{\textbf{Linux-specific commands}} \\
327 0x03 & Set Linux kernel command line parameters address. The payload is the 32-bit address. This address is written to the CPU register r1 before the kernel is started (using a jump command). \\
329 0x04 & Set Linux kernel initrd start address. The payload is the 32-bit address. This address is written to the CPU register r2. \\
331 0x05 & Set Linux kernel initrd end address. The payload is the 32-bit address. This address is written to the CPU register r3. \\
335 \subsection{Boot from the CF card}
336 If the device has not received an acknowledgement for UART boot after a certain period of time, it then attempts to boot from the CF card.
338 For this purpose, it searches for a file named \verb!BOOT.BIN! on the first FAT partition. It then loads it into the beginning of the SDRAM, and, if this was successful, transfers execution to the SDRAM.
340 If the first DIP switch on the board is set, the BIOS uses the \verb!ALTBOOT.BIN! file instead.
342 \paragraph{Linux support.} If the CF card also contains files named \verb!CMDLINE.TXT! and \verb!INITRD.BIN!, they are loaded into SDRAM at offsets \verb!0x1000000! (16MB) and \verb!0x1002000! (16MB + 8KB) respectively. The addresses are then passed to the kernel (loaded from \verb!BOOT.BIN! or \verb!ALTBOOT.BIN!) using CPU registers \verb!r1!, \verb!r2! and \verb!r3! (see above). The files must be small enough so that they do not overlap in memory.