Skip navigation
All Places > Contribute your knowledge > Blog



The STM32 embeds a temperature sensor that is can be used to measure the temperature of the die.

It is connected internally to one of the channel of the ADC.


I am attaching a simple code that reads the temperature sensor and then converts in degree C.


Note that this cannot be used to measure ambient temperature.


You also need to be aware of the min and the max as I stated in the code:


/* Internal temperature sensor: constants data used for indicative values in  */
/* this example. Refer to device datasheet for min/typ/max values.            */
/* For more accurate values, device should be calibrated on offset and slope  */
/* for application temperature range.                                         */
#define INTERNAL_TEMPSENSOR_V25        ((int32_t)1430)         /* Internal temperature sensor, parameter V25 (unit: mV). Refer to device datasheet for min/typ/max values. */
#define INTERNAL_TEMPSENSOR_AVGSLOPE   ((int32_t)4300)         /* Internal temperature sensor, parameter Avg_Slope (unit: uV/DegCelsius). Refer to device datasheet for min/typ/max values. */                                                               /* This calibration parameter is intended to calculate the actual VDDA from Vrefint ADC measurement. */


I have tested this code on a STM32F103 MCU on the STM3210E-EVAL board.


To run the code please copy and unzip the project zipped at:



You can download the Cube Library from our website:


Best Regards,



In this post how to use the basic features of SAP BusinessObjects Analysis, edition for OLAP and how to establish a data connection to our SAP NetWeaver BW system.

SAP NetWeaver Demo Model

Before we are going to look into more details of SAP BusinessObjects Analysis, edition for OLAP, you should take a look at the information available on SCN for the SAP NetWeaver Demo Model:

  • SAP NetWeaver Demo Model
  • SAP NetWeaver Demo Model: BI Content

During the excercises in this book we will use the SAP NetWeaver Demo Model in SAP NetWeaver BW as the basis for the BEx queries and as the basis for our excercises.

BEx Queries for Activities

For the next set of activities we will use a BEx Query based on the Multiprovider oD_NW_M01 of the SAP NetWeaver Demo Model.

Fig: BEx Query Designer

The BEx Query (see Figure 4.1) contains the following characteristics in the Rows:

  • Calendar Year
  • Region

The BEx Query contains the following characteristics in the Free Characteristics:

  • Country
  • Sales Organization
  • Sold to Party
  • Product Category
  • Product Group
  • Product
  • Calendar Year / Month
  • Distribution Channel
  • Division
  • Sales Group.

In addition the BEx query is using the following Key Figures:
Net Value

  • Open Order Quantity
  • Product Costs
  • Transport Costs
  • Rebates

For the first set of excercises we will use this BEx query.
Now that we have clarified, which InfoProviders and BEx queries we will use, we can start now in the next section with our first steps with SAP Businessobjects Analysis, edition for OLAP by establishing an OLAP connection to SAP NetWeaver BW.

Establishing an OLAP Connection

SAP BusinessObjects Analysis, edition for OLAP relies on the OLAP connections defined in your SAP BusinessObjects BI platform for the connection to SAP NetWeaver BW. So before we are going to learn more about SAP BusinessObjects Analysis, edition for OLAP and the product capabilities, we will have to configure a new OLAP connection towards our SAP NetWeaver BW system.

  1. Open the Central Management Console via Start > All Programs > SAP BusinessObjects Enterprise XI 4.0 > SAP BusinessObjects Enterprise  > SAP BusinessObjects Enterprise Central Management Console (see Figure 4.2)
  2. Set the authentication method to SAP.

Fig: Central Management console Log on

3. Logon with your SAP credentials towards you SAP NetWeaver BW System.

SAP Authentication

The usage of Single Sign On for your OLAP Connection does require that your SAP BusinessObjects BI environment is configured with the SAP authentication. The setup and installation of SAP BusinessObjects BI 4 is not part of this book, as this is already covered in my book Integrating SAP BusinessObjects BI Platform 4.x with SAP NetWeaver available with SAP Press.

