Skip to content

ULP program: output not working #3148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
perseus086 opened this issue Aug 28, 2019 · 4 comments
Closed

ULP program: output not working #3148

perseus086 opened this issue Aug 28, 2019 · 4 comments

Comments

@perseus086
Copy link

perseus086 commented Aug 28, 2019

I am trying to make blink a led with ULP

It works for some ports but not for others. GPIO 02 works fine 15 too but other no.

Got this code somewhere on the internet.

/*
 * ESP32 Sketch shows that you can program the ulp co-processor using
 * Arduino using the ulp assembly MACRO's. This sketch just blinks the
 * on board LED on for x microseconds and OFF x microseconds using the ulp. 
 * This sketch was inspired from https://github.com/espressif/esp-idf/blob/98e5c475b31ce704e08bd1a48f5d2de3f0b216b0/components/ulp/test/test_ulp.c 
 */
#include "esp32/ulp.h"
#include "driver/rtc_io.h"

void ULP_BLINK_RUN(uint32_t us);

void setup() {
  // microseconds to delay between halt and wake states
  ULP_BLINK_RUN(1000000);
}

void loop() {
  // put your main code here, to run repeatedly:

}
// ------------------------------------------------------------------------
void ULP_BLINK_RUN(uint32_t us) {

  RTC_SLOW_MEM[12] = 0;
  ulp_set_wakeup_period(0, us);
  const ulp_insn_t  ulp_blink[] = {
    I_MOVI(R3, 12),                         // #12 -> R3
    I_LD(R0, R3, 0),                        // R0 = RTC_SLOW_MEM[R3(#12)] 
    M_BL(1, 1),                             // GOTO M_LABEL(1) IF R0 < 1
    I_WR_REG(RTC_GPIO_OUT_REG, 14, 14, 1),  // RTC_GPIO36 = 1---> EXPECTING TO TURN ON LED
    I_SUBI(R0, R0, 1),                      // R0 = R0 - 1, R0 = 1, R0 = 0
    I_ST(R0, R3, 0),                        // RTC_SLOW_MEM[R3(#12)] = R0
    M_BX(2),                                // GOTO M_LABEL(2)
    M_LABEL(1),                             // M_LABEL(1)
      I_WR_REG(RTC_GPIO_OUT_REG, 14, 14, 0),// RTC_GPIO36 = 0  ---> EXPECTING TO TURN OFF LED
      I_ADDI(R0, R0, 1),                    // R0 = R0 + 1, R0 = 0, R0 = 1
      I_ST(R0, R3, 0),                      // RTC_SLOW_MEM[R3(#12)] = R0
    M_LABEL(2),                             // M_LABEL(2)
    I_HALT()                                // HALT COPROCESSOR
  };
  const gpio_num_t led_gpios[] = {
    GPIO_NUM_2,
    GPIO_NUM_0,
    GPIO_NUM_4
  };
  for (size_t i = 0; i < sizeof(led_gpios) / sizeof(led_gpios[0]); ++i) {
    rtc_gpio_init(led_gpios[i]);
    rtc_gpio_set_direction(led_gpios[i], RTC_GPIO_MODE_OUTPUT_ONLY);
    rtc_gpio_set_level(led_gpios[i], 0);
  }
  size_t size = sizeof(ulp_blink) / sizeof(ulp_insn_t);
  ulp_process_macros_and_load(0, ulp_blink, &size);
  ulp_run(0);
}

Here is the code

Anyone knows why it does not work for all the ports?

@Jeroen88
Copy link
Contributor

What pins are not working? Not all pins are free to use. Also GPIO34, 35, 36 and 39 are input only, so these pins will never let you blink a led

@perseus086
Copy link
Author

perseus086 commented Aug 28, 2019

I tried GPIO 0, 2, 4, 15, 13, 12, 25, 26, 32, 33 and others like 36.

Only 0, 2, and 4 working fine. But other pins not.

I found this tweet and I tried with this map: https://twitter.com/i/web/status/1142776900449787904

When I tried with c code for GPIO12. The typical blink example and pin 12 works fine as output:

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(12, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(12, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

Maybe it is because I am not initializing the pins as outputs?

@perseus086
Copy link
Author

@Jeroen88
I think I get what you tell me. according to: https://www.espressif.com/sites/default/files/1a-esp32_pin_list_en-v0.1.pdf

I can use GPIO 32, 33, 25, 26, 27, 2, 0, 4

Right?

@Jeroen88
Copy link
Contributor

According to this link you should be able to use more pins, maybe dependent on the development board you are using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants