Posted on — Leave a comment

Overview of STM32L476 Discovery Kit

This development board from STMicroelectronics has different peripherals such as an LCD screen, MEMS sensor, USB OTG, Microphone and a 16 MegaByte memory.

It has a cr2032 battery socket on the back. So you can use a 3-volt cr2032 battery to power this board. But for that, you have to change the jumper from 3v3 to batt.

Here is a video providing overview of the stm32l476 discovery kit.

Posted on — Leave a comment

IDE Supporting STM32L476-Discovery

An IDE combines a range of different tools which are essential for the development of software. Different IDE from different vendors is available.

Here are the IDE that I have used.

  1. STM CUBE IDE
    website: https://www.st.com/en/development-tools/stm32cubeide.html
    It is distribuited freely by ST. You can use this and it has a good device support and newer devices are quickly added to it. ST uses the eclipse IDE as the base and then they have customized it heavily for the microcontroller development. It also comes with their ST cube MX integrated in it. Which makes development quicker. From the information i have gathered till now it uses gcc as their compiler. Support is available at the forum hosted by ST on thier website.
    They offer support for freeRTOS out of the box.
  2. Keil MDK
    website: https://www2.keil.com/mdk5
    They have a wide support for ARM based devices. You can download the IDE from thier website. It has two version one is the evaluation which limits your code size to 32 Kilo Bytes; but it is good for begineers. The second is the paid option. In both the version all the tools works fine. It is just the code size that puts a limit.
    Keil also host a huge knowledge base on their website. It also has some sample which can be usefull in getting started.
  3. IAR Embedded Workbench for Arm (EWARM)
    website : https://www.iar.com/products/architectures/arm/iar-embedded-workbench-for-arm/
    They are also used by the electronic industry. They also has their own compiler which is written for the speed. They have a standard layout and option. They are user friendly. From the information gathered by me they have tested functions only. So it is very standardised set of tool. They also have put a limit on their evualtion IDE of 32 Kilo Byte Code size.
Posted on — Leave a comment

Powering STM32l476-DISCO using CR2032 Battery

STM32l476-DISCO using CR2032 Battery

The stm32l476-disco can be powered by a battery. The board has a socket to place the battery on the backside of the board.

For using the battery you need to do the following steps.

  1. Remove the RST jumper
  2. Remove the jumper marked as CN3
  3. The Jumper JP5 should be set to IDD
  4. The Jumper JP6 should be set to BATT

The battery-powered operation is useful in low power operations.

There is a switch to change the power selection from battery to USB. You need to physically change the jumper location to BATT from 3v3.

The controller gets 3v3 from the st-link section of the board. ST-link gets the power using the USB mini port.

Posted on — Leave a comment

STM32L476vg Discovery Kit Images

These are two images of the development board.

Almost entirely the board is made using SMD components. There are some through-hole components.

The back of the development board shows us the different fuses and connections.
At the back, there is a battery holder which can be powered using cr2032.

The top half of the board has an st-link debugger.

Posted on — Leave a comment

Introduction to Embedded System

An embedded system is a combination of software and hardware to perform a specific task at a instant of time.

There are two types of embedded system:

  1. Real-Time
    These are the system in which the output has to reach the desired set-point within an allocated time.
  2. Non Real-Time
    In the system the output doesn’t depend on the input. There is no time window allocation for the performing of task.

An embedded system can be distributed. A distributed embedded system is the one in which you can externally add or subtract specifics components. Example: consumer PC etc.

All the principles of control system directly affect the embedded system.

An Embedded system can be designed in two ways:

  1. Standalone mode
    In standalone mode, the system does all the work independently and doesn’t rely on any other external resources.
  2. Distributed mode
    In distributed mode, the system is a subset and depends on other subsets.

A processing element can be a self-contained unit or it may be spread across physically. example: AMD Sempron 145 is a self-contained unit whereas relay based processing element is physically spread across space.

Posted on — Leave a comment

How to use gdb debugger in raspberry pi for ARM assembly programs

After you have written your program. You try to run your program, sometimes the output produced by your program is not as you would have desired.

That’s when you use the debugger to look into the code and figure out what went wrong.

