Your browser does not support JavaScript! Skip to main content
Free 30-day trial Customer portal Careers DO-178C Handbook
 
Rapita Systems
 

Industry leading verification tools & services

Rapita Verification Suite (RVS)

  RapiTest - Unit/system testing   RapiCover - Structural coverage analysis   RapiTime - Timing analysis (inc. WCET)   RapiTask - Scheduling visualization   RapiCoverZero - Zero footprint coverage analysis   RapiTimeZero - Zero footprint timing analysis   RapiTaskZero - Zero footprint scheduling analysis

Multicore verification

  MACH178   Multicore Timing Solution   RapiDaemons

Services

  V & V Services   Qualification   Training   Tool Integration  Support

Industries

  Aerospace (DO-178C)   Automotive (ISO 26262)   Space

Other

  RTBx   Mx-Suite   Software licensing   Product life cycle policy  RVS development roadmap

Latest from Rapita HQ

Latest news

RVS 3.18 Launched
Solid Sands partners with Rapita Systems
Danlaw Acquires Maspatechnologies - Expanding Rapita Systems to Spain
Rapita co-authored paper wins ERTS22 Best paper award
View News

Latest from the Rapita blog

Why mitigating interference alone isn’t enough to verify timing performance for multicore DO-178C projects
There are how many sources of interference in a multicore system?
Supporting modern development methodologies for verification of safety-critical software
Flexible licensing software fit for modern working
View Blog

Latest discovery pages

do178c DO-178C Guidance: Introduction to RTCA DO-178 certification
matlab_simulink MATLAB® Simulink® MCDC coverage and WCET analysis
code_coverage_ada Code coverage for Ada, C and C++
amc-20-193 AMC 20-193
View Discovery pages

Upcoming events

Aerospace Tech Week Europe 2023
2023-03-29
Aeromart Montreal 2023
2023-04-04
Certification Together International Conference
2023-05-10
View Events

Technical resources for industry professionals

Latest White papers

DO178C Handbook
Efficient Verification Through the DO-178C Life Cycle
A Commercial Solution for Safety-Critical Multicore Timing Analysis
Compliance with the Future Airborne Capability Environment (FACE) standard
View White papers

Latest Videos

Streamlined software verification with RVS 3.18
Sequence analysis with RapiTime
Visualize call dependencies with RVS thumbnail
Visualize call dependencies with RVS
Analyze code complexity thumbnail
Analyze code complexity with RVS
View Videos

Latest Case studies

Supporting ISO 26262 ASIL D software verification for EasyMile
RapiCover’s advanced features accelerate the certification of military UAV Engine Control
Front cover of whitepaper collins
Delivering world-class tool support to Collins Aerospace
View Case studies

Other Downloads

 Webinars

 Brochures

 Product briefs

 Technical notes

 Research projects

Discover Rapita

Who we are

The company menu

  • About us
  • Customers
  • Distributors
  • Locations
  • Partners
  • Research projects
  • Contact us

US office

+1 248-957-9801
info@rapitasystems.com
Rapita Systems, Inc.
41131 Vincenti Ct.
Novi
MI 48375
USA

UK office

+44 (0)1904 413945
info@rapitasystems.com
Rapita Systems Ltd.
Atlas House
Osbaldwick Link Road
York, YO10 3JB
UK

Spain office

+34 930 46 42 72
info@rapitasystems.com
Rapita Systems S.L.
Parc UPC, Edificio K2M
c/ Jordi Girona, 1-3, Office 306-307
Barcelona 08034
Spain

Working at Rapita

Careers

Careers menu

  • Current opportunities & application process
  • Working at Rapita
Back to Top

Using I/O ports on the STM32 F4 Discovery

Breadcrumb

  1. Home
  2. Blog
  3. Using I/O ports on the STM32 F4 Discovery
2013-01-15

The STM32 F4 Discovery board is currently our board of choice for demonstrations and training at Rapita Systems. Here I will explain why we chose it and demonstrate how to set the STM32 F4 Discovery up as an output port without using ST libraries.

Why we chose the STM32 F4 Discovery

It has a suitable amount of constraints to enable us to show how we get round some of the problems of on-target verification on embedded systems, without being too tricky and at a very agreeable price.

How we use the STM32 F4 Discovery

At Rapita, our main interest in writing to output ports of microcontrollers is to collect structural coverage or execution time data from code that has been instrumented by our RVS tools.

The RTBx provides an efficient method to collect RVS data, and as such we'll discuss how to set the STM32 F4 Discovery board up to write data suitable for collection by the RTBx.

We want to set up the output port so we have strong signals on output pins. Here is an example implementation for setting the first 8 pins of port B as outputs:

{
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Pin = 	GPIO_Pin_0 |
							GPIO_Pin_1 |
							GPIO_Pin_2 |
							GPIO_Pin_3 |
							GPIO_Pin_4 |
							GPIO_Pin_5 |
							GPIO_Pin_6 |
							GPIO_Pin_7;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_Init(GPIOB,&GPIO_InitStructure);
}

This is fairly simple, but relies entirely on the firmware Libraries for the board, which can be downloaded from the ST website. So I'm going to explain what each part of this code snippet does and show you how to achieve the same thing manually without the ST libraries.

Setting the STM32 F4 Discovery up without using libraries

For power consumption efficiency the peripheral clock is gated for most peripherals on the device. So, the first call to RCC_AHB1PeriphClockCmd enables the peripheral clock for GPIO on the B port. This sets bit 1 in the RCC AHB1 peripheral clock register (RCC_AHB1ENR). To do this manually, you'd simply set

RCC_AHB1ENR |= 0x0002;

Next, we select which pins on that port we want to enable - in this case the full 8 bits for this port, pin 0 to 7. This does not actually have an equivalent register call - it simply defines which parts of the various registers we need to set later. As we're looking at the lower 8 pins on the port, we will either be setting the lower word or lower byte (depending on how wide the register settings are) for the set up explained below. We have the option of setting the IO mode to be input, output, alternative function or analogue. We're setting this to output, which is equivalent to this:

GPIOB_MODER &= 0xFFFF0000; /* clear the bits first - reset value
is not 0x00000000 on Port B */
GPIOB_MODER |= 0x00005555;

The first 8 bits of the port are set using the lower word of the register control. Input is 00 in binary, output is 01. Having set the pins to be output pins we now need to set the type of output and the speed they'll be driven at. This is done using the OTYPER and OSPEEDR registers. The output mode options available are push-pull or open drain. In our case we want the pin driven hard to get the cleanest edges possible so we've chosen Push-pull. This is equivalent to cleaning the bits for pin 0-7 like this:

GPIOB_OTYPER &= 0xFF00;

As we can potentially sample at 100 MHz, we want the output pins going as quickly as possible - although the STM32 board can be clocked at 168 MHz the pins seem to be limited to a maximum speed of 100 MHz (assuming 30pF). The reset value of this register is not zero, but as we want to set all the bits in the lower word there is no value in clearing those bits first:

GPIOB_OSPEEDR |= 0x0000FFFF;

Next, we set this output port to have an internal pull down:

GPIOB_PUPDR &= 0xFFFF0000; /* clear the bits first - reset value 
is not 0x00000000 on Port B */
GPIOB_PUPDR |= 0x0000AAAA;

Each pin has the following options in binary:

00 no pull up or pull down
01 pull up
10 pull down

Calling GPIO_Init initializes the port with the options I've outlined above. With these registers correctly configured, outputting a value is as simple as:

GPIOB_ODR = output_value;

Interested in RVS?


Learn more Free trial

DO-178C webinars

DO178C webinars

White papers

DO178C Handbook Efficient Verification Through the DO-178C Life Cycle
A Commercial Solution for Safety-Critical Multicore Timing Analysis
Compliance with the Future Airborne Capability Environment (FACE) standard
5 key factors to consider when selecting an embedded testing tool

Related blog posts

How did the first real-time embedded system also produce the first timing bug?

.
2019-07-16

Unboxing the new RTBx

.
2017-07-25

Optimising for code size might not do what you expect - a GCC and PowerPC example

.
2015-02-09

Lesser used PowerPC instructions

.
2014-02-25

Pagination

  • Current page 1
  • Page 2
  • Page 3
  • Page 4
  • Next page Next ›
  • Last page Last »
  • Solutions
    • Rapita Verification Suite
    • RapiTest
    • RapiCover
    • RapiTime
    • RapiTask
    • MACH178

    • Verification and Validation Services
    • Qualification
    • Training
    • Integration
  • Latest
  • Latest menu

    • News
    • Blog
    • Events
    • Videos
  • Downloads
  • Downloads menu

    • Brochures
    • Webinars
    • White Papers
    • Case Studies
    • Product briefs
    • Technical notes
    • Software licensing
  • Company
  • Company menu

    • About Rapita
    • Careers
    • Customers
    • Distributors
    • Industries
    • Locations
    • Partners
    • Research projects
    • Contact
  • Discover
    • AMC 20-193
    • What is CAST-32A?
    • Multicore Timing Analysis
    • MC/DC Coverage
    • Code coverage for Ada, C & C++
    • Embedded Software Testing Tools
    • Aerospace Software Testing
    • Automotive Software Testing
    • Certifying eVTOL
    • DO-178C
    • WCET Tools
    • Worst Case Execution Time
    • Timing analysis (WCET) & Code coverage for MATLAB® Simulink®

All materials © Rapita Systems Ltd. 2023 - All rights reserved | Privacy information | Trademark notice Subscribe to our newsletter