On-Chip-Peripherals

How can I find out which on-chip periphals of the Renesas R7FA4M1AB …

  • are already in use
  • are used by what library

Want to use one of the 2 32-bit GPTs to evaluate a rotary encoder.

I’m not 100% sure, but as far as I know you can’t really “query” the RA chip to see which peripherals are in use. It’s all decided at compile-time in the FSP Configurator. So I think the best way is just to check the FSP config and see which GPTs and pins are assigned there. If a GPT isn’t enabled or mapped, it should be free for your encoder.

Thanks… and what is the FSP and where to find it?

FSP is Renesas’ Flexible Software Package.
You’ll find it in e2studio under “FSP Configuration” that’s where all peripherals, pins and GPT timers are set up.

Here’s the official page:

FSP definition for Arduino uses of course (almost) all peripherals so the Arduino core can use them as needed for the current sketch.
A C archive file (.a) build in advance with FSP is part of the core and used for linking the resulting binary file of the sketch

I don't think the Arduino core uses the FSP "Configuration tools" (the "Configurator" is specifically for 3rd-party tools like IAR and Keil, while the "normal" configuration options seem to be a thing for use with the Renesas IDE (the e2studio that was mentioned. Which Arduino doesn't use. (although it might have been used to generate some of the code?)))

You should be able to get some idea by looking at the .../variant/*/pinmux.inc file.
If I understand what they've done, this has, for each pin that is "available", a list of all the features that it could use, and which on-chip peripherals get linked to that pin. (Won't help with the extra libraries, though.)

you can’t really “query” the RA chip to see which peripherals are in use.

Oh, I dunno. You can look at the pin settings and which clocks and peripherals are enabled. The problem is that it's much harder to tell which peripherals MIGHT be used. (the "dynamic" nature of renesas Interrupts has been discussed previously, for instance.)

Thanks a lot for all hints!

I think I’ll have to do it the ‘hard way’: F.e. to find out which GPT-channels are in use:

  • run the sw
  • look into the GPT-registers
  • see which ones have values other than the default values

That brings up the next problem: I found that debugging the UNO R4 and looking into the registers is possible with Arduino IDE, it seems not to be possible with Eclipse-Sloeber that I’m using for building and uploading. So I will have to go back to Arduino-IDE - at least for this purpose.

the FSPTimer class manages the timers allocation

Arduino doesn’t actually use the FSP Configurator, but it still ships with a pre-generated FSP project inside the core. The only practical way to see what’s in use is to look at the variant pinmux files and the peripheral state in the registers. By checking which pins are mapped and which GPTs are clocked or taken out of stop mode, you can usually tell whether a timer is free. There’s no direct tell me who uses this peripheral API, so you have to infer it from the pinmux and the runtime register state

The only catch with that approach is that the GPT registers don’t necessarily stay at their reset defaults unless the peripheral clock is enabled. A channel can look unused simply because its module is still in stop mode, even if some library intends to configure it later.

Also, some initialization happens very early in startup code, so depending on when you pause the program, you might miss the moment a peripheral is configured.

So reading the registers works, but you just need to be careful: it tells you what is currently active, not what the core or a library plans to use. It’s a good method, just not foolproof

@petersued: Yes, the FSPTimer class is a good way to detect a free timer – if all libraries used it.
Unfortunately, this class does not allow you to use all of the timer's functions.
In my MobaTools, I only use it to detect a free timer and then mark it as used. The timer configuration itself is then done directly via the registers. But I don't think all libraries will do it this way.
But this problem (Library conflicts regarding the hardware used) is not specific to the R4 ...

Where? I looked around for something like a generated project config file, and didn't see anything in what I thought were the obvious places.

It’s not a full e2studio-style .xml project, so you won’t find a classic FSP configuration folder. What Arduino ships is the generated FSP HAL layer (the ra/fsp and ra_gen directories inside the core). The ra_gen files are the output of an FSP project that was generated once and then bundled into the core, and Arduino builds on top of that fixed HAL setup. That’s what I meant by a pre-generated FSP project it’s the generated HAL sources, not the original configuration tool files

Thanks.

1 Like

https://github.com/arduino/ArduinoCore-renesas/tree/main/extras/e2studioProjects/Santiago

Problem solved - almost.

Found an Array gpt_used_channel[GPT_HOWMANY]. All used GPTs are marked with a value <> TIMER_FREE.

Originally I planned to directly write to the registers of the selected GPT-channel, but looking into Lib EncoderR4 I found nice and comfortable functions like FspTimer::open().

SW now is running: Position of Rotary-Encoder is readable from GPT-counter with no ISRs involved.

Remaining problem:
I’m using GPT1 that should have a 32-bit counter. For any reason I only keep getting the lower 16 bits. Any idea why this is the case?

Regards Peter