STM32L476 (Disco)

hello,
Rink here,

I am trying to do train accelerometer sensor data using edge impulse.
In edge impulse studio, all work well. I export the STM32cube.AI package file. Then I integrate that package in STMcubeIDE.After this process, I made simple code which just got accelerometer data, and this data processed by edge impulse sample API but I don’t get aspected output. So I need your help to get the best result in my project.

Project detail:- Make a Demo of accelerometer with detecting a minimum three types of movement for example right-left, up-down, Zick-zack.
Board - stm32l476 discovery
Sensor - lis2dw12

This is my code , every time I filled features named buffer with my accelerometer raw data which collecting in real time, this raw data got 100% accurate answer in edge impulse studio but in code that data don’t give proper answer ?

If you give any other detail about my project then I will give you , just solve my problem.

Hi Rink,

Do you always have same classification results or random ones?

Your model is probably overfitting as you have little data and training on 1500 cycles.
I would suggest adding more training samples, around 3 minutes for each movement, and then retrain on 100 cycles.

Cheers,
Aurelien

1 Like

@Rink, are you sure the data in the buffer is correct? You’re memsetting the features array to 0, then doing a single reading, so I assume get_feature_data will mostly retrieve zeros?

If everything is set up right you’ll get the features printed on the UART. Could you share those?

1 Like

See, i Called “lis2dw12_read_data_single()” function after memset() ok,
this function is to get data from the sensor and fills the buffer and I also see the buffer is filled or not.Screenshot_2020-10-01_09-10-47

see this is my function ,

your api works but results not appropriate.

Screenshot_2020-10-01_09-22-03

this is my result

ok , but if I put raw data on edge impulse studio , studio got perfect ans , with same data my code don’t give perfect ans .Screenshot_2020-10-01_09-27-53

Screenshot_2020-10-01_09-29-36

see , those two result …both have same raw data

@Rink could you print both the raw features array and the DSP result (pass true as third argument to run_classifier ?)

And just to confirm, if you fill the features array with static values (retrieved from the Studio) and classify, does it yield the correct answer? E.g. what we’re doing here: https://docs.edgeimpulse.com/docs/using-cubeai#running-the-impulse

Thanks for reply ,And yes I checked results on edge impulse studio with same raw data , studio get 100% right ans but code not , N i also prefer you base code which you given in you website . now what can i do .

see this is my output …At that time my sensor in steady position but still results are not give me steady position .

Screenshot_2020-10-01_17-54-09

Every time features buffer updated with new values … but still results don’t have any kind of change

@Rink I’ll take a look tomorrow on my L476!

Ok Sir ,
If you need my CubeIDE file then I will give you my project files…but this demo is very important for me .
After some changes , Right now my code give me same ans as studio , but this works only on static buffer , if i give real time sensor data on this buffer then its can’t provide right ans .

@Rink, I thought I had a L476 laying around, but I didn’t :slight_smile: Anyway, this is a demo on the DISCO-L475VG in STM32CubeIDE:

Includes

/* Includes ------------------------------------------------------------------*/
#include <edge-impulse-sdk/classifier/ei_run_classifier.h>
#include "main.h"
#include "stm32l475e_iot01_accelero.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

using namespace ei;

/* USER CODE END Includes */

Code

  /* USER CODE BEGIN 2 */
  ACCELERO_StatusTypeDef s = BSP_ACCELERO_Init();
  ei_printf("Accelerometer init result %d\n", s);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

  while (1) {
	  float features[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE] = { 0 };

	  for (size_t ix = 0; ix < EI_CLASSIFIER_RAW_SAMPLE_COUNT; ix++) {
		  uint64_t next_tick = ei_read_timer_us() + (EI_CLASSIFIER_INTERVAL_MS * 1000);

		  int16_t accel_data[3] = { 0 };
		  BSP_ACCELERO_AccGetXYZ(accel_data);

		  features[(ix * EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME) + 0] = static_cast<float>(accel_data[0]) / 100.0f;
		  features[(ix * EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME) + 1] = static_cast<float>(accel_data[1]) / 100.0f;
		  features[(ix * EI_CLASSIFIER_RAW_SAMPLES_PER_FRAME) + 2] = static_cast<float>(accel_data[2]) / 100.0f;

		  // busy-loop until next tick
		  while (ei_read_timer_us() < next_tick);
	  }

	  ei_impulse_result_t result;
	  signal_t signal;
	  numpy::signal_from_buffer(features, EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE, &signal);

      EI_IMPULSE_ERROR res = run_classifier(&signal, &result, false);
      ei_printf("run_classifier returned: %d\n", res);

      ei_printf("Predictions (DSP: %d ms., Classification: %d ms., Anomaly: %d ms.): \n",
          result.timing.dsp, result.timing.classification, result.timing.anomaly);

      // print the predictions
      ei_printf("[");
      for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
          ei_printf("%.5f", result.classification[ix].value);
  #if EI_CLASSIFIER_HAS_ANOMALY == 1
          ei_printf(", ");
  #else
          if (ix != EI_CLASSIFIER_LABEL_COUNT - 1) {
              ei_printf(", ");
          }
  #endif
      }
  #if EI_CLASSIFIER_HAS_ANOMALY == 1
      ei_printf("%.3f", result.anomaly);
  #endif
      ei_printf("]\n\n\n");
  }
  /* USER CODE END 3 */

