Has anyone managed to enter an interrupt Handler? My interrupts are triggered but the code never goes inside the dedicated function. Also I could not find the IRQHandler definition within the Arduino Core Mbed library : GitHub - arduino/ArduinoCore-mbed. I only found the IRQ numbers I am starting to believe that they were not defined? Anyone knows where to find the said Handlers? If they are indeed not defined how do I add them. I was thinking of doing it through the linker file using __attribute__ (.isr_vector)
but up till now it only resulted in failures.
I tried with ISR() and attachInterrupt() but they don't seem to be defined for the Portenta?
What code would that be ?
[code]
//#define PLL_N 168 //SYSTEM CLOCK SPEED (FCY (MHz))
//#define PLL_N 180 //SYSTEM CLOCK SPEED (FCY (MHz))
//#define HSI 16000000 //INTERAL OSC FREQUENCY
////Fcy = Fxtal x PLL_N/(PLL_P x PLL_M)
//#define PLL_M (HSI/2000000)
//#define PLL_P 2
//#define PLL_Q 7
//#include <stdint.h>
//#define HWREG(x) (*((volatile uint32_t *)(x)))
//static void SystemCkInit();
//extern void __libc_init_array();
#include <Arduino.h>
void GPIOH_Port15_Toggle();
void GPIOH_Init();
void ADC_Init();
void ADC_Start();
void AC_TIMER1_Init();
//extern "C" void Default_Handler() __attribute__((weak));
//void Reset_Handler() __attribute__((weak));
//void NMI_Handler() __attribute__((weak));
//void HardFault_Handler() __attribute__((weak));
//void MemManage_Handler() __attribute__((weak));
//void BusFault_Handler() __attribute__((weak));
//void UsageFault_Handler() __attribute__((weak));
//void SVC_Handler() __attribute__((weak));
//void DebugMon_Handler() __attribute__((weak));
//void PendSV_Handler() __attribute__((weak));
//void SysTick_Handler() __attribute__((weak));
//
//void WWDG_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void PVD_AVD_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TAMP_STAMP_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void RTC_WKUP_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void FLASH_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void RCC_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void EXTI0_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void EXTI1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void EXTI2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void EXTI3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void EXTI4_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA1_Stream0_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA1_Stream1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA1_Stream2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA1_Stream3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA1_Stream4_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA1_Stream5_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA1_Stream6_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void ADC_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void FDCAN1_IT0_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void FDCAN2_IT0_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void FDCAN1_IT1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void FDCAN2_IT1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void EXTI9_5_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM1_BRK_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM1_UP_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM1_TRG_COM_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM1_CC_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM4_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void I2C1_EV_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void I2C1_ER_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void I2C2_EV_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void I2C2_ER_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SPI1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SPI2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void USART1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void USART2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void USART3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void EXTI15_10_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void RTC_Alarm_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM8_BRK_TIM12_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM8_UP_TIM13_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM8_TRG_COM_TIM14_IRQHandler()__attribute__ ((weak, alias("Default_Handler")));
//void TIM8_CC_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA1_Stream7_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void FMC_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SDMMC1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM5_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SPI3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void UART4_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void UART5_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM6_DAC_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM7_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA2_Stream0_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA2_Stream1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA2_Stream2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA2_Stream3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA2_Stream4_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void ETH_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void ETH_WKUP_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void FDCAN_CAL_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA2_Stream5_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA2_Stream6_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA2_Stream7_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void USART6_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void I2C3_EV_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void I2C3_ER_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void OTG_HS_EP1_OUT_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void OTG_HS_EP1_IN_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void OTG_HS_WKUP_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void OTG_HS_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DCMI_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void RNG_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void FPU_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void UART7_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void UART8_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SPI4_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SPI5_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SPI6_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SAI1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void LTDC_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void LTDC_ER_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMA2D_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SAI2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void QUADSPI_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void LPTIM1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void CEC_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void I2C4_EV_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void I2C4_ER_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SPDIF_RX_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void OTG_FS_EP1_OUT_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void OTG_FS_EP1_IN_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void OTG_FS_WKUP_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void OTG_FS_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMAMUX1_OVR_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void HRTIM1_Master_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void HRTIM1_TIMA_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void HRTIM1_TIMB_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void HRTIM1_TIMC_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void HRTIM1_TIMD_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void HRTIM1_TIME_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void HRTIM1_FLT_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DFSDM1_FLT0_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DFSDM1_FLT1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DFSDM1_FLT2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DFSDM1_FLT3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SAI3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SWPMI1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM15_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM16_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void TIM17_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void MDIOS_WKUP_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void MDIOS_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void JPEG_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void MDMA_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SDMMC2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void HSEM1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void ADC3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void DMAMUX2_OVR_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void BDMA_Channel0_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void BDMA_Channel1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void BDMA_Channel2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void BDMA_Channel3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void BDMA_Channel4_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void BDMA_Channel5_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void BDMA_Channel6_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void BDMA_Channel7_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void COMP1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void LPTIM2_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void LPTIM3_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void LPTIM4_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void LPTIM5_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void LPUART1_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void CRS_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void SAI4_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//void WAKEUP_PIN_IRQHandler() __attribute__ ((weak, alias("Default_Handler")));
//
//
///*=================== Global variables ====================*/
///* Highest address of the user mode stack */
//extern const volatile uint32_t _estack;
///* start address for the initialization values of the .data section.
//defined in linker script */
//extern uint32_t _sidata;
///* start address for the .data section. defined in linker script */
//extern uint32_t _sdata;
///* end address for the .data section. defined in linker script */
//extern uint32_t _edata;
///* start address for the .bss section. defined in linker script */
//extern uint32_t _sbss;
///* end address for the .bss section. defined in linker script */
//extern uint32_t _ebss;
//
///* The Interrupt Vector Table */
//__attribute__ ((section(".isr_vector")))
//void (* const g_pfnVectors[])(void) = {
// ((void (*)(void)) (&_estack)),
// Reset_Handler,
// NMI_Handler,
// HardFault_Handler,
// MemManage_Handler,
// BusFault_Handler,
// UsageFault_Handler,
// 0,
// 0,
// 0,
// 0,
// SVC_Handler,
// DebugMon_Handler,
// 0,
// PendSV_Handler,
// SysTick_Handler,
//
// /* External Interrupts */
// WWDG_IRQHandler,
// PVD_AVD_IRQHandler,
// TAMP_STAMP_IRQHandler,
// RTC_WKUP_IRQHandler,
// FLASH_IRQHandler,
// RCC_IRQHandler,
// EXTI0_IRQHandler,
// EXTI1_IRQHandler,
// EXTI2_IRQHandler,
// EXTI3_IRQHandler,
// EXTI4_IRQHandler,
// DMA1_Stream0_IRQHandler,
// DMA1_Stream1_IRQHandler,
// DMA1_Stream2_IRQHandler,
// DMA1_Stream3_IRQHandler,
// DMA1_Stream4_IRQHandler,
// DMA1_Stream5_IRQHandler,
// DMA1_Stream6_IRQHandler,
// ADC_IRQHandler,
// FDCAN1_IT0_IRQHandler,
// FDCAN2_IT0_IRQHandler,
// FDCAN1_IT1_IRQHandler,
// FDCAN2_IT1_IRQHandler,
// EXTI9_5_IRQHandler,
// TIM1_BRK_IRQHandler,
// TIM1_UP_IRQHandler,
// TIM1_TRG_COM_IRQHandler,
// TIM1_CC_IRQHandler,
// TIM2_IRQHandler,
// TIM3_IRQHandler,
// TIM4_IRQHandler,
// I2C1_EV_IRQHandler,
// I2C1_ER_IRQHandler,
// I2C2_EV_IRQHandler,
// I2C2_ER_IRQHandler,
// SPI1_IRQHandler,
// SPI2_IRQHandler,
// USART1_IRQHandler,
// USART2_IRQHandler,
// USART3_IRQHandler,
// EXTI15_10_IRQHandler,
// RTC_Alarm_IRQHandler,
// 0,
// TIM8_BRK_TIM12_IRQHandler,
// TIM8_UP_TIM13_IRQHandler,
// TIM8_TRG_COM_TIM14_IRQHandler,
// TIM8_CC_IRQHandler,
// DMA1_Stream7_IRQHandler,
// FMC_IRQHandler,
// SDMMC1_IRQHandler,
// TIM5_IRQHandler,
// SPI3_IRQHandler,
// UART4_IRQHandler,
// UART5_IRQHandler,
// TIM6_DAC_IRQHandler,
// TIM7_IRQHandler,
// DMA2_Stream0_IRQHandler,
// DMA2_Stream1_IRQHandler,
// DMA2_Stream2_IRQHandler,
// DMA2_Stream3_IRQHandler,
// DMA2_Stream4_IRQHandler,
// ETH_IRQHandler,
// ETH_WKUP_IRQHandler,
// FDCAN_CAL_IRQHandler,
// 0,
// 0,
// 0,
// 0,
// DMA2_Stream5_IRQHandler,
// DMA2_Stream6_IRQHandler,
// DMA2_Stream7_IRQHandler,
// USART6_IRQHandler,
// I2C3_EV_IRQHandler,
// I2C3_ER_IRQHandler,
// OTG_HS_EP1_OUT_IRQHandler,
// OTG_HS_EP1_IN_IRQHandler,
// OTG_HS_WKUP_IRQHandler,
// OTG_HS_IRQHandler,
// DCMI_IRQHandler,
// 0,
// RNG_IRQHandler,
// FPU_IRQHandler,
// UART7_IRQHandler,
// UART8_IRQHandler,
// SPI4_IRQHandler,
// SPI5_IRQHandler,
// SPI6_IRQHandler,
// SAI1_IRQHandler,
// LTDC_IRQHandler,
// LTDC_ER_IRQHandler,
// DMA2D_IRQHandler,
// SAI2_IRQHandler,
// QUADSPI_IRQHandler,
// LPTIM1_IRQHandler,
// CEC_IRQHandler,
// I2C4_EV_IRQHandler,
// I2C4_ER_IRQHandler,
// SPDIF_RX_IRQHandler,
// OTG_FS_EP1_OUT_IRQHandler,
// OTG_FS_EP1_IN_IRQHandler,
// OTG_FS_WKUP_IRQHandler,
// OTG_FS_IRQHandler,
// DMAMUX1_OVR_IRQHandler,
// HRTIM1_Master_IRQHandler,
// HRTIM1_TIMA_IRQHandler,
// HRTIM1_TIMB_IRQHandler,
// HRTIM1_TIMC_IRQHandler,
// HRTIM1_TIMD_IRQHandler,
// HRTIM1_TIME_IRQHandler,
// HRTIM1_FLT_IRQHandler,
// DFSDM1_FLT0_IRQHandler,
// DFSDM1_FLT1_IRQHandler,
// DFSDM1_FLT2_IRQHandler,
// DFSDM1_FLT3_IRQHandler,
// SAI3_IRQHandler,
// SWPMI1_IRQHandler,
// TIM15_IRQHandler,
// TIM16_IRQHandler,
// TIM17_IRQHandler,
// MDIOS_WKUP_IRQHandler,
// MDIOS_IRQHandler,
// JPEG_IRQHandler,
// MDMA_IRQHandler,
// 0,
// SDMMC2_IRQHandler,
// HSEM1_IRQHandler,
// 0,
// ADC3_IRQHandler,
// DMAMUX2_OVR_IRQHandler,
// BDMA_Channel0_IRQHandler,
// BDMA_Channel1_IRQHandler,
// BDMA_Channel2_IRQHandler,
// BDMA_Channel3_IRQHandler,
// BDMA_Channel4_IRQHandler,
// BDMA_Channel5_IRQHandler,
// BDMA_Channel6_IRQHandler,
// BDMA_Channel7_IRQHandler,
// COMP1_IRQHandler,
// LPTIM2_IRQHandler,
// LPTIM3_IRQHandler,
// LPTIM4_IRQHandler,
// LPTIM5_IRQHandler,
// LPUART1_IRQHandler,
// 0,
// CRS_IRQHandler,
// 0,
// SAI4_IRQHandler,
// 0,
// 0,
// WAKEUP_PIN_IRQHandler
//};
void setup() {
Serial.begin(115200);
// put your setup code here, to run once:
//SystemCkInit();
//Reset_Handler();
GPIOH_Init();
digitalWrite(LEDB,LOW);
delay(1000);
ADC_Init();
digitalWrite(LEDB,HIGH);
delay(1000);
digitalWrite(LEDR,LOW);
delay(1000);
ADC_Start();
digitalWrite(LEDR,HIGH);
delay(1000);
digitalWrite(LEDG,LOW);
delay(1000);
AC_TIMER1_Init();
// digitalWrite(LEDG,HIGH);
// digitalWrite(LEDB,LOW);
// delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(READ_REG(TIM1->SR));
}
void ADC_Init(void) {
/***************CLOCK and PIN config******************/
// MODIFY_REG(RCC->D3CCIPR,RCC_D3CCIPR_ADCSEL_Msk,0x1L);
// delay(1000);
// dataFromRegister=READ_REG(RCC->D3CCIPR);
// Serial.print("D3CCIPR :");
// Serial.println(dataFromRegister,BIN);
SET_BIT(RCC->APB4ENR,RCC_APB4ENR_SYSCFGEN_Msk);
delay(1000);
// dataFromRegister=READ_REG(RCC->APB4ENR);
// Serial.print("RCC_APB4ENR:");
// Serial.println(dataFromRegister,BIN);
SET_BIT(RCC->APB4ENR,RCC_APB4ENR_RTCAPBEN_Msk);
delay(1000);
// dataFromRegister=READ_REG(RCC->APB4ENR);
// Serial.print("RCC_APB4ENR1:");
// Serial.println(dataFromRegister,BIN);
SET_BIT(RCC->AHB1ENR,RCC_AHB1ENR_ADC12EN_Msk);
delay(1000);
// dataFromRegister=READ_REG(RCC->AHB1ENR);
// Serial.print("RCC_AHB1ENR:");
// Serial.println(dataFromRegister,BIN);
//GPIOA PORT 1------------------------------------
SET_BIT(RCC->AHB4ENR,RCC_AHB4ENR_GPIOAEN_Msk);
delay(1000);
// dataFromRegister=READ_REG(RCC->AHB4ENR);
// Serial.print("RCC_AHB4ENR:");
// Serial.println(dataFromRegister,BIN);
SET_BIT(GPIOA->MODER, GPIO_MODER_MODE1_0);
SET_BIT(GPIOA->MODER, GPIO_MODER_MODE1_1);
CLEAR_BIT(GPIOA->PUPDR, GPIO_PUPDR_PUPD1_0);
CLEAR_BIT(GPIOA->PUPDR, GPIO_PUPDR_PUPD1_1);
SET_BIT(SYSCFG->PMCR, SYSCFG_PMCR_PA0SO_Msk);
delay(1000);
// dataFromRegister=READ_REG(SYSCFG->PMCR);
// Serial.print("SYSCFG->PMCR:");
// Serial.println(dataFromRegister,BIN);
SET_BIT(RCC->AHB1ENR,RCC_AHB1ENR_ADC12EN_Msk);
delay(1000);
// dataFromRegister=READ_REG(RCC->AHB1ENR);
// Serial.print("RCC->AHB1ENR2:");
// Serial.println(dataFromRegister,BIN);
/***************ADC not Enabled yet********************/
//ADC VOLTAGE REGULATOR-----------------------------
CLEAR_BIT(ADC2->CR,ADC_CR_DEEPPWD_Msk);
//dataFromRegister=READ_REG(ADC2->CR);
//Serial.print("ADCR: ");
//Serial.println(dataFromRegister,BIN);
//delay(1000);
SET_BIT(ADC2->CR,ADC_CR_ADVREGEN_Msk);
delay(1000);
// dataFromRegister=READ_REG(ADC2->CR);
// Serial.print("ADCAL: ");
// Serial.println(dataFromRegister,BIN);
delay(1000);
//
//ADC CALIBRATION-----------------------------------
CLEAR_BIT(ADC2->CR,ADC_CR_ADCALDIF_Msk);
SET_BIT(ADC2->CR,ADC_CR_ADCALLIN_Msk);
SET_BIT(ADC2->CR,ADC_CR_ADCAL_Msk);
while(ADC_CR_ADCAL & ADC_CR_ADCAL_Msk!=0){
// dataFromRegister=READ_REG(ADC2->CR);
// Serial.print("ADC2_CR: ");
// Serial.println(dataFromRegister,BIN);
}
//ADC prescaler selection clock and sample time delay
//MODIFY_REG(ADC22_COMMON->CCR,ADC_CCR_CKMODE | ADC_CCR_PRESC | ADC_CCR_DELAY ,0x3UL | 0x3UL | 0x8UL);
SET_BIT(ADC12_COMMON->CCR, ADC_CCR_CKMODE_0 | ADC_CCR_CKMODE_1 | ADC_CCR_PRESC_0 | ADC_CCR_PRESC_1 );//| ADC_CCR_DELAY_3
// MODIFY_REG(ADC12_COMMON->CCR,ADC_CCR_PRESC_Msk,0x3UL);
// MODIFY_REG(ADC12_COMMON->CCR,ADC_CCR_DELAY_Msk,0x8UL);
// dataFromRegister=READ_REG(ADC12_COMMON->CCR);
// Serial.print("ADC_CCR: ");
// Serial.println(dataFromRegister,BIN);
delay(1000);
//Set input mode------------------------------------
CLEAR_BIT(ADC2->DIFSEL,ADC_DIFSEL_DIFSEL_0);
/*******************ADC Enable**********************/
SET_BIT(ADC2->ISR,ADC_ISR_ADRDY_Msk);
SET_BIT(ADC2->CR,ADC_CR_ADEN_Msk);
while(ADC_ISR_ADRDY & ADC_ISR_ADRDY_Msk !=1){}
SET_BIT(ADC2->ISR,ADC_ISR_ADRDY_Msk);
/********************ADC Enabled********************/
//ADC CFGR------------------------------------------
SET_BIT(ADC2->CFGR, ADC_CFGR_RES_2 | ADC_CFGR_RES_1 | ADC_CFGR_OVRMOD_Msk | ADC_CFGR_DISCEN_Msk | ADC_CFGR_EXTEN_0 | ADC_CFGR_EXTSEL_1 | ADC_CFGR_EXTSEL_3);
CLEAR_BIT(ADC2->CFGR, ADC_CFGR_DMNGT_0 | ADC_CFGR_DMNGT_1 | ADC_CFGR_RES_0 | ADC_CFGR_EXTEN_1 | ADC_CFGR_EXTSEL_0 | ADC_CFGR_EXTSEL_2 | ADC_CFGR_EXTSEL_4);
//DATA ALIGNEMENT-----------------------------------
// ADC PCSEL----------------------------------------
SET_BIT(ADC2->PCSEL,ADC_PCSEL_PCSEL_0);
//ADC SQR1------------------------------------------
SET_BIT(ADC2->SQR1,ADC_SQR1_SQ1_1);
//ADC SMPR1-----------------------------------------
SET_BIT(ADC2->SMPR1,ADC_SMPR1_SMP0_0 | ADC_SMPR1_SMP0_1);
}
void ADC_Start(void) {
SET_BIT(ADC2->CR,ADC_CR_ADSTART_Msk);
}
void AC_TIMER1_Init(void) {
//------------------------------Horloge Timer1----------------------------------------//
SET_BIT(RCC->APB2ENR, RCC_APB2ENR_TIM1EN_Msk);
//------------------------------Select TRGO source-----------------------------------//
TIM1->PSC = 8399; //PSC=1
//----------------------------------------------------------TIM2 autoreload register--------------------------------------------//
TIM1->ARR = 10000;
//---------selectupdatevent-----------------//
SET_BIT(TIM1->CR2,TIM_CR2_MMS_1);
//-----------IT-----------------------//
SET_BIT(TIM1->DIER,TIM_DIER_UIE_Msk);
NVIC_EnableIRQ(TIM1_UP_IRQn);
SET_BIT(TIM1->CR1, TIM_CR1_CEN_Msk);//CEN=1
}
ISR(TIM1_UP_IRQvect){
digitalWrite(LEDR,LOW);
if (TIM1->DIER & 0x01) {
if (TIM1->SR & 0x01) {
TIM1->SR &= ~(1U << 0);
}
}
//Optionally we may toggle the LED to notice the intervals
GPIOH_Port15_Toggle();
}
void GPIOH_Init(void) {
SET_BIT(RCC->AHB4ENR,RCC_AHB4ENR_GPIOHEN_Msk);
delay(1000);
SET_BIT(GPIOH->MODER, GPIO_MODER_MODE15_0);
CLEAR_BIT(GPIOH->MODER, GPIO_MODER_MODE15_1);
CLEAR_BIT(GPIOH->OTYPER, GPIO_OTYPER_OT15);
}
void GPIOH_Port15_Toggle(void) {
SET_BIT(GPIOH->BSRR, GPIO_BSRR_BS15);
CLEAR_BIT(GPIOH->BSRR, GPIO_BSRR_BS15);
SET_BIT(GPIOH->BSRR, GPIO_BSRR_BR15);
CLEAR_BIT(GPIOH->BSRR, GPIO_BSRR_BR15);
}
/*================= Function definitions ==================*/
//void Default_Handler() {
// Serial.println("Dans la boucle");
// // Go into an infinite loop.
// while(1) {
//
//
// }
//}
//
//void Reset_Handler() {
//
// /* set stack pointer */
// __asm(" ldr sp, =_estack");
//
// /* Call the clock system initialization function */
// SystemInit();
//
// /* Copy the data segment initializers from flash to SRAM */
// uint32_t* pui32Src, *pui32Dest;
// pui32Src = &_sidata;
// for(pui32Dest = &_sdata; pui32Dest < &_edata; )
// *pui32Dest++ = *pui32Src++;
//
// /* Zero fill the bss segment */
// __asm(" ldr r0, =_sbss\n"
// " ldr r1, =_ebss\n"
// " mov r2, #0\n"
// " .thumb_func\n"
// "zero_loop:\n"
// " cmp r0, r1\n"
// " it lt\n"
// " strlt r2, [r0], #4\n"
// " blt zero_loop");
//
// /* Call static constructors */
// __libc_init_array();
//
// /* Call the application's entry point */
// main();
//}
//
//void NMI_Handler() {
// Serial.println("Dans la boucle");
// /* Go into an infinite loop */
// while(1) {
//
// }
//}
//
//void HardFault_Handler() {
// Serial.println("Dans la boucle");
// /* Go into an infinite loop */
// while(1) {
//
// }
//}
//
//void MemManage_Handler() {
// Serial.println("Dans la boucle");
// /* Go into an infinite loop */
// while(1) {
//
// }
//}
//
//void BusFault_Handler() {
// Serial.println("Dans la boucle");
// /* Go into an infinite loop */
// while(1) {
//
// }
//}
//
//void UsageFault_Handler() {
// Serial.println("Dans la boucle");
// /* Go into an infinite loop */
// while(1) {
//
// }
//}
//
//void SVC_Handler() {
// Serial.println("Dans la boucle");
// /* Go into an infinite loop */
// while(1) {
//
// }
//}
//
//void DebugMon_Handler() {
// Serial.println("Dans la boucle");
// /* Go into an infinite loop */
// while(1) {
//
// }
//}
//
//void PendSV_Handler() {
// Serial.println("Dans la boucle");
// /* Go into an infinite loop */
// while(1) {
//
// }
//}
//
//void SysTick_Handler() {
// Serial.println("Dans la boucle");
// /* Go into an infinite loop */
// while(1) {
//
// }
//}
//
//
//static void SystemCkInit(void) {
//
// /* Enable the floating-point unit. Any configuration of the
// floating-point unit must be done here prior to it being enabled */
// HWREG(0xE000ED88) = ((HWREG(0xE000ED88) & ~0x00F00000) | 0x00F00000);
//
// /*------- Reset the RCC clock configuration to the default reset state -------*/
// /* Set HSION bit */
// RCC->CR |= 0x00000001;
// /* Reset CFGR register */
// RCC->CFGR = 0x00000000;
// /* Reset HSEON, CSSON , CSION,RC48ON, CSIKERON PLL1ON, PLL2ON and PLL3ON bits */
// RCC->CR &= (uint32_t)0xEAF6ED7F;
// /* Reset D1CFGR register */
// RCC->D1CFGR = 0x00000000;
// /* Reset D2CFGR register */
// RCC->D2CFGR = 0x00000000;
// /* Reset D3CFGR register */
// RCC->D3CFGR = 0x00000000;
// /* Reset PLLCKSELR register */
// RCC->PLLCKSELR = 0x00000000;
// /* Reset PLLCFGR register */
// RCC->PLLCFGR = 0x00000000;
// /* Reset PLL1DIVR register */
// RCC->PLL1DIVR = 0x00000000;
// /* Reset PLL1FRACR register */
// RCC->PLL1FRACR = 0x00000000;
// /* Reset PLL2DIVR register */
// RCC->PLL2DIVR = 0x00000000;
// /* Reset PLL2FRACR register */
// RCC->PLL2FRACR = 0x00000000;
// /* Reset PLL3DIVR register */
// RCC->PLL3DIVR = 0x00000000;
// /* Reset PLL3FRACR register */
// RCC->PLL3FRACR = 0x00000000;
// /* Reset HSEBYP bit */
// RCC->CR &= (uint32_t)0xFFFBFFFF;
// /* Disable all interrupts */
// RCC->CIER = 0x00000000;
//
// /* Change the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
// HWREG(0x51008108) = 0x000000001;
//}
[/code]
The commented lines are my own trial and error to get to handlers. I Tried ISR in this code but I mainly use :
void TIM1_UP_IRQHandler(void){
//IT_routine
}
Which doesn't work either, the CMSIS file define that handler though... is there a special type I have to put in front like :
__IRQHandler TIM1_UP_IRQHandler(void){}
(I tried it too but it doesn't work well)
I have seen this library but I have never used it.
Yeah I have seen (and quite thoroughly read) that library too but it only enables timer interrupts and I have this issue with every single interrupt (for exemple DMA where in order to achieve fast communication between both cores of the portenta using DMA and Interrupts could be a very reliable possibility). Just to say I can not wait for a new library to be released for every peripherals also it doesn't make sense to do not be able to use interrupts... I mean that is quite an important feature). What I discovered during the afternoon using :
__NVIC_GetVector(TIM1_UP_IRQn);
I get the vector address related to the TIM1_UP_IRQn (interrupt on timer1 update event) I associated it to tim1_upd_it (defined as the vector for said interrupt). So I try to bypass the Handler by relying on the vector.
volatile uint32_t* tim1_upd_it =(uint32_t *) ADDRESS_FROM_NVIC;
But I get some troubles with ISR (function supposed to check the ITvector equivalent to attachInterrupt()
Arduino: 1.8.19 (Windows 10), Board: "Arduino Portenta H7 (M7 core), 1MB M7 + 1MB M4, None"
TEST_ADC2_TIM1_CMSIS2:171:5: error: expected constructor, destructor, or type conversion before '(' token
ISR(tim1_upd_it){
^
TEST_ADC2_TIM1_CMSIS2:171:4: error: expected constructor, destructor, or type conversion before '(' token
ISR(tim1_upd_it){
^
exit status 1
expected constructor, destructor, or type conversion before '(' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Well I will keep you updated
I don't have a Portenta with me today, but does a simple HAL code like this works?
#define LED LED_BUILTIN
TIM_HandleTypeDef htim1;
void setup() {
pinMode(LED, OUTPUT);
htim1.Instance = TIM6;
htim1.Init.Prescaler = 47999;
htim1.Init.Period = 499;
__HAL_RCC_TIM1_CLK_ENABLE();
HAL_NVIC_SetPriority(TIM1_UP_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM1_UP_IRQn);
HAL_TIM_Base_Init(&htim1);
HAL_TIM_Base_Start_IT(&htim1);
}
void loop() {
delay(100);
}
void TIM1_IRQHandler(void) {
HAL_TIM_IRQHandler(&htim1);
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
if (htim->Instance == TIM1) {
digitalWrite(LED, !digitalRead(LED));
}
}
I know that you do not want to use the HAL, but it is to check if a classic way of using interrupts works with Arduino Mbed.
EDIT a working version is available in post #16 below
First I am definitely not familiar with HAL defined functions so I tried your code and it does not seem to work but it also does not seem to even trigger an interrupt. So here are a few bugs (or so I think) :
-If I add a :
Serial.println(READ_REG(TIM1->CNT));
within the loop I notice that the counter is always at 0 which means that the TIM1 is not enabled, what sounds fair since it is written :
htim1.Instance = TIM6;
But if I do replace TIM6 by TIM1 I loose connection to the board soon after uploading (no print on the serial connection)?
On my part I found a few startup files like that one here (gui_h7/startup_stm32h743xx.lst at 7172d3f8a6744c8bc517dbc26750828fec78524c · f1engmin11/gui_h7 · GitHub) and I (perhaps stupidly) believe that I should add it to my code files in order to get my Handlers to work (since I can't find this file in the whole Arduino_mbed library)
Also according to the CMSIS files TIM6 only has an IRQ on DAC1 and 2. If I try the same code with TIM2 I go back to the first issue which is CNT=0.
Ah yes, my mistake for the TIM6
reference.
I have used a previous code using timer 6 on an stm32f4 but I have then noticed that timer 6 was not available to trigger a callback on H7 so I have replaced it by TIM1
.
Another thing to check might be that the timer 1 is used by the mbed RTOS.
I am going to check that (perhaps the safest way for someone as unfamiliar as I am with the HAL library would be to code it through the STM32CubeIDE and adapt the code to Arduino IDE). I will keep you updated (hope it works since it would mean that the problem comes from my code missing something ).
Yes, having the code generated by the STM32CubeIDE is easier but it generates a lot of boilerplate across several files.
Yeah I will be careful with that
Little Udpate (HAL) :
The IDE crashed 9 out of 10 tries and I have a hard time identifying the errors sources since I find HAL functions less meaningfull than registers. For the times I managed to upload the code and have it run for more than a few seconds the CNT never took another value than 0.
Update (Startupfiles) :
Here is an interesting tutorial I will follow : STM32_ From systeminit__ Main to main ()
I feel like this is what I need to do in order to get my interrupts as a matter of fact (even though I did not manage to have HAL work) the STM32CubeIDE always generate those files when you code with it.
Ok I was just missing one line sorry for the trouble and many thanks to the Arduino_mbed_core library for lending me a hand. The line :
NVIC_SetVector(TIM1_UP_IRQn, (uint32_t)&TIM1_UP_IRQHandler);
Answer on Github for reference:
For reference, working version of my HAL timer sketch:
#define LED LED_BUILTIN
TIM_HandleTypeDef htim1;
void setup() {
pinMode(LED, OUTPUT);
Serial.println("Start Timer");
htim1.Instance = TIM1;
htim1.Init.Prescaler = 39999;
htim1.Init.Period = 4999;
__HAL_RCC_TIM1_CLK_ENABLE();
HAL_NVIC_SetPriority(TIM1_UP_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM1_UP_IRQn);
HAL_TIM_Base_Init(&htim1);
HAL_TIM_Base_Start_IT(&htim1);
Serial.println("Timer Started");
}
void loop() {
delay(1000);
Serial.print("Count: ");
Serial.println(__HAL_TIM_GET_COUNTER(&htim1));
}
extern "C" {
void TIM1_UP_IRQHandler(void) {
HAL_TIM_IRQHandler(&htim1);
}
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
if (htim->Instance == TIM1) {
digitalWrite(LED, !digitalRead(LED));
}
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.