应该在哪里为微控制器编写引导加载程序代码? [英] Where should a bootloader code be written for a microcontroller ?
问题描述
我正在为Kinetis Design Studio(IDE)中的kinetis控制器首次开发启动加载程序。由于引导加载程序应该是第一个要执行的代码,我应该创建一个单独的源文件(比如BootLoader.C),而不是IDE自动生成的Main.c文件。或者我应该把它写在Main.c文件中吗?
这就是MAIN.C看起来如何......我应该在哪里放置我的代码
I am developing a boot loader for first time for a kinetis controller in Kinetis Design Studio (IDE). Since the Boot loader should be the first code to be executed, should I create a separate source file (say BootLoader.C) apart from the automatically generated Main.c file by IDE. Or should I write it in the Main.c file itself?
THIS IS HOW THE MAIN.C LOOKS LIKE.. WHERE SHOULD I PLACE MY CODE
Filename : main.c
** Project : TestBeta
** Processor : MKE02Z64VLD2
** Version : Driver 01.01
** Compiler : GNU C Compiler
** Date/Time : 2016-02-12, 11:47, # CodeGen: 0
** Abstract :
** Main module.
** This module contains user's application code.
** Settings :
** Contents :
** No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.01
** @brief
** Main module.
** This module contains user's application code.
*/
/*!
** @addtogroup main_module main module documentation
** @{
*/
/* MODULE main */
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "Bit1.h"
#include "BitIoLdd1.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
/* User includes (#include below this line is not maintained by Processor Expert) */
SHOULD I WRITE THE BOOTLOADER CODE HERE ?????
/*lint -save -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
/* Write your local variable definition here */
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
PE_low_level_init();
/*** End of Processor Expert internal initialization. ***/
/* Write your code here */
/* For example: for(;;) { } */
SHOULD I WRITE THE BOOTLOADER CODE HERE ?????
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;){}
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
我尝试了什么:
我正在尝试在头文件之后编写代码。我已经包含了其他必需的头文件,后面跟着代码片段。我没有执行,还没看到。哪个是正确的方法
What I have tried:
I am trying to write the code right after the header files. I have included other required header files which is followed by the snippets of code.. I didn't execute and see yet. Which is the correct method
推荐答案
通常在单独的文件中进行清洁代码开发,但是IDE的翻译方式正常。
链接器会将它放在二进制文件的正确位置。
也许这里有一些示例代码。
Normally in a separate file for "clean code development" but in a manner your IDE is translating it fine.
The linker takes care to place it in the right position of your binary.
Maybe here is some example code for you.
这篇关于应该在哪里为微控制器编写引导加载程序代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!