STM32WL LoRaWAN节点设备学习记录(一)

摸了几天开发板,感觉需要再系统学习一下。

以LoRaWAN_AT_Slave和LoRaWAN_End_Node两个工程为例进行学习。

an5406-how-to-build-a-lora-application-with-stm32cubewl-stmicroelectronics.pdf

an5481 LoRaWAN® AT commands for STM32CubeWL - Application note.pdf

en.MB1389-WL55JC-lowband-D04_Schematic.pdf

(1)硬件概要

一个供电

可选的双核--高安全需求场景

这个应该算软件特性

 

(2)sdk框架

分为driver、middleware、application(进一步分为Lorawan和phy),还有utilities--sequencer和timer。

还有utilities--sequencer和timer

 

 

The HAL uses STM32Cube APIs to drive the MCU hardware required by the application. Only specific hardware is included in the LoRa middleware as it is mandatory to run a LoRa application.


The RTC provides a centralized time unit that continues to run even in low-power mode (Stop 2 mode). The RTC alarm is used to wake up the system at specific timings managed by the timer server.


The SubGHz_Phy middleware uses the HAL SubGHz to control the radio (see the above figure). For more details, refer to Section 5


The MAC controls the SubGHz_Phy using the 802.15.4 model. The MAC interfaces with the SubGHz_Phy driver and uses the timer server to add or remove timed tasks. 

Since the state machine that controls the LoRa Class A is sensitive, an intermediate level of software is inserted (LmHandler.c) between the MAC and the application (refer to LoRaMAC driver in the above figure). With a limited set of APIs, the user is free to implement the Class A state machine at application level. For more details, refer to Section 6 .

The application, built around an infinite loop, manages the low-power mode, runs the interrupt handlers (alarm or GPIO) and calls the LoRa Class A if any task must be done.
 

(3)class A流程图

Once the radio has completed the application data transmission, an asynchronous RadioIRQ wakes up the system. The RadioIsr here calls txDone in the handler mode.
All RadioIsr and MAC timer call a LoRaMacProcessNotify callback to request the application layer to update the LoRaMAC state and to do further processing when needed.


For instance, at the end of the reception, rxDone is called in the ISR (handler), but all the Rx packet processing including decryption must not be processed in the ISR. This case is an example of call sequence. If no data is received into the Rx1 window, then another Rx2 window is launched..
 

(4)开发板BSP driver

替换的两种方式,我们用哪种?好像是第一种

 ST官方开发板,不知道debug lines 和sysclock有啥用?

关于FEctrl,我们模组实际只用2个pin,ctrl1--PB0,ctrl3--PA8

所以模块外部没后这两个pin,内部定义fectrl2-pa15,虽然没用。

 

关于bsp的tcxo和rf,dcdc,stm32wlxx_LM401_radio.c

 /**
  * @brief Radio maximum wakeup time (in ms)
  * @note override the default configuration of radio_driver.c
  */
#define RF_WAKEUP_TIME              ( 1UL )

 (5)SubGHz_Phy layer middlewareIt is not aware about hardware interface,,只是一个抽象层,不针对具体硬件。--内部是SX1262,就是semtech官方的驱动,不再描述

主要还是radio_s这个回调结构体和9个中断

  (6)LoRaWAN middleware--4大组件

The LoRa stack middleware is split into the following modules:
• LoRaMAC layer module (in Middlewares\Third_Party\LoRaWAN\Mac)
• LoRa utilities module (in Middlewares\Third_Party\LoRaWAN\Utilities)
• LoRa crypto module (in Middlewares\Third_Party\LoRaWAN\Crypto)
• LoRa LmHandler module (in Middlewares\Third_Party\LoRaWAN\LmHandler)

1)
The application layer和LoRaMAC layer之间采用request-confirm and  indication-response机制

 The LoRaMAC layer provides the following services:--被application主动调用
• MCPS services
In general, the LoRaMAC layer uses the MCPS services for data transmissions and data receptions.

• MLME services
The LoRaMAC layer uses the MLME services to manage the LoRaWAN network
• MIB services
The MIB stores important runtime information (such as MIB_NETWORK_ACTIVATION or MIB_NET_ID) and holds the configuration of the LoRaMAC layer (for example the MIB_ADR, MIB_APP_KEY).

The LoRaMAC user event functions primitives (also named callbacks) to be implemented by the application

--Response to a McpsRequest;

--Notifies the application that a received packet is available;

--MIB-No available functions.-MIB没有回调函数。,其它三个都有。

2)Middleware MAC layer timers-

3)Middleware LmHandler application function---这个重要lora_app.c就是实际业务文件。
 

LoRaWAN_End_Node and LoRaWAN_AT_Slave APIs used to access the LoRaMAC
services. The corresponding interface files are located in
Middlewares\Third_Party\LoRaWAN\LmHandler\LmHandler.c
The user must implement the application with these APIs.

(1)LmHandlerInit--Initialization of the LoRa finite state machine

(2)LmHandlerConfigure--Configuration of all applicative parameters

(3)LmHandlerStop--Stops the LoRa process and waits a new configuration before a
rejoin action.

(4)LmHandlerJoin--Join request to a network either in OTAA or ABP mode.

(5)LmHandlerRequestClass--Requests the MAC layer to change LoRaWAN class.

(6)LmHandlerSend--Sends an uplink frame. This frame can be either an unconfirmed empty frame or an unconfirmed/confirmed payload frame

callbacks---

 --OnMacProcessNotify--Will be called each time a Radio IRQ is handled by the MAC layer

--上面并不完整,可以根据需要再增加系统预定的函数。比如OnSysTimeUpdate等。

--还有很多--Getter/setter functions。

(7)sequencer

 to execute tasks in the background and enters low-power mode when there is no more activity. 

