Union magic : union in C for packing
The above code should output 0xDEAD value when run . Explanation: Union allocate the largest members size in memory , and all the members are stacked on top of each other this results in two struct fields pointing to the High byte of 16 bit union , while the other is the low byte Usage:…
Keep readingBit magic : Bitfields in C struct
Bit fields are very useful to manipulate individual bits and packed with struct The above code demonstrates a simple example of such usage Have a great day!
Keep readingPrintf redirect to UART2 stm32
There are multiple ways to do this use they below code to override _write in printf Note: IF you do not see any output use the below code to clear buffer before calling any printf and after UART init 2. Using Putchar method: 3. third method using SWV in stm32 enable SWV before using this…
Keep readingRiscV Workshop day 1
basic Gcc commands riscv64-unknown-elf-gcc -O1 -mabi=lp64 -march=rv64i filename.c riscv64-unknown-elf-objdump -d a.out | less simulation spike pk a.out spike -d pk a.out :until pc 0 100b0 100b0 is the memory location to jump to example main for breakpoint : reg 0 a2 // read valur of register a2
Keep readingPrint message using arguments with UART
va_list, va_start, va_end are used for variable argument from header “stdarg.h” vsprintf is used to combine the va_list arguments with the message passed to create a single string code:
Keep readingESP32 RGB led with PWM / FreeRTOS
Simple code that demonstrate how rgb led is setup and how various colors can be set using the below code
Keep readingESP32/RTOS — simple rgb led blink
Below is the code to control 3 gpios in rgb led in esp32
Keep readingTMUX basics
Hierarchy in tmux: session > window > pane. Prefix for commands and help:Ctrl-b and sth: issue a command to tmux, inside tmux.Ctrl-b and ?: see all commands. Session commands:tmux: creates a new session and enters it.tmux new -s sessionname: creates a session with the specified name.tmux ls: lists all sessions.Ctrl-b and d: detach current session.Ctrl-b…
Keep readingEmacs basics
Initial setup note: C= ctrl key , M = alt key (meta key) , example : C-x C-f means press Ctrl+x together release then press Ctrl+f together Basic commands required /info to use emacs handy commands: Cursor : Line edit : Emacs has an on-line help system that can be invoked by typing Control-H. If…
Keep reading[2] ARM assembly
When it comes to programming Arm in thumb2 instructions there are only a handful of opcodes to be considered 1.MOV is used to copy data between registers ex: MOV R0,R1 2. Basic load/Store commands: Used to load /store data between memory and Registers MOV R2,=0x20000000 LDR R1,[R2] STR [R2],[R3] //ASSUME R3 HAS A VALID ADDRESS…
Keep reading[1] ARM Minimal Assembly code (cortex m3/m4 + keil IDE)
ARM processors have supported two different instruction sets: the ARM instructions that are 32 bits and Thumb instructions that are 16 bits. Thumb2 instructuction was introduced later which are 32bit instruction and the processor doesnt have to switch between modes to perform instructions. ARM is faster as it requires less clock cycles for execution whereas…
Keep readingAVR Assembly code
Simple code example for load and add instruction: AVR MCUs’ are generally fast, they can execute 16MIPS at 16Mhz because of how the busses are designed and also the simplicity of RSIC architecture. Input/ output using gpio: steps: set DDRx to 0 for input , 1 for output write PORTx value to turn on or…
Keep reading[1] Stm32f4xx Custom PCB design using KiCAD v6
Stm32 is a widely popular MCU based on ARM core and I have always been fascinated to work with these tiny powerhouses! This post is a part of the custom PCB design build series and hopefully, I will keep posting about basic hardware design. Setup a KiCAD project as usual and we will start with…
Keep reading[Part-1] Yocto Linux Build for Raspberry pi zero w
The Yocto Project is an open-source project that delivers a set of tools that create operating system images for embedded Linux systems. The Yocto Project tools are based on the OpenEmbedded (OE) project, which uses the BitBake build tool, to construct complete Linux images. BitBake and OE are combined to form a reference build host…
Keep reading[7] Serial Pheripheral Interface(SPI) communication using atmega328 in AVR C
Refer this blog for more information [credit to author] Important registers for SPI 1.SPCR – SPI Control Register 2.SPSR – SPI Status Register 3.SPDR – SPI Data Register atmega328 to atmega328p communication using SPI : using PB5,4,3,2 for SPI (arduino uno digital pins 13,12,11,10) SCK,MISO,MOSI,SS SPI master using atmega328 Code for Slave arduino:
Keep reading[6] Analog (ADC)+USART using AVR (atmega328)
I am using LDR (light dependent resistor) to get analog values Below is the explanation from datasheet regarding how to use registers to start one time conversion / free running mode. A single conversion is started by disabling the Power Reduction ADC bit, PRADC, in ”Minimizing Power Consumption” on page 51 by writing a logical…
Keep reading[5] AVR C USART transmit with ISR using atmega328
I am using a very simple buffer to keep characters so they are send when USART UDR0 is ready to transmit using an ISR
Keep reading[4] AVR C PWM (fast PWM, phase correct PWM )
I found this wonderful article and another one that explains the theory of PWM and the waveform and where it’s used. Since I don’t think I can improve on that I will leave it there for reference. Summary of the above article [ for lazy people like me 😉 ] : As the title suggests,…
Keep reading[3] AVR timer 16 bit in CTC mode – timer 1 atmega328
set Timer Control register 1 (TCCR1B since WGM12 should be 1 for CTC) load the value to be compared in Overflow Compare register (OCR1A) enable interrupt for OCIE register using Timer1 Mask register (TIMSK1) enable register and set prescalar (1024 in the below example) use ISR use this online calculator for ticks calculations.
Keep reading[2] AVR timer/ counter — CTC mode
There is a TCNTn called timer/Counter Register for each of the timers in AVR. For example, In Atmega32 we have TCNT0, TCNT1 and TCNT2. The TCNTn is basically a counter. It counts up with each pulse. It contains zero when reset. We can read or load any value in the TCNTn register.Each of the timer…
Keep readingSaleae Logic Analyser Clone with Ubuntu Linux
The Saleae Logic is an 8 channel 24MHz logic analyser. Soon after its launch people in China opened them up to find that they are pretty simple inside and, as sure as night follows day, little workshops in Shenzen started producing clones impossibly cheaply and to be sold through eBay, AliExpress, etc Follow this link…
Keep reading[1] AVR 8 bit – GPIO
For GPIO only these 3 registers are important for bit manipulation. For each port there are three important registers: x=B,C,D : example DDRB,DDRC,DDRD etc , PORTB,PORTC,PORTD etc , PINB,PINC,PIND etc. Blink.c Input using push button without any input pullup (debounce not implemented ) input pullup fo switch write 1 to the pin bit using PORTx=(1<<PIN)
Keep readingAVR GCC AVRdude flashing using CLI (makefile example included)
simple hello world program for atmega328*: compiling using avr-gcc cli: avr gcc flags flashing .hex file: usbasp is the programmer used! To automate the whole process lets write a make file! example : avrfreaks makefile (updated on jul 4 2022)
Keep readingROS2 HUMBLE HAWKSBILL NOTES
Installation : follow the instruction: https://docs.ros.org/en/humble/Installation/Alternatives/Ubuntu-Development-Setup.html Creating a workspace: Creating a package:(Python based) ament_python should have the following dir structure setup.cfg should have: setup.py should have: __init__.py can be empty follow this link to learn more package.xml should have : CMakeLists.txt should have: build package: run the package: creating launch file: launch.py add dependency to…
Keep readingNVIDIA graphics not detected / device manager doesnt show on asus gaming laptop solution
I had asus a17 ryzen 7 rtx3050 unfortunately after a while nvidia control panel was showing no graphics detected ! solution: open asus “Armoury Crate software” goto system> profile and change eco mode to standard mode or any other performance mode now reintall nvidia graphics driver and check device manager . All should be working…
Keep readingROS 1 notes
personal notes while learning ROS2 ROS1 installation: >Using Ubuntu as a base operating system, follow the installation guide on ROS wiki ROS1 Workspaces: >Catkin is a build system used to make workspaces, packages and libraries for ROS To create a new workspace: use this cheatsheet to refer catkin commands another interesting gist that has a…
Keep readingYocto Linux Qemu build basics
Using Ubuntu /Popos as a development machine Install required packages for Ubuntu/Debian-based Linux Download poky build system source from git cd into poky directory and run the init command the directory is switched to build-qemux86 (else cd into build-qemux86). Check the configuration file and set the machine to qemux86 (or qemux86-64 for 64bit) Start qemu…
Keep readingStm32f407vg-disc1 board -clock configuration (from scratch)
IDE used: stm32 Cube IDE official step1 > crete new project > c program and dont select stm32 project under type types of clock: HSI- high speed internal HSE- high speed external PLL- phase locked loop HSI 16MHZ setup without pll code: /** @file : main.c @author : Auto-generated by STM32CubeIDE @brief : Main program…
Keep readingHow to build Raspberry pi zero w BUILDROOT image
Lately I was reading about embedded linux and came to know about two such custom embedded linux system build sytem the Yocto project and Buildroot.I wanted to make my own custom linux for raspberyy pi zero W i had in my *ahem* attic. Requirements: Raspberry pi zero w (ofcourse) A PC (with ubuntu 18.04 or…
Keep readingMy First Blog Post
Be yourself; Everyone else is already taken. — Oscar Wilde. This is the first post on my new blog. I’m just getting this new blog going, so stay tuned for more. Subscribe below to get notified when I post new updates.
Keep reading