816 views|2 replies

37

Posts

0

Resources
The OP
 

[Jihai APM32F4xx Tiny] Study Notes 05-Transplanting RTT NANO Project [Copy link]

 

5. Transplant RTT NANO project

Transplantation steps:

  1. mdk adds rtt nano package file
  2. Add source code
  3. Mask 2 interrupt processing functions
  4. Modify the board.c file
  5. Add a console
  6. Add finsh component
  7. Writing test projects

1. mdk adds rtt nano package file

Download link : https://www.rt-thread.org/download/mdk/RealThread.RT-Thread.3.1.5.pack

rtt nano installation location

2. Add source code to the project

After adding

3. Shield 2 interrupt processing functions

void HardFault_Handler(void)

void PendSV_Handler(void)

Modify systick

3. Modify the board.c file

Modify 3 places in total

3.1 Add header files

//Add header file
#include "apm32f4xx.h"
#include "bsp_usart.h"

3.2 Modify rt_hw_board_init function

SystemInit(); // (1) System initialization
SystemCoreClockUpdate(); // (2) Initialize the system clock
SysTick_Config(SystemCoreClock/RT_TICK_PER_SECOND); //(3) Tick timer initialization

3.4 rttconfig.h File Description

/* RT-Thread config file */

#ifndef __RTTHREAD_CFG_H__
#define __RTTHREAD_CFG_H__

// <<< Use Configuration Wizard in Context Menu >>>

// RT_THREAD_PRIORITY_MAX This macro indicates how many priorities RT-Thread supports. The value range is 8~256, and the default is 32.
#define RT_THREAD_PRIORITY_MAX 32

//RT_TICK_PER_SECOND indicates how many ticks the operating system has per second. Tick is the clock cycle of the operating system. The default value is 1000
#define RT_TICK_PER_SECOND 1000

// Indicates how many bytes the data processed by the CPU needs to be aligned, the default is 4 bytes
#define RT_ALIGN_SIZE  4

// The maximum length of the kernel object name, the value range is 2~16, the default is 8.
#define RT_NAME_MAX  8

// Initialize using RT-Thread component, enabled by default
#define RT_USING_COMPONENTS_INIT

// Use the user main function, open by default
#define RT_USING_USER_MAIN

// The main thread stack size ranges from 1 to 4086 in bytes, and the default is 512.
#define RT_MAIN_THREAD_STACK_SIZE   256

// </h>

// Debug configuration
// <c1>enable kernel debug configuration
// <i>Default: enable kernel debug configuration
//#define RT_DEBUG
// </c>
// <o>enable components initialization debug configuration<0-1>
// <i>Default: 0
#define RT_DEBUG_INIT 0
// <c1>thread stack over flow detect
// <i> Diable Thread stack over flow detect
//#define RT_USING_OVERFLOW_CHECK
// </c>
// </h>

// Hook function configuration, all are currently closed.
// <c1>using hook
// <i>using hook
//#define RT_USING_HOOK
// </c>
// <c1>using idle hook
// <i>using idle hook
//#define RT_USING_IDLE_HOOK
// </c>
// </h>

// Software timer configuration, currently disabled, do not use software timer.
#define RT_USING_TIMER_SOFT     0
#if RT_USING_TIMER_SOFT == 0
  #undef RT_USING_TIMER_SOFT
#endif
// <o>The priority level of timer thread <0-31>
// <i>Default: 4
#define RT_TIMER_THREAD_PRIO    4
// <o>The stack size of timer thread <0-8192>
// <i>Default: 512
#define RT_TIMER_THREAD_STACK_SIZE 512
// </e>


// Internal communication configuration, including semaphores, mutexes, events, mailboxes, and message queues, configured as needed
#define RT_USING_SEMAPHORE
// Mutex
//#define RT_USING_MUTEX
// event
//#define RT_USING_EVENT
// Mail
#define RT_USING_MAILBOX
//Message queue
//#define RT_USING_MESSAGEQUEUE
// </c>
// </h>

//Memory management configuration.
// This macro is used to indicate whether to use the memory pool. Currently it is closed and the memory pool is not used.
//#define RT_USING_MEMPOOL

// To indicate whether the heap is used, currently closed, the heap is not used
/*
 This is selected by enabling or disabling the RT_USING_HEAP macro.
 Use static or dynamic memory. Whether using static or dynamic memory solution, the internal SRAM is used.
 The difference is whether the memory used is allocated when the program is compiled or when it is run.
*/
#define RT_USING_HEAP
#define RT_USING_SMALL_MEM
// </c>
// <c1>using tiny size of memory
// <i>using tiny size of memory
//#define RT_USING_TINY_SIZE
// </c>
// </h>

// Console configuration. The console is the device for debugging output of the rt_kprintf() function, usually using the serial port
#define RT_USING_CONSOLE
//Console cache size
#define RT_CONSOLEBUF_SIZE     256
// </h>

//FINSH shell configuration
#include "finsh_config.h"
// </c>
// </h>

// <h>Device Configuration
// <c1>using device framework
// <i>using device framework
//#define RT_USING_DEVICE
// </c>
// </h>

// <<< end of configuration section >>>

#endif


4. Add a console

4.1 Add serial port initialization function in uart_init

4.2. Add console output function

//(4) Add console output function
void rt_hw_console_output(const char *str)
{
 rt_size_t size =0;
 size = rt_strlen(str);
 for(int i=0;i<size;i++)
 {
  if(str=='\n')
  {
      /* send a byte of data to the serial port */
   USART_TxData(DEBUG_USART, (uint8_t)'\r');
   /* wait for the data to be send */
   while (USART_ReadStatusFlag(DEBUG_USART, USART_FLAG_TXBE) == RESET);
  }
   /* send a byte of data to the serial port */
  USART_TxData(DEBUG_USART, (uint8_t)str);
  /* wait for the data to be send */
  while (USART_ReadStatusFlag(DEBUG_USART, USART_FLAG_TXBE) == RESET);
 }
}

5. Add finsh component

Improve the function of serial port data acquisition in finsh_port.h

6. Write a test project

static rt_thread_t tid1 = RT_NULL;

/* Entry function of thread 1 */
static void thread1_entry(void *parameter)
{
  rt_uint32_t count = 0;

  while (1)
  {
    /* Thread 1 runs at a low priority and keeps printing the count value*/
    // rt_kprintf("thread1 count: %d\n", count ++);
    led_toggle(LED1);
    rt_thread_delay(1000);
    // led_toggle(LED0);
  }
}

#define THREAD_PRIORITY     25
#define THREAD_STACK_SIZE    512
#define THREAD_TIMESLICE    5

int main(void)
{
  led_init(LED0);
  led_init(LED1);

  /* Create thread 1, named thread1, entry is thread1_entry*/
  tid1 = rt_thread_create("thread1",
              thread1_entry, RT_NULL,
              THREAD_STACK_SIZE,
              THREAD_PRIORITY, THREAD_TIMESLICE);

  /* If you get the thread control block, start this thread */
  if (tid1 != RT_NULL)
    rt_thread_startup(tid1);

  init_key_btn();
  while (1)
  {
    rt_thread_mdelay(500);
    led_toggle(LED0);
    // rt_kprintf("hello\n") ;
    key_lib_buttons_process();

  }
}


Example output results:

LED0 500ms flashing interval LED1 1000ms flashing interval

The console outputs the RTT version welcome message, and shell interaction is possible

This post is from Domestic Chip Exchange
 
 

37

Posts

0

Resources
2
 

This post is from Domestic Chip Exchange
 
 
 

37

Posts

0

Resources
3
 

Reference CSDN: Content Management-CSDN Creation Center

Modify systick

 #include <rtthread.h>
void SysTick_Handler(void)
{
    void rt_os_tick_callback(void);
    rt_os_tick_callback();
}

4.1 Add serial port initialization function in uart_init

static int uart_init(void)
{
        bsp_uart1_init(115200);
    
  return 0;
}
This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list