GPIO and leaf procedures

General discussions about working with the Astrobe IDE and programming ARM Cortex-M0, M3, M4 and M7 microcontrollers.
Post Reply
steve64
Posts: 43
Joined: Mon Jul 09, 2018 8:56 am
Location: Italy

GPIO and leaf procedures

Post by steve64 » Wed Sep 05, 2018 9:53 am

I suppose GPIO.Put() and GPIO.Get() are not valid inside a leaf procedure, do you confirm?
If so, it would be helpful to allow that. I have a user case in fast bitbanging where
a protocol could be implemented by calling leaf procedures just operating on GPIOs.

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: GPIO and leaf procedures

Post by cfbsoftware » Wed Sep 05, 2018 12:06 pm

By definition leaf procedures cannot call procedures. However, you can call SYSTEM.PUT directly if you want to perform GPIO operations in a leaf procedure. e.g. the Error procedure in the DramTest example lights the red LED before going into an infinite loop.

Code: Select all

PROCEDURE Error();
BEGIN
  GPIO.Put(LEDRed, HIGH);
  WHILE TRUE DO END
END Error;
If this had to be made much more efficient it could be written as a leaf procedure:

Code: Select all

PROCEDURE* Error();
CONST
  GPIO_BSRR = 018H;
  LEDRedOn = {14};
BEGIN
  SYSTEM.PUT(MCU.GPIOBBase + GPIO_BSRR, LEDRedOn);
  WHILE TRUE DO END
END Error;
Although SYSTEM.PUT looks like a procedure, it, like most other SYSTEM functions, generate inline code so it can be used in leaf procedures.

steve64
Posts: 43
Joined: Mon Jul 09, 2018 8:56 am
Location: Italy

Re: GPIO and leaf procedures

Post by steve64 » Wed Sep 05, 2018 12:16 pm

Thanks, using PUT and GET in leaf procedures for critical code can be fine.

Post Reply