Posted on — Leave a comment

Compile AVR Code in Raspberry Pi

I have recorded a video showing the steps to compile AVR code.

In this video, you will see how to compile AVR led blinking code for the atmega32 microcontroller is being compiled using AVR-GCC in raspberry pi 3 b+.

Step 1. : Create a file and put your avr c code in that file. Save that file with a “.c” extension

Step 2. : Run the following commands one by one

avr-gcc -g -0s -mmcu=atmega32 -c led.c
avr-gcc -g -mmcu=atmega32 -o led.elf led.o
avr-objcopy -j .text -j .data -o ihex led.elf led.hex

Step 3. : The step 2 will create a hex file. which can be uploaded to the microcontroller with the help of a programmer.

Posted on — Leave a comment

How to install AVR-GCC Compiler in raspberry pi

In this video, you will see that how avr compiler can be installed in raspberry pi model 3 b+.

For steps on how to install avrdude in raspberry pi you can go here.

http://www.exasub.com/component/integrated-circuit/microcontroller/avr/using-usbasp-v2-0-avr-programmer-with-raspberry-pi-3/

AVR compiler and avrdude together on raspberry pi make it a development environment for embedded systems involving Avr microcontroller.

Posted on — Leave a comment

Using USBASP V2.0 AVR Programmer with Raspberry Pi 3

Raspberry pi or Rpi can be used for programming certain AVR microcontrollers. I have made a video showing you the steps.

Step 1: you have to install AVRDUDE

sudo apt-get install avrdude -y

Step 2: You can check if the avrdude is installed properly or not using

avrdude

step 3: connect your USBASP v2.0 to your microcontroller

avrdude -c usbasp -p m32

Microcontroller Programmed:

Atmega32, atmega32a, Atmega16, Atmega16a,

Posted on — Leave a comment

How to add a new .h header file in STM32 Cube IDE

  1. Click on [arrow] besides Core in your project explorer
  2. Right Click on “Inc” folder and point your mouse at the “NEW” menu item.
  3. Select “header file” option
  4. A new Header file dialog box will appear
  5. Fill in the name of the header file in “Header file” with a dot h extension
  6. Click on finish
  7. Now open your main.c file and add your custom header file after USER CODE BEGIN Incudes
Posted on — Leave a comment

How to Perform Discrete Fourier Transform on N-Point Sequence using STM32L476G

x(n) = { 0, 1, 0, 1}

Here x(n) is a 4 point sequence

Now to perform Fourier transform on this sequence.

DFT Formula

Here X(k) is the DFT of x(n)

‘k’ is the index representing individual frequency component

‘N’ is the Length of the sample sequence

‘n’ is an index of the element of the sequence in x(n)

For example: if we calculate the value for k =1

This will give us the X(1)

So, if the sequence is sampled at 4Hz and the sampling frequency is equal to two times the max frequency. Then X(1) gives us the 1 Hz frequency component.

To calculate Euler identity

Here is the code:

/*
* Author: ABHAY KANT
* Discrete Fourier Transform using STM32L476vg on STM32L476g-Disco board.
* computes N point DFT
* computes magnitude of N/2 Points of dft
* computes phase of N/2 points of dft
* NOTE: DFT array is named xfft. It DOES NOT Calcultes DFT using FFT algo.
* Limitations: for a 2000 point sequence it takes a lot of time.
               And as the number of points increase the computational time also increases.
a rough estimate of time for a 2000 point dft it takes roughly ~ 60 seconds. 
*/
asm("nop");
//int xn[6] = {1,1,2,2,3,3};

int16_t Len = 1024; 
float xn[Len];

float xfft[Len * 2];

/*
 * calculating phase and mag for only N/2 since the value generated after N/2 are conjugate 
 */
float phase[Len/2], mag[Len/2];
int	k = 1;
int	N = 0;
int	n = 0;
float	real = 0;
float	imag = 0;
float	param = 0;
int	freq = 10;
int i;

/*
 * These two "for loops" are used to initalize the array with zero's
 */
for(n=0;n<=Len;n++){xn[n] = 0;}
for(n=0;n<=Len*2;n++){xfft[n] = 0;}



/*
 * Generating a sine Wave 
 */

	for(i=0; i<Len/2; i++){
		xn[i+512] = sin((2 * 3.1415926 * i * freq)/Len);
	}

