You are on page 1of 9

AIM2.

0 STM32L152 Programming Guide


The AIM 2.0 system consists of several key components and peripherals. This
include the microcontroller STM32L152RD, igloo FPGA, CMOS image sensor, 1MB
SRAM, Micro SDCard and several sensors (Accelerometer, Gyroscope, analog
sensors etc). Careful configuration and optimization procedures are needed to
maintain a low power operation. This document will describe the necessary
configuration and programming for the microcontroller to achieve the optimal
power performance.
1.0 STM32L152 in Low power sleep mode (LPSleep).
The microcontroller has several low power operation mode. Among all the low
power modes, low power sleep is chosen for a better trade-off between power
consumption and system functionality. Keep in mind that, while in low power
mode, some peripherals need to be continuously run. Table 1.0 shows the
peripherals functionalities in different operating mode.

Table 1.0

The low power sleep mode in the AIM2.0 system is configured with the system
clock (sysclk) running at ~32KHz. The MSI clock (65KHz) is used as the clock
source and this clock will be divided into 2 to get 32KHz. While in low power
sleep mode, all the not connected GPIOs is configured to be in analog mode and
all other components in the system is switched off. To switch off the camera, fpga
and sram, the 2.8V and 1.2V regulators must be disabled. This can be done by
configuring the GPIO pin PC13 in reset mode. Figure 1.0 shows the code to put
the microcontroller in the low power sleep mode. This should make the total
current consumed by the AIM2 system to be in about 6uA.

Figure 1.0
Please note that the GPIO pin 13 should be configure in pull down mode. This is
to make sure that the GPIO is in the same direction with the output.
Configuration in pull-up mode will not achieve lowest current consumption.
The system will be waken up from the low power sleep mode by RTC (Real Time
Clock). The RTC is configured (RTC_Config() function) to be clocked by LSE clock.
The low speed external (LSE) clock is 32 KHz clock and this clock is chosen due
to its stability compared to internal oscillator. The system will be waken up at
every ~4s. To change the wake up interval, the wake up counter can be changed.
In order to get the system to be in the lowest power possible, the
LowPowerSleepMode function have to be called. Figure 1.1 and 1.2 show the
RTC_Config and LowPowerSleepMode functions.

Figure 1.1

Figure 1.2

1.2 Waking up from interrupt


During the image capture mode, the system will go to low power sleep mode and
wakes up at every ~4s (as mentioned in previous section). Once the system
wakes up, the system will run the complete routine to capture an image and
store in the SDCard. This routine is defined in the RTC wakeup handler. The
example code is shown in figure 1.3.

Figure 1.3

2.0 Camera configuration


There are two types of camera being used/experimented in the development of
AIM2.0. One is 2 Megapixel OV2640 and the second one is 5 Megapixel OV5642
camera. The appropriate camera configuration function should be called in the
main program. Please note, both of the cameras used different address ID hence,
calling a wrong function with a wrong installed camera will not work.
In order for the camera to start working, the camera has to be powered on
(powered by 2.8V and 1.2V regulators) and input clock should be given to the
camera. The camera register configuration is supplied through I2C
communication. The camera registers are configured to be in JPEG mode and
other necessary settings that can be used by the FPGA module for image
capturing. The input clock is configured by the MCO1_Init function. This function
will generate the required clock through the microcontroller clock output pin
(GPIO pin PA8). For both of the camera, the MCO clock is configure to run at
16MHz. The input clock range for the OV2640 and OV5642 is 8MHz 20MHz and
8MHz 27MHz respectively. The camera input clock can be turned down or
completely turn off if not used. This can reduce the current consumption. Figure
2.1, 2.2 and 2.3 show the configuration code for MCO, camera register
configuration and I2C configuration respectively.

3.0 Main program

You might also like