allowing any function to wait for an event (where particular event is set by interrupt)

 MIPS and power to be easily saved in any application that implements “run to
completion” command.

Any task is run to completion and can not switch to another task like a RTOS can do
on RTOS tick unless a task suspends itself by calling UTIL_SEQ_WaitEvt.--每个任务都会调用吗?如何交出权限

void UTIL_SEQ_Init( void )
{
  TaskSet = UTIL_SEQ_NO_BIT_SET;
  TaskMask = UTIL_SEQ_ALL_BIT_SET;
  SuperMask = UTIL_SEQ_ALL_BIT_SET;
  EvtSet = UTIL_SEQ_NO_BIT_SET;
  EvtWaited = UTIL_SEQ_NO_BIT_SET;
  CurrentTaskIdx = 0U;
  (void)UTIL_SEQ_MEMSET8(TaskCb, 0, sizeof(TaskCb));
  (void)UTIL_SEQ_MEMSET8(TaskPrio, 0, sizeof(TaskPrio));
  UTIL_SEQ_INIT_CRITICAL_SECTION( );
}

Moreover, one single-memory stack is used. The sequencer is an advanced ‘while loop’ centralizing task and event bitmap flag

/core/main.c

  while (1)
  {
    /* USER CODE END WHILE */
    MX_LoRaWAN_Process();--

    /* USER CODE BEGIN 3 */
  }

application/lorawan/app/app_lorawan.c

void MX_LoRaWAN_Process(void)
{
  /* USER CODE BEGIN MX_LoRaWAN_Process_1 */

  /* USER CODE END MX_LoRaWAN_Process_1 */
  UTIL_SEQ_Run(UTIL_SEQ_DEFAULT);
  /* USER CODE BEGIN MX_LoRaWAN_Process_2 */

  /* USER CODE END MX_LoRaWAN_Process_2 */
}

/core/sys_app.c

 void UTIL_SEQ_Idle( void )
{
LPM_EnterLowPower( );在这里
}

//AT命令串口中断

static void CmdProcessNotify(void)
{
  /* USER CODE BEGIN CmdProcessNotify_1 */

  /* USER CODE END CmdProcessNotify_1 */
  UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_Vcom), 0);
  /* USER CODE BEGIN CmdProcessNotify_2 */

  /* USER CODE END CmdProcessNotify_2 */
}

//LoraWAN中断

static void OnMacProcessNotify(void)
{
  /* USER CODE BEGIN OnMacProcessNotify_1 */

  /* USER CODE END OnMacProcessNotify_1 */
  UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LmHandlerProcess), CFG_SEQ_Prio_0);

  /* USER CODE BEGIN OnMacProcessNotify_2 */

  /* USER CODE END OnMacProcessNotify_2 */
}

//IO中断

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  switch (GPIO_Pin)
  {
    case  BUTTON_SW1_PIN:
      /* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */
      UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
      break;
    case  BUTTON_SW2_PIN:
      break;
    case  BUTTON_SW3_PIN:
      break;
    default:
      break;
  }
}

//定时中断

static void OnTxTimerEvent(void *context)
{
  /* USER CODE BEGIN OnTxTimerEvent_1 */

  /* USER CODE END OnTxTimerEvent_1 */
  UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);

  /*Wait for next tx slot*/
  UTIL_TIMER_Start(&TxTimer);
  /* USER CODE BEGIN OnTxTimerEvent_2 */

  /* USER CODE END OnTxTimerEvent_2 */
}

32个task,32个event都在sequence中处理,

task--不是while(1)无限循环,而是单循环,这个跟rtos的任务不同;

event--跟task没有必然关系,与task一样,一般跟中断有关系,中断到来既可UTIL_SEQ_SetTask()启动一次task,也可以UTIL_SEQ_SetEvt()提供一个evt。知道该谁干,就task,不知道谁来处理,就evt。

void OnTxDone(void)//OnRxDone OnTxTimeout OnRxTimeout  OnRxError
{
  /* Set TxDone flag */
  RadioTxDone_flag = 1;
  UTIL_SEQ_SetEvt(1 << CFG_SEQ_Evt_RadioOnTstRF);
}

void UTIL_SEQ_WaitEvt(UTIL_SEQ_bm_t EvtId_bm)//这个函数比较复杂
{

  中间考虑多个waitEvt,死循环的。

}

//好像只有下面2个地方用到,从字面看,主要是测试过程用到,先暂时放下

int32_t TST_TX_Start(int32_t nb_packet)

{       /* Send payload once*/
      Radio.Send(payload, testParam.payloadLen);
      /* Wait Tx done/timeout */
      UTIL_SEQ_WaitEvt(1 << CFG_SEQ_Evt_RadioOnTstRF);
      Radio.Sleep();

}


int32_t TST_RX_Start(int32_t nb_packet)

{      。。。

      Radio.Rx(RX_TIMEOUT_VALUE);

      /* Wait Rx done/timeout */
      UTIL_SEQ_WaitEvt(1 << CFG_SEQ_Evt_RadioOnTstRF);
      Radio.Sleep();

      。。。}

(8)Timer server

The timer server allows the user to request timed-tasks execution. As the hardware timer is based on the RTC,the time is always counted, even in low-power modes.

The timer server provides a reliable clock for the user and the stack. The user can request as many timers as the application requires.

--32个task,32个event,但是可以很多timers。

(9)Low-power functions

when the DMA is in use to print data to the console, the system must not enter a low-power mode below Sleep mode because the DMA clock is switched off in Stop mode

 

 Low-level APIs must be implemented to define what the system must do to enter/exit a low-power mode.----这个关键,stm32_lpm_if.c
 

(9)System time

(10)Trace

The trace module enables to print data on a COM port using DMA.
 

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值