calloc, malloc and interrupts... necto AI ARM

Fully featured ARM compilers available on Windows, Linux, and macOS.
Post Reply
Author
Message
anubis
Posts: 3
Joined: 01 May 2020 21:10

calloc, malloc and interrupts... necto AI ARM

#1 Post by anubis » 05 Jan 2021 19:38

Hi,
1. I can't find calloc or malloc within stdlib.h from MikroElektronika, are there implentations in different libs?

2. Next question is about interrupts. I tried to implement an interrupt like shown in the help file. But I get the following compilation error: \main.c,53): Undeclared identifier 'NVIC_IntEnable' in expression.
How is the NVIC_IntEnable() implementation in mikroSDK2 or mikroSDK2.0.1? Seems that the helpfile shows how to use interrupts the "legacy way".

I appreciate your input.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: calloc, malloc and interrupts... necto AI ARM

#2 Post by filip » 14 Jan 2021 12:51

Hi,

Code: Select all

1. I can't find calloc or malloc within stdlib.h from MikroElektronika, are there implentations in different libs?
Malloc is implemented in the Memory Manager library, available for legacy projects.
2. Next question is about interrupts. I tried to implement an interrupt like shown in the help file. But I get the following compilation error: \main.c,53): Undeclared identifier 'NVIC_IntEnable' in expression.
How is the NVIC_IntEnable() implementation in mikroSDK2 or mikroSDK2.0.1? Seems that the helpfile shows how to use interrupts the "legacy way".
The NVIC_xyz functions are declared in legacy libraries, mixing the mikroSDK 2.0 and legacy stuff is something that is not recommended.

Regards,
Filip.

ralphw
Posts: 2
Joined: 03 Feb 2021 16:46

Re: calloc, malloc and interrupts... necto AI ARM

#3 Post by ralphw » 03 Feb 2021 17:49

Hi Filip,

So I have the same question - all the code examples use functions like NVIC_xxxx - or even just Enable_Interrupts(), both of which cause compiler errors. If I use the code generated by the Timer Calculator - it won't compile.

What is the workaround? How do we enable interrupts please?

Thanks!

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: calloc, malloc and interrupts... necto AI ARM

#4 Post by filip » 05 Feb 2021 09:28

Hi,

Are you using mikroSDK or legacy project ?

Regards,
Filip

anubis
Posts: 3
Joined: 01 May 2020 21:10

Re: calloc, malloc and interrupts... necto AI ARM

#5 Post by anubis » 11 Feb 2021 14:30

Well, the question is:
How can we use interrupts with mikroSDK?

Regards
anubis

ralphw
Posts: 2
Joined: 03 Feb 2021 16:46

Re: calloc, malloc and interrupts... necto AI ARM

#6 Post by ralphw » 15 Feb 2021 16:54

Try these - they directly manipulate the interrupt registers. I could get them to happily flash an LED on a timer tick. However - I'm not having as much fun with the UART interrupts :(

If you replace the call from the Timer Calculator to these, it should just work. The code's a bit clunky but hey, it works :)

Best,
R


#include "board.h"
#include "drv_port.h"

///@brief NVIC Enable
void RW_NVIC_EnableIRQ(int IRQn)
{
int bitpos = IRQn-16;
uint32_t bit_pattern = (uint32_t)(1UL << (((uint32_t)bitpos) & 0x1FUL));
uint32_t offset = (((uint32_t)IRQn) >> 5UL);

if ((int32_t)(IRQn) >= 0)
{
if(bitpos<32)
NVIC_ISER0 = bit_pattern;
else if(bitpos<64)
NVIC_ISER1 = bit_pattern;
else if(bitpos<96)
NVIC_ISER2 = bit_pattern;
}
}


///@brief NVIC Disable
void RW_NVIC_DisableIRQ(int IRQn)
{
int bitpos = IRQn-16;
uint32_t bit_pattern = (uint32_t)(1UL << (((uint32_t)bitpos) & 0x1FUL));
uint32_t offset = (((uint32_t)IRQn) >> 5UL);

// bit_pattern = 0xffffffff;

if ((int32_t)(IRQn) >= 0)
{
if(bitpos<32)
NVIC_ICER0 = bit_pattern;
else if(bitpos<64)
NVIC_ICER1 = bit_pattern;
else if(bitpos<96)
NVIC_ICER2 = bit_pattern;
}
}

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: calloc, malloc and interrupts... necto AI ARM

#7 Post by filip » 17 Feb 2021 12:28

Hi,

Currently, the interrupt mechanism via NVIC_ functions is not supported, we are planning to introduce it in one of the next releases of NECTO.

Regards,
Filip.

spgfer
Posts: 1
Joined: 13 Dec 2021 12:16

Re: calloc, malloc and interrupts... necto AI ARM

#8 Post by spgfer » 21 Jun 2022 10:52

Hi,

since the last post, has any interrupt mechanism (NVIC_ functions) been implemented for MikroC AI. I'm trying to use interrupts on STM32F407VG (Clicker 2)

Is it still needed to enable interrupts directly trough registers?

Code example:

Code: Select all

void Init_Interrupt()
{
  // Pin configuration
  GPIO_Digital_Input(&GPIOD_BASE, _GPIO_PINMASK_0);

  // Pin interrupt
  SYSCFGEN_bit = 1;              // Enable clock for alternate pin functions
  SYSCFG_EXTICR1 |= 0x0003;      // PD_0
  EXTI_IMR       |= 0x00000001;  // Set mask
  EXTI_RTSR      |= 0x00000001;  // Set interrupt on Rising edge
  EXTI_FTSR      |= 0x00000000;  // Set Interrupt on Falling edge

  NVIC_IntEnable(IVT_INT_EXTI0);    // Enable External interrupt
  EnableInterrupts();
}

void Do_Interrupt_EXTI0() iv IVT_INT_EXTI0 ics ICS_AUTO 
{
  if ((EXTI_PR & 0x00000001) != 0)
  {
    // Interrupt code 
    EXTI_PR |= 0x00000001 ; // Clear PD_0 trigger
  }
}
There is an error undeclared identifier for NVIC_IntEnable and EnableInterrupts, but also for GPIO_Digital_Input
Built_in.h doesn't contain any of these functions.

Any help is appreciated

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: calloc, malloc and interrupts... necto AI ARM

#9 Post by filip » 27 Sep 2022 15:44

Hi,

I'm afraid this hasn't been implemented yet.

Regards,
Filip.

Post Reply

Return to “ARM AI Compilers”