1

I decided to program a PWM using an ARDUINO UNO R4 WIFI. I tried to configure the RENESAS RA4M1 microcontroller with the FSP libraries through the Arduino IDE. What I want to do is generate a PWM and commute a LED connected to the pin 107 of the RENESAS (ARDUINO D5~), but the code doesn't work. Here is my code:

#include "common_data.h"
#include "hal_data.h"
#include "vector_data.h"
void setup() {
 clock_cfg();
 gpio_cfg();
 pwm_cfg();
}
void loop() {
}
 // Clock configuration function (user defined)
void clock_cfg() {
 static cgc_instance_ctrl_t cgc_instance_ctrl;
 static cgc_cfg_t cgc_cfg;
 static cgc_clocks_cfg_t cgc_clocks_cfg;
 static cgc_divider_cfg_t cgc_divider_cfg;
 cgc_divider_cfg.sckdivcr_b.pclkb_div = CGC_SYS_CLOCK_DIV_1;
 cgc_divider_cfg.sckdivcr_b.pclkd_div = CGC_SYS_CLOCK_DIV_1;
 cgc_divider_cfg.sckdivcr_b.iclk_div = CGC_SYS_CLOCK_DIV_1;
 cgc_divider_cfg.sckdivcr_b.pclka_div = CGC_SYS_CLOCK_DIV_1;
 cgc_divider_cfg.sckdivcr_b.pclkc_div = CGC_SYS_CLOCK_DIV_1;
 cgc_divider_cfg.sckdivcr_b.fclk_div = CGC_SYS_CLOCK_DIV_1;
 cgc_divider_cfg.sckdivcr_b.bclk_div = CGC_SYS_CLOCK_DIV_1;
 cgc_clocks_cfg.system_clock = CGC_CLOCK_HOCO;
 cgc_clocks_cfg.divider_cfg = cgc_divider_cfg;
 cgc_clocks_cfg.loco_state = CGC_CLOCK_CHANGE_STOP;
 cgc_clocks_cfg.moco_state = CGC_CLOCK_CHANGE_STOP;
 cgc_clocks_cfg.hoco_state = CGC_CLOCK_CHANGE_START;
 cgc_clocks_cfg.mainosc_state = CGC_CLOCK_CHANGE_STOP;
 cgc_clocks_cfg.pll_state = CGC_CLOCK_CHANGE_STOP;
 cgc_clocks_cfg.pll2_state = CGC_CLOCK_CHANGE_STOP;
 R_CGC_Open(&cgc_instance_ctrl, &cgc_cfg);
 R_CGC_ClocksCfg(&cgc_instance_ctrl, &cgc_clocks_cfg);
}
 // PWM configuration function (user defined)
void pwm_cfg() {
 static gpt_instance_ctrl_t gpt_instance_ctrl;
 static timer_cfg_t gpt_cfg;
 static gpt_extended_cfg_t gpt_extended_cfg;
 static uint32_t period = 48000000;
 static uint32_t duty = 24000000;
 static uint8_t channel = 0;
 gpt_extended_cfg.gtioca.output_enabled = true;
 gpt_extended_cfg.gtioca.stop_level = GPT_PIN_LEVEL_LOW;
 gpt_extended_cfg.gtiocb.output_enabled = false;
 gpt_extended_cfg.gtiocb.stop_level = GPT_PIN_LEVEL_LOW;
 gpt_extended_cfg.start_source = GPT_SOURCE_NONE;
 gpt_extended_cfg.stop_source = GPT_SOURCE_NONE;
 gpt_extended_cfg.clear_source = GPT_SOURCE_NONE;
 gpt_extended_cfg.capture_a_source = GPT_SOURCE_NONE;
 gpt_extended_cfg.capture_b_source = GPT_SOURCE_NONE;
 gpt_extended_cfg.count_up_source = GPT_SOURCE_NONE;
 gpt_extended_cfg.count_down_source = GPT_SOURCE_NONE;
 gpt_extended_cfg.capture_filter_gtioca = GPT_CAPTURE_FILTER_NONE;
 gpt_extended_cfg.capture_filter_gtiocb = GPT_CAPTURE_FILTER_NONE;
 gpt_cfg.mode = TIMER_MODE_PWM;
 gpt_cfg.source_div = TIMER_SOURCE_DIV_1;
 gpt_cfg.period_counts = period;
 gpt_cfg.duty_cycle_counts = duty;
 gpt_cfg.channel = channel;
 gpt_cfg.p_callback = NULL;
 gpt_cfg.p_context = NULL;
 gpt_cfg.p_extend = &gpt_extended_cfg;
 R_GPT_Open(&gpt_instance_ctrl, &gpt_cfg);
 R_GPT_Start(&gpt_instance_ctrl);
}
void gpio_cfg() {
 static ioport_instance_ctrl_t ioport_instance_ctrl;
 static ioport_cfg_t ioport_cfg;
 R_IOPORT_Open(&ioport_instance_ctrl, &ioport_cfg);
 R_IOPORT_PinCfg(&ioport_instance_ctrl, BSP_IO_PORT_01_PIN_07, IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_GPT0);
}

I have checked that the clocks are being configured since the "delay()" prebuild function is being affected when commuting the LED when I change the system clock divider. Also the GPIO can be configured if activated manually by setting the pin in output direction:

R_IOPORT_PinCfg(&ioport_instance_ctrl, BSP_IO_PORT_01_PIN_07, IOPORT_CFG_PORT_DIRECTION_OUTPUT);

And writting to it with the function:

R_IOPORT_PinWrite(&g_ioport_ctrl, BSP_IO_PORT_01_PIN_07, BSP_IO_LEVEL_HIGH);

Mysteriously for me, the pin is not outputting the PWM I want to commute the LED as described in the code above. Anyone can tell me what I am doing wrong please?

asked Sep 27 at 3:32

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.