Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h7: enable exti support #7054

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/drivers/accgyro/accgyro.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void gyroIntExtiInit(gyroDev_t *gyro)
}
#endif

#if defined (STM32F7)
#if defined (STM32F7) || defined (STM32H7)
IOInit(gyro->busDev->irqPin, OWNER_MPU, RESOURCE_EXTI, 0);

EXTIHandlerInit(&gyro->exti, gyroIntExtiHandler);
Expand Down
29 changes: 19 additions & 10 deletions src/main/drivers/exti.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extiChannelRec_t extiChannelRecs[16];
static const uint8_t extiGroups[16] = { 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6 };
static uint8_t extiGroupPriority[EXTI_IRQ_GROUPS];

#if defined(STM32F4) || defined(STM32F7)
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
static const uint8_t extiGroupIRQn[EXTI_IRQ_GROUPS] = {
EXTI0_IRQn,
EXTI1_IRQn,
Expand All @@ -48,6 +48,15 @@ static const uint8_t extiGroupIRQn[EXTI_IRQ_GROUPS] = {
# warning "Unknown CPU"
#endif

// Absorb the difference in IMR and PR assignments to registers
#if defined(STM32H7)
#define EXTI_REG_IMR (EXTI_D1->IMR1)
#define EXTI_REG_PR (EXTI_D1->PR1)
#else
#define EXTI_REG_IMR (EXTI->IMR)
#define EXTI_REG_PR (EXTI->PR)
#endif


void EXTIInit(void)
{
Expand All @@ -64,7 +73,7 @@ void EXTIHandlerInit(extiCallbackRec_t *self, extiHandlerCallback *fn)
self->fn = fn;
}

#if defined(STM32F7)
#if defined(STM32F7) || defined(STM32H7)
void EXTIConfig(IO_t io, extiCallbackRec_t *cb, int irqPriority, ioConfig_t config)
{
(void)config;
Expand Down Expand Up @@ -156,37 +165,37 @@ void EXTIRelease(IO_t io)

void EXTIEnable(IO_t io, bool enable)
{
#if defined(STM32F4) || defined(STM32F7)
#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
uint32_t extiLine = IO_EXTI_Line(io);
if (!extiLine)
return;
if (enable)
EXTI->IMR |= extiLine;
EXTI_REG_IMR |= extiLine;
else
EXTI->IMR &= ~extiLine;
EXTI_REG_IMR &= ~extiLine;
#elif defined(STM32F303xC)
int extiLine = IO_EXTI_Line(io);
if (extiLine < 0)
return;
// assume extiLine < 32 (valid for all EXTI pins)
if (enable)
EXTI->IMR |= 1 << extiLine;
EXTI_REG_IMR |= 1 << extiLine;
else
EXTI->IMR &= ~(1 << extiLine);
EXTI_REG_IMR &= ~(1 << extiLine);
#else
# error "Unsupported target"
#endif
}

void EXTI_IRQHandler(void)
{
uint32_t exti_active = EXTI->IMR & EXTI->PR;
uint32_t exti_active = EXTI_REG_IMR & EXTI_REG_PR;

while (exti_active) {
unsigned idx = 31 - __builtin_clz(exti_active);
uint32_t mask = 1 << idx;
extiChannelRecs[idx].handler->fn(extiChannelRecs[idx].handler);
EXTI->PR = mask; // clear pending mask (by writing 1)
EXTI_REG_PR = mask; // clear pending mask (by writing 1)
exti_active &= ~mask;
}
}
Expand All @@ -201,7 +210,7 @@ void EXTI_IRQHandler(void)

_EXTI_IRQ_HANDLER(EXTI0_IRQHandler);
_EXTI_IRQ_HANDLER(EXTI1_IRQHandler);
#if defined(STM32F7)
#if defined(STM32F7) || defined(STM32H7)
_EXTI_IRQ_HANDLER(EXTI2_IRQHandler);
#elif defined(STM32F3) || defined(STM32F4)
_EXTI_IRQ_HANDLER(EXTI2_TS_IRQHandler);
Expand Down
2 changes: 1 addition & 1 deletion src/main/target/MATEKH743/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@
#define USE_ESC_SENSOR
#define USE_SERIALSHOT

#if 0
#define USE_EXTI
#define USE_MPU_DATA_READY_SIGNAL

#if 0
// *************** PINIO ***************************
#define USE_PINIO
#define USE_PINIOBOX
Expand Down