Thursday, April 28, 2016

BSidesPR 2016 Led Matrix break down

So you got a BSides PR 2016 badge? Pretty cool ahh. If you are wondering how this led matrix works, well lets look at it.
 The badge led matrix is pretty simple. It consist of two shift registers that control rows and columns. Rows and Columns are represented by an eight bit number. Refer to picture bellow to show how bits are arranged in relation to the badge matrix.
When sending data from the micro controller to the badge. We first send row bits then send column bits. Data is pushed from one shift register into the other via the overflow bit. In order to turn on a led or multiple led the right combination of bits in row and column should be achieved. A 0 value on a row and a 1 value on a column will make a led to turn on.
This is an example of several leds turning on. We are using a set of functions provided in the firmware example available on github.
This example is sending a 0x01 value to the rows ( 00000001 ) and a 0x80 to the columns ( 10000000 ). This cause the columns bits 0 - 6 to be 0 and Column bit 7 be 1. Also to have Row bits 1-7 = 0 and Row bit 1 = 0. The yellow cells with ON represent what leds shold be turned on.
To ease the sending of data a function ledMatrix.write is used. This function receives two parameters. The first parameter being the byte for the rows and the second parameter the byte for the columns. In this example the function is called ledMatrix.write( 0x01, 0x80 )

This is a simple way of turning on several leds on the badge. Repeat same thing several times with different combination and an animation can be represented with leds.

For the very curious hackers, communication to the led matrix is via SPI and the STM32F0 supports DMA. So a clever hacker can use DMA to send data to the led matrix and free up some clock ticks from the CPU. As of this post, the example on github is not using DMA just simple serial communication.


Sunday, February 21, 2016

BSidesPR 2016 Badge programming tools


Now lets talk about how to code for the BSidesPR 2016 badge. If you do not know what this is all about refer to last post about an overview of the board here.

If you do not want to read, what you need?
  1. Keil (for windows)
    1. ARM Compiler, compatible with a lot of ARM MCUs
    2. Supports debug (to debug requires an external programmer debugger ST-Link)
  2. STM32CubeMX
    1. Code generator, helps creating Keil project and configuring MCU pins
    2. Compatible with Windows and Linux
  3. System Workbench for STM32 ( Linux)
    1. ARM Compiler compatible with Linux
    2. Free but need to register
    3. I downloaded but have not tested
  4. stm32flash to download binaries to board in linux
    1. clone and build tool from https://github.com/aguegu/stm32flash
    2. Use with -s to download
    3. ./stm32flash -s /dev/ttyUSB0 (should recognize device)

The badge has a STM3230F4P6 micro controller. It has a Arm Cortex M0 cpu, so standard coding tools used for arm chips should work with this board. I am far from an expert here and I was able to create some simple codes and download to it.
This chip is cross platform, but by the time I write this I haven't played with it in other than windows so that is what this post is all about.

I have used Keil to program for this badge from Windows it can be freely downloaded. For what I know Keil runs only on windows. It is basically an IDE like visual studio to code for Arm micro controllers. There are other compilers that should be compatible with the micro controller but as of this post I have not tested them.

You can do all with Keil alone, however I like to get a little help setting up the project so I use STM32CubeMX. The STM32CubeMX is a code generator, it help you get started on creating a project and configuring different ports of the STM32 chip as input, output or any other feature available. It is a wizard like interaction and it can produce a project file that you can open with Keil and compile.

Badge hardware circuit diagram (Please note that the prototypes use 5VDC regulators not 3.3V)

To use Serial data communication from code, it is required to configure the corresponding pins to be TX and RX. Also to use the LED matrix corresponding pins should be configured as well. Here is a simple configuration on how to just make it work, configured via STM32CubeMX.


LED matrix can be used bu configuring PA7, PA5 as SPI and should provide a better performance that just using them as standard outputs, however this way also works.





Saturday, February 20, 2016

BSidesPR 2016 Badge prototype

Last year (2015) BSides PR badge was cool but time pass and we need to keep on improving. This year badge is little different. As of when this post is published we only have a prototype, final version can and will change a bit. However key aspects of the board will stay the same. Design files for the board can be found at github.

Lets divide the badge in three areas. The brain, the communication and peripherals.

The Brain:
This badge carries some cool stuff. We went with a STM32F030F4P6 micro controller. This is an ARM® 32 bit Cortext M0 micro controller made by ST and consists of 16Kb of flash memory and it is clocked at 48Mhz. Information and manual can be found at manufacturer web site. It has 1 UART (in use to communicate with pc), 1 I2C and 1 SPI port. SPI port is used for shift registers.



Communication:
The badge can comunicate with the pc via USB. For this it uses a CH340G usb to serial chip. I have been using this chip for so long that I do not remember if linux needs any special driver. But for windows it indeed needs a driver. The chip works with Linux, Windows and MAC after is corresponding driver installation.
For drivers

    • Chinese official web site link
    • Some guy blogpost (has something for MAC, but I have never tried it)
    • Or just go to google and search for CH340G driver


Peripherals:
This baby is packing a few things.

  1. LED matrix
    • 8x8 LED matrix that is controlled from two 595 shift registers
    • One shift register is used for the rows and one for the columns
  2. Buttons
    • In the front it consists of four push buttons
    • The prototype do no have any of these buttons wired up to the microcontroller. Instead pins for the buttons are exposed at JP4 port. Pins are labeled Left, Right, Up and Down.
    • On the back there are two more buttons. One for programming and the other for reset.
  3. I/O exposed pins
    • To the left of the microcontroller a few pins are exposed. Please note the one that says 3.3V it is actually 5V. There pins PA0, PA1, PA2, PA3, PA6 and PB1 are available to be used. Easily can jump wire one of those pins to the buttons to interact with them.
    • On the right (beneath PROTOTYPE) is a ST-LINK port. It can be used for debugging with an external programmer. This is not required for normal programming but if you'll like to see a break point in your code this is the way to go and an external programmer is required. An external programmer can be a cheap ST-Link V2 programmer/debugger and are cheap on ebay.


Sunday, November 22, 2015

Badge as USBASP verry badly explained

Make your BSides Badge into a USBASP Programmer

Step 1. Download Github repo
https://github.com/soynerdito/BadgeUsbasp
Important stuff is:
Flash compiled file: https://github.com/soynerdito/BadgeUsbasp/raw/master/main.hex
MakeFile for easier flash: https://github.com/soynerdito/BadgeUsbasp/blob/master/Makefile

Step 2: Get your badge ready
Connect your Badge into the PC usb and press the reset button.
On Linux you should see something like (with lsusb):
"...ID 16c0:05dc Van Ooijen Technische Informatica shared ID for use with libusb"
On Windows you may need to install some drivers
If on windows 10 you may need signed driver. Use Adafruit's drivers,
https://learn.adafruit.com/introducing-pro-trinket/downloads
On mac, you are on your own but it should just work.

Step 3: Burn firmware
If using Makefile go ahead and just type
make flash
If you want to just flash the code use avrdude straight
avrdude -c usbasp -p atmega328p -P /dev/usb/ttyUSB0 -U flash:w:main.hex

avrdude port may change with different OS. Hope this helps, latter I hope to make this more organized.

USBASP pin out to connect another board, use same pins as Arduino as ISP
https://www.arduino.cc/en/Tutorial/ArduinoISP

Tuesday, June 2, 2015

A three months developer.... yeah right

All over the news we see reports about the need of developers and if we do not teach programming skills to youngster we might run out of
developers in the near future . I am all in to teach and encourage people to try programming. 

Becoming a developer is not for everyone, and as a society we need people in other professions as well. So showing what programming is to young is a good way to let them choose if this is the carer for them.

All is good but like always, there comes people that to my opinion are into this to only make money. Making promises to young people that in three months they can become excellent developers and land a job with a lot of money. That my friend in bull.