Ok sir ,
thanks for your help
I will try this demo on my setup .

Hey sir ,
I was trying to run you code on my system but still its gets same result which is not correct. Screenshot_2020-10-05_10-25-58

Screenshot_2020-10-05_10-30-11
Hey , Sir
I was thinking , Can I use a standard C++ file on My setup(stm32L4 + lis2dw12)?
Because this is just for testing purposes, Our company final goal is that edge impulse use in a Nordic microcontroller. So How can I use Standard C++ library . Please give me some details or sample code something , I also try your Mbed OS code which is given in GitHub , but still there is so many linking error I got .

@Rink you can but if the model does not work properly on the STM32Cube.AI export it won’t work in the normal C++ export either. Given that your results are always the same I’m still suspecting the buffer to not be filled correctly.

So How can I use Standard C++ library

For STM32Cube.IDE see Need help with porting (STM32 Nucleo)

I also try your Mbed OS code which is given in GitHub , but still there is so many linking error I got .

https://github.com/edgeimpulse/example-standalone-inferencing-mbed? This works out-of-the-box for me on the https://os.mbed.com/platforms/ST-Discovery-L476VG/, compiling with GCC ARM 9 - what linker errors do you see?

janjongboom:~/repos/example-standalone-inferencing-mbed (master) $ mbed compile -t GCC_ARM -m disco_l476vg
[mbed] Working path "/Users/janjongboom/repos/example-standalone-inferencing-mbed" (program)
[Warning] @,: Compiler version mismatch: Have 9.3.1; expected version >= 6.0.0 and < 7.0.0
Building project example-standalone-inferencing-mbed (DISCO_L476VG, GCC_ARM)
Scan: example-standalone-inferencing-mbed
Link: example-standalone-inferencing-mbed
Elf2Bin: example-standalone-inferencing-mbed
| Module                                |      .text |    .data |      .bss |
|---------------------------------------|------------|----------|-----------|
| [fill]                                |    146(+0) |   14(+0) |    27(+0) |
| [lib]/c.a                             |  33532(+0) | 2472(+0) |    89(+0) |
| [lib]/gcc.a                           |   7196(+0) |    0(+0) |     0(+0) |
| [lib]/m.a                             |   9976(+0) |    1(+0) |     0(+0) |
| [lib]/misc                            |    188(+0) |    4(+0) |    28(+0) |
| [lib]/nosys.a                         |     32(+0) |    0(+0) |     0(+0) |
| [lib]/stdc++.a                        |   5208(+0) |    8(+0) |    44(+0) |
| edge-impulse-sdk/CMSIS                |  15784(+0) |    0(+0) |     0(+0) |
| edge-impulse-sdk/dsp                  |   3226(+0) |    0(+0) |     0(+0) |
| edge-impulse-sdk/porting              |     74(+0) |    0(+0) |     0(+0) |
| edge-impulse-sdk/tensorflow           |  15444(+0) |  192(+0) |     0(+0) |
| mbed-os/components                    |     36(+0) |    0(+0) |     4(+0) |
| mbed-os/drivers                       |    174(+0) |    0(+0) |     0(+0) |
| mbed-os/hal                           |   1726(+0) |    8(+0) |   130(+0) |
| mbed-os/platform                      |   4482(+0) |  260(+0) |   408(+0) |
| mbed-os/rtos                          |   6854(+0) |  168(+0) | 10324(+0) |
| mbed-os/targets                       |  11050(+0) |    8(+0) |   966(+0) |
| source/main.o                         |   9100(+0) |   65(+0) |     4(+0) |
| tflite-model/trained_model_compiled.o |   1288(+0) |  744(+0) |  2832(+0) |
| Subtotals                             | 125516(+0) | 3944(+0) | 14856(+0) |
Total Static RAM memory (data + bss): 18800(+0) bytes
Total Flash memory (text + data): 129460(+0) bytes

Image: ./BUILD/DISCO_L476VG/GCC_ARM/example-standalone-inferencing-mbed.bin

sir , I Checked my buffer fill with proper data or not , even I also print it.
See this in picture , I printed my buffer data and result … my data continues changes but result cant , and this time I used c++ library instead of Cube-AI.