主頁 >  其他 > NRF52833學習筆記(2)——雙UART串口使用

NRF52833學習筆記(2)——雙UART串口使用

2020-12-18 12:47:55 其他

一、簡介

UARTE 是帶有 EasyDMA 的通用異步接收器/發送器 UART,提供快速、全雙工、異步的串口通信,內置流量控制(CTS,RTS)支持硬體,速率高達 1 Mbps,

以下是 UARTE 的主要功能:

  • 全雙工操作
  • 自動硬體流控制
  • 生成9位資料帶奇偶校驗
  • EasyDMA
  • 波特率高達 1 Mbps
  • 在支持的事務之間回傳 IDLE(使用HW流控制時)
  • 一個停止位
  • 最低有效位(LSB)優先

用于每個 UART 介面的 GPIO 可以從設備上的任何 GPIO 來選擇并且獨立地為可配置的,這使得能夠在器件的引腳和有效地利用電路板空間和信號路有很大的靈活性,

二、硬體連接

功能引腳描述
UART0_TXD6串口0發送端
UART0_RXD8串口0接收端
UART1_TXD5串口1發送端
UART1_RXD7串口1接收端

三、修改檔案

3.1 app_uart.h

app_uart.h 位于 SDK\components\libraries\uart,將原檔案備份,將以下內容替換到原檔案

/**
 * Copyright (c) 2013 - 2020, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/**@file
 *
 * @defgroup app_uart UART module
 * @{
 * @ingroup app_common
 *
 * @brief UART module interface.
 */

#ifndef APP_UART_H__
#define APP_UART_H__

#include <stdint.h>
#include <stdbool.h>
#include "app_util_platform.h"
#include "nrf_drv_uart.h"
#include "app_fifo.h"


