• 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);
  • 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.
  • 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.

  • 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.

  • 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.
  • 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.

  • 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.

  • 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.

  • 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.

  • Stack implementation without pointer

    Stack is a type of data structure, where data is stored in Last In First Out fashion. In embedded system there are different kind of stacks available.
    They are implemented in hardware and software.
    The hardware implementation of stack is faster than software stack; but the size of stack in hardware is limited.

    There are two types of stack available in hardware implementation:
    1. Up-counting
    2. Down-counting
    Up-counting stack: where the memory location of the top element of stack is incremented from the low memory address;
    Down-counting stack where the memory location is decremented from the highest memory address.

    The following is a general stack implementation program which is written on x86 machine.

    
    #include <stdio.h>
    
    #define MAX 7
    
    int arr[MAX]; // array of size MAX
    
    int top = -1; //top is the index which stores the location
                  // of the last inserted element in stack
    /*
    isFull Function checks that the top == MAX
    isEmpty Function checks that the top == -1
    */
    int isFull();
    int isEmpty();
    
    /*
    push(int num)     To insert a element in stack
    pop()             To remove the last inserted element in stack
    display()         To display all the element in stack
    */
    
    void pop();
    void push(int num);
    
    void display();
    
    int main() {
    
    display();	//display the elements of the stack
    
        push(32);
        push (1);
        push (26);
        push (64);
        push (127);
        push (-98);
        push (43);
        push (5);
        push (255);
        push (5);
        display();
        pop();
    
    return 0;
    }
    
    int isEmpty(){
    	if(top == -1){
    		return 1;
    	}
    	else
    		return 0;
    }
    
    int isFull(){
    	if(top == MAX){
    		return 1;
    	}
    	else
    		return 0;
    }
    
    /*check if the stack is full or not.
    If stack full 
    write overflow
    else 
    increment the TOP and write the value.
    */
    void push(int num){
    	if(isFull()){
    	printf("Stack Full OverFlow\n");
    	}
    	else {
    		top++;
    		arr[top] = num;
    	}
    	display();
    }
    /*check if the stack is empty or not.
    If stack empty 
    write underflow
    else 
    decrement the TOP.
    */
    void pop(){
    	if( isEmpty() ) {
    	printf("Stack Full OverFlow\n");
    	}
    	else {
    		top--;
    	}
    	display();
    }
    
    void display(){
    	if( isEmpty() ){
    		printf("Stack Empty UNDERFLOW\n");
    		
    	}
    	else{
    		int temp;
    		for(temp = top; temp >= 0 ; temp--){
    			printf("%d ",arr[temp]);
    		}
    		printf("\n");
    		/*int *ptr = arr;
    		while(ptr <= ((&arr)+MAX) ){
    			printf("%d ",*ptr);
    			ptr = ptr + 1;
    			printf("\n");
    		}
    		*/
    		
    	}
    }
    

    Output Of the above program

    
    Stack Empty UNDERFLOW
    
    32 
    
    1 32 
    
    26 1 32 
    
    64 26 1 32 
    
    127 64 26 1 32 
    
    -98 127 64 26 1 32 
    
    43 -98 127 64 26 1 32 
    
    5 43 -98 127 64 26 1 32 
    Stack Full OverFlow
    
    5 43 -98 127 64 26 1 32 
    Stack Full OverFlow
    
    5 43 -98 127 64 26 1 32 
    
    5 43 -98 127 64 26 1 32 
    
    43 -98 127 64 26 1 32