nrf52810/nrf52811/nrf52820 freeertos移植

  • 先按照示例 ble_app_hrs_freertos 模板将所有文件加载到工程
  • 修改代码 port.c
  • 修改代码 port_cmsis.c
  • 修改代码 mian.c

nrf52810 nrf52811 等nordic系列的MCU没有FPU,不能直接使用nordic提供的freertos软件包,本文介绍了如何进行修改实现freertos在nrf52810/811上面运行的办法。

先按照示例 ble_app_hrs_freertos 模板将所有文件加载到工程

注意: 需要修改文件,建议从 nRF5_SDK_xxxxx\external\freertos 中将freertos的源码拷贝到工程目录中,然后添加工程目录中的源码。这样不修改SDK中的源码。

添加对应目录的源码路径到工程目录

如图: 需要移除 drv_rtc.c 和 app_timer2.c 文件,新增加 app_timer_freertos.c

修改代码 port.c

__asm void xPortPendSVHandler( void )
{extern uxCriticalNesting;extern pxCurrentTCB;extern vTaskSwitchContext;PRESERVE8mrs r0, pspisb/* Get the location of the current TCB. */ldr r3, =pxCurrentTCBldr r2, [r3]/* Is the task using the FPU context?  If so, push high vfp registers. */#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)tst r14, #0x10it eqvstmdbeq r0!, {s16-s31}#endif/* Save the core registers. */stmdb r0!, {r4-r11, r14}/* Save the new top of stack into the first member of the TCB. */str r0, [r2]stmdb sp!, {r3}mov r0, #(configMAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))msr basepri, r0dsbisbbl vTaskSwitchContextmov r0, #0msr basepri, r0ldmia sp!, {r3}/* The first item in pxCurrentTCB is the task top of stack. */ldr r1, [r3]ldr r0, [r1]/* Pop the core registers. */ldmia r0!, {r4-r11, r14}/* Is the task using the FPU context?  If so, pop the high vfp registerstoo. */#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)tst r14, #0x10it eqvldmiaeq r0!, {s16-s31}#endifmsr psp, r0isbbx r14ALIGN
}

修改代码 port_cmsis.c

修改为只是

FPU->FPCCR |= FPU_FPCCR_ASPEN_Msk | FPU_FPCCR_LSPEN_Msk;

更改为

    #if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)/* Lazy save always. */FPU->FPCCR |= FPU_FPCCR_ASPEN_Msk | FPU_FPCCR_LSPEN_Msk;#endif //#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)
BaseType_t xPortStartScheduler( void )
{/* configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html */configASSERT( configMAX_SYSCALL_INTERRUPT_PRIORITY );/* This port is designed for nRF52, this is Cortex-M4 r0p1. */configASSERT( SCB->CPUID == portCORTEX_M4_r0p1_ID );#if ( configASSERT_DEFINED == 1 ){volatile uint32_t ulOriginalPriority;volatile uint8_t * const pucFirstUserPriorityRegister = &NVIC->IP[0];volatile uint8_t ucMaxPriorityValue;/* Determine the maximum priority from which ISR safe FreeRTOS APIfunctions can be called.  ISR safe functions are those that end in"FromISR".  FreeRTOS maintains separate thread and ISR API functions toensure interrupt entry is as fast and simple as possible.Save the interrupt priority value that is about to be clobbered. */ulOriginalPriority = *pucFirstUserPriorityRegister;/* Determine the number of priority bits available.  First write to allpossible bits. */*pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE;/* Read the value back to see how many bits stuck. */ucMaxPriorityValue = *pucFirstUserPriorityRegister;/* Use the same mask on the maximum system call priority. */ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue;/* Calculate the maximum acceptable priority group value for the numberof bits read back. */ulMaxPRIGROUPValue = SCB_AIRCR_PRIGROUP_Msk >> SCB_AIRCR_PRIGROUP_Pos;while ( ( ucMaxPriorityValue & portTOP_BIT_OF_BYTE ) == portTOP_BIT_OF_BYTE ){ulMaxPRIGROUPValue--;ucMaxPriorityValue <<= ( uint8_t ) 0x01;}/* Remove any bits that are more than actually existing. */ulMaxPRIGROUPValue &= SCB_AIRCR_PRIGROUP_Msk >> SCB_AIRCR_PRIGROUP_Pos;/* Restore the clobbered interrupt priority register to its originalvalue. */*pucFirstUserPriorityRegister = ulOriginalPriority;}#endif /* conifgASSERT_DEFINED *//* Make PendSV the lowest priority interrupts. */NVIC_SetPriority(PendSV_IRQn, configKERNEL_INTERRUPT_PRIORITY);/* Start the timer that generates the tick ISR.  Interrupts are disabledhere already. */vPortSetupTimerInterrupt();/* Initialise the critical nesting count ready for the first task. */uxCriticalNesting = 0;/* Ensure the VFP is enabled - it should be anyway. */vPortEnableVFP();#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)/* Lazy save always. */FPU->FPCCR |= FPU_FPCCR_ASPEN_Msk | FPU_FPCCR_LSPEN_Msk;#endif //#if (__FPU_PRESENT == 1U) && (__FPU_USED == 1U)/* Finally this port requires SEVONPEND to be active */SCB->SCR |= SCB_SCR_SEVONPEND_Msk;/* Start the first task. */vPortStartFirstTask();/* Should never get here as the tasks will now be executing!  Call the taskexit error function to prevent compiler warnings about a static functionnot being called in the case that the application writer overrides thisfunctionality by defining configTASK_RETURN_ADDRESS. */prvTaskExitError();/* Should not get here! */return 0;
}

