mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-23 11:43:24 +00:00
stm32-l053r8-em9304: enable interrupt on raising edge of SPI1_RDY, use IRQ instead of polling
This commit is contained in:
parent
da01dde272
commit
2dba691ca6
@ -48,6 +48,7 @@
|
|||||||
|
|
||||||
#define B1_Pin GPIO_PIN_13
|
#define B1_Pin GPIO_PIN_13
|
||||||
#define B1_GPIO_Port GPIOC
|
#define B1_GPIO_Port GPIOC
|
||||||
|
#define B1_EXTI_IRQn EXTI4_15_IRQn
|
||||||
#define DEBUG_0_Pin GPIO_PIN_0
|
#define DEBUG_0_Pin GPIO_PIN_0
|
||||||
#define DEBUG_0_GPIO_Port GPIOC
|
#define DEBUG_0_GPIO_Port GPIOC
|
||||||
#define USART_TX_Pin GPIO_PIN_2
|
#define USART_TX_Pin GPIO_PIN_2
|
||||||
@ -58,6 +59,7 @@
|
|||||||
#define EN_GPIO_Port GPIOB
|
#define EN_GPIO_Port GPIOB
|
||||||
#define SPI1_RDY_Pin GPIO_PIN_9
|
#define SPI1_RDY_Pin GPIO_PIN_9
|
||||||
#define SPI1_RDY_GPIO_Port GPIOA
|
#define SPI1_RDY_GPIO_Port GPIOA
|
||||||
|
#define SPI1_RDY_EXTI_IRQn EXTI4_15_IRQn
|
||||||
#define TMS_Pin GPIO_PIN_13
|
#define TMS_Pin GPIO_PIN_13
|
||||||
#define TMS_GPIO_Port GPIOA
|
#define TMS_GPIO_Port GPIOA
|
||||||
#define TCK_Pin GPIO_PIN_14
|
#define TCK_Pin GPIO_PIN_14
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
/* Exported functions ------------------------------------------------------- */
|
/* Exported functions ------------------------------------------------------- */
|
||||||
|
|
||||||
void SysTick_Handler(void);
|
void SysTick_Handler(void);
|
||||||
|
void EXTI4_15_IRQHandler(void);
|
||||||
void DMA1_Channel2_3_IRQHandler(void);
|
void DMA1_Channel2_3_IRQHandler(void);
|
||||||
void SPI1_IRQHandler(void);
|
void SPI1_IRQHandler(void);
|
||||||
|
|
||||||
|
@ -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]
|
||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
|
@ -283,10 +283,14 @@ static void MX_GPIO_Init(void)
|
|||||||
|
|
||||||
/*Configure GPIO pin : SPI1_RDY_Pin */
|
/*Configure GPIO pin : SPI1_RDY_Pin */
|
||||||
GPIO_InitStruct.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;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(SPI1_RDY_GPIO_Port, &GPIO_InitStruct);
|
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 */
|
/* USER CODE BEGIN 4 */
|
||||||
|
@ -70,6 +70,21 @@ void SysTick_Handler(void)
|
|||||||
/* please refer to the startup file (startup_stm32l0xx.s). */
|
/* 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.
|
* @brief This function handles DMA1 channel 2 and channel 3 interrupts.
|
||||||
*/
|
*/
|
||||||
|
@ -55,6 +55,7 @@ Mcu.UserName=STM32L053R8Tx
|
|||||||
MxCube.Version=4.21.0
|
MxCube.Version=4.21.0
|
||||||
MxDb.Version=DB.4.0.210
|
MxDb.Version=DB.4.0.210
|
||||||
NVIC.DMA1_Channel2_3_IRQn=true\:0\:0\:false\:false\:true
|
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.HardFault_IRQn=true\:0\:0\:false\:false\:false
|
||||||
NVIC.NonMaskableInt_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
|
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:false
|
||||||
@ -90,7 +91,7 @@ PA7.Signal=SPI1_MOSI
|
|||||||
PA9.GPIOParameters=GPIO_Label
|
PA9.GPIOParameters=GPIO_Label
|
||||||
PA9.GPIO_Label=SPI1_RDY
|
PA9.GPIO_Label=SPI1_RDY
|
||||||
PA9.Locked=true
|
PA9.Locked=true
|
||||||
PA9.Signal=GPIO_Input
|
PA9.Signal=GPXTI9
|
||||||
PB10.GPIOParameters=GPIO_Label
|
PB10.GPIOParameters=GPIO_Label
|
||||||
PB10.GPIO_Label=EN
|
PB10.GPIO_Label=EN
|
||||||
PB10.Locked=true
|
PB10.Locked=true
|
||||||
@ -187,6 +188,8 @@ RCC.VCOOutputFreq_Value=48000000
|
|||||||
RCC.WatchDogFreq_Value=37000
|
RCC.WatchDogFreq_Value=37000
|
||||||
SH.GPXTI13.0=GPIO_EXTI13
|
SH.GPXTI13.0=GPIO_EXTI13
|
||||||
SH.GPXTI13.ConfNb=1
|
SH.GPXTI13.ConfNb=1
|
||||||
|
SH.GPXTI9.0=GPIO_EXTI9
|
||||||
|
SH.GPXTI9.ConfNb=1
|
||||||
SPI1.CalculateBaudRate=2.097 MBits/s
|
SPI1.CalculateBaudRate=2.097 MBits/s
|
||||||
SPI1.Direction=SPI_DIRECTION_2LINES
|
SPI1.Direction=SPI_DIRECTION_2LINES
|
||||||
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
|
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate
|
||||||
|
@ -96,6 +96,11 @@ static uint16_t hal_spi_em9304_tx_size;
|
|||||||
static int test_done;
|
static int test_done;
|
||||||
static int event_received;
|
static int event_received;
|
||||||
static int command_sent;
|
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){
|
static inline int hal_spi_em9304_rdy(void){
|
||||||
return HAL_GPIO_ReadPin(SPI1_RDY_GPIO_Port, SPI1_RDY_Pin) == GPIO_PIN_SET;
|
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){
|
switch (hal_spi_em9304_state){
|
||||||
case SPI_EM9304_RX_W4_READ_COMMAND_SENT:
|
case SPI_EM9304_RX_W4_READ_COMMAND_SENT:
|
||||||
hal_spi_em9304_state = SPI_EM9304_RX_READ_COMMAND_SENT;
|
hal_spi_em9304_state = SPI_EM9304_RX_READ_COMMAND_SENT;
|
||||||
// trigger run loop;
|
hal_spi_em9304_trigger_run_loop();
|
||||||
break;
|
break;
|
||||||
case SPI_EM9304_TX_W4_WRITE_COMMAND_SENT:
|
case SPI_EM9304_TX_W4_WRITE_COMMAND_SENT:
|
||||||
hal_spi_em9304_state = SPI_EM9304_TX_WRITE_COMMAND_SENT;
|
hal_spi_em9304_state = SPI_EM9304_TX_WRITE_COMMAND_SENT;
|
||||||
// trigger run loop;
|
hal_spi_em9304_trigger_run_loop();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -128,7 +133,7 @@ void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi){
|
|||||||
switch (hal_spi_em9304_state){
|
switch (hal_spi_em9304_state){
|
||||||
case SPI_EM9304_RX_W4_DATA_RECEIVED:
|
case SPI_EM9304_RX_W4_DATA_RECEIVED:
|
||||||
hal_spi_em9304_state = SPI_EM9304_RX_DATA_RECEIVED;
|
hal_spi_em9304_state = SPI_EM9304_RX_DATA_RECEIVED;
|
||||||
// trigger run loop;
|
hal_spi_em9304_trigger_run_loop();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -139,13 +144,19 @@ void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi){
|
|||||||
switch (hal_spi_em9304_state){
|
switch (hal_spi_em9304_state){
|
||||||
case SPI_EM9304_TX_W4_DATA_SENT:
|
case SPI_EM9304_TX_W4_DATA_SENT:
|
||||||
hal_spi_em9304_state = SPI_EM9304_TX_DATA_SENT;
|
hal_spi_em9304_state = SPI_EM9304_TX_DATA_SENT;
|
||||||
// trigger run loop;
|
hal_spi_em9304_trigger_run_loop();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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){
|
static void hal_spi_em9304_process(void){
|
||||||
uint16_t bytes_to_read;
|
uint16_t bytes_to_read;
|
||||||
uint16_t bytes_ready;
|
uint16_t bytes_ready;
|
||||||
@ -265,7 +276,17 @@ void port_main(void){
|
|||||||
hal_spi_em9304_reset();
|
hal_spi_em9304_reset();
|
||||||
int step = 0;
|
int step = 0;
|
||||||
while (!test_done){
|
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();
|
hal_spi_em9304_process();
|
||||||
|
|
||||||
|
// simulate stack
|
||||||
switch (step){
|
switch (step){
|
||||||
case 0:
|
case 0:
|
||||||
if (!event_received) continue;
|
if (!event_received) continue;
|
||||||
@ -275,6 +296,7 @@ void port_main(void){
|
|||||||
//
|
//
|
||||||
hal_spi_em9304_tx_data = hci_reset;
|
hal_spi_em9304_tx_data = hci_reset;
|
||||||
hal_spi_em9304_tx_size = sizeof(hci_reset);
|
hal_spi_em9304_tx_size = sizeof(hci_reset);
|
||||||
|
hal_spi_em9304_trigger_run_loop();
|
||||||
step++;
|
step++;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user