https://toitlang.org/ logo
Docs
Join the conversationJoin Discord
Channels
general
help
porting
Powered by Linen
help
  • Problems with highspeed UART and interrupt flags
    r

    Rikke

    01/06/2023, 10:34 AM
    Hello, We have a problem with creating a 2nd UART. The first UART is low speed, and we want to make a second UART with
    --baud_rate=2_500_000
    from the
    toit-pixel-strip
    package. We get the following error when creating the driver:
    ******************************************************************************
    Decoding by `jag`, device has version <2.0.0-alpha.47>
    ******************************************************************************
    EXCEPTION error. 
    UNKNOWN ERROR 0x105(261)
      0: uart_create_              <sdk>/uart.toit:310:3
      1: Port                      <sdk>/uart.toit:99:13
      2: UartPixelStrip            <pkg:toit-pixel-strip>/uart.toit:124:13
      3: setLED_.<block>           ../src/pinout.toit:254:18
      4: catch.<block>             <sdk>/core/exceptions.toit:124:10
      5: catch                     <sdk>/core/exceptions.toit:122:1
      6: catch                     <sdk>/core/exceptions.toit:73:10
      7: setLED_                   ../src/pinout.toit:253:12
      8: update_connection_LED_    ../src/pinout.toit:195:5
      9: update_AP_status_LED      ../src/pinout.toit:191:3
     10: main                      ../src/gateway.toit:35:3
    ******************************************************************************
    followed by ALREADY_IN_USE everytime it is called. The
    UNKNOWN ERROR 0x105
    has been traced down to a
    ESP_ERR_NOT_FOUND
    error, and located in the file
    intr_alloc.c
    in function `esp_err_t esp_intr_alloc_intrstatus(`:
    e
    • 2
    • 8
  • string contains
    z

    z3ugma

    01/07/2023, 5:42 PM
    After reading the docs at https://docs.toit.io/language/strings I don't understand the way to do string contains. In Python:
    if "foo" in "foobar":
        print("String was contained")
    Ruby:
    if my_string.include? "foo"
    Is there a way to check to see if a string contains a substring?
    k
    e
    • 3
    • 7
  • BLE Connection to device which does not advertise any services
    z

    z3ugma

    01/08/2023, 5:57 AM
    import ble
    
    DEV_NAME  ::= "O2Ring"
    SCAN_DURATION   ::= Duration --s=3
    
    find_by_name central/ble.Central name/string:
      central.scan --duration=SCAN_DURATION: | device/ble.RemoteScannedDevice |
        if device.data.name and device.data.name.contains name:
            return device.address
      throw "no ring device found"
    
    main:
      adapter := ble.Adapter
      central := adapter.central
    
      address := find_by_name central DEV_NAME
      remote_device := central.connect address
      print remote_device.address
      
      services := remote_device.discover_services 
      //0x0d    BLE_HS_ETIMEOUT    Operation timed out.
      //   EXCEPTION error. 
      // NimBLE error, Type: host, error code: 0x0d. See https://gist.github.com/mikkeldamsgaard/0857ce6a8b073a52...
      //   0: ble_get_error_            <sdk>/ble.toit:980:3
      //   1: Resource_.throw_error_    <sdk>/ble.toit:811:5
    I'm trying to communicate with a ring-based pulse oximeter which does not advertise any services. when calling
    discover_services
    I receive a NimBLE timeout error. I know the service UUID, and the UUID of the characteristics I'm interested in. Can I skip straight to exchanging write/notify data from the characteristics? Service data from LightBlue screenshots are attached
    f
    m
    k
    • 4
    • 70
  • Running `jag watch hello.toit` does not notice when the hello.toit file is changed on MacOS
    m

    mattsoftware

    01/09/2023, 11:53 PM
    Following the tutorial from https://github.com/toitlang/jaguar on a mac. I can run jag monitor, and then jag run hello.toit on the simple Hello World program. When I
    jag run hello.toit
    the monitor spits out Hello World! as expected. When I run
    jag watch hello.toit
    the monitor spits out Hello World! but then any writes to the file after that does not do anything. I have tried appending to the file on cli using echo, vim and text edit
    f
    k
    • 3
    • 24
  • jag command is not recognized as an internal or external command in Windows 10 and 11
    m

    Mobivs

    01/11/2023, 1:10 AM
    Hello, I'm trying to follow the " Quick Start Guide" in the Toit docs. I install as instructed for windows: winget install --id=Toit.Jaguar -e it runs telling me it found Jaguar [Toit.Jaguar] Version 1.8.1 it then downloads it and says the package was successfully installed. The problem starts when I try to type any jag command. I get back 'jag' is not recognized as an internal or external command, operable program or batch file. I have tried this on two separate windows machines but get the same issue. Does anyone know what I could be doing wrong?
    f
    • 2
    • 3
  • Console Working?
    m

    Mobivs

    01/11/2023, 3:14 AM
    is it still possible to provision using the console at console.toit.io? I used to have no issues provisioning, now none of my boards will provision there.
    • 1
    • 1
  • 'toit' is not recognized as an internal or external command
    c

    clpelema

    01/14/2023, 9:51 AM
    I flashed my ESP32 through the jaguar cli and now it is not being claimed in the console. The claiming process uses toit command though. I followed all the steps but the toit command does not seem to be working, the jeg command does. Do I have to add toit to my PATH manually? thanks
    f
    • 2
    • 5
  • Update wifi settings without re-flashing
    m

    mattsoftware

    01/19/2023, 9:07 PM
    I've moved my ESP32 to a different position and I need to reconfigure the wifi SSID and Password. However I do not want to re-flash. Is there a way to do this over serial by any chance? Thanks.
    f
    • 2
    • 14
  • Toit CMD authentication
    k

    Koirin

    02/02/2023, 5:26 PM
    Is there anyway to pass login-information to the "toit auth" command, instead of having to login using the web-browser?
    f
    • 2
    • 2
  • "DEBUG: Attempting to (re)connect"
    k

    Koirin

    02/07/2023, 2:06 PM
    After my device receives a "DEADLINE_EXCEEDED" error, the device gets stuck in this "DEBUG: Attempting to (re)connect" loop. It won't even reboot. It is set up with an MQTT-connection, and I think this somehow is the cause. How can I fix this?
    f
    • 2
    • 12
  • BLE notifications
    o

    ojmason

    02/13/2023, 9:46 AM
    Question for @MikkelD -- I'm trying to interact with a button via BLE, but I must be missing something. I've tried this both with an "AB Shutter3" button, and a "VR-PARK" joystick. I scan, discover, and connect to the device. Then I retrieve the relevant service, and the characteristic.The properties are 18 and 26 respectively, ie they support notifications. I subscribe to the characteristic, and then
    wait_for_notification
    on it. This blocks, and nothing happens, even if I press the button(s) to create events. (Actually, even reading out the characteristic without bothering with the notification doesn't yield any changed values). Any idea what I'm missing? For the VR-PARK, there is some sample code which I'm trying to replicate: https://github.com/BigJBehr/ESP32-Bluetooth-BLE-Remote-Control/blob/master/BLE-VRBOX.ino
    f
    m
    • 3
    • 18
  • I2S Audio on ESP32-WROVER-E
    n

    Nathan

    02/18/2023, 2:58 AM
    Hello! I have an ESP32-LyraT v4.3 development board which has a ESP32-WROVER-E and ES8388 codec chip on-board. I am trying to get audio from the AUX_IN to the PHONEJACK. Using the I2S library, I'm trying to do basic reads/writes to/from an I2S bus but I guess I am missing something, because I only seem to be able to read 0x00 out of the bus. Here's what I have so far:
    import i2s
    import gpio
    
    SCLK ::= gpio.Pin 5
    LRCK ::= gpio.Pin 25
    DSDIN ::= gpio.Pin 26
    ASDOUT ::= gpio.Pin 35
    
    main:
        // Initialize I2S bus
    
        bus := i2s.Bus --sck=SCLK --ws=LRCK --tx=DSDIN --rx=ASDOUT --sample_rate=44100 --bits_per_sample=16 --buffer_size=32
        i := 255
    
        while i-- > 0:
            bytes := bus.read
            print "Writing $(bytes.size) bytes"
            print "$bytes"
            bus.write bytes
    Any advice would be much appreciated!
    f
    m
    f
    • 4
    • 121
  • Use of Bucket.open --ram ?
    d

    davidg238

    02/24/2023, 7:15 PM
    Values stored in RAM are retained between reboots, so long as power is maintained, right? I have tried this code on two ezsbc ESP32 boards with fully charged LiPo's and JAG monitoring via USB. If I use --flash, the storage count increases. I I use --ram, the storage count is always 1, nothing is retained after deep-sleep. Using JAG v1.9.1, I just can't see what I am doing wrong.
    import esp32
    import system.storage as storage
    
    
    // RAM_STORE_       ::= storage.Bucket.open --flash   "/admin"
    RAM_STORE_       ::= storage.Bucket.open --ram   "/admin"
    
    
    main:
    
      RAMBuffer.add Time.now.s_since_epoch
    
      print "size after $RAMBuffer.size"
    
      esp32.deep_sleep (Duration --s=5)
    
    
    class RAMBuffer:
    
      static exists -> bool:
        return null != (RAM_STORE_.get "buffer")
    
      static get_buff_ -> List:
        buffer := RAM_STORE_.get "buffer"
        if not buffer: buffer = []
        return buffer
    
      static add entry/any -> none:
        buffer := List.from get_buff_
        buffer.add entry
        RAM_STORE_["buffer"] = buffer
    
      static clear -> none:
        RAM_STORE_["buffer"] = []
    
      static size -> int:
        return get_buff_.size
    
      static remove_first -> any:
        buffer := get_buff_
        entry := buffer.first
        RAM_STORE_["buffer"] = buffer[1..]
        return entry
    k
    • 2
    • 102
  • SD Card Example?
    o

    ojmason

    02/26/2023, 7:16 PM
    Hi, I'm trying to store some data on an SD Card. I have found the flash library, which provides
    Mount
    , which allows me to mount (and format, if necessary) an SD Card. But how do I read and write with it? Are there any examples that I could use as a starting off point?
    f
    m
    i
    • 4
    • 85
  • touch exception
    o

    ojmason

    02/26/2023, 7:59 PM
    I'm trying out the example code from the
    Touch
    class, but I'm getting an error when trying to run it:
    ******************************************************************************
    Decoding by `jag`, device has version <2.0.0-alpha.53>
    ******************************************************************************
    EXCEPTION error. 
    UNKNOWN ERROR 0xffffffff(-1)
      0: touch_read_               <sdk>/gpio/touch.toit:113:3
      1: Touch.read                <sdk>/gpio/touch.toit:58:12
      2: main                      touch-test.toit:21:18
    ******************************************************************************
    The code I'm using is
    while true:
        touch := Touch (gpio.Pin 0) --threshold=500
        print (touch.read --raw)
        touch.close
        sleep --ms=1000
    (plus the relevant imports). I'm using a TTGO T-BEAM, and pins 0 or 32 bothe didn't work... Any ideas?
    f
    k
    • 3
    • 41
  • MQTT Libary Problems
    z

    Zeroject

    02/27/2023, 10:01 AM
    Hey im pretty new to Toit and Jag, but i would love some help. Im trying to connect to a mqtt brokker but when im trying to use the libary mqtt and follow the guides i keep getting errors with anything that relates to the mqtt. Im programming on the web console from toit.
    f
    • 2
    • 7
  • Inter-task communication
    o

    ojmason

    03/02/2023, 8:46 PM
    Is there any documentation about how to use the various classes from the
    monitor
    package? Like Gate, Mailbox, etc?
    f
    • 2
    • 5
  • LoRa/LoRaWAN finding the right devices to use
    d

    diego.ar

    03/03/2023, 6:21 PM
    Hi there, thanks in advance for any help I need to run some tests to evaluate the LoRa protocol, and i have been checking a bit on Toit language and i see it would be great to use it on the project. I dont see at a first glance any device ESP32 based that could be used, to run Toit on it and also with LoRa capabilities, is this possible? can you suggest any PCB that could be used for this purpose? On the other hand, i have some TTGO boards that implement LoRa and even are based on ESP32, i guess i cant run Toit over this kind of boards, this correct? Thank you, looking forward to an answer.. cheers
    o
    f
    k
    • 4
    • 12
  • SD Card Format
    o

    ojmason

    03/05/2023, 7:44 PM
    The defaul argument for
    max_files
    for formatting SD cards is 5; is that not a bit small? What exactly is the meaning of that value?
    m
    k
    • 3
    • 6
  • The amount of SD card files slows down Ota
    r

    Rikke

    03/08/2023, 8:14 AM
    Hello, I noticed some varying Ota speeds on our toit devices, and decided to investigate the problem. The speeds would vary from 40 seconds to over 3 minutes. After i cleaned the SD card on the slow devices, it brought the time down to like 40 seconds. I made some tests with the SD-card, by making big files and many files to see the impact on the Ota speed. The files I made are in a folder being used by the device. I tried putting the files outside the working folder, but that did not change the Ota speed. In conclusion: The amount of files present in a working folder slows down the device. I have trouble finding out why this is the case. - We are appending to a single file 0-3 times a second - SPI clock is at 400 kHz - The
    host
    package is used to create a file stream to the 1 file - The Ota data is received with http client - Ota data is written with
    firmware.FirmwareWriter
    writer
    k
    m
    +2
    • 5
    • 26
  • can I still sign up online account? Went to the toit.io, can not find anything for it
    c

    ChinseJackLee

    03/10/2023, 3:22 AM
    can I still sign up online account? Went to the toit.io, can not find anything for opening a new account
    f
    • 2
    • 1
  • OTA with FirmwareWriter freezes esp32 on alpha63
    r

    Rikke

    03/10/2023, 9:25 AM
    Hello. I've updated to alpha 63 from alpha 47, but I have problems with OTA now. It looks like the esp32 completly freezes after writing ~350-400 times with the
    FirmwareWriter
    . The OTA process is spawned, but everything freezes when writing with
    FirmwareWriter
    . I will provide more details soon
    m
    k
    • 3
    • 31
  • Jaguar wifi closes (ESP32S3)
    m

    MikkelD

    03/10/2023, 12:00 PM
    I am having an issue where a device flashed with jaguar and just rebooted, closes the Wifi after about 40 seconds and does not reestablish the wifi connection. A log from the console (with more wifi info than normal)
    [wifi] DEBUG: connecting
    I (6206) wifi:mode : sta (f4:12:fa:d4:9a:20)
    I (6206) wifi:enable tsf
    I (7416) wifi:new:<11,2>, old:<1,0>, ap:<255,255>, sta:<11,2>, prof:1
    I (8096) wifi:state: init -> auth (b0)
    I (8096) wifi:state: auth -> assoc (0)
    I (8156) wifi:state: assoc -> run (10)
    W (8166) wifi:<ba-add>idx:0 (ifx:0, 70:a7:41:ba:7e:46), tid:5, ssn:1, winSize:64
    I (8166) wifi:connected with Spottune, aid = 1, channel 11, 40D, bssid = 70:a7:41:ba:7e:46
    I (8166) wifi:security: WPA2-PSK, phy: bgn, rssi: -40
    I (8166) wifi:pm start, type: 1
    
    I (8166) wifi:set rx beacon pti, rx_bcn_pti: 0, bcn_timeout: 0, mt_pti: 25000, mt_time: 10000
    [wifi] DEBUG: connected
    I (8176) wifi:BcnInt:102400, DTIM:1
    W (8246) wifi:<ba-add>idx:1 (ifx:0, 70:a7:41:ba:7e:46), tid:6, ssn:1, winSize:64
    I (9246) esp_netif_handlers: sta ip: 192.168.1.152, mask: 255.255.255.0, gw: 192.168.1.1
    [wifi] INFO: network address dynamically assigned through dhcp {ip: 192.168.1.152}
    [wifi] INFO: dns server address dynamically assigned through dhcp {ip: [192.168.1.1]}
    [jaguar] INFO: running Jaguar device 'stex_jig' (id: 'dc6b35c1-f193-45bb-a7d7-7926b54d3fbc') on 'http://192.168.1.152:9000'
    I (38866) wifi:state: run -> init (6c0)
    I (38866) wifi:pm stop, total sleep time: 16065060 us / 30696067 us
    
    W (38866) wifi:<ba-del>idx
    W (38866) wifi:<ba-del>idx
    I (38866) wifi:new:<11,0>, old:<11,2>, ap:<255,255>, sta:<11,2>, prof:1
    [wifi] DEBUG: closing
    I (38866) wifi:flush txq
    I (38866) wifi:stop sw txq
    I (38866) wifi:lmac stop hw txq
    I (38866) wifi:Deinit lldesc rx mblock:10
    After this, the device needs to be rebooted before it starts jaguar again
    r
    k
    • 3
    • 25
  • [wifi] DEBUG: closing | freezes on alpha.63+
    r

    Rikke

    03/13/2023, 1:48 PM
    Hello, I've noticed how the esp32 can freeze and never recover, after getting the
    [wifi] DEBUG: closing
    . I've seen this issue when the esp32 goes completely out of memory, and now after not being able to read from sd-card.
    ******************************************************************************
    Decoding by `jag`, device has version <2.0.0-alpha.64>
    ******************************************************************************
    EXCEPTION error. 
    FILE_NOT_FOUND
      0: stat                      <pkg:pkg-host>/file.toit:197:3
      1: is_directory              <pkg:pkg-host>/file.toit:178:11
      2: get_file_names            ../src/sd_card/sd_card_driver.toit:68:6
      3: delete_old_files          ../src/persistance.toit:182:22
      4: handle_data_message.<lambda> ../src/persistance.toit:39:21
    ******************************************************************************
    
    [wifi] DEBUG: closing
    Nothing happens after this, when it is supposed to print out something 1-5 times every second. I'm unsure how to provide more useful information right now, but I didn't notice this on alpha-47 and I saw this problem when out of memory on alpha-60
    k
    • 2
    • 11
  • MPU 6050 help!!
    d

    Daniel Sam

    03/14/2023, 3:32 AM
    I am trying to write code to get the acceleration values from MPU 6050, the code in arduino for this is:
    #include<Wire.h>
    const int MPU = 0x68;
    float AccX, AccY, AccZ;
    
    void setup() {
      Serial.begin(9600);
    
      Wire.begin();
      Wire.beginTransmission(MPU);
      Wire.write(0x6B);
      Wire.write(0);
      Wire.endTransmission(true);
    
    
      Wire.beginTransmission(MPU);
      Wire.write(0x1C);
      Wire.write(0b00011000);  //scale factor +/-16g
      Wire.endTransmission();
    }
    loop(){
      Wire.beginTransmission(MPU);
      Wire.write(0x3B);
      Wire.endTransmission(false);
      Wire.requestFrom(MPU, 14, true); // Solicita os dados ao sensor
    
     AccX = Wire.read() << 8 | Wire.read(); //0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
     AccY = Wire.read() << 8 | Wire.read(); //0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
     AccZ = Wire.read() << 8 | Wire.read(); //0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
    
     Serial.print(AccX / 2048);
     Serial.print(" ");
     Serial.print(AccY / 2048);
     Serial.print(" ");
     Serial.println(AccZ / 2048);
    }
    i have already started making the porting to toit, and i am stuck in this:
    import gpio
    import i2c
    
    MPU9250_ADDRESS := 0x68
    ACCEL_CONFIG_REG := 0x1C
    
    
    main:
        bus := i2c.Bus
            --sda=gpio.Pin 21
            --scl=gpio.Pin 22
    
        device := bus.device MPU9250_ADDRESS
    can any one help me to finish this code in toit?
    f
    • 2
    • 18
  • Error with ESP32-C3 (failed to target RAM)
    b

    Ben Potter

    03/14/2023, 10:16 PM
    Hi - I'm running into this issue with my c3. Any ideas?
    sh
    āžœ  jaguar jag flash --chip esp32c3
    Flashing device over serial on port '/dev/cu.usbmodem552E0028621' ...
    esptool.py v3.3.2-dev
    Serial port /dev/cu.usbmodem552E0028621
    Connecting....
    Chip is ESP32-C3 (revision 3)
    Features: Wi-Fi
    Crystal is 40MHz
    MAC: 10:91:a8:36:3f:08
    Uploading stub...
    
    A fatal error occurred: Failed to write to target RAM (result was 01070000: Operation timed out)
    Error: exit status 1
    f
    • 2
    • 15
  • UART write leads to device reset
    b

    Ben Potter

    03/15/2023, 1:21 AM
    Under what cases would writing to UART lead to a machine reset?
    sh
    [jaguar] INFO: running Jaguar device 'wiro' (id: '402d9458-9cf0-42c7-9cee-09714a97d6bf') on 'http://192.168.86.200:9000'
    [jaguar] INFO: program 7e4b355c-9066-ca1b-a357-14f20db16477 started
    Hello test!
    ESP-ROM:esp32c3-api1-20210207
    Build:Feb  7 2021
    rst:0x3 (RTC_SW_SYS_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
    Saved PC:0x40386f10
    SPIWP:0xee
    mode:DIO, clock div:1
    load:0x3fcd6100,len:0x48
    load:0x403ce000,len:0x64c
    load:0x403d0000,len:0x2318
    entry 0x403ce000
    [toit] INFO: starting <v2.0.0-alpha.64>
    [wifi] DEBUG: connecting
    [wifi] DEBUG: connected
    [wifi] INFO: network address dynamically assigned through dhcp {ip: 192.168.86.200}
    [wifi] INFO: dns server address dynamically assigned through dhcp {ip: [192.168.86.1]}
    [jaguar] INFO: running Jaguar device 'wiro' (id: '402d9458-9cf0-42c7-9cee-09714a97d6bf') on 'http://192.168.86.200:9000'
    My code:
    import uart
    import gpio
    import reader show BufferedReader
    import writer show Writer
    
    main:
        print "Hello test!"
    
        port := uart.Port
          --rx=gpio.Pin 20
          --tx=gpio.Pin 21
          --baud_rate=9600
    
        writer := Writer port
        10.repeat:
          print "Writing"
          writer.write "Test \n\n\n"
          sleep --ms=1000
    f
    m
    k
    • 4
    • 28
  • Device ID mismatch
    b

    Ben Potter

    03/15/2023, 11:08 PM
    I am seeing this occasionally on my esp32-3c. Any ideas? I have reset
    .cache/jaguar
    once and re-flashed.
    sh
    [jaguar] INFO: denied request, header: 'X-Jaguar-Device-ID' was '402d9458-9cf0-42c7-9cee-09714a97d6bf' not '0226b5d0-ab1a-4d7b-9c5f-cddda7dddf12'
    After a while, it will end up working for a few runs and then goes back to this too
    k
    • 2
    • 2
  • INA219 Driver
    w

    whatever

    03/19/2023, 5:55 AM
    hi toit is really great! I'm having fun with it on multiple devices. It was no problem to get into it all. But I have problem to create a new driver for the Ina219 i2c sensor. I use other i2c drivers as blueprints. I get an I2C_READ_FAILED when I try to read the chip id.
    k
    f
    • 3
    • 15
  • Toit VS Code extension high CPU usage (MacOS)
    b

    Ben Potter

    03/19/2023, 7:53 PM
    I'm not really able to use the VS Code extension on my MacOS machine as it causes huge CPU spikes and makes VS Code pretty much unusable. It works fine on my linux machine. Here's what I see in the output panel in VS Code
    sh
    2023-03-19T14:50:17.591-0500    ERROR    Compiler.compiler_protocol    compiler/compiler_fs_protocol.go:135    read failed    {"error": "io: read/write on closed pipe"}
    github.com/toitware/toit.git/toitlsp/lsp/compiler.(*CompilerFSProtocol).HandleConn
        /Users/runner/work/toit/toit/tools/toitlsp/lsp/compiler/compiler_fs_protocol.go:135
    github.com/toitware/toit.git/toitlsp/lsp/compiler.(*PipeFileServer).handleConn
        /Users/runner/work/toit/toit/tools/toitlsp/lsp/compiler/file_server_pipe.go:52
    Also created an issue: https://github.com/toitware/ide-tools/issues/212
    f
    k
    • 3
    • 56
Powered by Linen
Toit VS Code extension high CPU usage (MacOS)
b

Ben Potter

03/19/2023, 7:53 PM
I'm not really able to use the VS Code extension on my MacOS machine as it causes huge CPU spikes and makes VS Code pretty much unusable. It works fine on my linux machine. Here's what I see in the output panel in VS Code
sh
2023-03-19T14:50:17.591-0500    ERROR    Compiler.compiler_protocol    compiler/compiler_fs_protocol.go:135    read failed    {"error": "io: read/write on closed pipe"}
github.com/toitware/toit.git/toitlsp/lsp/compiler.(*CompilerFSProtocol).HandleConn
    /Users/runner/work/toit/toit/tools/toitlsp/lsp/compiler/compiler_fs_protocol.go:135
github.com/toitware/toit.git/toitlsp/lsp/compiler.(*PipeFileServer).handleConn
    /Users/runner/work/toit/toit/tools/toitlsp/lsp/compiler/file_server_pipe.go:52
Also created an issue: https://github.com/toitware/ide-tools/issues/212
f

floitsch

03/19/2023, 7:54 PM
😦
Do you know if the error message is related?
Is the CPU spiking after such a message?
Is the error message showing up continuously?
b

Ben Potter

03/19/2023, 7:56 PM
Yeah the error is showing up continuously
CPU spikes almost immediately after I open a toit file and the error appears
Ah there is a bit more at the top! Sorry
https://gist.github.com/bpmct/ba17b88a5c43e9d6c35b48082ae7829b
f

floitsch

03/19/2023, 8:00 PM
I will have a look at the code, but without a reproduction it's going to be a long shot. (Especially since I'm on Linux).
b

Ben Potter

03/19/2023, 8:02 PM
Hmm... This time, the errors appeared and CPU usage was quite low and after 3 minutes or so (and connecting my device, running
jag monitor / jag watch
) it got slow
No worries. I have a Linux machine so I'm happy to use that
f

floitsch

03/19/2023, 8:02 PM
Fyi: a short description of the architecture: the client (vscode) communicates with a Go program (toit.go) which then launches the compiler in a special mode for every request. Normally, you should see the compiler see up in 'top', as this is the process that does the most work. However, it's also short-lived. If the Go program is spiking in CPU, it means that we are doing something wrong. Potentially continuously trying to read from a dead sub process, wasting all CPU. We already had such an issue... (A missed
if error != null
).
Do you, by chance, have
delve
installed (Go's debugger).
b

Ben Potter

03/19/2023, 8:04 PM
No, but I'l happy to install it.\
f

floitsch

03/19/2023, 8:04 PM
If you attach to it
dlv attach pid
you might be able to see which function it is continuously calling, and why it doesn't stop.
I'm not sure if it works without the sources, but this is how we found the issue last time.
b

Ben Potter

03/19/2023, 8:05 PM
To the pid for
toit.lsp
?
f

floitsch

03/19/2023, 8:05 PM
yes.
b

Ben Potter

03/19/2023, 8:05 PM
Sure. Giving this a shot now
I'm afraid I don't know where to go from here:
sh
āžœ  bin dlv attach 61015
Type 'help' for list of commands.
(dlv)
f

floitsch

03/19/2023, 8:11 PM
not too familiar with Golang/delve either, but let me look it up.
can you start by
threads
?
b

Ben Potter

03/19/2023, 8:12 PM
Thread 3792956 at :0
  Thread 3792960 at :0
* Thread 3792961 at 0x108d200 /Users/runner/hostedtoolcache/go/1.17.13/x64/src/sort/search.go:83 sort.SearchInts
  Thread 3792962 at :0
  Thread 3792963 at :0
  Thread 3792994 at 0x1014830 /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/mbitmap.go:947 runtime.heapBitsSetType
  Thread 3793039 at 0x1093ed1 /Users/runner/hostedtoolcache/go/1.17.13/x64/src/internal/poll/fd_mutex.go:186 internal/poll.(*fdMutex).rwunlock
  Thread 3793044 at :0
  Thread 3793045 at :0
  Thread 3793046 at :0
  Thread 3793047 at :0
  Thread 3793048 at 0x105f0e8 /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/netpoll.go:284 internal/poll.runtime_pollReset
  Thread 3793087 at :0
  Thread 3793088 at 0x1109fed /Users/runner/hostedtoolcache/go/1.17.13/x64/src/bufio/bufio.go:105 bufio.(*Reader).fill
  Thread 3793118 at :0
  Thread 3793645 at :0
  Thread 3793646 at 0x100c86b /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/malloc.go:858 runtime.mallocgc
  Thread 3793647 at :0
  Thread 3793648 at 0x10644be /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/asm_amd64.s:772 runtime.asmcgocall
  Thread 3793649 at :0
  Thread 3793651 at :0
  Thread 3793652 at :0
  Thread 3796699 at :0
  Thread 3797876 at 0x1045f2e /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/select.go:310 runtime.selectgo
  Thread 3798078 at :0
  Thread 3798079 at 0x10368df /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/proc.go:410 runtime.acquireSudog
  Thread 3798080 at :0
  Thread 3798081 at :0
f

floitsch

03/19/2023, 8:13 PM
trying to find the right commands.
Not sure this is what needs to be done, but:
goroutines
list all goroutines.
goroutine X
allows to switch to a goroutine.
list
shows the source it's currently executing.
bt
prints a backtrace of the current goroutine.
b

Ben Potter

03/19/2023, 8:18 PM
Ah nice, it seems like we're getting somewhere
sh
(dlv) list
> sort.SearchInts() /Users/runner/hostedtoolcache/go/1.17.13/x64/src/sort/search.go:83 (PC: 0x108d200)
Warning: debugging optimized function
Command failed: open /Users/runner/hostedtoolcache/go/1.17.13/x64/src/sort/search.go: no such file or directory
f

floitsch

03/19/2023, 8:19 PM
that's probably ok.
if you go
up
you might get the sources.
But just having the
bt
backtrace could already help.
b

Ben Potter

03/19/2023, 8:19 PM
sh
(dlv) goroutine 2636
Switched from 2636 to 2636 (thread 3792961)
(dlv) bt
 0  0x000000000108d200 in sort.SearchInts
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/sort/search.go:83
 1  0x00000000012a6119 in github.com/toitware/toit.git/toitlsp/lsp/toit.FindLastGreaterThanIdx
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/summary.go:544
 2  0x00000000012aaa0d in github.com/toitware/toit.git/toitlsp/lsp/toit/text.(*summaryReader).topLevelReferenceFromGlobalID
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:776
 3  0x00000000012a91b3 in github.com/toitware/toit.git/toitlsp/lsp/toit/text.(*summaryReader).readType
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:430
 4  0x00000000012a8b6a in github.com/toitware/toit.git/toitlsp/lsp/toit/text.(*summaryReader).readMethod
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:359
 5  0x00000000012a8325 in github.com/toitware/toit.git/toitlsp/lsp/toit/text.(*summaryReader).readFunctions
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:257
 6  0x00000000012a785b in github.com/toitware/toit.git/toitlsp/lsp/toit/text.(*summaryReader).readModule
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:121
 7  0x00000000012a7545 in github.com/toitware/toit.git/toitlsp/lsp/toit/text.(*summaryReader).Read
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:82
 8  0x00000000012a728c in github.com/toitware/toit.git/toitlsp/lsp/toit/text.ParseSummary
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:49
 9  0x00000000012b3ca7 in github.com/toitware/toit.git/toitlsp/lsp/compiler.(*parser).AnalyzeOutput
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/compiler/parser.go:69
10  0x00000000012ac1da in github.com/toitware/toit.git/toitlsp/lsp/compiler.(*Compiler).Analyze.func1
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/compiler/compiler.go:136
11  0x00000000012ae903 in github.com/toitware/toit.git/toitlsp/lsp/compiler.(*Compiler).run.func1
    at /Users/runner/work/toit/toit/tools/toitlsp/lsp/compiler/compiler.go:336
12  0x0000000001064661 in runtime.goexit
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/asm_amd64.s:1581
> sort.SearchInts() /Users/runner/hostedtoolcache/go/1.17.13/x64/src/sort/search.go:83 (PC: 0x108d200)
Warning: debugging optimized function
Frame 1: /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/summary.go:544 (PC: 12a6119)
(dlv) up
> sort.SearchInts() /Users/runner/hostedtoolcache/go/1.17.13/x64/src/sort/search.go:83 (PC: 0x108d200)
Warning: debugging optimized function
Frame 2: /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:776 (PC: 12aaa0d)
(dlv) up
> sort.SearchInts() /Users/runner/hostedtoolcache/go/1.17.13/x64/src/sort/search.go:83 (PC: 0x108d200)
Warning: debugging optimized function
Frame 3: /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:430 (PC: 12a91b3)
(dlv) up
> sort.SearchInts() /Users/runner/hostedtoolcache/go/1.17.13/x64/src/sort/search.go:83 (PC: 0x108d200)
Warning: debugging optimized function
Frame 4: /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:359 (PC: 12a8b6a)
(dlv) up
> sort.SearchInts() /Users/runner/hostedtoolcache/go/1.17.13/x64/src/sort/search.go:83 (PC: 0x108d200)
Warning: debugging optimized function
Frame 5: /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:257 (PC: 12a8325)
(dlv) up
> sort.SearchInts() /Users/runner/hostedtoolcache/go/1.17.13/x64/src/sort/search.go:83 (PC: 0x108d200)
Warning: debugging optimized function
Frame 6: /Users/runner/work/toit/toit/tools/toitlsp/lsp/toit/text/parser.go:121 (PC: 12a785b)
f

floitsch

03/19/2023, 8:20 PM
Thanks.
Now let's continue the program (
continue
) and wait a bit.
Then
ctrl-c
to go back into delve and see if the backtrace changed.
b

Ben Potter

03/19/2023, 8:23 PM
sh
received SIGINT, stopping process (will not forward signal)
Stopped at: 0x7ff80872911a
=>   1:    no source available
(dlv) bt
 0  0x00007ff80872911a in ???
    at ?:-1
 1  0x0000000001066490 in runtime.pthread_cond_wait_trampoline
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/sys_darwin_amd64.s:535
 2  0x00000000010644ed in runtime.asmcgocall
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/asm_amd64.s:795
 3  0x0000000000000000 in ???
    at ?:-1
 4  0x0000000001052c34 in runtime.pthread_cond_wait
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/sys_darwin.go:444
 5  0x000000000102fdad in runtime.semasleep
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/os_darwin.go:66
 6  0x000000000100b2e5 in runtime.notesleep
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/lock_sema.go:182
 7  0x000000000103904a in runtime.mPark
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/proc.go:1441
 8  0x000000000103a558 in runtime.stopm
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/proc.go:2408
 9  0x000000000103e6d6 in runtime.exitsyscall0
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/proc.go:4115
10  0x0000000001062543 in runtime.mcall
    at /Users/runner/hostedtoolcache/go/1.17.13/x64/src/runtime/asm_amd64.s:307
f

floitsch

03/19/2023, 8:23 PM
Looks completely different. Maybe a different goroutine?
b

