What happens if we change the callback identifier

Assignment Help Other Engineering
Reference no: EM133688331

Introduction to Embedded Computing

Multiple Choice Question 1

In Ass-3-Q1.c, why is IntCount defined as a global variable?
a) To save memory space.
b) It is an arbitrary decision, and the code works equally well even if it is defined as a local variable.
c) So that it can be accessed by multiple functions.
d) None of the above. Enter your answer on Canvas.

Configuration Information

Navigate to the MX_GPIO_Init(void) function in main.c. Search for JOY_C_Pin and see what the initialisation code looks like. The code is similar to the other pins that have been config- ured as inputs only that this one has the mode set to GPIO_MODE_IT_FALLING. Since this an interrupt input, additional information is required.
Recall that PB15 is connected to the external interrupt line 10:15. Search for EXTI15_10 in
main.c to see the priority being set and the interrupt enabled.
Finally, the Interrupt Service Routine (ISR) needs to be defined. The ISR name is found in
Startup/startup_stm32f407vgtx.s. Look under the section /* External Interrupts
*/ for the ISR that is responsible for external lines 10 to 15. The ISR is defined in Core/Src/stm32f4xx_it.c. Check that the ISR calls another function in stm32f4xx_hal_gpio.c, which calls the callback function. The callback function is defined as a weak function that can be overridden by the user program. Have a look at the three functions
in the two files mentioned.

Multiple Choice Question 1.2

What is the purpose of the call to HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin) in stm32f4xx_hal_gpio.c?
a) Has no effect on the operation of the interrupt.
b) Forces the interrupt input pin (PB15) low.
c) Signals the MCU to start the callback function.
d) Resets the corresponding pending bit of the EXTI controller. Enter your answer on Canvas.

Interrupt Example

There are two parts to the code in Ass-3-Q1.c. The first is the main loop Ass_3_main (void), which checks a variable IntCount that gets updated in the ISR.
Each time around the loop, the value of the variable that is updated in the ISR is printed on the console if the value has changed. The ISR callback function is HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin).
Compile and run the program (under debug mode) to view the output in console. Observe what is printed out when the joystick is moved down. Note that no debouncing is implemented so sometimes one of the numbers does not get printed out as one would expect.
The interrupt connected to the joystick input is configured to be falling-edge triggered. Change the operation of the interrupt to rising edge triggered and observed what changes when the program is run. There are two ways to do this (try both):

Using the Device Configuration Tool.
Changing GPIO_MODE_IT_FALLING to GPIO_MODE_IT_RISING in Ass_3_main (void).

Multiple Choice Question 1.3

What is the effect of changing GPIO_MODE_IT_FALLING to GPIO_MODE_IT_RISING?
a) The ISR is called when down joystick is released.
b) There is no change to the operation of the program.
c) ISR does not run at all.
d) The program crashes. Enter your answer on Canvas.
Read through the HAL documentation to become familiar with functions used for interrupts.

Direct Memory Access
This exercise uses the STM32CubeIDE device configuration tool to set up DMA. The HAL will also be used to configure and initiate a DMA transfer.

STM32CubeIDE
In Device Configuration Tool, go to System Core → DMA → DMA2. Add a MEMTOMEM (memory-to-memory) DMA request. By default, DMA2 Stream 0 is created. Configure the following:
Mode: Normal
Use Fifo: Yes
Threshold: Full
Increment Address: Yes for both
Data Width: Word for both
Burst Size: Single for both
In System Core → NVIC, enable the interrupt for DMA2 stream0.
Save to update code.
For Section 2, we will create another source file Ass-3-Q2.c containing the same function
void Ass_3_main (void) as follows:

