不爱胡萝卜的仓鼠 发表于 2024-11-12 11:46

[STM32H7R/S]测评 ⑨nano edge ai studio 训练一个模型--下

<div class='showpostmsg'> 本帖最后由 不爱胡萝卜的仓鼠 于 2024-11-11 21:37 编辑

<p>/***********************************************************************************************************/</p>

<p>本文强烈建议和上一篇文章以及datalogger的那篇一起交叉看,因为今天又学到了一点新东西。并且还发现了之前datalogger的一个重大BUG</p>

<p>/***********************************************************************************************************/</p>

<p>&nbsp;</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在上一篇中最后一步移植.a文件到工程中没能顺利完成,我个人感觉还是工程的问题,可惜我能力有限,没法解决。</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; 正经能力我可能有限,但是我歪办法多<img height="52" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/pleased.gif" width="48" />。我的思路是创建一个空白工程,用Keil,然后只要boot工程,不要跳转APP工程,直接把Boot工程当做主工程来用,我看了主芯片Flash和Ram其实还是可以的,有64K Flash,620K RAM,简单跑跑这个项目应该问题不大。只要我能想尽一切办法让这个boot工程的代码能顺利编译,那就万事大吉啦</p>

<p>&nbsp;</p>

<div>&nbsp; &nbsp; &nbsp; &nbsp; 经过不懈努力,我终于搞定了我想要的东西,现在这个工程就是实现了之前dataLogger功能的,可以用keil编译的,相比之前的我还增加了ready信号的get,这样应该会更好一点,每次都可以保证获取到新的值。还发现之前datalogger代码的一个BUG,他打印出来的结果是错误的,偏移写的不正确。</div>

<div>&nbsp; &nbsp; &nbsp; &nbsp; 之前的工程红框位置的偏移写错了</div>

<div>
<div style="text-align: center;"></div>

<p>本次修正后</p>

<div style="text-align: center;"></div>
</div>

<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;工程如下:(后面我把datalogger的功能整合进最终的工程了,所以这个大家有兴趣的话就打开看看,可以忽略不看,并且后续有一些代码的小修改,他和最终工程中的也不一定一致,主要是数据格式从int改成了float)</div>

<p>&nbsp;</p>

<div></div>

<div>&nbsp;</div>

<div><strong><span style="font-size:24px;">一.再次训练模型</span></strong></div>

<p>&nbsp; &nbsp; &nbsp; &nbsp; 因为上一个模型有问题,我就重新训练了一个模型,这个模型比之前的那个好,现在这个可以到100%,上一篇就92.5(不过上一篇用了错误的datalogger代码,原始样本数据就是错的,那个模型就是报废的。也没啥参考意义)。具体操作步骤我就不说了,详见上一篇</p>

<div style="text-align: center;">
<div style="text-align: center;">
<div style="text-align: center;"></div>

<p>&nbsp;</p>
</div>
</div>

<p>&nbsp; &nbsp; &nbsp; &nbsp; 并且在验证环节,我尝试了正确位置放正确数据,还尝试交换放数据,结果都是100%正确识别。这个模型肯定嘎嘎好用</p>

<div style="text-align: center;">
<div style="text-align: center;">
<div style="text-align: center;"></div>

<p>&nbsp;</p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>

<p style="text-align: left;">/***********************************************************************************************************/</p>

<p style="text-align: left;">这里再补充一点,最后一步生成库文件时,Compilation Flags默认会勾选第1个和第3个。我的编译器可能不匹配,如果按默认的来,我这儿能编译,能运行,但是检测出来的结果一直是同一个,很奇怪,编译器这玩意也是触摸到了我的知识盲区,搞不明白。反正全部去掉勾选,就可以了</p>

<div style="text-align: center;"></div>

<p style="text-align: left;">/***********************************************************************************************************/</p>
</div>

<p style="text-align: left;">&nbsp;</p>

<p style="text-align: left;"><strong><span style="font-size:24px;">二.在线验证模型</span></strong></p>

<p style="text-align: left;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;并且本次我还发现一个很有用的东西,就是在线模拟,通过串口直接把datalogger实时采集的数据传给电脑,电脑直接运行模型,推算结果。这样就不用把模型下载到开发板上再验证结果了,并且这样在线验证后,我们就可以知道模型是不是真的好用,如果回头在开发板上运行时有问题,那至少可以排除模型的问题</p>

<div style="text-align: center;">
<div style="text-align: center;"></div>
</div>

