This repo contains notes and programming assignments for the Udemy's "Mastering Microcontroller: Timers, PWM, CAN, Low Power (MCU2)" course by FastBit Embedded Brain Academy.
Date: August, 2019. Date Updated (STM32CubeIDE): January, 2024.
-
The course is instructed by Engineer Kiran Nayak.
-
The Certificate is available.
In this course we are going to learn and master Timers , PWM, CAN, RTC, Low Power modes of STM32F4x Micro-controller with step by step guidance, with various real-time exercises which help to master every peripheral covered in this course and covers both theory and practical aspects of Timers, PWM, CAN, RTC, Low Power modes of STM32F4x Micro-controller.
In Timer Section the course covers:
- Simple time-based generation using the basic timer in both polling and interrupt mode.
- Timer interrupts and IRQ numbers, ISR implementation, callbacks, etc.
- General-purpose timer.
- Working with Input Capture channels of General-purpose timer.
- Interrupts, IRQs, ISRs, callbacks related to Input Capture engine of the general purpose timer.
- Working with output capture channels of the General purpose timer.
- Interrupts, IRQs, ISRs, callbacks related to Output Capture engine of the general purpose timer.
- PWM generation using output capture modes.
- PWM Exercises.
- Step by Step code development process will help you to master the TIMER peripheral.
In CAN Section the course covers:
- Introduction to the CAN protocol.
- CAN frame formats.
- Understanding a CAN node.
- CAN signaling (single-ended signals vs differential signals).
- CAN Bus recessive state and dominant state.
- CAN Bit timing Calculation.
- CAN network with Transceivers.
- Exploring inside view of CAN transceivers.
- CAN Self-test modes such as LOOPBACK, SILENT LOOPBACK, etc with code exercises.
- Exploring STM32 bXCAN peripheral.
- self-testing of bxCAN peripheral with exercises.
- bXCAN block diagram.
- Tx/Rx path of the bxCAN Peripheral.
- CAN frame filtering and executrices.
- CAN in Normal Mode.
- Communicating between 2 boards over CAN.
- Code exercises.
In the Power Controller Section the course covers:
- ARM Cortex Mx Low Power Modes Normals Vs DeepSleep.
- STM32 SLEEP mode.
- STOP mode.
- STANDBY mode.
- Current measurement with different submode.
- Waking up MCU by using wakeup pins, EXTI, RTC, etc.
- Backup SRAM.
- Step by Step coverage with lots of code exercises.
In RTC Section the course covers:
- RTC functional block diagram.
- RTC clock management.
- RTC calendar unit.
- RTC Alarm unit.
- RTC wake-up unit.
- RTC Time Stamp Unit.
- waking up MCU using RTC events.
- RTC interrupts.
- and lots of other details with step by step code exercises.
STM32 Device HAL framework:
- STM32 Device Hal framework details.
- APIs details.
- Interrupt handling.
- Callback implementation.
- Peripheral Handling and configurations.
- Step by Step explanation with code exercises.
STM32 Nucleo-F446RE Development Board - Board used in this course but any board with Arm Cortex-M0/3/4 core will work, just modifying the target board and configuring with the respective datasheet.
Eclipse-based STM32CubeIDE - C/C++ development platform with peripheral configuration, code generation, code compilation, and debug features for STM32 microcontrollers and microprocessors. Works on Windows/Linux/Mac and is free.
-
Right click on the project -> properties -> expand C/C++ build -> Settings -> Tool settings -> MCU settings
Floating-point unit: None
Floating-point ABI: Software implementation ( -mfloat-abi=soft )
Open syscalls.c file and paste following code bellow Includes
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Implementation of printf like feature using ARM Cortex M3/M4/ ITM functionality
// This function will not work for ARM Cortex M0/M0+
// If you are using Cortex M0, then you can use semihosting feature of openOCD
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Debug Exception and Monitor Control Register base address
#define DEMCR *((volatile uint32_t*) 0xE000EDFCU )
/* ITM register addresses */
#define ITM_STIMULUS_PORT0 *((volatile uint32_t*) 0xE0000000 )
#define ITM_TRACE_EN *((volatile uint32_t*) 0xE0000E00 )
void ITM_SendChar(uint8_t ch)
{
//Enable TRCENA
DEMCR |= ( 1 << 24);
//enable stimulus port 0
ITM_TRACE_EN |= ( 1 << 0);
// read FIFO status in bit [0]:
while(!(ITM_STIMULUS_PORT0 & 1));
//Write to ITM stimulus port0
ITM_STIMULUS_PORT0 = ch;
}
After that find function _write and replace __io_putchar(*ptr++)
with ITM_SendChar(*ptr++)
like in code snippet below
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
//__io_putchar(*ptr++);
ITM_SendChar(*ptr++);
}
return len;
}
After these steps navigate to Debug configuration and check Serial Wire Viewer (SWV)
check box like on snapshot below
Once you enter Debug mode, go to Window -> Show View -> SWV -> Select SWV ITM Data Console
. On this way ITM Data Console
will be shown in Debug session.
In SWV ITM Data Console Settings
in section ITM Stimulus Ports
enable port 0, so that you can see printf
data.