update
[libreriscv.git] / shakti / m_class / peripheralschematics.mdwn
1 # Example Reference Schematics for Peripherals
2
3 # Selection of a suitable PMIC
4
5 Selecting a PMIC is tricky. Corporations such as Intel have gotten themselves
6 into a lot of trouble by supplying an SoC under NDA, then forgetting that
7 it's ultra-important to supply an easily-accessible PMIC that doesn't
8 additionally require a totally separate NDA just to gain access to it!
9 Total madness: cartelling by accident or by design (literally).
10
11 Allwinner's solution was to actually buy a PMIC company (X-Powers), and
12 for every new SoC they actually designed a corresponding companion PMIC,
13 often selling it along-side the SoC at a combined price. Ingenic, as
14 a smaller company, picks off-the-shelf PMICs from Actions Semi (typically
15 the ACT8600 or similar). Rockchip also picked Actions Semi PMICs for
16 the RK3288 designs but unlike the majority of X-Powers (AXP) offerings,
17 none of these cover battery charging or OTG Power-switching.
18
19 DCin, battery and OTG "Charging" is a **three-way** power-routing problem
20 that, due to the amounts of current involved, and the possibility of
21 blowing up lithium cells and causing people's houses to catch fire, is
22 somthing that has to be taken very very seriously.
23 Not blowing up devices by getting into a current bun-fight over who is
24 going to supply 5.0v (battery, main power, DCin or the USB charger) is
25 really quite complicated, and the AXP209 in conjunction with SY6280
26 current-limiter ICs per USB port can take care of that, easily enough.
27
28 Without this integrated capacity to route power it actually becomes
29 extremely hair-raising and requires something like 60 discrete components
30 and ICs to replicate (see jz4760 reference schematics "LEPUS Board"
31 for an example). Alternatives for higher power (up to 4.5A) but not
32 the same level of integration as the AXP209, include the bq2419x series
33 from TI. Using anything from the bq24193 series still requires external
34 components for 3-way power protection, as well as an external high-current
35 efficient power-regulator to drop the input DC down to a stable 5V supply.
36
37 Alternatives which do not have the same OTG Power provision
38 but are lower cost and around the same current include the ACT8600 (2A),
39 and the ACT8846 which can handle around 3A but requires companion
40 ICs (SYR627 and SYR628) for the SoC core domain supply (see below).
41 Another option would be something like the AXP803, however this PMIC
42 requires a rather large companion MOSFET to handle / switch the battery
43 and charging current, where the AXP209, by being less power-hungry,
44 has that same MOSFET integrated.
45
46 A critical aspect of PMIC selection is that the default output voltages
47 at power-up are compatible with the SoC. Supply voltages **need** to be set
48 so that during low clock rate operation the amount of power consumed is
49 greatly reduced, however at higher clockrates the current draw of flipping
50 1s to 0s and vice-versa causes a voltage drop that takes 1s and 0s outside
51 of their "definitions". The solution: increase the voltage supply.
52
53 The AXP209's main "core voltage" DCDC converter
54 defaults to 1.2v for example, and the
55 DCDC converter that is used for supplying the
56 DRAM typically defaults to 1.5v. **These voltages are typically hard-wired
57 into the PMIC's firmware**.
58 Some PMICs may be re-programmed manually (at the factory) i.e have
59 an on-board EEPROM, but this adds considerable complexity to manufacturing,
60 as the PMIC must be pre-programmed **before** it can be safely connected
61 to the SoC.
62
63 So to avoid cartel scenarios and also to avoid custom-ordering of (minimum
64 10k-50k PMICs), and to avoid the manufacturing and design complexity of
65 re-programming the PMIC before it can be connected to the SoC, the best
66 course of action is to analyse some available and extremely common PMICs,
67 find out what their default outputs are, and then **arrange the SoC and
68 the DRAM to be compatible with them** rather than the other way round.
69 Primarily it is the core CPU voltage that, if exceeded, could damage the
70 processor: the PMICs below default to between 1.0 and 1.25v; the DRAM
71 voltage also typically defaults to 1.5v, meaning that DRAM ICs selected
72 for the application will need to be rated for that. During the first
73 second or so of startup, the boot firmware will need to get the SoC to
74 communicate with the PMIC and set more suitable voltages before carrying
75 on with the boot process. This is a Standard Operational Procedure
76 which is encoded into either the BIOS or into u-boot.
77
78 ## AXP209
79
80 An extremely well-supported, very simple-to-deploy and very comprehensive
81 PMIC that includes support for USB OTG power flipping as well as battery
82 charging. It copes with up to around a 2A power provision.
83
84 Control Signals for the AXP209 are as follows:
85
86 * NMI# - Non-maskable Interrupt. connect to main SoC. absolutely critical.
87 * PWRON - Power On. Press-and-hold style, generates IRQ for SoC to shut down.
88 * I2C SDA/SCL - for being able to manage the PMIC, change voltage output levels
89 * GPIO1-3 - spare GPIO accessible over the I2C Bus
90 * VBUSEN# - for controlling (enabling) the VBUS power.
91
92 This latter signal - VBUSEN# - is absolutely critical. The AXP209 can cut
93 the power when needed (when an OTG charger is plugged in), or it can do so as
94 directed by the SoC, which detects incoming power or there is the required
95 OTG "ID" negotiated.
96
97 Power outputs are roughly as follows:
98
99 * IPSOUT - basically either the battery or the 5V DC mains input. Needs
100 to be boosted (e.g. SY7208) to provide a stable 5.0v
101 * DCDC outputs - the exact voltages are under I2C control. They're high
102 current, usually used for the DDR3 main supply, core SoC supply and so on.
103 * LDO outputs - again controlled through I2C. Typically used for Camera,
104 Analog 3.3v and so on (around 200-300mA). One of them is suitable for a
105 RTC supply, when the rest of the board (and the PMIC) are in shut-down mode.
106
107 Note that for the CPU and DDR3, the SoC has to either be designed to cope
108 with the default pre-set voltages (1.2v for the CPU core for example and
109 1.5v for DDR3) and to run for a very short while on those whilst the CPU gets
110 a chance to change them by communicating over the I2C Bus to the PMIC, or it
111 is necessary to **custom-order** a very special PMIC with preset voltages
112 from a PMIC Manufacturer, which means a MOQ of 10k to 50k units.
113
114 Honestly it is simpler to just design the SoC to cope with the higher voltage.
115
116 [[!img AXP209.jpg]]
117
118 # ACT8846 with SYR827 and SYR828 companion ICs
119
120 This PMIC is used typically in conjunction with the 28nm Rockchip RK3288,
121 and full schematics may be found by searching for "T-Firefly" and also
122 "EOMA68-RK3288". Like the AXP209 it is an integrated PMIC but it does **not**
123 handle battery charging or VBUS detection and OTG triple-way power switching.
124
125 It does however, in combination with the SYR827 and SYR828, handle a lot
126 more power than the AXP209 (2.8A for two of its DC-DC converters). The SYR827
127 and SYR828 are used on the RK3288 to provide the SoC core domain power and
128 the GPU core power, respectively. The default voltage is 1.0 volts and may
129 be reduced or increased under I2C control as needed.
130
131 [[!img ACT8846.jpg]]
132
133 [[!img SYR827.828.jpg]]
134
135 # AXP803 and companion MOSFET for Battery
136
137 The AXP803 handles a lot more current and has a lot more options than the
138 AXP209: it's a bit larger, a bit more expensive, but is specifically designed
139 for modern quad-core SoCs. It can also handle a lot more current for charging
140 because the battery MOSFET is an external IC.
141
142 The A64 for which this PMIC was first deployed is a 40nm quad-core SoC, so
143 the default power domains are designed specifically for that SoC.
144
145 Control Signals include:
146
147 * I2C for control, access to GPIO and selection of voltages on all outputs
148 * 2 GPIOs which may be switched to an additional pair of LDOs
149 * NMI# - Non-Maskable Interrupt. Critical to be connected to the SoC.
150 * RESET# - a reset signal
151 * PWR-ON - press or press-and-hold, used for hard power-cycling of the device
152 * USB-DM/DP - this is to detect the presence of an OTG device in a clean way
153 * USBVBUSEN - just as with the AXP209 this controls power to the OTG port.
154
155 The AXP803 has additional capability to detect whether a USB 3.0 OTG Charger
156 has been connected (so that additional current may be negotiated). This is
157 most likely the reason why the USB+/- lines have to be connected to the PMIC.
158
159 Outputs include:
160
161 * 6 DC-DC converters
162 * 3 ELDOs (extremely low-dropout outputs, for high-stability)
163 * 4 DLDOs (digital LDOs)
164 * 3 ALDOs (separate LDOs for Analog supply)
165 * 2 FLDOs (no idea what these are: refer to the datasheet)
166 * Dedicated RTC VCC supply
167
168 Overall it is an extremely sophisticated PMIC which has the advantage of being
169 mass-produced, proven (just like the AXP209 before it), and significant
170 linux kernel driver support that is well-understood.
171
172 [[!img AXP803.jpg]]
173
174 # Ingenic JZ4760 PMIC Approach: Discrete ICs
175
176 The team that did the Ingenic JZ4760 LEPUS Reference Design decided to take
177 a different approach to Power Management: multiple discrete ICs for each
178 power domain. They selected multiple RT8008 ICs and used different resistors
179 to set the required current (which is then not adjustable, but the jz4760 is
180 so low power anyway that this doesn't really matter), and used RT9169 and other
181 3-pin LDOs for the RTC and low-power 1.2v supply.
182
183 Of particular interest is how they did battery charging and the USB OTG
184 power-switching. For the battery charging including being able to charge
185 from either a 5V DCin or the OTG VBUS, they selected the RT9502. A MOSFET
186 protects against power input from VBUS fighting with DCIN, and a Schottky
187 Diode protects against current fights. A **second** MOSFET and Schottky
188 Diode allows power-selection of either battery or DCin to the RT9502.
189 All in all it's quite a sophisticated and clever circuit.
190
191 [[!img RT9502.jpg]]
192
193 USB Power Switching - selecting between either 5V or VBUS to go in (or out)
194 of the OTG Port without blowing anything up - is done with a matched pair
195 of RT9711A and RT9711B ICs. A SY6280 has not been deployed, so it is not
196 precisely clear which IC does the current-provision / over-current protection
197 on the OTG port.
198
199 In addition to these discrete ICs for power provision, there is the usual
200 step-up converter (an RT9266) which converts the 3.8-4.2v battery directly
201 into a stable +5V supply. This is fairly normal, and can be seen in
202 pretty much every design (whether using the AXP209, AXP803, ACT8600, ACT8846
203 and so on). It is very interesting in this case however to note that
204 the DCin is wired (via the two MOSFETs and Schottky Diodes) directly to
205 BAT-V (and thus supplies the +5V rail) but that, thanks to those MOSFETs
206 and Schottkys, if either VBUS powers up or the battery powers up, they
207 **replace** the power stream to BAT-V in a priority-cascade.
208
209 This example is included to show that power-provision **can** be done without
210 a dedicated PMIC (but also demonstrating quite how many components it
211 actually needs, to do so). Perhaps it might even still be a viable solution,
212 by replacing some of the discrete (fixed) SY8008 LDOs with SYR828 and SYR829
213 I2C-controllable high-current voltage regulators.
214
215 [[!img RT9711.jpg]]
216
217 [[!img Vregs.jpg]]
218
219 # USB-OTG and USB-Host Ports
220
221 This section covers how to set up an OTG port and a plain USB2 Host port.
222 The USB Host is quite straightforward: protect the power with a SY6280 which
223 performs current-limiting and also stops over-voltage from the USB port
224 bleeding back down into the 5V supply (if someone does something silly like
225 connect a 5.5v or 6v PSU to the USB port), and that's basically it, apart
226 from one note-worthy fact that the SY6280 may be enabled/disabled under the
227 control of the SoC in order to save power or to carry out a hard-reset on USB
228 devices.
229
230 The OTG port is slightly different. Note that there are 2 power lines and
231 3 I/O signals involved:
232
233 * VCC-5V input - for when power is **supplied** to the USB port (OTG Host)
234 * USBVBUS - for when power is supplied **by** the USB port
235 (OTG Client aka usually "OTG Charging")
236 * USB-ID - for OTG negotiation of which end is to be Client and which Host
237 * VBUSDET - a resistor-divider bridge allowing the SoC to detect USBVBUS on/off
238 * USB-DRV - enables or disables the VCC-5V power **supply** (but does not
239 affect, involve, or otherwise stop VBUS - outgoing or incoming)
240
241 It is a good idea to place the USB-DRV under the control of the PMIC, so that
242 it may detect when a charger is plugged in, even if the main SoC is powered
243 down. Bear in mind that this all is a cooperative arrangement where the SoC
244 and the PMIC must collaborate to prevent power-loss and current bun-fights.
245 VBUSDET must be arranged so that the resistor-divider bridge creates just
246 enough of a voltage to trigger an EINT-capable GPIO on the SoC with a "HIGH"
247 or "LOW" digital level (not an ADC in other words).
248
249 [[!img USBports.jpg]]
250
251 # Level-shifted MicroSD
252
253 For instances where the GPIO voltage of the SoC's I/O is not 3.3v, the
254 deployment of a level-shifter is needed. Note the inclusion of ESD protection
255 (which needs to be very close to the SD card slot) and the 47k pull-up
256 resistors. Strictly speaking the Card Detect line (which is an Open Drain)
257 need not be routed through the level-shifter, whereas the SDcard signals,
258 which are push-push high-speed, definitely do. Many "Arduino-style"
259 amateur-deployed level shifting techniques are in fact Open-Drain style and
260 really do not work properly as they rely on the internal capacitance of
261 pins and tracks to drop towards Ground levels: this simply doesn't happen
262 quickly enough, corrupting the signal integrity and is why push-push was
263 invented in the first place.
264
265 This schematic could actually be dynamically converted to adjustable 3.3v/1.8v
266 by replacing the level-shifter VCC-3V3 input power (U2, VCCB) with a power
267 source that is under the control of the SoC. When the SoC detects
268 that the inserted card has 1.8v capability, the SoC could then drop the
269 level-shifter's B side down from 3.3v signal levels to 1.8v levels... all
270 without having to adjust the actual SoC GPIO levels. The down-side:
271 level-shifter ICs are around USD $1, take up a lot of board space relatively
272 speaking, and require double the number of pins as I/O signals.
273
274 [[!img LevelShiftedMicroSD.jpg]]
275
276 # Power-domain-controlled MicroSD
277
278 This second circuit is much simpler in principle yet may still adjust the
279 SD/MMC power levels from 3.3v to 1.8v as required. Also note that the
280 SD Card itself may be powered down under the control of a GPIO signal
281 (named SDMMC-PWR) from the SoC.
282
283 The level-shifting trick however in this case relies on the capability of the
284 SoC and requires the cooperation of the PMIC. A specific LDO output from the
285 PMIC is dedicated to this **one** SD card, and the **entire** power domain
286 for this particular GPIO-bank (which happens only to have SD/MMC on it)
287 is flipped from 3.3v down to 1.8v if needed.
288
289 Note that whilst this GPIO voltage domain power-drop occurs the actual SD
290 card itself is still supplied by 3.3v. Also note that in this circuit
291 the SD-Det is still powered from SDIO (3.3v) so the SoC GPIO will need
292 to be 3.3v tolerant even when it is dropped to 1.8v signalling levels.
293
294 The alternative scheme would be to have an on-board level-shifter where the
295 SD/MMC signal levels (only) are shifted between 3.3v and 1.8v levels, whilst
296 leaving the rest of the entire GPIO bank's voltage levels alone. This seems
297 inordinately overcomplex.
298
299 [[!img PowerDomainMicroSD.jpg]]
300
301 # AC97-compliant (I2S) Audio
302
303 Under certain circumstances, USB Audio may be preferred over I2S (the
304 CM108AH is a very good low-cost choice that is still mass-produced and
305 has full schematics and no NDAs required). However USB bulk audio
306 framing introduces latency that may prove intolerable under certain
307 high-end circumstances (Media Centre for example). I2S was designed
308 for low-latency and high-quality Digital Audio, send and receive.
309
310 An example AC97-compliant Audio IC is the ES8323. In this instance it
311 is a very low-cost one (around $0.50 for single quanties from multiple
312 vendors on taobao.com), that only has a single stereo earphone output and
313 a single mono microphone input. For ultra-low-cost applications this
314 is perfectly fine, considering the price and high availability. Also,
315 using the right type of stereo headphone jack (a PJ-0345 6-pin) it
316 becomes possible to hard-switch (and detect - using another of the
317 precious EINT lines to the SoC) stereo headphone jack insertion and to
318 route both outputs, via the headphone jack, back to a pair of low-cost
319 audio amplifier ICS (TDA2822), the important thing being that this
320 requires **no** additional signals or involvement or wires to/from the
321 AC97 Audio IC. It's crude but effective: the only thing needed to watch
322 out for is to make sure that the jack insertion (or removal) is properly
323 detected and that the audio volume level adjusted in sufficient time
324 (if needed). Careful inclusion of the right resistor-divider bridges
325 etc. can mitigate even against needing to do that.
326
327 Control signals to the ES8323 are:
328
329 * 5-pin I2S: this includes, in this example, only one DO and only one DI.
330 * I2C: used to control the ES8323 (volume, configuration)
331
332 Audio signals are:
333
334 * Mono Microphone input
335 * Stereo Headphone
336
337 Many more sophisticated examples exist, which include 5-lane I2S (4 output,
338 1 input) for Dolby 5.1 and 7 Surround Sound, multiple audio paths including
339 Line-out, Line-in, Car Stereo, etc. etc. - one obsolete one that was extremely
340 good was the Akai AK4641 used in the HTC Universal clamshell / micro-laptop
341 smartphone. All in all it just depends on the application but the actual
342 signals / buses involved remains pretty much the same in all cases: I2S for
343 Audio data, I2C for control of the IC (AC97 volumes and routing etc.) and
344 optional GPIO for detection e.g. of physical insertion of headphone and
345 other jacks. That's about it.
346
347 [[!img ES8323.jpg]]
348
349 [[!img TDA2822.jpg]]
350
351 # 802.11 WIFI and BT
352
353 **WARNING: there are *NO* low-power embedded WIFI ICs that are RYF-Endorseable.
354 *ALL* firmware for *ALL* embedded (SD/MMC) WIFI SIP modules and ICs are
355 proprietary and cannot in any way be trusted not to compromise a machine
356 through *built-in* factory-installed spying, or hardware level malicious
357 hacking (this is not a theoretical concept: it has been successfully
358 demonstrated by Security Researchers, numerous times on numerous chipsets
359 and numerous architectures and OSes). If you include a hard-wired
360 SD/MMC embedded WIFI SIP module hard-soldered to a PCB it is a sure-fire
361 *GUARANTEED* way to 100 percent *FAIL* RYF Endorsement and Certification.
362 If RYF Endorsement and the safety and privacy of end-users is important,
363 ensure that the WIFI module may be *REMOVED* (physically by the user
364 or simply not installed at the factory) and USB-based WIFI such as the
365 ThinkPenguin TP150N, a small 802.11abgn WIFI dongle, inserted into the
366 device instead (either internally or externally) with the end-user having
367 the right to remove it.**
368
369 With that huge warning out of the way, we can move on to describe the signals
370 required for an example 802.11a/b/g/n/ac WIFI and BT 4.0 SIP Module. These
371 are:
372
373 * 4-lane SD/MMC for the WIFI data. This is standard for low-power SIP WIFI
374 * 4-wire UART for Bluetooth, including TX/RX as well as CTS/RTS.
375 * Quite a lot of IRQ and communication lines: up to five EINTs and GPIO in
376 the case of this particular SoC.
377
378 The GPIO lines particularly EINTs are critical for WIFI and Bluetooth,
379 particularly as applications may be adversely affected by clashes of these
380 two protocols sharing the same 2.4ghz frequency bands. So the OS needs to
381 know when a clash is detected, immediately: that requires an EINT-capable
382 GPIO, on its own. Also, BT or WIFI (separately) may be used to wake up a
383 host that has been placed into low-power sleep mode: again, that requires
384 two separate and distinct EINT-capable GPIO lines.
385
386 This particular WIFI SIP module also takes a 32.768kHz RTC input signal
387 (which may be generated by the SoC or by a companion MCU), and it is also
388 recommended to dedicate an additional GPIO to a MOSFET or other means to
389 hard-kill the entire WIFI module.
390
391 So on the face of it, it seems very straightforward, just route SD/MMC
392 and UART, but it's actually quite involved. It would seem, then, that
393 deploying a USB WIFI module would be a much simpler idea, especially
394 given that USB2 is only 2 wires (plus power) and things like "wakeup"
395 and "signalling" etc. are typically handled (with the common exception
396 of protocol-clashing) via the provision of features built-in to the
397 USB Bus Protocol. The down-side: most USB2 WIFI dongles, modules and
398 chipsets are simply not designed for low-power scenarios, not at the
399 hardware level and certainly not at the firmware level.
400
401 Only one (modern) USB chipset - which only supports 802.11abgn and not ac -
402 has full firmware source code available under Libre Licensing, thanks to
403 ThinkPenguin's tireless efforts: the Atheros AR9271 USB Chipset. ThinkPenguin
404 spent two years walking Atheros through the process of releasing the full
405 firmware source code, and it is the only chipset where peer-to-peer mesh
406 networking has been added by the Free Software Community, and it is the
407 only chipset that could be considered for adjusting the firmware to reduce
408 power consumption. Time however is running out for this chip because
409 Qualcomm subequently bought Atheros, and Qualcomm replaced the entire
410 management with people who completely fail to comprehend what made the
411 AR9271 so very successful.
412
413 Bottom line: WIFI and Bluetooth are an ethical minefield as far as
414 user privacy, rights, and hardware-level remote hacking are concerend,
415 and it starts right at the early design phase: component selection.
416 A good way to ensure that users have control over their own devices is
417 to add hardware (physical) kill-switches to the power lines, and/or
418 to allow them to actually physically and completely remove the WIFI /
419 BT module without invalidating the warranty.
420
421 Datasheet: <http://www.t-firefly.com/download/firefly-rk3288/hardware/AP6335%20datasheet_V1.3_02102014.pdf>
422
423 [[!img AP6335.jpg]]
424
425 # I2C Sensors
426
427 I2C sensors appear on the face of it to be quite straightforward: wire them
428 up to the 2-line I2C bus and it's done, right? It's not that simple: I2C
429 is a **master** bus only, meaning that if the peripheral has important data,
430 it has to have some way of letting the SoC know that something's happened.
431 This requires an EINT-capable IRQ line on the SoC in order to wake up the
432 SoC from tasks or low-power mode(s). In addition, it's often the case
433 that the sensor may need an occasional (or a definitive, on start-up)
434 RESET. In particular it's a good idea to reset sensors after power-on due
435 to potential problems caused by in-rush current instability: often this is
436 covered in the datasheet as being **required**.
437
438 So typically for each sensor, two extra GPIO lines are required: one EINT
439 and one not. If the amount of GPIO begins to run out (EINTs are usually a
440 finite resource) then it is technically possible to share SoC EINT lines
441 using logic gates (one for a group of sensors), board-space permitting.
442 The other technique is to use a companion MCU for EINT aggregation, and
443 even, if pins are particularly sparse, to use the fact that the USB Bus
444 has built-in wake-up capability to the SoC. A signal (or the actual data
445 if the sensor is directly connected to the MCU instead) can be sent over
446 USB. Typically in this instance it's a good idea to use the MCU to convert
447 to a more standard format such as presenting one or more USB-HID endpoints
448 (for CTP, Trackpad and mouse-like sensors), otherwise a special linux kernel
449 driver needs to be written.
450
451 Other than that, sensors are pretty straightforward. Most already have a
452 linux kernel driver already available. If they don't, they're best avoided:
453 pick another one that does, as it's a sure-fire sign that the sensor has not
454 seen mass-volume production deployment, or if it has, there's been zero
455 opportunity to do a security review of the source code and/or it'll be
456 GPL-violating.
457
458 [[!img I2CSensors.jpg]]
459
460 # Ethernet PHY IC
461
462 The normal standard for Ethernet PHYs is MII (10/100) and its variants, GMII
463 (10/100/1000 Ethernet), RGMII and so on. There is however a different
464 approach: MCU-based interfaces. In this particular instance, the Shakti
465 team have already created a FlexBus implementation, which can be used
466 to emulate the required SRAM / 8080-style micro-controller interface needed.
467 A number of MCU-based Ethernet PHY ICs exist, including the AX88180
468 (which is a Gigabit MCU-to-RGMII converter), the AX88796A (a 10/100
469 PHY which supports 8080 as well as MC68k-style interfaces), and the
470 low-cost and well-established 10/100 DM9000 PHY. It requires the
471 following signals:
472
473 * 16-bit Data/Address Bus
474 * CMD select (Changes bus from Data to Address lines)
475 * PWRST# (Power-on Reset)
476 * IRQ (Interrupt indicator from DM9000 to SoC)
477 * IOR# (Read Ready)
478 * IOW# (Write Ready)
479 * CS# (Chip Select)
480
481 This comes to a total of 22 GPIO lines, which is a significant amount.
482 However it is also possible to run the DM9000 bus at a reduced 8-bit
483 width (with a slightly different pin arrangement for the top 8 bit pins:
484 see datasheet for details), for a total 14 pincount. In addition,
485 as a general-purpose shared memory bus it's possible to connect other
486 peripherals simultaneously, mitigating the high pincount issue, requiring
487 only one Chip Select line per peripheral. For example, if two Ethernet
488 PHY ICs are required they may be placed on the exact same Bus: only one
489 extra CS# line is required, and the pincount is now 15 pins for two
490 Ethernet PHY ICs: a much better average pincount ratio than would be
491 achieved from using two RGMII PHYs.
492
493 Other important details: the AX88180, AX88796A and the DM9000 all have
494 had linux kernel and u-boot driver source code available for many years.
495
496 Datasheet: <https://www.heyrick.co.uk/blog/files/datasheets/dm9000aep.pdf>
497
498 [[!img DM9000.jpg]]
499
500 # USB-based Camera IC or Bit-banging CSI
501
502 Low-cost Cameras typically require either a MIPI interface (CSI-2) or
503 a Parallel Bus-style interface (CSI-1). Theoretically it is possible
504 to bit-bang the CSI-1 interface, using a PWM for generating the clock,
505 reading the HSYNC and VSYNC signals and the 8 to 12-bit data, and even
506 using DMA to optimise the process. For an example implementation of this
507 techique see
508 <https://www.nxp.com/docs/en/application-note/AN4627.pdf>
509
510 However the DMA / bit-banging technique takes up at least 12 pins,
511 14 if the I2C interface is included, and many sensors require a minimum
512 clockrate (data-rate) of 12 mhz before they will respond. A way to greatly
513 reduce pincount is to use a USB-based IC, such as the low-cost, mass
514 produced VC0345 from VIMicro.
515
516 The VC0345 can do up to VGA @ 30fps, and can take still pictures up to 3M-pixels
517 so is not exactly the fastest bunny on the block, but it has the distinct
518 advantage of not requiring an NDA to gain access to either the datasheet or
519 the app notes, and it is so commonly available that approaching the
520 manufacturer is not actually necessary: it can be obtained directly from
521 Shenzhen Markets. Also as it is a UVC-video compliant device, linux kernel
522 driver support is automatic.
523
524 An alternative approach to using an off-the-shelf CSI-to-USB Camera IC is
525 to use a companion MCU: after all, the VC0345 is just a general-purpose
526 8051 MCU. A student achieved this with an ultra-low-cost
527 Camera Sensor (QVGA) and an STM32F103 back in 2010:
528 <https://github.com/adamgreig/negativeacknowledge/blob/master/content/from-wordpress/robot2-an-arm-based-colour-tracking-robot.md>
529
530 However for coping with larger sensors, care has to be taken: not least,
531 it is not possible to fit an entire sensor frame into the SRAM of a small
532 MCU, so there has to be some care taken to avoid loss of data. Also,
533 the MCU must have 480mbit/sec USB2 capability, as beyond around
534 640x480 even at 15fps a USB 1.1 11mbit/sec bus becomes completely saturated.
535 Also to watch out for is whether the MCU's USB hardware supports enough
536 simultaneous endpoints, particularly if USB-HID for keyboard (matrix to
537 USB-HID keyboard) and/or USB-HID trackpad (mouse) or other devices are
538 to be managed by the same MCU. Those caveats in mind: it is actually
539 achievable.
540
541 * Datasheet: <http://hands.com/~lkcl/eoma/kde_tablet/VC0345TLNA-1102-V10-EN.pdf>
542 * VC0345 App Note: <http://hands.com/~lkcl/eoma/kde_tablet/VC0345_app_notes.pdf>
543
544 # USB-Based 3G / UMTS/HSDPA Modem
545
546 GSM / GPRS / EDGE Modems are typically slow enough to be able to use a UART
547 at 115200 baud data rates. 3G on the other hand is fast enough to warrant the
548 use of a USB connection. Depending on the firmware, some 3G USB-based Modems
549 offer multiple endpoints, some of which can transfer audio data. Others
550 offer two-way duplex digital audio over a standard four-wire "PCM" arrangement.
551 The MU509 also (as previously mentioned in relation to the HTC Universal)
552 has GPIO pins which may be accessed over an AT command-set. Using these
553 becomes extra-complex as far as software is concerned, so should only really
554 be used as a last resort.
555
556 Connectivity for this particular 3G Modem is as follows, which will give
557 the minimum functionality:
558
559 * USB2 (+/-)
560 * 3G Power Enable (to an LDO to cut/enable power to the entire Modem)
561 * RESET#
562 * PWRON
563 * WAKEUPIN# (to wake up the 3G Modem)
564 * WAKEUPOUT# (for the 3G Modem to wake up the SoC: requires EINT-capable pin)
565 * SIM Card (connected to the MU509, not the SoC)
566
567 This is a minimum of 5 GPIO plus 2 USB lines. Optional extras include:
568
569 * Full UART (TX/RX, CTS/RTS, DTR/DCD/DSR, RING)
570 * PCM 4-wire audio (standard WAV format, supported by many Audio HW CODECs)
571 * Twin Mics
572 * Speaker Out
573 * Headset Out
574 * 12 pins GPIO
575
576 Note also in the example schematic that MMBT3904 transistors have been deployed
577 for simple level-shifting and also convenient inversion of the control
578 signals. Care needs to be taken in reading the datasheet to ensure that the
579 voltage levels of the GPIO match the GPIO Power Domain of the SoC GPIO Bank
580 to which the control signals of the MU509 are connected (and level-shifting
581 deployed if needed).
582
583 Also, special attention must be paid to the power supply: GSM and 3G Modems,
584 particularly the "M2M" ones, require an enormous amount of current: 2 to 2.5
585 **AMPS** is not unusual. M2M modules are also typically designed to operate
586 off of a direct Lithium battery voltage and are **not** to be run off of
587 a 3.3v or 5.0v supply. Hence in the example schematic below an LP6362
588 high-current LDO is used. This however requires an additional GPIO, which
589 is utilised to control the power supply of the 3G Modem.
590
591 Deploying hard-power-kill switches (physical and/or under SoC GPIO-control)
592 is generally a good idea with USB-based 3G and GSM Modems. During long-term
593 operation, these modems, which are basically yet another ARM Processor and
594 their own DDR and NAND storage with a full Software Stack (often linux kernel
595 based) inside an enclosed metal box, are pretty much guaranteed to crash so
596 hard that they become completely unrecoverable and unresponsive, and have
597 even been known to cause the USB Host Endpoints that they are connected to
598 to hard-crash as well. The only way to deal with that is to hard power-cycle
599 the Modem module in order to do a full reset of its USB PHY.
600
601 The other reason for considering deployment of a hard (physical) kill-switch
602 is for respecting user privacy and safety. Also, it is worth ensuring that
603 the 3G Modem does not require its firmware to be uploaded each and every time
604 it is powered up: it's much better to select a Modem that has its own
605 independent on-board NAND Flash (fortunately, unlike with the WIFI
606 module industry which is the total opposite, it is standard practice to
607 include on-board NAND on GSM/3G Modems). The hassle of getting a Modem Hardware
608 Manufacturer to provide the exact and correct firmware per country per
609 Cell-Operator (the FCC is particularly strict about this in the USA, and
610 even requires FCC Re-Certification **per Operating System** at a cost of
611 USD $50,000 per modem, per cell-operator, per firmware release, **per OS
612 release**),
613 all of which of course will require an NDA (for binaries??), and require
614 MOQs of 100k units or above just to get them to answer enquiries: it's
615 just not worth the hassle and the cost "savings" of not having NAND
616 Flash on the actual Modem module.
617
618 Plus, uploading of software (firmware) from main OS Storage to a peripheral
619 is something that instantly terminates any possibility of obtaining RYF
620 Hardware-Endorsement Certification. To make that clear: as long as all
621 peripherals (such as a 3G Modem) that run proprietary software are
622 fully-functional from the moment they leave the factory, i.e. they do
623 not **require** software to be uploaded to them via the main OS in order
624 to do their **full** job, RYF Certification can be sought. Ath5k and
625 Ath9k WIFI modules are another example of peripherals that have on-board
626 NAND and are fully-functional from the factory, so do not stop RYF
627 Certification.
628
629 [[!img MU509.jpg]]
630
631 # SimCOM SIM7600 / SIM7100 USB-based GSM/EDGE/3G/4G/LTE Penta-band Modem
632
633 An up-to-date low-cost Modem example is one from SimCOM. SimCOM are best
634 known for their low-cost SIM800 and SIM900 "workhorse" GSM modems, which
635 are extremely popular in the Shenzhen Markets. SimCom also have some
636 LTE multi-band modems, the 7100 and 7600 Series. Full technical documents can
637 be obtained by registering and then logging in to their website
638 (or instead by simply searching online without registration).
639 The SIM7600E is here: <http://simcomm2m.com/En/module/detail.aspx?id=178>.
640 Checking pricing and availability, it actually seems that the SIM7100C
641 is more popular. has lots of developer kits available, some MiniPCIe
642 designs, bare modules, and, importantly, plenty of suppliers which is
643 a good sign.
644
645 The pinouts are pretty much exactly the same as the Huawei MU509,
646 with the addition of two SD Card interfaces, two ADCs, and an SPI interface
647 for running a display. This module, it seems, is actually designed for
648 use as a stand-alone, fully-functioning actual phone, not even requiring
649 a companion SoC or MCU at all. The SIM7100 also supports sending and
650 reading of Audio data over USB. The Application Notes are **significant**
651 which makes it an extremely good choice. There is even advice on how
652 to design an interoperable PCB that supports the low-cost SIM800C, the
653 SIM5360 and the SIM7100, all of which are in the same footprint and are
654 nearly 100% pin-compatible. Documents can be obtained without
655 NDA from here: <http://simcomm2m.com/En/module/detail.aspx?id=85>
656
657 [[!img SIM7600.jpg]]
658