0% found this document useful (0 votes)
14 views11 pages

ESD_exp01

The document outlines an experiment for toggling an LED on the STM32F439ZIT6U development board as part of an Embedded System Design course. It details the objectives, required equipment, theory behind the STM32F4 microcontroller, and provides a step-by-step procedure for software setup, building, and debugging. Additionally, it includes code snippets and hardware configuration necessary for the experiment.

Uploaded by

dindevishakha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views11 pages

ESD_exp01

The document outlines an experiment for toggling an LED on the STM32F439ZIT6U development board as part of an Embedded System Design course. It details the objectives, required equipment, theory behind the STM32F4 microcontroller, and provides a step-by-step procedure for software setup, building, and debugging. Additionally, it includes code snippets and hardware configuration necessary for the experiment.

Uploaded by

dindevishakha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

College of Engineering Pune Dept of Electrical Engineering

SUBJECT: EMBEDDED SYSTEM DESIGN


NAME:
BRANCH: CLASS:
MIS NO. :
DATE OF PERFORMANCE: DATE OF SUBMISSION:
EXAMINED:

EXPERIMENT NO - 01

TITLE: Toggle Led on STM32F439ZIT6U board

OBJECTIVE:

To Toggle on board led of STM32F4 board

EQUIPMENTS:

STM32F4 development board


Power supply
Development environment (STM32CubeIDE)

THEORY:

STM32F4 Microcontroller:
 Provides general-purpose input/output (GPIO) pins to connect to the sensor.
 Employs timers to generate the trigger pulse and measure the echo pulse duration.
 Possesses a built-in ADC (optional, depending on LCD type) for analog signals from some
LCDs.
 Integrates with various LCD driver/controller ICs using communication protocols like
SPI or I2C

COMPONENT SPECIFICATIONS:

1. STM32F4 Micro-controller (e.g., STM32F439ZI, STM32F446RE):

 Core: ARM Cortex-M4F processor


 Clock Speed: Up to 180 MHz (varies depending on the specific model)
 Memory:
o Flash memory: Up to 2 MB (varies depending on the specific model)
o RAM: Up to 1 MB (varies depending on the specific model)
 Peripherals:
o Timers: Multiple timers for various timing and pulse generation tasks

Embedded Systems Design


College of Engineering Pune Dept of Electrical Engineering

o General-Purpose Input/Output (GPIO) pins: For connecting to external


components like sensors and actuators
o Serial communication interfaces: SPI, I2C, USART (for communication with
other devices)
o Analog-to-Digital Converter (ADC, optional): For converting analog signals (e.g.,
from sensors) to digital values
 Power Consumption: Varies depending on clock speed and workload, but generally
offers low-power operation modes.

Onboard LEDs and Their GPIO Pin Locations:


Using an STM32F439ZI-based development board (such as the NUCLEO-F439ZI or
Discovery Kit), it usually has user LEDs. The mapping may vary depending on the
board, but common assignments are:
1. LD1 (Green)
o Connected to GPIOB, Pin PB0
o Always ON when power is supplied
2. LD2 (User led - Blue)
o Connected to GPIOB, Pin PB7
o Can be toggled via software
3. LD3 (user led – Red)
o Connected to GPIOB, Pin PB14
o Used for status indication (debugging, errors, etc.)

PROCEDURE:

Software setup in stm32cubeide:

 Launch stm32cubeide: open stm32cubeide on your computer.

 New project: click on "file" -> "new" -> "STM32 project."

 Board selection: in the "create a new stm32 project" window, select your specific
STM32F439ZIT6U board from the "device" selector. Refer to your board's user manual
or manufacturer's website for the exact board name (e.g., "NUCLEO-F439ZI").

 Project configuration: click on "next" and configure other project settings like project
name, location, and middleware selection (if applicable).

 Code generation: click on "finish" to generate the initial project code structure.

 Configure the led’s and use HAL_Delay() to create a delay in milliseconds.

Building and debugging:


Embedded Systems Design
College of Engineering Pune Dept of Electrical Engineering

 Build the project: click on the "hammer" icon (build) on the toolbar to compile your
project code. If there are no errors, the build will be successful.

 Debug configuration: go to "run" -> "debug configurations" and ensure the debugger is
set to "st-link" and the connection interface is configured correctly (usually swd).

 Debug your code: click on the "debug" button (play icon) on the toolbar. This will start a
debugging session, allowing you to step through code, set breakpoints, and examine
variables while the code runs on your STM32F439ZIT6U board.

STM32F439ZIT6U BOARD:

HARDWARE:

Embedded Systems Design


College of Engineering Pune Dept of Electrical Engineering

CODE:

#include "main.h"

#include "string.h"

ETH_TxPacketConfig TxConfig;

ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT];

ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT];

ETH_HandleTypeDef heth;

UART_HandleTypeDef huart3;

PCD_HandleTypeDef hpcd_USB_OTG_FS;

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_ETH_Init(void);

static void MX_USART3_UART_Init(void);

static void MX_USB_OTG_FS_PCD_Init(void);

int main(void)

HAL_Init();

