Files
stm32-cnn/PORTING/CNN/debug.c
2024-12-19 14:06:05 +08:00

106 lines
2.6 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "debug.h"
#include "led.h"
#include "exfuns.h"
u8 _DEBUG = 1;
void DEBUG(){
_DEBUG = !_DEBUG;
printf("DEBUG IS: %s",(_DEBUG ? "ON" : "OFF"));
}
void DEBUG_PRINTF(const char *fmt, ...) {
if(_DEBUG){
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
}
}
void SDRAM_USED(){
u16 memused = 0;
u8 paddr[20];
memused=my_mem_perused(SRAMEX);
sprintf((char*)paddr,"%d.%01d%%",memused/10,memused%10);
printf("SDRAM使用量为%s\r\n",paddr);
}
void scan_files(u8 * path)
{
FRESULT res;
res = f_opendir(&dir,(const TCHAR*)path); //打开一个目录
if (res == FR_OK)
{
printf("\r\n");
while(1)
{
res = f_readdir(&dir, &fileinfo); //读取目录下的一个文件
if (res != FR_OK || fileinfo.fname[0] == 0) break; //错误了/到末尾了,退出
//if (fileinfo.fname[0] == '.') continue; //忽略上级目录
printf("%s/", path);//打印路径
printf("%s\r\n",fileinfo.fname);//打印文件名
}
}
}
TIM_HandleTypeDef TIM3_Handler; //定时器句柄
//通用定时器3中断初始化
//arr自动重装值。
//psc时钟预分频数
//定时器溢出时间计算方法:Tout=((arr+1)*(psc+1))/Ft us.
//Ft=定时器工作频率,单位:Mhz
//这里使用的是定时器3!(定时器3挂在APB1上时钟为HCLK/2)
void TIM3_Init(u16 arr,u16 psc)
{
TIM3_Handler.Instance=TIM3; //通用定时器3
TIM3_Handler.Init.Prescaler=psc; //分频系数
TIM3_Handler.Init.CounterMode=TIM_COUNTERMODE_UP; //向上计数器
TIM3_Handler.Init.Period=arr; //自动装载值
TIM3_Handler.Init.ClockDivision=TIM_CLOCKDIVISION_DIV1;//时钟分频因子
HAL_TIM_Base_Init(&TIM3_Handler);
HAL_TIM_Base_Start_IT(&TIM3_Handler); //使能定时器3和定时器3更新中断TIM_IT_UPDATE
}
//定时器底册驱动,开启时钟,设置中断优先级
//此函数会被HAL_TIM_Base_Init()函数调用
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
{
if(htim->Instance==TIM3)
{
__HAL_RCC_TIM3_CLK_ENABLE(); //使能TIM3时钟
HAL_NVIC_SetPriority(TIM3_IRQn,1,3); //设置中断优先级抢占优先级1子优先级3
HAL_NVIC_EnableIRQ(TIM3_IRQn); //开启ITM3中断
}
}
//定时器3中断服务函数
void TIM3_IRQHandler(void)
{
HAL_TIM_IRQHandler(&TIM3_Handler);
}
//回调函数,定时器中断服务函数调用
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim==(&TIM3_Handler))
{
LED_R=!LED_R; //LED1反转
}
}