Hello,
I am trying to send an array which has 2048 bytes via UART. But, when I add a some delay to repeat the the UART transfer, the code gets stuck on the HardFault. I am using nRF52DK for it.
This is the code:
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "app_uart.h"
#include "nrf_delay.h"
#include "nrf.h"
#include "bsp.h"
#include "nrf_uart.h"
#define UART_TX_BUF_SIZE 2048 /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
#define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED /**< Hardware flow control disabled. */
uint8_t data_array[2048] = {0};
void send_data_array(uint8_t *data_array, uint32_t length)
{
for (uint32_t i = 0; i < length; i++)
{
uint32_t err_code = app_uart_put(data_array[i]);
if (err_code != NRF_SUCCESS)
{
// Handle error if any
printf("UART transmission error: %lu\n", err_code);
}
}
}
void intialise_array(uint8_t *array)
{
for (uint32_t i = 0; i < 2048; i++)
{
array[i] = i % 255;
}
}
int main(void)
{
uint32_t err_code;
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
UART_HWFC,
false,
NRF_UART_BAUDRATE_115200
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
NULL,
APP_IRQ_PRIORITY_LOWEST,
err_code);
if (err_code != NRF_SUCCESS)
{
// Initialization failed, handle error
printf("UART initialization error: %lu\n", err_code);
return err_code;
}
APP_ERROR_CHECK(err_code);
intialise_array(data_array);
while (true)
{
send_data_array(data_array, 2048);
nrf_delay_ms(2000);
}
}
I would greatly appreciate any help from the community.