Debugging gives you an insight look into the low level programming instructions that your compiler have produced. But to understand the logic and program execution; you need to know at least the basics of assembly programming.

On Linux based operating system such as Debian, a gdb debugger is available.

But it not very friendly to operate. So there are various tools that make it easy to work with the gdb debugger. One of them is the GEF extension.

The GEF extension provides you with the view of registers, stack and disassembly of program, on a single page.

Posted on — Leave a comment

STM32L476vg ARM Cortex M4F Architecture

It uses ARM v7E-M architecture.

It a Harvard based architecture with two distinct buses for data and memory.

It has all the instruction set of M0, M1 and M3 .

It also has an additional feature set to support Floating-point Arithmetic. IEEE754 standard in single precision and double precision.

The following points are from the programming model.

There are three modes of operations:

  1. Thumb State
    1. Thread mode: Privileged
    2. Thread mode: Unprivileged
  2. Debug mode

Two thread mode are given to support a operating system. Kernel software run in priviledged mode and the user application software runs in unprivledged mode.

Unprivileged mode has some restriction on memory access.

Privileged mode has full access to system resources.

If an operating system is running and a user application needs to access the Privileged resources it has to generate an exception/interrupt and then the interrupt will be taken by the handler and put the system in privilege mode.

You can switch from privilege mode to unprivileged mode by setting nPRIV and SPSEL bit in the CONTROL register.

Just like all the other processors ARM Cotex M4 has registers and pointer registers.

The major difference is the use of two different stack pointer registers.

  1. Main Stack Pointer (MSP)
  2. Process Stack Pointer (PSP)

If application is running in privileged mode than main stack pointer will be used. And if the application is working in unprivileged the process stack pointer will be used.

General Purpose Registers:

R0 – R12 – General Purpose Register

R13 – Stack Pointer (SP) {MSP and PSP}

R14 – Link Register (LR)

R15 – program counter (PC)

Special registers:

  • xPSR – {APSR, EPSR, IPSR}
  • FAULTMASK
  • BASEPERI
  • PRIMASK
  • CONTROL
floating point registers of arm cortex m4f

There are 32 FPU registers from s0 to s31.

They group together to form a single 64-bit register. which are from D0 to D15

There is a Floating Point Status and Control Register (FPSCR).

Posted on — Leave a comment

ARM Processor Based Microcontrollers from ST

There are lot of ARM based microcontroller offered by ST.

They use ARM Cortex M processor with ST peripheral such as GPIO, ADC etc.

They mostly fall into these following groups:

  1. ARM Cortex M0
  2. ARM Cortex M3
  3. ARM Cortex M4
  4. ARM Cortex M33
  5. ARM Cortex M7
    which is also known as M4F as it has an FPU unit.

Then there is ST classification :

  • High performance
    Higher clock speed, Has almost everything included from that segment.
  • Mainstream
    Balanced between Low Power and High Performance.
  • Low Power
    Clock speed reduced to a limit, Has additional hardware for switching off individual peripherals.
  • Wireless
    Has cortex M0+, Peripherals support for radio

The widely available stm32f1 microcontroller also known as the blue pill has ARM cortex M3.

STM32L4 has an ARM Cortex M4F.

Posted on — Leave a comment

The command-line argument in C

Lets say if we want our program to work with other programs and other program call our program. Then just like how we provide arguments in function call; we can call our program and the arguments can be given using the command line.

#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[]){
	int arr[5] = {1,2,3,4,5};

	printf("the argument number of of main argc : %d\n",argc);
	printf("The first argument : %s\n",argv[1]);
	
	return 0;
}


argc contains the number of argument passed to the main function.

argv is the argument vector. Contains the argument given from index 1 and above.

index 0 of argv is the file name of the function.

Posted on — Leave a comment

Union

Union is another user defined data type.

The difference between union and struct is that; struct uses a contagious memory allocation for each individual item inside it; whereas union uses the size of biggest element for allocation of memory.

union segment1 {
int x1;
char y2;
};

// sizeof segement1 union is 4 bytes 

struct segment2{
int x1;
char y2;
};

// sizeof segement1 union is 8 bytes