Fig: Central Management Console Home

4. Select the entry OLAP connections in the category Organize.
5. Select the button in the toolbar to create a new connection

Fig: OLAP Connection

6. Enter your system details according to  below Table

Element NameDescription
NameHere you can enter a name for the OLAP connection. The name will then be shown to the user when creating a new workspace. Example: SAP BW
DescriptionHere you can enter a description for the OLAP Connection, which will be shown to the user when creating a new workspace.           Example : SAP NetWeaver Demo InfoProvider
Provider Here you need to select the type of data source that you will be using. In our example: SAP NetWeaver Business Warehouse.
Server Type  Here you can choose between an Application Server (Server) or a Message Server (Group) based connection, depending on your SAP landscape
System  Here you need to enter the three digits System ID of the SAP server. Example: IH1
Server Here you need to enter the full qualified server name of the application server. The entry Server is only shown, when you select the Server Type Server.Example:
System Number Here you need to enter the two digit system number of your SAP server. The entry System Number is only shown, when you select the Server Type Server. Example: 01
Group Name Here you need to enter the name of the Logon Group configured for your SAP system. The entry Group Name is only shown, when you select the Server Type Group. Example: PUBLIC
Message Server   Here you need to enter the full qualified server name of the Message Server. The entry Message Server is only shown, when you select the Server Type Group.Example:
Client Here you enter the three digit client number of your SAP system. Example: 100
LanguageHere you need to enter the language code that you would like to use to establish the connection to the SAP system. Example: EN
Save Language The checkbox Save Language allows you to specify if the entered Language Code is being used always, or if the Preferred Viewing Local (configured in the user profile) is being used. When the option Save Language is activated, the entered Language Code is always used.
AuthenticationHere you can configure which type of Authentication is used. You can choose between Pre-defined, Prompt, and SSO. Pre-defined will require you to enter a user and password, which then will always be used. Prompt will result in a logon dialog for all users when using this OLAP connection and the users will have to enter the credentials manually. SSO will leverage the entered SAP credentials and requires the users to be logged on with their SAP credentials.

Table: OLAP Connection Details

7. Click Connect.
8.You will then be asked to enter your SAP credentials to logon towards the SAP NetWeaver BW system.
9. Click OK.
10. You are presented with the cube browser  showing all InfoArea from the SAP NetWeaver BW system. As we are going to use BEx queries based on the SAP NetWeaver Demo model, we are selecting the SAP NetWeaver Demo model.

Fig: Cube Browser

OLAP Connections

You can configure OLAP Connections to be based on the SAP NetWeaver BW system, on an InfoArea, on an InfoProvider, or on a single BEx query. When creating a workspace the user will always use a BEx query and depending on which level the OLAP Connection has been defined, will see a list of queries, or InfoProvider and queries, or even InfoArea.
For example if the OLAP Connection has been defined on the InfoProvider level, like in our previous steps, the user will see all BEx queries available for this InfoProvider.

OLAP Connections & Authorizations

Often people ask on which level they should define the OLAP Connections, and the answer depends to some degree also what has been defined in SAP NetWeaver BW already.
In case you are using naming conventions to limit access to InfoProvider and BEx queries already in SAP NetWeaver BW, a single OLAP Connection configured with Single Sign On (SSO) might be all that is needed. In case you are not using such naming conventions in SAP NetWeaver BW, you might have to create multiple OLAP Connections and use security settings in your SAP BusinessObjects BI platform to grant or deny access to certain OLAP Connections to your users.

  1. Set the Authentication to the option SSO.
  2. Click Save.
  3. Close the Central Management Console.

We know created an OLAP Connection in the Central Management Console (CMC) and can use this connection in combination with SAP Business Objects Analysis, edition for OLAP. In the next section we will use this newely created OLAP connection and create our very first workspace.

Creating your very first workspace

In this section we will now explore SAP BusinessObjects Analysis, edition for OLAP and create our very first workspace. After we learned about the different areas of SAP BusinessObjects Analysis, edition for OLAP, we will also review how the different elements from a BEX QUERY are being mapped to SAP BusinessObjects Analysis, edition for OLAP.

  1. Open the BI Launchpad via Start > All Programs > SAP BusinessObjects BI Platform 4.0 > SAP BusinessObjects BI Platform > SAP BusinessObjects BI Platform Java BI Launchpad.
  2. Logon with your SAP credentials and the SAP authentication for your SAP NetWeaver BW system.
  3. Select the menu Applications.
  4. Select Analysis, Edition for OLAP. In the next step you are presented with the list of available OLAP Connections.

Fig: OLAP Connections

5. select the connection we created previously pointing to your SAP NetWeaver BW system.
6. Click Next. You are now receiving the list of available BEx queries. You can also use tab Find to search for specific queries

Fig: List of BEx Queries

7. Select the BEx Query you created and click OK

  • The DATA panel provides you with the access to the connections and the available elements of your underlying data source as well as the properties for the used elements.
  • The LAYOUT panel allows you to define the layout of your cross tab by using simple drag and drop navigations and defining the elements in the Rows, Columns, and Background area.
  • The Cross tab area in your worksheet presents the actual data in form of a cross tab or a chart to the end-user.
  • You can have multiple sheets in a single workspace and you can navigate between the sheets by using the navigation below the cross tab.
  • The menu tabs Analyze, Insert, and Display give you access to all the features and functions of SAP BusinessObjects Analysis, edition for OLAP.
  • The menus on the far left give you access to the save and export capabilities.

Sheets and Components

SAP BusinessObjects Analysis, edition for OLAP allows you to have multiple sheets in a single workspace, but you can only have four components (charts, cross tabs) on a single sheet.
Before we are now starting to use SAP BusinessObjects Analysis, edition for OLAP, let’s explore where the information defined in our BEx query, appears in our workspace.

Fig: Data Panel

The Data Panel provides you access to the underlying meta-data from the used BEx query. In the example shown above you can see that:

  • All Key Figures are listed together in a folder called Key Figures.
  • All characteristics are visible in the data panel and each characteristic has a set of elements. For example characteristic Country is shown here with the element Country for the characteristic itself but also the available hierarchies – here Country Hierarchy 1 – are available.
  • Display Attributes for the characteristics are shown below the characteristic itself – here shown for Sales Organization.

One of the not so obvious items is the different display options such as the key, short text, medium text, or long text. The option to switch between these display settings is part of the context menu (right mouse click) of the characteristic when displayed in the crosstab.

Fig: Menu – Display as

After we identified all the necessary meta-data from our BEx query, we are now ready for our first steps in SAP BusinessObjects Analysis, edition for OLAP.
In the next couple of steps we use some of the basic functionality of SAP BusinessObjects Analysis, edition for OLAP. We created a new workspace based on the BEx query we created previously, so our workbook shows:

  • Characteristic Calendar Year and Region in the Rows.
  • All Measures in the Columns.

Fig: Analysis Workspace

1. Select characteristic Calendar Yearin the Rows.
2. Drag and drop Calendar Year to an empty area to remove it from the Rows. You cal also use a right-click and select the menu Remove

Fig: Analysis Workspace Navigation

3. Now select Country in the Data Panel and open the list of available objects

Fig: Characteristic Country

4. Now drag Country on top of Region in the Rows so that it replaces Region

Fig: Exchanging characteristics

5. Select Country in the Rows and use a right-click.
6. Select the menu Display as to switch between the different options of showing the key or text for characteristic Country.
7. Select the option Text.

Fig: Analysis Workspace

8. Select the characteristic Region in the Data Panel.
9. Drag and drop Region to the Rows so that your cross tab displays first the Countries and then the Regions.
In addition to the simple drag and drop navigations you also have the menu options Move to, Move Before, Move After, and Swap with, which allow you to select a characteristic in the Layout Panel and move to the Rows, or Columns, or move before or after another characteristic, or swap it with another characteristic.
In this section we learned the basic navigation steps in SAP Business Objects Analysis, edition for OLAP and where the meta-data from our existing BEx  queries appears. In the next section we will learn the different options to FILTER THE DATA.

Adding or removing characteristics and key figures

From the previous section our workspace now shows a cross tab with characteristic Country and characteristic Region in the Rows and all the available key figures in the Columns. In the next few steps we will learn about the different options of adding or removing characteristics and key figures to the cross tab.

Fig: Analysis Workspace

Adding Characteristics

Adding characteristics to the cross tab or to a chart is possible by using the menus and by a simple drag and drop navigation. We will start with the options in the menus first.

1. In Our existing workspace open the list of available items for characteristic Product.

Fig: Characteristic Product

2. Select the entry Product.
3. On top of the list of available objects you also have a toolbar which allows you to add the selected characteristic to the Rows, Columns, or the Background area.

Fig: Toolbar

4. Click on the button to add characteristic Product to the Rows.

Fig: Analysis Workspace

Our cross tab shows now the key figures broken down by Country, Region, and Product.
5. Click on the  Undo button in the toolbar.
6. Now use the  button to add characteristic Product to the Columns.
The cross tab will show the key figures separated by each Product grouped by Country and Region.

Fig: Analysis Workspace

7. Click on the Undo button in the toolbar.
8. Now use the button to add characteristic Product to the Background Filter area.

Fig: Member Selector

The Member dialog will be shown on the left hand side and you can now define which members of characteristic Product are being used as filter values.
9. Select all members.
10. Click OK.
11. Click on the   Undo button in the toolbar.
So far we have used the buttons in the toolbar to add characteristic Product to the Rows, Columns, or Background area, but you can also use a simple drag and drop navigation.
1. In our existing workspace open the list of available items for characteristic Product.

Fig: Data and Layout Panel

2. Select the entry Product and drag characteristic Product into the Rows area.
You can – while keeping the mouse button pressed – move characteristic Product into the Rows and place it either on top of Country, or between Country and Region, or below Region, or you can replace Country or Region. You will be able to see the differences also in the video at the end of these steps.
3. Place characteristic Product into the Rows so that it replaces characteristic Region.
4. Select characteristic Region in the Data Panel.
5. Drag characteristic Region on top of the members of characteristic Product in the cross tab.

Fig: Analysis Workspace

Now characteristic Region will replace characteristic Product.
6. Select characteristic Product in the Data Panel.
7. Drag characteristic Product into the cross tab so that is being placed as the most inner characteristic, which means your cross tab will display the key figures by Country, Region, and then Product.

Fig: Analysis Workspace

So far we have seen that we can use the buttons in the toolbar of the Data Panel to add characteristics to the cross tab and that we can use a drag and drop navigation to the Layout panel or directly to the cross tab as well. Now let’s take a look how we can remove characteristics.

Removing Characteristics

In this section we will focus on the workflows that allow us to remove characteristics or key figures from the workspace. From our previous section we have a workspace that shows the characteristics Country, Region, and Product in the Rows and all the key figures in the columns.

Fig: Analysis Workspace

Removing characteristics is possible by using a simple drag and drop navigation, and by using the contextmenu in the Layout panel.
1. In our existing workspace select characteristic Product in the Rows of the Layout panel.
2. Use a right-click on characteristic Product to open the context menu.

Fig: Context Menu

3. Use the menu Remove to remove characteristic Product from the cross tab.
4. Now use the  Undo button in the toolbar.
5. Select characteristic Product in the Rows of the Layout panel.
6. Keep the left mouse button pressed and drag characteristic Product to an empty area.

Fig: Data Panel

With a simple drag and drop navigation you removed the characteristic from the cross tab.
7. Now select the first entry for characteristic Country in the cross tab.

Fig: Removing Characteristics

8. Use a right-click and select the menu Remove.

Fig: Filtered Characteristic

You will notice that the characteristic Country is still shown in the cross tab, but that the selected country has been removed. It is important to recognize that the menu Remove in the cross tab itself is acting like a filter. You can also notice that in the Rows, because characteristic Country is shown with a Filter symbol, indicating that there is a filter defined for the characteristic.
9. Now use the  Undo button in the toolbar.
Removing key figures from the cross tab is possible by using the Remove menu and by using the Filter option as part of the context menu.
1. In our existing workspace select the column for key figure Net Value.
2. Use a right-click to open the context menu.
3. Select the menu option Remove.

Fig: Context Menu

Fig: Analysis Workspace

Key figure Net Value is being removed from the cross tab and the filter symbol in the Layout Panel  also indicates that the list of available key figures has been filtered.
4. Select the entry Key Figures in the Columns.
5. Use a right-click to open the context menu.
6. Use the menu Filter by member.

Fig: Filter by Member

7. The Filter by Member dialog is being shown and you can now decide which of the available key figures should be included into the cross tab.

Fig: Filter by Member

8. Select the key figures Net Value, Transport Costs, and Product Costs.
9. Click OK.

Fig: Analysis Workspace

In this section we reviewed the different options to remove characteristics and key figures by using menus and simple navigations. In the next section we will take a look at the options to format the data.


Thank You!


This presentation is aimed at helping users to control the toggling of a LED

by an interrupt using a simple timer
This example was developed using the Keil programing environment for

a nucleo stm32l476 board


This project is only a simple introduction to STM32 for students at phelma, school of engineering in

Physics, Applied Physics, Electronics & Materials Science at Grenoble (France)


JC Toussaint

Full Professor at Phelma



I wanted to share with you a document I received from AC6 directly about using their IDE: System Workbench for STM32: or SW4STM32 as we call it.


Hope you find it useful.


I am also attaching a short Hands-on I did at customers.







When you are doing IAP you will need to have a project for your application code which is located at an address after the user bootlaoder and settable in the code. You also need to relocate the vector table.


This code example does that.


The zip file contains a set of sources files that build the application to be loaded into Flash memory using In-Application Programming (IAP, through USART for example).


To build such application, some special configuration has to be performed:


1. Set the program load address at 0x08004000, using your toolchain linker file
2. Relocate the vector table at address 0x08004000, using the "NVIC_SetVectorTable"


@note Care must be taken when using HAL_Delay(), this function provides accurate delay (in milliseconds)
based on variable incremented in SysTick ISR. This implies that if HAL_Delay() is called from
a peripheral ISR process, then the SysTick interrupt must have higher priority (numerically lower)
than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
To change the SysTick interrupt priority you have to use HAL_NVIC_SetPriority() function.

@note The application need to ensure that the SysTick time base is always set to 1 millisecond
to have correct HAL operation.

Four LEDs are toggled with a timing defined by the Delay function.


Hope it helps.





Make sure first of all that you have a part number ending in P in the STM32L on the Nucleo board: this will ensure that the STM32L supports external SMPS.


On the Nucleo board a SMPS has been populated and the idea is to measure the overall power consumption of the MCU with and without the use of SMPS.


Startting with the STM32CubeL4 Firmware Package V1.7.0, we provide the STM32 Nucleo PWR GUI tool allowing a quick assessment of STM32L4 low power performance.


The STM32 Nucleo Power GUI tool is readily available under Utilities/PC_Software/STM32Nucleo_Power_GUI


It connects to the STM32 Nucleo hardware boards  supported by the firmware package and allows selecting the various low-power modes and benchmarking codes thanks to the available binary files.


To use "STM32 Nucleo Power GUI tool"  : 

    - Connect the STM32 Nucleo board to a PC with a 'USB type A to Micro-B'

      (Nucleo-144) or 'USB type A to Mini-B' (Nucleo-64) cable through USB

      connector CN1 to power the board.

    - Select the wanted binary available under “STM32Nucleo_Power_GUI/Binaries” and reprogram

      (e.g. with STM32 ST-LINK Utility, available for download from the STM32 Nucleo firmware.

      Once done, to ensure all IOs are at their reset levels, unplug then plug

      the board again.

    - Connect an amperemeter to the IDD jumper (JP5 for Nucleo-144, JP6 for Nucleo-64).     

    - Unzip "Nucleo" on your laptop or desktop and launch Qtserial.exe.

    - Obey the instructions appearing on the screen in connecting to the COM port

      associated with the Nucleo board.

    - Pick one low power mode proposed among those by the GUI tool and press


    - Measure the MCU power consumption on the amperemeter.

    - Reset the board before picking up another low power mode. 


Binaries available under " STM32Nucleo_Power_GUI/Binaries " folder are

      - STM32L476RG_NUCLEO.hex for STM32L476RG Nucleo board

      - STM32L496ZG_NUCLEO.hex for STM32L496ZG Nucleo board without external SMPS

      - STM32L496ZG_NUCLEO_extSMPS.hex for STM32L496ZG Nucleo board with external SMPS


The GUI will permit to enter different low power modes and see the difference


Best Regards.



Dear Reader:

I guess In All " UART IO Operation Functions" such as HAL_UART_Transmit(), HAL_UART_Receive(), ...

the second input argument which is (uint8_t *pData) should be modified as (uint16_t *pData) so we would not encounter a problem in a 9_bit communication, otherwise in a 9_bit communication the following lines in those functions may malfunction:

temp = (uint16_t *)pData;

huart -> Instance -> DR = (*temp & (uint16_t)0x01FF);

best regards




I did a training this week and would like to share it with you.


It is perfect for beginners to get started with SW4STM32: first we turn on a LED, then we move to more advanced examples.


You will need to use a STM32L476 Nucleo board.









In our STM32 the VREFINT (Voltage reference) is connected internally to an ADC channel.




I wrote a code to be able to read VREFINT using ADC.


The code reads the data and then convert it in mV unit depending on VREF+.


I ran the code on a Nucleo F767.


I read the following values: 1206 mV which is within spec:




I am attaching my code. It is using STM32Cube_FW_F7_V1.6.0.


To run the code copy and unzip it at:




I used Keil uVision 5 for IDE.





I2C master




I just finished porting a software implementation of I2C master to a STM8S.


It implements the read and write registers functions:


You will find the functions located in BB_I2C.c:


The functions read and write 16 bit data:


Read register function:

BB_I2C_Result BB_I2C_ReadReg (uint8_t regAddress, uint16_t* pValue, uint8_t SlaveAddressshiftedByOne)

Parameters are:

regAddress: 8 bit internal register address where to write

pValue: 16 bit address of the variable where the read will be stored

SlaveAddressshiftedByOne: 8 bit I2C address of the device you want to address over I2C shifted by one bit to the left



The function return a Boolean

BB_I2C_OK: Pass

BB_I2C_ERR: Error



Write register function:

BB_I2C_Result BB_I2C_WriteReg (unsigned char regAddress, uint16_t value, uint8_t SlaveAddressshiftedByOne)


Parameters are:

regAddress: 8 bit internal register address where to write

value: 16 bit value to write

SlaveAddressshiftedByOne: 8 bit I2C address of the device you want to address over I2C shifted by one bit to the left



The function return 1 or 0:

BB_I2C_OK: Pass

BB_I2C_ERR: Error



In your application code you need first to call: BB_I2C_Init();

This function will initialize the IOs.


You will also need to include BB_I2C.h:

#include "BB_i2c.h"


To customize the IOs used you will need to edit: BB_I2C.h

#define BB_I2C_SDA GPIO_PIN_6
#define BB_I2C_SCL GPIO_PIN_7


You can also edit the I2C slave address (address NOT shifted by one bit to the left) just below:

#define SLAVE_ADDRESS 0x28 // I2C address of the STUSB device


I attaching below a project example:

The zip file contains the project files and user files.

It needs to be unzip in the STM8S/A Standard Peripheral Library (I used version 2.2.0) at the following location:



I used STVD and Cosmic so the Project is located at:



I used the project "stm8s103"


For hardware I used a STM8S-Discovery board.


Here is my set-up:


STM8S I2C Master Software


In my set-up PD6 is I2C SDA and PD7 is I2C SCL.


I connected those IOs to SDA and SCL of the Slave device (a STUSB device).


I connected also the ground.


You need to make sure that the pull-ups are installed on SCL and SDA.


Here is the test I did:
 BB_I2C_WriteReg (0x81, 0xAA55, 0x50);
BB_I2C_ReadReg (0x81, &Register_readvalue_2, 0x50);



I wrote value 0xAA55 at register address 0x81 of the STUSB chip which I2C address is 0x50.


I then wrote it back and checked that the return value is indeed 0xAA55 and it was the case.


Please see my code attached.







Recently I had to write a sample code for a customer in order to turn on the read out protection of the flash to a level 1.


I did it for a STM32L15x Nucleo or Discovery board but it can be easily ported to another family of STM32.


The code is simple: if the level of readout protection is not set to 1, it will set it to level 1.


If the STM32 RDP is already at level 1 it will do nothing.


I have attached my code zipped.


Unzip it at:




Use the IDE of your choice to build and load the code : IAR, Keil or SW4STM32.

Then once code is built and loaded.


Reset the board so that code will execute.


Now try to use ST-LINK Utility to access the flash: the tool will tell you that the read operation cannot be made because the readout protection has been activated.







Here is the important part of the code to execute:


  /* Unlock the Flash to enable the flash control register access *************/

  /* Unlock the Options Bytes *************************************************/

  /* Get pages write protection status ****************************************/

  /* Check if readoutprtection is enabled ***********************/
  if((OptionsBytesStruct.RDPLevel) == OB_RDP_LEVEL_0)
    OptionsBytesStruct.OptionType= OPTIONBYTE_RDP;
    OptionsBytesStruct.RDPLevel   = OB_RDP_LEVEL_1;
    if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)
      /* Error occurred while options bytes programming. **********************/
      while (1)


    /* Generate System Reset to load the new option byte values ***************/

  /* Lock the Options Bytes *************************************************/