<p style="text-align: left;">&nbsp; &nbsp; &nbsp; &nbsp; 开发板上运行datalogger的代码,然后界面上选择串口和波特率,再点开始即可</p>

<div style="text-align: center;">
<div style="text-align: center;">
<div style="text-align: center;"></div>

<div style="text-align: center;">&nbsp;</div>

<div style="text-align: center;">
<div style="text-align: center;"></div>

<p>&nbsp;</p>
</div>
</div>
</div>

<p style="text-align: left;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;这个玩意儿图文不够生动,我就录了一段视频给大家</p>

<p style="text-align: left;">69151aec60f97e6d2658b72ad5fb01e5<br />
&nbsp;</p>

<p style="text-align: left;"><strong><span style="font-size:24px;">三.移植模型到开发版上运行</span></strong></p>
</div>

<div>&nbsp; &nbsp; &nbsp; &nbsp;最终得到的模型压缩包如下:</div>

<div></div>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;接下来就是把本次得到的新模型弄到工程中去运行一下,在如图路径创建一个文件夹,用于存放.a和.h</p>

<div style="text-align: center;"></div>

<p>然后把压缩包里的.a、.h拷贝到这个路径下</p>

<div style="text-align: center;"></div>

<p>接下来我们打开keil,然后添加nanoedgeai的文件夹和文件</p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>

<div style="text-align: center;"></div>

<p>接下来是添加头文件路径</p>

<div style="text-align: center;"></div>

<div style="text-align: center;"></div>

<p>然后要对.a文件做一下修改,右键点击.a文件</p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>

<div style="text-align: center;"></div>

<p>&nbsp;</p>

<p>接下来就是对main.c进行修改了,参照nanoEdgeAi给的示例代码,和上一篇的修改差不多,只是我这边用了printf(这玩意儿终于好用了)</p>

<p>以下是整个main.c,我这边是整合了datalogger工程和AI模型的,通过&ldquo;MODE&rdquo;这个宏定义控制</p>

<pre>
<code class="language-cpp">/* USER CODE BEGIN Header */
/**
******************************************************************************
* <a href="home.php?mod=space&amp;uid=1307177" target="_blank">@File </a>         : main.c
* <a href="home.php?mod=space&amp;uid=159083" target="_blank">@brief </a>          : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include &quot;main.h&quot;

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include &quot;stdio.h&quot;
#include &quot;iks4a1_motion_sensors.h&quot;
#include &quot;iks4a1_motion_sensors_ex.h&quot;
#include &quot;lsm6dso16is_reg.h&quot;
#include &quot;NanoEdgeAI.h&quot;
#include &quot;knowledge.h&quot;

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
typedef struct displayFloatToInt_s {
int8_t sign; /* 0 means positive, 1 means negative*/
uint32_tout_int;
uint32_tout_dec;
} displayFloatToInt_t;
/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define MAX_BUF_SIZE 256

#define ACC_SAMPLE_MAX 64
#define AXIS3

#define MODE (1)    /* 0:datalogger模式, 1: 运行nanoedgeai模型模式 */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

UART_HandleTypeDef huart4;

/* USER CODE BEGIN PV */
//static uint8_t verbose = 0;/* Verbose output to UART terminal ON/OFF. */

static IKS4A1_MOTION_SENSOR_Capabilities_t MotionCapabilities;

static char dataOut;

// static int acc_sample_buffer = {0};
float input_user_buffer; // Buffer of input values
float output_class_buffer; // Buffer of class probabilities

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MPU_Config(void);
static void MX_GPIO_Init(void);
static void MX_UART4_Init(void);
static void MX_FLASH_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
int fputc(int ch, FILE *f)

{

HAL_UART_Transmit(&amp;huart4, (uint8_t *)&amp;ch, 1, 0xffff);

return ch;

}

static void floatToInt(float in, displayFloatToInt_t *out_value, int32_t dec_prec)
{
if(in &gt;= 0.0f)
{
    out_value-&gt;sign = 0;
}else
{
    out_value-&gt;sign = 1;
    in = -in;
}

in = in + (0.5f / pow(10, dec_prec));
out_value-&gt;out_int = (int32_t)in;
in = in - (float)(out_value-&gt;out_int);
out_value-&gt;out_dec = (int32_t)trunc(in * pow(10, dec_prec));
}