SystemClock_Config();

MX_GPIO_Init();

MX_ETH_Init();

MX_USART3_UART_Init();

MX_USB_OTG_FS_PCD_Init();

while (1)

Embedded Systems Design


College of Engineering Pune Dept of Electrical Engineering

HAL_GPIO_WritePin(GPIOB,GPIO_PIN_7,);

HAL_Delay(250);

HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,);

HAL_Delay(250);

HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,);

HAL_Delay(250);

void SystemClock_Config(void)

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

__HAL_RCC_PWR_CLK_ENABLE();

__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

RCC_OscInitStruct.PLL.PLLM = 4;

RCC_OscInitStruct.PLL.PLLN = 168;

RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

RCC_OscInitStruct.PLL.PLLQ = 7;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

Error_Handler();

Embedded Systems Design


College of Engineering Pune Dept of Electrical Engineering

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)

Error_Handler();

static void MX_ETH_Init(void)

static uint8_t MACAddr[6];

heth.Instance = ETH;

MACAddr[0] = 0x00;

MACAddr[1] = 0x80;

MACAddr[2] = 0xE1;

MACAddr[3] = 0x00;

MACAddr[4] = 0x00;

MACAddr[5] = 0x00;

heth.Init.MACAddr = &MACAddr[0];

heth.Init.MediaInterface = HAL_ETH_RMII_MODE;

heth.Init.TxDesc = DMATxDscrTab;

Embedded Systems Design


College of Engineering Pune Dept of Electrical Engineering

heth.Init.RxDesc = DMARxDscrTab;

heth.Init.RxBuffLen = 1524;

if (HAL_ETH_Init(&heth) != HAL_OK)

Error_Handler();

memset(&TxConfig, 0 , sizeof(ETH_TxPacketConfig));

TxConfig.Attributes = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD;

TxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC;

TxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT;

static void MX_USART3_UART_Init(void)

huart3.Instance = USART3;

huart3.Init.BaudRate = 115200;

huart3.Init.WordLength = UART_WORDLENGTH_8B;

huart3.Init.StopBits = UART_STOPBITS_1;

huart3.Init.Parity = UART_PARITY_NONE;

huart3.Init.Mode = UART_MODE_TX_RX;

huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart3.Init.OverSampling = UART_OVERSAMPLING_16;

if (HAL_UART_Init(&huart3) != HAL_OK)

Error_Handler();

static void MX_USB_OTG_FS_PCD_Init(void)

Embedded Systems Design


College of Engineering Pune Dept of Electrical Engineering

hpcd_USB_OTG_FS.Instance = USB_OTG_FS;

hpcd_USB_OTG_FS.Init.dev_endpoints = 4;

hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;

hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;

hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;

hpcd_USB_OTG_FS.Init.Sof_enable = ENABLE;

hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;

hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;

hpcd_USB_OTG_FS.Init.vbus_sensing_enable = ENABLE;

hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;

if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)

Error_Handler();

static void MX_GPIO_Init(void)

GPIO_InitTypeDef GPIO_InitStruct = {0};

__HAL_RCC_GPIOC_CLK_ENABLE();

__HAL_RCC_GPIOH_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();

__HAL_RCC_GPIOB_CLK_ENABLE();

__HAL_RCC_GPIOD_CLK_ENABLE();

__HAL_RCC_GPIOG_CLK_ENABLE();

/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(GPIOB, LD1_Pin|LD3_Pin|LD2_Pin, GPIO_PIN_RESET);

Embedded Systems Design


College of Engineering Pune Dept of Electrical Engineering

/*Configure GPIO pin Output Level */

HAL_GPIO_WritePin(USB_PowerSwitchOn_GPIO_Port, USB_PowerSwitchOn_Pin, GPIO_PIN_RESET);

/*Configure GPIO pin : USER_Btn_Pin */

GPIO_InitStruct.Pin = USER_Btn_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(USER_Btn_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pins : LD1_Pin LD3_Pin LD2_Pin */

GPIO_InitStruct.Pin = LD1_Pin|LD3_Pin|LD2_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

/*Configure GPIO pin : USB_PowerSwitchOn_Pin */

GPIO_InitStruct.Pin = USB_PowerSwitchOn_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

HAL_GPIO_Init(USB_PowerSwitchOn_GPIO_Port, &GPIO_InitStruct);

/*Configure GPIO pin : USB_OverCurrent_Pin */

GPIO_InitStruct.Pin = USB_OverCurrent_Pin;

GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

GPIO_InitStruct.Pull = GPIO_NOPULL;

Embedded Systems Design


College of Engineering Pune Dept of Electrical Engineering

HAL_GPIO_Init(USB_OverCurrent_GPIO_Port, &GPIO_InitStruct);

void Error_Handler(void)

__disable_irq();

while (1)

void assert_failed(uint8_t *file, uint32_t line)

#endif /* USE_FULL_ASSERT */

OUTPUT:

Embedded Systems Design


College of Engineering Pune Dept of Electrical Engineering

CONCLUSION:

Embedded Systems Design

You might also like