Transcript
Page 1: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 1

JX-STM32 ARM Cortex-M3

Microcontroller boardDocumentation

INNOVATIVE EXPERIMENT

www.inexglobal.com

Page 2: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

2 l JX-STM32 ARM Cortex-M3 microcontroller board

Page 3: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 3

PrefaceThe STM32 evaluation boards provide complete development platforms for the

STM32F103 ARM® Cortex™ -M3 core-based microcontrollers. They provide cost effective,flexible and open design solutions ideal for demonstrating device capabilities and rapidlyevaluating features and peripherals. They include an STM32 microcontroller with highperformance ARM Cortex-M3 core, full speed USB 2.0 interface, CAN 2.0A/B compliantinterface, I2C, SPI, USART and Graphic LCD

The JX-STM32 boards include a complete range of hardware features forevaluating microcontroller performance and starting development of a wide range ofapplications. Features include SD card, GLCD, USB, CAN, I2C, RS-232, audio amplifiercircuit.

The boards feature industry standard JTAG connector allowing developers tochoose from a wide choice of development tools from third-party tool suppliers. Inaddition, the JX-STM32 board includes a high density 20-pin connector so that users cantake advantage of tools offering runtime trace.

The software devleopment tools includes third-party solutions that come completewith an integrated development environment and in-circuit debugger/programmerfeaturing JTAG application interface. Developers who are new to this family and theCortex™ core can also benefit from the range of starter kits that are specially designedto help developers evaluate device features and start their own applications.

Thanks to ST firmware libraries and a comprehensive set of application notes,the STM32 microcontrollers offer total software control and improved time to market.The superb combination of the state-of-the-art and efficient library of software driversand extensive support for all major tool providers offers a fast route to best-fit and anoptimized development process.

Page 4: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

4 l JX-STM32 ARM Cortex-M3 microcontroller board

Example project files summary forSTM32F103VBT6 in Raisonance Rkit-ARM7tool suit

Main folderC:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples

ADC (Analog to Digital converter module)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\ADC

The most examplefiles can work with the JX-STM32 board (5 examples) except3ADCs_DMA example.

Backup registerC:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\BKP

All example files can work with JX-STM32 board (2 examples)

CAN (Control Area Network module)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\CAN

All example files can work with JX-STM32 board (1 example)

Cortex-M3 processorC:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\CortexM3

All example files can work with JX-STM32 board (2 examples)

DMA (Direct Access Memory)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\DMA

The most examplefiles can work with the JX-STM32 board (4 examples) exceptFSMC example.

EXTI (External Interrupt)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\EXTI

All example files can work with JX-STM32 board (1 example)

Flash memoryC:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\FLASH

All example files can work with JX-STM32 board (2 examples)

Page 5: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 5

GPIO (General purpose Inout/Output port)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\GPIO

All example files can work with JX-STM32 board (2 examples)

I2C (Inter-Integrated bus)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\I2C

The most examplefiles can work with the JX-STM32 board (4 examples) exceptM24C08_EEPROM example.

IWDG (Independent Watchdog module)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\IWDG

All example files can work with JX-STM32 board (1 example)

LIB_DebugC:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\DEBUG

All example files can work with JX-STM32 board (1 example)

NVIC (Nested Vectored Interrupt Controller)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\NVIC

All example files can work with JX-STM32 board (6 examples)

Power save mode operationC:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\PWR

All example files can work with JX-STM32 board (2 examples)

RCC (Real Counter Controller)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\RCC

JX-STM32 can support this example files by removing (desodering) 8MHz crystalfrom the JX-STM32 board. Requires the desoldering skill for removing the crystal frommicrocontroller board.

RTC (Real-Time Clock module)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\RTC

Only Calender example files can work with JX-STM32 board (1 example)

SPI (Serial Peripheral Interface)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\SPI

The most examplefiles can work with the JX-STM32 board (5 examples) exceptM25P64_FLASH example by connecting the SPI port pin that connected with SDcard socket.

Page 6: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

6 l JX-STM32 ARM Cortex-M3 microcontroller board

SysTickC:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\SysTick

All example files can work with JX-STM32 board (1 example)

TIM (Timer/Counter)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\TIM

All example files can work with JX-STM32 board (15 examples).

Requires the Oscilloscope for measuring the signal waveform.

USART (Universal Synchronous/Asynchronous Receiver Transmitter)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\UART

Most example files can work with the JX-STM32 (9 exmaples) except IRDA,Smartcard and Synchronous example.

WWDG (Window Watchdog)C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples\WWDG

All example files can work with JX-STM32 board (1 example)

Page 7: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 7

1.1 Technical featuresl CPU core : 32-bit ARM Cortex-M3 Maximum clock frequency 72MH with Single-

cycle multiplication and hardware division

l Memory : Flash 128KB and Static RAM 20KB

l Clock frequency : 4 to 16MHz in Crystal oscillator, 8MHz Internal RC, 40kHzInternal RC, 32kHz Internal clock for Real-time clock module and Phase-lock-loop for CPUclock up to 72MHz.

l Supply voltagr : 2.0 to 3.6Vdc

l Power management : Power-On Reset (POR), Power-Down Reset (PDR),Programmable voltage detector (PVD). Support 3 power-save modes; Sleep, Stop andStandby

l VBAT supply for RTC and backup registers

l ADC module : Speed 1ms. 2 of 12-bit resolution ADC module, 16 channelstotal. Support input voltage 0 to 3.6Vdc. 2 of sample and hold circuit and on-chiptemperature sensor.

l DMA : 7 channels. Support Timer, ADC, SPI,m I2C bus and USART moduels

l Input/Output port : 80-pin high speed anmd +5V tolerance

l Debug : Support Serial wire debug (SWD) and JTAG

l Timer : 7 units- Up to three 16-bit timers, each with up to 4 IC/OC/PWM or pulse counter- 16-bit, 6-channel advanced control timer:

up to 6 channels for PWM output, deadtime generation andemergency stop

– 2 watchdog timers (Independent and Window)– SysTick timer: a 24-bit downcounter

l Serial interface module : 9 communication interfaces- 2 of I2C bus interfaces; support SMBus and PMBus- 3 of USART; support ISO 7816, LIN, IrDA and modem control signal- 2 of SPI speed 18Mbit/second- CAN 2.0B Active type- - USB 2.0 full speed

More information available at http://www.st.com

1 : STM32F103BVT6 The ARM Cortex-M3microcontroller from STMicroelectronics

Page 8: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

8 l JX-STM32 ARM Cortex-M3 microcontroller board

1.2 STM32F103VBT6 architechtureThe figure 1-1 shows STM321F103VBT6 microcontroller operation diagram.

1.2.1 Embedded memorySTM32F103VBT6 embedded 128 Kbytes of embedded Flash is available for storing

programs and data. and embedded SRAM 20 Kbytes of embedded SRAM accessed(read/write) at CPU clock speed with 0 wait states. The figure 1-2 show flash memory-mapping of STM32F103VBT6.

1.2.2 Nested vectored interrupt controller (NVIC)The STM32F103xx performance line embeds a Nested Vectored Interrupt

Controller able to handle up to 43 maskable interrupt channels (not including the 16interrupt lines of Cortex-M3) and 16 priority levels.

l Closely coupled NVIC gives low latency interrupt processingl Interrupt entry vector table address passed directly to the corel Closely coupled NVIC core interfacel Allows early processing of interruptsl Processing of late arriving higher priority interruptsl Support for tail-chainingl Processor state automatically savedl Interrupt entry restored on interrupt exit with no instruction overhead

This hardware block provides flexible interrupt management features with minimalinterrupt latency.

1.2.3 External interrupt/event controller (EXTI)The external interrupt/event controller consists of 16 edge detectors lines used

to generate interrupt/event requests. Each line can be independently configured toselect the trigger event (rising edge, falling edge, both) and can be maskedindependently. A pending register maintains the status of the interrupt requests. TheEXTI can detect external line with pulse width lower than the Internal APB2 clock period.Up to 80 GPIOs are connected to the 16 external interrupt lines.

1.2.4 Clocks and startupSystem clock selection is performed on startup, however the internal RC 8 MHz

oscillator is selected as default CPU clock on reset. An external 4 to16 MHz clock canbe selected and is monitored for failure. During such a scenario, it is disabled andsoftware interrupt management follows. Similarly, full interrupt management of the PLLclock entry is available when necessary (for example on failure of an indirectly usedexternal crystal, resonator or oscillator).

The maximum frequency of the AHB and the High Speed APB domains is 72 MHz.The maximum allowed frequency of the Low Speed APB domain is 36 MHz.

Page 9: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 9

Figure 1-1 STM32F103VBT6 block diagram

TPIU

SW/JTAGTrace

Cortex-M372MHz clock

NVIC

DMA

7-ch.

Supplysupervisor

POR/PDR

PVD

Externalinterrupt

GPIOA

GPIOB

GPIOC

GPIOD

GPIOE

TIM1

SPI1

USART1

ADC1 12-bit

ADC2 12-bit

Temperaturesensor

Adva

nced

per

iphe

ral b

us 2

(AP

B2)

48 o

r 72

MH

z

AHB2-APB2interface

AHB2-APB1interface

Adva

nced

per

iphe

ral b

us 1

(AP

B1)

48 o

r 72

MH

z

TIM2

TIM3

TIM4

USART2

USAERT3

SPI2

I2C1

I2C2

bxCAN

USB2.0 FS

SRAM 512 bytes

RTCAWU

XTAL 32k

Backupregister

Backup interface

IWDG

XTAL 4-16MHz

Standbyinterface

PLL&Clock

management

RC 8MHz

RC 40kHz

PCLK1PCLK2HCLKFCLK

Bus

mat

rix

Static RAM20KB

Flashmemory128KB

Flashmemoryinterface

Instruction bus

data bus

system bus

AHB

48 t

o 72

MH

z

Trace controllerdata bus

ResetInterrupt

WWDG

Supply voltage

1.8V regulator

VDD 2 to 3.6V

Vss

OSC_INOSC_OUT

VBAT

4-ch.

Rx,Tx,CTS,RTS,CKRx,Tx,CTS,RTS,CKMOSI,MISO,SCK,SS

SCL,SDA

SCL,SDA

USBDP/CANTXUSBDM/CANRX

OSC32_INOSC32_OUT

TAMPER-RTC

VREF+VREF-

MOSI,MISO,SCK,SSRx,Tx,

RTS,CTS

4-ch.

PA0-PA15

PB0-PB15

PC0-PC15

PD0-PD15

PE0-PE15

80 I/OEXTI

NRSTVDDAVSSA

TRACECLKTRACED0-3

JNTRST

JTCLK/SWCLKJTDI

JTMS/SWDIOJTDO

@VDDA

@VBAT

@VDDA

@VDDA

@VDD

Wakeup (PA0)

4-ch.

4-ch.

Page 10: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

10 l JX-STM32 ARM Cortex-M3 microcontroller board

7

6

5

4

3

2

1

0

0x0000 0000

0x2000 0000

0x4000 0000

0x6000 0000

0x8000 0000

0xA000 0000

0xC000 0000

0xE000 0000

0xFFFF FFFF

0xE010 0000 เพอริเฟอรัลภายในCortex-M3 โปรเซสเซอร

เพอริเฟอรัล

สแตติกแรม

โคด

0x0800 0000

0x0801 FFFFหนวยความจํา

แฟลช

0x1FFF F000

หนวยความจําระบบ

0x1FFF F800 ออปช่ันไบต0x1FFF F80F

สํารองไว0x1FFF FFFF

TIM20x4000 0000

TIM3TIM4

0x4000 04000x4000 0800

0x4000 2800

0x4000 0C00

RTCWWDGIWDG

0x4000 2C000x4000 30000x4000 34000x4000 3800 SPI20x4000 3C00

0x4000 4400 USART2USART30x4000 4800

0x4000 4C00

0x4000 5400 I2C1I2C2

USB รีจิสเตอรUSB/CAN SRAM

bxCAN

BKPPWR

AFIOEXTIPort APort BPort CPort DPort E

ADC1ADC2TIM1SPI1

USART1

DMA

RCC

Flash interface

0x4000 58000x4000 5C000x4000 60000x4000 64000x4000 68000x4000 6C000x4000 70000x4000 7400

0x4001 00000x4001 0400

0x4001 2400

0x4001 3C000x4002 00000x4002 0400

0x4002 10000x4002 1400

0x4002 20000x4002 2400

0x4001 08000x4001 0C000x4001 10000x4001 14000x4001 18000x4001 1C00

0x4001 28000x4001 2C000x4001 30000x4001 34000x4001 3800

0x4002 30000x4002 3400

1 กิโลบติ1 กิโลบติ1 กิโลบติ

7 กิโลบติ

1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ

1 กิโลบติ1 กิโลบติ

1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ

35 กิโลบติ

1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ2 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ1 กิโลบติ

1 กิโลบติ

1 กิโลบติ

1 กิโลบติ

1 กิโลบติ

3 กิโลบติ

3 กิโลบติ

3 กิโลบติ

1 กิโลบติ

2 กิโลบติ

2 กิโลบติ

สํารองไว

Figure 1-2 STM32F103VBT6 memory assignment

Page 11: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 11

1.2.5 Boot modeAt startup, boot pins are used to select one of three boot options:

l Boot from User Flash

l Boot from System Memory

l Boot from SRAM

The boot loader is located in System Memory. It is used to reprogram the Flashmemory by using USART1.

1.2.6 Supply voltageSTM32F103VBT6 requires the main supply voltage (VDD) and Analog module supply

voltage (VDDA) 2 to 3.6Vdc. Back up voltage for Real-time clokc module (VBAT) 1.8 to3.6V from external battery.

1.2.7 Power supply supervisorThe device has an integrated Power On Reset (POR)/Power Down Reset (PDR)

circuitry. It is always active, and ensures proper operation starting from/down to 2V.The device remains in reset mode when VDD is below a specified threshold, VPOR/PDR,without the need for an external reset circuit.

The device features an embedded programmable voltage detector (PVD) thatmonitors the VDD power supply and compares it to the VPVD threshold. An interrupt canbe generated when VDD drops below the VPVD and/or when VDD is higher than the VPVD

threshold. The interrupt service routine can then generate a warning message and/orput the MCU into a safe state. The PVD is enabled by software.

1.2.8 Voltage regulatorThe regulator has three operation modes: main (MR), low power (LPR) and power

down.

l MR is used in the nominal regulation mode (Run)

l LPR is used in the Stop mode

l Power down is used in Standby mode: the regulator output is in highimpedance: the kernel circuitry is powered-down, inducing zero consumption (but thecontents of the registers and SRAM are lost)

This regulator is always enabled after reset. It is disabled in Standby Mode,providing high impedance output.

Page 12: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

12 l JX-STM32 ARM Cortex-M3 microcontroller board

1.2.9 Low power modesThe STM32F103xx performance line supports three low-power modes to achieve

the best compromise between low power consumption, short startup time and availablewakeup sources:

l Sleep : In Sleep mode, only the CPU is stopped. All peripherals continueto operate and can wake up the CPU when an interrupt/event occurs.

l Stop : Stop mode allows to achieve the lowest power consumptionwhile retaining the content of SRAM and registers. All clocks in the 1.8V domain arestopped, the PLL, the HSI and the HSE RC oscillators are disabled. The voltage regulatorcan also be put either in normal or in low power mode.

The device can be woken up from Stop mode by any of the EXTI line. TheEXTI line source can be one of the 16 external lines, the PVD output, the RTC alarm orthe USB wakeup.

l Standby : The Standby mode allows to achieve the lowest powerconsumption. The internal voltage regulator is switched off so that the entire 1.8 V domainis powered off. The PLL, the HSI and the HSE RC oscillators are also switched off. Afterentering Standby mode, SRAM and registers content are lost except for registers in theBackup domain and Standby circuitry.

The device exits Standby mode when an external reset (NRST pin), a IWDGreset, a rising edge on the WKUP pin, or an RTC alarm occurs.

1.2.10 RTC (real-time clock) and backup registersThe RTC and the backup registers are supplied through a switch that takes power

either on VDD supply when present or through the VBAT pin. The backup registers (ten 16-bit registers) can be used to store data when VDD power is not present.

The real-time clock provides a set of continuously running counters which can beused with suitable software to provide a clock calendar function, and provides analarm interrupt and a periodic interrupt. It is clocked by a 32.768kHz external crystal,resonator or oscillator, the internal low power RC oscillator or the high speed externalclock divided by 128. The internal low-power RC has a typical frequency of 40kHz. TheRTC can be calibrated using an external 512Hz output to compensate for any naturalcrystal deviation.

The RTC features a 32-bit programmable counter for long term measurementusing the Compare register to generate an alarm. A 20-bit prescaler is used for the timebase clock and is by default configured to generate a time base of 1 second from aclock at 32.768kHz.

Page 13: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 13

1.2.11 Independent Watchdog (IWDG)The independent watchdog is based on a 12-bit downcounter and 8-bit prescaler.

It is clocked from an independent 40 kHz internal RC and as it operates independentlyfrom the main clock, it can operate in Stop and Standby modes. It can be used eitheras a watchdog to reset the device when a problem occurs, or as a free running timerfor application time out management. It is hardware or software configurable throughthe option bytes. The counter can be frozen in debug mode.

1.2.12 Window Watchdog (WWDG)The window watchdog is based on a 7-bit downcounter that can be set as free

running. It can be used as a watchdog to reset the device when a problem occurs. It isclocked from the main clock. It has an early warning interrupt capability and the countercan be frozen in debug mode.

1.2.13 SysTick timerThis timer is dedicated for OS, but could also be used as a standard down counter.

It features:

l A 24-bit down counter

l Autoreload capability

l Maskable system interrupt generation when the counter reaches 0.

l Programmable clock source

1.2.14 General purpose timer (TIMx)There are up to 3 synchronizable standard timers embedded in the

STM32F103VBT6 devices. These timers are based on a 16-bit auto-reload up/down counter,a 16-bit prescaler and feature 4 independent channels each for input capture/outputcompare, PWM or one pulse mode output. This gives up to 12 input captures / outputcompares / PWMs on the largest packages. They can work together with the AdvancedControl Timer via the Timer Link feature for synchronization or event chaining.

The counter can be frozen in debug mode.

Any of the standard timers can be used to generate PWM outputs. Each of thetimers has independent DMA request generations.

Page 14: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

14 l JX-STM32 ARM Cortex-M3 microcontroller board

1.2.15 Advanced control timer (TIM1)The advanced control timer (TIM1) can be seen as a three-phase PWM multiplexed

on 6 channels. It can also be seen as a complete general-purpose timer. The 4independent channels can be used for

1. Input Capture

2. Output Compare

3. PWM generation (edge or center-aligned modes)

4. One Pulse Mode output

5. Complementary PWM outputs with programmable inserted dead-times.

If configured as a standard 16-bit timer, it has the same features as the TIMx timer.If configured as the 16-bit PWM generator, it has full modulation capability (0 to 100%).

The counter can be frozen in debug mode.

Many features are shared with those of the standard TIM timers which have thesame architecture. The advanced control timer can therefore work together with theTIM timers via the Timer Link feature for synchronization or event chaining.

1.2.16 I2C bus moduleSTM32F103VBT6 provides two I²C bus interfaces can operate in multi-master and

slave modes. They can support standard and fast modes.

They support dual slave addressing (7-bit only) and both 7/10-bit addressing inmaster mode. A hardware CRC generation/verification is embedded.

They can be served by DMA and they support SM Bus 2.0/PM Bus.

1.2.17 Universal synchronous/asynchronous receiver transmitter(USART)

One of the USART interfaces is able to communicate at speeds of up to 4.5Mbit/s.The other available interfaces communicate at up to 2.25 Mbit/s. They provide hardwaremanagement of the CTS and RTS signals, IrDA SIR ENDEC support, are ISO 7816 compliantand have LIN Master/Slave capability.

All USART interfaces can be served by the DMA controller.

1.2.18 Serial Peripheral Interface (SPI)STM32F103VBT6 provides up to two SPIs are able to communicate up to 18 Mbits/

s in slave and master modes in fullduplex and simplex communication modes. The 3-bitprescaler gives 8 master mode frequencies and the frame is configurable from 8-bit to16-bit. The hardware CRC generation/verification supports basic SD Card/MMC modes.

Both SPIs can be served by the DMA controller.

Page 15: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 15

1.2.19 Controller area network (CAN)The CAN is compliant with specifications 2.0A and B (active) with a bit rate up to

1 Mbit/s. It can receive and transmit standard frames with 11-bit identifiers as well asextended frames with 29-bit identifiers. It has three transmit mailboxes, two receive FIFOswith 3 stages and 14 scalable filter banks.

1.2.10 GPIOs (general-purpose inputs/outputs)Each of the GPIO pins can be configured by software as output (push-pull or

open-drain), as input (with or without pull-up or pull-down) or as peripheral alternatefunction. Most of the GPIO pins are shared with digital or analog alternate functions. AllGPIOs are high currentcapable.

The I/Os alternate function configuration can be locked if needed following aspecific sequence in order to avoid spurious writing to the I/Os registers.

I/Os on APB2 with up to 18 MHz toggling speed

1.2.11 Analog to digital converter module (ADC)Two 12-bit Analog to Digital Converters are embedded into STM32F103VBT6

devices and each ADC shares up to 16 external channels, performing conversions insingleshot or scan modes. In scan mode, automatic conversion is performed on aselected group of analog inputs.

Additional logic functions embedded in the ADC interface allow:

l Simultaneous sample and hold

l Interleaved sample and hold

l Single shunt

The ADC can be served by the DMA controller.

An analog watchdog feature allows very precise monitoring of the convertedvoltage of one, some or all selected channels. An interrupt is generated when theconverted voltage is outside the programmed thresholds.

The events generated by the standard timers (TIMx) and the Advanced Controltimer (TIM1) can be internally connected to the ADC start trigger, injection trigger, andDMA trigger respectively, to allow the application to synchronize A/D conversion andtimers.

1.2.12 Temperature sensorThe temperature sensor has to generate a linear voltage with any variation in

temperature.

The conversion range is between 2 V < VDDA < 3.6 V. The temperature sensor isinternally connected to the ADC12_IN16 input channel which is used to convert thesensor output voltage into a digital value

Page 16: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

16 l JX-STM32 ARM Cortex-M3 microcontroller board

1.2.13 Direct memory access (DMA)This is special feature of STM32F103VBT6 device. The flexible 7-channel general-

purpose DMA is able to manage memory-to-memory, peripheral-to-memory and memory-to-peripheral transfers. The DMA controller supports circular buffer management avoidingthe generation of interrupts when the controller reaches the end of the buffer.

Each channel is connected to dedicated hardware DMA requests, with supportfor software trigger on each channel. Configuration is made by software and transfersizes between source and destination are independent.

The DMA can be used with the main peripherals: SPI, I2C, USART, general purposeand advanced control timers TIMx and ADC.

1.2.14 Universal serial bus (USB)The STM32F103VBT6 embeds a USB device peripheral compatible with the USB

Full-speed 12 Mbs. The USB interface implements a full speed (12 Mbit/s) function interface.It has software configurable endpoint setting and suspend/resume support. Thededicated 48 MHz clock source is generated from the internal main PLL.

1.2.15 Serial wire JTAG debug port (SWJ-DP)The ARM SWJ-DP Interface is embedded. and is a combined JTAG and serial

wire debug port that enables either a serial wire debug or a JTAG probe to beconnected to the target.

The JTAG TMS and TCK pins are shared respectively with SWDIO and SWCLK anda specific sequence on the TMS pin is used to switch between JTAG-DP and SW-DP.

1.3 STM32F103VBT6 pin assignmentFigure 1-3 shows the pin assignment of STM32F103VBT6 dev ice in LQFP-100

package. This documentation will be reference with this packcage

The function of each pin is summarized following the Table 1-1.

Page 17: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 17

VDD

_3VS

S_3

PE1

PE0

PB9

PB8

BOO

T0PB

7PB

6PB

5PB

4PB

3PD

7PD

6PD

5PD

4PD

3PD

2PD

1PD

0PC

12PC

11PC

10PA

15PA

14PA2PA1

PA0-WKUPVDDA

VREF+VREF -

VSSAPC3PC2PC1PC0

NRSTOSC_OUT

OSC_INVDD_5VSS_5

PC15-OSC32_outPC14-OSC32_in

PC13-TAMPER-RTCVBAT

PE6PE5PE4PE3PE2

PB12PB13PB14PB15PD8PD9PD10PD11PD12PD13PD14PD15PC6PC7PC8PC9PA8PA9PA10PA11PA12PA13NCVSS_2VDD_2

VSS_

1V

DD

_1PB

11PB

10PE

15PE

14PE

13PE

12PE

11PE

10PE9

PE8

PE7

PB2

PB1

PB0

PC5

PC4

PA7

PA6

PA5

PA4

VD

D_4

VSS_

4PA

399 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76

23456789101112131415161718192021222324

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

747372717069686766656463626160595857565554535251

7526

25

110

0

STM32F103VBT6

Figure 1-3 STM32F103VBT6 device pin assignment

Page 18: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

18 l JX-STM32 ARM Cortex-M3 microcontroller board

Table 1-1 STM32F103VBT6 pin function (continue)

Pinno. Type

I/O

Mainfunction

PE2

Alternate function

Default Alternate

WKUPUSART2_CTADC12_IN0TIM2_CH1_ETR

TRACECK1I/O PE3 TRACED02I/O PE4 TRACED13I/O PE5 TRACED24I/O PE6 TRACED35

Battery supply VBAT6I/O PC13 TAMPER-RTC7I/O PC14 OSC32_IN8I/O PC15 OSC32_OUT9

Ground VSS_510I/O VDD_511

Input12Output13

I/O14I/O ADC12_IN1015I/O ADC12_IN1116I/O ADC12_IN1217I/O ADC12_IN1318

Ground19Reference voltage20Reference voltage21Supply voltage22

I/O23

Name

PE2

PE3

PE4

PE5

PE6

VBAT

PC13-TAMPER-RTC

PC14-OSC32_IN

PC15-OSC32_OUT

VSS_5

VDD_5

OSC_IN

OSC_OUT

NRST

PC0

PC1

PC2

PC3

VSSA

VREF-

VREF+

VDDA

PA0-WKUP

OSC_IN

OSC_OUT

NRST

PC0

PC1

PC2

PC3

VSSA

VREF-

VREF+

VDDA

PA0

USART2_RTSADC12_IN1TIM2_CH2

I/O24 PA1 PA1

I/O25 PA2 PA2 USART2_TXADC12_IN2TIM2_CH3

I/O26 PA3 PA3 USART2_RXADC12_IN3TIM2_CH4

Ground27Supply voltage28

VSS_4

VDD_4

VSS_4

VDD_4

Page 19: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 19

Table 1-1 STM32F103VBT6 pin function (continue)

USART3_CKSPI2_NSSI2C2_SMBAITIM1_BKIN

I/O51 PB12 PB12

Ground49 VSS_1 VSS_1

Supply voltage50 VDD_1 VDD_1

I/OPB11 PB1148 USART3_RXI2C2_SDA

TIM2_CH4

I/OPB10 PB1047 USART3_TXI2C2_SCL

TIM2_CH3

PE12

PE13

PE14

PE15

PE7

PE8

PE9

PE10

PE11

I/O TIM1_CH3N43I/O TIM1_CH344

PE12

PE13

I/O TIM4_CH445I/O TIM1_BKIN46

PE14

PE15

I/O37I/O TIM1_ETR38

PB2/BOOT1

PE7

PB2/BOOT1

I/O TIM1_CH1N39I/O TIM1_CH140

PE8

PE9

I/O TIM1_CH2N41I/O TIM1_CH242

PE10

PE11

TIM1_CH2N

I/OPB1 PB136 ADC12_IN9TIM3_CH4

TIM1_CH3N

I/OPB0 PB035 ADC12_IN8TIM3_CH3

I/OPA7 PA732 ADC12_IN7SPI1_MOSITIM3_CH2

TIM1_CH1N

I/OPA6 PA531 ADC12_IN6SPI1_MISOTIM3_CH1

I/OPA5 PA530 ADC12_IN5SPI1_SCK

TIM1_BKIN

I/O29 PA4 PA4 USART2_CKADC12_IN4SPI1_NSS

PinNO. Type Main

functionAlternate function

Default Alternate

I/O ADC12_IN1433I/O ADC12_IN1534

Name

PC4

PC5

PC4

PC5

Page 20: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

20 l JX-STM32 ARM Cortex-M3 microcontroller board

Table 1-1 STM32F103VBT6 pin function (continue)

Ground74 VSS_2 VSS_2

Not used --73

JTMS/SWDIOI/O72 PA13PA13/JTMS/SWDIO

I/O71 PA12 PA12 USART1_RTSTIM1_ETRCANTXUSBDP

I/OPA10 PA1069 USART1_RXTIM1_CH3

I/O70 PA11 PA11 USART1_CTSTIM1_CH4CANRXUSBDM

PC9I/O TIM3_CH466 PC9

PC6

PC7

PC8

I/O TIM3_CH163 PC6

I/O TIM3_CH264I/O TIM3_CH365

PC7

PC8

I/OPD12 PD1259 USART3_RTSTIM4_CH1

I/OPA9 PA968 USART1_TXTIM1_CH2

I/OPA8 PA867 USART1_CKTIM1_CH1MCO

PD13

PD14

PD15

PD8

PD9

PD10

PD11

I/O TIM4_CH260 PD13

I/O TIM4_CH361I/O TIM4_CH462

PD14

PD15

I/O USART3_TX55 PD8

I/O USART3_RX56I/O USART3_CK57

PD9

PD10

I/O USART3_CTS58 PD11

I/O53 PB14 PB14 USART3_RTSSPI2_MISOTIM1_CH2N

I/OPB15 PB1554 SPI2_MOSITIM1_CH3N

I/O52 PB13 PB13 USART3_CTSSPI2_SCKTIM1_CH1N

Pinno. Type Main

functionAlternate function

Default AlternateName

Page 21: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 21

Table 1-1 STM32F103VBT6 pin function (final)

Supply voltage100 VDD_3 VDD_3

Supply voltage75 VDD_2 VDD_2

Ground99 VSS_3 VSS_3

PE0I/O97 TIM4_ETRPE0

PE1I/O98 PE1

I/OPB9 PB996 TIM4_CH4 I2C1_SDACANTX

BOOT0Input94 BOOT0

I/OPB8 PB895 TIM4_CH3 I2C1_SCLCANRX

I/OPB5 PA1091 I2C1_SMBAI TIM3_CH2SPI1_SCK

I/OPB4/JNTRST PA990 PB4 TIM3_CH1SPI1_MOSI

PD3

PD4

I/O USART2_CTS84 PD3

I/O USART2_RTS85 PD4

PB3TRACESWO

I/OPB3/JTDO JTDO89 TIM2_CH2SPI1_SCK

PD2I/O83 TIM3_ETRPD2

PD5

PD6

I/O USART2_TX86 PD5

I/O USART2_RX87 PD6

PD7I/O USART2_CK88 PD7

JTCK/SWCLKI/O76 PA14PA14/JTCK/SWCLK

I/OPB7 PA1093 I2C1_SDATIM4_CH2

USART1_RX

I/OPB6 PA992 I2C1_SCLTIM4_CH1

USART1_TX

OSC_OUT

PC10

PC11

PC12

OSC_IN

อินพุต/เอาตพุต CANTX82 PD1

I/O USART3_TX78 PC10

I/O USART3_RX79I/O USART3_CK80

PC11

PC12

I/O CANRX81 PD0

TIM2_CH1_ETRSPI1_NSS

I/OPA15/JTDI JTDI77 PA15

Pinno. Type Main

functionAlternate function

Default AlternateName

I/O

Page 22: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

22 l JX-STM32 ARM Cortex-M3 microcontroller board

Page 23: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-
Page 24: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 23

We suggest the f ree software tools from Raisonance (www.raiso-nance.com) to develope C programming for STM32 microcontroller.Developers mustregister before download at www.raisonance.com or http://www.mcu-raisonance.com/mcu_downloads.html

The tool set for developing STM32 microcontroller includes 3 main software asfollows :

1. Ride7 IDE for ARM This software tool can be used with a range ofdevelopment tools including: an editor, debugger and project manager that is commonto several ST microcontroller families of ARM cores and which integrates the GNU GCCtoolchain and software-based simulator,

2. Rkit-ARM It includes GNU C compiler which support ARM Cortex M-3from STMicroelectronic and Firmware librarlies.

3 . Flash Loader Demonstrator I t is downloader software fromSTMicroelectronics. User can downlaod free of charge at www.st.com. This tool requires.HEX file from C compiler and downlaod to flash memory of STM32 microcontroller viaUSART port. It can support USB to RS-232 serial port converter.

Figure 2-1 Ride7 main screen

2 : C programming developement forSTM32 micrcontroller

Page 25: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

24 l JX-STM32 ARM Cortex-M3 microcontroller board

Figure 2-2 ARM7 tool download webpage of Raisonance(www.raisonance.com)

Figure 2-3 Flash Loader Demonstrator download webpage of STMicroelectronics(www.st.com)

Page 26: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 25

In the JX-STM32 education board prepares all software tools with CD-ROM thatbundled with the kit.

2.1 Software installationAll Ride7 IDE, Rkit-ARM and Flash Loader require Windows XP SP2 or higher and at

least 500MB harddisk space. Computer must have free a serial (COM) port for interfacingthe JX-STM32 board. Also require USB to RS-232 serial port converter if computer has onlyUSB port. UCON-232S is recommended (www.inexglobal.com)

2.1.1 Ride7 IDE installation(1) Double-click on Ride7 IDE setup file. The title page will appear and click at

Install Ride7 or its components list.

(2) Select location for installation winbdow will appear. Select the installationpath. The default is C:\Program Files\Raisonance\. After that, click on the Start installbutton to start the installation.

(3) Wait for installation complete.

Page 27: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

26 l JX-STM32 ARM Cortex-M3 microcontroller board

2.1.2 Rkit-ARM installation(1) Dopuble the installation file; RKit-ARM_BN45A.exe (the number of file is possible

to change to latest version available). The welcome window is appeared. Click on theNext button.

(2) The License Agreement window is appeared. Click to check at I accept theterms in the license agreement box and click on the Next button. The installation starts.

(3) After the installation is completed, the complete wizard window is appeared.Click on the Finish button. Now, Rkit-ARM suit is ready for developing.

Page 28: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 27

2.2 STM32 documentationAfter the Rkit-ARM and RIDE7 are installed completely. Many documentation are

copied to software installation folder. It includes :

1. STM32F10x_ref_manual.pdf; this manual file location is C:\ProgramFiles\Raisonance\Ride\Doc\ARM\Manuals

2. STM32-LIB_manual.pdf or STM32_Firmware_Library.pdf ; this file describesabout detai l s of STM32 Firmware Library. You can found at C:\ProgramFiles\Raisonance\Ride\Doc\ARM\Manuals a n d C:\Program Files\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\

3. GettingStartedARM_RIDE7.pdf ; this is first manual for developing STM32micrcontroller with RIDE7 and Rkit-ARM. Its location is C:\Program Files\Raisonance\Ride\Doc\ARM

4. Example project file; Raisonance created many example of STM32devices. The reference hardware is STM32F103B-EVAL board (The JX-STM32 is designedfollowing with this evaluation board). Location of all example files are C:\ProgramFiles\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\examples

Page 29: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

28 l JX-STM32 ARM Cortex-M3 microcontroller board

3V batteryfor RTC

- + ON

STM32O

N CANTERMINATE

CANMODE

B8 D2

E6 C11

C10

C9 C8 C7 C6 A8 B15

B14

B13

B12

B11

B10

E7 D15

D13

D11

D10

B1 B0 C5 A4 A3 A2 A1 C3 C2 C1 C0

ON

1

0

1

0BOOT0 BOOT1

0 x USER FLASH1 Embed. SRAM1 System MEM.

10

JTAGRESET

SWD/JTAG

USB

BATT

.

VDD

VBAT RESET

VO

LUM

E

ADCIN14

AMPLIFIER(speaker is

installed at theback side)

JOYSTICK

JX-STM32ARM Cortex-M3 board

LM75Temp.sensor

E2E3E4E5

SDA1 B7SCL1 B6

+3V3

GND+3V3

GND

WAKEUPPA0

TAMPERPC13

SW1PB9

SW2PD7

LED4PC9

LED3PC8

LED2PC7

LED1PC6

UART2

UART1

BOOTLOADER

DC input 6-9V

SD/M

MC

USART2

USART1 anddownload port

JTAGconnector

USB port

CAN port

I2C-basedTemperature sensor

LED

+6 to +9Vdcsupply voltage Power indicator

POWERswitch

POT for A/Dexperiment

SD/MMCsocket

4-directionJoytick switch

GPIO port

Breadboard

128x84 pixelGLCD

Mode switch

CAN bus switch

Figure 2-4 JX-STM32 microcontroller board layout

Page 30: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 29

2.3 JX-STM32 : STM32F103VBT6 microcontroller boardThis education board are designed under supporting by STMicroelectronics Asia

Pacific (Thailand) and ST Microelectronic Business Headquarter Singapore.

The figure 2-4 illustrates the layout of JX-STM32 board.

The technical features of this education board are :

l STM32F103VBT6 main microcontroller

l 128KB Flash memory

l 20KB Static RAM

l 16MHz master crystal. The maximum clock frequency is 72MHz with PLL.

l 32.768kHz crystal for on-chip RTC module

l 2 of USART connector. Support serial data communication anddownloading user code via USART0 port.

l USB2.0 interface

l CAN ubs interfacing circuit with CAN transceiver chip

l 4 of the active low buttons

l 5-ch 4-direction Joystick switch with pull-up resistor

l Audio amplifier with on-board speaker and Volume control

l Graphic module GLCD5110 interfacing circuit

l 8-LED with limited current resistor

l SD catd interfacing

l LM75ADP temperature sensor. interface through I2C bus

l Free port pin for interfacing the real world.

l 350-points breadboard

l Support JTAG port. The suggestion tools are R-Link (Raisonance), U-Link(Keil) and ST-LINK

l Supply voltage +6V 500mA with +3.3V regulator

The full schematic diagram of JX-STM32 board is shown in the figure 2-5 and 2-6.

Page 31: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

30 l JX-STM32 ARM Cortex-M3 microcontroller board

STM

32

F10

3V

BT6

STM

32

Mic

roco

ntr

olle

rA

RM

Cor

tex-

M3

NRS

T14

PA0-

WKU

P/U

SART

2_CT

S/AD

C_IN

0/TI

M2_

CH1_

ETR

23PA

0

PA1/

USA

RT2_

RTS/

ADC_

IN1/

TIM

2_CH

224

PA1

PA2/

USA

RT2_

TX/A

DC_

IN2/

TIM

2_CH

325

PA2

PA3/

USA

RT2_

RX/A

DC_

IN3/

TIM

2_CH

426

PA3

PA4/

SPI1

_NSS

/USA

RT2_

CK/A

DC_

IN4

29PA

4

PA5/

SPI1

_SCK

30PA

5

PA6/

SPI1

_MIS

O31

PA6

PA7/

SPI1

_MO

SI32

PA7

PA8/

USA

RT1_

CK/T

IM1_

CH/M

CO67

PA8

PA9/

USA

RT1_

TX68

PA9

PA10

/USA

RT1_

RX69

PA10

PA11

/USB

DM

70PA

11

PA12

/USB

DP

71PA

12

PA13

/JTM

S-SW

DAT

72PA

13

PA14

/JTC

K-SW

CLK

76PA

14

PA15

/JTD

I77

PA15

PB0/

ADC_

IN8/

TIM

4_CH

335

PB0

PB1/

ADC_

IN9/

TIM

4_CH

436

PB1

PB2/

BOO

T137

PB2

PB3/

JTD

O89

PB3

PB4/

JTRS

T90

PB4

PB5/

I2C1

_SM

BA1

91PB

5

PB6/

I2C1

_SCL

/TIM

4_CH

192

PB6

PB7/

I2C1

_SD

A/TI

M4_

CH2

93PB

7

PB8/

TIM

4_CH

395

PB8

PB9/

TIM

4_CH

496

PB9

PB10

/I2C

2_SC

L/U

SART

3_TX

47PB

10

PB11

/I2C

2_SC

K/U

SART

3_RX

48PB

11

PB12

/SPI

2_N

SS/I

2C2_

SMBA

I/U

SART

3_CK

/TIM

1_BK

IN51

PB12

PB13

/SPI

2_SC

K/U

SART

3_CT

S/TI

M1_

CH1N

52PB

13

PB14

/SPI

2_M

ISO

/USA

RT3_

RTS/

TIM

1_CH

2N53

PB14

PB15

/SPI

2_M

OSI

/TIM

1_CH

3N54

PB15

PA1

PA2

PA3

PA4

PA8

PA10

/ R

XD1

USB

D-

USB

D+

TMS

/ SW

DIO

TCK

/ SW

CLK

TDI

PB0

PB1

PA9

/ TX

D1

TDO

/ S

WO

TRST

PB6

/ SC

L1PB

7 /

SDA1

PB5

/ IN

T

PB10

PB11

PB12

PB13

PB14

PB15

PB8

10k

+3.

3V

BO

OT1

JX-S

TM32

Sch

emat

icM

ain

sh

eet

Rev

isio

n 1

.0

20

08

-05

-05

shee

t 1

of

2

BOO

T094

BOO

T010

k

+3.

3V

BO

OT0

RES

ET10

0nF

+3.

3V

10k

RESE

TSD

SCK

SD M

OSI

SD M

ISO

PC0/

ADC_

IN10

15PC

0

PC1/

ADC_

IN11

16PC

1

PC2/

ADC_

IN12

17PC

2

PC3/

ADC_

IN13

18PC

3

PC4/

ADC_

IN14

33PC

4

PC5/

ADC_

IN15

34PC

5

PC6

63PC

6

PC7

64PC

7

PC8

65PC

8

PC9

66PC

9

PC10

78PC

10

PC11

79PC

11

PC12

80PC

12

PC13

/AN

TI_T

AMP

7PC

13

PC1

PC2

PC3

PC8

PC11

XTAL

32.7

68KH

z

PC15

-OSC

32_O

UT

PC14

-OSC

32_I

N8 9

PC0

PC6

PC7

PC9

PC10

PC5

SD C

S1k

x 4

LED4

LED3

LED2

LED1

+3.

3V

AD

C_

IN1

4

TAM

PER

100n

F

+3.

3V

10k

PD0/

CAN

_RX

81

PD1/

CAN

_TX

82

PD2

83

PD3/

USA

RT2_

CTS

84

PD4/

USA

RT2_

RTS

85

PD5/

USA

RT2_

TX86

PD6/

USA

RT2_

RX87

PD7

88

PD8

55

PD9

56

PD10

57

PD11

58

PD12

59

PD13

60

PD14

61

PD15

62

PE0

97

PE1

98

PE2

1

PE3

2

PE4

3

PE5

4

PE6

5

PE7

38

PE8

39

PE9

40

PE10

41

PE11

42

PE12

43

PE13

44

PE14

45

PE15

46

PE2

PE3

PE4

PE5

PE6

PE7

1kP

E2

PE3

PE4

PE5

1k 1k 1k

330 47

k

+3.

3V

+3.

3V

GLC

D 5

110

GLC

D B

ACKI

GH

TG

LCD

CLK

GLC

D D

ATA

GLC

D D

/CG

LCD

RES

GLC

D C

E

PD2

PD4

/ RT

S2

PD3

/ CT

S2

PD6

/ RX

D2

PD5

/ TX

D2

JOY

UP

JOY

RIG

HT

JOY

LEFT

USB

DIS

CON

NEC

T

JOY

CEN

TER

JOY

DO

WN

PD11

PD13

PD15

SW

210

0nF

+3.

3V

10k

SPEA

KER

SW

110

0nF

+3.

3V

10k

MM

BT22

22A

VBAT

6

+3.

3V

BA

TTER

YC

R2

03

2

BA

TT.

+3

.3V

VDD

A22

VREF

+21

BEAD

1.8u

H

47

100n

F

100n

F10

uF

+3.

3V

VREF

-20

LIN

K

VSSA

19

+3.

3V

WA

KEU

P10

0nF

220k

330

+3.

3V

VSS1

49

VSS2

74

VSS3

99

VSS4

27

VSS5

10

100n

F x

5

75 VDD

2

50 VDD

1

100 VD

D3

28 VDD

4

11 VDD

5

OSC

_IN

12

OSC

_OU

T13

20pF

XTAL

8MH

z

1M

20pF

12

INO

UT

4IN

HG

ND

3

KIA

27

8R

33

1000

uF6.

3V

+3.

3V

1k

PO

WER

470u

F16

V

PO

WER

SW

ITC

H

DC.

INPU

T

3 2

14

AC. A

dapt

er I

NPU

T(9

to

12 V

DC.

)

CAN

_TX

CAN

_RX

PD10

BO

OT0

BO

OT1

Mod

e

0X

Use

r FL

AS

H

11

Emb

edd

ed S

RA

M

10

Sys

tem

Mem

ory

24681012141618201719 1315 911 57 13

+3.

3V+

3.3V

DBG

ACK

DBG

RQN

RST

TDO

VREF

VTG

T

100n

F

TRST

TMS

TDI

TCK

RTCK

10k

x 4

10k

x 4

+3.

3V TDO

/SW

O

RESE

T

TCK/

SWCL

KTM

S/SW

DIO TD

ITR

ST

JTA

G /

SW

D2

0 p

inJT

AG

RES

ET

PB8

PD2PE6

PC11PC10PC9

PC8PC7PC6PA8

PB15PB14

PB13PB12PB11PB10

PE7PD15PD13PD11PD10

PB1PB0PC5PA4PA3

PA2PA1PC3PC2PC1

PC0

PE2

PE3

PE4

PE5

PB7

/ SD

A1PB

6 /

SCL1

+3.

3V

Con

nec

tion

Pin

out

JTA

G /

SW

D

SD P

ROTE

CTSD

PRE

SEN

T

Figure 2-5 JX-STM32 schematic (Microcontroller section with GLCD5110)

Page 32: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 31

JX-S

TM3

2 S

chem

atic

Per

iph

eral

Rev

isio

n 1

.0

20

08

-05

-05

shee

t 2

of

2

16

2 3 4 5

7 8 9

DB

-9 F

emal

eU

SAR

T1(B

ootl

oade

r)

R2O

UT

9T2

IN10

R2I

NT2

OU

T87

MA

X3

23

2C

SE

+3.

3V

TX O

UT

RX

INPA

10 /

RXD

1PA

9 /

TXD

1

C1-

3

C1+

1

100n

F

C2-

5

C2+

4

100n

F

V-6

100n

F

V+2

100n

F

VCC

GN

D

100n

F

1615

16

2 3 4 5

7 8 9

R1O

UT

12T1

IN11

R1I

NT1

OU

T1314

MA

X3

23

2C

SE

+3.

3V

TX O

UT

RX

INPD

6 /

RXD

2PD

5 /

TXD

2

C1-

3

C1+

1

100n

F

C2-

5

C2+

4

100n

F

V-6

100n

F

V+2

100n

F

VCC

GN

D

100n

F

1615

DB

-9 F

emal

eU

SAR

T2

RTS

CTS

R2O

UT

9T2

IN10

R2I

NT2

OU

T87

PD3

/ CT

S2PD

4 /

RTS

2

SPEA

KER

USA

RT1

Inte

rfac

e

USA

RT2

Inte

rfac

e

1k5

100n

F

Vo

lum

e

50k

10k

100n

FO

UT1

1

VCC

GN

D

IN2+

IN1+

67 5

2

TD

A2

82

2D

4

IN2-

10k

8IN

1-

100n

F

10uF

10uF

+3.

3V

OU

T23

SP

EA

KE

R8

Oh

m0

.25

W.

PB6

/ SC

L1O

S/IN

T3

SCL

2

PB5

/ IN

T

PB7

/ SD

A1SD

A1

+3.

3V

4k7

x 3

VDD

VSS

A2A1A0

100n

F

567 4

8

LM7

5A

Tem

pera

ture

Sens

orI2

C In

terf

ace

59

4 3 2 1

8 7 6DB

-9 M

ale

CAN

Con

nect

or

CA

NT

ER

MIN

AT

E

120

1/4W

.

R4

D1

+3.

3V

VDD

VSS

CAN

LCA

NH

RS

100n

F

678 5

3

SN

65

HV

D3

20

2

2.2k

10k

CA

N M

OD

E

CAN

_RX

CAN

_TX

CAN

BU

SIn

terf

ace

VREF

12

3

Jum

per

1-2

2-3

Op

en

Mo

de

Hig

h-s

pee

d M

od

e

Sta

nd

by

Mo

de

Slo

pe

con

tro

l Mo

de

JOY

UP

JOY

LEFT

JOY

RIG

HT

JOY

CEN

TER

JOY

DO

WN

SWIT

CH5-

Way

JOYS

TICK

10k

x 5

+3.

3V

UP

COM

CEN

TER

LEFT D

OW

NR

IGH

T

USB

D+

USB

D-

27 27

1k5

+3.

3V

MM

BT22

22A

47k

10k

4.7k

USB

DIS

CON

NEC

T

47k

USB

MM

BT22

22A

100n

F

+3.

3V

USB

Inte

rfac

e

GNDD+D-

VUSB

US

B1k5

9 1 2 3 4 5 6 7 8

1011

CS DI

VSS

VDD

CLK

VSS2 DO

CAR

D P

RES

ENT

CAR

D U

NLO

CKSD

PR

OTE

CTSD

PR

ESEN

T

SD M

OSI

SD S

CK

SD C

S

SD M

ISO

RSV

RSV

10k

x 6

+3.

3V

SD C

AR

D S

OCK

ET

CASE

100n

FSD

CA

RD

Inte

rfac

e

Figure 2-6 JX-STM32 schematic (Input/Output devices and RS-232 intrerfacediagram)

Page 33: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

32 l JX-STM32 ARM Cortex-M3 microcontroller board

2.4 How to develop STM32 project file with RIDE7The first example of STM32 developing with RIDE7 demonstrates the blinking LED

at PC6 port.

(1) Open Ride7 tool. Select menu Project àNew Project for creating the newproject file.

(2) The new application window is appeared. Select the target microcontroller,Porject file name and location following the picture below.

(2.1) Type : Select New application to be built (It is default)

(2.2) Processsor : Select the target microcontroller as STMF103VBT6

(2.3) Name : Set the project file name as LedBlink

Page 34: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 33

(2.4) Lacation : Set the project file’s location. This example is C:\LedBlink.Suggest to create the LedBlink folder first.

(2.5) Click on the Finish button.

(3) Copy the 3 of important header files as follows to same target folder.

l stm32f10x_conf.h ; the original location of this f i le isC:\ProgramFiles\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\project

l stm32f10x_vector.c ·the original location of this f i le isC:\ProgramFiles\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\project\RIDE

l stm32f10x_it.h the original location of this file is C:\ProgramFiles\Raisonance\Ride\Lib\ARM\STM32F10x_LIB\project

Note : Copying files in this step is important. Suggest to do always whencreate the new project file.

Page 35: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

34 l JX-STM32 ARM Cortex-M3 microcontroller board

(4) Create the C source file by select menu File à Source File.

(5) Type C code following the Listing 2-1 into editor space.

(6) Save file with select menu File à Save as... Define the name as LedBlink.cand store in same folder of stm32f10x_conf.h file. Select tab Source File. The saved filename will be appear.

(7) Includes the C Souce File and stm32f10x_vector.c file into the project file. Clickthe right button mouse at LedBlink root . Select menu Add…à Existing Item…followingthe picture below. Allow to select each or both files. Next, select menu Add...à ExistingItem...

Page 36: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 35

#include “stm32f10x_lib.h” // Include STM32 header filevoid delay(unsigned long ms)// delay 1 ms per count @ Crystal 8.0 MHz and PLL9x or SYSCLK = 72 MHz{

volatile unsigned long i,j;for (i = 0; i < ms; i++ )for (j = 0; j < 5525; j++ );

}void RCC_setup(void){ ErrorStatus HSEStartUpStatus; // Keep error status RCC_DeInit(); // RCC system reset(for debug purpose) RCC_HSEConfig(RCC_HSE_ON); // Enable HSE HSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is ready if(HSEStartUpStatus == SUCCESS) { RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2 FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait state FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable Prefetch Buffer RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

// PLLCLK = 8MHz * 9 = 72 MHz

RCC_PLLCmd(ENABLE); // Enable PLL while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

// Wait until PLL is ready

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);// Select PLL as system clock source

while(RCC_GetSYSCLKSource() != 0x08);// Wait till PLL is used as system clock source

}}void GPIO_setup(){ GPIO_InitTypeDef GPIO_InitStructure; // Enable GPIOC clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);

// Configure PC6,PC7,PC8 and PC9 as Output push-pull(connect with LED)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure);}int main(){ RCC_setup(); // System Clocks Configuration GPIO_setup(); // GPIO ports configuration while(1) // Infinite loop { GPIO_WriteBit(GPIOC, GPIO_Pin_6,1); // LED at PC6 ON delay(500); // Delay 0.5 sec GPIO_WriteBit(GPIOC, GPIO_Pin_6,0); // LED at PC6 OFF delay(500); // Delay 0.5 sec }}

Listing 2-1 LEDBlink.c file; the first example file demonstrates LED blinkingat PC6 port of STM32F103VBT6 on the JX-STM32 board

Page 37: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

36 l JX-STM32 ARM Cortex-M3 microcontroller board

(8) The file selection window is appeared. Select both files LedBlink.c andstm32f10x_vector.c.

(9) After including, LedBlink.c and stm32f10x_vector.c file will included to theproject file follwing the file nevigator on the left.

Page 38: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 37

(10) Next, set the properties for preparing the proejct filr to compilation. Selectmenu Project à Properties

Extend the LD Linker. Click to select Startup and set 2 parameters as follows :

(10.1) At Use Default Startup set No

(10.2) At Startup File, delect the previous file to empty space.

(11) Back to LD Linker root again. Click the Scripts to set item Starter Kit Limitationas No. This step is important. It is allowing the compiling to full range of microcontrollerusage. Click on the Close button to confirm the setting.

Page 39: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

38 l JX-STM32 ARM Cortex-M3 microcontroller board

(12) Compile the project file by select menu Project à Build Project.

(13) The Build log area will show message “Build successful”.

(14) The result file; LedBlink.hex is created in same folder of the project file. Thishex file will be downloaded to flash memory of STM32 microcontroller later.

Page 40: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 39

2.5 Download and testing....(1) Apply the supply voltage to the JX-STM32 board. Turn-on the POWER switch.

The LED power indicator is turned on.

(2) Connect the downlaod cable to USART1 port of the JX-STM32 board andCOM port. If your computer have only USB port; the USB to RS-232 port converter ierequired. UCON-232S is recommended.

(3) Open the Flash loader demonstator software.

(4) Set the parameter for firsting downloading.

(4.1) Port Name - Select the COM port.

(4.2) Baud Rate - Set the baud rate as 115200 bit per second.

(4.3) Data Bit - Set length of data as 8 bits.

(4.4) Parity - Set parity checking as None.

(4.5) Stop Bit - Set the Stop bit as 1 bit.

(4.6) Timeout(s) - Set time out value as 5 seconds

After setting, all parameter will exist for next operation. User can changeanytime.

Page 41: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

40 l JX-STM32 ARM Cortex-M3 microcontroller board

(5) Set the JX-STM32 to Program mode. Set the BOOT0 jumper switch to ‘1’ position,BOOT1 jumper switch set to ‘0’ position and press RESET swtich at once.

1

0

1

0BOOT0 BOOT1

0 x USER FLASH1 Embed. SRAM1 System MEM.

10

(6) At Flash loader demonstator software, click on the Next button at once. Ifthe communication is completed, the main window will reprt the memory size of targetmicrocontroller. This example is 128KB flash and 20KB RAM. Click on the Next button tonext step.

If not, the error dialogue box will appear. Developer must back to check allconnection, communication parameter setting and COM port violation.

Page 42: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 41

(7) Flash loader demonstator software reports the target microcontrollerinformation following the picture below. You can set the code protection option at thiswindow. Click on the Next button to next step.

(8) Downloading window will appear. Check the Download to device box. Selectfile LedBlink.hex from path C:\LedBlink\LedBlink.hex and click on the Next button tostart the downloading.

Page 43: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

42 l JX-STM32 ARM Cortex-M3 microcontroller board

(9) Next, the Flash loader demonstator software will enter to downloading modeand shows download progress.

(10) After complete, it reports the target microcontroller information, path ofhex file and usage memoory size.

Page 44: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 43

(11)Run the downloaded code. Set the BOOT0 and BOOT1 jumper switch to ‘0’postion and press RESET swith at once to run the program.

1

0

1

0BOOT0 BOOT1

0 x USER FLASH1 Embed. SRAM1 System MEM.

10

(12) Observe the operation on the JX-STM32 board

LED at PC6 of JX-STM32 board is blinked continuous.

STM32

ON

CANTERMINATE

CANMODE

ON

1

0

1

0BOOT0 BOOT1

0 x USER FLASH1 Embed. SRAM1 System MEM.

10

JTAGRESET

SWD/JTAG

USB

VO

LUM

E

ADCIN14

JOYSTICK

JX-STM32ARM Cortex-M3 board

WAKEUPPA0

TAMPERPC13

SW1PB9

SW2PD7

LED4PC9

LED3PC8

LED2PC7

LED1PC6

SD

/MM

C

Page 45: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

44 l JX-STM32 ARM Cortex-M3 microcontroller board

2.6 Openning the exist file to editIn case developer requires to edit the exist project file. Select the menu Project

à open Project and select to path of target project file. The RIDE7 project file surnameis *.rprj.

For example, open the LedBlink project file to develop. Open this project filefollowing the picture below. After that, edit the C source file or change anythingdepends on demand.

Page 46: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-
Page 47: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 45

STM32 microcontroller contains many peripheral modules. Each module hasindependent clock source. Figure 3-1 show the clock system of STM32F103VBT6.

8MHzHSI-RC

(High speedinternal RC clock)

÷2

PLLSRC

PLLx2,x4,...,x16

SW

AHB prescaler÷1, ¸2,.., ¸512

APB1 prescaler÷1, 2, 4, 8, 16 PCLK1

to APB1 bus

Clock SecuritySystem(CSS)

PLLXTPRE

4 to 16MHz HSE(High speed external

clock)

RTCSEL[1:0]

÷12832.768kHz LSE(Low speed external

clock)

÷2

40kHz LSI-RC(Low speed internal

RC clock)

LSI

LSE RTCCLKclock to RTC

clock to IWDGIWDGCLK

HSE

PLLCLK

HSI

USB prescaler÷1, ÷1.5

÷8

Peripheral clockenable (3-bit)

freq. = 48MHz

TIM2,3,4multiplier x1, 2

36MHz max

APB2 prescaler¸1, 2, 4, 8, 16

TIMxCLKto TIM2,3,4

Peripheral clock enable (13-bit)

Peripheral clock enable (3-bit)

PCLK2to APB2 bus

72MHzmax.

TIM1multiplier x1, 2 TIM1CLK

to TIM1

Peripheral clock enable (1-bit)

Peripheral clock enable (11-bit)

ADC prescaler¸2, 4, 6, 8

ADCCLKto ADC module

USBCLKto USB portinterfacing circuit

72MHz max.HCLKto AHB, DMA andmemory

System timer

FCLKFree running clock

SYSCLK f(max) 72MHz

÷2 PLLCLK

HSI

HSE

SYSCLK

MCO

Main clock outputMCO

OSC32_OUT

OSC32_IN

OSC_IN

OSC_OUT

Figure 3-1 STM32F103VBT6 clock system diagram

3 : STM32 clock system

Page 48: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

46 l JX-STM32 ARM Cortex-M3 microcontroller board

3.1 STM32 clock system operationThree different clock sources can be used to drive the system clock (SYSCLK):

l HSI oscillator clock

l HSE oscillator clock

l PLL clock

The devices have the following two secondary clock sources:

l 40 kHz low speed internal RC (LSI RC) which drives the independentwatchdog and optionally the RTC used for Auto Wakeup from Stop/Standby mode.

l 32.768 kHz low speed external crystal (LSE crystal) which optionally drivesthe realtime clock (RTCCLK)

Each clock source can be switched on or off independently when it is not used,to optimize power consumption.

Refer clock system diagram in figure 3-1, developer selects the system clockfrom 3 clock sources HSI, HSE or PLLCLK. The maximum clokc frequency is 72MHz (withPLL). After that set the prescaler value for setting the peripheral clock or HCLK to AHB(Advanced high speed bus).

Both APB1 (Advance Peripheral Bus 1) and APB2 (Advance Peripheral Bus 2)can set the prescaler value to generate the peripheal clock. The maximum frequencyof APB1 bus is 36MHz and APB2 bus clock frequency is 72MHz maximum.

Peripherla module on APB1 bus consist of :

l TIM2 (Timer 2)

l TIM3 (Timer 3)

l TIM4 (Timer 4)

l WWDG (Window Watchdog)

l SPI2 (Serial Peripheral Interface 2)

l USART2 (Universal Synchronous Asynchronous Receiver Transmitter 2)

l USART3 (Universal Synchronous Asynchronous Receiver Transmitter 3)

l I2C1 (I2C bus module 1)

l I2C2 (I2C bus module 1)

l USB (Universal Serial bus)

l CAN (Control Area Network)

l BKP (Backup register)

l PWR (Power control module)

Page 49: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 47

Peripherla module on APB2 bus consist of :

l GPIOA (General purpose I/O A)

l GPIOB (General purpose I/O B)

l GPIOC (General purpose I/O C)

l GPIOD (General purpose I/O D)

l GPIOE (General purpose I/O E)

l ADC1 (Analog to Digtial Converter 1)

l ADC2 (Analog to Digtial Converter 2)

l TIM1 (Timer 1)

l SPI1 (Serial Peripheral Interface 1)

l USART1 (Universal Synchronous Asynchronous Receiver Transmitter 1)

The system clock (SYSCLK) is limited to 64MHz maximum when select the clocksource as HSI and PLL

3.2 Reset and Clock control registerEach peripheral module of STM32 devices has independent clock source. The

control register group is RCC (Reset and Clock Contol) register. They consist of 10 controlregisters as follows :

1. RCC_CR : Clock control register

2. RCC_CFGR : Clock configuration register

3. RCC_CIR : Clock interrupt register

4. RCC_APB2RSTR : APB2 Peripheral reset register

5. RCC_APB1RSTR : APB1 Peripheral reset register

6. RCC_AHBENR : AHB Peripheral Clock enable register

7. RCC_APB2ENR : APB2 Peripheral Clock enable register

8. RCC_APB1ENR : APB1 Peripheral Clock enable register

9. RCC_BDCR : Backup domain control register

10. RCC_CSR : Control/status register

See STM32 reference manual for details of all registers. Free downlaod from

www.st.com.

Page 50: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

48 l JX-STM32 ARM Cortex-M3 microcontroller board

3.3 RCC Register structureRCC register is defined in RCC_TypeDef within stm32f10x_map.h file. It is included

within the header file stm32f10x_lib.h. The detail are as follows :typedef struct{

vu32 CR;vu32 CFGR;vu32 CIR;vu32 APB2RSTR;vu32 APB1RSTR;vu32 AHBENR;vu32 APB2ENR;vu32 APB1ENR;vu32 BDCR;vu32 CSR;

} RCC_TypeDef;

STMicroelectronics create the firmware library for each important module includesRCC group register. See full information in the STM32_Firmware_Library.pdf file inC:\Program Files\Raisonance\Ride\lib\ARM\STM32F10x_LIB folder after RIDE7 isinstalled.

3.4 RCC library functionAccessing all function of RCC firmware libraries, developer must copy the

stm32f10x_conf.h into the target project folder and declare the RCC firmware libraryby command #define _RCC at the header file.

There are 15 firmware library funnction for RCC regiater. However this chapterwill describe only some nescessary function as follows :

3.4.1 RCC_DeInitResets the RCC clock configuration to the default reset state.

Syntaxvoid RCC_DeInit(void)

Parameter

None

3.4.2 RCC_HSEConfigConfigures the External High Speed oscillator (HSE).

Syntaxvoid RCC_HSEConfig(u32 RCC_HSE)

ParameterRCC_HSE could be set the value as follows :

Page 51: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 49

RCC_HSE_OFF - HSE oscillator offRCC_HSE_ON - HSE oscillator onRCC_HSE_Bypass -HSE oscillator bypassed with external clock

3.4.3 RCC_WaitForHSEStartUpWaits for HSE start-up.

SyntaxErrorStatus RCC_WaitForHSEStartUp(void)

Parameter

SUCCESS - HSE oscillator is stable and ready to useERROR - HSE oscillator not yet ready

3.4.4 RCC_HSICmdEnables or disables the Internal High Speed oscillator (HSI).

Syntaxvoid RCC_HSICmd(FunctionalState NewState)

Parameter

NewState This parameter can be:ENABLE - Disable HSIDISABLE - Enable HSI

3.4.5 RCC_PLLConfigConfigures the PLL clock source and multiplication factor.

Syntaxvoid RCC_PLLConfig(u32 RCC_PLLSource, u32 RCC_PLLMul)

Parameter

RCC_PLLSource This parameter can be:RCC_PLLSource_HSI_Div2 - select clokc source as HSI/2RCC_PLLSource_HSE_Div1 - select clokc source as HSERCC_PLLSource_HSE_Div2 - select clokc source as HSE/2

RCC_PLLMul This parameter can be set 2 to 16RCC_PLLMul_2 - PLL clock entry x 2

Page 52: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

50 l JX-STM32 ARM Cortex-M3 microcontroller board

.

.RCC_PLLMul_16 - PLL clock entry x 16

3.4.6 RCC_PLLCmdEnables or disables the PLL module

Syntaxvoid RCC_PLLCmd(FunctionalState NewState)

Parameter

NewState This parameter can be:ENABLE - Enable PLLDISABLE - Disable PLL

3.4.7 RCC_SYSCLKConfigConfigures the system clock (SYSCLK).

Syntaxvoid RCC_SYSCLKConfig(u32 RCC_SYSCLKSource)

Parameter

RCC_SYSCLKSource This parameter can be:RCC_SYSCLKSource_HIS - HSI selected as system clockRCC_SYSCLKSource_HSE - HSE selected as system clockRCC_SYSCLKSource_PLLCLK - PLL selected as system clock

3.4.8 RCC_GetSYSCLKSourceReturns the clock source used as system clock.

Syntaxu8 RCC_GetSYSCLKSource(void)

Parameter

NoneRetun value

Page 53: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 51

0x00 - HSI used as system clock0x04 - HSE used as system clock0x08 - PLL used as system clock

3.4.9 RCC_HCLKConfigConfigures the AHB clock(HCLK).

Syntaxvoid RCC_HCLKConfig(u32 RCC_HCLK)

Parameter

RCC_HCLK This parameter can be :RCC_SYSCLK_Div1 - AHB clock = SYSCLKRCC_SYSCLK_Div2 - AHB clock = SYSCLK/2RCC_SYSCLK_Div4 - AHB clock = SYSCLK/4RCC_SYSCLK_Div8 - AHB clock = SYSCLK/8RCC_SYSCLK_Div16 - AHB clock = SYSCLK/16RCC_SYSCLK_Div64 - AHB clock = SYSCLK/64RCC_SYSCLK_Div128 - AHB clock = SYSCLK/128RCC_SYSCLK_Div256 - AHB clock = SYSCLK/256RCC_SYSCLK_Div512 - AHB clock = SYSCLK/512

3.4.10 RCC_PCLK1ConfigConfigures the Low Speed APB clock (PCLK1).

Syntaxvoid RCC_PCLK1Config(u32 RCC_PCLK1)

Parameter

RCC_PCLK1 This parameter can be :RCC_HCLK_Div1 - APB1 clock = HCLKRCC_HCLK _Div2 - APB1 clock = HCLK/2

Page 54: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

52 l JX-STM32 ARM Cortex-M3 microcontroller board

RCC_HCLK_Div4 - APB1 clock = HCLK/4RCC_HCLK_Div8 - APB1 clock = HCLK/8RCC_HCLK_Div16 - APB1 clock = HCLK/16

3.4.11 RCC_PCLK2ConfigConfigures the High Speed APB clock (PCLK2).

Syntaxvoid RCC_PCLK2Config(u32 RCC_PCLK2)

Parameter

RCC_PCLK2 This parameter can be :RCC_HCLK_Div1 - APB2 clock = HCLKRCC_HCLK _Div2 - APB2 clock = HCLK/2RCC_HCLK_Div4 - APB2 clock = HCLK/4RCC_HCLK_Div8 - APB2 clock = HCLK/8RCC_HCLK_Div16 - APB2 clock = HCLK/16

3.4.12 RCC_GetFlagStatusChecks whether the specified RCC flag is set or not

SyntaxFlagStatus RCC_GetFlagStatus(u8 RCC_FLAG)

Parameter

RCC_FLAG This parameter can be :RCC_FLAG_HSIRDY - HSI oscillator clock readyRCC_FLAG_HSERDY - HSE oscillator clock readyRCC_FLAG_PLLRDY - PLL clock readyRCC_FLAG_LSERDY - LSE oscillator clock readyRCC_FLAG_LSIRDY - LSI oscillator clock readyRCC_FLAG_PINRST - Pin resetRCC_FLAG_PORRST - Power-On reset and Power-Down resetRCC_FLAG_SFTRST - Software resetRCC_FLAG_IWDGRST - Independent watchdog resetRCC_FLAG_WWDGRST - Window watchdog reset

Page 55: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 53

RCC_FLAG_LPWRRST - Low power resetReturn value

SET - State of RCC flag is setRESET - State of RCC flag is reset (not set)

3.4.13 RCC_AHBPeriphClockCmdEnables or disables the AHB peripheral clock.

Syntaxvoid RCC_AHBPeriphClockCmd(u32 RCC_AHBPeriph,FunctionalState NewState)

Parameter

RCC_AHBPeriph This parameter can be :RCC_AHBPeriph_DMA - DMA clockRCC_AHBPeriph_SRAM - SRAM clockRCC_AHBPeriph_FLITF - Flash memory interface clock

NewState This parameter can be :ENABLE or DISABLEOnly RCC_AHBPeriph_SRAM and RCC_AHBPeriph_FLIT can be disabled only

during sleep mode.3.4.14 RCC_APB2PeriphClockCmd

Enables or disables the High Speed APB (APB2) peripheral clock.

Syntaxvoid RCC_APB2PeriphClockCmd(u32 RCC_APB2Periph,FunctionalState NewState)

Parameter

RCC_APB2Periph This parameter can be :RCC_APB2Periph_AFIO - Alternate function I/O module clockRCC_APB2Periph_GPIOA - GPIOA module clockRCC_APB2Periph_GPIOB - GPIOB module clockRCC_APB2Periph_GPIOC - GPIOC module clockRCC_APB2Periph_GPIOD - GPIOD module clockRCC_APB2Periph_GPIOE - GPIOE module clockRCC_APB2Periph_ADC1 - ADC1 clockRCC_APB2Periph_ADC2 - ADC2 clockRCC_APB2Periph_TIM1 - TIM1 clockRCC_APB2Periph_SPI1 - SPI1 clock

Page 56: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

54 l JX-STM32 ARM Cortex-M3 microcontroller board

RCC_APB2Periph_USART1 - USART1 clockRCC_APB2Periph_ALL - All APB2 peripheral clock

NewState This parameter can be :ENABLE or DISABLE

3.4.15 RCC_APB1PeriphClockCmdEnables or disables the Low Speed APB (APB1) peripheral clock.

Syntaxvoid RCC_APB1PeriphClockCmd(u32 RCC_APB1Periph,FunctionalState NewState)

Parameter

RCC_APB1Periph This parameter can be :RCC_APB1Periph_TIM2 - Timer2 clockRCC_APB1Periph_TIM3 - Timer3 clockRCC_APB1Periph_TIM4 - Timer4 clockRCC_APB1Periph_WWDG - Window watchdog clokcRCC_APB1Periph_SPI2 - SPI2 clockRCC_APB1Periph_USART2 - USART2 clockRCC_APB1Periph_USART3 - USART3 clockRCC_APB1Periph_I2C1 - I2C1 clockRCC_APB1Periph_I2C2 - I2C2 clockRCC_APB1Periph_USB - USB clockRCC_APB1Periph_CAN - CAN clockRCC_APB1Periph_BKP - Backup register clockRCC_APB1Periph_PWR - Power controller interface clockRCC_APB1Periph_ALL - All APB1 peripheral clock

NewState This parameter can be :ENABLE or DISABLE

Page 57: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 55

3.5 Setting latency time of FLASH_ACR registerThe system clock (SYSCLK) setting effects to latency time of flash memory access

time corresponding with CPU processing as follows :

0 wait state : no wait state if SYSCLK frequency as 0 to 24MHz

1 wait state : set 1 wait state if SYSCLK frequency as 24 to 48MHz

2 wait states : set 2 wait state SYSCLK frequency as 48 to 72 MHz

Setting the latency time can with write the data to FLASH_ACR register pass thefirmware library as follows :

3.5.1 FLASH_SetLatencySets the code latency value.

Syntaxvoid FLASH_SetLatency(u32 FLASH_Latency)

Parameter

FLASH_Latency This parameter can be :FLASH_Latency_0 - set 0 wait stateFLASH_Latency_1 - set 1 wait stateFLASH_Latency_2 - set 2 wait state

3.5.2 FLASH_PrefetchBufferCmdEnables or disables the Prefetch Buffer.

Syntaxvoid FLASH_PrefetchBufferCmd(u32 FLASH_PrefetchBuffer)

Parameter

FLASH_PrefetchBuffer ก ําหนดค าได ดั งนี ้FLASH_PrefetchBuffer_Enable - enable the Prefetch BufferFLASH_PrefetchBuffer_Disable - disable the Prefetch Buffer

Page 58: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

56 l JX-STM32 ARM Cortex-M3 microcontroller board

3.6 Setting the system clockEvery developing the code or application of STM32, first step is setting the system

clock frequency. It relates the RCC configuration setting and FLASH_ACR.

3.6.1 Procedure summary(1) Enable the external high speed clock (HSE) or intermal high speed clock

(HSI).

(2) Poll to check the ready flag of clock source.

(3) After the system clock is in the steady state, set the properties of all peripheralmodule in STM32.

(4) Set the Latency time

(5) If requires PLL for clock source, do these step following.

(5.1) Set the clock source fro PLL

(5.2) Set the clock multiplier (2 to 16)

(5.3) Enable PLL

(5.4) Poll to check PLL ready

(6) Select the system clock source

(7) Wait untill the system clock ready.

3.6.2 Example code of steeing the system clock for STM32Example 1 : Select HSI to SYSCLK clock source (8MHz). Set the function name as

RCC_setup1. The exmaple C code is shown below :

#include <stm32f10x_lib.h> // Header file for STM32void RCC_setup1(){

RCC_DeInit();RCC_HSICmd(ENABLE); // Enable internal 8MHz clock sourcewhile(RCC_GetFlagStatus(RCC_FLAG_HSIRDY)==RESET);

// Wait until HIS readyRCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK= SYSCLK = 8 MHzRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2= HCLK/1= 8 MHzRCC_PCLK1Config(RCC_HCLK_Div2); // PCLK2= HCLK/2= 4 MHzRCC_ADCCLKConfig(RCC_PCLK2_Div2); // ADCCLK= PCLK2/2=4 MHzFLASH_SetLatency(FLASH_Latency_0); // Set latency time as 0 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable PrefetchBufferRCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); // Select HSI as the system clockwhile(RCC_GetSYSCLKSource()!=0x00); // Wait the system clock ready

}int main(){

RCC_setup1(); // Start with setting the clock source........................

}

Page 59: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 57

Example 2 : Select HSE to SYSCLK clock source. Set the function name asRCC_setup2. The exmaple C code is shown below :

#include <stm32f10x_lib.h> // Header file for STM32void RCC_setup2(){

ErrorStatus HSEStartUpStatus; // Declare ErrorStatus variableRCC_DeInit();RCC_HSEConfig(RCC_HSE_ON); // Enable HSE clock sourceHSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait HSE readyif(HSEStartUpStatus==SUCCESS) // Check HSE ready{

RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK/1RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK2 = HCLK/2RCC_ADCCLKConfig(RCC_PCLK2_Div6); // ADCCLK = PCLK2/6FLASH_SetLatency(FLASH_Latency_0);

// Set Latency time as 0 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable PrefetchBufferRCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);

// Select HSE as system clockwhile(RCC_GetSYSCLKSource()!=0x04);

// Wait clock source ready}

}int main(){

RCC_setup2();........................

}

Page 60: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

58 l JX-STM32 ARM Cortex-M3 microcontroller board

Example 3 : Select HSE to SYSCLK clock source. The crystal clock frequency is8MHz. Enable PLL to multiply frequrecny 9 times as the system clock frequency 72MHz.Set the function name as RCC_setup3.. The exmaple C code is shown below :

#include <stm32f10x_lib.h> // Header file for STM32void RCC_setup3(){

ErrorStatus HSEStartUpStatus; // Declare ErrorStatus variableRCC_DeInit();RCC_HSEConfig(RCC_HSE_ON); // Enable HSEHSEStartUpStatus = RCC_WaitForHSEStartUp();if(HSEStartUpStatus == SUCCESS){

RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK/1 = 72MHzRCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2 = 36MHzRCC_ADCCLKConfig(RCC_PCLK2_Div4);

// ADCCLK = PCLK2/4 = 18 MHzFLASH_SetLatency(FLASH_Latency_2);

// Set latency time as 2 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable PrefetchBufferRCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

// Set HSE to system clock and use PLL// (PLLCLK = 8MHz x 9 = 72MHz)

RCC_PLLCmd(ENABLE); // Enable PLLwhile(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

// Wait until PLL readyRCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

// Select the PLL as system clock sourcewhile(RCC_GetSYSCLKSource() != 0x08);}

}int main(){

RCC_setup3();........................

}

All exmples in this manual select the clock source same exmple 3 codes above.HSE are setting as 8MHz.

Page 61: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-
Page 62: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 59

This experiment demonstrates the STM32F103VBT6 output port programming.Drives simple output devices; LED at PC6 to PC9 and PE2 to PE5 on the JX-STM32 board.

Experment-1 : Output port interfacing(PC6 to PC9 and PE2 to PE5)

3VVBAT

- + ON

STM32

ON CAN

TERMINATE

CANMODE

B8 D2

E6 C11

C10

C9 C8 C7 C6 A8 B15

B14

B13

B12

B11

B10

E7 D15

D13

D11

D10

B1 B0 C5 A4 A3 A2 A1 C3 C2 C1 C0

ON

1

0

1

0BOOT0 BOOT1

0 x USER FLASH1 Embed. SRAM1 System MEM.

10

JTAGRESET

SWD/JTAG

USB

BATT

.

VDD

VBAT RESET

VO

LUM

E

ADCIN14

AMPLIFIER

JOYSTICK

JX-STM32ARM Cortex-M3 board

LM75Temp.sensor

E2E3E4E5

SDA1 B7SCL1 B6

+3V3

GND+3V3

GND

WAKEUPPA0

TAMPERPC13

SW1PB9

SW2PD7

LED4PC9

LED3PC8

LED2PC7

LED1PC6

UART2

UART1

BOOTLOADER

DC input 6-9V

SD

/MM

C

4 : General purpose I/O port example

Page 63: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

60 l JX-STM32 ARM Cortex-M3 microcontroller board

Procedure(1.1) Create the project file ; output_01

(1.2) Create C source file; output_01.c with Listing L1-1.

(1.3) Build the project file and downlaod to STM32F103VBT6 on the JX-STM32microcontroller board. See more details in chapter 2 of this document.

(1.4) Run program and observe the operation.

LED at PC6 to PC9 and PE2 to PE5 is blinked 0.5 second rate.

// Program : Test output at PC6 to PC9// Description: LED Blinking at PC6 to PC9// Filename: output_01.c// C complier : RkitARM 1.03.0003 for RIDE7// Firmwar Library : STMicroelectronics FWLib V1.0// ******************************************************************#include “stm32f10x_lib.h” // Include STM32 header file//************************* Function delay*************************void delay(unsigned long ms)// delay 1 ms per count @ Crystal 8.0 MHz and PLL9x or SYSCLK = 72 MHz{

volatile unsigned long i,j;for (i = 0; i < ms; i++ )for (j = 0; j < 5525; j++ );

}

// **********************Function RCC Configuration ******************//void RCC_setup(void){

ErrorStatus HSEStartUpStatus; // Keep error statusRCC_DeInit(); // RCC system reset(for debug purpose)RCC_HSEConfig(RCC_HSE_ON); // Enable HSEHSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is readyif(HSEStartUpStatus == SUCCESS){

RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLKRCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable Prefetch BufferRCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

// PLLCLK = 8MHz * 9 = 72 MHzRCC_PLLCmd(ENABLE); // Enable PLLwhile(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

// Wait until PLL is ready

Listing L1-1 : output_01.c ; C file for STM32 micrcontroller demonstratesthe output port operation. (continue)

Page 64: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 61

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);// Select PLL as system clock source

while(RCC_GetSYSCLKSource() != 0x08);// Wait till PLL is used as system clock source

} }

// **************** Function GPIO Configuration *********************void GPIO_setup(){

GPIO_InitTypeDef GPIO_InitStructure; // Enable GPIOC clockRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOE,ENABLE);// Configure PC6,PC7,PC8 and PC9 as Output push-pull// (connect with LED)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOC, &GPIO_InitStructure);

// Configure PE2,PE3,PE4 and PE5 as Output push-pull(connect with LED)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOE, &GPIO_InitStructure);

}

//************************ Main Program***********************int main(){

RCC_setup(); // System Clocks ConfigurationGPIO_setup(); // GPIO ports configurationwhile(1) // Infinite loop{

GPIO_WriteBit(GPIOC, GPIO_Pin_6,1); // LED at PC6 ONGPIO_WriteBit(GPIOC, GPIO_Pin_7,1); // LED at PC7 ONGPIO_WriteBit(GPIOC, GPIO_Pin_8,1); // LED at PC8 ONGPIO_WriteBit(GPIOC, GPIO_Pin_9,1); // LED at PC9 ONGPIO_WriteBit(GPIOE, GPIO_Pin_2,1); // LED at PE2 ONGPIO_WriteBit(GPIOE, GPIO_Pin_3,1); // LED at PE3 ONGPIO_WriteBit(GPIOE, GPIO_Pin_4,1); // LED at PE4 ONGPIO_WriteBit(GPIOE, GPIO_Pin_5,1); // LED at PE5 ONdelay(500); // Delay 0.5 secGPIO_WriteBit(GPIOC, GPIO_Pin_6,0); // LED at PC6 OFFGPIO_WriteBit(GPIOC, GPIO_Pin_7,0); // LED at PC7 OFFGPIO_WriteBit(GPIOC, GPIO_Pin_8,0); // LED at PC8 OFFGPIO_WriteBit(GPIOC, GPIO_Pin_9,0); // LED at PC9 OFFGPIO_WriteBit(GPIOE, GPIO_Pin_2,0); // LED at PE2 OFFGPIO_WriteBit(GPIOE, GPIO_Pin_3,0); // LED at PE3 OFFGPIO_WriteBit(GPIOE, GPIO_Pin_4,0); // LED at PE4 OFFGPIO_WriteBit(GPIOE, GPIO_Pin_5,0); // LED at PE5 OFFdelay(500); // Delay 0.5 sec

}}

Listing L1-1 : output_01.c ; C file for STM32 micrcontroller demonstratesthe output port operation. (continue)

Page 65: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

62 l JX-STM32 ARM Cortex-M3 microcontroller board

Code description

This code includes the header file ; stm32f10x_lib.h at the command line :

#include <stm32f10x_lib.h>Developer can access all resources and STM32 firmware library. (Must copy the

stm32f10x_conf.h file into the target project first).

The main function starts with set the clokc source parameters by RCC_setupfunction. Next, set the ports PC6 to PC9 and PE2 to PE5 as push-pull output type byGPIO_setup function.

After that program will run in loop while(1){} to send data to PC6 to PC9 and PE2to PE5 ports by instrunction GPIO_WriteBit with swap data “1” (LED on) and “0” (LEDoff) every 500 millsecond from delay function.

This is more description about important fucntion of this example code :

RCC_setup : set the clock source for STM32

void RCC_setup(void){

ErrorStatus HSEStartUpStatus; // Keep error statusRCC_DeInit(); // RCC system reset(for debug purpose)RCC_HSEConfig(RCC_HSE_ON); // Enable HSEHSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is readyif(HSEStartUpStatus == SUCCESS){

RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLKRCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // Enable Prefetch BufferRCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

// PLLCLK = 8MHz * 9 = 72 MHzRCC_PLLCmd(ENABLE); // Enable PLLwhile(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); // Wait until PLL is readyRCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock sourcewhile(RCC_GetSYSCLKSource() != 0x08); // Wait till PLL is used as system clock source

} }

This function purpose is set the SYSCLK=72MHz from HSE=8 MHz and enable PLL)

Listing L1-1 : output_01.c ; C file for STM32 micrcontroller demonstratesthe output port operation. (continue)

Page 66: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 63

GPIO_setup : set the port properties

void GPIO_setup(){

GPIO_InitTypeDef GPIO_InitStructure; // Enable GPIOC clockRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOE,ENABLE);

// Configure PC6,PC7,PC8 and PC9 as Output push-pull (connect with LED)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOC, &GPIO_InitStructure);

// Configure PE2,PE3,PE4 and PE5 as Output push-pull (connect with LED)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOE, &GPIO_InitStructure);

}

delay : set delay time in millisecond unit rference the SYSCLK at 72MHz

Listing L1-1 : output_01.c ; C file for STM32 micrcontroller demonstratesthe output port operation. (final)

Page 67: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