When we configure the DMA, a new variable
DMA_HandleTypeDef hdma_memtomem_dma2_stream0;
is defined in main.c (look under /* Private variables). To ensure that we can use this variable in Ass-3-Q2.c, we declare this variable in header file Ass-3.h. Add this line to Ass-3.h:

Also, in order to run function void Ass_3_main (void) in Ass-3-Q2.c instead of the same one in Ass-3-Q1.c, we change the definition of DO_QUESTION from 1 to 2 in the header file. Save all files.
Navigate to Ass-3-Q1.c. You will see that some parts are greyed out. This indicates that the portion will be removed by the preprocessor due to the change in the definition of DO_QUESTION. So, at any one time, the compiler will see only one version of void Ass_3_main (void).

Multiple Choice Question 2.1

In our DMA configuration, both Src Memory and Dst Memory are marked for incrementation. Where would not incrementing the address be useful?
a) Reading from a device, such as a UART receive data register.
b) Writing to a device, such as a UART transmit data register.
c) Filling a large portion of memory with the same value.
d) All of the above. Enter your answer on Canvas.

Configuration Information

Navigate to main.c. There is only one DMA stream configured, which is for the memory- to-memory transfer. Have a look at the configuration parameters in the initialisation function MX_DMA_Init(), referring to the HAL manual (UM1725, page 263) to see the meaning of pa- rameters.

Multiple Choice Question 2.2

What is missing from the DMA initialisation function in main.c?
a) DMA controller stream and channel.
b) Direction of transfer.

c) Start address for the source and destination.
d) DMA FIFO thresholds. Enter your answer on Canvas.

DMA Example

Compile the project and run it under the debug mode.
Polling of the DMA controller is used to check that if the transfer has been complete. It also unlocks the DMA, which is locked by HAL_DMA_Start().
View the output in the console. Observe that memory has been copied from the source to the destination using DMA. Try experimenting with the code, changing some of the parameters of the transfer. Note that it is very easy to crash the program if it writes to the wrong memory location.

Multiple Choice Question 2.3-a

What is the effect of changing the Data Width of both the Src Memory and the Dst Memory
from Word to Byte in the Device Configuration Tool?
a) Only two characters are transferred by the DMA.
b) Only four characters are transferred by the DMA.
c) The transfer does not take place.
d) None of the above.

Multiple Choice Question 2.3-b

What is the effect of changing the argument for data length from 2 to 1 in the following command in Ass_3_main()?
HAL_DMA_Start (&hdma_memtomem_dma2_stream0, (uint32_t) src, (uint32_t) dst, 2);
a) Only two characters are transferred by the DMA.
b) Only four characters are transferred by the DMA.
c) The transfer does not take place.
d) None of the above. Enter your answer on Canvas.
Read through the HAL documentation to become familiar with the DMA functions.

Direct Memory Access and Interrupts

This exercise is similar to the previous one, only that an interrupt is used to indicate the end of a DMA transfer.

STM32CubeIDE

Now, we will create another source file Ass-3-Q3.c with another version of the function
Ass_3_main (void):

Remember to change the definition of DO_QUESTION in the header file from 2 to 3.

Multiple Choice Question 3.1

Why is there no rising or falling edge trigger option required for the DMA interrupt like that for GPIO interrupts?
a) There should be an option, but STM32CubeIDE does not implement it.
b) The DMA interrupt is an internal signal, and so there is no need for such an option.
c) Rising edge is assumed.
d) Falling edge is assumed. Enter your answer on Canvas.

Configuration Information

Compile and run the project under debug mode to view the output. Observe that memory has been copied from the source to the destination using DMA. Try experimenting with the code, changing some of the parameters of the transfer.
Navigate to the MX_DMA_Init(void) function in main.c. In the previous exercise, you would have noticed the code at the end of the DMA initialisation function that sets up the NVIC for the DMA interrupt. This has been automatically set up when we enabled the DMA2 stream0 global interrupt in System Core → NVIC using the Device Configuration Tool.

Multiple Choice Question 3.2

What would happen if the code that sets up the NVIC for the DMA interrupt in main.c was commented out?
a) Both DMA transfer and DMA interrupt would still occur.

b) Both DMA transfer and DMA interrupt would not occur.
c) DMA transfer would still occur, but DMA interrupt would not occur.
d) DMA transfer would not occur, but DMA interrupt would still occur.y Enter your answer on Canvas.

DMA with Interrupt Example

Unlike the GPIO external interrupts, the callback function for DMA needs to be registered. This is done using HAL_DMA_RegisterCallback at the start of the function Ass_3_main (void). If the callback function is not required anymore, it can be unregistered.
In the code supplied, the callback function is void DMACallback(DMA_HandleTypeDef * hdma). Check the function HAL_DMA_RegisterCallback in stm32f4xx_hal_dma.c to find out what arguments the callback function takes and what it returns.
The second argument supplied to the function HAL_DMA_RegisterCallback is the callback identifier HAL_DMA_CallbackIDTypeDef defined in stm32f4xx_hal_dma.h. It registers which stage during the DMA the interrupt should fire. The identifiers include HAL_DMA_XFER_CPLT_CB_ID for full transfer and HAL_DMA_XFER_HALFCPLT_CB_ID for half transfer.

Multiple Choice Question 3.3

What happens if we change the callback identifier from HAL_DMA_XFER_CPLT_CB_ID to HAL_DMA_XFER_HALFCPLT_CB_ID when calling HAL_DMA_RegisterCallback?
a) There is no noticeable change in the output since the DMA happens very quickly.
b) The program crashes.
c) The program does not compile.
d) DMA does not start. Enter your answer on Canvas.
Read through the HAL documentation to become familiar with the additional DMA functions with interrupts.

Direct Memory Access to Special Function Register (12 Marks)
The aim of this exercise is to write some code that will demonstrate the use of interrupt events to trigger DMA transfer to certain memory addresses that control peripherals.

Program requirement
Write your code for this question in Ass-3-Q4.c.
Your code should do the following:
The green, the red, and the blue LEDs will be used.
Pushing the joystick to the A position turns only the green LED on and the rest off. Pushing the joystick to the D position turns only the red LED on and the rest off.
Pushing the joystick to the C position turns only the blue LED on and the rest off. Pushing the joystick to the CTR position turns all the three LEDs off.
Pushes of the joystick to positions A, D, C, and CTR are detected using EXTI inter- rupts. Do not use the HAL_GPIO_ReadPin function.
Use the EXTI interrupt service routine (ISR) to only set a flag to determine which joystick position is recorded. Do not read or write the LED setting in the ISR.
The LEDs should be controlled solely using DMA in the memory-to-memory mode, by transferring data from a memory location to the memory address of the bit set/reset register (BSRR) of the GPIO port. Transfer only one word per one joystick push. Do not use the HAL_GPIO_WritePin function.
DMA operations should be started in the looping executive, that is, within the while(1)
loop in Ass_3_main (void).
Avoid unnecessary commands, for example, perform a DMA transfer only when a button is pushed.
Hints:
The address of the bit set/reset register (BSRR) of the GPIOD port is &(GPIOD->BSRR).
Refer to the section on GPIO port bit set/reset register (GPIOx_BSRR) in the RM0090 Reference Manual for the usage of the BSRR.
Use HAL_DMA_Start_IT instead of HAL_DMA_Start as the latter required
HAL_DMA_PollForTransfer to unlock the DMA after the operation.
Think about whether or not you need to debounce the joystick for this application.

Demonstration

The following will be marked by the lab demonstrator during the lab session:

a) Joystick turns on/off LEDs.
b) Interrupt detects joystick pushes.
c) DMA controls LEDs.

d) ISR sets a flag.
e) Efficient code, no unnecessary commands.
f) Able to explain code.

Reference no: EM133688331

Questions Cloud

Build a model to predict which customers will buy headphones : Build a model to estimate Sales of a GroceryPlus store and Build a model to predict which customers will buy headphones after purchasing a mobile phone
Caring for their child with nasopharyngitis : For which clinical signs would the nurse recommend the family contact the health care provider when caring for their child with nasopharyngitis?
Evaluate own learning as a data analyst : MIS771 Descriptive Analytics and Visualisation, Deakin Business School - Apply quantitative reasoning skills to solve complex problems
Design a brand marketing program : MKT2BBM Branding And Brand Management, La Trobe University - Design a marketing program - based on your findings from part a, design a brand marketing program
What happens if we change the callback identifier : ELEC2720 Introduction to Embedded Computing, University of Newcastle - What is the purpose of the call to HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin) in stm32f4xx_hal_gpio
Medication error based on which transcribed prescription : The risk management nurse conducts audit of client's medical record and determines a potential for a medication error based on which transcribed prescription?
Engage in critical evaluation of the external stakeholders : Engage in a critical evaluation of the external stakeholders involved in your healthcare setting.
Woman presents to clinic with chief complaint of shaking : A 51-year-old woman presents to clinic with a chief complaint of shaking in her left hand. She is right handed.
Diagnosis of huntington disease to the hiring committee : Identify the Issue: The issue at hand is that Bill Russo did not disclose his recent diagnosis of Huntington's disease to the hiring committee.

Reviews

Write a Review

Other Engineering Questions & Answers

  Characterization technology for nanomaterials

Calculate the reciprocal lattice of the body-centred cubic and Show that the reciprocal of the face-centred cubic (fcc) structure is itself a bcc structure.

  Calculate the gasoline savings

How much gasoline do vehicles with the following fuel efficiencies consume in one year? Calculate the gasoline savings, in gallons per year, created by the following two options. Show all your work, and draw boxes around your answers.

  Design and modelling of adsorption chromatography

Design and modelling of adsorption chromatography based on isotherm data

  Application of mechatronics engineering

Write an essay on Application of Mechatronics Engineering

  Growth chracteristics of the organism

To examine the relationship between fermenter design and operating conditions, oxygen transfer capability and microbial growth.

  Block diagram, system performance and responses

Questions based on Block Diagram, System Performance and Responses.

  Explain the difference in a technical performance measure

good understanding of Mil-Std-499 and Mil-Std-499A

  Electrode impedances

How did this procedure affect the signal observed from the electrode and the electrode impedances?

  Write a report on environmental companies

Write a report on environmental companies

  Scanning electron microscopy

Prepare a schematic diagram below of the major parts of the SEM

  Design a pumping and piping system

creating the pumping and piping system to supply cool water to the condenser

  A repulsive potential energy should be a positive one

Using the data provided on the webvista site in the file marked vdw.txt, try to develop a mathematical equation for the vdW potential we discussed in class, U(x), that best fits the data

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd