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" function.
@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.
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);
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.
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
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.
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