static void Accelero_Sensor_Handler(uint32_t Instance)
{
//float odr;
//int32_t fullScale;
IKS4A1_MOTION_SENSOR_Axes_t acceleration;
//displayFloatToInt_t out_value;
//uint8_t whoami;
uint16_t i = 0;
lsm6dso16is_status_reg_t Status;

for (i = 0; i &lt; ACC_SAMPLE_MAX;)
{
    while(1)
    {
      if (BSP_ERROR_NONE == IKS4A1_MOTION_SENSOR_Get_DRDY_Status(Instance, MOTION_ACCELERO, (uint8_t *)&amp;Status))
      {
      if (Status.xlda == 1)
      {
          break;
      }
      }
    }

    if (0 == IKS4A1_MOTION_SENSOR_GetAxes(Instance, MOTION_ACCELERO, &amp;acceleration))
    {
      input_user_buffer = (float)acceleration.x;
      input_user_buffer[(AXIS * i) + 1] = (float)acceleration.y;
      input_user_buffer[(AXIS * i) + 2] = (float)acceleration.z;

      i++;
    }
}


for(i = 0; i &lt; ACC_SAMPLE_MAX - 1; i++)
{
    sprintf(dataOut, &quot;%.2f,%.2f,%.2f,&quot;, input_user_buffer[(AXIS * i)], input_user_buffer[(AXIS * i)+1], input_user_buffer[(AXIS * i)+2]);
    printf(&quot;%s&quot;, dataOut);
}
i = ACC_SAMPLE_MAX - 1;
sprintf(dataOut, &quot;%.2f,%.2f,%.2f&quot;, input_user_buffer[(AXIS * i)], input_user_buffer[(AXIS * i)+1], input_user_buffer[(AXIS * i)+2]);
printf(&quot;%s\r\n&quot;, dataOut);
}

/* USER CODE END 0 */

/**
* @briefThe application entry point.
* @retval int
*/
int main(void)
{

/* USER CODE BEGIN 1 */
#if MODE == 1
uint16_t id_class = 0;
#endif
/* USER CODE END 1 */

/* MPU Configuration--------------------------------------------------------*/
MPU_Config();

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_UART4_Init();
MX_FLASH_Init();
/* USER CODE BEGIN 2 */
        printf(&quot;test&quot;);
/* ACC传感器初始化 */
displayFloatToInt_t out_value_odr;
int i;
IKS4A1_MOTION_SENSOR_Init(IKS4A1_LSM6DSO16IS_0, MOTION_ACCELERO | MOTION_GYRO);
printf(&quot;IKS4A1_MOTION_SENSOR_Init ok\r\n&quot;);
for(i = 0; i &lt; IKS4A1_MOTION_INSTANCES_NBR; i++)
{
    IKS4A1_MOTION_SENSOR_GetCapabilities(i, &amp;MotionCapabilities);
    snprintf(dataOut, MAX_BUF_SIZE,
             &quot;\r\nMotion Sensor Instance %d capabilities: \r\n ACCELEROMETER: %d\r\n GYROSCOPE: %d\r\n MAGNETOMETER: %d\r\n LOW POWER: %d\r\n&quot;,
             i, MotionCapabilities.Acc, MotionCapabilities.Gyro, MotionCapabilities.Magneto, MotionCapabilities.LowPower);
    printf(&quot;%s&quot;, dataOut);
    floatToInt(MotionCapabilities.AccMaxOdr, &amp;out_value_odr, 3);
    snprintf(dataOut, MAX_BUF_SIZE, &quot; MAX ACC ODR: %d.%03d Hz, MAX ACC FS: %d\r\n&quot;, (int)out_value_odr.out_int,
             (int)out_value_odr.out_dec, (int)MotionCapabilities.AccMaxFS);
    printf(&quot;%s&quot;, dataOut);
    floatToInt(MotionCapabilities.GyroMaxOdr, &amp;out_value_odr, 3);
    snprintf(dataOut, MAX_BUF_SIZE, &quot; MAX GYRO ODR: %d.%03d Hz, MAX GYRO FS: %d\r\n&quot;, (int)out_value_odr.out_int,
             (int)out_value_odr.out_dec, (int)MotionCapabilities.GyroMaxFS);
    printf(&quot;%s&quot;, dataOut);
    floatToInt(MotionCapabilities.MagMaxOdr, &amp;out_value_odr, 3);
    snprintf(dataOut, MAX_BUF_SIZE, &quot; MAX MAG ODR: %d.%03d Hz, MAX MAG FS: %d\r\n&quot;, (int)out_value_odr.out_int,
             (int)out_value_odr.out_dec, (int)MotionCapabilities.MagMaxFS);
    printf(&quot;%s&quot;, dataOut);
}

#if MODE == 1
enum neai_state error_code = neai_classification_init(knowledge);
if (error_code != NEAI_OK)
{
    while(1)
    {
      /* This happens if the knowledge does not correspond to the library or if the library works into a not supported board. */
      printf(&quot;neai_classification_init fail&quot;);
      HAL_Delay(1000);
    }
}
printf(&quot;neai_classification_init ok&quot;);
#endif
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
          // HAL_GPIO_WritePin(GPIOO, GPIO_PIN_1, GPIO_PIN_RESET);
          // HAL_Delay(1000);
          // printf(&quot;led on&quot;);
          // HAL_GPIO_WritePin(GPIOO, GPIO_PIN_1, GPIO_PIN_SET);
          // HAL_Delay(1000);
          // printf(&quot;led off&quot;);
    Accelero_Sensor_Handler(0);
#if MODE == 1
    neai_classification(input_user_buffer, output_class_buffer, &amp;id_class);
    printf(&quot;stop:%.2f, line:%.2f, circle:%.2f\r\n&quot;, output_class_buffer, output_class_buffer, output_class_buffer);
    printf(&quot;result: %d\r\n&quot;, id_class);
#endif

}
/* USER CODE END 3 */
}