Ben Potter

03/19/2023, 8:25 PM
It doesn't seem to have a goroutine "selected"
sh
Sending output to pager...
(dlv) list
Stopped at: 0x7ff80872911a
=>   1:    no source available
should i completely quit out of delve and then attach again?
f

floitsch

03/19/2023, 8:25 PM
Just noticed: "goroutine 2636". That's a lot of goroutines. My biggest is "66"...
If you
goroutines
you should see a list of all goroutines.
Maybe one jumps out as Toit related.
k

kasperl

03/19/2023, 8:26 PM
(FWIW, I think I see this too on my Mac)
f

floitsch

03/19/2023, 8:26 PM
great(?) news. At least we should be able to debug this tomorrow, if we don't see anything fishy today.
k

kasperl

03/19/2023, 8:27 PM
Yup!
b

Ben Potter

03/19/2023, 8:28 PM
I'm having trouble copying the whole list, but here's my full history: https://gist.github.com/bpmct/10a64bcc2df8363fa988fa85cf26f702
Ah, great! I'm also happy to give one of y'all
tmate
/ssh access to my machine tomorrow if you need to debug further
f

floitsch

03/19/2023, 8:29 PM
If we can reproduce we should manage. But thanks.
Not making huge progress yet, but the server just seems to plow through goroutines...
I don't see anything obvious yet, so I think @kasperl and I will debug this tomorrow.
b

Ben Potter

03/19/2023, 8:35 PM
Sounds great. Thanks for the quick response, as always
f

floitsch

03/19/2023, 8:36 PM
And thanks for reporting and giving delve a try.
k

kasperl

03/24/2023, 1:32 PM
Maybe give Jaguar v1.9.13 a spin and see if the updated Go compiler and support packages help toit.lsp?
View count: 5