bdring / FluidNC

The next generation of motion control firmware
Other
1.46k stars 356 forks source link

Problem: undefined reference to `esp_ipc_call_blocking' when compile default_envs = wifi_s2 #1066

Open bwenquan opened 8 months ago

bwenquan commented 8 months ago

Wiki Search Terms

Controller Board

image image

Machine Description

-

Input Circuits

No response

Configuration file

-

Startup Messages

invalid header: 0xffffffff
invalid header: 0xffffffff
invalid header: 0xffffffESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x7 (TG0WDT_SYS_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4001276a
invalid header: 0xffffffff
invalid header: 0xffffffff
invalid header: 0xffffffff

User Interface Software

No response

What happened?

This error occurred when I compiled esp32-s2 default_envs = wifi_s2

image

GCode File

No response

Other Information

No response

bdring commented 8 months ago

Why do you need to compile.

Can you just install?

http://wiki.fluidnc.com/en/installation

bwenquan commented 8 months ago

Because the firmware in the release was for the ESP32 (more accurately, it should be called the ESP32-S), the ESP32-S2 had a lot of differences from the ESP32, and the firmware of the two is not universal.

The key difference is that the esp32-wroom has two cores( Xtensa® 32-bit LX6 ), while the esp32-s2-wroom has only one core (Xtensa® 32-bit LX7 ): image image

So, I need to recompile the firmware using the chip environment of the esp32-s2.

bwenquan commented 8 months ago

I followed the documentation to produce this result:

image

Now, I modified part of the code to fit ESP32-S2, and I will try to make a PR after test on my machine. image

bdring commented 8 months ago

I am familiar with that ESP32 chip and the other versions.

MitchBradley commented 8 months ago

The S2 code is not complete and not supported. We started working on it but have not had time to finish, because of other priorities. If you can help us get it working that would be much appreciated. In addition to getting the code working, the release scripts will need to be modified to include s2 versions of the binary files, and to list them in the manifest.json file so the web installer can see them.

MitchBradley commented 8 months ago

Is the Kirizu Laser board a commercial product or something that you built yourself?

bwenquan commented 8 months ago

Thanks, Kirizu Laser board is built by myself. I tried to modify the code, but I found that it runs on 2 core, I think it is not suitable to run at esp32-s2 which only have one core, because, I found that polling_loop and output_loop is running at another core? (I'm not sure), I'm not familiar with multi-core, so I can't change the code any further. Now I'll try to modify the motherboard to esp32-wroom.

If need me to provide more information or do some tests , I'll be glad to help.

I tried to modify these codes,

  1. Enable USB-CDC over USB Pin (Not Test)
    -DARDUINO_USB_CDC_ON_BOOT=1
  2. Uart.cpp (line near 40)

        // We init UARTs on core 0 so the interrupt handler runs there,
        // thus avoiding conflict with the StepTimer interrupt
        esp_ipc_call_blocking(0, uart_driver_n_install, (void*)_uart_num);

    changed to

    #ifdef CONFIG_IDF_TARGET_ESP32S2
        // ESP32-S2
        // single core
    
        uart_driver_n_install((void*)_uart_num);
    #elif
        // For: Esp32 / Esp32-S3
        // We init UARTs on core 0 so the interrupt handler runs there,
        // thus avoiding conflict with the StepTimer interrupt
        esp_ipc_call_blocking(0, uart_driver_n_install, (void*)_uart_num);
    #endif
  3. MachineConfig.cpp (line near 40)
        handler.section("uart1", _uarts[1], 1);
        handler.section("uart2", _uarts[2], 2);

    changed to (because esp32-s2 on has uart 0/1)

        for (size_t i = 1; i < MAX_N_UARTS; i++)
        {
            handler.section(("uart" + String(i)).c_str(), _uarts[i], i);
            handler.section(("uart_channel" +  String(i)).c_str(), _uart_channels[i]);
        }

Now, the firmware is initialized and running normally, but I guess there is a problem with the handler, there is a WiFi AP (it can be connected) but I can't access the WEB through it, and sending commands to the mcu through serial is not responding. Telnet also fails to connect.

bwenquan commented 7 months ago

Hi, I spent some time to make this firmware to run at ESP32-S3. It's working now, but I haven't tested it on my machine yet.

There are my changes:

/FluidNC/esp32/PwmPin.cpp

     // Increase the precision (bits) until it exceeds the frequency
     // The hardware maximum precision is 20 bits
     const uint8_t  ledcMaxBits = 20;
-    const uint32_t apbFreq     = 80000000;
+    const uint32_t apbFreq     = 40000000;
     const uint32_t maxCount    = apbFreq / frequency;
     for (uint8_t bits = 2; bits <= ledcMaxBits; ++bits) {

FluidNC/esp32/gpio.cpp

-std::vector<int> avail_gpios = { 0, 1, 3, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, 33, 34, 35, 36, 39 };
+std::vector<int> avail_gpios = { 0, 1, 3, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, 33, 34, 35, 36, 39 ,40,41,42,43,44,45,46,47,48};

 struct pin_mux {
     int         pinnum;
@@ -240,6 +240,16 @@ struct pin_mux {
     { 37, "SENSOR_CAPP", { "GPIO37", "-", "GPIO37", "-", "-", "-" } },
     { 38, "SENSOR_CAPN", { "GPIO38", "-", "GPIO38", "-", "-", "-" } },
     { 39, "SENSOR_VN", { "GPIO39", "-", "GPIO39", "-", "-", "-" } },
+    { 40, "GPIO40", { "GPIO25", "-", "GPIO25", "-", "-", "EMAC_RXD0" } },
+    { 41, "GPIO41", { "GPIO25", "-", "GPIO25", "-", "-", "EMAC_RXD0" } },
+    { 42, "GPIO25", { "GPIO25", "-", "GPIO25", "-", "-", "EMAC_RXD0" } },
+    { 43, "GPIO25", { "GPIO25", "-", "GPIO25", "-", "-", "EMAC_RXD0" } },
+    { 44, "GPIO25", { "GPIO25", "-", "GPIO25", "-", "-", "EMAC_RXD0" } },
+    { 45, "GPIO25", { "GPIO25", "-", "GPIO25", "-", "-", "EMAC_RXD0" } },
+    { 46, "GPIO25", { "GPIO25", "-", "GPIO25", "-", "-", "EMAC_RXD0" } },
+    { 47, "GPIO25", { "GPIO25", "-", "GPIO25", "-", "-", "EMAC_RXD0" } },
+    { 48, "GPIO25", { "GPIO25", "-", "GPIO25", "-", "-", "EMAC_RXD0" } },
+
     { -1, "", { "" } },
 };

FluidNC/src/Pins/GPIOPinDetail.cpp

     PinCapabilities GPIOPinDetail::GetDefaultCapabilities(pinnum_t index) {
         // See https://randomnerdtutorials.com/esp32-pinout-reference-gpios/ for an overview:
 #ifdef CONFIG_IDF_TARGET_ESP32S3
            switch(index){
                case 0:  // Outputs PWM signal at boot
                    return PinCapabilities::Native | PinCapabilities::Input | PinCapabilities::Output | PinCapabilities::PullUp |
                       PinCapabilities::PullDown | PinCapabilities::PWM | PinCapabilities::ISR |
                       PinCapabilities::UART;
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                case 10:
                case 11:
                case 12:
                case 13:
                case 14:
                case 15:
                case 16:
                case 17:
                case 18:
                case 19:
                case 20:
                    return PinCapabilities::Native | PinCapabilities::Input | PinCapabilities::Output | PinCapabilities::PullUp |
                       PinCapabilities::PullDown | PinCapabilities::PWM | PinCapabilities::ADC | PinCapabilities::ISR |
                       PinCapabilities::UART;
                case 21:
                case 26:
                case 27:
                case 28:
                case 29:
                case 30:
                case 31:
                case 32:
                case 33:
                case 34:
                case 35:
                case 36:
                case 37:
                case 38:
                case 39:
                case 40:
                case 41:
                case 42:
                case 43:
                case 44:
                case 45:
                case 46:
                case 47:
                case 48:
                    return PinCapabilities::Native | PinCapabilities::Input | PinCapabilities::Output | PinCapabilities::PullUp |
                       PinCapabilities::PullDown | PinCapabilities::PWM | PinCapabilities::ISR |
                       PinCapabilities::UART;

            }
        #elif

/X86TestSupport/TestSupport/esp32-hal-gpio.h

@@ -48,13 +48,23 @@ typedef enum {

     GPIO_NUM_32  = 32, /*!< GPIO32, input and output */
     GPIO_NUM_33  = 33, /*!< GPIO33, input and output */
-    GPIO_NUM_34  = 34, /*!< GPIO34, input mode only */
-    GPIO_NUM_35  = 35, /*!< GPIO35, input mode only */
-    GPIO_NUM_36  = 36, /*!< GPIO36, input mode only */
-    GPIO_NUM_37  = 37, /*!< GPIO37, input mode only */
-    GPIO_NUM_38  = 38, /*!< GPIO38, input mode only */
-    GPIO_NUM_39  = 39, /*!< GPIO39, input mode only */
-    GPIO_NUM_MAX = 40,
+    GPIO_NUM_34  = 34, /*!< GPIO34, input and output */
+    GPIO_NUM_35  = 35, /*!< GPIO35, input and output */
+    GPIO_NUM_36  = 36, /*!< GPIO36, input and output */
+    GPIO_NUM_37  = 37, /*!< GPIO37, input and output */
+    GPIO_NUM_38  = 38, /*!< GPIO38, input and output */
+    GPIO_NUM_39  = 39, /*!< GPIO39, input and output */
+    GPIO_NUM_40  = 40, /*!< GPIO40, input and output */
+    GPIO_NUM_41  = 41, /*!< GPIO41, input and output */
+    GPIO_NUM_42  = 42, /*!< GPIO42, input and output */
+    GPIO_NUM_43  = 43, /*!< GPIO43, input and output */
+    GPIO_NUM_44  = 44, /*!< GPIO44, input and output */
+    GPIO_NUM_45  = 45, /*!< GPIO45, input and output */
+    GPIO_NUM_46  = 46, /*!< GPIO46, input and output */
+    GPIO_NUM_47  = 47, /*!< GPIO47, input and output */
+    GPIO_NUM_48  = 48, /*!< GPIO48, input and output */
+
+    GPIO_NUM_MAX = 48,
     /** @endcond */
 } gpio_num_t;

platformio.ini

 [common_esp32_base]
-platform = https://github.com/platformio/platform-espressif32.git
+platform = espressif32
 framework = arduino
-platform_packages =
-    framework-arduinoespressif32@ https://github.com/espressif/arduino-esp32.git#2.0.7
 board_build.arduino.upstream_packages = no
-
 upload_speed = 921600
 board_build.partitions = min_littlefs.csv ; For 4M ESP32
 board_build.filesystem = littlefs

SDCARD(SPI)/UART/WIFI/WEB/PWM/LIMIT/TMC2209(2226) has been tested, but I don't have time to test the other functions.

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0xb (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbe4
load:0x403cc700,len:0x2a38
entry 0x403c98d4

[MSG:INFO: FluidNC v3.0.x (noGit)  (noGit)]
[MSG:INFO: Compiled with ESP32 SDK:v4.4.4]
[MSG:INFO: Local filesystem type is spiffs]
[MSG:INFO: Configuration file:config.yaml]
[MSG:WARN: frequency_hz value 80000000 constrained to range (400000,20000000)]
[MSG:INFO: Machine Kirizu-Laser V1.0]
[MSG:INFO: Board Kirizu-Laser]
[MSG:INFO: UART1 Tx:gpio.12 Rx:gpio.13 RTS:NO_PIN Baud:115200]
[MSG:INFO: SPI SCK:gpio.41 MOSI:gpio.40 MISO:gpio.42]
[MSG:INFO: SD Card cs_pin:gpio.39 detect:NO_PIN freq:20000000]
[MSG:INFO: Stepping:RMT Pulse:4us Dsbl Delay:0us Dir Delay:0us Idle Delay:255ms]
[MSG:INFO: Axis count 3]
[MSG:INFO: Shared stepper disable gpio.48]
[MSG:INFO: Axis X (-600.000,0.000)]
[MSG:INFO:   Motor0]
[MSG:INFO:     tmc_2209 UART1 Addr:0 CS:NO_PIN Step:gpio.20 Dir:gpio.3 Disable:NO_PIN R:0.100]
[MSG:INFO:  X Neg Limit gpio.16:low:pu]
[MSG:INFO:   Motor1]
[MSG:INFO: Axis Y (-600.000,0.000)]
[MSG:INFO:   Motor0]
[MSG:INFO:     tmc_2209 UART1 Addr:1 CS:NO_PIN Step:gpio.9 Dir:gpio.46 Disable:NO_PIN R:0.100]
[MSG:INFO:  Y Neg Limit gpio.15:low:pu]
[MSG:INFO:   Motor1]
[MSG:INFO: Axis Z (-1000.000,0.000)]
[MSG:INFO:   Motor0]
[MSG:INFO: X Axis driver test passed]
[MSG:INFO: Y Axis driver test passed]
[MSG:INFO: Kinematic system: Cartesian]
[MSG:INFO: Laser Ena:gpio.2:low:pu Out:gpio.38 Freq:25000Hz Period:1023]
[MSG:INFO: Using spindle Laser]
[MSG:INFO: Connecting to STA SSID:1703]
[MSG:INFO: Connecting.]
[MSG:INFO: Connecting..]
[MSG:INFO: Connected - IP is 192.168.36.64]
[MSG:INFO: WiFi on]
[MSG:INFO: Start mDNS with hostname:http://fluidnc.local/]
[MSG:INFO: SSDP Started]
[MSG:INFO: HTTP started on port 80]
[MSG:INFO: Telnet started on port 23]

Grbl 3.0 [FluidNC v3.0.x (noGit) (wifi) '$' for help]
[MSG:INFO: ALARM: Unhomed]
ALARM:14
[MSG:INFO: WebUI: Request from 192.168.36.211]
[MSG:INFO: WebUI: Request from 192.168.36.211]

image

Can I submit a PR? Is there anything to pay attention to here and could you help me check where I made a mistake? Thanks.

MitchBradley commented 7 months ago

You will need to find some way to make the changes conditional so the same code base can be used for both CPU variants. Also the release scripts will need to change to build both variants.