Stm32-f0/f1/f2

Source: Internet
Author: User
Tags file copy

The resources used are:
A, St Company provides: stm32f10x Development standard library V3.5
B, experimental platform: Battleship Development Board V2.1
C, compiling software: MDK3.8
D, editing software: Source insight_v3.5
E, rtos:ucosii_v2.92
F, experimental phenomenon design: red light off each 800ms, green lights off each 300ms

First, access to the source code
This can be Baidu download, our forum is also a lot of source engineering, the official website can be downloaded here http://micrium.com/downloadcenter/micrium-source-code/
I'm porting version 2.92.


Second, access to ucosii source files
Unzip the downloaded compressed package, see the following file directory structure

Red box is the Ucosii source folder, double-click Open

Double-click the red box in the folder to see inside the content, there is no small excitement under it???

Yes, this is the location of ucosii source.

A, in the "Ports" folder is Ucos with the CPU to deal with the code "look at the folder English name will know."
B, in the "Source" folder is the core code of Ucos
C, as to os_cfg.h this file is what to do, double-click Open a look at the beginning of the instructions, oh ... The original is cut with, hehe, such as open what function, close what function with and so on, specific please look at the following comments

Third, the new test project

Here to build a new project, such as ucosii (self-established), I set up in the project three folders to store the ucosii code. According to their own preferences to build just fine, hehe

1, the above mentioned "Source" folder inside the file copy to the "core" folder inside, this file is Ucos core code, without modification.
2, the above mentioned "Ports" folder inside the file copy to the "Ports" folder inside, here is the core of the transplant
3, return to the previous level folder, the "os_cfg.h" This file copy to the "CONFIG" This folder, here also to add a file, this file is not in the "Ucos-ii" folder inside, specifically where???

Here "... \ucos\app\" this path, see no "includes.h" This file, copied to the "CONFIG" in this folder.


4, in MDK (of course, like to use other editors of the comrade is also possible) to add files, as shown, depending on personal preferences to establish the directory structure, I set up the "Ucosii_core", "Ucosii_ports", "Ucosii_config" These three folders hold the relevant code for Ucos.


Ha ha... The next step is the smooth and crooked link ...

Iv. Modifying the Code

1, the Earth people know, people have heartbeat, operating system is no exception, double-click to open the "os_cfg.h" this file, find "os_ticks_per_sec" This macro definition, the original is 1000 that is 1 seconds (see the following comments), here I change it to 200 is the beat of 5ms , as for the 5ms how to get, according to the code to come out


2, find "os_max_tasks" This macro definition, see this name to know what to do, yes, is the largest task number, here I define 5 that is up to 5 tasks, the specific number of their own weigh


3, here we close a part of the function of Ucos, such as Os_debug_en, Os_event_multi_en, os_event_name_en and so on, the specific function please see the definition of the following comments or the project code.

4, in front of the operating system's heartbeat, here can be provided in a variety of ways, in the CM3 there is a tick timer, this guy can provide, so here we use it to do operating system heartbeat. Modify the macro definition in this project sys.h _system_support_rots change its value to 1 "If you use the Atomic Brother's SYSTEM folder, change the System_support_ucos macro definition to 1."

5. Open "Os_cpu_a.asm" file, modify the relevant assembly

A, the first thing to see is the previous function entry code


Modified into this look, hehe

B, then pseudo-define register and related values


The specific register address and related values can be referenced in the CORTEX-M3 authoritative guide (Chinese). pdf content between page No. 284 to No. 286


C, then the following changes to look like



D, drag the file to the end, where the program is marked with a character to refer to the definition of the beginning of the file changes, specific reference code

6, open "os_cpu.h" file, here is mainly to modify the relevant data types, depending on the platform and modified, detailed file content see project.



7, open "Includes.h" This file, here is mainly a collection of the need for the header file, delete or comment some useless, increase the inside no but need to use. See the project document in detail.

A, find it, comment it all out, or delete it, because these libraries are useless here, but your project will be useful to keep it, V2.86 version seems to define these files



B, find here, modify this library header file



Five, main function edit


1, add the following in the main function, note that the higher the value of the priority is lower, 0 is the highest priority, so

/* Start Task Related Settings */

Task priority

#define Start_task_prio 10//Lowest priority

Task Stack size

#define START_STK_SIZE 64

Task Stack space size

OS_STK Start_task_stk[start_stk_size];

Task interface functions

void Start_task (void *pdata);

/* LED0 Task 0 */

Task priority

#define Led0_task_prio 7//Lowest priority

Task Stack size

#define LED0_STK_SIZE 64

Task Stack space size

OS_STK Led0_task_stk[led0_stk_size];

Task interface functions

void Led0_task (void *pdata);

/* LED1 Task 1 */

Task priority

#define Led1_task_prio 6//Lowest priority

Task Stack size

#define LED1_STK_SIZE 64

Task Stack space size

OS_STK Led1_task_stk[led1_stk_size];

Task interface functions

void Led1_task (void *pdata);

The main above is to set the stack size of the task and the priority of the interrupt


2. Create a task

int main (void)

{

Os_heart_init (); Initialize Ucos Heartbeat

My_nvic_prioritygroup_config (nvic_prioritygroup_2); Initialize Interrupt Priority

Usart1_init (9600);

Led_init (); Initializing the LED hardware interface

printf ("\ r \ n System init ok! Enter os...\r\n ");

Osinit (); Initialize Ucos

Ostaskcreate (Start_task, (void *) 0, (OS_STK *) &start_task_stk[start_stk_size-1], Start_task_prio); Create a start task

Osstart (); Ucos start

}

/******************************************************************************

* Function Name--Start task

* Description---none

* Input-to *pdata: task pointer

* Output--None

* Reaturn---none

******************************************************************************/

void Start_task (void * pdata)

{

OS_CPU_SR cpu_sr=0;

pdata = pdata;

Os_enter_critical (); Enter the critical section and cannot be interrupted

printf ("\ r \ n start task\r\n");

Ostaskcreate (Led0_task, (void *) 0, (OS_STK *) &led0_task_stk[led0_stk_size-1], Led0_task_prio);

Ostaskcreate (Led1_task, (void *) 0, (OS_STK *) &led1_task_stk[led1_stk_size-1], Led1_task_prio);

Ostasksuspend (Start_task_prio); Suspend start Task

Os_exit_critical (); Exits critical section, can be interrupted interrupted

}

/******************************************************************************

* Function Name--Task 0

* Description---none

* Input-to *pdata: task pointer

* Output--None

* Reaturn---none

******************************************************************************/

void Led0_task (void * pdata)

{

while (1)

{

LED0 = 0;

Delay_ms (800);

LED0 = 1;

Delay_ms (800);

};

}

/******************************************************************************

* Function Name--Task 1

* Description---none

* Input-to *pdata: task pointer

* Output--None

* Reaturn---none

******************************************************************************/

void Led1_task (void * pdata)

{

while (1)

{

LED1 = 0;

Delay_ms (300);

LED1 = 1;

Delay_ms (300);

};

}


Vi. compiling and modifying errors

When the above work is ready, compile and change the error. Until there are no errors and warnings, done, haha ... Download to the board, see two lights are flashing constantly. One flash a little faster, a little slower.



Summarize:

1, ucosii This operating system is still relatively simple to transplant, is mainly the porting of this assembly file, corresponding to different platforms with the corresponding platform code.
2, if you do not bother to modify what, the officer network download the corresponding test project is also possible
3, can be cut, this function is very good, according to different tasks and needs to cut their own needs can be
4, small caught dead, master MO offense
5, the attachment is the Warship Development Board test project, hoped can help the novice
6, also welcome you master, big God shoot brick guidance, we learn and common progress




Attachment 1:ucosii porting STM32 notes. pdf (File size: 613 KB downloaded: 2,123 times)


Attachment 2:ucosii (Battleship Development Board). zip (file size: 791 KB downloaded: 1941 times)

Stm32-f0/f1/f2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.