STM32L0 Freeze on setting NVIC/GPIO

Refresh

March 2019

Views

2 time

0

I'm working with an STM32L073RZ CPU running MbedOS 5.11.2. Eventually I aim to get this working in a very low-power mode (STOP mode) that will be awoken with either an RTC interrupt or an interrupt from a peripheral device on pin PA_0 (WAKEUP_PIN_1). At the moment I am simply attempting to setup PA_0 as an interrupt using the STM32 HAL API. Please see my code below:

#include "mbed.h"

#define LOG(...) pc.printf(__VA_ARGS__); pc.printf("\r\n");

DigitalOut  led(LED1);
Serial      pc(USBTX, USBRX);

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
    led = !led;
}

int main()
{
    pc.baud(9600);
    led = 1;

    // GPIO SETUP
    LOG("Enabling GPIO port A clock");
    __HAL_RCC_GPIOA_CLK_ENABLE();
    GPIO_InitTypeDef GPIO_InitStruct;
    GPIO_InitStruct.Pin = GPIO_PIN_0;
    GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    LOG("Initialising PA_0");
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    // NVIC SETUP
    LOG("Setting IRQ Priority");
    HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 1); // Priorities can be 0, 1, 2, 3 with lowest being highest prio
    LOG("Enabling IRQ");
    HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);

    LOG("Going into STOP mode");
    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE);
}

As you can see, the code is broken into two sections: GPIO setup and NVIC setup. My issue is as follows:

If I perform GPIO setup before NVIC setup then the program seems to hang on HAL_NVIC_SetPriority(), however, if I perform NVIC setup before GPIO setup then the code seems to hang on HAL_NVIC_EnableIRQ().

I am completely stumped as to what is causing this. Any insight is greatly appreciated.

0 answers