Thursday, 8 December 2016

Favorite Atom plugins

Favorite atom plugins
  • pdf-view
    • For pdf previews in atom
  • vim-mode-plus
    • vim style key binding
  •  language-markdown
    • syntax highlighting for markdown
  •  markdown-preview-enhanced
    • live markdown preview
    • latex support
    • export to pdf
    • export to html

Friday, 2 September 2016

Remarkable markdown editor


Remarkable is a good markdown editor for generating PDF or HTML pages. This makes it good for writing reports that include code snippets. Also CSS and be customized to create different themes.

Saturday, 23 July 2016

My list of failed/incomplete projects

Some of the failed/incomplete projects.
This is only the projects I can remember:
  • Project Popsicle Stick v1
  • Data Shrinker Computer Program v2
  • zetta kernel
  • CircuitSimulator
  • AICity

Monday, 20 June 2016

How to use STM32 GPIO

Firstly, add the header files. Configure the clocks if needed.

This header is for STM32F1 change it to your own.



Secondly, configure the GPIOs. This is for PA3 set to output.


To set pin low.



To set pin high.



To toggle pin.



To read pin.



How to use STM32 ADC

Firstly, add the header files. Configure the clocks if needed.

This header is for STM32F1 change it to your own.



Configure the ADC.
Set hadc.Init.ContinuousConvMode to ENABLE and hadc.Init.EOCSelection to DISABLE for continuous sampling.


Or equivalently on STM32CubeMX.



Simple continuous sampling blinking. hadc is the structure of ADC. Starts ADC with HAL_ADC_Start. Then polls all the conversions with HAL_ADC_PollForConversion. The data retrieved with HAL_ADC_GetValue. digital value =((Analog input voltage)/(reference voltage high- reference voltage low)) * (2n - 1) where n = number of bits of ADC digital output



Sunday, 12 June 2016

STM32 USB CDC VCP

I had a lot of trouble using USB CDC. So I decided to create a small library. The library uses STM32 HAL and the USB middle-ware. The code is for STM32L0. However it can be easily modified for other STM32 lines.


First add VCP.h



Then add VCP.c



Modify usbd_cdc_if.c. I also changed APP_RX_DATA_SIZE and APP_RX_DATA_SIZE to 256


Finally change main.c . Include the VCP.h .



The VCP_read checks if the FIFO has data. If it has data then it sends the data back to the computer using VCP_write.

To see interaction use

picocom -b 9600 /dev/ttyACM0

Then enter some data into the VCP.

 echo "hello world" > /dev/ttyACM0


The response

 Terminal ready
stack=0,i=12,data=hello world

Saturday, 11 June 2016

How to use OpenSTM32

See How to use STM32CubeMX to generate code.

Open the IDE.

Import the project. File > Import




Select Existing Projects into Workspace .



Select the folder.



Now the project is imported. Add some code.

To debug/flash follow this. Project > Target > Program chip



Select the executable.




Configure the debugger. Select ST-LinkV2-1 for built in debugger. Select ST-LinkV2 for external debugger.




Debug > Debug Configurations



Select your executable under Ac6 STM32 Debugging. Then select Debugger. Click on Manual spec in Script. Then configure the debugger. 
Hit Apply and then Debug.



 OpenSTM32 should flash the chip and enter debug mode.



Friday, 10 June 2016

How to use Unity for testing code

Unit tests are important for testing code. Unity is a library for testing C code.


To use unity add this header.

The main function starts Unity. Runs the test_stuff(). Then stops Unity.

The function for testing code. This tests if the condition is true.

This tests if the 32 bit int is equal to 10.


Function to test null pointers. If the pointer is null then it will fail and give a message.

How to use STM32CubeMX

STM32CubeMX


Open STM32CubeMX and click New project.




Select the MCU.





Select configuration and enable the middle wares (e.g. FreeRTOS).





Set pin configurations and clocks in pinouts.




Set clock configurations.





Project > Generate code. Name project and select directory. Select SW4STM32 for OpenSTM32 IDE.




How to use GCC and make


GCC is the main compiler for C.

To compile a C file.


gcc -o hello hello.c


Running the executable

./hello



Makefiles is used for building the whole project. This is an example file.


all: hello

hello: hello.o
     gcc -o hello hello.o

hello.o: hello.c
     gcc -c hello.c
    
clean:
     rm hello.o hello


Use this to build everything into a executable.

make



Use this to clean the project.

make clean




Monday, 6 June 2016

Plans for Project Popsicle Stick v2.0

Well I failed to program the STM32 with STLinkV2. Not matter what I do, the STLinkV2 doesn't detect the STM32.
List of things checked:
  • All VDD pins are 3.3V
  • All ground pins are grounded
  • There are no shorts to ground
  • Ripple in VDD is minimal
  • BOOT0 is grounded
  • NSRT is connect to VDD
  • STLinkV2 is connected using SWD
  • All PCB traces are continuous
  • Power for STM32 is 3.63 mW (1.1 mA at 3.3V). Seems reasonable.
  • STM32 is in the correct orientation
  • STLinkV2 works on other STM32
  • All STM32 pins were checked
  • Supplier didn't give a faulty STM32 as I un-soldered it and replaced it with a new one


I am thinking about designing version 2.0 of Project Popsicle Stick. However, I have trouble deciding how to pick a new ICE40 chip. The ICE40LP is pretty cost effective for the amount of LUTs. The downside is that I need a 4 layer board. That adds complexity and cost. iCE40-HX4K-TQ144 doesn't require a 4 layer board. The downside is that I need a bigger board and iCE40-HX4K-TQ144 has less LUTs. Anyone have advice?
 
I also created a poll if anyone want to help me decide.
https://www.strawpoll.me/10242026

Sunday, 29 May 2016

StlinkV2 wiring diagram


RED = VDD
GREY = SWDIO
ORANGE = SWCLK
YELLOW = NRST
BLACK = VSS




Inquire IDE

Inquire IDE is a custom IDE for my custom projects.

Specifications:
  • Qt Quick and Javascript for interface
  • C++ for back end processing
  • Use arm gcc compilers
  • Use rust/zinc compilers
  • Git version control
  • JSON for config files
Supported boards and languages:
  • STM32L1 discovery
    • C
    • Rust/zinc
  • Project Garbanzo
    • C
    • Rust/zinc

Sunday, 15 May 2016

USB Design


Some specifications of USB can be complicated as USB has a high data rate.



USB 2.0 low speed (small distances)


Data rate is 1.5 Mbit/s. Doesn't need impedance matching and same trace lengths for small distances. Requires a pull up resistor for USB_DM. Some MCUs have pull up resistors from USB_DM (D-) to VDD (voltage of MCU).

USB 2.0 full speed (small distances)

Data rate is 12 Mbit/s. Doesn't need impedance matching and same trace lengths for small distances. Requires a pull up resistor for USB_DP. Some MCUs have pull up resistors from USB_DP (D+) to VDD (voltage of MCU).


USB 2.0 full speed/low speed (long distances)

Here you need to consider trace length and impedance matching. Design steps:
  1. Add ground plane bellow traces (if ground plane not available add a VDD plane)
  2. Find the minimum lengths of D+ and D- traces to MCU
  3. Take the longest of the lengths and make length of the traces match
  4. Use micro-strip calculator to calculate impedance
  5. Adjust width of trace for the impedance between D+ and D- is 90 ohms
  6. Adjust size of ground plane for the impedance of D+ to ground is 30 ohms and D- to ground is 30 ohms









Friday, 13 May 2016

General PCB design process

Documentation for general PCB design process
  • Set design requirements
  • Pick components
  • Read datasheets
  • Design circuit
  • Check footprints
  • Check layout of PCB
  • Use DRC and signal integrity tools
  • Review circuit design
  • Make footprints
  • Check layout of PCB
  • Review footprints dimensions
  • Do a preliminary placement of components
  • Read all signal specifications
  • Place traces for signals
  • Place traces for power supply
  • Place traces for ground
  • Use DRC and signal integrity tools
  • Review PCB design

Designing for STM32 ARM

There are a few thing to worry about designing STM32 circuits/PCBs. The main ones are power supply,ground, reset, boot pins, SWD, crystals, analog side, USB, and boot loaders.


Power supply


Power is provided with VDD (digital). The voltages are typically around +3.3V. Use decoupling capacitors (example: 0.1uF) near STM32. Place the STM32 close to power supply. Use a large trace for power. Read datasheet for more information.


Ground

Ground is provided with VSS (digital). Use a ground plane or a large trace for ground.