One past challenge was to drive 3 SPI slaves sensors in parallel.


- A global signal to tell them when to "start measuring"

- Each slave notifies by EXTI interrupt when their data is ready to flow out

- Data was significant quantity (few kilobytes, not necessarily the same dats size for each slave)

- Sometime the strategy required for all sensors to wait for each other during the process.

- The sequence to launch a measurement and read out all data has to be nearly transparent to the user code


==> Use code would tell which pseudo sequence to run, launch it, do other things and either wait for a callback when complete, or read a complete flag updated by the interrupt based sequencer.


After some thinking and several itterations came up the concept of a pseudo state machine:


A typical MCU core has a program pointer, read the opcode, execute it and goes to the next one. Usually the core is running based on its internal clock.


The concept was to mimic an MCU core except that it takes one interrupt event to go to the next op-code and execute it.

The state machine is then interrupt based.


This implementation can be found in the attached source file.

Op codes can be created on demand, changed for each application.

Only one interrupt must be armed to trigger the next op code execution.

All interrupts must be same level to keep the system easy to manage and maintain.

To kickstart a sequencer, it must be called from the user code and mimic an interrupt = disable interrupts before calling the sequencer for the first time.


FTM is a composite state machines built from the 3 other individual state machines FT1, FT2 and FT3.


This was an interesting project as it emulates a hidden under the hood complex peripheral running in the background without RTOS, touches parallelism simple programming and scalability of the solution looked elegant and interesting.

S. Marsanne

Display Interface Overview

Posted by S. Marsanne Moderator Dec 25, 2016

People are mostly visual and over the years Microcontrollers were having ways to optically interact with users.

Here is a quick summary of the various display interfaces and technologies supported by the STM32 family.


LEDs: This is the simplest way for a microcontroller (MCU) to optically interact. Each LED will consume 5mA for decent brightness, however, remember that 4 LEDS will consume as much as an STM32L4 at 80MHz... LEDs can be smartly connected to a TIMER.CC channel to be brightness modulated by PWM (Pulse Width Modulation).


LCD Displays: Some are backlighted, some are reflective (as you calculator), some are transflective (both).

Some are Black and White, some have Greyscale and some have Colors (which number depends on the driver chipset)

Some will have a capacitive touch screen overlaid (On Cell) with typically I2C interface plus interrupt pin, some will have the capacitive layer within the display plane and are called In Cell (In LCD Pixel Cell).


A simple segmented LCD Display can be directly driven by some STM32.

Dot matrix LCD Display come with a display controller with specific interfaces to communicate with MCU.


Here are the typical interfaces:


I2C LCD Display : Quite rare however handy for debug because you need only 2 GPIOs to generate an I2C bus.

If the LCD is character base, it won't require lots of Flash/RAM resources from the STM32.


SPI LCD Display: This enables higher throughput which could be dot matrix display type

NHD-C0216CZ-FSW-FBW-3V3 Newhaven Display Intl | Optoelectronics | DigiKey


Then for higher throughput of pixel update, there is the typically 8 bit parallel interface called 8080/6800 type LCD Display


NHD-320240WX-CoTFH-V#I040 (NO Mounting tabs) NHD?320240WX?C0TFH?V#I040 [94.7mm x 71.7mm] - $59.95 : Newhaven Display Int… 


When the display resolution increases and the color depth is also increasing to become close to smart phone, the quantity of information to throughput grows significantly, especially if video animation is a demand.


Historically, you'll have a pixel interface:


16 Million colors = 256 Red x 256 Green x 256 Blue = 24 bit for one pixel = 24 GPIO for the color information

This is the 24 bit parallel interface. Add a pixel clock and some sync signals (DE=Data Enable) and that's all what is needed to drive such type of display.

Need to use less pins?

Exist 16 bit mode color palette would be reduced to 5:6:5 (32 Red, 64 Green, 32 Blue Levels for 65k Colors)

If the resolution is VGA = 640x480 pixels refreshed at 50 Hz, the data throughput is getting tough.

For long video cables a specific technology was introduced named LVDS (Low Voltage Differential Signaling)

With this, multiple CMOS lines are replaced by a PLL used to serialize bits in a differential pair which can pass more bitrate than the CMOS equivalent. In display usually 7 digital signals are stuffed in one differential pair.

TTL to LVDS, LVDS to TTL conversion chipsets are available to stretch the length of the video cable whenever needed.

This was typically used in laptop between the motherboard and the display, using a hidden flex ribbon.


Detail: HSYNC and VSYNC are typically no longer needed, DE (Display Enable) toggles at pixel frequency and tells if the pixel is valid or not (blanking pixels or lines). In the display the LVDS receiver is called TCON (Timing Controller). 


For short distance when power consumption and pincount is critical, a newer standard was created : DSI (Display Serial Interface) from MIPI a standardization organisation aiming a smartphone design. This interface enables even higher data rate to reduce the number of differential pairs needed. This DSI interface is also available on some of the latest STM32 such as STM32F469.

Display Technologies:


LCD : Light polarisation modulated by liquid crystals. Mature technology

OLED : Light is emitted by each pixel (array of LEDs). Trying to replace LCD technology. Better contrast.

e-Paper : Bistable Displays which only require energy when the display content changes. Slow and Low power


Hope this help.

More details will be added as time goes.