IRQ and POlling now working as well
This commit is contained in:
@ -1,7 +1,12 @@
|
||||
#include "interrupts.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_dma.h"
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
void (*spi1_user_handler) (void* args) = NULL;
|
||||
void * spi1_user_args = NULL;
|
||||
|
||||
@ -37,3 +42,32 @@ void SPI2_IRQHandler() {
|
||||
}
|
||||
Default_Handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA Rx interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void dma_rx_irq_handler(void* dma_handle) {
|
||||
HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dma_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA Rx interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void dma_tx_irq_handler(void* dma_handle) {
|
||||
HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dma_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SPIx interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void spi1_irq_handler(void* spi_handle)
|
||||
{
|
||||
HAL_SPI_IRQHandler((SPI_HandleTypeDef *) spi_handle);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,15 @@ typedef enum {
|
||||
*/
|
||||
void assign_spi_user_handler(SpiBus spiBus, user_handler_t user_handler, user_args_t user_args);
|
||||
|
||||
/**
|
||||
* Generic interrupt handlers supplied for convenience. Do not call these directly! Set them
|
||||
* instead with assign_dma_user_handler and assign_spi_user_handler functions.
|
||||
* @param dma_handle
|
||||
*/
|
||||
void dma_rx_irq_handler(void* dma_handle);
|
||||
void dma_tx_irq_handler(void* dma_handle);
|
||||
void spi1_irq_handler(void* spi_handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -11,10 +11,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void dma_rx_irq_handler(void* dma_handle);
|
||||
void dma_tx_irq_handler(void* dma_handle);
|
||||
void spi1_irq_handler(void* spi_handle);
|
||||
|
||||
/**
|
||||
* @brief SPI MSP Initialization
|
||||
* This function configures the hardware resources used in this example:
|
||||
@ -195,3 +191,17 @@ void hal_spi_msp_deinit_polling(void *hspi) {
|
||||
/* Configure SPI MOSI as alternate function */
|
||||
HAL_GPIO_DeInit(SPIx_MOSI_GPIO_PORT, SPIx_MOSI_PIN);
|
||||
}
|
||||
|
||||
void hal_spi_msp_init_interrupt(void *hspi) {
|
||||
hal_spi_msp_init_polling(hspi);
|
||||
// Configure the NVIC for SPI
|
||||
assign_spi_user_handler(SPI_1, &spi1_irq_handler, hspi);
|
||||
HAL_NVIC_SetPriority(SPIx_IRQn, 1, 0);
|
||||
HAL_NVIC_EnableIRQ(SPIx_IRQn);
|
||||
}
|
||||
|
||||
void hal_spi_msp_deinit_interrupt(void *hspi) {
|
||||
hal_spi_msp_deinit_polling(hspi);
|
||||
// Disable the NVIC for SPI
|
||||
HAL_NVIC_DisableIRQ(SPIx_IRQn);
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ void hal_spi_msp_deinit_dma(void *hspi);
|
||||
void hal_spi_msp_init_polling(void *hspi);
|
||||
void hal_spi_msp_deinit_polling(void *hspi);
|
||||
|
||||
void hal_spi_msp_init_interrupt(void *hspi);
|
||||
void hal_spi_msp_deinit_interrupt(void *hspi);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -32,34 +32,6 @@ SPI_HandleTypeDef* get_spi_handle() {
|
||||
return spiHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA Rx interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void dma_rx_irq_handler(void* dma_handle) {
|
||||
HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dma_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles DMA Rx interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void dma_tx_irq_handler(void* dma_handle) {
|
||||
HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dma_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles SPIx interrupt request.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void spi1_irq_handler(void* spi_handle)
|
||||
{
|
||||
HAL_SPI_IRQHandler((SPI_HandleTypeDef *) spi_handle);
|
||||
}
|
||||
|
||||
void set_spi_msp_functions(msp_func_t init_func, void* init_args, msp_func_t deinit_func,
|
||||
void* deinit_args) {
|
||||
msp_init_func = init_func;
|
||||
|
Reference in New Issue
Block a user