Reset


Reset pin is NRST. Typically the pin is connect to VDD with a pull-up resistor. To reset the STM32 set NRST low. Add a decoupling capacitor (example: 0.1uF) near NRST.


Boot pins


Boot pins are typically BOOT0 and BOOT1. Functionality of boot pins.

BOOT1BOOT0Boot mode
X 0User Flash memory
0 1 System memory (boot-loader)
1 1Embedded SRAM

Add a pull-down resistor (example: 1K ohms) from boot pins to VSS.


SWD


Here are the pins for SWD (Serial debug wire):
  • VDD power supply
  • VSS ground
  • SWDIO
  • SWCLK
  • NRST reset
SWD is used to flash and debug STM32. The STM32 doesn't have flashing/debugging capabilities by itself. STM32 requires STLinkV2 to flash and debug STM32. See SWD design blog post for more information.


Crystals


Some STM32 requires HSE (high frequency external oscillator) and LSE (low frequency external oscillator) . Pin names have OSCIN and OSCOUT. Steps to design:
  1. Find if HSE or LSE or both is required in the datasheet
  2. Find acceptable range of frequencies for crystals (use STM32CubeMX)
  3. Select crystals from component distributor
  4. Get load capacitance of crystals
  5. Find stray capacitance of PCB
  6. Use load capacitance of crystals to calculate external load capacitors
CL = ((C1 x C2) / (C1 + C2)) + Cstray

Where CL = load capacitance of crystal
C1 = external load capacitor
C2 = external load capacitor
Cstray = stray capacitance of PCB

Analog side


The pins are VDDA and VSSA. They are analog power supply and ground. Design steps:
  1. Find if STM32 has VDDA or VSSA or both
  2. If they exist then they must be connected properly
  3. Find tolerances for VDD
  4. Design filter circuit using an inductor and capacitor from VDDA to VDD
  5. Separate VDDA and VDD
  6. Separate VSSA and VSS
  7. Use star ground configurations to connect planes of VSSA and VSS 
  8. VDD and VSS must not be noisy 

 

USB


USB uses USB_DM and USB_DP pins. For USB 2.0 low speed/full speed impedance matching and trace length doesn't matter. Some STM32 have pull up resistors from USB_DP to VDD. See USB page for more information.


Boot loaders



Boot loaders are used to load user flash. Some STM32 have boot loaders builtin from the factory. Use STLinkV2 or STM32 DFU to flash boot loader.



Unused pins


Unused pins can be configured using the following way:
  • Not connected to anything. Make pin output.
  • Connect to VSS using a pull down resistor.
  • Connect to VDD using a pull up resistor.

Saturday, 2 April 2016

NVC - VHDL Compiler

NVC

An open source VHDL compiler.

To analyze a files.

nvc -a blah.vhdl tb_blah.vhdl

Bit code generation of workbench.

 nvc -e tb_blah

Simulation of the file. Generate a wave file named data.fst from 0 ns to 50 ns.

nvc -r --wave=data.fst --stop-time=50ns tb_blah

 Viewing the workbench wave file.

 gtkwave data.fst

Saturday, 12 March 2016

Embitz 0.42 on Linux

I have been messing around with Embitz on wine. It seems to be functional enough to compile code.

I have written a script to install Embitz automatically.
https://www.playonlinux.com/en/app-2764-Embitz_042.html
It uses Playonlinux,which is a system for containing specific workspaces for each wine applications. It installs each program separately with the program's dependencies.

Hopefully, the program can flash STM32F0 MCUs without any modifications.



Sunday, 7 February 2016

Project Popsicle Stick: Preliminary PCB design



A very rough version of the PCB design. I need to look it over to see if it works. The pinouts have changed to make PCB design easier. After this, I might manufacture it at smart prototyping.

Friday, 5 February 2016

Project Popsicle Stick: Components

Components:
  • STM32F070CBT6     MCU
  • ICE40HX1K-TQ144     FPGA
  • NX3225SA-32.000MHZ-STD-CSR-1  32MHz crystal
  • CDBU0520  0.4V diode
  • LD1117S33CTR   3.3V regulator
  • LD1117S12CTR   1.2V regulator
  • 150080VS75000    Green LED
  • CRCW060366R5FKEA    66.5 ohm resistor
  • CRCW0603100RFKEA    100 ohm resistor
  • CRCW060310K0FKEA    10K ohm resistor
  • 1X20 header pins
  • 1X4 header pins
  • CL05A104MP5NNNC      0.1uF capacitor
  • CL21B103KBANNNC     0.01uF capacitor
  • GRM1555C1H6R0WA01D    6pF capacitor
  • CL21A106KQCLRNC           10uF capacitor
  • GRM155R60J105KE19D      1uF capacitor
  • B3F-1000                             Push button switch
  • 10118192-0001LF               Micro USB B

Sunday, 24 January 2016

Project Popsicle Stick: General schematic

General schematic and header layout. The PCB will have:
  • 17 Pins for STM32F070CBT6
  • 36 Pins for ICE40HX1K-TQ144
  • 4 Pins for SWD programming and debugging
  • 1 LED
  • 1 Micro USB

Project Popsicle Stick: ICE40HX1K-TQ144

Components:
  • ICE40HX1K-TQ144
  • CDBU0520


Specifications:
  • Programmable logic
  • Drive outputs on headers
  • Interface with STM32F070CBT6

Friday, 22 January 2016

STM32F070CBT6 Pin information

General pin Information:
  • VDD: Voltage source 3.3V
  • VSS: Ground
  • VDDA: Analog voltage source 3.3V
  • VSSA: Ground
  • BOOT0: Ground to boot from flash
  • OSCIN: High speed external clock
  • OSCOUT: High speed external clock
  • OSC32IN: Low speed external clock (optional for RTC)
  • OSC32OUT: Low speed external clock (optional for RTC)
  • NRST: Reset STM32
  • PA12: USBD+
  • PA11: USBD-
  • SWDIO: Debug/programming
  • SWCLK: Debug/programming

Project Popsicle Stick: STM32F070CBT6

Components:
  • STM32F070CBT6
  • NDK NX3225SA-32.000MHZ-STD-CSR-1
  • Push button


Specification:
  • Interface with SPI
  • Program ICE40HX1K-TQ144 with SPI
  • Interface with pins
  • Programmable through USB

Project Popsicle Stick: Power System

Components:
  • LD1117S33CTR
  • LD1117S12CTR
  • C_0603
  • C_0805
  • R_0603
  • 150080VS75000

Specification:
  • Produce 1.2V, 3.3V
  • Input 5V

Thursday, 21 January 2016

Project Popsicle Stick

Project Popsicle Stick

https://github.com/brosnanyuen/Project-Popsicle-Stick 

ICE40 + STM32 development board
Popsicle STick

Main components:
  • STM32F070CBT6
  • ICE40HX1K-TQ144
  • 5V Micro USB connector
  • Crystal oscillators
  • Linear voltage regulators

Specification:
  • Power from 5V Micro USB
  • Program STM32 using USB 2.0 or JTAG
  • Configure FPGA from STM32 using SPI
  • 96 IO pins for FPGA
  • 37 IO pins for STM32

Friday, 8 January 2016

Xilinx Vivado on unsupported Linux OS

How to install Xilinx Vivado on unsupported Linux OS.


Change permissions

chmod 777 ./Xilinx_Vivado_SDK_2015.4_1118_2_Lin64.bin

Run as root

./Xilinx_Vivado_SDK_2015.4_1118_2_Lin64.bin --confirm

Proceed and get the /tmp/selfgz4324 location.

Edit the xsetup

sudo vim /tmp/selfgz4324/xsetup

Replace

if [ "$(uname -i)" != "x86_64" ]; then

with

if [ "$(uname -m)" != "x86_64" ]; then

Proceed.

Friday, 1 January 2016

DLCS 1.1.X and JointJs

I am abandoning DLCSim for DLCS as DLCSim is a bit too complex. DLCSim has grown too large for a single library. Many parts of DLCSim could be reused in other project and libraries. So I am going split it up and make general libraries out of them. DLCSim will be split into 3 parts.

The smaller libraries:
  • funary . General purpose arbitrary binary operations library. For use of manipulating binary using arrays.
  • DLCS . Core simulation library. For calculating the values and properties of the simulation.
  • DLCS.Utils . Library for integration of DLCS and JointJS. This is used for bridging DLCS and JointJS. This will also handle other third party libraries.

From DLCS 1.1.X onwards will be focused on integrating DLCS and JointJS.