NavHAL 0.1.0
NAVRobotec's architecture-agnostic HAL for embedded systems.
Loading...
Searching...
No Matches
startup.c File Reference

Cortex-M4 startup code for STM32F4 series. More...

#include <stdint.h>
Include dependency graph for startup.c:

Macros

#define WEAK_ALIAS   __attribute__((weak, alias("Default_Handler")))

Functions

int main (void)
 Main application entry point.
void Default_Handler (void)
 Default interrupt handler.
void Reset_Handler (void)
 Reset handler for Cortex-M4.
void NMI_Handler (void)
 Vector table for Cortex-M4.

Variables

uint32_t _sidata
 Start of init values in flash (.data)
uint32_t _sdata
 Start of .data in RAM.
uint32_t _edata
 End of .data in RAM.
uint32_t _sbss
 Start of .bss.
uint32_t _ebss
 End of .bss.
uint32_t _estack

Detailed Description

Cortex-M4 startup code for STM32F4 series.

This file provides the vector table and reset handler implementation for initializing memory sections before calling the main application.

Macro Definition Documentation

◆ WEAK_ALIAS

#define WEAK_ALIAS   __attribute__((weak, alias("Default_Handler")))

Function Documentation

◆ Default_Handler()

void Default_Handler ( void )

Default interrupt handler.

Called if no specific interrupt handler is defined. Loops forever to indicate an unhandled interrupt.

◆ main()

int main ( void )
extern

Main application entry point.

Main application entry point.

Initializes GPIOA pin 5 as output and toggles it in an infinite loop. Typically connected to an LED (e.g., onboard LED on Nucleo boards).

Main application entry point.

Main entry point.

  • Initializes system clock using PLL.
  • Configures SysTick timer.
  • Initializes UART2 for console output.
  • Configures multiple timers with interrupts and attaches callbacks.
  • Enters infinite loop with optional debug prints.

Main application entry point.

Initializes GPIOA pin 5 as output and toggles it in an infinite loop. Typically connected to an LED (e.g., onboard LED on Nucleo boards).

Main entry point.

  • Initializes system clock using PLL.
  • Configures SysTick timer.
  • Initializes UART2 for console output.
  • Configures multiple timers with interrupts and attaches callbacks.
  • Enters infinite loop with optional debug prints.

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

< Send string over UART2

< Wait for 1 second

< Buffer to hold timer count as string

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

< Initialize TIM5 with auto-reload 1e9

< Convert timer value to string

< Print label

< Print TIM5 counter value

< Newline and carriage return

< Initialize system clock with PLL

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

Initialize TIM2, enable interrupt, attach callback

Initialize TIM3, enable interrupt, attach callback

Initialize TIM4, enable interrupt, attach callback

Initialize TIM5, enable interrupt, attach callback

Initialize TIM9, enable interrupt, attach callback

Optional debug prints uart2_write("SysTicks: "); uart2_write(hal_get_tick()); uart2_write(", Millis: "); uart2_write(timer_get_count(TIM5)); uart2_write("\n\r");

< Optional 1-second delay

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Configure PA05 as output

< Initialize TIM5 with prescaler 0 and auto-reload 1e9

< Set PA05 HIGH

< Delay 500 ms

< Set PA05 LOW

< Delay 500 ms

< Print label

< Print system millis

< Newline and carriage return

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Set PB10 as alternate function

< AF1 for TIM2_CH3

< Initialize PWM handle on TIM2, channel 3

< Init PWM at 15 kHz, 10% duty cycle

< Start PWM output

< Variable for duty cycle update

< Update PWM duty cycle

< Increment duty cycle by 1%

< Reset to 0% after 100%

< Print current duty cycle over UART2

< Newline and carriage return

< Delay 10 ms

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

< Send string over UART2

< Wait for 1 second

< Buffer to hold timer count as string

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

< Initialize TIM5 with auto-reload 1e9

< Convert timer value to string

< Print label

< Print TIM5 counter value

< Newline and carriage return

< Initialize system clock with PLL

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

Initialize TIM2, enable interrupt, attach callback

Initialize TIM3, enable interrupt, attach callback

Initialize TIM4, enable interrupt, attach callback

Initialize TIM5, enable interrupt, attach callback

Initialize TIM9, enable interrupt, attach callback

Optional debug prints uart2_write("SysTicks: "); uart2_write(hal_get_tick()); uart2_write(", Millis: "); uart2_write(timer_get_count(TIM5)); uart2_write("\n\r");

< Optional 1-second delay

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Configure PA05 as output

< Initialize TIM5 with prescaler 0 and auto-reload 1e9

< Set PA05 HIGH

< Delay 500 ms

< Set PA05 LOW

< Delay 500 ms

< Print label

< Print system millis

< Newline and carriage return

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Set PB10 as alternate function

< AF1 for TIM2_CH3

< Initialize PWM handle on TIM2, channel 3

< Init PWM at 15 kHz, 10% duty cycle

< Start PWM output

< Variable for duty cycle update

< Update PWM duty cycle

< Increment duty cycle by 1%

< Reset to 0% after 100%

< Print current duty cycle over UART2

< Newline and carriage return

< Delay 10 ms

< Initialize system clock with PLL

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Print SYSCLK label

< Print system clock

< Print APB1CLK label

< Print APB1 clock

< Print APB2CLK label

< Print APB2 clock

< Print AHBCLK label

< Print AHB clock

< Newline

< Wait 1 second

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

< Send string over UART2

< Wait for 1 second

< Buffer to hold timer count as string

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

< Initialize TIM5 with auto-reload 1e9

< Convert timer value to string

< Print label

< Print TIM5 counter value

< Newline and carriage return

< Initialize system clock with PLL

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

Initialize TIM2, enable interrupt, attach callback

Initialize TIM3, enable interrupt, attach callback

Initialize TIM4, enable interrupt, attach callback

Initialize TIM5, enable interrupt, attach callback

Initialize TIM9, enable interrupt, attach callback

Optional debug prints uart2_write("SysTicks: "); uart2_write(hal_get_tick()); uart2_write(", Millis: "); uart2_write(timer_get_count(TIM5)); uart2_write("\n\r");

< Optional 1-second delay

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Configure PA05 as output

< Initialize TIM5 with prescaler 0 and auto-reload 1e9

< Set PA05 HIGH

< Delay 500 ms

< Set PA05 LOW

< Delay 500 ms

< Print label

< Print system millis

< Newline and carriage return

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Set PB10 as alternate function

< AF1 for TIM2_CH3

< Initialize PWM handle on TIM2, channel 3

< Init PWM at 15 kHz, 10% duty cycle

< Start PWM output

< Variable for duty cycle update

< Update PWM duty cycle

< Increment duty cycle by 1%

< Reset to 0% after 100%

< Print current duty cycle over UART2

< Newline and carriage return

< Delay 10 ms

< Initialize system clock with PLL

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Print SYSCLK label

< Print system clock

< Print APB1CLK label

< Print APB1 clock

< Print APB2CLK label

< Print APB2 clock

< Print AHBCLK label

< Print AHB clock

< Newline

< Wait 1 second

< Initialize SysTick for delays

< Initialize UART2 at 9600 baud

< Stop execution if I2C init fails

< Wait for conversion (~4.5 ms for temperature)

< Assumes uart2_write_int exists

< Wait 1 second before next measurement

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

< Send string over UART2

< Wait for 1 second

< Buffer to hold timer count as string

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

< Initialize TIM5 with auto-reload 1e9

< Convert timer value to string

< Print label

< Print TIM5 counter value

< Newline and carriage return

< Initialize system clock with PLL

< Initialize SysTick with 1 ms tick

< Initialize UART2 at 9600 baud

Initialize TIM2, enable interrupt, attach callback

Initialize TIM3, enable interrupt, attach callback

Initialize TIM4, enable interrupt, attach callback

Initialize TIM5, enable interrupt, attach callback

Initialize TIM9, enable interrupt, attach callback

Optional debug prints uart2_write("SysTicks: "); uart2_write(hal_get_tick()); uart2_write(", Millis: "); uart2_write(timer_get_count(TIM5)); uart2_write("\n\r");

< Optional 1-second delay

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Configure PA05 as output

< Initialize TIM5 with prescaler 0 and auto-reload 1e9

< Set PA05 HIGH

< Delay 500 ms

< Set PA05 LOW

< Delay 500 ms

< Print label

< Print system millis

< Newline and carriage return

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Set PB10 as alternate function

< AF1 for TIM2_CH3

< Initialize PWM handle on TIM2, channel 3

< Init PWM at 15 kHz, 10% duty cycle

< Start PWM output

< Variable for duty cycle update

< Update PWM duty cycle

< Increment duty cycle by 1%

< Reset to 0% after 100%

< Print current duty cycle over UART2

< Newline and carriage return

< Delay 10 ms

< Initialize system clock with PLL

< Initialize SysTick with 40 µs tick

< Initialize UART2 at 9600 baud

< Print SYSCLK label

< Print system clock

< Print APB1CLK label

< Print APB1 clock

< Print APB2CLK label

< Print APB2 clock

< Print AHBCLK label

< Print AHB clock

< Newline

< Wait 1 second

< Initialize SysTick for delays

< Initialize UART2 at 9600 baud

< Stop execution if I2C init fails

< Wait for conversion (~4.5 ms for temperature)

< Assumes uart2_write_int exists

< Wait 1 second before next measurement

◆ NMI_Handler()

void NMI_Handler ( void )

Vector table for Cortex-M4.

This table contains the initial stack pointer and pointers to all exception and interrupt handlers.

< Initial Stack Pointer

< Reset Handler

< NMI Handler

< Hard Fault Handler

< MPU Fault Handler

< Bus Fault Handler

< Usage Fault Handler

< Reserved

< SVCall Handler

< Debug Monitor Handler

< Reserved

< PendSV Handler

< SysTick Handler

◆ Reset_Handler()

void Reset_Handler ( void )

Reset handler for Cortex-M4.

Initializes the .data and .bss sections, enables interrupts, and calls the main application.

Variable Documentation

◆ _ebss

uint32_t _ebss
extern

End of .bss.

◆ _edata

uint32_t _edata
extern

End of .data in RAM.

◆ _estack

uint32_t _estack
extern

◆ _sbss

uint32_t _sbss
extern

Start of .bss.

◆ _sdata

uint32_t _sdata
extern

Start of .data in RAM.

◆ _sidata

uint32_t _sidata
extern

Start of init values in flash (.data)