cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411CEU6 with VL53L8CX SWD ist not working

julion2
Associate II

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

12 REPLIES 12
RomainR.
ST Employee

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

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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

RomainR.
ST Employee

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,  

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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

RomainR.
ST Employee

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,

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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? 

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,

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Yes, I want to use the VL53L8CX with the STM32F411.
I already tried to refer to the  example of the X-CUBE-TOF1, but It did not work. 

Thanks for your help

Ok, can you clarify the X-CUBE-TOF1 example you tried, the examples are designed for Nucleo-F401RE and Nucleo-L476RG. In your case the good example to refer is for Nucleo-F401RE.

which hardware:

- STM32F411 is a custom board or other ?
- VL53L8X is X-NUCLEO-53L8A1 evaluation kit or other ?
Are you able to execute the following X-CUBE-TOF1 successfully ?
VL53L8A1_RANGING_SENSOR_Init()
VL53L8A1_RANGING_SENSOR_ReadID()

You say "It didn't work", but can you explain what are the problem you are facing? Compilation or code stuck somewhere?

Can you monitor I2C signal between STM32F411 and ToF sensor with a logic analyzer to check I2C serial  protocol is present? 

 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.