MR frame
- MR frame
- Brief introduction
- Key characteristic
- Major component
- Standardized device interface
- Configuration tool
- Directory structure
- Get Started
- Let's Light an LED
- Hello World
- Now that you have completed the introductory tutorial, start using the MR Library.
Brief introduction
The MR framework is a lightweight framework designed specifically for embedded systems. It fully considers the
resource and performance requirements of embedded systems.
By providing standardized device management interfaces, it greatly simplifies the development of embedded applications and helps developers quickly build embedded applications.
The framework provides developers with standardized open, close, ioctl, read, write and other
interfaces. It decouples the applications from the low-level hardware drivers. The applications do not need to know the
implementation details of the drivers.
When the hardware changes, the applications can seamlessly migrate to the new hardware by only adapting the low-level drivers. This greatly improves the reusability of software and its extensibility to new hardware.
Key characteristic
- Standardized device access interfaces
- Decoupled application and driver development
- Simplified lower-level driver and application development
- Lightweight and easy to use with low resource usage
- Modular design with loose coupling between components for independent development and extremely low hardware migration costs
- Supported in bare-metal and operating system environments
Major component
- Device framework: Provides standardized device access interfaces
- Memory management: Dynamic memory management
- Tools: Common data structures like lists, queues, balanced trees etc.
- Various functional components
Standardized device interface
All operations of the device can be implemented through the following interfaces:
| interface | describe |
|---|---|
| mr_dev_register | Registered device |
| mr_dev_open | Open device |
| mr_dev_close | Close device |
| mr_dev_ioctl | Control device |
| mr_dev_read | Read data from the device |
| mr_dev_write | Writes data to the device |
| mr_dev_isr | Device interrupt control |
Configuration tool
MR provides Kconfig visual configuration tool that developers can configure without deep knowledge of the source
code.
Kconfig will automatically generate the configuration options interface based on the configuration file. Developers
can select the functional components that need to be enabled and set relevant parameters through simple operations.
By modifying parameters, you can quickly tailor the required functions. After the configuration is complete,
the Python script automatically generates the configuration file.
Directory structure
| name | describe |
|---|---|
| bsp | Board support package |
| components | Components |
| device | Device file |
| document | Document |
| driver | Driver file |
| include | Library header file |
| source | Library source file |
| Kconfig | Configuration files |
| kconfig.py | Automatic configuration script |
| LICENSE | Open-source license |
Get Started
Configure the Kconfig Environment
Note: Kconfig is not mandatory, but recommended (installation and configuration are very quick, and the following tutorials are based on applying Kconfig).
-
Verify that the system has a Python environment installed. Run
python --versionin the command line to check the Python version (Kconfig depends on python, please install python if it is not available). -
Use the following commands to install Kconfig in the command line:
python -m pip install windows-curses python -m pip install kconfiglib -
Run
menuconfig -hin the command line to verify successful installation.
Import the Framework into the Project
-
Download the latest version source code from the Gitee or Github repository to the local.
-
Import the source code into the directory where your project is located. Taking an STM32 project as an example:
-
If the used chip has BSP adaptation, please refer to the chip's corresponding BSP configuration tutorial to complete the BSP configuration.
-
Remove unnecessary files such as
bsp、document、moduledirectories (you can also remove the.gitfile to delete GIT if not needed). The directory structure is shown below after completion:
Configure Menu Options
-
Open the command line tool in the
mr-librarydirectory and runmenuconfigto configure the menu.Note: When the corresponding chip driver is added,
Device configureandDriver configurewill be displayed. Please refer to the tutorial underBSPforDriver configure. -
Enter the menu by pressing the Enter key on
Device configure, and configure the desired functions according to needs. -
After configuration is complete, press
Qto exit the menu configuration interface, pressYto save the configuration.
Generate Configuration File
- Run
python kconfig.pyin the command line tool undermr-librarydirectory to automatically generate the configuration filemr_config.h.
Add Include Paths
-
Add the include paths of
mr-libraryin the compiler, takingkeilas an example: -
Configure automatic initialization (GCC environment), find the link script file with suffix
.ldin your project directory (usuallylink.ld), and add the following code to the script file:/* mr-library auto init */ . = ALIGN(4); _mr_auto_init_start = .; KEEP(*(SORT(.auto_init*))) _mr_auto_init_end = .;Example:
-
Include
#include "include/mr_lib.h"in your project. -
Add the automatic initialization function
mr_auto_init();in the main function.
Let's Light an LED
#include "include/mr_lib.h"
/* Define the LED pin-number (PC13) */
#define LED_PIN_NUMBER 45
int main(void)
{
/* Automatic initialization */
mr_auto_init();
/* Open the PIN device */
int ds = mr_dev_open("pin", MR_OFLAG_RDWR);
/* Set to the LED pin */
mr_dev_ioctl(ds, MR_CTL_PIN_SET_NUMBER, mr_make_local(int, LED_PIN_NUMBER));
/* Set the LED pin to push-pull output mode */
mr_dev_ioctl(ds, MR_CTL_PIN_SET_MODE, mr_make_local(int, MR_PIN_MODE_OUTPUT));
while(1)
{
/* Light up the LED */
mr_dev_write(ds, mr_make_local(uint8_t, MR_PIN_HIGH_LEVEL), sizeof(uint8_t));
mr_delay_ms(500);
mr_dev_write(ds, mr_make_local(uint8_t, MR_PIN_LOW_LEVEL), sizeof(uint8_t));
mr_delay_ms(500);
}
}
Hello World
#include "include/mr_lib.h"
int main(void)
{
/* Automatic initialization */
mr_auto_init();
/* Open the Serial-1 device */
int ds = mr_dev_open("serial1", MR_OFLAG_RDWR);
/* Output Hello World */
mr_dev_write(ds, "Hello World\r\n", sizeof("Hello World\r\n"));
while(1);
}
Now that you have completed the introductory tutorial, start using the MR Library.
- See more tutorials: directory
document. - Try developing drivers based on certain chips to practice device driver programming.
- Try writing more device templates and developing more features.
- Welcome to provide your opinions and suggestions. If you are interested in development, you are welcome to
participate in the development of the
MRproject. The project discussion group is: 199915649(QQ).








