Your browser does not support JavaScript! Skip to main content
Free 30-day trial DO-178C Handbook RapiCoupling Preview DO-178C Multicore Training Multicore Resources
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  RapiCouplingPreview - DCCC analysis

Multicore Verification

  MACH178  MACH178 Foundations  Multicore Timing Solution  RapiDaemons

Engineering Services

  V&V Services  Data Coupling & Control Coupling  Object code verification  Qualification  Training  Consultancy  Tool Integration  Support

Industries

  Civil Aviation (DO-178C)   Automotive (ISO 26262)   Military & Defense   Space

Other

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

Latest from Rapita HQ

Latest news

SAIF Autonomy to use RVS to verify their groundbreaking AI platform
RVS 3.22 Launched
Hybrid electric pioneers, Ascendance, join Rapita Systems Trailblazer Partnership Program
Magline joins Rapita Trailblazer Partnership Program to support DO-178 Certification
View News

Latest from the Rapita blog

How to certify multicore processors - what is everyone asking?
Data Coupling Basics in DO-178C
Control Coupling Basics in DO-178C
Components in Data Coupling and Control Coupling
View Blog

Latest discovery pages

control_tower DO-278A Guidance: Introduction to RTCA DO-278 approval
Picture of a car ISO 26262
DCCC Image Data Coupling & Control Coupling
Additional Coe verification thumb Verifying additional code for DO-178C
View Discovery pages

Upcoming events

Avionics and Testing Innovations 2025
2025-05-20
DASC 2025
2025-09-14
DO-178C Multicore In-person Training (Fort Worth, TX)
2025-10-01
DO-178C Multicore In-person Training (Toulouse)
2025-11-04
View Events

Technical resources for industry professionals

Latest White papers

Mitigation of interference in multicore processors for A(M)C 20-193
Sysgo WP
Developing DO-178C and ED-12C-certifiable multicore software
DO178C Handbook
Efficient Verification Through the DO-178C Life Cycle
View White papers

Latest Videos

Rapita Systems - Safety Through Quality
Simulation for the Motorola 68020 microprocessor with Sim68020
AI-driven Requirements Traceability for Faster Testing and Certification
Multicore software verification with RVS 3.22
View Videos

Latest Case studies

GMV case study front cover
GMV verify ISO26262 automotive software with RVS
Kappa: Verifying Airborne Video Systems for Air-to-Air Refueling using RVS
Supporting DanLaw with unit testing and code coverage analysis for automotive software
View Case studies

Other Resources

 Webinars

 Brochures

 Product briefs

 Technical notes

 Research projects

 Multicore resources

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 93 351 02 05
info@rapitasystems.com
Rapita Systems S.L.
Parc UPC, Edificio K2M
c/ Jordi Girona, 1-3
Barcelona 08034
Spain

Working at Rapita

Careers

Careers menu

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

Using I/O ports on the STM32 F4 Discovery

Breadcrumb

  1. Home
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

Mitigation of interference in multicore processors for A(M)C 20-193
Sysgo WP Developing DO-178C and ED-12C-certifiable multicore software
DO178C Handbook Efficient Verification Through the DO-178C Life Cycle
A Commercial Solution for Safety-Critical Multicore Timing Analysis

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
    • Multicore Timing Analysis
    • Embedded Software Testing Tools
    • Worst Case Execution Time
    • WCET Tools
    • Code coverage for Ada, C & C++
    • MC/DC Coverage
    • Verifying additional code for DO-178C
    • Timing analysis (WCET) & Code coverage for MATLAB® Simulink®
    • Data Coupling & Control Coupling
    • Aerospace Software Testing
    • Automotive Software Testing
    • Certifying eVTOL
    • DO-178C
    • AC 20-193 and AMC 20-193
    • ISO 26262
    • What is CAST-32A?

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