BLE Embedded MCU's IoT STM32 MCU's STM32WB55 Tech

Introduction to STM32WB55

Table of Contents About STMicroelectronics STMicroelectronics is a leading provider of semiconductor solutions that are seamlessly integrated into billions of electronic devices used by people worldwide on a daily basis. The semiconductor company builds products, solutions, and ecosystems that enable smarter mobility, more efficient power and energy management, and the wide-scale deployment of the Internet of Things and connectivity technologies. To know more about STMicroelectronics refer to its website: www.st.com. Going back in history, ST was formed in 1987 by the merger of two government-owned semiconductor companies: Italian SGS Microelettronica (where SGS stands for Società Generale Semiconduttori, “Semiconductors’ General Company”), and French Thomson Semiconductors, the semiconductor arm of Thomson. In this blog, we are going to start with ST IoT-based Nucleo Board STm32WB55. What is STM32WB Series all about? The STM32WB55xx and STM32WB35xx are advanced multiprotocol wireless devices that boast ultra-low-power consumption. These devices are equipped with a powerful and efficient radio that is compliant with the Bluetooth® Low Energy SIG specification 5 and IEEE 802.15.4-2011 (Zigbee). Additionally, they feature a dedicated Arm® Cortex®-M0+ processor that handles all real-time low-layer operations. These cutting-edge devices are perfect for a wide range of applications that require reliable and efficient wireless communication. Whether you’re working on a smart home project, a wearable device, or an industrial automation system, the STM32WB55xx and STM32WB35xx are the ideal choices. With their advanced features and capabilities, these devices are sure to revolutionize the way we think about wireless communication. So why wait? Start exploring the possibilities today and discover what the STM32WB55xx and STM32WB35xx can do for you! The devices have been meticulously crafted to operate on minimal power and are built around the high-performance Arm® Cortex®-M4 32-bit RISC core, which can operate at a frequency of up to 64 MHz. This core boasts a Floating-point unit (FPU) single precision that supports all Arm® single-precision data-processing instructions and data types. Additionally, it is equipped with a full set of DSP instructions and a memory protection unit (MPU) that enhances application security. These devices have been designed with the utmost care and attention to detail, ensuring that they are not only efficient but also highly effective. The Arm® Cortex®-M4 32-bit RISC core is a powerful tool that enables these devices to perform at an exceptional level, while the FPU single precision and DSP instructions provide unparalleled accuracy and precision. Furthermore, the memory protection unit (MPU) ensures that your applications are secure and protected from any potential threats. Enhanced inter-processor communication is provided by the IPCC with six bidirectional channels. The HSEM provides hardware semaphores used to share common resources between the two processors. The devices embed high-speed memories (up to 1 Mbyte of flash memory for STM32WB55xx, up to 512 Kbytes for STM32WB35xx, up to 256 Kbytes of SRAM for STM32WB55xx, 96 Kbytes for STM32WB35xx), a Quad-SPI flash memory interface (available on all packages) and an extensive range of enhanced I/Os and peripherals.  About STM32WB55 Architecture Memories Security and Safety True random number generator (RNG) RF Subsystem Low Power Modes Clocks and Startup General Purpose Input Output(GPIOs) Direct Memory Access (DMA) Interrupts and Events Analog to Digital Convertor (ADC) Comparators (COMP) Touch Sensing Controller Liquid crystal display controller (LCD) Timers and watchdogs Real-time clock (RTC) and backup registers Inter Integrated Circuit (I2C) Universal Synchronous/Asynchronous Receiver Transmitter (USART) Serial Peripheral Interface(SPI) Serial audio interfaces (SAI) Quad-SPI memory interface (QUADSPI) Architecture Architecture STM32WB55 Architecture The host application is housed on an Arm® Cortex®-M4 CPU (named CPU1) that connects with a generic microcontroller subsystem. The RF subsystem is made up of a specialized Arm® Cortex®-M0+ microprocessor (named CPU2), Bluetooth Low Energy and 802.15.4 digital MAC blocks, an RF analog front end, and proprietary peripherals. All Bluetooth Low Energy and 802.15.4 low-layer stack functions are handled by the RF subsystem, which limits communication with the CPU1 to high-level exchanges. Some functions are shared between the RF subsystem CPU (CPU2) and the Host CPU (CPU1): Flash memories  SRAM1, SRAM2a, and SRAM2b (SRAM2a can be retained in Standby mode)  Security peripherals (RNG, AES1, PKA)  Clock RCC Power control (PWR) Memories Memories STM32WB55 Memories 2.1.  Adaptive real-time memory accelerator (ART Accelerator) The ART Accelerator is a memory accelerator optimized for STM32 industry-standard Arm® Cortex®-M4 processors. It balances the inherent performance advantage of the Arm® Cortex®-M4 over flash memory technologies. To release the processor near 80 DMIPS performance at 64 MHz, the accelerator implements an instruction prefetch queue and branch cache, which increases program execution speed from the 64-bit flash memory. Based on CoreMark benchmark, the performance achieved thanks to the ART accelerator is equivalent to 0 wait state program execution from flash memory at a CPU frequency up to 64 MHz. 2.2.  Memory protection unit In order to prevent one task from unintentionally corrupting the memory or resources used by any other active task, the memory protection unit (MPU) is used to manage the CPU1’s accesses to memory. This memory area is organized into up to eight protected areas. The MPU is especially helpful for applications where some critical or certified code must be protected against the misbehavior of other tasks. It is usually managed by an RTOS (real-time operating system). 2.3.  Embedded flash memory The STM32WB55xx and STM32WB35xx devices feature, respectively, up to 1 Mbyte and 512 Kbytes of embedded flash memory available for storing programs and data, as well as some customer keys. 2.4.  Embedded SRAM The STM32WB55xx devices feature up to 256 Kbytes of embedded SRAM, split in three blocks: SRAM1: up to 192 Kbytes mapped at address 0x2000 0000  SRAM2a: 32 Kbytes located at address 0x2003 0000 also mirrored at 0x1000 0000, with hardware parity check (this SRAM can be retained in Standby mode)  SRAM2b: 32 Kbytes located at address 0x2003 8000 (contiguous with SRAM2a) and mirrored at 0x1000 8000 with hardware parity check. Security and Safety Security and Safety The STM32WB55xx  contain many security blocks both for the Bluetooth Low Energy or IEEE 802.15.4 and the Host application. It includes:  Customer storage of the Bluetooth Low Energy and