修改代码 mian.c


#include "FreeRTOS.h"
#include "list.h"
#include "task.h"
#include "timers.h"
#include "semphr.h"
#include "event_groups.h"#if NRF_LOG_ENABLED
static TaskHandle_t m_logger_thread;                                /**< Definition of Logger thread. *//**@brief Thread for handling the logger.** @details This thread is responsible for processing log entries if logs are deferred.*          Thread flushes all log entries and suspends. It is resumed by idle task hook.** @param[in]   arg   Pointer used for passing some arbitrary information (context) from the*                    osThreadCreate() call to the thread.*/
static void logger_thread(void * arg)
{UNUSED_PARAMETER(arg);while (1){NRF_LOG_FLUSH();vTaskSuspend(NULL); // Suspend myself}
}
#endif //NRF_LOG_ENABLED/**@brief A function which is hooked to idle task.* @note Idle hook must be enabled in FreeRTOS configuration (configUSE_IDLE_HOOK).*/
void vApplicationIdleHook( void )
{
#if NRF_LOG_ENABLEDvTaskResume(m_logger_thread);
#endif
}int main(void)
{ret_code_t err_code;log_init();/* Initialize clock driver for better time accuracy in FREERTOS */err_code = nrf_drv_clock_init();APP_ERROR_CHECK(err_code);//clock_initialization(); //clock_init();// Do not start any interrupt that uses system functions before system initialisation.// The best solution is to start the OS before any other initalisation.#if NRF_LOG_ENABLED// Start execution.if (pdPASS != xTaskCreate(logger_thread, "LOGGER", 256, NULL, 1, &m_logger_thread)){APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);}#endifNRF_LOG_INFO("nrf5281x freertos example");uint32_t heap_mem = xPortGetFreeHeapSize();NRF_LOG_INFO("Scheduler start[%dB/%d.%02dK]/[%dB/%d.%02dK].", heap_mem, heap_mem/1024, (heap_mem%1024)*100/1024, \configTOTAL_HEAP_SIZE, configTOTAL_HEAP_SIZE/1024, (configTOTAL_HEAP_SIZE%1024)*100/1024);// Start FreeRTOS scheduler.vTaskStartScheduler();for (;;){APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN);}
}

nrf52810/nrf52811/nrf52820 freeertos移植相关推荐

  1. NRF52840/NRF52832/NRF52810/NRF52811/NRF52805蓝牙5.0芯片对比

    目录 一.蓝牙5.0传输速度翻倍,距离4倍.8倍数据传输量领跑物联网连接标准 二.通信速度提高一倍意味着功耗减半 三.四倍通信距离意味着蓝牙将抢夺Wi-Fi在智能家居市场的份额 四.增加数据广播容量 ...

  2. Nordic蓝牙系列芯片对比 及nRF52832详细介绍

    自从蓝牙4.0中引入低功耗蓝牙以来,蓝牙5  是蓝牙标准中最重大的进步.它正在将Bluetooth LE提升到一个新的水平,并使全新的用例成为可能,并改善现有用例. 蓝牙5 有四个重要的新功能: (1 ...

  3. NORDIC蓝牙52系列芯片选型与参数对比-NRF52805,NRF52810,NRF52811,NRF52820,NRF52832,NRF52833,NRF52840

    NRF52805,NRF52810,NRF52811,NRF52820,NRF52832,NRF52833,NRF52840参数对比

  4. [单片机框架][bsp层][nrf52832][nrf52840][nrf52810][nrf52820][ESB(2.4G)] ESB(2.4G)使用说明

    这个指南描述了什么是ESB(Enhanced ShockBurst)以及如何在nRF5系列中使用ESB. ESB支持双向数据包通信,包括数据包缓冲,数据包确认和丢失数据包的自动重传的基本协议.ESB提 ...

  5. FreeRTOS 之一 源码目录文件 及 移植详解

    写在前面 2018/1/15更新了文章中的部分错误. FreeRTOS源码为最新版的10.0.1.FreeRTOS 10包含两个重要的新功能:流缓冲区和消息缓冲区. 从10.0.0开始,FreeRTO ...

  6. 首款Nordic蓝牙5.1室内定位SoC芯片nRF52811

    Nordic nRF52811 SoC继承Nordic nRF52系列平台的成功基础,可为采用先进无线物联网功能(如蓝牙5.1寻向以及Thread和ZigBee)的应用带来更丰富的连接性能. nRF5 ...

  7. PowerBuilder程序 ASA 数据库移植后不能连接解决

    前言: 软件开发工具实践课作业用的powerbuilder自带的数据库画板建立的,建好之后运行成功后就没有再管过了.后来代码在别人的机器跑不起来.报错信息如下 找到原因: 程序运行完后,没有手动断开连 ...

  8. web server大全之GoAhead移植(转载)

    转自:http://linux.chinaunix.net/techdoc/develop/2009/06/19/1119124.shtml 注:最近在做goAhead web server和移植其到 ...

  9. Tomcat V6 Examples移植到Apusic V5.1

    目标:将Tomcat V6的的例子Examples移植到Apusic V5.1上 术语:Tomcat:只提供了WEB容器的开源服务器: Apusic:提供了完整的J2EE支持的商用服务器: %TOMC ...

最新文章

  1. 深度:应用安全是信息安全防护的短板
  2. sqlserver2012不是有效的安装文件夹_SQL Server 2012软件安装说明
  3. DFTug - Architecture Your Test Design
  4. linux函数实验报告,linux实验报告
  5. 已知一个特殊字符的 unicode 编码值,如何在 ABAP 里打印出这个特殊字符?
  6. python中深拷贝和浅拷贝
  7. [深度学习] 自然语言处理 --- BERT模型原理
  8. 每天一道算法题(39)——含有重复字符的全排列
  9. display: inline-block;水平居中
  10. 程序员需要了解的硬核知识之操作系统和应用
  11. Java -- 新IO -- 目录
  12. Remote Desktop Connection Manager (RDCMan) 介绍
  13. C语言课程设计 雷克子波反射系数 相位移动等
  14. mysql bug frash_MySQL Flush导致的等待问题
  15. WINDOW -- 给硬盘分盘以及合盘
  16. 申请微信公众号,当前绑定的银行卡暂不支持实名验证...
  17. ggplot作图显示中文
  18. java文件批量改名代码_[原创]JAVA版批量更名程序(附源码)(要求加分)
  19. 2023,VC投资的分水岭
  20. 用matlab画黑底白条,计算机仿真F型结构电能表自动检测流水线_论文答辩PPT范例...

热门文章

  1. java JNI调用C++代码(给出一个简单java application示例和实际java web项目过程及错误解决)(一)
  2. 啥?以后找工作面试求职者的将不是人!那是啥?道翰天琼认知智能机器人平台API接口为您揭秘-1。
  3. Browserslist: caniuse-lite is outdated. Please run: npx update-browserslist-db@latest
  4. LeetCode521
  5. php 让百度蜘蛛抓取403,百度蜘蛛不抓取页面的解决方法
  6. 人生, 总有那么一瞬间
  7. ROS2GO之手机连接Cozmo人工智能机器人玩具
  8. RecyclerView实现多种item布局
  9. 某商标局公告抓取思路总结爬虫过无限debugger Js逆向调试
  10. 服务器结构中的1U 2U 3U是什么意思?