/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

/** Configure the main internal regulator output voltage
*/
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
{
    Error_Handler();
}

/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL1.PLLState = RCC_PLL_NONE;
RCC_OscInitStruct.PLL2.PLLState = RCC_PLL_NONE;
RCC_OscInitStruct.PLL3.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&amp;RCC_OscInitStruct) != HAL_OK)
{
    Error_Handler();
}

/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
                              |RCC_CLOCKTYPE_PCLK4|RCC_CLOCKTYPE_PCLK5;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
RCC_ClkInitStruct.APB5CLKDivider = RCC_APB5_DIV1;

if (HAL_RCC_ClockConfig(&amp;RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
    Error_Handler();
}
}

/**
* @brief FLASH Initialization Function
* @param None
* @retval None
*/
static void MX_FLASH_Init(void)
{

/* USER CODE BEGIN FLASH_Init 0 */

/* USER CODE END FLASH_Init 0 */

FLASH_OBProgramInitTypeDef pOBInit = {0};

/* USER CODE BEGIN FLASH_Init 1 */

/* USER CODE END FLASH_Init 1 */
HAL_FLASHEx_OBGetConfig(&amp;pOBInit);
if ((pOBInit.USERConfig2 &amp; OB_I2C_NI3C_I2C) != OB_I2C_NI3C_I2C)
{
if (HAL_FLASH_Unlock() != HAL_OK)
{
    Error_Handler();
}
if (HAL_FLASH_OB_Unlock() != HAL_OK)
{
    Error_Handler();
}
pOBInit.OptionType = OPTIONBYTE_USER;
pOBInit.USERType = OB_USER_I2C_NI3C;
pOBInit.USERConfig2 = OB_I2C_NI3C_I2C;
if (HAL_FLASHEx_OBProgram(&amp;pOBInit) != HAL_OK)
{
    Error_Handler();
}
if (HAL_FLASH_OB_Lock() != HAL_OK)
{
    Error_Handler();
}
if (HAL_FLASH_Lock() != HAL_OK)
{
    Error_Handler();
}
}
/* USER CODE BEGIN FLASH_Init 2 */

/* USER CODE END FLASH_Init 2 */

}

/**
* @brief UART4 Initialization Function
* @param None
* @retval None
*/
static void MX_UART4_Init(void)
{

/* USER CODE BEGIN UART4_Init 0 */

/* USER CODE END UART4_Init 0 */

/* USER CODE BEGIN UART4_Init 1 */

/* USER CODE END UART4_Init 1 */
huart4.Instance = UART4;
huart4.Init.BaudRate = 921600;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_1;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart4.Init.OverSampling = UART_OVERSAMPLING_16;
huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&amp;huart4) != HAL_OK)
{
    Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&amp;huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
    Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&amp;huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
    Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&amp;huart4) != HAL_OK)
{
    Error_Handler();
}
/* USER CODE BEGIN UART4_Init 2 */

/* USER CODE END UART4_Init 2 */

}

/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOO_CLK_ENABLE();

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOO, GPIO_PIN_1, GPIO_PIN_RESET);

/*Configure GPIO pin : PO1 */
GPIO_InitStruct.Pin = GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOO, &amp;GPIO_InitStruct);

/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/* MPU Configuration */