Embedded MCU's Kinetic Sensor/Modules Sensor/Module Interfacing Sensors and Modules SPI Modules STM32 MCU's STM32F1

Implementation of MPU6050 with STM32

In the last blog I talked about the basics of MPU6050, this time let’s see how to interface it with the STM32 based controller and get the values of accelerometer and Gyro sensor. But before  starting first, let’s see the I2C block and the STM32 I2C block to get some idea of the basic structure of the I2C protocol. Figure 1: I2C Hardware Circuit The above circuit diagram shows the hardware connection of the I2C protocol in open drain configuration. The external pull up resistors are being used to make the circuit work efficiently. These days the controllers come with the internal pull up resistors so while writing the code for the same these resistors can be pulled up in the configuration. Before proceeding further lets understand certain terms like pull up, pull down, open drain etc. While using an I/O pin, in the digital domain it has values as LOGIC 1 (HIGH), LOGIC 0 (LOW) and Z-STATE (HIGH IMPEDANCE or FLOATING or TRI-STATE). The purpose of pull up and pull down is to maintain these states of the pin while working. PULL-UP means that the pin is internally connected to the power supply via a resistor and is read as LOGIC 1. PULL-DOWN means that the pin is internally connected to the ground via a resistor and is read as LOGIC 0. In between the two in the configuration, when the pin is neither pull-up nor pull-down and the analog value cannot be represented in the logic value, this state is termed as Z-STATE where there is a floating value.    Figure 2: Pull-up and Pull-Down Configuration Now let’s understand the Push-Pull and Open Drain configurations. PUSH-PULL Configuration: This configuration consist of a pair of complementary transistors which works as: For LOGIC 0, the transistor connected to the ground is turned on to sink an electric current from the external circuit. For LOGIC 1, the transistor connected to the power supply is turned on, and it provides an  electric current to the external circuit connected to the output pin. The slave address of the MPU-6050 id 0b110100x, a 7-bit long. Here the LSB bit i.e.x in the 7-bit long address is determined by the logic level at AD0 pin.If x=0 i.e., pin AD0 is Logic LOW otherwise Logic HIGH. Figure 3: Push-Pull Configuration   Figure 4: The Logic 0 and 1 for Push-Pull Configuration   OPEN-DRAIN Configuration: This configuration consist of a single transistors which works as: For LOGIC 0, the transistor connected to the ground is turned on to sink an electric current from the external circuit. For LOGIC 1, it cannot supply any electric current to the external load because the output pin is floating, connected to neither the power supply nor the ground. Hence the Open-Drain has two states LOGIC 0 (LOW) and LOGIC 1 (Z-STATE). This configuration use external pull up resistor. Figure 5: Open-Drain Configuration   Figure 6: The Logic 0 and 1 for Open-Drain Configuration I2C Let’s analyze the functional block diagram of the STM32. As shown in the figure, the I2C protocol consists of SDA and SCL lines along with an additional pin SMBA used in SMB protocol known as System Management Bus. The figure shows that there is a single Data Register along with the single Shift Register as the protocol is half -duplex. The address block is also there and a comparator to compare the addresses. The control logic consists of Control Register (CR 1 and CR2) and Status Registers (SR1 and SR2)  along with the Clock Control Register for generating the clock for the communication. Figure 7: I2C Block Diagram I2C Implementation Of Figure 9: Pin Connections Above is the pin connection of the MPU6050 with the STM32F411CE. Now set up the stm32 environment as follows: Step 1 Step 2 Step 1 Set up the RCC ad the SYS in the STM32Cube IDE as shown: Step 2 Now enable the I2C1 in the standard mode. Now starting with the code create a mpu6050.h file in the Inc folder and mpu6050.c file in Scr folder. We are all done. Let’s start with the code. In total there are around 80 registers in the IC but during the code all the registers are not required there are certain sets of registers which we are going to use which we will be defining in the header file mpu6050.h. These registers are: Name of the Register Address of the Register (Hex) Function REG_MPU6050_ADDR 0xD0 It is the device address for the MPU6050 module REG_SMPLRT_DIV 0x19 This register specifies the divider from the gyroscope output rate used to generate the Sample Rate for the MPU-6050. REG_GYRO_CONFIG 0x1B This register is used to trigger gyroscope self-test and configure the gyroscopes’ full scale range. REG_ACCEL_CONFIG 0x1C This register is used to trigger the accelerometer self test and configure the accelerometer full scale range. This register also configures the Digital High Pass Filter (DHPF). REG_ACCEL_XOUT_H 0x3B These registers store the most recent accelerometer measurements. REG_TEMP_OUT_H 0x41 These registers store the most recent temperature sensor measurement. REG_GYRO_XOUT_H 0x43 These registers store the most recent gyroscope measurements. REG_PWR_MGMT_1 0x6B This register allows the user to configure the power mode and clock source. It also provides a bit for resetting the entire device, and a bit for disabling the temperature sensor. REG_WHO_AM_I 0x75 This register is used to verify the identity of the device. The contents of WHO_AM_I are the upper 6 bits of the MPU-60X0’s 7-bit I2C address. The least significant bit of the MPU-60X0’s I2C address is determined by the value of the AD0 pin. The value of the AD0 pin is not reflected in this register. Apart from these registers we have two structures and the function definitions that we are using in the main file. Lets now jump directly towards the mpu6050.c file and see how things are working. In this phase, keep in mind the 3 things. Initializing the mpu6050. Read the RAW values of accelerometer and gyroscope Convert the RAR values to ‘g’ and ‘dps’ for Accelerometer

Embedded MCU's Getting Started and Peripheral Coding STM32 MCU's STM32F1

PWM on STM32F103

