stm32-l053r8-em9304: enable interrupt on raising edge of SPI1_RDY, use IRQ instead of polling

This commit is contained in:
Matthias Ringwald 2017-06-25 19:05:56 +02:00
parent da01dde272
commit 2dba691ca6
7 changed files with 54 additions and 7 deletions

View File

@ -48,6 +48,7 @@
#define B1_Pin GPIO_PIN_13
#define B1_GPIO_Port GPIOC
#define B1_EXTI_IRQn EXTI4_15_IRQn
#define DEBUG_0_Pin GPIO_PIN_0
#define DEBUG_0_GPIO_Port GPIOC
#define USART_TX_Pin GPIO_PIN_2
@ -58,6 +59,7 @@
#define EN_GPIO_Port GPIOB
#define SPI1_RDY_Pin GPIO_PIN_9
#define SPI1_RDY_GPIO_Port GPIOA
#define SPI1_RDY_EXTI_IRQn EXTI4_15_IRQn
#define TMS_Pin GPIO_PIN_13
#define TMS_GPIO_Port GPIOA
#define TCK_Pin GPIO_PIN_14

View File

@ -46,6 +46,7 @@
/* Exported functions ------------------------------------------------------- */
void SysTick_Handler(void);
void EXTI4_15_IRQHandler(void);
void DMA1_Channel2_3_IRQHandler(void);
void SPI1_IRQHandler(void);

View File

@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [2.23.0] date: [Sun Jun 25 10:44:49 CEST 2017]
# File automatically-generated by tool: [projectgenerator] version: [2.23.0] date: [Sun Jun 25 18:34:23 CEST 2017]
##########################################################################################################################
# ------------------------------------------------

View File

@ -283,10 +283,14 @@ static void MX_GPIO_Init(void)
/*Configure GPIO pin : SPI1_RDY_Pin */
GPIO_InitStruct.Pin = SPI1_RDY_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(SPI1_RDY_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
}
/* USER CODE BEGIN 4 */

View File

@ -70,6 +70,21 @@ void SysTick_Handler(void)
/* please refer to the startup file (startup_stm32l0xx.s). */
/******************************************************************************/
/**
* @brief This function handles EXTI line 4 to 15 interrupts.
*/
void EXTI4_15_IRQHandler(void)
{
/* USER CODE BEGIN EXTI4_15_IRQn 0 */
/* USER CODE END EXTI4_15_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);
/* USER CODE BEGIN EXTI4_15_IRQn 1 */
/* USER CODE END EXTI4_15_IRQn 1 */
}
/**
* @brief This function handles DMA1 channel 2 and channel 3 interrupts.
*/

View File

@ -55,6 +55,7 @@ Mcu.UserName=STM32L053R8Tx
MxCube.Version=4.21.0
MxDb.Version=DB.4.0.210
NVIC.DMA1_Channel2_3_IRQn=true\:0\:0\:false\:false\:true
NVIC.EXTI4_15_IRQn=true\:0\:0\:false\:false\:true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:false
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:false
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:false
@ -90,7 +91,7 @@ PA7.Signal=SPI1_MOSI
PA9.GPIOParameters=GPIO_Label
PA9.GPIO_Label=SPI1_RDY
PA9.Locked=true
PA9.Signal=GPIO_Input
PA9.Signal=GPXTI9
PB10.GPIOParameters=GPIO_Label
PB10.GPIO_Label=EN
PB10.Locked=true
@ -187,6 +188,8 @@ RCC.VCOOutputFreq_Value=48000000
RCC.WatchDogFreq_Value=37000
SH.GPXTI13.0=GPIO_EXTI13
SH.GPXTI13.ConfNb=1
SH.GPXTI9.0=GPIO_EXTI9
SH.GPXTI9.ConfNb=1
SPI1.CalculateBaudRate=2.097 MBits/s
SPI1.Direction=SPI_DIRECTION_2LINES
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate

View File

@ -96,6 +96,11 @@ static uint16_t hal_spi_em9304_tx_size;
static int test_done;
static int event_received;
static int command_sent;
static volatile int run_loop_triggered;
static inline void hal_spi_em9304_trigger_run_loop(void){
run_loop_triggered = 1;
}
static inline int hal_spi_em9304_rdy(void){
return HAL_GPIO_ReadPin(SPI1_RDY_GPIO_Port, SPI1_RDY_Pin) == GPIO_PIN_SET;
@ -113,11 +118,11 @@ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi){
switch (hal_spi_em9304_state){
case SPI_EM9304_RX_W4_READ_COMMAND_SENT:
hal_spi_em9304_state = SPI_EM9304_RX_READ_COMMAND_SENT;
// trigger run loop;
hal_spi_em9304_trigger_run_loop();
break;
case SPI_EM9304_TX_W4_WRITE_COMMAND_SENT:
hal_spi_em9304_state = SPI_EM9304_TX_WRITE_COMMAND_SENT;
// trigger run loop;
hal_spi_em9304_trigger_run_loop();
break;
default:
break;
@ -128,7 +133,7 @@ void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi){
switch (hal_spi_em9304_state){
case SPI_EM9304_RX_W4_DATA_RECEIVED:
hal_spi_em9304_state = SPI_EM9304_RX_DATA_RECEIVED;
// trigger run loop;
hal_spi_em9304_trigger_run_loop();
break;
default:
break;
@ -139,13 +144,19 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi){
switch (hal_spi_em9304_state){
case SPI_EM9304_TX_W4_DATA_SENT:
hal_spi_em9304_state = SPI_EM9304_TX_DATA_SENT;
// trigger run loop;
hal_spi_em9304_trigger_run_loop();
break;
default:
break;
}
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
if (hal_spi_em9304_rdy()){
hal_spi_em9304_trigger_run_loop();
}
}
static void hal_spi_em9304_process(void){
uint16_t bytes_to_read;
uint16_t bytes_ready;
@ -265,7 +276,17 @@ void port_main(void){
hal_spi_em9304_reset();
int step = 0;
while (!test_done){
// wait for event / sleep
HAL_GPIO_WritePin(DEBUG_0_GPIO_Port, DEBUG_0_Pin, GPIO_PIN_SET);
while (!run_loop_triggered){};
HAL_GPIO_WritePin(DEBUG_0_GPIO_Port, DEBUG_0_Pin, GPIO_PIN_RESET);
run_loop_triggered = 0;
// handle event
hal_spi_em9304_process();
// simulate stack
switch (step){
case 0:
if (!event_received) continue;
@ -275,6 +296,7 @@ void port_main(void){
//
hal_spi_em9304_tx_data = hci_reset;
hal_spi_em9304_tx_size = sizeof(hci_reset);
hal_spi_em9304_trigger_run_loop();
step++;
break;
case 1: