Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

TDC2016SP - Trilha Linux Embarcado

265 views

Published on

Linux 4.6 em Microcontroladores: Um caso prático.

Published in: Education
  • Be the first to comment

TDC2016SP - Trilha Linux Embarcado

  1. 1. Linux 4.6 em Microcontroladores: Um caso prático. CPS | CERTI 2016 COPYRIGHT 2016 – Fundação CERTI
  2. 2. COPYRIGHT 2016 – Fundação CERTI DISCLAIMER The information in this presentation was compiled from sources believed to be reliable for informational purposes only. Content includes opinions, presentations, articles, hyperlinks or other third party content (“Third Party Material”) that is not intended to, nor constitutes an endorsement by CERTI of the author or the Third Party Materials. The content and views within the Third Party Material are solely those of the third party and do not reflect the opinions of CERTI. The opinions expressed in this presentation and on the following slides are solely those of the presenter and not necessarily those of CERTI. CERTI does not guarantee the accuracy or reliability of the information provided herein. Presentation Notes
  3. 3. WARM UP www.linkedin.com/in/bherrera COPYRIGHT 2016 – Fundação CERTI Present how Linux can be ported to MCUs with low memory and low storage how can it leverage the MCU development environment and avoid fragmentation(kind of). Goal BrunoMHerrera
  4. 4. WARM UP www.linkedin.com/in/bherrera COPYRIGHT 2016 – Fundação CERTI I’m a Computer Engeneer I’m a Computer Enginere I’m a Computer Engenere I’m good with Computers …. Who I Am BrunoMHerrera
  5. 5. MCU Chapter 1 Action Chapter 4 Linux Chapter 2 Wrap up Chapter 5 WIP Chapter 3 AG EN DA COPYRIGHT 2016 – Fundação CERTI
  6. 6. COPYRIGHT 2016 – Fundação CERTI Photo credit: Adam Greig via VisualHunt / CC BY-SA MCU – Microcontroller Unit “Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications consisting of various discrete chips.” -Wikipedia
  7. 7. COPYRIGHT 2016 – Fundação CERTI Microcontrollers usually contain MPU (memory protection unit) MMU-less Reduced RAM <192k Flash (ROM) <2Mb ASP 2014 - $0.83 ASP 2015 - $0.65 *7 to 8 times in Brazil http://www.icinsights.com/news/ bulletins/Microcontroller-Unit- Shipments-Surge-But-Falling-Prices- Sap-Sales-Growth/ Microcontrollers usually contain from several to dozens of general purpose input/output pins (GPIO). GPIO pins are software configurable to either an input or an output state.[1] Microcontrollers usually contain several peripherals integrated (U[S]ART, ADC, USB, SDIO, etc…) Automation Healthcare Automotive Aerospace Wellness Internet of Things MCU - Traits Small Footprint Low Price ApplicationsSoCGPIO
  8. 8. COPYRIGHT 2016 – Fundação CERTI BSP(board support package) / HAL (hardware abstraction layer) provided by the “Chip” vendor Hardware dependent code, not portable No operating system Hard to port applications Hard to update on the field Do not forget: it is all about registers!! without addition; basic and simple Chapter 1 | MCU Bare Metal
  9. 9. COPYRIGHT 2016 – Fundação CERTI eLua www.eluaproject.net Embedded power, driven by Lua Quickly prototype and develop embedded software applications with the power of Lua and run them on a wide range of microcontroller architectures MicroPython micropython.org MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments. Netduino www.netduino.com Netduino, an open-source electronics platform using the .NET Micro Framework. Cont: JavaME, Chapter 1 | MCU Bare Metal Not so bare
  10. 10. COPYRIGHT 2016 – Fundação CERTI ATmega328P 14 Digital I/O Pins 6 PWM Digital I/O Pins 6 Analog Input Pins 32 KB Flash Memory of which 0.5 KB used by bootloader 2KB SRAM 1KB EEPROM 16MHz Clock Speed U$ 3.38 Chapter 1 | MCU Arduino Uno “The UNO is the best board to get started with electronics and coding. If this is your first experience tinkering with the platform, the UNO is the most robust board you can start playing with” https://www.arduino.cc/en/Main/ ArduinoBoardUno
  11. 11. COPYRIGHT 2016 – Fundação CERTI Real Time Operating System FreeRTOS www.freertos.org FreeRTOS is the market leading real time operating system (or RTOS), and the de-facto standard solution for microcontrollers and small microprocessors. Nuttx nuttx.org NuttX is a real-time operating system (RTOS) with an emphasis on standards compliance and small footprint. Scalable from 8-bit to 32-bit microcontroller environments, the primary governing standards in NuttX are Posix and ANSI standards. Zypher www.zephyrproject.org Zephyr Project is a small, scalable real- time operating system for use on resource-constrained systems supporting multiple architectures. Cont: Contiki (IoT), BROS, ChibiOs Chapter 1 | MCU RTOS
  12. 12. COPYRIGHT 2016 – Fundação CERTI VxWorks windriver.com/products/vxworks VxWorks is designed for use in embedded systems requiring real-time, deterministic performance and, in many cases, safety and security certification, for industries, such as aerospace and defense, medical devices, industrial equipment, robotics, energy, transportation, network infrastructure, automotive, and consumer electronics.[X] Nucleus mentor.com/embedded-software/nucleus/ The Nucleus RTOS is designed for deeply embedded systems applications including consumer electronics, set-top boxes, cellular phones, and other portable and handheld devices. For limited memory systems Nucleus RTOS can be scaled down to a memory footprint as small as 13 KB for both code and data. Cont: QNX, SAFERTOS, Chapter 1 | MCU RTO$ Real Time Operating System
  13. 13. COPYRIGHT 2016 – Fundação CERTI “as one of key benefits of an MMU: an operating system can use it to protect against errant programs by disallowing access to memory that a particular program should not have access to” “Given the need for a high security bar in IoT we try and design Brillo in way that promotes a strong security architecture in the final products. I’m afraid if we offered a MMU-less variant of Brillo we'd be promoting a very insecure architecture, and for that reason its not something we'd consider.” [Brillo Mailist] Chapter 1 | MCU MMU-less WARNING: No memory management!
  14. 14. COPYRIGHT 2016 – Fundação CERTI you-see-linux www.uclinux.org The Embedded Linux/ Microcontroller project is a port of Linux to systems without a Memory Management Unit (MMU). No elf support Not in mainstream(2.6.x) uClibc Emcraft (Commercial and Opensource) https://github.com/ EmcraftSystems/linux-emcraft/ Chapter 1 | MCU uClinux
  15. 15. COPYRIGHT 2016 – Fundação CERTI Photo credit: Derek K. Miller via VisualHunt.com / CC BY-NC Linux “That's what makes Linux so good: you put in something, and that effort multiplies. It's a positive feedback cycle.” - Linus Torvalds
  16. 16. COPYRIGHT 2016 – Fundação CERTI Linus was wrong Chapter 2 | Linux History https://groups.google.com/forum/#!msg/comp.os.minix/ dlNtH7RRrGA/SwRavCzVE7gJ
  17. 17. COPYRIGHT 2016 – Fundação CERTI Video Chapter 2 | Linux History The Story of Linux: Commemorating 20 Years of the Linux Operating System
  18. 18. COPYRIGHT 2016 – Fundação CERTI Chapter 2 | Linux History 1995 > BusyBox a collection of command line utilies - Bruce Perens (1.44Mb) Debian Installer > MIPS 1996 > M68k, PPC 1998 > uClinux at m68k DragonBall on 3Com palm pilot 1999 > ARM 2000 > iPaq H3600 running X11 2005 > Nokia 770 Internet Tablet running Maemo Linux embedded
  19. 19. COPYRIGHT 2016 – Fundação CERTI Chapter 2 | Linux History 1995 > BusyBox a collection of command line utilies - Bruce Perens (1.44Mb) Debian Installer > MIPS 1996 > M68k, PPC 1998 > uClinux at m68k DragonBall on 3Com palm pilot 1999 > ARM 2000 > iPaq H3600 running X11 2005 > Nokia 770 Internet Tablet running Maemo Linux embedded
  20. 20. COPYRIGHT 2016 – Fundação CERTI Pros Chapter 2 | Linux Why Linux? Strong Community / Big Players contributing / Stable versions and release cycles Portable (ARM Cortex M3/M4 support is now mainstream) POSIX Compliant OSS Environment and Tools Huge drivers support XIP (execution in Place) Free
  21. 21. COPYRIGHT 2016 – Fundação CERTI Cons Chapter 2 | Linux Why not Linux? Big footprint (linux-tiny) Latency / Not real time (linux-rt) Bloated subsystems (procps, printk, comand line parser) Not designed for MCU : “The Linux community is skeptical about MCUs “[x] Too many config parameters, hard to find the optimal configuration Do try this without and external RAM (8Mb)
  22. 22. COPYRIGHT 2016 – Fundação CERTI www.devicetree.org The devicetree is a data structure for describing hardware. Rather than hard coding every detail of a device into an operating system, many aspects of the hardware can be described in a data structure that is passed to the operating system at boot time. The kernel no longer contains the description of the hardware, it is located in a separate binary: the device tree blob The Device Tree Blob is produced by the compiler, and is the binary that gets loaded by the bootloader and parsed by the kernel at boot time. model = “TDC 2016 Linux Embarcado”; Chapter 2 | Linux Device Tree
  23. 23. COPYRIGHT 2016 – Fundação CERTI www.devicetree.org The devicetree is a data structure for describing hardware. Rather than hard coding every detail of a device into an operating system, many aspects of the hardware can be described in a data structure that is passed to the operating system at boot time. The kernel no longer contains the description of the hardware, it is located in a separate binary: the device tree blob The Device Tree Blob is produced by the compiler, and is the binary that gets loaded by the bootloader and parsed by the kernel at boot time. model = “TDC 2016 Linux Embarcado”; Chapter 2 | Linux Device Tree
  24. 24. COPYRIGHT 2016 – Fundação CERTI make menuconfig Chapter 2 | Linux KConfig The configuration database is a collection of configuration options organized in a tree structure [Kernel Doc] “Can't use strategy of manual tuning(i.e.config options) 3.9 has about 13,000 options” [X Tim Bird] Start from one known configuration stm32_defconfig Don’t Panic
  25. 25. COPYRIGHT 2016 – Fundação CERTI Chapter 2 | Linux BootLoader Essentially, the boot loader should provide (as a minimum) the following: 1. Setup and initialize the RAM. 2. Initialize one serial port. 3. Detect the machine type. 4. Setup the kernel tagged list. 5. Load initramfs. 6. Call the kernel image. https://www.kernel.org/doc/Documentation/arm/Booting Run Lola Run
  26. 26. COPYRIGHT 2016 – Fundação CERTI fast Chapter 2 | Linux BootLoader Forget about u-Boot! It is big! Directly load Linux kernel by really small program AFBoot (only works with XIP now) Tiny Linux bootloader for the STM32F429-Discovery https://github.com/mcoquelin- stm32/afboot-stm32 Bootloader + Kernel in less than 1sec. (I can prove)
  27. 27. COPYRIGHT 2016 – Fundação CERTI Chapter 2 | Linux BootLoader Essentially, the boot loader should provide (as a minimum) the following: 1. Setup and initialize the RAM. 2. Initialize one serial port. 3. Detect the machine type. 4. Setup the kernel tagged list. 5. Load initramfs. 6. Call the kernel image. https://www.kernel.org/doc/Documentation/arm/Booting Eclipse
  28. 28. COPYRIGHT 2016 – Fundação CERTI Chapter 3 | Wip mainstream STM32F429 support added to mainstream kernel by Maxime Coquelin at 2015 Peripherals already supported: RCC GPIO RNG UART Ethernet DMA On Going: USB I2C SDIO WIP
  29. 29. COPYRIGHT 2016 – Fundação CERTI Chapter 3 | Wip mainstream https://patchwork.kernel.org/ project/linux-arm-kernel/list/? q=stm32 WIP
  30. 30. COPYRIGHT 2016 – Fundação CERTI 80386DX 32Bits MPU 1985 12 MHz to 40 MHz FPU Co Processor 80387 STM32F429 32Bits MCU ?? Up to 180MHz FPU 192Kb RAM 512Kb to 2Mb FLASH MAC(Ethernet), SDIO, TFT, USB, SERIAL tale of the tape Clash of Titans
  31. 31. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action Target Action
  32. 32. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action Tools Toolchain https://launchpad.net/gcc-arm- embedded/4.9/4.9-2014-q4-major sudo add-apt-repository ppa:terry.guo/ gcc-arm-embedded sudo apt-get update sudo apt-get install gcc-arm-none-eabi Open OCD git clone git://git.code.sf.net/p/openocd/ code openocd cd openocd git submodule init && git submodule update && ./bootstrap && ./configure -- enable-stlink && make && sudo make install Action
  33. 33. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action Talk is cheap… git clone git://git.kernel.org/pub/scm/linux/ kernel/git/torvalds/linux.git cd linux make ARCH=arm CROSS_COMPILE=arm- none-eabi- stm32_defconfig make ARCH=arm CROSS_COMPILE=arm- none-eabi- Action
  34. 34. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action
  35. 35. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action
  36. 36. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action
  37. 37. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action GPIO What is a GPIO? =============== A "General Purpose Input/Output" (GPIO) is a flexible software-controlled digital signal. They are provided from many kinds of chip, and are familiar to Linux developers working with embedded and custom hardware. Each GPIO represents a bit connected to a particular pin, or "ball" on Ball Grid Array (BGA) packages. Board schematics show which external hardware connects to which GPIOs. Drivers can be written generically, so that board setup code passes such pin configuration data to drivers. https://www.kernel.org/doc/Documentation/gpio/gpio.txt Action
  38. 38. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action GPIO The famous hello world “led blink” at user space gpio = (bank * 16) + pin gpio = 6 * 16 + 14(LD4) = 110 cd /sys/class/gpio echo 110 > export echo out > gpio110/direction echo 1 > gpio110/value Action
  39. 39. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action GPIO The famous hello world “led blink” at user space (cont) while echo blink > do > echo 1 > gpio110/value; sleep 1 > echo 0 > gpio110/value; sleep 1 > done Action
  40. 40. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action LEDs LED handling under Linux ======================== In its simplest form, the LED class just allows control of LEDs from userspace. LEDs appear in /sys/ class/leds/. The maximum brightness of the LED is defined in max_brightness file. The brightness file will set the brightness of the LED (taking a value 0- max_brightness). Most LEDs don't have hardware brightness support so will just be turned on for non-zero brightness settings. https://www.kernel.org/doc/Documentation/leds/leds-class.txt Action
  41. 41. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action LEDs The famous hello world “led blink” using the DT Action
  42. 42. COPYRIGHT 2016 – Fundação CERTI Chapter 4 | Action Optimization The tip of the iceberg ./scripts/bloat-o-meterAction
  43. 43. COPYRIGHT 2016 – Fundação CERTI Photo credit: Derek K. Miller via VisualHunt.com / CC BY-NC Wrap Up “People who are really serious about software should make their own hardware” - Alan Kay
  44. 44. COPYRIGHT 2016 – Fundação CERTI Chapter 5 | Wrap Up When developing your hardware select components that are supported (device drivers) Linux has a lot of space for optimization and tinyfication Cannot run without external RAM(yet) Hardware is hard, so take care of your design. Try first in development boards One size does not fit all! Linux may not be the best option for your case Take away
  45. 45. COPYRIGHT 2016 – Fundação CERTI References https://en.wikipedia.org/wiki/Microcontroller https://events.linuxfoundation.org/sites/events/files/slides/ petazzoni-device-tree-dummies.pdf http://2net.co.uk/embedded-history http://elinux.org/STM32 http://www.emcraft.com/stm32f429discovery/controlling-gpio- from-linux-user-space http://elinux.org/Kernel_Size_Tuning_Guide
  46. 46. COPYRIGHT 2016 – Fundação CERTI Thanks! Obrigado!
  47. 47. COPYRIGHT 2016 – Fundação CERTI Sorteio Good Luck! Powered by STMicroelectronics

×