What is PWM? PWM or Pulse Width Modulation, is a type of digital electrical signal which is periodic in nature, with a rectangular waveform. There are certain terms associated with PWM which we need to understand before we move ahead. Here’s a graphical representation of a PWM signal- ·       ‘Period’ = Tp , is the time it takes to repeat the same waveform ·       ‘Duty cycle’ is the time for which the signal is a logic 1 by the total time period. Ton is the time for which the pulse is high Hence, Duty cycle % = (Ton/ Tp) X 100 ·       ‘Frequency’ = F is the number of times the waveform repeats in a second. So, F = 1/Tp. Applications of PWM signals PWM signals have an extremely wide range of applications, here are a few of them- ·       Variable voltage generator– if you vary the duty cycle of a PWM signal and apply it to certain electrical components, the components act as if they are receiving analog signals. This is because the response time of the components is finite. So, components like LEDs, buzzers, brushed DC motors etc. can be controlled by PWM signals. Meaning, you could control speed of a motor, brightness of an LED or amplitude of a buzzer and so on. The voltage that they receive has a linear relationship with the duty cycle. So, if logic 1 is 5 Volts 0% duty cycle – 0V 25% duty cycle – 1.25 V 50% duty cycle – 2.5 V 75% duty cycle – 3.75V 100% duty cycle – 5V ·       As a control signal – Some electrical devices/components analyze PWM signals that they are receiving to give a corresponding output. So, changes in the duty cycle are reflected in the output. These include Servo motors, electronic speed controllers (ESCs) and many more. Here, the devices respond only to specific PWM duty cycles and frequencies If you take the example of servo motors, they can only be operated at 50Hz signal with a duty cycle of 2.5 % to 12% . Anything beyond that doesn’t result in the movement of the servo. (The frequency and duty cycles vary from among different servos, this is a very common value which most 180-degree servos respond to) Similarly, ESCs respond to a PWM signal with ON time of 1ms for minimum throttle and 2ms for maximum throttle with PWM frequency of 50 Hz. Some devices such as HCSR04 ultrasonic sensors give an output as a PWM signal in which the pulse width corresponds to the time it took for the ultrasonic wave to be received. How is PWM signal Generated on STM32?? Timer peripheral STM32 blue pill has 15 pins which can generate a PWM signal, with other models having even more pins for PWM generation. In this section, we will try to understand how PWM signals are generated by STM32 Every microcontroller has a built-in circuit which can measure the passing of time. These are called Timers. What timers essentially do is count up to a certain number and upon reaching that number, they change the value of a certain register to indicate that the timer has counted up to that number. Now, the time it takes to increment this count by 1 is determined by the timer’s clock frequency. So, if the frequency of a timer is 1KHz, its time period will be 1 Millisecond. Hence, if we count up to 10, we have measured the passing of 10 Milliseconds. This is how, by simply incrementing a number, timers can measure the time that has passed since the timer began counting. (This is how the HAL_Delay() function generates delays) The maximum count a timer can make is determined by its register size. So, an 8 bit timer can count up to 28 = 256, 10-bit timer –210 = 1024 16-bit timer –216 = 65536 32-bit timer –232 = 4294967296 So, a 1 bit increase in timer size equals to double the count Timers are extremely necessary for the functioning of a microcontroller as a lot of events in programs are time based, which you may not even realize. Timer Peripheral modes and features Coming to STM32 Blue pill, it has 4 timers of 16-bit size. To perform these functions, they need to be in specific modes. Here are all the modes in which timers can operate in STM32- 1.    Input capture mode– In this mode, a pin on the board is set as input on which a PWM signal is sent by some device and we measure the frequency and duty cycle of that signal. This can be used to interface with devices such as HCSR04 ultrasonic sensors, which send a PWM signal as input to the microcontroller, where different parameters of PWM signals can be used to determine the distance which the sensor is trying to measure. 2.    Output compare mode– In this mode, the timer is used as a counter and the count is compared to a register which contains a pre-programmed value, when they are equal, a software interrupt is generated and using this, a given pin is switched high or low. This mode comes in very handy when you are making a project which requires you to use multiple peripherals and at the same time generate a rectangular waveform of a given frequency and duty cycle, as it is interrupt based. 3.    One pulse mode– In this mode, a pulse can be generated based upon a trigger from an input pin on the board , the pulse generation takes place after a certain delay from when the input trigger pulse was detected. This can be considered as a combination of mode 1&2 (IC &OC) 4.    PWM generation mode– In this mode, we can generate a PWM signal on a given pin by fixing a frequency and a duty cycle. This is the mode we will be using to generate PWM signals through the main loop. The difference of this mode to mode 2 (Output compare

Embedded MCU's Getting Started and Peripheral Coding STM32 MCU's STM32F1

STM32 Overview

What is STM32 ? STM32 is a family of 32-bit Microcontrollers and development boards manufactured by ST Microelectronics which offer very high performance for a relatively low price. All STM32 microcontrollers are based on ARM Cortex-M processor which make them much better in terms of computing power than most of the common microcontrollers/microcontroller development boards which are available in the market. These microcontrollers also have been provided with software support by ST for developers for free. If you have experience with microcontrollers like Arduino, this is a great step forward in understanding microcontrollers in depth. The STM32 framework allows you to control all peripherals and allows you to tweak them as per your wish, whereas in Arduino IDE, when you program in C++, it comes with in-built functions and libraries which don’t allow you to understand the backend working behind everything. This is very crucial, as it allows you to use the microcontroller to its full potential. STM32 FAMILY The STM32 family of microcontrollers is vast and expansive, offering a variety of options for the consumer to choose from. The family of microcontrollers is broadly classified into 4 categories- High performance ST offers a series of microcontrollers which have the fastest code execution time, high speed data transfer and relatively higher flash memory. Along with this, the feature the most advance peripherals that ST offers. This makes these controllers very useful for real-time applications such as running an RTOS. STM32H7x The H7 series controllers are based on the ARM Cortex M7 offering very high speeds of upto 550Mhz. The microcontroller series comes in two variants, single core and dual core. Dual core H7 series controllers come with an ARM Cortex M4 core as well as an ARM Cortex M7 core which allows for processing work distribution, very useful for applications requiring many peripherals where response time is critical. The dual Core variants also come with an inbuilt SMPS as well. The single core series comes with an ARM Cortex M7 core with clock speed between 220-550Mhz, depending upon the variant. STM32F7x The F7 series controllers are based on the ARM Cortex M7, Thanks to an L1 (level 1) cache, the series delivers the maximum possible theoretical performance of the Cortex-M7 core. Cache memory temporarily stores instructions frequently accessed by the processor STM32F4x – The F4 series is based on the ARM Cortex M4. These controllers have less processing power then H7 and F7 series but still come with advanced peripherals and high flash memory. A very useful line of microcontrollers which offer a wide variety of features and come at a relatively lower cost than that of an F7/H7 controllers. The F4 series is broadly divided into 3 segments- 1.F4 Advance line- Offers up to 180Mhz of clock speed and a maximum of 2 Mb of dual bank flash memory, with advanced peripherals, consisting of communication buses such as QSPI. 2.F4 foundation line- Offer lower flash memory (between 512Kb-1Mb) , with few controllers offering advance peripherals and features such as camera interface and Ethernet MAC. 3.F4 Access line- This line of F4 controllers consists of entry level controller which can be termed ‘High Performance’. These controllers come with lower clock speeds, lower RAM but feature very good power efficiency, while also not compromising on peripherals. Wireless The main focus of the STM32Wx microcontroller family is wireless connectivity. They cover sub-GHz as well as 2.4Ghz frequency range operation The STM32 wireless MCUs are further divided into 2 categories– STM32WB These MCUs have a dual core processor unit, Cortex M4 & Cortex M0+, which allows for processing distribution, making it a great candidate for real-time processing and execution. The MCU series is based on STM32L4 architecture, which offers dynamic voltage scaling, reducing the power consumption of the device. They also support BLE 5.3, Open Thread and Zigbee protocols, making them a great choice for IOT applications, providing a lot of functionality onboard the chip itself. STM32WL These MCUs also come with a dual core processor unit like the STM32WB series, and some variants also come with a single ARM Cortex M4 as their processing unit. The key highlight of this series of microcontrollers is that not only do they work as a general purpose microcontroller, but also come with an integrated sub GHz radio supporting LoRa WAN which makes it a great choice for smart home applications, utilities, logistics, Industrial IOT etc.   Ultra-Low Power – STM32 ultra-low-power microcontrollers offer designers of energy-efficient embedded systems and applications a balance between performance, power, security and cost effectiveness. The portfolio includes the STM8L (8-bit proprietary core), the STM32L4 (Arm® Cortex®-M4), the STM32L0 (Arm® Cortex®-M0+) and the STM32L1 (Arm® Cortex®-M3). The STM32L5 MCU (Arm® Cortex®-M33) with its enhancedsecurity features is the latest addition to this rich portfolio. The new STM32U5 series combines the latest and most efficient Arm Cortex-M33 core with an innovative 40 nm platform that reduces energy consumption to the bone, while increasing performance. The series also adds the state-of-the-art features which are required in today’s applications,including advanced cyber security with hardware-based protection, and graphics accelerators for rich graphical user interfaces. The STM32L5 series enhanced security features leverage Arm® Cortex®-M33 and its TrustZone® for Armv8-M. Thanks to this new core and a new ST ART Accelerator™ (also supporting external memory), the STM32L5 reaches an 443 CoreMark. The STM32L4 series offers the excellence of ST’s ultra-low power platform with an additional performance dimension by providing 100 DMIPS with DSP instructions and Floating-Point Unit (FPU), more memory (up to 1 Mbyte of Flash memory) and innovative features. The STM32L4+ series extends STM32L4 technology by offering higher performance (120 MHz/409 CoreMark executing from internal Flash memory), larger embedded memories (up to 2 Mbytes of Flash memory and 640 Kbytes of SRAM), and rendering advanced graphics without compromising ultra-low-power consumption. The STM32L0 series offers a genuine energy-saving solution for entry-level applications. Available in tiny packages down to 14 pins and with a wide range of Flash memory densities from 8 to 192 Kbytes, the STM32L0 features ultra-low power consumption in a competitive portfolio. Mainstream– The mainstream microcontrollers are more general-purpose boards

DIY Projects Embedded MCU's STM32 MCU's STM32F1

STM32_IoT_Metering_Eval_Board

Hola Amigos!! Welcome you all to Gettobyte platform. I am firmware developer and when I am learning firmware development by interfacing number of sensors and modules that has to be connected with MCU. It becomes headache when it comes to making connections of all sensors, using jumper wires on breadboard to interface all modules which are required. Thus, development this board which has almost all peripherals of STM32 MCU connected to one or other sensor to make different kind of Firmware’s (via interrupts, DMA or pooling, RTOSes frameworks, Bare-metal or HAL Based and etc.). In short, this board is best for people who wants to learn firmware development and understand all peripherals of the MCU. What is GB_STM32_EVAL_BOARDV_1? GB_STM32_EVAL_BOARDV_1 is a Custom Eval Board which is designed based on the SMART Energy Metering application, which has several on-board sensors and modules concentric to metering applications. GB_STM32_EVAL_BOARDV_1 is also a Custom Eval Board based on STM32F103 MCU, which is designed to get hands on all the basic peripherals of STM32 MCU and learn different frameworks of Firmware Development like RTOS, STM32HAL and Bare Metal Codes. Features of GB_STM32_EVAL_BOARDV_1? The board is based on SMART Energy Metering application, which has a number of on-board sensors and modules concentric to metering applications. The board has following onboard external components directly connected to STM32MCU via its peripherals. AC energy metering IC: HLW8012(Timer Input Capture peripheral): AC energy metering IC with 2.5kV galvanic isolation of signal and power fascinated by onboard isolated switch mode DC-DC converter and optocouplers for isolation of signal Temperature sensor module: DHT11(Timer peripheral) DC energy metering IC: INA219(I2C peripheral) OLED graphical Screen: SSD1306(I2C peripheral) Wifi Transceiver module: ESP8266(UART peripheral) Industrial Communication Protocol Transceiver: RS485( UART peripheral) RF transceiver module: NRF24L01(SPI peripheral) External Flash Memory IC: W25Q32(SPI peripheral) In addition to the above peripherals the board  has LEDS & Pushbuttons, to play with GPIO peripheral.  10k Ohm potentiometer to get hands on ADC peripheral of STM32 MCU’s. The board has breakout pins headed out of all the pins of MCU, for connecting another sensor. This board has 0 ohm resistors which act as jumpers. These can be useful while debugging the PCB and also to utilize the pins of the MCU that have been occupied by onboard peripherals. The board also has Female-header pins exposed out with each Onboard sensor/module, for connecting the Logic Analyzer to test and debug the working of sensor. Module connected to those pins. The board can measure AC Ratings upto, The board can measure DC Ratings upto It has an on-board data logging feature for 128MB of data, that is approximately 60 days of readings. Debugger The board can be programmed and debugged via STLINKV2 debugger externally. The board has SWD and SWO debugger pins both headed out via on board Header pins, P1 which can be connected to external debugger STLINKV2, as shown below.  Power Supply The board has number of On-board power supply options. It can be powered by DC adaptor of 6V-40V DC. It can be powered directly via STLINKV2 also. It can be programmed via UART-FTDO connector too How to get started with the Board? To get started with the board is quite simple, simply connect the STLINKV2 debugger via its Debugger pins. You can now open the STM32CubeIDE and simply create a new project by selecting MCU as STM32F103C8.   That’s all, just configure the project according to your wish. Now you can program the board according to your wish using different frameworks of Firmware as follows: Using Bare Metal Coding, by making device drivers of the peripherals  in register level and then using that for Application development. This way is recommended for beginners who want to learn Embedded Firmware Development from scratch. Using STM32 HAL, by configuring the firmware of the board via STM32CubeMX. And directly focusing on the Smart Metering Application project development. This way, is recommended for those who wants to do R&D and prototyping for Smart Metering Application, by building different kind of Applications on the board Using RTOS, for building of complex applications. The board houses a number of Input/Output sensors and modules. So it is idle to learn RTOSes like FreeRTOS,Mbed RTOS and etc.  You can program it via STM32CubeMX, configure the project according Use Cases of Board Custom Evaluation board on STM32 MCU For accelerating prototyping and development time.Board has on board Metering sensors, Display Screen, Wi-Fi module, RF module, external flash memory, Temperature Sensor, ADC module and RS485 port. So that Development team and engineers can test their Firmware’s directly on EVAL boards for different scenarios and cases, without going on to hustle to mimic the hardware on breadboard and Jumper Wires during POC. Board can also be used as DIY KIT, by hobbyists, students and makers to learn STM32 MCU.Eval board has different sensors and modules interfaced to STM32 MCU touching all peripherals of the MCU. Don’t need to involve in the hustle of interfacing every sensor and module via jumper wires and breadboard. Use of jumper wires and breadboard, makes the circuit too messy and ugly to work on. Thus developed this EVAL board which has quite famous sensors and modules interfaced to STM32 MCU on PCB, to make the different application firmware on different No RTOS or RTOS frameworks. Board is concentric to Metering Industry. In Depth Overview AC Energy metering IC HLW8012: Connected to MCU via TIMER INPUT CAPTURE. HLW8012 has 3 pins: SEL, CF1 and CF. Which are connected as shown below. It has to be powered externally via 5V DC supply. Also, it is isolated from power supply of the board, as this part of circuit will be having high Electrical voltage. Also, there are test point P16, for debugging and testing the signals of HLW8012 via logic Analyzer or Oscilloscope. CF1: PB5(T2C2) CF: PB6(T4C1) SEL: PB7(GPIO) DC Energy metering IC INA219: Connected to MCU via I2C1 of MCU. SCL: PB8 SDA: PB9 W25Q128JV SPI flash memory: Connected to MCU via SPI1. CS:PA4 MISO(DO):PA6 MOSI(DI):PA7 SCK: PA5 NRF24L01 RF Transceiver

Embedded MCU's Getting Started and Peripheral Coding STM32 MCU's STM32F1

STM32F103 & ADC: Single Channel Conversion

In the last post, we have gotten to know about the features of ADC Peripheral that we have in STM32 MCU. Now in this blog with the series of bare Metal Programming for Blue Pill, we will understand different register bytes and bits of ADC Peripheral to be used for using it in different features, configurations, and modes as we get to know about in the Previous Post. In this blog, we will be going through how to use  ADC Peripheral for converting a Single Channel of ADC (only one ADC pin) and see its bare metal code. Single  Channel Conversion  Mode: Only one ADC pin is used, this mode is like when we have say connected only one analog sensor to one of the ADC pins of MCU  like the Potentiometer is connected at PA0 pin. ADC Registers In depth for: Let\’s get into an in-depth understanding of which registers and their bits are used for configuring the ADC peripheral of Blue Pill in Single Channel Configuration. We will focus on bits and will give an explanation of why those bits are used for the 1.   ADC_SR(ADC status Register) –>This register tells the status of ADC channel  Conversion, as it name says. STM32F103 ADC Status Register: 11.12.1 Bit 1[EOC ]: This bit is set by hardware when a single channel of any group (Regular or Injected) is converted successfully. So this bit is used for monitoring when the ADC conversion is completed by using it inside the while loop if interrupts are disabled. 0: ADC Channel Conversion is not completed 1: ADC Channel Conversion is completed When hardware set this bit, we can clear this bit from the firmware end by setting the bit to 0 or by reading ADC_DR(ADC Data Register) Bit 4[STRT]: This bit is set by hardware when regular channel conversion has begun. So when we start the Regular Channel Conversion, we will use this bit inside the while loop to check that whether Regular Channel conversion has started or not. 0: No regular Channel Conversion has started 1: Regular Channel Conversion has started When hardware sets this bit, we can clear this bit from the firmware end by setting the bit to 0. Even if we don\’t clear this bit it will cause no effect during ADC Conversion. But its good practise to clear all bits of Status Register before starting the new conversion 2.            ADC_DR(ADC Data Register) –> This register stores the converted digital data at a 12-bit resolution of the converted ADC channel. STM32F103 ADC Data Register 11.12.14 Bit 15:0 [DATA 15:0]: The ADC_DR is divided into two 16 bits groups. The first 16 bits from 0-15 contain the Converted value of the configured ADC Regular Channel. As our ADC is of 12-bit resolution, so this is left aligned or right aligned to 4 bits so as to get the 12 ADC converted data . Left Aligned or Right alignment of ADC Data Depends on ALIGN bit of ADC_CR2 So we will have following code and algorithm for ADC_SR & ADC_DR register:while(!(ADC1->SR & ADC_SR_STRT)) while(!(ADC1->SR & ADC_SR_EOC)); // wait till a group channel converstion has completed adc_data = ADC1->DR; //clear the EOC bit by reading DR register ADC1->SR &= ~ADC_SR_STRT;      3.      ADC_CR1(ADC Configuration register 1) –> This register is used for the  Configuration of ADC peripheral for Analog Watchdog Discontinuous Mode Interrupt Enable/disable Dual Mode configuration Scan Mode  As we are not using any of these features, so all the bits for these registers will be set to zero, and to know about these features and their bit functions, u can navigate to corresponding blogs for those. STM32F103 ADC Configuration Register 1. 11.12.2 Bits 19:16 [DUALMODE 3:0]:  These bits are used to configure the type of operating mode. In the blue pill, we have two ADC peripherals: ADC1 & ADC2. We can use these  2 ADC peripherals simultaneously by configuring the respective ADC in different modes or in independent modes. We are going to use these ADC in independent mode as will be using only ADC1 peripheral, so DUALMODE[3:0] will be set to 0. Bit 8[SCAN]: This bit is used to enable/disable the SCAN Mode feature in the ADC peripheral of BLUEPILL. Scan Mode is used when we convert more than 1 channel to scan all the configured channels in a Regular Group. As we are using only a single channel, means only one ADC pin is used so SCAN mode is not used and this bit will be set to 0. 0: Scan Mode disabled. 1:Scan Mode Enabled. So we will have following code and algorith for ADC_CR1 register:ADC1->CR1 &= ~(ADC_CR1_SCAN); // SCAN DISABLED, if using scan mode then dma must be enabled ADC1->CR1 &= ~(ADC_CR1_JDISCEN | ADC_CR1_DISCEN); // Discontinous mode disabled for both injected and regular groups ADC1->CR1 &= ~(ADC_CR1_DISCNUM_2 | ADC_CR1_DISCNUM_1 | ADC_CR1_DISCNUM_2 ); // no channels are configured in discontinous way. // if discontinous mode is enabled then number of //conversions to be done by discontinous mode has to be configured // DISNUM bits ADC1->CR1 &= ~(ADC_CR1_DUALMOD_0 | ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_2); // INDEPENDENT MODE SELECTED ADC1->CR1 &= ~(ADC_CR1_AWDEN | ADC_CR1_JAWDEN); // Analog watchdog disabled for both groups: regular and ibnjected 4. ADC_CR2(ADC Configuration Register 2) –> This register is used for the configuration of  ADC Peripheral for:  ADC Conversion enables/disabled for regular and injected groups and ADC peripheral enable/disable. Trigger source configuration for regular and injected groups. ADC Data Alignment, DMA, Continous, temperature sensor setting. STM32F103 ADC Configuration Register 2 11.12.3 Bit 0 [ADON]: ADC Peripheral On/OFF. This bit will be set to 1 to enable the ADC peripheral.  All channel configurations and ADC Peripheral configurations have to be made before setting this bit to 1. 0: Disable ADC Peripheral 1: Enable ADC Peripheral Bit 1 [CONT]: This bit configures between Single Conversion mode and Continous Conversion mode. Continuous Conversion mode is selected when we have more than 1 ADC channel to be converted. As in this blog, we have

Embedded MCU's Getting Started and Peripheral Coding STM32 MCU's STM32F1

ADC(Analog To Digital Converter) in STM32F103

Home Category Child Category Introduction Imagine that we are building a robot or an interactive art piece. We might be interested in measuring temperature, distance to the nearest object, force, and acceleration, sound pressure level, brightness, or any other physical characteristics. The first step is to convert all these physical quantities into a voltage using a transducer. The world is analog in nature, so every quantity that we need to measure is measured by the transducer in an analog output. But our Computers, MCU, Processors are digital in nature, that is they can Understand only ‘1’ and ‘0’. Thus we need an interface that can convert analog values of the world into digital values so as to process them. Thus here comes the ADC(Analog to Digital converter) “Analog Signals need to be processed correctly before they can be converted into digital form. This processinbg of Analog Signal is done by Signal Conditioning circuits” Important Terms in ADC Resolution of ADC: As said, ADC transforms an analog voltage to a binary number(series of 1’s &0’s) which is then represented as a Digital Number over our screens. The Number of Binary digits (1 &0) that represents the Digital Number determines the ADC Resolution ADC Introduction in STM32 Like every modern family of MCU, STM32 too has inbuilt ADC. Now if we open the datasheet of STM32F103 Bluepill and Navigate to its ADC Section. Now let’s break down this ADC Introduction part to understand the ADC Peripheral in STM32 MCU Successive Approximation: Type of ADC which is used in STM32 MCU.Which is made using OPAMPS, Resistors, Digital & Analog Electronic Circuit. So depending upon the type of circuit their are different types of ADC. 1) Successive Approximation 2) Sigma Delta 3) Voltage to frequency 4)Dual Slope ADC Analog Sensors & Electronics are huge topic, so wont be able to cover everything & would be focusing on STM32 MCU ADC Peripheral Click Here12 Bit ADC : Resolution of the ADC Peripheral in STM32 MCUThis is Resolution of the ADC Peripheral in STM32 MCU.Means Decoded ADC value which we will get will be ranging from [0-4095] = 2^12Click Here18 Multiplexed Channels: Blue Pill we have 18 ADC pinsBasically channels means from which Analog Values of the External world/Transducer will be fed to the MCU. Out of the 18 Pins Blue Pill has 16 external and 2 internal sources. This means that in 1) 16 pins [ADC0-15], we can fed analog values from the external world, like interfacing some analog sensors 2) 2 pins[ADC16:17] have the internal analog sources (Internal temperature Sensor & Internal Reference Voltage) : There is one inbuilt Temperature sensor inside the MCU which Outputs the data in analog value & send it to ADC_Channel 16.Click Here Previous Next So that is for the basic introduction of the ADC peripheral of STM32F103, now let\’s dive into more in-depth to know about the features of ADC peripheral in STM32 MCU. ADC Features in STM32 MCU Regular and Injected groups In STM32 MCU ADC peripheral their is a feature of Regular and Injected Group, we can configure the ADC Channels to be either in Regular Group or Injected Group. Regular Group: ADC Channels which are configured in regular group are converted regularly( when ADC peripheral is started by setting ADC_CR2:ADON bit), just like basic ADC conversion of channels one by one Injected Group: Now Channels which are configured in injected group works on same principal of Regular Group but this group have higher priorty then Regular group. As it names says injected, this group will interrupt the Regular group Conversion Click Here Types of Conversion Modes in STM32 ADCTheir are 4 types of Channel Conversion Modes in STM32. 1) Single Conversion Mode 2) Continuous Conversion Mode 3) Scan Mode 4) Discontinuous ModeClick HereSingle Conversion Mode: As it name says \”Single Conversion\” so when ADC peripheral is configured to be in Single Conversion Mode , only one time conversion of configured ADC channels is done when ADC peripheral is triggered.Click HereContinous Conversion Mode:As it name says \”Continuous Conversion\”, so this is vice versa of single conversion. All the configured ADC channels are continuously converted once the ADC Peripheral is triggered by Software or by external event and converted data is continuously stored in ADC_DRClick HereScan Mode:This is 3rd type of Mode, as its name says\”Scan\”. So when configured in this mode, ADC works like a \”SCAN\”, it is used to scan a regular or injected group channel. In short, we can say if we are using more than 1 ADC channel & doing conversion of all configured ADC channels then we will be using Scan Mode. After the first channel conversion, it will go to the next configured channel for its conversion till the last channel configured Click HereDiscontinous Mode:This is 4th type of mode, in this mode we can convert configured channels of regular and injected group in short sequences of n conversion (n

Embedded MCU's Getting Started and Peripheral Coding STM32 MCU's STM32F1

About ARM Processor’s

first View What is a Processor Processor is programmable electronic circuitry that performs operations according to the instructions stored in memory. The processor as of itself does not have the memory and I/O devices. The processor reads the instructions stored in the memory, interprets it, and stores the output in memory or signals the I/Os. Processor Consists of the Processor core which contains circuitry for instruction fetching, decoding, and execution, register banks, and control units. According to the architecture design of the processor, the different processors have different components. For example, ARM cortex-M4 processors have NVIC, MPU, Floating point units, optional debug subsystems. This allows the microcontroller vendors to design differently. A block diagram of the microcontroller. Fig 1.2 – A microcontroller contains Many different blocks How does Processor control the world? Processors become an integral part of our life. We come across many devices which have processors embedded in them. For example: The smartphone on which I am writing this article has ARM cortex-A55 and cortex-A75 as processor,   The Famous Tesla motors FSD Self-driving computer has many ARM processors. To give the idea of how processors are running the world look at these two examples. Upto 2019, Arm partners have shipped more than 160 billion Arm-based chips. Due to the shortage of semiconductor chips(processors) many car manufacturing companies had to reduce the number of cars manufactured. ARM Processor ARM Processor ARM processors are designed by ARM Ltd., ARM does not manufacture processors or sell the chips directly. Instead ARM licenses these designs to other semiconductor companies so that they can make their processor, microcontroller, SOCs as ARM processors are configurable. In the Cortex processor range, the processors are divided into three profiles: 1) The A Profile is designed to handle complex applications such as high-end embedded OSs. 2) The R profile processors are targeted primarily at the high end of the real-time market. These are applications, such as hard drive controllers, automotive systems, etc. 3) The M profile processors target smaller-scale applications such as microcontrollers and mixed-signal design. ARM CortexA1) The A Profile is designed to handle complex applications such as high-end embedded OSs.Click HereARM Cortex RThe R profile processors are targeted primarily at the high end of the real-time market. These are applications, such as hard drive controllers, automotive systems, etc.Click HereARM Cortex MThe M profile processors target smaller-scale applications such as microcontrollers and mixed-signal design.Click Here Previous Next ARM develops new processors, new instructions, and architectural features are added from time to time, as a result, there are different versions of the architecture. For example: ARM7TDMI is based on the architecture version ARMv4T. ARMv5TE architecture was introduced with the ARM9E processor families. With the ARM11 Processor family, the architecture was extended to ARMv6 with memory system features and SIMD instructions included.  Cortex family processors are based on ARMv7 and ARMv6. The cortex-M3 and cortex-M4 processors are based on ARMv7-M architecture. The architecture evolution of the ARM can be seen in the following (Fig 1.4). All the cortex-M processors support Thumb-2 technology(16-bit and 32-bit instructions), with no need to switch the processor between Thumb state and ARM state. Keil MDK-ARMIAR systems(Embedded workbench for ARM Cortex-M) GCC_based IDEs Previous Next For Programming and debugging ARM Processor based MCU’s, we will be using Microcontrollers of different vendors like: STMicroelectronics and NXP Semiconductors. We will be using STM32 Family of STMicroelectronics and S32 Family of NXP Semiconductors. Both of these are based on ARM Processor and have rich set of features and specifications which are ideal for learning embedded systems. Now both the companies provide their own IDE’s for  : STM32CubeIDE and S32 Design IDE for respective family of MCU mentioned above. Or we can also use the Above-mentioned IDE’s which are general IDE’s can be used to program any ARM processor based MCU. But recomended one is to use Vendor specific IDE as it has many extra featutes for programming. CMSIS The Common Microcontroller Software Interface Standard(CMSIS) was developed by ARM to allow microcontroller and software vendors to use a consistent software infrastructure to develop software solutions for cortex microcontrollers. THE AIM OF CMSIS: Software reusability: make it easier to reuse code with different Cortex-M processors, reducing time to market and verification efforts.  Software compatibility: Due to consistent software infrastructure, software from various sources can work together, reducing the risk in integration.  The CMSIS allows easy access to processor core features from the c language.  CMSIS-compliant device drivers can be used with various compilation tools. CMSIS started out as a way to establish consistency in device-driver for the Cortex-M microcontrollers, and this has become CMSIS-Core. Since then, additional CMSIS projects have started: CMSIS-Core  A set of APIs for applications developers to access the features on the Cortex-M processor regardless of microcontroller devices and toolchain used. CMSIS-DSP library This library is intended to allow software developers to create DSP applications on Cortex-M microcontrollers easily. CMSIS-SVD the System View Description in an XMl-based file format to describe peripheral set in microcontroller products. CMSIS-RTOS  the CMSIS-RTOS is an API specification for embedded OS running on Cortex-M Microcontrollers. CMSIS-DAP the CMSIS-DAP(Debug Access Port) is a reference design for a debug interface adaptor, which supports USB to JTAG/Serial protocol conversions. The CMSIS files are integrated into device-driver library packages from the microcontroller vendor. So when you are using CMSIS-compliant device-driver libraries provided by the microcontroller vendors, you are already using CMSIS. We can define the CMSIS into multiple layers: Core peripheral Peripheral Layer Name definitions,address definitions, and helper functions to access core registers and core peripherals. This is processor specific and is provided by ARM. Device Peripheral Access LAyer:  Name definitions, address definitions of peripheral registers etc. This is device specific. Access Functions For Peripherals Access Functions For Peripherals How do I use CMSIS-Core ? Add Source files to the project. This includes: Device specific, toolchain-specific startup code, in the form of assembly or C. Device-specific device initialization code(e.g. System_c). Add header files into the search path of the project: A device-specific header