#ifdef __cplusplus
extern "C" {
#endif

#define  UART_PIN_DISCONNECTED 0xFFFFFFFF /**< Value indicating that no pin is connected to this UART register. */

/**@brief UART Flow Control modes for the peripheral.
 */
typedef enum
{
    APP_UART_FLOW_CONTROL_DISABLED, /**< UART Hw Flow Control is disabled. */
    APP_UART_FLOW_CONTROL_ENABLED,  /**< Standard UART Hw Flow Control is enabled. */
} app_uart_flow_control_t;

/**@brief UART communication structure holding configuration settings for the peripheral.
 */
typedef struct
{
    uint32_t                rx_pin_no;    /**< RX pin number. */
    uint32_t                tx_pin_no;    /**< TX pin number. */
    uint32_t                rts_pin_no;   /**< RTS pin number, only used if flow control is enabled. */
    uint32_t                cts_pin_no;   /**< CTS pin number, only used if flow control is enabled. */
    app_uart_flow_control_t flow_control; /**< Flow control setting, if flow control is used, the system will use low power UART mode, based on CTS signal. */
    bool                    use_parity;   /**< Even parity if TRUE, no parity if FALSE. */
    uint32_t                baud_rate;    /**< Baud rate configuration. */
} app_uart_comm_params_t;

/**@brief UART buffer for transmitting/receiving data.
 */
typedef struct
{
    uint8_t * rx_buf;      /**< Pointer to the RX buffer. */
    uint32_t  rx_buf_size; /**< Size of the RX buffer. */
    uint8_t * tx_buf;      /**< Pointer to the TX buffer. */
    uint32_t  tx_buf_size; /**< Size of the TX buffer. */
} app_uart_buffers_t;

/**@brief Enumeration which defines events used by the UART module upon data reception or error.
 *
 * @details The event type is used to indicate the type of additional information in the event
 * @ref app_uart_evt_t.
 */
typedef enum
{
    APP_UART_DATA_READY,          /**< An event indicating that UART data has been received. The data is available in the FIFO and can be fetched using @ref app_uart_get. */
    APP_UART_FIFO_ERROR,          /**< An error in the FIFO module used by the app_uart module has occured. The FIFO error code is stored in app_uart_evt_t.data.error_code field. */
    APP_UART_COMMUNICATION_ERROR, /**< An communication error has occured during reception. The error is stored in app_uart_evt_t.data.error_communication field. */
    APP_UART_TX_EMPTY,            /**< An event indicating that UART has completed transmission of all available data in the TX FIFO. */
    APP_UART_DATA,                /**< An event indicating that UART data has been received, and data is present in data field. This event is only used when no FIFO is configured. */
} app_uart_evt_type_t;

/**@brief Struct containing events from the UART module.
 *
 * @details The app_uart_evt_t is used to notify the application of asynchronous events when data
 * are received on the UART peripheral or in case an error occured during data reception.
 */
typedef struct
{
    app_uart_evt_type_t evt_type; /**< Type of event. */
    union
    {
        uint32_t error_communication; /**< Field used if evt_type is: APP_UART_COMMUNICATION_ERROR. This field contains the value in the ERRORSRC register for the UART peripheral. The UART_ERRORSRC_x defines from nrf5x_bitfields.h can be used to parse the error code. See also the \nRFXX Series Reference Manual for specification. */
        uint32_t error_code;          /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */
        uint8_t  value;               /**< Field used if evt_type is: NRF_ERROR_x. Additional status/error code if the error event type is APP_UART_FIFO_ERROR. This error code refer to errors defined in nrf_error.h. */
    } data;
} app_uart_evt_t;

/**@brief Function for handling app_uart event callback.
 *
 * @details Upon an event in the app_uart module this callback function will be called to notify
 *          the application about the event.
 *
 * @param[in]   p_app_uart_event Pointer to UART event.
 */
typedef void (* app_uart_event_handler_t) (app_uart_evt_t * p_app_uart_event);

struct nrf_uart_obj{
	nrf_drv_uart_t		instance;
	bool rx_done;
	bool rx_ovf;
	app_uart_event_handler_t   event_handler;
	uint8_t tx_buffer[1];
	uint8_t rx_buffer[1];
	app_fifo_t rx_fifo;    /**< RX FIFO buffer for storing data received on the UART until the application fetches them using app_uart_get(). */
	app_fifo_t tx_fifo;/**< TX FIFO buffer for storing data to be transmitted on the UART when TXD is ready. Data is put to the buffer on using app_uart_put(). */
	app_uart_comm_params_t const* comm_params;
};
typedef struct nrf_uart_obj nrf_uart_obj_t;

#define APP_UART_DEF(_name, _instance, _buf_size, _event_handler)	\
	static uint8_t	   _name##_rx_buf[_buf_size]; \
	static uint8_t	   _name##_tx_buf[_buf_size]; \
	static app_uart_buffers_t _name##_buffers = { \
		.rx_buf      = _name##_rx_buf,                     \
        .rx_buf_size = sizeof (_name##_rx_buf),            \
        .tx_buf      = _name##_tx_buf,                     \
        .tx_buf_size = sizeof (_name##_tx_buf),  \
	};  \
	nrf_uart_obj_t _name = {\
		.instance = NRF_DRV_UART_INSTANCE(_instance),\
		.rx_done = false,\
		.rx_ovf = false,\
		.event_handler = _event_handler,\
	}

/**@brief Macro for safe initialization of the UART module in a single user instance when using
 *        a FIFO together with UART.
 *
 * @param[in]   P_COMM_PARAMS   Pointer to a UART communication structure: app_uart_comm_params_t
 * @param[in]   RX_BUF_SIZE     Size of desired RX buffer, must be a power of 2 or ZERO (No FIFO).
 * @param[in]   TX_BUF_SIZE     Size of desired TX buffer, must be a power of 2 or ZERO (No FIFO).
 * @param[in]   EVT_HANDLER   Event handler function to be called when an event occurs in the
 *                              UART module.
 * @param[in]   IRQ_PRIO        IRQ priority, app_irq_priority_t, for the UART module irq handler.
 * @param[out]  ERR_CODE        The return value of the UART initialization function will be
 *                              written to this parameter.
 *
 * @note Since this macro allocates a buffer and registers the module as a GPIOTE user when flow
 *       control is enabled, it must only be called once.
 */
#define APP_UART_FIFO_INIT(P_COMM_PARAMS, RX_BUF_SIZE, TX_BUF_SIZE, EVT_HANDLER, IRQ_PRIO, ERR_CODE) \
    do                                                                                             \
    {                                                                                              \
        app_uart_buffers_t buffers;                                                                \
        static uint8_t     rx_buf[RX_BUF_SIZE];                                                    \
        static uint8_t     tx_buf[TX_BUF_SIZE];                                                    \
                                                                                                   \
        buffers.rx_buf      = rx_buf;                                                              \
        buffers.rx_buf_size = sizeof (rx_buf);                                                     \
        buffers.tx_buf      = tx_buf;                                                              \
        buffers.tx_buf_size = sizeof (tx_buf);                                                     \
        ERR_CODE = app_uart_init(P_COMM_PARAMS, &buffers, EVT_HANDLER, IRQ_PRIO);                  \
    } while (0)

/**@brief Macro for safe initialization of the UART module in a single user instance.
 *
 * @param[in]   P_COMM_PARAMS   Pointer to a UART communication structure: app_uart_comm_params_t
 * @param[in]   EVT_HANDLER   Event handler function to be called when an event occurs in the
 *                              UART module.
 * @param[in]   IRQ_PRIO        IRQ priority, app_irq_priority_t, for the UART module irq handler.
 * @param[out]  ERR_CODE        The return value of the UART initialization function will be
 *                              written to this parameter.
 *
 * @note Since this macro allocates registers the module as a GPIOTE user when flow control is
 *       enabled, it must only be called once.
 */
#define APP_UART_INIT(P_COMM_PARAMS, EVT_HANDLER, IRQ_PRIO, ERR_CODE)                              \
    do                                                                                             \
    {                                                                                              \
        ERR_CODE = app_uart_init(P_COMM_PARAMS, NULL, EVT_HANDLER, IRQ_PRIO);                      \
    } while (0)

/**@brief Function for initializing the UART module. Use this initialization when several instances of the UART
 *        module are needed.
 *
 *
 * @note Normally single initialization should be done using the APP_UART_INIT() or
 *       APP_UART_INIT_FIFO() macro depending on whether the FIFO should be used by the UART, as
 *       that will allocate the buffers needed by the UART module (including aligning the buffer
 *       correctly).

 * @param[in]     p_comm_params     Pin and communication parameters.
 * @param[in]     p_buffers         RX and TX buffers, NULL is FIFO is not used.
 * @param[in]     error_handler     Function to be called in case of an error.
 * @param[in]     irq_priority      Interrupt priority level.
 *
 * @retval      NRF_SUCCESS               If successful initialization.
 * @retval      NRF_ERROR_INVALID_LENGTH  If a provided buffer is not a power of two.
 * @retval      NRF_ERROR_NULL            If one of the provided buffers is a NULL pointer.
 *
 * The below errors are propagated by the UART module to the caller upon registration when Hardware
 * Flow Control is enabled. When Hardware Flow Control is not used, these errors cannot occur.
 * @retval      NRF_ERROR_INVALID_STATE   The GPIOTE module is not in a valid state when registering
 *                                        the UART module as a user.
 * @retval      NRF_ERROR_INVALID_PARAM   The UART module provides an invalid callback function when
 *                                        registering the UART module as a user.
 *                                        Or the value pointed to by *p_uart_uid is not a valid
 *                                        GPIOTE number.
 * @retval      NRF_ERROR_NO_MEM          GPIOTE module has reached the maximum number of users.
 */
uint32_t app_uart_init(nrf_uart_obj_t * uart_obj,
                             app_uart_buffers_t *     p_buffers,
                             app_irq_priority_t       irq_priority);

/**@brief Function for getting a byte from the UART.
 *
 * @details This function will get the next byte from the RX buffer. If the RX buffer is empty
 *          an error code will be returned and the app_uart module will generate an event upon
 *          reception of the first byte which is added to the RX buffer.
 *
 * @param[out] p_byte    Pointer to an address where next byte received on the UART will be copied.
 *
 * @retval NRF_SUCCESS          If a byte has been received and pushed to the pointer provided.
 * @retval NRF_ERROR_NOT_FOUND  If no byte is available in the RX buffer of the app_uart module.
 */
uint32_t app_uart_get(nrf_uart_obj_t * uart_obj, uint8_t * p_byte);

/**@brief Function for putting a byte on the UART.
 *
 * @details This call is non-blocking.
 *
 * @param[in] byte   Byte to be transmitted on the UART.
 *
 * @retval NRF_SUCCESS        If the byte was successfully put on the TX buffer for transmission.
 * @retval NRF_ERROR_NO_MEM   If no more space is available in the TX buffer.
 *                            NRF_ERROR_NO_MEM may occur if flow control is enabled and CTS signal
 *                            is high for a long period and the buffer fills up.
 * @retval NRF_ERROR_INTERNAL If UART driver reported error.
 */
uint32_t app_uart_put(nrf_uart_obj_t * uart_obj, uint8_t byte);

/**@brief Function for flushing the RX and TX buffers (Only valid if FIFO is used).
 *        This function does nothing if FIFO is not used.
 *
 * @retval  NRF_SUCCESS  Flushing completed (Current implementation will always succeed).
 */
uint32_t app_uart_flush(nrf_uart_obj_t * uart_obj);

/**@brief Function for closing the UART module.
 *
 * @retval  NRF_SUCCESS             If successfully closed.
 * @retval  NRF_ERROR_INVALID_PARAM If an invalid user id is provided or the user id differs from
 *                                  the current active user.
 */
uint32_t app_uart_close(nrf_uart_obj_t * uart_obj);


#ifdef __cplusplus
}
#endif

#endif //APP_UART_H__

/** @} */

3.2 app_uart_fifo.c

app_uart_fifo.c 位于 SDK\components\libraries\uart,將原檔案備份,將以下內容替換到原檔案

/**
 * Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
#include "sdk_common.h"
#if NRF_MODULE_ENABLED(APP_UART)
#include "app_uart.h"

#include "nrf_drv_uart.h"
#include "nrf_assert.h"

//static nrf_drv_uart_t app_uart_inst = NRF_DRV_UART_INSTANCE(APP_UART_DRIVER_INSTANCE);

static __INLINE uint32_t fifo_length(app_fifo_t * const fifo)
{
  uint32_t tmp = fifo->read_pos;
  return fifo->write_pos - tmp;
}

#define FIFO_LENGTH(F) fifo_length(&F)              /**< Macro to calculate length of a FIFO. */


//static app_uart_event_handler_t   m_event_handler;            /**< Event handler function. */
//static uint8_t tx_buffer[1];
//static uint8_t rx_buffer[1];
//static bool m_rx_ovf;

//static app_fifo_t                  m_rx_fifo;                               /**< RX FIFO buffer for storing data received on the UART until the application fetches them using app_uart_get(). */
//static app_fifo_t                  m_tx_fifo;                               /**< TX FIFO buffer for storing data to be transmitted on the UART when TXD is ready. Data is put to the buffer on using app_uart_put(). */

static void uart_event_handler(nrf_drv_uart_event_t * p_event, void* p_context)
{
    app_uart_evt_t app_uart_event;
    uint32_t err_code;

    nrf_uart_obj_t * uart_obj = (nrf_uart_obj_t *)p_context;

    switch (p_event->type)
    {
        case NRF_DRV_UART_EVT_RX_DONE:
            // If 0, then this is a RXTO event with no new bytes.
            if(p_event->data.rxtx.bytes == 0)
            {
               // A new start RX is needed to continue to receive data
               (void)nrf_drv_uart_rx(&uart_obj->instance, uart_obj->rx_buffer, 1);
               break;
            }

            // Write received byte to FIFO.
            err_code = app_fifo_put(&uart_obj->rx_fifo, p_event->data.rxtx.p_data[0]);
            if (err_code != NRF_SUCCESS)
            {
                app_uart_event.evt_type          = APP_UART_FIFO_ERROR;
                app_uart_event.data.error_code   = err_code;
                uart_obj->event_handler(&app_uart_event);
            }
            // Notify that there are data available.
            else if (FIFO_LENGTH(uart_obj->rx_fifo) != 0)
            {
                app_uart_event.evt_type = APP_UART_DATA_READY;
                uart_obj->event_handler(&app_uart_event);
            }

            // Start new RX if size in buffer.
            if (FIFO_LENGTH(uart_obj->rx_fifo) <= uart_obj->rx_fifo.buf_size_mask)
            {
                (void)nrf_drv_uart_rx(&uart_obj->instance, uart_obj->rx_buffer, 1);
            }
            else
            {
                // Overflow in RX FIFO.
                uart_obj->rx_ovf = true;
            }

            break;

        case NRF_DRV_UART_EVT_ERROR:
            app_uart_event.evt_type                 = APP_UART_COMMUNICATION_ERROR;
            app_uart_event.data.error_communication = p_event->data.error.error_mask;
            (void)nrf_drv_uart_rx(&uart_obj->instance, uart_obj->rx_buffer, 1);
            uart_obj->event_handler(&app_uart_event);
            break;

        case NRF_DRV_UART_EVT_TX_DONE:
            // Get next byte from FIFO.
            if (app_fifo_get(&uart_obj->tx_fifo, uart_obj->tx_buffer) == NRF_SUCCESS)
            {
                (void)nrf_drv_uart_tx(&uart_obj->instance, uart_obj->tx_buffer, 1);
            }
            else
            {
                // Last byte from FIFO transmitted, notify the application.
                app_uart_event.evt_type = APP_UART_TX_EMPTY;
                uart_obj->event_handler(&app_uart_event);
            }
            break;

        default:
            break;
    }
}


uint32_t app_uart_init(nrf_uart_obj_t * uart_obj,
                             app_uart_buffers_t *     p_buffers,
                             app_irq_priority_t       irq_priority)
{
    uint32_t err_code;

//    m_event_handler = event_handler;

    if (p_buffers == NULL)
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    // Configure buffer RX buffer.
    err_code = app_fifo_init(&uart_obj->rx_fifo, p_buffers->rx_buf, p_buffers->rx_buf_size);
    VERIFY_SUCCESS(err_code);

    // Configure buffer TX buffer.
    err_code = app_fifo_init(&uart_obj->tx_fifo, p_buffers->tx_buf, p_buffers->tx_buf_size);
    VERIFY_SUCCESS(err_code);

    nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
    config.baudrate = (nrf_uart_baudrate_t)uart_obj->comm_params->baud_rate;
    config.hwfc = (uart_obj->comm_params->flow_control == APP_UART_FLOW_CONTROL_DISABLED) ?
            NRF_UART_HWFC_DISABLED : NRF_UART_HWFC_ENABLED;
    config.interrupt_priority = irq_priority;
    config.parity = uart_obj->comm_params->use_parity ? NRF_UART_PARITY_INCLUDED : NRF_UART_PARITY_EXCLUDED;
    config.pselcts = uart_obj->comm_params->cts_pin_no;
    config.pselrts = uart_obj->comm_params->rts_pin_no;
    config.pselrxd = uart_obj->comm_params->rx_pin_no;
    config.pseltxd = uart_obj->comm_params->tx_pin_no;
    config.p_context = uart_obj;

    err_code = nrf_drv_uart_init(&uart_obj->instance, &config, uart_event_handler);
    VERIFY_SUCCESS(err_code);
    uart_obj->rx_ovf = false; 

    // Turn on receiver if RX pin is connected
    if (uart_obj->comm_params->rx_pin_no != UART_PIN_DISCONNECTED)
    {
        return nrf_drv_uart_rx(&uart_obj->instance, uart_obj->rx_buffer,1);
    }
    else
    {
        return NRF_SUCCESS;
    }
}


uint32_t app_uart_flush(nrf_uart_obj_t * uart_obj)
{
    uint32_t err_code;

    err_code = app_fifo_flush(&uart_obj->rx_fifo);
    VERIFY_SUCCESS(err_code);

    err_code = app_fifo_flush(&uart_obj->tx_fifo);
    VERIFY_SUCCESS(err_code);

    return NRF_SUCCESS;
}


uint32_t app_uart_get(nrf_uart_obj_t * uart_obj, uint8_t * p_byte)
{
    ASSERT(p_byte);
    bool rx_ovf = uart_obj->rx_ovf;

    ret_code_t err_code =  app_fifo_get(&uart_obj->rx_fifo, p_byte);

    // If FIFO was full new request to receive one byte was not scheduled. Must be done here.
    if (rx_ovf)
    {
        uart_obj->rx_ovf = false;
        uint32_t uart_err_code = nrf_drv_uart_rx(&uart_obj->instance, uart_obj->rx_buffer, 1);

        // RX resume should never fail.
        APP_ERROR_CHECK(uart_err_code);
    }

    return err_code;
}


uint32_t app_uart_put(nrf_uart_obj_t * uart_obj, uint8_t byte)
{
    uint32_t err_code;
    err_code = app_fifo_put(&uart_obj->tx_fifo, byte);
    if (err_code == NRF_SUCCESS)
    {
        // The new byte has been added to FIFO. It will be picked up from there
        // (in 'uart_event_handler') when all preceding bytes are transmitted.
        // But if UART is not transmitting anything at the moment, we must start
        // a new transmission here.
        if (!nrf_drv_uart_tx_in_progress(&uart_obj->instance))
        {
            // This operation should be almost always successful, since we've
            // just added a byte to FIFO, but if some bigger delay occurred
            // (some heavy interrupt handler routine has been executed) since
            // that time, FIFO might be empty already.
            if (app_fifo_get(&uart_obj->tx_fifo, uart_obj->tx_buffer) == NRF_SUCCESS)
            {
                err_code = nrf_drv_uart_tx(&uart_obj->instance, uart_obj->tx_buffer, 1);
            }
        }
    }
    return err_code;
}


uint32_t app_uart_close(nrf_uart_obj_t * uart_obj)
{
    nrf_drv_uart_uninit(&uart_obj->instance);
    return NRF_SUCCESS;
}

#endif //NRF_MODULE_ENABLED(APP_UART)

3.3 retarget.c

retarget.c 位于 SDK\components\libraries\uart,將原檔案備份,將以下內容替換到原檔案

/**
 * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
#include "sdk_common.h"
/** @file
 *
 * @defgroup retarget Retarget layer for stdio functions
 * @{
 * @ingroup app_common
 * @} */
#if NRF_MODULE_ENABLED(RETARGET)
#if !defined(NRF_LOG_USES_RTT) || NRF_LOG_USES_RTT != 1
#if !defined(HAS_SIMPLE_UART_RETARGET)


#include <stdio.h>
#include <stdint.h>
#include "app_uart.h"
#include "nrf_error.h"


#if defined(__CC_ARM)

// This part is taken from MDK-ARM template file and is required here to prevent
// linker from selecting libraries functions that use semihosting and failing
// because of multiple definitions of fgetc() and fputc().
// Refer to: http://www.keil.com/support/man/docs/gsac/gsac_retargetcortex.htm
// -- BEGIN --
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
// --- END ---

extern uint32_t _app_uart_get(uint8_t * p_byte);
extern uint32_t _app_uart_put(uint8_t byte);

int fgetc(FILE * p_file)
{
    uint8_t input;
    while (_app_uart_get(&input) == NRF_ERROR_NOT_FOUND)
    {
        // No implementation needed.
    }
    return input;
}

int fputc(int ch, FILE * p_file)
{
    UNUSED_PARAMETER(p_file);

    UNUSED_VARIABLE(_app_uart_put((uint8_t)ch));
    return ch;
}

#elif defined(__GNUC__) && defined(__SES_ARM)

int __getchar(FILE * p_file)
{
    uint8_t input;
    while (app_uart_get(&input) == NRF_ERROR_NOT_FOUND)
    {
        // No implementation needed.
    }
    return input;
}

#if defined(__SES_VERSION) && (__SES_VERSION >= 34000)
int __putchar(int ch, __printf_tag_ptr tag_ptr)
{
    UNUSED_PARAMETER(tag_ptr);

    UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
    return ch;
}
#else
int __putchar(int ch, FILE * p_file)
{
    UNUSED_PARAMETER(p_file);

    UNUSED_VARIABLE(app_uart_put((uint8_t)ch));
    return ch;
}
#endif

#elif defined(__GNUC__) && !defined(__SES_ARM)

int _write(int file, const char * p_char, int len)
{
    int i;

    UNUSED_PARAMETER(file);

    for (i = 0; i < len; i++)
    {
        UNUSED_VARIABLE(app_uart_put(*p_char++));
    }

    return len;
}

int _read(int file, char * p_char, int len)
{
    UNUSED_PARAMETER(file);
    while (app_uart_get((uint8_t *)p_char) == NRF_ERROR_NOT_FOUND)
    {
        // No implementation needed.
    }

    return 1;
}
#elif defined(__ICCARM__)

size_t __write(int handle, const unsigned char * buffer, size_t size)
{
    int i;
    UNUSED_PARAMETER(handle);
    for (i = 0; i < size; i++)
    {
        UNUSED_VARIABLE(app_uart_put(*buffer++));
    }
    return size;
}

size_t __read(int handle, unsigned char * buffer, size_t size)
{
    UNUSED_PARAMETER(handle);
    UNUSED_PARAMETER(size);
    while (app_uart_get((uint8_t *)buffer) == NRF_ERROR_NOT_FOUND)
    {
        // No implementation needed.
    }

    return 1;
}

long __lseek(int handle, long offset, int whence)
{
    return -1;
}
int __close(int handle)
{
    return 0;
}
int remove(const char * filename)
{
    return 0;
}

#endif

#endif // !defined(HAS_SIMPLE_UART_RETARGET)
#endif // NRF_LOG_USES_RTT != 1
#endif //NRF_MODULE_ENABLED(RETARGET)

四、移植檔案

鏈接:https://pan.baidu.com/s/1eyT7_gK1MBkvk9PNVT_u3g 提取碼:h664
board_uart.cboard_uart.h 兩個檔案加入工程的Application檔案夾下

4.1 board_uart.c

/*********************************************************************
 * INCLUDES
 */
#include "nrf_uart.h"
#include "app_uart.h"
#include "nrf_log.h"

#include "board_uart.h"

static void uart0_handleEvent(app_uart_evt_t *pEvent);
static void uart1_handleEvent(app_uart_evt_t *pEvent);

/*********************************************************************
 * GLOBAL VARIABLES
 */

/*********************************************************************
 * LOCAL VARIABLES
 */
APP_UART_DEF(uart0, 0, UART_RX_BUF_SIZE, uart0_handleEvent);
APP_UART_DEF(uart1, 1, UART_RX_BUF_SIZE, uart1_handleEvent);
static uint8_t s_uart0ReadDataBuffer[UART_RX_BUF_SIZE] = {0};
static uint8_t s_index = 0;
static bool s_begin = false;
static uint8_t s_uart1ReadDataBuffer[UART_RX_BUF_SIZE] = {0};
static uint8_t s_index2 = 0;
static bool s_begin2 = false;

/*********************************************************************
 * PUBLIC FUNCTIONS
 */
/**
 @brief 串口驅動初始化
 @param 無
 @return 無
*/
void UART_Init(void)
{
    uint32_t errCode;
    
    /*------------------------ UART0 ------------------------*/
    app_uart_comm_params_t const commParams_0 =
    {
        .rx_pin_no    = BOARD_UART0_RX_IO,
        .tx_pin_no    = BOARD_UART0_TX_IO,
        .rts_pin_no   = NRF_UART_PSEL_DISCONNECTED,
        .cts_pin_no   = NRF_UART_PSEL_DISCONNECTED,                    
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,             // 關掉流控
        .use_parity   = false,
#if defined (UART_PRESENT)
        .baud_rate    = NRF_UART_BAUDRATE_115200                    // 波特率
#else
        .baud_rate    = NRF_UARTE_BAUDRATE_115200
#endif
    };
    uart0.comm_params = &commParams_0;
    errCode = app_uart_init(&uart0, &uart0_buffers, APP_IRQ_PRIORITY_LOWEST);
    APP_ERROR_CHECK(errCode);
    
    /*------------------------ UART1 ------------------------*/
    app_uart_comm_params_t const commParams_1 =
    {
        .rx_pin_no    = BOARD_UART1_RX_IO,
        .tx_pin_no    = BOARD_UART1_TX_IO,
        .rts_pin_no   = NRF_UART_PSEL_DISCONNECTED,
        .cts_pin_no   = NRF_UART_PSEL_DISCONNECTED,                    
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,             // 關掉流控
        .use_parity   = false,
#if defined (UART_PRESENT)
        .baud_rate    = NRF_UART_BAUDRATE_115200                    // 波特率
#else
        .baud_rate    = NRF_UART_BAUDRATE_115200
#endif
    };
    uart1.comm_params = &commParams_1;
    errCode = app_uart_init(&uart1, &uart1_buffers, APP_IRQ_PRIORITY_LOWEST);
    APP_ERROR_CHECK(errCode);
}

/**
 @brief 串口寫資料函式
 @param uartNum -[in] 串口號
 @param pData -[in] 寫入資料
 @param dataLen -[in] 寫入資料長度
 @return 無
*/
void UART_WriteData(uint8_t uartNum, uint8_t *pData, uint8_t dataLen)
{
    uint8_t i;
    if(uartNum == 0)
    {
        for(i = 0; i < dataLen; i++)
        {
            app_uart_put(&uart0, pData[i]);
        }
    }
    else if(uartNum == 1)
    {
        for(i = 0; i < dataLen; i++)
        {
            app_uart_put(&uart0, pData[i]);
        }
    }
}

uint32_t _app_uart_get(uint8_t * p_byte)
{
    return app_uart_get(&uart1, p_byte);
}
uint32_t _app_uart_put(uint8_t byte)
{
    return app_uart_put(&uart1, byte);
}


/*********************************************************************
 * LOCAL FUNCTIONS
 */
/**
 @brief 串口0讀取資料處理函式
 @param pEvent -[in] 串口事件
 @return 無
*/
static void uart0_handleEvent(app_uart_evt_t *pEvent)
{
    uint8_t dataChar = 0;

    switch(pEvent->evt_type)
    {
        // 已接收到UART資料
        case APP_UART_DATA_READY:
        {
            UNUSED_VARIABLE(app_uart_get(&uart0, &dataChar));
            
            // 不是回車符或換行符則開始   
            if(dataChar != '\n' && dataChar != '\r')
            {
                s_begin = true;
            }
            if(s_begin)
            {
                s_uart0ReadDataBuffer[s_index] = dataChar;
                s_index++;
            }

            // 遇到回車符或換行符結束      
            if((s_uart0ReadDataBuffer[s_index - 1] == '\n') ||
               (s_uart0ReadDataBuffer[s_index - 1] == '\r') ||
               (s_index >= MAX_RECV_BUF_SIZE))
            {
				NRF_LOG_HEXDUMP_INFO(s_uart0ReadDataBuffer, s_index);   

                memset(s_uart0ReadDataBuffer, 0, s_index); 
                s_index = 0;
                s_begin = false;                
            }
        } break;

        // 接收程序中發生通信錯誤
        case APP_UART_COMMUNICATION_ERROR:
//            APP_ERROR_HANDLER(pEvent->data.error_communication);
            break;

        // app_uart模塊使用的FIFO模塊中出現錯誤
        case APP_UART_FIFO_ERROR:
//            APP_ERROR_HANDLER(pEvent->data.error_code);
            break;

        default:
            break;
    }
}

/**
 @brief 串口1讀取資料處理函式
 @param pEvent -[in] 串口事件
 @return 無
*/
static void uart1_handleEvent(app_uart_evt_t *pEvent)
{
    uint8_t dataChar = 0;

    switch(pEvent->evt_type)
    {
        // 已接收到UART資料
        case APP_UART_DATA_READY:
        {
            UNUSED_VARIABLE(app_uart_get(&uart1, &dataChar));

            // 不是回車符或換行符則開始   
            if(dataChar != '\n' && dataChar != '\r')
            {
                s_begin2 = true;
            }
            if(s_begin2)
            {
                s_uart1ReadDataBuffer[s_index2] = dataChar;
                s_index2++;
            }

            // 遇到回車符或換行符結束      
            if((s_uart1ReadDataBuffer[s_index2 - 1] == '\n') ||
               (s_uart1ReadDataBuffer[s_index2 - 1] == '\r') ||
               (s_index2 >= MAX_RECV_BUF_SIZE))
            {
				NRF_LOG_HEXDUMP_INFO(s_uart1ReadDataBuffer, s_index2);   

                memset(s_uart1ReadDataBuffer, 0, s_index2); 
                s_index2 = 0;
                s_begin2 = false;                
            }
        } break;

        // 接收程序中發生通信錯誤
        case APP_UART_COMMUNICATION_ERROR:
//            APP_ERROR_HANDLER(pEvent->data.error_communication);
            break;

        // app_uart模塊使用的FIFO模塊中出現錯誤
        case APP_UART_FIFO_ERROR:
//            APP_ERROR_HANDLER(pEvent->data.error_code);
            break;

        default:
            break;
    }
}

/****************************************************END OF FILE****************************************************/

4.2 board_uart.h

#ifndef _BOARD_UART_H_
#define _BOARD_UART_H_

/*********************************************************************
 * INCLUDES
 */
#include "nrf_gpio.h"

/*********************************************************************
 * DEFINITIONS
 */
#define UART_TX_BUF_SIZE                256                     // UART TX buffer size
#define UART_RX_BUF_SIZE                256                     // UART RX buffer size

// UART0
#define BOARD_UART0_TX_IO               6                       // 發送引腳  
#define BOARD_UART0_RX_IO               8                       // 接收引腳
// UART1
#define BOARD_UART1_TX_IO               5   					// 發送引腳  
#define BOARD_UART1_RX_IO               7   					// 接收引腳

#define UART0                           0
#define UART1                           1

/*********************************************************************
 * GLOBAL VARIABLES
 */

/*********************************************************************
 * API FUNCTIONS
 */
void UART_Init(void);
void UART_WriteData(uint8_t uartNum, uint8_t *pData, uint8_t dataLen);

#endif /* _BOARD_UART_H_ */

五、API呼叫

需包含頭檔案 board_uart.h

UART_Init

功能初始化UART驅動
函式定義void UART_Init(void)
引數
回傳

UART_WriteData

功能串口寫資料函式
函式定義void UART_WriteData(uint8_t uartNum, uint8 *pData, uint8 dataLen)
引數uartNum:串口號
pData:寫入資料
pdataLen:寫入資料長度
回傳

六、SDK配置

點擊 sdk_config.h 檔案

選擇 Configuration Wizard

nRF_Drivers 中勾選UART、UARTE、FIFO、STRERROR和RETARGET相關選項

有的工程 nRF_Libraries 沒有 APP_FIFO_ENABLEDAPP_UART_ENABLEDRETARGET_ENABLED,則在 sdk_config.h 6044行后加上

//==========================================================
// <q> APP_FIFO_ENABLED  - app_fifo - Software FIFO implementation
#ifndef APP_FIFO_ENABLED
#define APP_FIFO_ENABLED 1
#endif

// <e> APP_UART_ENABLED - app_uart - UART driver
//==========================================================
#ifndef APP_UART_ENABLED
#define APP_UART_ENABLED 1
#endif
// <o> APP_UART_DRIVER_INSTANCE  - UART instance used
 
// <0=> 0 

#ifndef APP_UART_DRIVER_INSTANCE
#define APP_UART_DRIVER_INSTANCE 0
#endif

// </e>

// <q> RETARGET_ENABLED  - retarget - Retargeting stdio functions
#ifndef RETARGET_ENABLED
#define RETARGET_ENABLED 1
#endif

nRF_Drivers UART_ENABLED 上加上 UART1 使能

// <e> UART1_ENABLED - Enable UART1 instance
//==========================================================
#ifndef UART1_ENABLED
#define UART1_ENABLED 1
#endif
// <q> UART0_CONFIG_USE_EASY_DMA  - Default setting for using EasyDMA
 

#ifndef UART1_CONFIG_USE_EASY_DMA
#define UART1_CONFIG_USE_EASY_DMA 1
#endif

// </e>

七、添加組件庫

nRF_Drivers 檔案夾和 nRF_Libraries 檔案夾確認以下組件庫是否存在,不存在則添加,

在主從一體的工程中后三個檔案沒有,需要添加:

  1. 添加 app_uart_fifo.cretarget.c


  2. 添加 app_fifo.c

  3. 添加上述編譯檔案路徑

八、使用例子

1)添加頭檔案