64 l JX-STM32 ARM Cortex-M3 microcontroller board

This experiment demonstrates the STM32F103VBT6 input/output portprogramming. Get the inpu data from switches PD7, PB9, PC13 and PA0 to drives simpleoutput devices; LED at PC6 to PC9 respectively on the JX-STM32 board.

3VVBAT

- + ON

STM32

ON CAN

TERMINATE

CANMODE

B8 D2

E6 C11

C10

C9 C8 C7 C6 A8 B15

B14

B13

B12

B11

B10

E7 D15

D13

D11

D10

B1 B0 C5 A4 A3 A2 A1 C3 C2 C1 C0

ON

1

0

1

0BOOT0 BOOT1

0 x USER FLASH1 Embed. SRAM1 System MEM.

10

JTAGRESET

SWD/JTAG

USB

BATT

.

VDD

VBAT RESET

VO

LUM

E

ADCIN14

AMPLIFIER

JOYSTICK

JX-STM32ARM Cortex-M3 board

WAKEUPPA0

TAMPERPC13

SW1PB9

SW2PD7

LED4PC9

LED3PC8

LED2PC7

LED1PC6

UART2

UART1

BOOTLOADER

DC input 6-9V

SD

/MM

C

Procedure(2.1) Create the project file ; input_01

(2.2) Create C source file; input_01.c with Listing L2-1.

(2.3) Build the project file and downlaod to STM32F103VBT6 on the JX-STM32microcontroller board. See more details in chapter 2 of this document.

(2.4) Run program. Press the button on PD7, PB9, PC13 and PA0 and observe the LED atPC6 to PC9 ports

Button PD7 controls LED at PC6,

Button PB9 controls LED at PC7

Button PC13 controls LED at PC8

Button PA0 controls LED at PC9

Experment-2 : Input/Output controller

Page 68: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 65

//***********************************************************************//// Program : Test input port// Description: test input switch at PD7 result is toggle LED at PC6// Filename: input_01.c// C complier : RkitARM 1.03.0003 for RIDE7// Firmwar Library : STMicroelectronics FWLib V1.0//********************************************************************//#include “stm32f10x_lib.h” // Include STM32 header file

//**************************** Function delay *************************//void delay(unsigned long ms)// delay 1 ms per count @ Crystal 8.0 MHz and PLL9x or SYSCLK = 72 MHz{

volatile unsigned long i,j;for (i = 0; i < ms; i++ )for (j = 0; j < 5525; j++ );

}//********************** Function RCC Configuration *****************//void RCC_setup(void){

ErrorStatus HSEStartUpStatus; // Keep error statusRCC_DeInit(); // RCC system reset(for debug purpose)RCC_HSEConfig(RCC_HSE_ON); // Enable HSEHSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is readyif(HSEStartUpStatus == SUCCESS){

RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLKRCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable Prefetch BufferRCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

// PLLCLK = 8MHz * 9 = 72 MHzRCC_PLLCmd(ENABLE); // Enable PLLwhile(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

// Wait until PLL is readyRCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

// Select PLL as system clock sourcewhile(RCC_GetSYSCLKSource() != 0x08);

// Wait till PLL is used as system clock source}

}//********************* Function GPIO Configuration ******************//void GPIO_setup(){

GPIO_InitTypeDef GPIO_InitStructure;

// Enable GPIOA,GPIOB,GPIOC and GPIODRCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |

RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOD,ENABLE);

Listing L2-1 : inout_01.c ; C file for STM32 micrcontroller demonstrates theinput/output port operation. (continue)

Page 69: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

66 l JX-STM32 ARM Cortex-M3 microcontroller board

// Configure PC6 as Output push-pull(connect with LED)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOC, &GPIO_InitStructure);

// Configure PA0 as Input floating(connect with switch)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOA, &GPIO_InitStructure);

// Configure PB9 as Input floating(connect with switch)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOB, &GPIO_InitStructure);

// Configure PC13 as Input floating(connect with switch)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOC, &GPIO_InitStructure);

// Configure PD7 as Input floating(connect with switch)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOD, &GPIO_InitStructure);

}//************************* Main Program ******************************//int main(){

RCC_setup(); // RCC ConfigurationGPIO_setup(); // GPIO ports configurationwhile(1) // Infinite loop{

if(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_7)==0) // Switch at PD7 press?{

// Toggle LED at PC6GPIO_WriteBit(GPIOC,GPIO_Pin_6,

(BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_6))));delay(200); // Delay 0.2 sec

}if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9)==0) // Switch at PB9 press?{

// Toggle LED at PC7GPIO_WriteBit(GPIOC, GPIO_Pin_7,

(BitAction)((1-GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_7))));delay(200); // Delay 0.2 sec

}if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)==0) // Switch at PC13 press?{

// Toggle LED at PC8GPIO_WriteBit(GPIOC, GPIO_Pin_8,

(BitAction)((1-GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_8))));delay(200); // Delay 0.2 sec

}

Listing L2-1 : inout_01.c ; C file for STM32 micrcontroller demonstrates theinput/output port operation. (continue)

Page 70: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 67

if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1)// Switch at PA0 press? (circuit is pull down)

{// Toggle LED at PC9GPIO_WriteBit(GPIOC, GPIO_Pin_9,

(BitAction)((1-GPIO_ReadOutputDataBit(GPIOC,GPIO_Pin_9))));delay(200); // Delay 0.2 sec

}}

}

Code description

This code includes the header file ; stm32f10x_lib.h at the command line :

#include <stm32f10x_lib.h>Developer can access all resources and STM32 firmware library. (Must copy the

stm32f10x_conf.h file into the target project first).

The main function starts with set the clokc source parameters by RCC_setupfunction. Next, set the ports PC6 to PC9 as push-pull output type and PD7, PB9, PC13 andPA0 as input port by GPIO_setup function.

After that program will run in loop while(1){} to poll the input ports status byinstruction GPIO_ReadInputDataBit. Any bit as “0” means switch at that port is pressed.CPU will invert data and send to PC6 to PC9 following the conistion as follows :

Case 1 : if the button switch at PD7 is pressed, PC6 data is converted to “0”LED is on.

Case 2 : if the button switch at PB9 is pressed, PC7 data is converted to “0”LED is on.

Case 3 : if the button switch at PC13 is pressed, PC8 data is converted to “0”LED is on.

Case 4 : if the button switch at PA0 is pressed, PC9 data is converted to “0”LED is on.

Every pressing, program will delay 200 millisecond to debounce the switch pressing.

Invert data executation will do by GPIO_WriteBit instruction. This instrucrtion willread current data at the specific port by GPIO_ReadOutputDataBit instruction. Afterthat substracted by 1. Next, cast type to BitAction format as SET (or ‘1”) and RESET (or“0”)

Listing L2-1 : inout_01.c ; C file for STM32 micrcontroller demonstrates theinput/output port operation (final).

Page 71: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

68 l JX-STM32 ARM Cortex-M3 microcontroller board

This experiment demonstrates the interfacing with 5-direction button. It’s call “Joystick”. Set the GPIO as input port to read the joystick status. Get the input data toshows at output port; PC6 to PC9.

3VVBAT

- + ON

STM32

ON CAN

TERMINATE

CANMODE

B8 D2

E6 C11

C10

C9 C8 C7 C6 A8 B15

B14

B13

B12

B11

B10

E7 D15

D13

D11

D10

B1 B0 C5 A4 A3 A2 A1 C3 C2 C1 C0

ON

1

0

1

0BOOT0 BOOT1

0 x USER FLASH1 Embed. SRAM1 System MEM.

10

JTAGRESET

SWD/JTAG

USB

BATT

.

VDD

VBAT RESET

VO

LUM

E

ADCIN14

AMPLIFIER

JOYSTICK

JX-STM32ARM Cortex-M3 board

WAKEUPPA0

TAMPERPC13

SW1PB9

SW2PD7

LED4PC9

LED3PC8

LED2PC7

LED1PC6

UART2

UART1

BOOTLOADER

DC input 6-9V

SD

/MM

C

Procedure(3.1) Create the project file ; joystick_01

(3.2) Create C source file; joystick_01.c with Listing L3-1.

(3.3) Build the project file and downlaod to STM32F103VBT6 on the JX-STM32microcontroller board. See more details in chapter 2 of this document.

Experment-3 : Input/Output controller withthe joystick

Page 72: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 69

//*********************************************************************//// Program : Test Joystick port// Description: test Joystick active with conditional// - when JOY_UP active LED at PC6 ON// - when JOY_DOWN active LED at PC7 ON// - when JOY_LEFT active LED at PC8 ON// - when JOY_RIGHT active LED at PC9 ON// - when JOY_SELECT active LED at PC6,PC7,PC8 and PC9 ON// Filename: joystick_01.c// C complier : RkitARM 1.03.0003 for RIDE7//*******************************************************************//#include “stm32f10x_lib.h” // Include STM32 header file

//************************* Function delay ***************************//void delay(unsigned long ms)// delay 1 ms per count @ Crystal 8.0 MHz and PLL9x or SYSCLK = 72 MHz{

volatile unsigned long i,j;for (i = 0; i < ms; i++ )for (j = 0; j < 5525; j++ );

}

//********************** Function RCC Configuration *******************//void RCC_setup(void){

ErrorStatus HSEStartUpStatus; // Keep error statusRCC_DeInit(); // RCC system reset(for debug purpose)RCC_HSEConfig(RCC_HSE_ON); // Enable HSEHSEStartUpStatus = RCC_WaitForHSEStartUp() // Wait till HSE is readyif(HSEStartUpStatus == SUCCESS){

RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLKRCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable Prefetch BufferRCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

// PLLCLK = 8MHz * 9 = 72 MHzRCC_PLLCmd(ENABLE); // Enable PLLwhile(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

// Wait until PLL is ready

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);// Select PLL as system clock source

while(RCC_GetSYSCLKSource() != 0x08);// Wait till PLL is used as system clock source

}}//***************** Function GPIO Configuration ****************************void GPIO_setup(){

GPIO_InitTypeDef GPIO_InitStructure;

Listing L3-1 : joystick_01.c ; C file for STM32 micrcontroller demonstratesthe input/output port operation with the joystick; the 5-direction switch(continue).

Page 73: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

70 l JX-STM32 ARM Cortex-M3 microcontroller board

Listing L3-1 : joystick_01.c ; C file for STM32 micrcontroller demonstratesthe input/output port operation with the joystick; the 5-direction switch(continue).

// Enable GPIOC,GPIOD and GPIOERCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |

RCC_APB2Periph_GPIOE,ENABLE);

// Configure PC6,PC7,PC8 and PC9 as Output push-pull(connect with LED)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 ;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOC, &GPIO_InitStructure);

// Configure PD8,PD12 and PD14 as Input floating(connect with Joystick)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_12 | GPIO_Pin_14;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOD, &GPIO_InitStructure);

// Configure PE0,PE1 as Input floating(connect with Joystick)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOE, &GPIO_InitStructure);

}//******************** Main Program ************************************int main(){ RCC_setup(); // System Clocks Configuration GPIO_setup(); // GPIO ports configuration while(1) // Infinite loop {

if(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_8)==0) // Joystick_UP at PD8 press?{

GPIO_WriteBit(GPIOC, GPIO_Pin_6,1); // LED at PC6 ONdelay(200); // Delay 0.2 secGPIO_WriteBit(GPIOC, GPIO_Pin_6,0); // LED at PC6 OFF

}if(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_14)==0) // Joystick_DOWN at PD14 press?{

GPIO_WriteBit(GPIOC, GPIO_Pin_7,1); // LED at PC7 ONdelay(200); // Delay 0.2 secGPIO_WriteBit(GPIOC, GPIO_Pin_7,0); // LED at PC7 OFF

}if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_1)==0) // Joystick_LEFT at PE1 press?{

GPIO_WriteBit(GPIOC, GPIO_Pin_8,1); // LED at PC7 ONdelay(200); // Delay 0.2 secGPIO_WriteBit(GPIOC, GPIO_Pin_8,0); // LED at PC7 OFF

}if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_0)==0) // Joystick_RIGHT at PE0 press?{

GPIO_WriteBit(GPIOC, GPIO_Pin_9,1); // LED at PC7 ONdelay(200); // Delay 0.2 secGPIO_WriteBit(GPIOC, GPIO_Pin_9,0); // LED at PC7 OFF

}

Page 74: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 71

Listing L3-1 : joystick_01.c ; C file for STM32 micrcontroller demonstratesthe input/output port operation with the joystick; the 5-direction switch(continue).

if(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_12)==0) // Joystick_SELECT at PD12 press?{

GPIO_WriteBit(GPIOC, GPIO_Pin_6,1); // LED at PC6 ONGPIO_WriteBit(GPIOC, GPIO_Pin_7,1); // LED at PC7 ONGPIO_WriteBit(GPIOC, GPIO_Pin_8,1); // LED at PC8 ONGPIO_WriteBit(GPIOC, GPIO_Pin_9,1); // LED at PC9 ONdelay(200); // Delay 0.2 secGPIO_WriteBit(GPIOC, GPIO_Pin_6,0); // LED at PC6 OFFGPIO_WriteBit(GPIOC, GPIO_Pin_7,0); // LED at PC7 OFFGPIO_WriteBit(GPIOC, GPIO_Pin_8,0); // LED at PC8 OFFGPIO_WriteBit(GPIOC, GPIO_Pin_9,0); // LED at PC9 OFF

} }}

Code description

This code includes the header file ; stm32f10x_lib.h at the command line :

#include <stm32f10x_lib.h>Developer can access all resources and STM32 firmware library. (Must copy the

stm32f10x_conf.h file into the target project first).

The main function starts with set the clokc source parameters by RCC_setupfunction. Next, set the ports PC6 to PC9 as push-pull output type and PD8, PD12, PD14,PE0 and PE1 as input floating port for getting the joystick status by GPIO_setup function.

After that program will run in loop while(1){} to poll the joystick port status byinstruction GPIO_ReadInputDataBit. CPU will invert data and send to PC6 to PC9 followingthe conditions as follows :

Cast 1 - PD8 as “0” : Joystick is pressed in Up direction (JOY_UP). PC6is set. LED on 200 millisecond after that turn it off.

Cast 2 - PD14 as “0” : Joystick is pressed in Down direction (JOY_DOWN).PC7 is set. LED on 200 millisecond after that turn it off.

Cast 3 - PE1 as “0” : Joystick is pressed in Left direction (JOY_LEFT).PC8 is set. LED on 200 millisecond after that turn it off.

Cast 4 - PE0 as “0” : Joystick is pressed in Right direction (JOY_RIGHT).PC9 is set. LED on 200 millisecond after that turn it off.

Cast 5 - PD12 as “0” : Joystick is pressed in Up direction(JOY_SELECTION). PC6 to PC9 data are set . All LED on 200 millisecond after that turnthem off.

Page 75: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

72 l JX-STM32 ARM Cortex-M3 microcontroller board

Listing L3-1 : joystick_01.c ; C file for STM32 micrcontroller demonstratesthe input/output port operation with the joystick; the 5-direction switch(final).

The interesting function of this code is GPIO_setup. See more detrial aboutthis function below.

void GPIO_setup(){

GPIO_InitTypeDef GPIO_InitStructure; // Declare variable type to Structure

// Enable clock to GPIOC, GPIOD and GPIOE moduleRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |

RCC_APB2Periph_GPIOE,ENABLE);

// Set the PC6 port as Output push-pull ,50 MHz modeGPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 ;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOC, &GPIO_InitStructure);

// Set the PD8, PD12 and PD14 as Input Floating modeGPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_12 | GPIO_Pin_14;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOD, &GPIO_InitStructure);

// Set the PE0 andPE1as Input Floating modeGPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOE, &GPIO_InitStructure);

}

Page 76: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 73

(3.4) Run program. Stroke the joystick’s shaft and press the button at the center. Observethe LED at PC6 to PC9 ports.

(3.4.1) Stroke the shaft to up direction (JOY_UP).

LED at PC6 is on in a moment and off.

(3.4.2) Stroke the shaft to down direction (JOY_DOWN).

LED at PC7 is on in a moment and off.

(3.4.3) Stroke the shaft to left direction (JOY_LEFT).

LED at PC8 is on in a moment and off.

(3.4.4) Stroke the shaft to right direction (JOY_RIGHT).

LED at PC9 is on in a moment and off.

(3.4.5) Press the shaft (JOY_SELECTION).

All LED at PC6 to PC9 are on in a moment and off.

Page 77: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-
Page 78: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

74 l JX-STM32 ARM Cortex-M3 microcontroller board

Experment-4 : External interrupt

5 : External Interrupt example

This experiment demonstrates the EXTI operation. Coding will set the EXTI to detectthe falling edge of interrupt signal at PA0 and PC13 pin. THe PA0 is assigned to EXTI line0and PC13 as line13. Both pins are connected with button swtiches. The LEDs at PC6and PC9 are assinged to display device of this experiment.

3VVBAT

- + ON

STM32

ON

CANTERMINATE

CANMODE

B8 D2

E6 C11

C10

C9 C8 C7 C6 A8 B15

B14

B13

B12

B11

B10

E7 D15

D13

D11

D10

B1 B0 C5 A4 A3 A2 A1 C3 C2 C1 C0

ON

1

0

1

0BOOT0 BOOT1

0 x USER FLASH1 Embed. SRAM1 System MEM.

10

JTAGRESET

SWD/JTAG

USB

BATT

.

VDD

VBAT RESET

VO

LUM

E

ADCIN14

AMPLIFIER

JOYSTICK

JX-STM32ARM Cortex-M3 board

WAKEUPPA0

TAMPERPC13

SW1PB9

SW2PD7

LED4PC9

LED3PC8

LED2PC7

LED1PC6

UART2

UART1

BOOTLOADER

DC input 6-9V

SD

/MM

C

STM32 external interrupt program developing procedure(1) Define the suitable clock source and frequency to STM32 CPU core and

peripherals

(2) Set the GPIO module properties that assign to input port. The Input Floatingtype is recommended. Enable the clock to GPIO operated and AFIO of APB2 peripheralgroup.

(3) Set the EXTI moduel parameter. Select the detection edge of interrupt signal.

(4) Enable EXTI module in NCIC module controller.

(5) Declare the intterupt service function.

Page 79: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 75

Listing L4-1 : switch_Int_01.c ; C file for STM32 micrcontroller demonstratesthe exrternal interrupt operation. (continue)

//************************************************************************// Program :Test EXTI at port PA0 and PC13// Description : LED Toggle at PC9 when switch PA0 pressed// : LED Toggle at PC6 when switch PC13 pressed

:(Falling edge sensing)// Filename : switch_int_01.c// C complier : RkitARM 1.03.0003 for RIDE7//************************************************************************

#include “stm32f10x_lib.h” // Include STM32 header file

//********************* Function RCC Configuration *******************//void RCC_setup(void){ ErrorStatus HSEStartUpStatus; // Keep error status RCC_DeInit(); // RCC system reset(for debug purpose) RCC_HSEConfig(RCC_HSE_ON); // Enable HSE HSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is ready if(HSEStartUpStatus == SUCCESS) { RCC_HCLKConfig(RCC_SYSCLK_Div1);// HCLK = SYSCLK RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2 FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait state FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable Prefetch Buffer RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

// PLLCLK = 8MHz * 9 = 72 MHz

RCC_PLLCmd(ENABLE); // Enable PLL while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

// Wait until PLL is ready

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);// Select PLL as system clock source

while(RCC_GetSYSCLKSource() != 0x08);// Wait till PLL is used as system clock source

}}//******************* Function GPIO Configuration *********************//void GPIO_setup(){ GPIO_InitTypeDef GPIO_InitStructure;

// Enable GPIOB and GPIOC clockRCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC,ENABLE);

// Configure PC6 and PC9 as Output push-pull(connect with LED)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOC, &GPIO_InitStructure);

Page 80: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

76 l JX-STM32 ARM Cortex-M3 microcontroller board

Listing L4-1 : switch_Int_01.c ; C file for STM32 micrcontroller demonstratesthe exrternal interrupt operation. (continue)

// Configure PC13 as input floating (EXTI Line13)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOC, &GPIO_InitStructure);

// Configure PA0 as input floating (EXTI Line0)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOA, &GPIO_InitStructure);

}//********************* Function NVIC Configuration ********************//void NVIC_setup(){

NVIC_InitTypeDef NVIC_InitStructure;

// Configure one bit for preemption priorityNVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

// Enable the EXTI0 InterruptNVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQChannel;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure)

// Enable the EXTI13 InterruptNVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);

}//******************** Function EXTI Configuration *********************//void EXTI_setup(){

EXTI_InitTypeDef EXTI_InitStructure;

// Enable AFIO for EXTI moduleRCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);

// Connect EXTI Line0 to PA0

// Configure EXTI Line0 to generate an interrupt on falling edgeEXTI_InitStructure.EXTI_Line = EXTI_Line0;EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;EXTI_InitStructure.EXTI_LineCmd = ENABLE;EXTI_Init(&EXTI_InitStructure);

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);// Connect EXTI Line13 to PC13

// Configure EXTI Line0 to generate an interrupt on falling edgeEXTI_InitStructure.EXTI_Line = EXTI_Line13;EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;

Page 81: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 77

Listing L4-1 : switch_Int_01.c ; C file for STM32 micrcontroller demonstratesthe exrternal interrupt operation. (continue)

EXTI_InitStructure.EXTI_LineCmd = ENABLE;EXTI_Init(&EXTI_InitStructure);

}//*************************** Function ISR line 0 **********************//void EXTI0_IRQHandler(void) //{

if(EXTI_GetITStatus(EXTI_Line0) != RESET)// Ensure get EXTI line 0 pending bit

{// Toggle PC6 pinGPIO_WriteBit(GPIOC, GPIO_Pin_6,

(BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_6))));EXTI_ClearITPendingBit(EXTI_Line0);

// Clear the EXTI line 0 pending bit }}//**********************Function ISR line 10 to 15 ********************//void EXTI15_10_IRQHandler(void){ if(EXTI_GetITStatus(EXTI_Line13) != RESET) // Ensure get EXTI line 13 pending bit {

// Toggle PC9 pinGPIO_WriteBit(GPIOC, GPIO_Pin_9,

(BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_9))));EXTI_ClearITPendingBit(EXTI_Line13); // Clear the EXTI line 13 pending bit

}}//**************************** Main Program ***************************//int main(){ RCC_setup(); // RCC Configuration GPIO_setup(); // GPIO ports configuration EXTI_setup(); // EXTI configuration NVIC_setup(); // NVIC configuration while(1); // Break program}Code description

This code includes the header file ; stm32f10x_lib.h at the command line :

#include <stm32f10x_lib.h>Developer can access all resources and STM32 firmware library. (Must copy the

stm32f10x_conf.h file into the target project first).

This code consist of many functions. We can explain as follows :

RCC_setup - set the operating clokck source and frequency.

SYSCLK = 72MHz from external crystal 8MHz and enable PLL tomultiply clock frequency 9 times.

HCLK = SYSCLK

PCLK2 = HCLK/1 = 72 MHz

Page 82: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

78 l JX-STM32 ARM Cortex-M3 microcontroller board

Listing L4-1 : switch_Int_01.c ; C file for STM32 micrcontroller demonstratesthe exrternal interrupt operation. (final)

PCLK1 = HCLK/2 = 36 MHz

LATENCY - 2 wait state (because 48 MHz < SYSCLK <= 72 MHz)

GPIO_setup - set the GPIO mode operation

Set PC6 and PC9 as push-pull output type

Set PA0 and PC13 as input floating type for detecting the externalinterrupt signal

EXTI_setup - set the EXTI module operation

Set PA0 and PC13 port as EXTI line0 and line 13 respectively. Detectthe falling edge signal.

NVIC_setup - Set the interrupt service at NVIC module

Select the interrupt source as EXTI line 0 and line13. Define EXTIline0 priority higher than EXTI line13.

After that program will run in loop while(1){} to detect the faling edge interuptsignal at PA0 and PC13. If they are occured, the interrupt service routine is executed.

Case 1 - E XT line 0 interrupt is occured. CPU will jump to EXTI0_IRQHandler;the interrupt service function for EXTI line0. This function will invert logic of LED at PC6port and clear interrupt flag of EXTI line 0 for next opertation.

Case 2 - EXT line 13 interrupt is occured. CPU will jump to EXTI15_10_IRQHandler; the interrupt service function for EXTI line10 to line 15. This function willinvert logic of LED at PC9 port and clear interrupt flag of EXTI line 13 for next opertation.

Procedure(4.1) Create the project file ; switch_int_01

(4.2) Create C source file; switch_int.c with Listing L4-1.

(4.3) Build the project file and downlaod to STM32F103VBT6 on the JX-STM32microcontroller board. See more details in chapter 2 of this document.

(4.4) Run program. Press button at PA0 and PC13 and observe the operation.

If the button at PA0 is pressed, the externqal inteuuprt signal are occured. LED atPC9 is turned on and off following the pressing switch at PA0 pin.

If the button at PC13 is pressed, the external interrupt signal are occured. LED atPC6 is turned on and off following the pressing switch at PC13 pin.

Page 83: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-
Page 84: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board���79

6.1 GLCD5110 technical features� Graphic LCD module # LPH7366. Resolution is 84 x 48 pixel.

� Built-in PCD8544 controller with SPI interface bus.

� Built-in the backlight blue LED controlled by software

� Supply voltage range is +3 to +3.3V. Maximum current is 10mA (with backlight

LED)

� Display the standard size 5x7 pixel character up to 14 characters 6 lines and

mono-tone graphic image.

� Size is 4.5 x 4.5 cm.

� Easy to connection

� Interface with any popular microcontroller.

- If interface with +3V logic system, user can connect GLCD with

microcontroller port directly.

- If interface with +5V system, user must connect through the attenuator

circuit for redeuce the logic level from +5V to +3 or +3.3V or not over the supply voltage

of GLCD5110.

The figure 6-1 shows size and pin assignment of GLCD5110.

The figure 6-2 shows the interfacing circuit with the microcontroller.

6.2 Interfacing with JX-STM32The interfacing of GLCD5110 on the JX-STM32 microcontroller board is summary

as follows :

GLCD5110 STM32F103VBT6

SDIN PE11

SCLK PE12

SCE PE8

RESET PE9

D/C PE10

LED PE13

THe figure 6-3 shows the interface circuit on the JX-STM32 board.

������������ ������������������

Page 85: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

80���JX-STM32 ARM Cortex-M3 microcontroller board

�������������� ������� ��������������������������

�����

�����

�����

�����

��� ���� ��������

� � ������������� ������ ����

�� ������

� ��� ��������������������

� ����� �������������������

� �� � !�""���������������

����������������� ���

�����������������

� � �� ����������������

� ���� !���#���������

� �� $�#���%�&��������������������%��%

'����������"�������������������( )

Page 86: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board���81

������������������������ ������������!��� �� ���������

�����

�"�

��#

$#�#%

�&�

��'"

���(

���

�� ���

�����������

�����������

�����������

�����������

�����

�����

������

�����

�����

������

���

��

�� ��

�� ��

���������

�������������

��������

���������

��������

��������

�������

�����

�� ��

�����������

��������)���%*)���)+,%�� ���������������� ����� !�� �� ��� �� �

����!��-.�%*)��/� ��

Page 87: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

82���JX-STM32 ARM Cortex-M3 microcontroller board

6.3 GLCD5110 programming development with STM32The heart of GLCD5110 interfacing for STM32 is GLCD5110 library. It is glcd5110.h.

This library is created by Innovative Experiment (INEX). It is contained in JX-STM32ís CD-ROM.

Developer must include this library file at the head of C sourcecode by instruction

#include ìglcd5110.hî The step of path defining this library file have 2 methods as

follows :

1. Path defining method 1

Copy the glcd5110.h library file to under development project folder. The

compiler will access this library file automatically.

2. Path defining method 2

This method must do with Ride7. It has many steps as follows.

(2.1) Click on the menu Project � Properties

(2.2) The Properties windows is appeared. Click to select Directories.

Page 88: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board���83

(2.3) At the right hand of window, click to select Include Directoriesfollowing click on the Browse button at the right end side to define the path.

(2.4) The Dialog window will appear. Click on the New button to define

the new path. For this example is :

���������� ��������������������������

However the path location of libraries and header files are

depended on each developer.

Page 89: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

84���JX-STM32 ARM Cortex-M3 microcontroller board

(2.5) After setting the path of glcd5110.h completly, click on the OK button

to confirm.

Note : The glcd5110.h library file set the mode of PE8 to PE13 as push-pull output

already.

Page 90: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board���85

This experiment demonstrates the GLCD5110 simple operation with

STM32F103VBT6. Coding will asssign the GLCD5110 to display simple text on GLCDís

screen.

Procedure(5.1) Create the project file ; glcd_01

(5.2) Create C source file; glcd_01.c with Listing L5-1.

(5.3) Build the project file and downlaod to STM32F103VBT6 on the JX-STM32

microcontroller board. See more details in chapter 2 of this document.

(5.4) Run program. Observe the operation on GLCD5110 screen on the JX-STM32 board.

The GLCD5110 will disply following the picture below :

�� � ��� � ��

�� ������

��������

� � � � � � � � � � � � � �

���������

���� !"�#���$

Also, the backlight LED of GLCD5110 is blinked with 0.5 second rating.

Experment-5 : Simple display with GLCD5110

Page 91: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

86���JX-STM32 ARM Cortex-M3 microcontroller board

//////////////////////////////////////////////////////////////////////////// Program : Test GLCD5110// Description: Basic for display message on GLCD5110// Filename: glcd_01.c// C complier : RkitARM 1.03.0003 for RIDE7// Firmwar Library : STMicroelectronics FWLib V1.0//////////////////////////////////////////////////////////////////////////

#include “stm32f10x_lib.h” // Include STM32 header file#include “glcd5110.h” // Include library file for GLCD5110//******************** Function RCC Configuration ***************//void RCC_setup(void){ ErrorStatus HSEStartUpStatus; // Keep error status RCC_DeInit(); // RCC system reset(for debug purpose) RCC_HSEConfig(RCC_HSE_ON); // Enable HSE HSEStartUpStatus = RCC_WaitForHSEStartUp();

// Wait till HSE is ready if(HSEStartUpStatus == SUCCESS) { RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLK RCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLK RCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2 FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait state FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable Prefetch Buffer RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

// PLLCLK = 8MHz * 9 = 72 MHz RCC_PLLCmd(ENABLE); // Enable PLL while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

// Wait until PLL is ready RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

// Select PLL as system clock source while(RCC_GetSYSCLKSource() != 0x08);

// Wait till PLL is used as system clock source }}//************************** Main Program *****************************//int main(){

int cnt; // Counter variableRCC_setup(); // Reset/Clock ConfigurationlcdString(1,1,”JX-STM32"); // Set message on line 1lcdString(1,2,”Graphic LCD”); // Set message on line 2lcdString(1,3,”Nokia 5110"); // Set message on line 3lcdUpdate(); // Display message

lcdGotoXY(1,4); // Go to (1,4)for(cnt=0;cnt<14;cnt++) // Loop for set ‘-’ on line 4{

lcdChar(‘-’);}lcdUpdate(); // Display messagelcdGotoXY(3,5);for(cnt=’0';cnt<=’9';cnt++) // Loop for set ‘0’-’9' on line 5

������������0��� �1�2 �3�������������%*)���� � ������������������ �����!�

�������������� ������ ���2� �!��� ����������� ���� �������� � ����

4 �������5

Page 92: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board���87

{lcdChar(cnt);

}lcdUpdate(); // Display messagelcdGotoXY(1,6);for(cnt=’A’;cnt<=’N’;cnt++) // Loop for set ‘A’-’N’ on line 6{

lcdChar(cnt);}lcdUpdate(); // Display messagewhile(1){

lcdBackLight(1); // BackLight ONdelay_ms(500); // Delay 500 mslcdBackLight(0); // BackLight OFFdelay_ms(500); // Delay 500 ms

}}

�������������

���������������� ������������

��������� ��������� ��!"#$

��������� %&���'���"#(

������� ��� ������ ���� �������� ������� � �������� ��������� ������ ����� ��

���������� �������������������������������������� ��������!�

��������������������������������"����#�����������������

�����������$������������������%�%������������&����

�'�()*� +� , �-.� ����� #����� �������� /�-.� ��� ���� 0))� ��

�������������%���&����1������

-()*�+��'�()*

0()* �+�-()*23�+�, ��-.

0()*3�+�-()*2 �+��4��-.

)5�67('�$� ������������������8/��-.�9��'�()*�9+�, ��-.!

����������������

���������$������������������������

���:�����$��������������������

���;���<'�$���������������������

���=��%)�����$�(������;)(�>33?@��)6�����%��������2���

������������0��� �1�2 �3�������������%*)���� � ������������������ �����!�

�������������������� ���2��!�������������� ������������� �����4��� �5

Page 93: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

88���JX-STM32 ARM Cortex-M3 microcontroller board

This experiment demonstrates the GLCD5110 simple operation with STM32F103VBT6.

Coding will asssign the GLCD5110 to display simple graphic on GLCDís screen.

Procedure(6.1) Create the project file ; glcd_02

(6.2) Create C source file; glcd_02.c with Listing L6-1.

(6.3) Build the project file and downlaod to STM32F103VBT6 on the JX-STM32

microcontroller board. See more details in chapter 2 of this document.

(6.4) Run program. Observe the operation on GLCD5110 screen on the JX-STM32 board.

The GLCD5110 will disply following the picture below :

����������

��� ���

�������� ���

Experment-6 : Simple graphic displayprogramming

Page 94: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board���89

//////////////////////////////////////////////////////////////////////////// Program : Test GLCD5110// Description: Basic for display graphic on GLCD5110// Filename : glcd_02.c// Firmwar Library : STMicroelectronics FWLib V1.0//////////////////////////////////////////////////////////////////////////#include “stm32f10x_lib.h” // Include STM32 header file#include “glcd5110.h” // Include library file for GLCD5110//******************** Function RCC Configuration *********************//void RCC_setup(void){

ErrorStatus HSEStartUpStatus; // Keep error statusRCC_DeInit(); // RCC system reset(for debug purpose)RCC_HSEConfig(RCC_HSE_ON); // Enable HSEHSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is readyif(HSEStartUpStatus == SUCCESS){

RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLKRCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable Prefetch BufferRCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

// PLLCLK = 8MHz * 9 = 72 MHzRCC_PLLCmd(ENABLE); // Enable PLLwhile(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); // Wait until PLL is readyRCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock sourcewhile(RCC_GetSYSCLKSource() != 0x08);

// Wait till PLL is used as system clock source}

}//**************************** Main Program ***************************//int main(){

RCC_setup(); // Reset/Clock ConfigurationlcdPixel(60,20,1); // Draw Pixel at(60,20)lcdLine(40,30,25,40,1); // Draw Line at(40,30) to (25,40)lcdRect(5,5,25,25,0,1); // Draw Rectangle corner at(5,5) to (25,25)lcdUpdate(); // Display messagewhile(1); // Break program

}

�������������

���������������� ������������

A������9���� �3?#B�����C

A������ D����>33?��E

������� ��� ������ ���� �������� ������� � �������� ��������� ������ ����� ��

���������� �������������������������������������� ��������!�

������������������>33?���������������������������

���0�#��$������������������������#�����

���)��$������������������������������������������

��������)���������#��*�������������������&��#��������&�����&��*#��"

�������� ��� � 0� �� �1��2 � 3��� ����� ���� �%*)���� � ���������

�������� ������!�������!����������� �!� ���������� ����

Page 95: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

90���JX-STM32 ARM Cortex-M3 microcontroller board

This experiment demonstrates the GLCD5110 simple operation with

STM32F103VBT6. Coding will asssign the GLCD5110 to display the simple progress bar

graphic on GLCDís screen.

Procedure(7.1) Create the project file ; glcd_03

(7.2) Create C source file; glcd_03.c with Listing L7-1.

(7.3) Build the project file and downlaod to STM32F103VBT6 on the JX-STM32

microcontroller board. See more details in chapter 2 of this document.

(7.4) Run program. Observe the operation on GLCD5110 screen on the JX-STM32 board.

The GLCD5110 will disply following the picture below :

��%%��

�������%

� � � � � � � � � � � � � �

���������

���� !"�#���$

The screen shows the shadow ratio value of the progress bar on the first 1 line.

The progrss bar is created on next line. It is started at (0,10) at left side. The progress bar

size is 83 pixels length and 5 pixel width.

The shadow ratio value of the progress bar increase every 0.2 second. It will

reset to 0 after the value reach 100 and restart again.

Experment-7 : Progress bar display

Page 96: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board���91

//////////////////////////////////////////////////////////////////////////// Program : Test GLCD5110// Description: Basic for display graphic on GLCD5110// Filename: glcd_03.c// Firmwar Library : STMicroelectronics FWLib V1.0//////////////////////////////////////////////////////////////////////////#include “stm32f10x_lib.h” // Include STM32 header file#include “glcd5110.h” // Include library file for GLCD5110#include “stdio.h” // Include library for sprintf function//*************************** Function RCC Configuration ***************//void RCC_setup(void){

ErrorStatus HSEStartUpStatus; // Keep error statusRCC_DeInit(); // RCC system reset(for debug purpose)RCC_HSEConfig(RCC_HSE_ON); // Enable HSEHSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is readyif(HSEStartUpStatus == SUCCESS){

RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLKRCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // Enable Prefetch BufferRCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9); // PLLCLK = 8MHz * 9 = 72 MHzRCC_PLLCmd(ENABLE); // Enable PLLwhile(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

// Wait until PLL is readyRCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

// Select PLL as system clock sourcewhile(RCC_GetSYSCLKSource() != 0x08);

// Wait till PLL is used as system clock source }}//*************************** Main Program *************************//int main(){

char str[15]; // Buffer for keep string from percentage(0-100%)int percentage=0; // Keep percentage of Progress BarRCC_setup();while(1) // Infinite loop{

sprintf(str,”%d%% “,percentage);// Convert string to display percentage

lcdString(1,1,str); // Set percentage value display on line 1lcdProgBar(0,10,83,5,percentage);// Display progress bar at(0,10),width 83 pixel,high 5 pixel

lcdUpdate(); // Display messagedelay_ms(200); // Delay for displaypercentage++; // Increase percentageif(percentage>100) // Check percentage over 100?{

percentage = 0; // Set percentage to zero}

}}

�������� �6� � 0� �� �1�)2 � 3��� ����� ���� �%*)���� � ���������

�������� ���� ��!�������!�����������/ ���� �!� ��������

� ����

Page 97: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

92���JX-STM32 ARM Cortex-M3 microcontroller board

Page 98: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

92 l JX-STM32 ARM Cortex-M3 microcontroller board

STM32F103VBT6 has 2 of 12-bit Analog to Digital Converter (ADC) modules. Theyare successive approximation analog-to-digital converter. It has up to 18 multiplexedchannels allowing it measure signals from 16 external and two internal sources. A/Dconversion of the various channels can be performed in single, continuous, scan ordiscontinuous mode. The result of the ADC is stored in a left-aligned or right-aligned 16-bitdata register.

The analog watchdog feature allows the application to detect if the input voltagegoes outside the user-defined high or low thresholds.

7.1 Main featuresl 12-bit resolution

l Interrupt generation at End of Conversion, End of Injected conversion andAnalog Watchdog event

l Single and continuous conversion modes

l Scan mode for automatic conversion of channel 0 to channel ‘n’

l Self-calibration

l Data alignment with in-built data coherency

l Channel by channel programmable sampling time

l External trigger option for both regular and injected conversion

l Discontinuous mode

l Dual mode (on devices with 2 ADCs)

l ADC conversion time:

1µs at 56MHz (1.17µs at 72 MHz)

l ADC supply requirement: 2.4 V to 3.6 V

l ADC input range: VREF- < VIN < VREF+

l DMA request generation during regular channel conversion

7.2 ADC module pin connectionSTM32F103VBT6 has related 21 pins with ADC module. they include :

VREF+ - External reference voltage input. Range is 2.4V < VREF+ < VDDA

VDDA - ADC module supply voltage. Range is 2.4V < VDDA < 3.6V.

VREF- - External reference negative voltage input. It is equal VSSA

VSSA - Ground pin of ADC module

ADCx_IN[15:0] - Analog input. Total are 16 pins.

7 : Analog to Digital converter example

Page 99: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 93

7.3 ADC Firmware library summary for this exampleFunction name Description

ADC_DeInit Resets the ADCx peripheral registers to theirdefault reset values.

ADC_Init Inital ADC module

ADC_Cmd Enable or Disable ADC module

ADC_DMACmd Enables or disables the specified ADC DMArequest

ADC_ITConfig Enables or disables the specified ADCinterrupts.

ADC_ResetCalibration Resets the selected ADC calibration registers

ADC_GetResetCalibrationStatus Gets the selected ADC reset calibrationregisters status.

ADC_StartCalibration Starts the selected ADC calibration process.

ADC_GetCalibrationStatus Gets the selected ADC calibration status.

ADC_SoftwareStartConvCmd Enables or disables the selected ADC softwarestart conversion.

ADC_RegularChannelConfig Configures for the selected ADC regularchannel the corresponding rank in thesequencer and the sample time.

ADC_GetConversionValue Returns the last ADCx conversion result datafor regular channel

ADC_AnalogWatchdogCmd Enables or disables the analog watchdog onsingle/all regular or injected channels

ADC_AnalogWatchdogThresholdsConfig

Configures the high and low thresholds of theanalog watchdog

ADC_AnalogWatchdogSingleChannelConfig

Configures the analog watchdog guardedsingle channel

ADC_GetFlagStatus Checks whether the specified ADC flag is setor not.

ADC_ClearFlag Clears the ADCx pending flags.

ADC_GetITStatus Checks whether the specified ADC interrupthas occurred or not.

ADC_ClearITPendingBit Clears the ADCx interrupt pending bits.

Page 100: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

94 l JX-STM32 ARM Cortex-M3 microcontroller board

This experiment demonstrates the reading analog signal at port PC4 or Analoginput channel-14. The potentiometer 10kW is represented the analog voltage source.The anlog voltage is applied to A/D converter input. The digital conversion data willsend to display on GLCD5110 on the JX-STM32 board.

Experment-8 : Reading analog signal

STM

32F

103

VB

T6S

TM3

2 M

icro

cont

rolle

rA

RM

Cor

tex-

M3

NRST

14

PA9/

USA

RT1_

TX68

PA10

/USA

RT1_

RX69

PB2/

BOO

T137

10k

+3.

3V

BO

OT1

BOO

T094

10k

+3.

3V

BO

OT0

RES

ET10

0nF

+3.

3V

10k

PC4/

ADC_

IN14

33PC

4

XTAL

32.7

68KH

z

PC15

-OSC

32_O

UTPC

14-O

SC32

_IN

8 9

+3.

3V

AD

C_IN

14

PE8

39

PE9

40

PE10

41

PE11

42

PE12

43

PE13

44

330 47

k

+3.

3V

+3.

3V

GLC

D 5

110

GLCD

BAC

KIGH

TGL

CD C

LKGL

CD D

ATA

GLCD

D/C

GLCD

RES

GLCD

CE

MM

BT22

22A

VBAT

6

+3.

3V

BA

TTER

YC

R2

032

BA

TT.

+3.

3V

VDD

A22

VREF

+21

BEAD

1.8u

H

47

100n

F

100n

F10

uF

+3.

3V

VREF

-20

VSSA

19

+3.

3V

VSS1

49

VSS2

74

VSS3

99

VSS4

27

VSS5

10

100n

F x

5

75 VDD

2

50 VDD

1

100 VD

D3

28 VDD

4

11 VDD

5

OSC

_IN

12

OSC

_OU

T13

20pF

XTAL

8MH

z

1M

20pF

BO

OT0

BO

OT1

Mod

e

0X

Use

r FL

ASH

11

Embe

dded

SR

AM

10

Syst

em M

emor

y

16

2 3 4 5

7 8 9 DB

-9 F

emal

eU

SA

RT1

(Boo

tloa

der)

R2O

UT9

T2IN

10

R2IN

T2O

UT

87

MA

X32

32CS

E

+3.

3V

TX O

UT

RX I

N

C1-

3

C1+

1

100n

F

C2-

5

C2+

4

100n

F

V-6

100n

F

V+2

100n

F

VCC

GND

100n

F

1615

+3.

3V

Figure L8-1 STM32’s ADCexperiment circuit

Page 101: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 95

The experimental schematic diagram is shown in the figure L8-1.

Procedure(8.1) Create the project file ; adc_01

(8.2) Create C source file; adc_01.c with Listing L8-1.

//——————————————————————————————————————————————————————————————————————//// Program : Test ADC// Description: Get analog value to display on GLCD5110 by polling flag EOC// Filename : adc_01.c// C complier : RkitARM 1.03.0003 for RIDE7// Firmware Library : STMicroelectronics FWLib V2.0//——————————————————————————————————————————————————————————————————————//#include “stm32f10x_lib.h” // Include STM32 header file#include “glcd5110.h” // Include library file for GLCD5110

//——————————————— Function RCC Configuration —————————————————————//void RCC_setup(){

ErrorStatus HSEStartUpStatus;// Keep error status RCC_DeInit(); // RCC system reset(for debug purpose) RCC_HSEConfig(RCC_HSE_ON); // Enable HSE HSEStartUpStatus = RCC_WaitForHSEStartUp(); // Wait till HSE is ready if(HSEStartUpStatus == SUCCESS) {

RCC_HCLKConfig(RCC_SYSCLK_Div1); // HCLK = SYSCLKRCC_PCLK2Config(RCC_HCLK_Div1); // PCLK2 = HCLKRCC_PCLK1Config(RCC_HCLK_Div2); // PCLK1 = HCLK/2RCC_ADCCLKConfig(RCC_PCLK2_Div4); // ADCCLK = PCLK2/4FLASH_SetLatency(FLASH_Latency_2); // Flash 2 wait stateFLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

// Enable Prefetch BufferRCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);

// PLLCLK = 8MHz * 9 = 72 MHz

RCC_PLLCmd(ENABLE); // Enable PLLwhile(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

// Wait until PLL is ready

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); // Select PLL as system clock sourcewhile(RCC_GetSYSCLKSource() != 0x08);// Wait till PLL is used as system clock source

}}

//——————————————— Function GPIO Configuration ————————————————————//void GPIO_setup(){ GPIO_InitTypeDef GPIO_InitStructure; // Enable GPIOC clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); // Configure PC4 as analog input(ADC Channel14) GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOC, &GPIO_InitStructure);}

Listing L8-1 : adc_01.c ; C file for STM32 micrcontroller demonstrates theA/D converter module operation (continue)

Page 102: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

96 l JX-STM32 ARM Cortex-M3 microcontroller board

Listing L8-1 : adc_01.c ; C file for STM32 micrcontroller demonstrates theA/D converter module operation (continue)

//——————————————— Function ADC Configuration —————————————————————//void ADC_setup(){

ADC_InitTypeDef ADC_InitStructure; // Enable ADC1 clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE); // ADC1 configuration ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); // ADC1 regular channel14 configuration

ADC_RegularChannelConfig(ADC1,ADC_Channel_14, 1, ADC_SampleTime_13Cycles5);

ADC_Cmd(ADC1, ENABLE); // Enable ADC1

ADC_ResetCalibration(ADC1); // Enable ADC1 reset cal.registerwhile(ADC_GetResetCalibrationStatus(ADC1));

ADC_StartCalibration(ADC1); // Start ADC1 calibarationwhile(ADC_GetCalibrationStatus(ADC1)); // Check the end of ADC1 calibration

}

//———————————————————— Main Program ———————————————————————//int main(){ unsigned long adc_val=0,percentage; // Keep analog value char str[14]; // Keep string convert RCC_setup(); // Reset/Clock Configuration GPIO_setup(); // GPIO Configuration ADC_setup(); // ADC Configuration lcdString(1,1,”ADC Demo...”); // Set message on line 1

lcdUpdate(); // Display message while(1) // Infinite loop {

ADC_Cmd(ADC1,ENABLE); // Enable ADC1while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)==RESET); // Wait EOC flag setadc_val = ADC_GetConversionValue(ADC1);// Get analog value from ADC channel 14(PC4)

percentage = (adc_val*100)/4095;// Convert analog to percentage(0-100% reference from 0-4095)

sprintf(str,”AIN14: %d “,adc_val); // Convert analog value to string

lcdString(1,3,str); // Set message on line 3lcdProgBar(0,26,83,5,percentage);// Display progress bar at(0,26),width 83 pixel,high 5 pixel

sprintf(str,”%d%% “,percentage); // Convert percentage value to string

lcdString(6,5,str); // Set message on line 5(position(6,5))lcdUpdate(); // Display messagedelay_ms(50); // Delay a few time

}}

Page 103: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

JX-STM32 ARM Cortex-M3 microcontroller board l 97

Listing L8-1 : adc_01.c ; C file for STM32 micrcontroller demonstrates theA/D converter module operation (final)

Code description

This code includes 3 header files :

#include <stm32f10x_lib.h>#include “glcd5110.h”#include “stdio.h”

Developer can access all resources and STM32 firmware library. (Must copy thestm32f10x_conf.h and glcd5110.h file into the target project first) and use sprintf

function for convert the string data type.

The code operation can describe with 3 sections as follows :

1. RCC_setup function - Set the clock system

1.1 HCLK = SYSCLK

1.2 PCLK2 = HCLK/1 = 72 MHz

1.3 PCLK1 = HCLK/2 = 36 MHz

1.4 ADCCLK = PCLK2/4 = 18 MHz

1.5 LATENCY for 2 wait state (48 MHz < SYSCLK <= 72 MHz)

2. GPIO_setup function - Select the GPIO operation mode. In this code, set the PC4as Analog input mode.

3. ADC_setup function - Set ADC module operation. In this code, set the a/ADCmodule operation as Independent mode. Select ADC1 module, Regular type input, Selectanalog input 14, Sample time as 13.5 ADC module clock cycles

Page 104: ARM Cortex-M3 Microcontroller board … ARM Cortex-M3 microcontroller board l 3 Preface The STM32 evaluation boards provide complete development platforms for the STM32F103 ARM® Cortex™-

98 l JX-STM32 ARM Cortex-M3 microcontroller board

(8.3) Build the project file and downlaod to STM32F103VBT6 on the JX-STM32microcontroller board. See more details in chapter 2 of this document.

(8.4) Run program.Try to adjust the knob of potentiomneter PC4 on the JX-STM32 board.

(8.5) Observe the operation on GLCD5110 screen relate the potentiometer adjustment.

The GLCD5110 will disply following the picture below :

- + ON

STM32

ON CAN

TERMINATE

CANMODE

ON

1

0

1

0BOOT0 BOOT1

0 x USER FLASH1 Embed. SRAM1 System MEM.

10

JTAGRESET

SWD/JTAG

USB

BATT

.

VDD

VBAT RESET

VO

LUM

E

ADCIN14

AMPLIFIER

JOYSTICK

JX-STM32ARM Cortex-M3 board

WAKEUPPA0

TAMPERPC13

SW1PB9

SW2PD7

LED4PC9

LED3PC8

LED2PC7

LED1PC6

UART2

UART1

BOOTLOADER

DC input 6-9V

SD/M

MC

3VdcBattery

CR20332

1

1

ADC%Demo...000

Nokia:204 0000

- - - - - - - - - - - - - -

0001250%%78900

ABCDE GHIJKLMNF

A IN14 8

Value following AIN14: is the digital data conversion from ADC module.Range is 0 to 4095.

Value under the Progress bar is ratio 0 to 100% (thus 100% = 4095).

All value could be changed from adjust the potentiometer at PC4/ADC14input port.


Top Related