Embedded MCU's Getting Started and Peripheral Coding STM32 MCU's

How to Use Trace Features in STM32 with STLINKv2 in CubeIDE – Part 2

This is Follow up video of the previous Blog, In this How to use Trace features in STM32 MCU via SWV are explained using STLINKv2 Programmer and Debugger in STM32CubeIDE. Table of Contents Various Trace Features by SWV, Live Expressions and Using them SWV in STM32CubeIDE provide us with following Trace Features to be used in STM32MCU. Figure 14 SWV Features can only be used in Debug mode, so after creating your project as mentioned in below section, click on Debug Icon on the Menu bar of CubeIDE. Figure 15 If you are debugging your code for first time, debug configuration window will pop up, in which u must select your Debugger and made some Configurations. Main things to select in Debug Configuration window are. Debug Probe -> Select GDB server or OpenOCD. Enable the Serial wire Viewer(SWV) by checking on enable button and select the Core clock of SWV exactly as the Clock frequency that u have configured for your MCU system Clock, SWO clock as 2000 khz Under Misc. Section select the Enable Live Expressions Figure 16 Out of all SWV features I will be showing how to use marked SWV Trace Features from above pic of SWV Show View. SWV ITM Data Console So first Starting the SWV ITM Data Console which is used for printing printf() commands for printing Strings on the ITM terminal screen without using UART. For that We have to include the following code in your main.c file and include Header file Stdio.h in your main.c for printing the printf() commands on your ITM console. And now in your while loop of main.c file just write printf() commands like these. In the following Pic I have also blinked the led at PC13 pin. And then Debug the code by clicking on Debug Icon in Menu bar of CubeIDE. And after entering Debug Mode, click on Window -> Show View -> SWV -> SWV ITM Data console. Now as You open the SWV ITM Data Console, or any SWV window, u will find Following 2 icons in every view.  The first one is the SWV configuration Button, which is very important and configures our SWV. And another one is Start button for Starting the Trace. At first, we must do the SWV configurations, so click on first button. SWV Configuration window will pop out. Now For Using the ITM Data console, just click on the below marked check box for printing Printf() commands on the ITM port 0.and then click on ok.  Now start the trace by clicking on Red Button alongside the Configuration button. And now Resume the Code in Debug Mode only by clicking on the Resume button in menu bar of Cube IDE. Now as You click on Resume Button, U can see your printf() output strings on the ITM Data console. So that is how one can Print the strings using SWV + SWD in STM32 MCU via STLINKv2 without using UART for debugging the firmware. Click on Suspend button to stop the SWV. SWV Data Trace and SWV Data Trace Timeline Graph These two windows can be used to trace up to any Variables/Address locations of our code. Showing their value and other necessary details. For showing their use case, in our main.c I will be creating two variables by a&b. As shown in below pic. Now debug the code and open the SWV Data Trace and SWV Data Trace Timeline Graph windows. From those windows open the SWV configuration window as told in previous Section. And do the following changes, Enable the Comparator 0 and 1: one can data trace only up to 4 variables or address locations as you can see there are 4 Data Trace Comparators in our SWV Configuration window. In Var/Addr sections of Comparator 0&1 write the variables or address locations to be traced. And select ACCESS and GENERATE according to your variable being traced or address location being Traced. Below is the pic, showing my configurations: Click on okay and then start the Trace and Resume the Code in Debug Mode only as specified in Previous Section. Now you will see in SWV Data Trace view, all trace data of configured variables/address locations is being shown under History Section, showing various parameters like Value, Access, Program Counter value, Clock Cycles and Time for the Traced Event. As shown in Figure. Out of Configured Comparator, one can select for which comparator we want to see the history from the Watch section of Data trace, as shown in above Two pics.  Data trace data can be of great value for monitoring Time critical variables and address locations and observing their behavior during Program execution. In SWV Data Trace Timeline Graph, one can see the plotting of value of the configured Comparators in the form of graph and Analyzing Variables that are dependent on each other or Time critical. The Graph is plotted as shown in Pic. There are various options available on TimeLine Graph window, you can experiment those features by your won. SWV Statistical profiling Is used to see in which functions of your code, CPU is spending too much of time when program is running in MCU. To use SWV Statistical Profiling we do not have to write any code, just do as mentioned in Various Trace Features by SWV and Using them section above and enable the PC Sampling in SWV configuration window. Then start the trace and Resume the Code in Debug code as told in above sections. Now For Statistical Profiling wait for x number of secs after resuming your code according to your choice, in that time no data will be shown on Screen. After x amount, suspend the Program Execution and You will see something like this. As you can see, in above pic one can analyse in which functions our code is spending most of the and how much time. Which can be of great help in Very Complex codes which includes multiple I/O

Stay Updated With Us

Error: Contact form not found.