Skip to main content
Visitor II
December 28, 2023
Question

STM32F411CEU6 with VL53L8CX SWD ist not working

  • December 28, 2023
  • 4 replies
  • 6557 views

Hey guys,

I set the SWD up for a project inculding a PCB with an F411CEU6 and an VL43L8CX. To test the pcb, I wana get the distance printed to the SWD console. I set up the SWD and with the main.c file it works fine, but with the vl53l8cx.c the printf statements don´t get printed...

Do you guys have an idea?

Best regards,

Julian

    This topic has been closed for replies.

    4 replies

    ST Employee
    December 28, 2023

    Hi @julion2 

    SWV needs pin PB3/SWO to transfer ITM data and the CPU clock speed correctly configured in SWD console.
    Check if :
    - Your firmware does not change the PB3/SWO configuration when using VLX ToF by reading the GPIO register.
    - Your CPU frequency speed is also the same between the SWD console and the device (STM32F411 CPU max frequency = 100MHz)
    Let me know if it helps.
    Regards,
    Romain

     

    julion2Author
    Visitor II
    December 28, 2023

    Thanks, for the answer. PB3 was actullay used for an gpio output so I changed that, but still not working in the vl53l8cx.c file... 

    The clock frequency is the same (printf is working in main.c but not vl53l8cx.c)
    Here is an part of the vl53l8cx.c with the printf statements Code:

     

    int32_t VL53L8CX_GetDistance(VL53L8CX_Object_t *pObj, VL53L8CX_Result_t *pResult)
    {
     int32_t ret;
     ret = VL53L8CX_OK;
     if ((pObj == NULL) || (pResult == NULL))
     {
     ret = VL53L8CX_INVALID_PARAM;
     }
     else if (pObj->IsRanging == 0U)
     {
     ret = VL53L8CX_ERROR;
     }
    
     if (ret == VL53L8CX_OK)
     {
     if (pObj->IsBlocking == 1U)
     {
     ret = vl53l8cx_poll_for_measurement(pObj, V53L8CX_POLL_TIMEOUT);
     }
     else
     {
     ret = vl53l8cx_poll_for_measurement(pObj, 0U);
     }
     }
    
     /* a new measure is available if no error is returned by the poll function */
     if (ret == VL53L8CX_OK)
     {
     ret = vl53l8cx_get_result(pObj, pResult);
    
     if (ret == VL53L8CX_OK)
     {
     // Add a debug print statement before the loop
     printf("Debug: About to print distance information to console.\n");
    
     for (uint8_t i = 0; i < pResult->NumberOfZones; i++)
     {
     printf("Zone %d:\n", i);
     for (uint8_t j = 0; j < pResult->ZoneResult[i].NumberOfTargets; j++)
     {
     printf(" Target %d - Distance: %d mm\n", j, pResult->ZoneResult[i].Distance[j]);
     }
     }
     }
     }
    
     return ret;
    }

     

    This is the Pinnout:Screenshot 2023-12-28 at 11.53.21.png

    ST Employee
    December 28, 2023

    I tested on my side printf with SWO, first from main() and from an external function. It works in both case.
    Share your project and I will check it.

    Regards,
    Romain,  

    julion2Author
    Visitor II
    December 28, 2023

    Okay interesting, here is the ioc, main.c and vl53l8cx.c. I am using an STLINK v3

    ST Employee
    December 28, 2023

    Thank you for sharing ioc, main.c and your vl53l8cx.c.

    First, you do not include <stdio.h>, so you need it everywhere you use stdio function like printf, putchar or getchar...
    Then your main function call only printf("Test"); and never use any of the function used by vl53l8cx.c?
    If you never call VL53L8CX_GetDistance() somewhere, there is no chance to print something somewhere... 

    I confirm the printf through SWV is working everywhere. I just written the function below outside of main.c and force some constants values because I do not have ToF sensor in my hands today.

    int32_t VL53L8CX_GetDistance(VL53L8CX_Object_t *pObj, VL53L8CX_Result_t *pResult)

     

    RomainR_0-1703768599637.png

    Check again your firmware, call vl53l8 function from main and place some breakpoint in order to debug. 

    Regards,

    Romain,

    julion2Author
    Visitor II
    December 28, 2023

    Sorry for the dumb questions, so I just have to paste the function you provided outside of main(void) and than call the function in the loop? 

    ST Employee
    December 28, 2023

    What is your goal? Use the Vl53l8 with your STM32F411?
    If so, you need to write your firmware in order to use the relevant functions of this sensor, from main loop or from your own function somewhere in your project.

    You could refer to the example provided with the X-CUBE-TOF1 (here below)

    STM32Cube\Repository\Packs\STMicroelectronics\X-CUBE-TOF1\3.4.0\Projects\NUCLEO-F401RE\Examples\53L8A1\53L8A1_SimpleRanging

    Regards,
    Romain,

    ST Employee
    December 28, 2023

    Make sure you use the same voltage levels on the pins referenced to IOVDD.
    According to datasheet DS14161, you must adapt the GPIO levels to 1.8V between the STM32F411 and the sensor. I hope your pcb includes a voltage level shifter?

    https://www.st.com/resource/en/datasheet/vl53l8cx.pdf

    I wish you all the best in your I2C communication trials, let us know if you need help.

    Best regards,
    Romain,

    julion2Author
    Visitor II
    December 31, 2023

    Okay thanks, I missed that’s while designing the PCB. I will redesign it and than try it again. Thanks and a have great ne year!