There is no way that you can go from zero to senior in three months, not even to beginner. There will always be people with talent that can achieve a lot in short period of times. And even those (minority) need to get some typing time, and they will because they love what they do. However the regular person will not have the born talent and require a lot of practice. It takes practice and dedication to become a good developer as everything else. Snapping together some web framework and a beautiful template  (downloaded) does not makes you an developer, and even less a good one.

All this crap about three months excellent developer is like a loose weight without diet and exercise. It does not works like that.

What would happen if a people buy into the dream of senior developer in no time? Well a lot of people asking for a lot of money to copy/paste code from web and create crappy code. The ones paying are not stupid, and when they keep spending money and not receiving good products in return will force them to look for other alternatives. What are those alternatives you may say, not other that outsourcing.

To keep my rant short. Do not buy in the idea that anyone can snap their fingers and make you a good developer with a simple programming course. To become a good developer you need some fire inside that keep you eager to learn and keep on learning. When the lights goes out you still want to  keep on going because you are in the flow of the moment. Do it because you love it, not because of the money.

It is easy to point fingers into a doctor and say they are into that only for the money and in doing so risking the life of he/her's customers. Same thing apply to IT professionals in all areas.
In conclusion practice, practice and practice is the only way. Work day and night and eventually you will get better and better. There is no substitute to good elbow grease.


Friday, November 7, 2014

ESP8266 possible breadboard interface

Probably you know what the ESP8266, if not it is a very cheap Uart to Wifi module (more info). Anyhow to the important part.
This module is 3.3V and my Arduino is 5V. There is a problem. Also the module is not "breadboard friendly".
So there are two problems that a simple interface board can fix very easy. Based on that, I have a few ideas running in my head about this. I am in the process of designing a board that I would like to build a prototype.
What this magic board do?
1. Voltage regulator, IN 5V and regulate to 3.3V with 3.3V output as well.
2. Level shifter for RX and TX signals, so you can wire it up straight to the arduino.
3. Bread board friendly header pins for easy testing.

This is a very small design to keep it cheap. As is of now it is 1 inch by 1 inch. It is not in its final stage, however I like to write about it, just in case.

pcb board



schematic

I will continue on improving the design for a bit more. However I want to try to actually build it, however build time for me is very limited now, so only time will tell how this gets done.

All eagleCad files are here. This is very early in the design process. I have started two times, and probably restart it all again.

Any idea or comment, please do. This is public domain, so you may do what ever you want with it. If you build it as is or modify it, comment about it and post pictures. There is no need to mention or link back to me.

Update:
Board modified a little bit and sent to oshpark for a prototype. Soon will know if it actually works.
Eagle files moved to a github repo of it's own here. Now the board has a name it is called WifIco (it needed a name you know).

This is the image rendered by OSHPark web site when ordered.

Bottom View Top View


This has not been tested however I decided to order it anyhow. It has a mini usb port beneath only for 5V input. Just in case I wanted to power it stand alone, who knows!
It also has two resistors visible on the bottom view, that should be soldered shut for normal use. You may solder a wire or a zero resistor, actually whatever you have. They are pull up and can be shut. I figure that since I will be receiving a few boards may find it useful to use one to update the firmware and in those cases I would need access to the pins exposed there. But for normal operations I may not. 

Update:
This design has a lot of errors in the silk screen for the board connections. It worked, but the labeling of the connections is incorrect.




Thursday, October 2, 2014

Adding .gitignore file after first repository commit

It happen to me very often to create a git repository and even push it to mu github without first creating a .gitignore file. Specially on Android projects this publishes a lot of unwanted files, like binary and temporary files. For this I found a post on stackoverflow for just that.

From all the post I read this is the one that worked for me (at least now)
http://stackoverflow.com/questions/7927230/remove-directory-from-remote-repository-after-adding-them-to-gitignore

I did this, however in the post is more information about it, please go to the stackoverflow link and if it work for you go ahead a plus it.
git rm --cached `git ls-files -i --exclude-from=.gitignore` 
git commit -m 'Removed all files that are in the .gitignore' 
git push origin master

If you have a better way to do this please leave a comment.