Thursday, February 15, 2018

Linux Internals

What happens at boot?

  1. Kernel Boot Process by 0xAX at Github
  2. Analyzing the Linux boot process by Alison Chaiken

What happens when a device is plugged in?

  1. What actually happens when you plug in a USB device? by Ian Wienand

What happens when you execute a userspace programm from the command line?

  1. How to show all shared libraries used by executables in Linux? Stack Overflow
  2. Loading of shared libraries and RAM usage Unix & Linux Stack Exchange

What happens when you compile userspace applications?

  1. How to write shared libraries? by Ulrich Drepper
  2. Static, Shared Dynamic and Loadable Linux Libraries YoLinux.com
  3. Load-time relocation of shared libraries eli.thegreenplace.net
  4. Position Independent Code (PIC) in shared libraries eli.thegreenplace.net
  5. Where the top of the stack is on x86 eli.thegreenplace.net

What happens when you compile the kernel?

  1. Shrinking the kernel with link-time garbage collection LWN.net
  2. Shrinking the kernel with link-time optimization LWN.net
  3. Shrinking the kernel with an axe LWN.net

Thursday, February 1, 2018

Hacking "ESP8266 Black Board T5" Part 1 - Blinky on Keil

A few months ago, I got my hands on ESP8266 Black cloud features Board T5 which has an ESP8266, an 8051 microcontroller and a few sensors. The 8051 microcontroller acts as a master to the ESP8266 and comes loaded with a demo program which is supposed to work with some android app. ESP8266 can be directly programmed using Arduino, so it would be better if I would reprogram the 8051 to act as a slave connected to ESP8266. The ESP8266 will run an Arduino sketch (that I would write) and ask the 8051 for the sensor readings (over UART). To do that I would need to program the 8051 with come C program that I have written.

So the first step was to learn how to compile a simple blinky program for the 8051 and be able to download and run it on it.

Links:

  1. Black Board T5 User guide (in Chinese) explain how to use the android app (Translated version)
  2. Reworking the AI Thinker "Black board T5
  3. Schematic of Black Board T5 (You will need Batang font to view it)
  4. Source code (Keil uVision project) of the original code running inside 8051
  5. Datasheet of STC15L2K32S2 (The 8051 Microcontroller present on Black board T5)
  6. Android app and its source code
  7. Keil C51 Evaluation Kit ver 9.57 - C compiler for 8051
  8. Windows utility (stc-isp-15xx-v6.86I.exe) to program the flash memory of STC15L2K32S2 over its UART. The utility is in Chinese so you have to feel your way around it.

Schematic for Blackboard
STC15L2K32S2 has two UARTs (Serial Ports). One is connected to ESP8266 and the other one is brought out on the 3 pin header. The one brought out on the 3 pin header can be used to reprogram the microcontroller using the STC's ISP utility (In System Programming)

I used a USB-Serial convertor to connect 8051's UART like so:

TxD, RxD, GND from CH340 board connected to Blackboad T5's R,T,G Signals respectively

To run blinky on 8051, I performed the following steps:
  1. Installed Keil C51 Evaluation Kit on my Windows Laptop
  2. Connect the USB-Serial board to Blackboard
  3. Install drivers for CH340 present on my USB-Serial board
  4. Use the STC utility to install headers for STC microcontrollers to Keil. Keil doesn't come with support for STC microcontrollers built-in.
  5. Use the STC utility to generate demo code for controlling PWM on STC15L2K32S2. Instead of copying the C code, click "Save project" to save a Keil C51 project - that way all the settings are exported as well.
  6. Open the project in keil and build the project by pressing the F7 key. Hex file will be generated. The evaluation version is limited to generating 2kB of code, which is fine if you just want to blink LED using the PWM feature of STC15L2K32S2.
  7. Go back to STC utility, select the MCU type as STC15L2K32S2
  8. Select the appropriate COM Port
  9. Load the hex file onto the STC utility (click Open Code File)
  10. While the Black board T5 is connected to your computer via the CH340 board, keep the batteries installed in Black board T5 but keep it powered off
  11. Click on "Download/Program" in STC utility
  12. Turn on the power via the slide switch on the black board and watch the program download.
  13. Once the program is complete, the code will run and LEDs will fade in and out.

STC Utility: Install headers for STC microcontrollers to Keil

STC Utility: Generate demo code

Keil C51 Evaluation kit: Build the program to generate hex file

STC Utility: select the correct microcontroller, com port,
load the hex file and click Download/Program


Incase you aren't able to generate code from the STC utility, here is the link to the code (Keil C51 project): STC15L2K32S2_Hello_LED.rar