N = Len;				
/* Note: if Len/8 then it will only calculate the 1/8 th term from 0 only.*/
/*
 * This loop calculates the x[n].e^(-j2.PI.n.k/N)
 */

	for(k=0 ; k<N ; k++){

		for(n=0 ; n<N; n++){
		param = ((2 * M_PI * n * k)/N);
		real = real + ( xn[n] * cos(param) );
		imag = imag + ((-1) * xn[n] * sin(param) );
		}
		xfft[2 * k] = real;
		xfft[(2 * k) + 1] = imag;
		real = 0;
		imag = 0;
	}



/*
 * Calculate phase angle of each frequency component
 */
float temp;
for(k=0; k<N/2;k++)
{
	temp = xfft[(2 * k ) + 1] / xfft[2 * k];
	phase[k] = atan(temp);
}

/*
 * Calculate Magnitude of each frequency 
 */

for(k=0; k<N/2;k++)
{
	temp = sqrt( (xfft[(2 * k ) + 1] * xfft[(2 * k ) + 1] ) + ( xfft[2 * k] * xfft[2 * k] ) );
	mag[k] = temp;
}
asm("nop");  //added to support for creating breakpoint during debug
Posted on — Leave a comment

How to add CMSIS DSP Library to STM32 Cube IDE Project for stm32l476vg

To add CMSIS DSP library in you stm32cube project.

You can follow the steps written on ST’s website

Configuring DSP libraries on STM32CubeIDE

I have also made a video.

In this video. I have shown steps to add the arm_math.h header file. You need to configure the stm32 cube ide.

Posted on — Leave a comment

How to use LCD Driver of STM32L476VGT on STM32L476 Discovery

To use the internal LCD driver of stm32l476; the best way is to use the LCD driver provided in the BSP. It is located inside the STM32Cube_FW_L4_V1.16.0 repository.

  • Go to the
    ..\STM32Cube\Repository\STM32Cube_FW_L4_V1.16.0\Drivers\BSP\STM32L476G-Discovery
  • Copy the stm32l476g_discovery.c, stm32l476g_discovery.h, stm32l476g_discovery_glass_lcd.c and stm32l476g_discovery_glass_lcd.h
  • Paste the files in your project.
  • Include the header file in your project.
    #include “stm32l476g_discovery_glass_lcd.h”

After this you need to

  1. Initialize the LCD segment
    BSP_LCD_GLASS_Init();
  2. Clear the LCD RAM
    BSP_LCD_GLASS_Clear();
  3. Write Data in LCD RAM
    BSP_LCD_GLASS_DisplayChar((uint8_t *)”A”, POINT_ON, DOUBLEPOINT_OFF, 1);
Posted on — Leave a comment

How to use printf using serial wire debug on STM32L476 Discovery

We all use printf statements for debugging purposes at some point in time.

To use print statement. You need to do fuse one solder bridge

Solder Bridge information from the STM32L476 Discovery Kit User Manual UM1789

Fuse the solder bridge number SB14.

Always be careful since the solder bridges are very small.

After you have done fused the solder bridge. You can configure your project in STM32 Cube IDE.

Watch the video below for complete instructions.

A few things must be taken care of before you start debugging:

  • The Core Clock in your debug configuration must be equal to the system core clock.
  • Press the record button in SWV ITM Data Console before you start debugging.
Posted on — 1 Comment

How to start a project for STM32L476 Discovery in STM32 Cube IDE

Download the STM32 Cube IDE from https://www.st.com/en/development-tools/stm32cubeide.html

Watch this video tutorial.

Write a program using STM32L476G-DISCO

Step1: Install STM32 Cube IDE

Step2: Create a New Workspace
A workspace is a directory which will contain all your code and library related to your project.

Step 3: click on “Start new STM32 Project” button

Step 4: Select your board “stm32l476G-DISCO”

Step 5: Give your project a name
Do not change any options

Step 6: Select “YES” when prompted for “Initialze all peripheral with their default mode”
It is very important that you select YES other wise it will remove all the associated peripherals and you have to manually add the desired peripherals one by one; which is very difficult for beginners.

After these steps your project is created and it will open a STM32 CUBEMX inside your IDE.

Please watch the video. As there are a lots of steps and instruction which are difficult to explain by writing alone. Video will show you a step by step procedure and give you a basic explainition.

You can now change the option or you can proceed forward and click on generate code. This will create all the required code changes.

Now you can open you “main.c” file inside your IDE and write code.