static void MPU_Config(void)
{
MPU_Region_InitTypeDef MPU_InitStruct = {0};

/* Disables the MPU */
HAL_MPU_Disable();

/** Initializes and configures the Region and the memory to be protected
*/
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.BaseAddress = 0x0;
MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
MPU_InitStruct.SubRegionDisable = 0x87;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

HAL_MPU_ConfigRegion(&amp;MPU_InitStruct);
/* Enables the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);

}

/**
* @briefThis function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}

#ifdefUSE_FULL_ASSERT
/**
* @briefReports the name of the source file and the source line number
*         where the assert_param error has occurred.
* @paramfile: pointer to the source file name
* @paramline: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
   ex: printf(&quot;Wrong parameters value: file %s on line %d\r\n&quot;, file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
</code></pre>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>编译后有如图报错</p>

<div style="text-align: center;"></div>

<pre>
<code>TEST_Boot\TEST_Boot.axf: Error: L6242E: Cannot link object NanoEdgeAI.o as its attributes are incompatible with the image attributes.
   ... wchart-16 clashes with wchart-32.
Not enough information to list image symbols.
Not enough information to list load addresses in the image map.</code></pre>

<p>需要做如下修改:</p>

<div style="text-align: center;"></div>

<pre>
<code>--wchar32</code></pre>

<p>还要切换回AC5,否则这个改了以后还会有更多的报错</p>

<div style="text-align: center;"></div>

<p>这样就万事大吉了,虽然有点警告,但问题不大</p>

<div style="text-align: center;"></div>

<p>接下来就是激动人心的时刻了,运行代码,看看能否正确识别</p>

<p>7e48eb830a8c166617694c7f478f2e49<br />
&nbsp;</p>

<p>本次最终的工程:</p>

<div></div>

<p>&nbsp;</p>

<p><strong><span style="font-size:24px;">四.心得</span></strong></p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;本次STM32H7R/S-DK开发板的测评终于圆满完成。本次真的是收获满满,我在今年上半年就了解到ST在Ai方向的各种方案及工具,但是当时nanoedgeai还是要收费的,并且我的本职工作不是做AI方向的开发的,对于Ai相关的知识以及如何训练模型、使用模型完全不懂,是属于小白的档位,所以一直就处于观望阶段,最近nanoedgeai免费了,正好遇上H7S7开发板的试用,就趁着这个契机逼自己一把,学习一下相关的知识和技能。</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; 不得不说,ST在文档、demo、视频教程相关的技术支持、工具的设计等真的没的说,在业界绝对算的上数一数二。我通过看官方提供的学习资料,一个门外汉,通过几十小时的学习、实践。可以快速掌握模型训练、在单片上运行模型的开发技能,可以看得出来ST的工程师绝对是付出了巨大的努力,并且训练出来的模型实际效果也是非常棒,100条数据,训练一次,就得到了一个非常完美的模型,体积很小,响应很快,准确度很高。这样的结果真的是令我非常震撼,在得到结果前我一直认为会需要有多轮的训练、调参数、调整样本等</p>

<p>&nbsp; &nbsp; &nbsp; &nbsp; &middot;最后再次感谢ST和EEWORLD给我这次试用的机会,谢谢</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>
</div><script>                                        var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;"   style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
                                       
                                        if(parseInt(discuz_uid)==0){
                                                                                                (function($){
                                                        var postHeight = getTextHeight(400);
                                                        $(".showpostmsg").html($(".showpostmsg").html());
                                                        $(".showpostmsg").after(loginstr);
                                                        $(".showpostmsg").css({height:postHeight,overflow:"hidden"});
                                                })(jQuery);
                                        }                </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>

Jacktang 发表于 2024-11-13 07:50

<p>STM32H7R/S-DK开发板的测评做的不错,赞</p>

电子烂人 发表于 2024-11-14 17:00

<p>好文章,等我回去试试这个方法。打个胶先(</p>

不爱胡萝卜的仓鼠 发表于 2024-11-15 11:08

Jacktang 发表于 2024-11-13 07:50
STM32H7R/S-DK开发板的测评做的不错,赞

<p>谢谢夸奖<img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/lol.gif" width="48" /></p>

不爱胡萝卜的仓鼠 发表于 2024-11-15 11:10

电子烂人 发表于 2024-11-14 17:00
好文章,等我回去试试这个方法。打个胶先(

<p>好呀,有问题我们再交流<img height="28" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/smiling-face-with-open-mouth-and-smiling-eyes_1f604.png" width="28" /></p>
页: [1]
查看完整版本: [STM32H7R/S]测评 ⑨nano edge ai studio 训练一个模型--下