#include "board_uart.h"

2)添加初始化代碼
加入 UART_Init()

int main(void)
{
	bool erase_bonds;

    /*-------------------------- 外設驅動初始化 ---------------------------*/
	// Initialize.
    log_init();																	// 日志驅動初始化																	
    timers_init();																// 定時器驅動初始化(在此加入自定義定時器)
	UART_Init();																// SI522驅動初始化(含SPI)	
	
	/*-------------------------- 藍牙協議堆疊初始化 ---------------------------*/
    power_management_init();
    ble_stack_init();															// 協議堆疊初始化
    gap_params_init();
    gatt_init();
    advertising_init();															// 廣播初始化
    services_init();															// 服務初始化
    conn_params_init();															// 連接引數初始化
    peer_manager_init();
	
	/*-------------------------- 開啟應用 ---------------------------*/
	// Start execution.
    NRF_LOG_INFO("Template example started."); 
    advertising_start(erase_bonds);												// 開啟廣播	
	application_timers_start();													// 定時器應用開啟(在此開啟自定義定時器)	
	
    // Enter main loop.
    for(;;)
    {
        idle_state_handle();
    }
}

3)寫入串口資料

uint8_t temp[1] = {0x01};
UART_WriteData(UART0, (uint8 *)&temp, 1);

UART_WriteData(UART1, (uint8 *)&temp, 1);

4)接收串口資料


? 由 Leung 寫于 2020 年 12 月 17 日

? 參考:nrf52840的uart0與uart1雙串口使用

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/236658.html

標籤:其他

上一篇:shell編程基礎教學之重定向

下一篇:Arduino+DHT11+OLED顯示溫濕度資訊(附詳細檔案+原始碼)

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more