文章目录前言一、代码前言启动前需要通过mcu通讯来判断是进入正常开机还是关机充电。一、代码#includeapp/boot_ui.h#ifdefWITH_PLATFORM_MEDIATEK_COMMON_CHARGER#includemtk_charger.h#endif#includelib/kcmdline.h#ifdefWITH_PLATFORM_MEDIATEK_COMMON_KEYPAD#includemtk_key.h#endif#includeplatform/boot_mode.h#includeplatform/mboot_params.h#includeplatform/wdt.h#includeplatform_mtk.h#includestring.h#includetrace.h#includedev/uart.h#includeuart_api.h#includeplatform/addressmap.h#includeplatform/gpio.h#includegpio_api.h#defineudelay(x)spin(x)#definemdelay(x)udelay((x)*1000)staticu8 g_boot_modeNORMAL_BOOT;voidboot_mode_check(void){u8 pl_modepl_mode_check();if(pl_mode)g_boot_modepl_mode;elseif(recovery_check())g_boot_modeRECOVERY_BOOT;elseif(fastboot_check())g_boot_modeFASTBOOT_BOOT;elseif(factory_key_check())g_boot_modeFACTORY_BOOT;elseif(bootmenu_check())g_boot_modeboot_menu_select();elseif(kpoc_check())g_boot_modeKERNEL_POWER_OFF_CHARGING_BOOT;//GPIO INITUART_1mt_set_gpio_mode(GPIO136,GPIO_MODE_07);mt_set_gpio_dir(GPIO136,GPIO_DIR_IN);mt_set_gpio_pull_select(GPIO136,GPIO_PULL_UP);mt_set_gpio_pull_enable(GPIO136,GPIO_PULL_ENABLE);mt_set_gpio_mode(GPIO137,GPIO_MODE_07);mt_set_gpio_dir(GPIO137,GPIO_DIR_OUT);//获取 boot modeuart_init_port(1,115200);charc[10]{0x02,0x02,0x00,0x04,0x11,0x14,0x00,0x00,0x03,0x40};for(inti0;i10;i){uart_putc(1,c[i]);}dprintf(CRITICAL,------------uart port 1 putc end\n);mdelay(100);constcharc_cmp[15]{0x02,0x02,0x00,0x09,0x11,0x14,0x01,0x00,0x04,0x00,0x00,0x00,0xff,0x09,0x40};for(inti0;i15;i){intretuart_getc(1,false);dprintf(CRITICAL,------------uart port 1 getc c[%d] 0x%x \n,i,ret);//考虑到没有mcu电源板的情况首字节错误直接跳出判断if(i0ret!0x02){dprintf(CRITICAL,------------uart port 1 getc error \n);break;}if(c_cmp[i]!ret){//index_i 12, 0x00:异常开机0x01关机充电0x02按键开机if(i12){if(ret0x00){//异常开机需要怎么处理dprintf(CRITICAL,------------uart port 1 c[%d] 0x%x, abnormal boot \n,i,ret);}elseif(ret0x01){//关机充电g_boot_modeKERNEL_POWER_OFF_CHARGING_BOOT;dprintf(CRITICAL,------------uart port 1 c[%d] 0x%x, only charging \n,i,ret);}elseif(ret0x02){//按键开机g_boot_modeNORMAL_BOOT;dprintf(CRITICAL,------------uart port 1 c[%d] 0x%x, normal boot \n,i,ret);}continue;}dprintf(CRITICAL,------------uart port 1 error c[%d] 0x%x \n,i,ret);}}dprintf(CRITICAL,%s zzh g_boot_mode %d \n,__func__,g_boot_mode);}
mtk lk使用串口通讯
发布时间:2026/6/15 1:02:05
文章目录前言一、代码前言启动前需要通过mcu通讯来判断是进入正常开机还是关机充电。一、代码#includeapp/boot_ui.h#ifdefWITH_PLATFORM_MEDIATEK_COMMON_CHARGER#includemtk_charger.h#endif#includelib/kcmdline.h#ifdefWITH_PLATFORM_MEDIATEK_COMMON_KEYPAD#includemtk_key.h#endif#includeplatform/boot_mode.h#includeplatform/mboot_params.h#includeplatform/wdt.h#includeplatform_mtk.h#includestring.h#includetrace.h#includedev/uart.h#includeuart_api.h#includeplatform/addressmap.h#includeplatform/gpio.h#includegpio_api.h#defineudelay(x)spin(x)#definemdelay(x)udelay((x)*1000)staticu8 g_boot_modeNORMAL_BOOT;voidboot_mode_check(void){u8 pl_modepl_mode_check();if(pl_mode)g_boot_modepl_mode;elseif(recovery_check())g_boot_modeRECOVERY_BOOT;elseif(fastboot_check())g_boot_modeFASTBOOT_BOOT;elseif(factory_key_check())g_boot_modeFACTORY_BOOT;elseif(bootmenu_check())g_boot_modeboot_menu_select();elseif(kpoc_check())g_boot_modeKERNEL_POWER_OFF_CHARGING_BOOT;//GPIO INITUART_1mt_set_gpio_mode(GPIO136,GPIO_MODE_07);mt_set_gpio_dir(GPIO136,GPIO_DIR_IN);mt_set_gpio_pull_select(GPIO136,GPIO_PULL_UP);mt_set_gpio_pull_enable(GPIO136,GPIO_PULL_ENABLE);mt_set_gpio_mode(GPIO137,GPIO_MODE_07);mt_set_gpio_dir(GPIO137,GPIO_DIR_OUT);//获取 boot modeuart_init_port(1,115200);charc[10]{0x02,0x02,0x00,0x04,0x11,0x14,0x00,0x00,0x03,0x40};for(inti0;i10;i){uart_putc(1,c[i]);}dprintf(CRITICAL,------------uart port 1 putc end\n);mdelay(100);constcharc_cmp[15]{0x02,0x02,0x00,0x09,0x11,0x14,0x01,0x00,0x04,0x00,0x00,0x00,0xff,0x09,0x40};for(inti0;i15;i){intretuart_getc(1,false);dprintf(CRITICAL,------------uart port 1 getc c[%d] 0x%x \n,i,ret);//考虑到没有mcu电源板的情况首字节错误直接跳出判断if(i0ret!0x02){dprintf(CRITICAL,------------uart port 1 getc error \n);break;}if(c_cmp[i]!ret){//index_i 12, 0x00:异常开机0x01关机充电0x02按键开机if(i12){if(ret0x00){//异常开机需要怎么处理dprintf(CRITICAL,------------uart port 1 c[%d] 0x%x, abnormal boot \n,i,ret);}elseif(ret0x01){//关机充电g_boot_modeKERNEL_POWER_OFF_CHARGING_BOOT;dprintf(CRITICAL,------------uart port 1 c[%d] 0x%x, only charging \n,i,ret);}elseif(ret0x02){//按键开机g_boot_modeNORMAL_BOOT;dprintf(CRITICAL,------------uart port 1 c[%d] 0x%x, normal boot \n,i,ret);}continue;}dprintf(CRITICAL,------------uart port 1 error c[%d] 0x%x \n,i,ret);}}dprintf(CRITICAL,%s zzh g_boot_mode %d \n,__func__,g_boot_mode);}