first commit
This commit is contained in:
commit
92cbe97616
1978 files changed
+1688498
No files matched your search
@@ -0,0 +1,466 @@
|
||||
/*
|
||||
* ipc_eth_consumer.c
|
||||
*
|
||||
* Created on: 11.08.2026
|
||||
* Author: Thorsten
|
||||
*/
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
#include "main.h"
|
||||
#include "openamp.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "stdio.h"
|
||||
#include "assert.h"
|
||||
|
||||
#include "FreeRTOS_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
#include "message_buffer.h"
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
#include "IPC/ipc_eth_consumer.h"
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
struct IPC_ETH_CONSUMER_Context
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
struct rpmsg_endpoint rp_endpoint;
|
||||
MessageBufferHandle_t mbufH;
|
||||
TaskHandle_t taskH;
|
||||
QueueHandle_t reqQH;
|
||||
int running;
|
||||
char endpoint[64];
|
||||
char payload[1520];
|
||||
char rxNetBuff[1520];
|
||||
uint32_t ipaddr;
|
||||
uint32_t bcast;
|
||||
uint32_t subnet;
|
||||
int ready;
|
||||
};
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
#define IPC_PKT_HEADERLEN (20 )
|
||||
#define IPC_PKT_CONTROL_TYPE (0xDEADBEEF )
|
||||
#define IPC_PKT_ETHERNET_TYPE (0xDEADC0DE )
|
||||
#define IPC_PKT_DISCOVERY_TYPE (0xDEADDA7A )
|
||||
#define IPC_PKT_MAXSIZE (RPMSG_BUFFER_SIZE-32-IPC_PKT_HEADERLEN)
|
||||
|
||||
#define IPC_CTRL_TYPE_GETPENDING (0x80 )
|
||||
#define IPC_CTRL_TYPE_GETIPADDR (0xF0 )
|
||||
#define IPC_CTRL_TYPE_GETSUBNET (0xF1 )
|
||||
|
||||
#define IPC_CTRLREMOTE_SPINDLE_START (0xA0 )
|
||||
#define IPC_CTRLREMOTE_SPINDLE_STOP (0xA1 )
|
||||
#define IPC_CTRLREMOTE_STEP_RESET (0xA2 )
|
||||
#define IPC_CTRLREMOTE_STEP_REF (0xA3 )
|
||||
#define IPC_CTRLREMOTE_STEP_ON (0xA4 )
|
||||
#define IPC_CTRLREMOTE_STEP_OFF (0xA5 )
|
||||
#define IPC_CTRLREMOTE_STEP_MOVE (0xA6 )
|
||||
#define IPC_CTRLREMOTE_MAX_LENGTH (20 )
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
typedef struct ipc_eth_packet
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
unsigned int magic;
|
||||
unsigned int type;
|
||||
unsigned int length;
|
||||
unsigned int seqID;
|
||||
int result;
|
||||
char payload[IPC_PKT_MAXSIZE];
|
||||
} __attribute__((packed)) ipc_eth_packet_t;
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
static ipc_eth_packet_t heartbeatPayload = {
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
.magic = IPC_PKT_DISCOVERY_TYPE,
|
||||
.type = 0,
|
||||
.length = 37,
|
||||
.result = 0,
|
||||
.seqID = 0,
|
||||
.payload = "Hello from STM32H755ZI-Q on ARM CM4!"
|
||||
};
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
static int ipc_eth_ConsumerRpMsgRxClb(struct rpmsg_endpoint *ep, void *data, size_t len, uint32_t src, void *priv)
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
(void)ep;
|
||||
(void)src;
|
||||
|
||||
if(!priv)
|
||||
return -1;
|
||||
|
||||
IPC_ETH_CONSUMER_Handle_t h = (IPC_ETH_CONSUMER_Handle_t)priv;
|
||||
if(len < IPC_PKT_HEADERLEN)
|
||||
return 0;
|
||||
|
||||
if(!h->priv->ready)
|
||||
{
|
||||
ipc_eth_packet_t *req = (ipc_eth_packet_t *)data;
|
||||
req->result = -2;
|
||||
req->length = 0;
|
||||
OPENAMP_send(&h->priv->rp_endpoint, req, req->length + IPC_PKT_HEADERLEN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ignore overflow cases, because we can not give errors back in that framework
|
||||
xMessageBufferSend(h->priv->mbufH, data, len, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
static int ipc_eth_ConsumerHandleControl(IPC_ETH_CONSUMER_Handle_t h, ipc_eth_packet_t *req)
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!req)
|
||||
return -1;
|
||||
|
||||
req->length = 0;
|
||||
if(req->type != IPC_CTRL_TYPE_GETIPADDR && req->type != IPC_CTRL_TYPE_GETSUBNET && req->type != IPC_CTRL_TYPE_GETPENDING)
|
||||
return -1;
|
||||
|
||||
if( req->type != IPC_CTRL_TYPE_GETPENDING) {
|
||||
req->length = 4;
|
||||
uint32_t source = h->priv->ipaddr;
|
||||
if ( req->type == IPC_CTRL_TYPE_GETSUBNET )
|
||||
source = h->priv->subnet;
|
||||
|
||||
memcpy(req->payload, &source, sizeof(source));
|
||||
}
|
||||
else {
|
||||
int index = 0;
|
||||
req->result = 0;
|
||||
while( pdPASS == xQueueReceive(h->priv->reqQH, &req->payload[index * (IPC_CTRLREMOTE_MAX_LENGTH+IPC_PKT_HEADERLEN)], 0) ) {
|
||||
index += 1;
|
||||
if ( index > 8)
|
||||
break;
|
||||
req->length = index * (IPC_CTRLREMOTE_MAX_LENGTH+IPC_PKT_HEADERLEN);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
static void ipc_eth_ConsumerTaskFunction( void * arg )
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
IPC_ETH_CONSUMER_Handle_t h = (IPC_ETH_CONSUMER_Handle_t)arg;
|
||||
size_t bLen = 0;
|
||||
int rxLen = 0;
|
||||
BaseType_t ret;
|
||||
Socket_t xSocket = FREERTOS_INVALID_SOCKET;
|
||||
const TickType_t tmFlag = 0;
|
||||
struct freertos_sockaddr xDestinationAddress;
|
||||
struct freertos_sockaddr xLocalAddress;
|
||||
struct freertos_sockaddr xRecvAddress;
|
||||
socklen_t xRecvAddressLen;
|
||||
int status = 0;
|
||||
int rounds = 0;
|
||||
|
||||
uint32_t ulIPAddress;
|
||||
uint32_t ulBroadcast;
|
||||
uint32_t ulNetMask;
|
||||
NetworkInterface_t *pxInterface = NULL;
|
||||
NetworkEndPoint_t *pxEndPoint = NULL;;
|
||||
|
||||
if(!h)
|
||||
goto error;
|
||||
|
||||
if (!h->priv)
|
||||
goto error;
|
||||
|
||||
MAILBOX_Init();
|
||||
|
||||
if (MX_OPENAMP_Init(RPMSG_REMOTE, NULL))
|
||||
goto error;
|
||||
|
||||
status = OPENAMP_create_endpoint(&h->priv->rp_endpoint, h->priv->endpoint, RPMSG_ADDR_ANY,
|
||||
ipc_eth_ConsumerRpMsgRxClb, NULL);
|
||||
if (status < 0)
|
||||
goto error;
|
||||
|
||||
// set this instance as private data
|
||||
h->priv->rp_endpoint.priv = h;
|
||||
h->priv->ready = 0;
|
||||
|
||||
while(h->priv->running) {
|
||||
h->priv->ready = 0;
|
||||
rounds = 0;
|
||||
heartbeatPayload.seqID = 0;
|
||||
|
||||
// make sure, we always proceed only, when the stack is ready!
|
||||
while(xIPIsNetworkTaskReady() == pdFALSE) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
OPENAMP_check_for_message();
|
||||
if (h->priv->running == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
pxInterface = FreeRTOS_FirstNetworkInterface();
|
||||
if(pxInterface == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
// wait for PHY link detection
|
||||
if (pxInterface->pfGetPhyLinkStatus != NULL)
|
||||
{
|
||||
while(pxInterface->pfGetPhyLinkStatus(pxInterface) != pdTRUE ) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1));
|
||||
OPENAMP_check_for_message();
|
||||
if (h->priv->running == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pxEndPoint = FreeRTOS_FirstEndPoint( pxInterface );
|
||||
while( pxEndPoint != NULL )
|
||||
{
|
||||
#if ( ipconfigUSE_IPv6 != 0 )
|
||||
if( pxEndPoint->bits.bIPv6 != pdFALSE ) {
|
||||
pxEndPoint = FreeRTOS_NextEndPoint( pxInterface, pxEndPoint );
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if( pxEndPoint == NULL ) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
|
||||
if(xSocket == FREERTOS_INVALID_SOCKET) {
|
||||
h->priv->running = 0;
|
||||
}
|
||||
|
||||
if ( xSocket != FREERTOS_INVALID_SOCKET ) {
|
||||
// in free rtos stack we do not have to set the broadcast flag for a socket explicitly!
|
||||
//ret = FreeRTOS_setsockopt(xSocket, 0, SO_BROADCAST, &bFlag, sizeof(bFlag));
|
||||
//if(ret) {
|
||||
// FreeRTOS_closesocket(xSocket);
|
||||
// h->priv->running = 0;
|
||||
//}
|
||||
|
||||
// we set the reception timeout to zero here
|
||||
ret = FreeRTOS_setsockopt(xSocket, 0, FREERTOS_SO_RCVTIMEO, &tmFlag, sizeof(tmFlag));
|
||||
if(ret) {
|
||||
FreeRTOS_closesocket(xSocket);
|
||||
h->priv->running = 0;
|
||||
}
|
||||
|
||||
//why the hack the broadcast address is completely wrong in this network stack? we fix it now!
|
||||
pxEndPoint->ipv4_defaults.ulBroadcastAddress = ( pxEndPoint->ipv4_defaults.ulIPAddress & pxEndPoint->ipv4_defaults.ulNetMask )
|
||||
| ~pxEndPoint->ipv4_defaults.ulNetMask;
|
||||
pxEndPoint->ipv4_settings.ulBroadcastAddress = ( pxEndPoint->ipv4_settings.ulIPAddress & pxEndPoint->ipv4_settings.ulNetMask )
|
||||
| ~pxEndPoint->ipv4_settings.ulNetMask;
|
||||
|
||||
if (pxEndPoint->ipv4_settings.ulIPAddress == 0) {
|
||||
ulIPAddress = pxEndPoint->ipv4_defaults.ulIPAddress;
|
||||
ulNetMask = pxEndPoint->ipv4_defaults.ulNetMask;
|
||||
ulBroadcast = pxEndPoint->ipv4_defaults.ulBroadcastAddress;
|
||||
}
|
||||
else{
|
||||
ulIPAddress = pxEndPoint->ipv4_settings.ulIPAddress;
|
||||
ulNetMask = pxEndPoint->ipv4_settings.ulNetMask;
|
||||
ulBroadcast = pxEndPoint->ipv4_settings.ulBroadcastAddress;
|
||||
}
|
||||
|
||||
h->priv->ipaddr = ulIPAddress;
|
||||
h->priv->bcast = ulBroadcast;
|
||||
h->priv->subnet = ulNetMask;
|
||||
|
||||
|
||||
xDestinationAddress.sin_len = sizeof(xDestinationAddress);
|
||||
xDestinationAddress.sin_address.ulIP_IPv4 = ulBroadcast;
|
||||
xDestinationAddress.sin_port = FreeRTOS_htons( 10000 );
|
||||
xDestinationAddress.sin_family = FREERTOS_AF_INET4;
|
||||
|
||||
xLocalAddress.sin_len = sizeof(xLocalAddress);
|
||||
xLocalAddress.sin_address.ulIP_IPv4 = 0;
|
||||
xLocalAddress.sin_port = FreeRTOS_htons( 10000 );
|
||||
xLocalAddress.sin_family = FREERTOS_AF_INET4;
|
||||
|
||||
OPENAMP_check_for_message();
|
||||
ret = FreeRTOS_bind(xSocket, &xLocalAddress, sizeof(struct freertos_sockaddr));
|
||||
if(ret) {
|
||||
FreeRTOS_closesocket(xSocket);
|
||||
h->priv->running = 0;
|
||||
}
|
||||
}
|
||||
|
||||
while(h->priv->running) {
|
||||
rounds += 1;
|
||||
OPENAMP_check_for_message();
|
||||
h->priv->ready = 1;
|
||||
|
||||
// only accept valid packets with at least the full packet size, otherwise ignore them!
|
||||
if ( (bLen = xMessageBufferReceive(h->priv->mbufH, h->priv->payload, sizeof(h->priv->payload), pdMS_TO_TICKS(1))) >= IPC_PKT_HEADERLEN) {
|
||||
|
||||
// check header to decide whether the packet is for control purpose or desired for
|
||||
// Ethernet transmission
|
||||
ipc_eth_packet_t *req = (ipc_eth_packet_t *)h->priv->payload;
|
||||
|
||||
if (req->length <= (bLen - IPC_PKT_HEADERLEN))
|
||||
{
|
||||
switch (req->magic)
|
||||
{
|
||||
case IPC_PKT_CONTROL_TYPE:
|
||||
{
|
||||
req->result = -1;
|
||||
req->result = ipc_eth_ConsumerHandleControl(h, req);
|
||||
break;
|
||||
}
|
||||
case IPC_PKT_ETHERNET_TYPE:
|
||||
{
|
||||
req->result = FreeRTOS_sendto( xSocket, req->payload, req->length, 0,
|
||||
&xDestinationAddress, sizeof( xDestinationAddress ));
|
||||
req->length = 0;
|
||||
break;
|
||||
}
|
||||
case IPC_PKT_DISCOVERY_TYPE:
|
||||
{
|
||||
req->result = FreeRTOS_sendto( xSocket, req, req->length + IPC_PKT_HEADERLEN, 0,
|
||||
&xDestinationAddress, sizeof( xDestinationAddress ));
|
||||
req->length = 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
req->result = -1;
|
||||
req->length = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
OPENAMP_check_for_message();
|
||||
OPENAMP_send(&h->priv->rp_endpoint, req, req->length + IPC_PKT_HEADERLEN);
|
||||
}
|
||||
}
|
||||
|
||||
if( rounds >= 1000 ) {
|
||||
|
||||
OPENAMP_check_for_message();
|
||||
if (FreeRTOS_sendto( xSocket, &heartbeatPayload, heartbeatPayload.length + IPC_PKT_HEADERLEN,
|
||||
0, &xDestinationAddress, sizeof( xDestinationAddress ) ) < 0 ) {
|
||||
break;
|
||||
}
|
||||
rounds = 0;
|
||||
}
|
||||
|
||||
if ((rxLen = FreeRTOS_recvfrom(xSocket, h->priv->rxNetBuff, sizeof(h->priv->rxNetBuff),
|
||||
0, &xRecvAddress, &xRecvAddressLen)) >= IPC_PKT_HEADERLEN) {
|
||||
|
||||
OPENAMP_check_for_message();
|
||||
ipc_eth_packet_t *req = (ipc_eth_packet_t *)h->priv->rxNetBuff;
|
||||
|
||||
if (req->magic == IPC_PKT_CONTROL_TYPE && req->type >= IPC_CTRLREMOTE_SPINDLE_START &&
|
||||
req->type <= IPC_CTRLREMOTE_STEP_MOVE && req->length <= IPC_CTRLREMOTE_MAX_LENGTH) {
|
||||
// ignore overruns in case we have some
|
||||
if( req->length <= (size_t)rxLen - IPC_PKT_HEADERLEN )
|
||||
xQueueSend(h->priv->reqQH, req, 0);
|
||||
}
|
||||
}
|
||||
else if(rxLen < 0 && rxLen != FREERTOS_EWOULDBLOCK) {
|
||||
// socket error, so jump out of loop
|
||||
break;
|
||||
}
|
||||
|
||||
// check PHY link detection
|
||||
if (pxInterface->pfGetPhyLinkStatus != NULL)
|
||||
{
|
||||
if(pxInterface->pfGetPhyLinkStatus(pxInterface) != pdTRUE ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
h->priv->ready = 0;
|
||||
FreeRTOS_closesocket(xSocket);
|
||||
xSocket = FREERTOS_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
error:
|
||||
if (xSocket != FREERTOS_INVALID_SOCKET) {
|
||||
FreeRTOS_closesocket(xSocket);
|
||||
}
|
||||
if (h) {
|
||||
if (h->priv) {
|
||||
if (h->priv->rp_endpoint.priv == h) {
|
||||
// no abstraction for destroying, so calling library function directly
|
||||
rpmsg_destroy_ept(&h->priv->rp_endpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
OPENAMP_DeInit();
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
IPC_ETH_CONSUMER_Handle_t IPC_ETH_CONSUMER_Init(const char *endpoint)
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
IPC_ETH_CONSUMER_Handle_t h = NULL;
|
||||
|
||||
if(!endpoint)
|
||||
goto error;
|
||||
|
||||
if(endpoint[0] == '\0')
|
||||
goto error;
|
||||
|
||||
if(!(h = (IPC_ETH_CONSUMER_Handle_t)calloc(1, sizeof(struct IPC_ETH_CONSUMER_Handle))))
|
||||
goto error;
|
||||
|
||||
h->priv = (IPC_ETH_CONSUMER_Context_t)calloc(1, sizeof(struct IPC_ETH_CONSUMER_Context));
|
||||
if(!h->priv)
|
||||
goto error;
|
||||
|
||||
if ((h->priv->mbufH = xMessageBufferCreate(4*IPC_PKT_MAXSIZE)) == NULL)
|
||||
goto error;
|
||||
|
||||
if ((h->priv->reqQH = xQueueCreate(6, IPC_PKT_HEADERLEN + IPC_CTRLREMOTE_MAX_LENGTH)) == NULL)
|
||||
goto error;
|
||||
|
||||
strncpy(h->priv->endpoint, endpoint,
|
||||
sizeof(h->priv->endpoint)-1 < strlen(endpoint) ?
|
||||
sizeof(h->priv->endpoint)-1 : strlen(endpoint));
|
||||
h->priv->endpoint[sizeof(h->priv->endpoint)-1] = '\0';
|
||||
h->priv->running = 1;
|
||||
if (pdPASS != xTaskCreate(ipc_eth_ConsumerTaskFunction, "ipc2eth", 4096, h, configMAX_PRIORITIES - 3, &h->priv->taskH))
|
||||
goto error;
|
||||
|
||||
return h;
|
||||
|
||||
error:
|
||||
if (h) {
|
||||
if(h->priv) {
|
||||
if(h->priv->taskH) {
|
||||
h->priv->running = 0;
|
||||
vTaskDelete(h->priv->taskH);
|
||||
}
|
||||
if(h->priv->mbufH) {
|
||||
vMessageBufferDelete(h->priv->mbufH);
|
||||
}
|
||||
if(h->priv->reqQH) {
|
||||
vQueueDelete(h->priv->reqQH);
|
||||
}
|
||||
free(h->priv);
|
||||
}
|
||||
free(h);
|
||||
}
|
||||
h = NULL;
|
||||
|
||||
return h;
|
||||
}
|
||||
@@ -0,0 +1,505 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "string.h"
|
||||
#include "openamp.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "stdio.h"
|
||||
#include "assert.h"
|
||||
|
||||
#include "FreeRTOS_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
#include "FreeRTOS_DHCP.h"
|
||||
#include "FreeRTOS_Routing.h"
|
||||
|
||||
#include "IPC/ipc_eth_consumer.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
extern void initialise_stdlib_abstraction( void );
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
#ifndef HSEM_ID_0
|
||||
#define HSEM_ID_0 (0U) /* HW semaphore 0*/
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint32_t w[3]; // STM32 UUID: 96 Bit
|
||||
} uuid96_t;
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
#if 0
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma location=0x10040000
|
||||
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
|
||||
#pragma location=0x10040080
|
||||
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */
|
||||
|
||||
#elif defined ( __CC_ARM ) /* MDK ARM Compiler */
|
||||
|
||||
__attribute__((at(0x10040000))) ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
|
||||
__attribute__((at(0x10040080))) ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */
|
||||
|
||||
#elif defined ( __GNUC__ ) /* GNU Compiler */
|
||||
|
||||
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((section(".RxDescripSection"))); /* Ethernet Rx DMA Descriptors */
|
||||
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((section(".TxDescripSection"))); /* Ethernet Tx DMA Descriptors */
|
||||
#endif
|
||||
|
||||
ETH_TxPacketConfig TxConfig;
|
||||
|
||||
ETH_HandleTypeDef heth;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
#endif
|
||||
ETH_HandleTypeDef heth;
|
||||
|
||||
static UBaseType_t ulNextRand;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
static void MX_GPIO_Init(void);
|
||||
static void MX_ETH_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
extern void initialise_stdlib_abstraction( void );
|
||||
|
||||
#define BKPSRAM_BASE 0x38800000UL
|
||||
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t uuid[3];
|
||||
} device_shared_t;
|
||||
|
||||
#define DEVICE_SHARED \
|
||||
((volatile device_shared_t *)BKPSRAM_BASE)
|
||||
|
||||
static inline void stm32_read_uuid(uuid96_t *u)
|
||||
{
|
||||
if(DEVICE_SHARED->magic != 0x48475531) {
|
||||
u->w[0] = 0xDEADC0DE;
|
||||
u->w[1] = 0xBADEAFFE;
|
||||
u->w[2] = 0xCAFEBABE;
|
||||
} else {
|
||||
u->w[0] = DEVICE_SHARED->uuid[0];
|
||||
u->w[1] = DEVICE_SHARED->uuid[1];
|
||||
u->w[2] = DEVICE_SHARED->uuid[2];
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t mix32(uint32_t x)
|
||||
{
|
||||
x ^= x >> 16;
|
||||
x *= 0x7feb352d;
|
||||
x ^= x >> 15;
|
||||
x *= 0x846ca68b;
|
||||
x ^= x >> 16;
|
||||
return x;
|
||||
}
|
||||
|
||||
static void uuid_to_mac(uint8_t mac[6], uint32_t ifidx)
|
||||
{
|
||||
uuid96_t u;
|
||||
stm32_read_uuid(&u);
|
||||
|
||||
uint32_t a = mix32(u.w[0] ^ u.w[2] ^ ifidx);
|
||||
uint32_t b = mix32(u.w[1] ^ (ifidx * 0x9e3779b9u));
|
||||
|
||||
mac[0] = (uint8_t)(a >> 24);
|
||||
mac[1] = (uint8_t)(a >> 16);
|
||||
mac[2] = (uint8_t)(a >> 8);
|
||||
mac[3] = (uint8_t)(a);
|
||||
mac[4] = (uint8_t)(b >> 8);
|
||||
mac[5] = (uint8_t)(b);
|
||||
|
||||
mac[0] &= 0xFE; // unicast
|
||||
mac[0] |= 0x02; // locally administered
|
||||
}
|
||||
|
||||
static uint32_t uuid_to_seed(uint32_t ifidx)
|
||||
{
|
||||
uuid96_t u;
|
||||
stm32_read_uuid(&u);
|
||||
|
||||
return mix32(u.w[0] ^ u.w[1] ^ u.w[2] ^ (ifidx * 0x9e3779b9u));
|
||||
}
|
||||
|
||||
static uint32_t uuid_to_ipv4_lla(uint32_t ifidx)
|
||||
{
|
||||
uuid96_t u;
|
||||
stm32_read_uuid(&u);
|
||||
|
||||
uint32_t h = mix32(u.w[0] ^ u.w[1] ^ u.w[2] ^ (ifidx * 0x9e3779b9u));
|
||||
|
||||
uint8_t x = 1 + ((h >> 8) % 254);
|
||||
uint8_t y = 1 + (h & 0xFF);
|
||||
|
||||
return (169u << 24) | (254u << 16) | ((uint32_t)x << 8) | y;
|
||||
}
|
||||
|
||||
void vApplicationMallocFailedHook( void )
|
||||
{
|
||||
taskDISABLE_INTERRUPTS();
|
||||
__asm volatile( "bkpt #0" );
|
||||
for (;;) {;}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
|
||||
{
|
||||
( void ) pcTaskName;
|
||||
( void ) pxTask;
|
||||
|
||||
taskDISABLE_INTERRUPTS();
|
||||
__asm volatile( "bkpt #0" );
|
||||
for (;;) {;}
|
||||
}
|
||||
|
||||
void vAssertCalled( const char * const pcFileName, unsigned long ulLine )
|
||||
{
|
||||
volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0;
|
||||
|
||||
/* Parameters are not used. */
|
||||
( void ) ulLine;
|
||||
( void ) pcFileName;
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
/* You can step out of this function to debug the assertion by using
|
||||
the debugger to set ulSetToNonZeroInDebuggerToContinue to a non-zero
|
||||
value. */
|
||||
while( ulSetToNonZeroInDebuggerToContinue == 0 )
|
||||
{
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
|
||||
int __stdout_put_char(int ch)
|
||||
{
|
||||
(void)ch;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __stdin_get_char(void)
|
||||
{
|
||||
return EOF;
|
||||
}
|
||||
|
||||
void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent,
|
||||
struct xNetworkEndPoint * pxEndPoint )
|
||||
{
|
||||
(void)pxEndPoint;
|
||||
static BaseType_t xTasksAlreadyCreated = pdFALSE;
|
||||
|
||||
/* If the network has just come up...*/
|
||||
if( ( eNetworkEvent == eNetworkUp ) && ( xTasksAlreadyCreated == pdFALSE ) )
|
||||
{
|
||||
/* Do nothing. Just a stub. */
|
||||
|
||||
xTasksAlreadyCreated = pdTRUE;
|
||||
}
|
||||
}
|
||||
|
||||
UBaseType_t uxRand( void )
|
||||
{
|
||||
static uint32_t ulMultiplier = 0;
|
||||
if( !ulMultiplier ) uuid_to_seed(0);
|
||||
const uint32_t ulIncrement = 1UL;
|
||||
|
||||
/* Utility function to generate a pseudo random number. */
|
||||
|
||||
ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
|
||||
return( ( int ) ( ulNextRand ) & 0x7fffUL );
|
||||
}
|
||||
|
||||
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
|
||||
{
|
||||
*pulNumber = ( uint32_t ) uxRand();
|
||||
|
||||
return pdTRUE;
|
||||
}
|
||||
|
||||
extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
|
||||
uint16_t usSourcePort,
|
||||
uint32_t ulDestinationAddress,
|
||||
uint16_t usDestinationPort )
|
||||
{
|
||||
( void ) ulSourceAddress;
|
||||
( void ) usSourcePort;
|
||||
( void ) ulDestinationAddress;
|
||||
( void ) usDestinationPort;
|
||||
|
||||
return ( uint32_t ) uxRand();
|
||||
}
|
||||
|
||||
void vApplicationPingReplyHook( ePingReplyStatus_t eStatus,
|
||||
uint16_t usIdentifier )
|
||||
{
|
||||
(void)eStatus;
|
||||
(void)usIdentifier;
|
||||
/* Provide a stub for this function. */
|
||||
}
|
||||
|
||||
|
||||
eDHCPCallbackAnswer_t xApplicationDHCPHook_Multi( eDHCPCallbackPhase_t eDHCPPhase,
|
||||
struct xNetworkEndPoint * pxEndPoint,
|
||||
IP_Address_t * pxIPAddress )
|
||||
{
|
||||
(void)eDHCPPhase;
|
||||
(void)pxEndPoint;
|
||||
(void)pxIPAddress;
|
||||
|
||||
/* Provide a stub for this function. */
|
||||
return eDHCPContinue;
|
||||
}
|
||||
|
||||
const char * pcApplicationHostnameHook( void )
|
||||
{
|
||||
/* This function will be called during the DHCP: the machine will be registered
|
||||
* with an IP address plus this name. */
|
||||
return "STM32H755ZI-Q-Labor";
|
||||
}
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
static NetworkInterface_t xInterfaces[ 1 ];
|
||||
static NetworkEndPoint_t xEndPoints[ 1 ];
|
||||
|
||||
extern NetworkInterface_t * pxSTM32_FillInterfaceDescriptor( BaseType_t xEMACIndex,
|
||||
NetworkInterface_t * pxInterface );
|
||||
extern NetworkInterface_t * pxLoopback_FillInterfaceDescriptor( BaseType_t xEMACIndex,
|
||||
NetworkInterface_t * pxInterface );
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* USER CODE BEGIN Boot_Mode_Sequence_1 */
|
||||
/*HW semaphore Clock enable*/
|
||||
__HAL_RCC_HSEM_CLK_ENABLE();
|
||||
/* Activate HSEM notification for Cortex-M4*/
|
||||
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));
|
||||
/*
|
||||
Domain D2 goes to STOP mode (Cortex-M4 in deep-sleep) waiting for Cortex-M7 to
|
||||
perform system initialization (system clock config, external memory configuration.. )
|
||||
*/
|
||||
HAL_PWREx_ClearPendingEvent();
|
||||
HAL_PWREx_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFE, PWR_D2_DOMAIN);
|
||||
/* Clear HSEM flag */
|
||||
__HAL_HSEM_CLEAR_FLAG(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));
|
||||
|
||||
/* USER CODE END Boot_Mode_Sequence_1 */
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
pxSTM32_FillInterfaceDescriptor(
|
||||
1,
|
||||
&( xInterfaces[ 0 ] )
|
||||
);
|
||||
|
||||
/* Attach an endpoint to that interface. */
|
||||
uint32_t ip4gen = uuid_to_ipv4_lla(0);
|
||||
const uint8_t ucIPAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { ( ip4gen >> 24 ) & 0xFF,
|
||||
( ip4gen >> 16 ) & 0xFF, ( ip4gen >> 8 ) & 0xFF, ( ip4gen >> 0 ) & 0xFF };
|
||||
const uint8_t ucNetMask[ ipIP_ADDRESS_LENGTH_BYTES ] = { 255, 255, 0, 0 };
|
||||
const uint8_t ucGatewayAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 169, 254, 0, 1 };
|
||||
const uint8_t ucDNSServerAddress[ ipIP_ADDRESS_LENGTH_BYTES ] = { 1, 1, 1, 1 };
|
||||
uint8_t ucMACAddress[ ipMAC_ADDRESS_LENGTH_BYTES ] = { 0 };
|
||||
uuid_to_mac(ucMACAddress, 0);
|
||||
|
||||
/* Attach an endpoint to that interface. */
|
||||
FreeRTOS_FillEndPoint(
|
||||
&( xInterfaces[ 0 ] ),
|
||||
&( xEndPoints[ 0 ] ),
|
||||
ucIPAddress,
|
||||
ucNetMask,
|
||||
ucGatewayAddress,
|
||||
ucDNSServerAddress,
|
||||
ucMACAddress
|
||||
);
|
||||
|
||||
//switch off dhcp and directly use LLA address determined by the UUID
|
||||
xEndPoints[ 0 ].bits.bWantDHCP = 0;
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_ETH_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
IPC_ETH_CONSUMER_Init("eth_endpoint");
|
||||
|
||||
initialise_stdlib_abstraction();
|
||||
|
||||
FreeRTOS_IPInit_Multi();
|
||||
|
||||
vTaskStartScheduler();
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ETH Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_ETH_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN ETH_Init 0 */
|
||||
#if 0
|
||||
/* USER CODE END ETH_Init 0 */
|
||||
|
||||
static uint8_t MACAddr[6];
|
||||
|
||||
/* USER CODE BEGIN ETH_Init 1 */
|
||||
|
||||
/* USER CODE END ETH_Init 1 */
|
||||
heth.Instance = ETH;
|
||||
MACAddr[0] = 0x00;
|
||||
MACAddr[1] = 0x80;
|
||||
MACAddr[2] = 0xE1;
|
||||
MACAddr[3] = 0x00;
|
||||
MACAddr[4] = 0x00;
|
||||
MACAddr[5] = 0x00;
|
||||
heth.Init.MACAddr = &MACAddr[0];
|
||||
heth.Init.MediaInterface = HAL_ETH_RMII_MODE;
|
||||
heth.Init.TxDesc = DMATxDscrTab;
|
||||
heth.Init.RxDesc = DMARxDscrTab;
|
||||
heth.Init.RxBuffLen = 1536;
|
||||
|
||||
/* USER CODE BEGIN MACADDRESS */
|
||||
|
||||
/* USER CODE END MACADDRESS */
|
||||
|
||||
if (HAL_ETH_Init(&heth) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
memset(&TxConfig, 0 , sizeof(ETH_TxPacketConfig));
|
||||
TxConfig.Attributes = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD;
|
||||
TxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC;
|
||||
TxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT;
|
||||
/* USER CODE BEGIN ETH_Init 2 */
|
||||
#endif
|
||||
/* USER CODE END ETH_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
@@ -0,0 +1,869 @@
|
||||
/**
|
||||
* \file mvsyscall.c
|
||||
* \brief Wrappers required to use newlib malloc-family within FreeRTOS.
|
||||
* The syscalls for stdlib are implemented in a minimum way as well
|
||||
*
|
||||
* \par Overview
|
||||
* Route FreeRTOS memory management functions to newlib's malloc family.
|
||||
* Thus newlib and FreeRTOS share memory-management routines and memory pool,
|
||||
* and all newlib's internal memory-management requirements are supported.
|
||||
*
|
||||
* \author Dave Nadler
|
||||
* \author Thorsten Kimmel
|
||||
* \date 20-August-2019
|
||||
* \version 02-Dec-2021 implemented syscalls for stdlib
|
||||
* \version 27-Jun-2020 Correct "FreeRTOS.h" capitalization, commentary
|
||||
* \version 24-Jun-2020 commentary only
|
||||
* \version 11-Sep-2019 malloc accounting, comments, newlib version check
|
||||
*
|
||||
* \see http://www.nadler.com/embedded/newlibAndFreeRTOS.html
|
||||
* \see https://sourceware.org/newlib/libc.html#Reentrancy
|
||||
* \see https://sourceware.org/newlib/libc.html#malloc
|
||||
* \see https://sourceware.org/newlib/libc.html#index-_005f_005fenv_005flock
|
||||
* \see https://sourceware.org/newlib/libc.html#index-_005f_005fmalloc_005flock
|
||||
* \see https://sourceforge.net/p/freertos/feature-requests/72/
|
||||
* \see http://www.billgatliff.com/newlib.html
|
||||
* \see http://wiki.osdev.org/Porting_Newlib
|
||||
* \see http://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html
|
||||
*
|
||||
*
|
||||
* \copyright
|
||||
* (c) Dave Nadler 2017-2020, All Rights Reserved.
|
||||
* Web: http://www.nadler.com
|
||||
* email: drn@nadler.com
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Use or redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions, and the following disclaimer.
|
||||
*
|
||||
* - Use or redistributions of source code must retain ALL ORIGINAL COMMENTS, AND
|
||||
* ANY CHANGES MUST BE DOCUMENTED, INCLUDING:
|
||||
* - Reason for change (purpose)
|
||||
* - Functional change
|
||||
* - Date and author contact
|
||||
*
|
||||
* - Redistributions in binary form 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Includes
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
#include <newlib.h>
|
||||
#include <malloc.h>
|
||||
#include <FreeRTOS.h>
|
||||
|
||||
/*!
|
||||
* In case there is a FreeRTOS used for this application, we have to include
|
||||
* additional dependencies which are used in memory wrappers
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifdef INC_FREERTOS_H
|
||||
# include "task.h"
|
||||
# include "semphr.h"
|
||||
#endif
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*!
|
||||
* conditional check to make sure this syscall abstraction and the memory
|
||||
* wrapper fits to the correct newlib / stdlib version
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
#if (( __NEWLIB__ != 3) && ( __NEWLIB__ != 4 )) || ((__NEWLIB__ != 3) && (__NEWLIB_MINOR__ < 1)) || \
|
||||
((__NEWLIB__ == 3) && (__NEWLIB_MINOR__ > 3) )
|
||||
#warning "This wrapper was verified for newlib versions 3.1 - 3.3; please ensure newlib's external requirements for malloc-family are unchanged!"
|
||||
#endif
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*!
|
||||
* conditional check to make sure the correct reentrancy configuration has been
|
||||
* set. Otherwise the stdlib calls could be lead to undefined behavior whenever
|
||||
* a function is called simultaneous by more than one thread
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
#ifdef INC_FREERTOS_H
|
||||
# if !defined(configUSE_NEWLIB_REENTRANT) || (configUSE_NEWLIB_REENTRANT != 1)
|
||||
# error "#define configUSE_NEWLIB_REENTRANT 1 which is required for thread-safety of newlib sprintf, dtoa, strtok, etc..."
|
||||
# endif
|
||||
#endif
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef INC_FREERTOS_H
|
||||
// ----------------------------------------------------------------------------
|
||||
// The following functions are used to lock IRQs to make sure the newlib functions
|
||||
// can be used in an IRQ as well, this is not working as expected and so we disable it
|
||||
// for our platform so far, therefore we have to make sure the user can not enter newlib
|
||||
// functions when running in ISR context
|
||||
//! Disables interrupts (after saving prior state)
|
||||
# define NEWLIB_FUNCS_INSIDE_ISR 0
|
||||
# if defined(NEWLIB_FUNCS_INSIDE_ISR) && NEWLIB_FUNCS_INSIDE_ISR != 0
|
||||
define DRN_ENTER_CRITICAL_SECTION(_usis) { _usis = taskENTER_CRITICAL_FROM_ISR(); }
|
||||
# else
|
||||
# define DRN_ENTER_CRITICAL_SECTION(_usis) do { int insideAnISR = xPortIsInsideInterrupt(); configASSERT( !insideAnISR ); } while(0)
|
||||
# endif
|
||||
|
||||
//! Re-enables interrupts (unless already disabled prior taskENTER_CRITICAL)
|
||||
# if defined(NEWLIB_FUNCS_INSIDE_ISR) && NEWLIB_FUNCS_INSIDE_ISR != 0
|
||||
# define DRN_EXIT_CRITICAL_SECTION(_usis) { taskEXIT_CRITICAL_FROM_ISR(_usis); }
|
||||
# else
|
||||
# define DRN_EXIT_CRITICAL_SECTION(_usis)
|
||||
# endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
# define __HeapBase _end
|
||||
# define __HeapLimit _estack
|
||||
|
||||
#define MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_STDOUT
|
||||
#define MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_MALLOC
|
||||
#define MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_ENV
|
||||
|
||||
/*!
|
||||
* The symbols __HeapBase and __HeapLimit are defined to read the
|
||||
* heap parameters from symbols defined in the linker script. The
|
||||
* define macros above are used to adapt these names to the name
|
||||
* of the variable in the linker script. Both variables will be used
|
||||
* later to allocate and manage memory of the heap and to detect a
|
||||
* stack / heap crash...
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
extern char __HeapBase, __HeapLimit;
|
||||
|
||||
int _write( int file, char* ptr, int len );
|
||||
int _read( int file, char* ptr, int len );
|
||||
|
||||
/*!
|
||||
* The following semaphore is used to prevent the stdout and stderr device
|
||||
* to be accessed simultaneous while writing data. This is necessary because
|
||||
* the stdlib itself is thread safe and has its own buffers for a thread but
|
||||
* the access to the hardware must be locked as well
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
static char memAlignmentAndSafetyBuffer[32] = {0};
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_STDOUT)
|
||||
static SemaphoreHandle_t stdioSemaphore;
|
||||
#endif
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_MALLOC)
|
||||
static SemaphoreHandle_t mallocSemaphore;
|
||||
#endif
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_ENV)
|
||||
static SemaphoreHandle_t envSemaphore;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
* pointer to array of char* strings that define the current
|
||||
* environment variables of the applications environment
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
#define xstr(a) str(a)
|
||||
#define str(a) #a
|
||||
#define NEWLIB_ENV "STDLIB=newlib-" xstr(__NEWLIB__) "." xstr(__NEWLIB_MINOR__)
|
||||
#ifdef NDEBUG
|
||||
# define DEBUG_ENV "DEBUG_ENV=RELEASE"
|
||||
#else
|
||||
# define DEBUG_ENV "DEBUG_ENV=DEBUG"
|
||||
#endif
|
||||
#define GNUC_ENV "GNUC=" xstr(__GNUC__) "." xstr(__GNUC_MINOR__)
|
||||
#define OS_VERSION_ENV "OSVERSION=" xstr(tskKERNEL_VERSION_MAJOR) "." xstr(tskKERNEL_VERSION_MINOR)
|
||||
static char* __env[] = { "ARCH=ARM32", "MCU=STM32F746ZI", "PLATFORM=ARM_FW_PLAYGROUND", "OS=FreeRTOS", "USERNAME=STM32",
|
||||
NEWLIB_ENV, OS_VERSION_ENV, GNUC_ENV, DEBUG_ENV, "BUILDTIME=" xstr(__TIME__), "BUILDDATE=" xstr(__DATE__),
|
||||
NULL
|
||||
};
|
||||
char** environ = &__env[0];
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*!
|
||||
* \brief is used to provide an overwritable stdout channel which can be used
|
||||
* for debugging purposes in the application
|
||||
* \param chr
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
__attribute__( ( weak ) ) void __stdout_put_char( int chr );
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*!
|
||||
* \brief is used to provide an overwritable stdin channel which can be used
|
||||
* for debugging purposes in the application
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
__attribute__( ( weak ) ) int __stdin_get_char( void )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*!
|
||||
* \brief is used to provide an overwritable clock tick function which is used
|
||||
* by the stdlib
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
__attribute__( ( weak ) ) unsigned long long __stdlib_get_system_clock_ticks( void )
|
||||
{
|
||||
#if defined(INC_FREERTOS_H)
|
||||
return (unsigned long long)xTaskGetTickCount();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/*!
|
||||
* \brief semihosting initialization function which should be called when _start
|
||||
* is called. afterwards main would be called.
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
void initialise_monitor_handles( void )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
memAlignmentAndSafetyBuffer[0] = 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief this function will be called after initialization of the .bss, .text,
|
||||
* and .data segment of the application and while the stdlib begins to initialize
|
||||
* its requirements. This is done by calling the __libc_init_array in _start.S routine
|
||||
* before calling the main function. By tagging a function with the "constructor"
|
||||
* attribute, the compiler will add the function pointer to this initialization list.
|
||||
* \attention This is a GCC attribute. In case the application is compiled with another
|
||||
* compiler, this attribute must be ported as well!
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
__attribute__((constructor))
|
||||
void initialise_stdlib_abstraction( void )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
initialise_monitor_handles();
|
||||
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_STDOUT)
|
||||
stdioSemaphore = xSemaphoreCreateRecursiveMutex();
|
||||
|
||||
if ( stdioSemaphore == 0 )
|
||||
{
|
||||
vAssertCalled( __FILE__, __LINE__ );
|
||||
}
|
||||
#endif
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_MALLOC)
|
||||
mallocSemaphore = xSemaphoreCreateRecursiveMutex();
|
||||
|
||||
if ( mallocSemaphore == 0 )
|
||||
{
|
||||
vAssertCalled( __FILE__, __LINE__ );
|
||||
}
|
||||
#endif
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_ENV)
|
||||
envSemaphore = xSemaphoreCreateRecursiveMutex();
|
||||
|
||||
if ( envSemaphore == 0 )
|
||||
{
|
||||
vAssertCalled( __FILE__, __LINE__ );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief returns the process ID (PID) of the calling process.
|
||||
* \attention we have no real OS and so we only return PID 1 because
|
||||
* this is the only running process. Everything is in "kernel space" or
|
||||
* "machine mode"
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
int _getpid( void )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief The command kill sends the specified signal to the specified
|
||||
* process.
|
||||
* \attention we have no real OS and so we cannot kill our only running
|
||||
* process with PID 1
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
int _kill( int pid, int sig )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )pid;
|
||||
( void )sig;
|
||||
|
||||
if ( _impure_ptr != 0 )
|
||||
{
|
||||
_impure_ptr->_errno = EINVAL;
|
||||
}
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief The command exit is used to stop the process or application
|
||||
* \attention if the application has called exit, we do must not return
|
||||
* from this function anymore
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
__attribute__( ( noreturn ) )
|
||||
void _exit ( int status )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
_kill( status, -1 );
|
||||
while ( 1 ) {}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief attempts to read up to 'len' bytes from file descriptor 'file'
|
||||
* into the buffer starting at 'ptr'.
|
||||
* \note currently there is only support for stdin. If any other devices
|
||||
* have to be integrated as well, one should implement an abstraction layer
|
||||
* which delegates the calls directly to the required device or ressource.
|
||||
* An example can be seen in altera board support packages with the "dev" struct
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
int _read( int file, char* ptr, int len )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )file;
|
||||
|
||||
int DataIdx;
|
||||
int resLen = 0;
|
||||
|
||||
if ( file == STDIN_FILENO )
|
||||
{
|
||||
for ( DataIdx = 0; DataIdx < len; )
|
||||
{
|
||||
int result = __stdin_get_char();
|
||||
if ( result == EOF )
|
||||
{
|
||||
if ( resLen == 0 )
|
||||
{
|
||||
resLen = EOF;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
*ptr++ = ( char )result;
|
||||
resLen++;
|
||||
DataIdx++;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( _impure_ptr != 0 )
|
||||
{
|
||||
_impure_ptr->_errno = EBADF;
|
||||
}
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return resLen;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief attempts to write 'len' bytes from file descriptor 'file'
|
||||
* out of the buffer starting at 'ptr'.
|
||||
* \note currently there is only support for stdout and stderr. If any other devices
|
||||
* have to be integrated as well, one should implement an abstraction layer
|
||||
* which delegates the calls directly to the required device or ressource.
|
||||
* An example can be seen in altera board support packages with the "dev" struct
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
int _write( int file, char* ptr, int len )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )file;
|
||||
|
||||
int DataIdx, locked = 0;
|
||||
|
||||
if ( file == STDOUT_FILENO || file == STDERR_FILENO )
|
||||
{
|
||||
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_STDOUT)
|
||||
if ( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
|
||||
{
|
||||
xSemaphoreTakeRecursive( stdioSemaphore, -1 );
|
||||
locked = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (file == STDERR_FILENO)
|
||||
{
|
||||
__stdout_put_char('\033');
|
||||
__stdout_put_char('[');
|
||||
__stdout_put_char('3');
|
||||
__stdout_put_char('1');
|
||||
__stdout_put_char('m');
|
||||
}
|
||||
for ( DataIdx = 0; DataIdx < len; DataIdx++ )
|
||||
{
|
||||
__stdout_put_char( ptr[DataIdx] );
|
||||
}
|
||||
if (file == STDERR_FILENO)
|
||||
{
|
||||
__stdout_put_char('\033');
|
||||
__stdout_put_char('[');
|
||||
__stdout_put_char('0');
|
||||
__stdout_put_char('m');
|
||||
}
|
||||
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_STDOUT)
|
||||
if ( locked )
|
||||
{
|
||||
xSemaphoreGiveRecursive( stdioSemaphore );
|
||||
}
|
||||
#endif
|
||||
|
||||
return len;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( _impure_ptr != 0 )
|
||||
{
|
||||
_impure_ptr->_errno = EBADF;
|
||||
}
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief attempts to close a descriptor.
|
||||
* \note currently there is no support for this function. If any other devices
|
||||
* have to be integrated as well, one should implement an abstraction layer
|
||||
* which delegates the calls directly to the required device or ressource.
|
||||
* An example can be seen in altera board support packages with the "dev" struct
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
int _close( int file )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )file;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief These function returns information about a file, in the buffer
|
||||
* pointed to by stat
|
||||
* \note currently there is only support for stdin/out/err function. If any other devices
|
||||
* have to be integrated as well, one should implement an abstraction layer
|
||||
* which delegates the calls directly to the required device or ressource.
|
||||
* An example can be seen in altera board support packages with the "dev" struct
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
int _fstat( int file, struct stat* st )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
st->st_dev = file;
|
||||
st->st_size = 0;
|
||||
st->st_blocks = 0;
|
||||
|
||||
if ( file >= 1 && file <= 3 )
|
||||
{
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
st->st_mode = S_IFREG;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief checks wether a descriptor 'file' is a TTY device or not
|
||||
* \note currently there is only support for stdin/out/err function. If any other devices
|
||||
* have to be integrated as well, one should implement an abstraction layer
|
||||
* which delegates the calls directly to the required device or ressource.
|
||||
* An example can be seen in altera board support packages with the "dev" struct
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
int _isatty( int file )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
// is stdin, stdout or stderror
|
||||
if ( file >= 0 && file <= 2 )
|
||||
{
|
||||
return file;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int _lseek( int file, int ptr, int dir )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )file;
|
||||
( void )ptr;
|
||||
( void )dir;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int _open( char* path, int flags, ... )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )path;
|
||||
( void )flags;
|
||||
|
||||
/* Pretend like we always fail */
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int _wait( int* status )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )status;
|
||||
|
||||
if ( _impure_ptr != 0 )
|
||||
{
|
||||
_impure_ptr->_errno = ECHILD;
|
||||
}
|
||||
errno = ECHILD;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int _unlink( char* name )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )name;
|
||||
|
||||
if ( _impure_ptr != 0 )
|
||||
{
|
||||
_impure_ptr->_errno = ENOENT;
|
||||
}
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int _times( struct tms* buf )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
buf->tms_utime = buf->tms_cutime = 0; // we have no user space!
|
||||
buf->tms_stime = buf->tms_cstime = __stdlib_get_system_clock_ticks( ); // everything runs in one process!
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int _stat( char* file, struct stat* st )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )file;
|
||||
( void )st;
|
||||
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int _link( char* old, char* new )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )old;
|
||||
( void )new;
|
||||
|
||||
if ( _impure_ptr != 0 )
|
||||
{
|
||||
_impure_ptr->_errno = EMLINK;
|
||||
}
|
||||
errno = EMLINK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int _fork( void )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
if ( _impure_ptr != 0 )
|
||||
{
|
||||
_impure_ptr->_errno = EAGAIN;
|
||||
}
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int _execve( char* name, char** argv, char** env )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )env;
|
||||
( void )name;
|
||||
( void )argv;
|
||||
|
||||
if ( _impure_ptr != 0 )
|
||||
{
|
||||
_impure_ptr->_errno = ENOMEM;
|
||||
}
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
// External routines required by newlib's malloc (sbrk/_sbrk, __malloc_lock/unlock)
|
||||
// ================================================================================================
|
||||
|
||||
#if !defined(INC_FREERTOS_H)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
caddr_t _sbrk( int incr )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
register char* stack_ptr asm( "sp" );
|
||||
|
||||
extern char end asm( "end" );
|
||||
static char* heap_end;
|
||||
char* prev_heap_end;
|
||||
|
||||
if ( heap_end == 0 )
|
||||
{
|
||||
heap_end = &end;
|
||||
}
|
||||
|
||||
prev_heap_end = heap_end;
|
||||
if ( heap_end + incr > stack_ptr )
|
||||
{
|
||||
// write(1, "Heap and stack collision\n", 25);
|
||||
// abort();
|
||||
if ( _impure_ptr != 0 )
|
||||
{
|
||||
_impure_ptr->_errno = ENOMEM;
|
||||
}
|
||||
errno = ENOMEM;
|
||||
return ( caddr_t ) -1;
|
||||
}
|
||||
|
||||
heap_end += incr;
|
||||
|
||||
return ( caddr_t ) prev_heap_end;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int heapBytesRemaining;
|
||||
static unsigned int stickyHeapBytesRemaining;
|
||||
uint32_t TotalHeapSize;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
static UBaseType_t malLock_uxSavedInterruptStatus;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void* _sbrk_r( struct _reent* pReent, int incr )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )malLock_uxSavedInterruptStatus;
|
||||
( void )pReent;
|
||||
( void )incr;
|
||||
register char* stack_ptr asm( "sp" );
|
||||
|
||||
// make sure to calculate the correct heap size and bytes remaining at the first call!
|
||||
if( TotalHeapSize == 0 )
|
||||
{
|
||||
TotalHeapSize = heapBytesRemaining = stickyHeapBytesRemaining
|
||||
= ( int )( ( &__HeapLimit ) - ( &__HeapBase ) )
|
||||
#ifdef configISR_STACK_SIZE_WORDS
|
||||
- ( configISR_STACK_SIZE_WORDS * 4 )
|
||||
#endif
|
||||
;
|
||||
};
|
||||
static char* currentHeapEnd = &__HeapBase;
|
||||
char* limit = ( xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED ) ?
|
||||
stack_ptr : // Before scheduler is started, limit is stack pointer (risky!)
|
||||
&__HeapLimit
|
||||
#ifdef configISR_STACK_SIZE_WORDS
|
||||
- ( configISR_STACK_SIZE_WORDS * 4 )
|
||||
#endif
|
||||
; // Once running, OK to reuse all remaining RAM except ISR stack (MSP) stack
|
||||
DRN_ENTER_CRITICAL_SECTION( malLock_uxSavedInterruptStatus );
|
||||
if ( currentHeapEnd + incr > limit )
|
||||
{
|
||||
// Ooops, no more memory available...
|
||||
#if( configUSE_MALLOC_FAILED_HOOK == 1 )
|
||||
{
|
||||
extern void vApplicationMallocFailedHook( void );
|
||||
DRN_EXIT_CRITICAL_SECTION( malLock_uxSavedInterruptStatus );
|
||||
vApplicationMallocFailedHook();
|
||||
}
|
||||
#elif defined(configHARD_STOP_ON_MALLOC_FAILURE)
|
||||
// If you want to alert debugger or halt...
|
||||
// WARNING: brkpt instruction may prevent watchdog operation...
|
||||
while( 1 )
|
||||
{
|
||||
__asm( "bkpt #0" );
|
||||
}; // Stop in GUI as if at a breakpoint (if debugging, otherwise loop forever)
|
||||
#else
|
||||
// Default, if you prefer to believe your application will gracefully trap out-of-memory...
|
||||
pReent->_errno = ENOMEM; // newlib's thread-specific errno
|
||||
DRN_EXIT_CRITICAL_SECTION( malLock_uxSavedInterruptStatus );
|
||||
#endif
|
||||
return ( char* ) -1; // the malloc-family routine that called sbrk will return 0
|
||||
}
|
||||
|
||||
char* previousHeapEnd = currentHeapEnd;
|
||||
currentHeapEnd += incr;
|
||||
heapBytesRemaining -= incr;
|
||||
|
||||
// implement the statistical feature to provide the minimum free heap size feature
|
||||
// of FreeRTOS statistics
|
||||
if ( stickyHeapBytesRemaining > xPortGetFreeHeapSize() )
|
||||
{
|
||||
stickyHeapBytesRemaining = xPortGetFreeHeapSize();
|
||||
}
|
||||
|
||||
DRN_EXIT_CRITICAL_SECTION( malLock_uxSavedInterruptStatus );
|
||||
return ( char* ) previousHeapEnd;
|
||||
}
|
||||
|
||||
/*! \brief non-reentrant sbrk uses is actually reentrant by using current context
|
||||
* because the current _reent structure is pointed to by global _impure_ptr
|
||||
*/
|
||||
// ----------------------------------------------------------------------------
|
||||
void* sbrk( ptrdiff_t __incr )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
return _sbrk_r( _impure_ptr, __incr );
|
||||
}
|
||||
|
||||
//! _sbrk is a synonym for sbrk.
|
||||
// ----------------------------------------------------------------------------
|
||||
char* _sbrk( int incr )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
return sbrk( incr );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
__attribute__( ( weak ) ) void __malloc_lock( struct _reent* r )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )r;
|
||||
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_MALLOC)
|
||||
if ( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
|
||||
{
|
||||
xSemaphoreTakeRecursive( mallocSemaphore, -1 );
|
||||
}
|
||||
#endif
|
||||
|
||||
DRN_ENTER_CRITICAL_SECTION( malLock_uxSavedInterruptStatus );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
__attribute__( ( weak ) ) void __malloc_unlock( struct _reent* r )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
( void )r;
|
||||
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_MALLOC)
|
||||
if ( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
|
||||
{
|
||||
xSemaphoreGiveRecursive( mallocSemaphore );
|
||||
}
|
||||
#endif
|
||||
|
||||
DRN_EXIT_CRITICAL_SECTION( malLock_uxSavedInterruptStatus );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
__attribute__( ( weak ) ) void __env_lock( void )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_ENV)
|
||||
if ( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
|
||||
{
|
||||
xSemaphoreTakeRecursive( envSemaphore, -1 );
|
||||
}
|
||||
#endif
|
||||
|
||||
DRN_ENTER_CRITICAL_SECTION( malLock_uxSavedInterruptStatus );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
__attribute__( ( weak ) ) void __env_unlock( void )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
#if defined(INC_FREERTOS_H) && defined(MV_SYSCALL_USE_EXCLUSIVE_LOCK_FOR_ENV)
|
||||
if ( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
|
||||
{
|
||||
xSemaphoreGiveRecursive( envSemaphore );
|
||||
}
|
||||
#endif
|
||||
|
||||
DRN_EXIT_CRITICAL_SECTION( malLock_uxSavedInterruptStatus );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void* pvPortMalloc( size_t xSize )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
void* p = malloc( xSize );
|
||||
return p;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void vPortFree( void* pv )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
free( pv );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
size_t xPortGetFreeHeapSize( void )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
static int lockGuard = 0;
|
||||
if ( lockGuard != 0 ) return stickyHeapBytesRemaining;
|
||||
lockGuard = 1;
|
||||
struct mallinfo mi = mallinfo();
|
||||
size_t result = mi.fordblks + heapBytesRemaining;
|
||||
lockGuard = 0;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
size_t xPortGetMinimumEverFreeHeapSize ( void )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
return stickyHeapBytesRemaining;
|
||||
}
|
||||
|
||||
//! No implementation needed, but stub provided in case application already calls vPortInitialiseBlocks
|
||||
// ----------------------------------------------------------------------------
|
||||
void vPortInitialiseBlocks( void )
|
||||
// ----------------------------------------------------------------------------
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,207 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_msp.c
|
||||
* @brief This file provides code for the MSP Initialization
|
||||
* and de-Initialization codes.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Macro */
|
||||
|
||||
/* USER CODE END Macro */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* External functions --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ExternalFunctions */
|
||||
|
||||
/* USER CODE END ExternalFunctions */
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
/**
|
||||
* Initializes the Global MSP.
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN MspInit 0 */
|
||||
|
||||
/* USER CODE END MspInit 0 */
|
||||
|
||||
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
||||
|
||||
/* System interrupt init*/
|
||||
|
||||
/* Peripheral interrupt init */
|
||||
/* CM7_SEV_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(CM7_SEV_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(CM7_SEV_IRQn);
|
||||
/* HSEM2_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(HSEM2_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(HSEM2_IRQn);
|
||||
|
||||
/* USER CODE BEGIN MspInit 1 */
|
||||
|
||||
/* USER CODE END MspInit 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ETH MSP Initialization
|
||||
* This function configures the hardware resources used in this example
|
||||
* @param heth: ETH handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETH_MspInit(ETH_HandleTypeDef* heth)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(heth->Instance==ETH)
|
||||
{
|
||||
/* USER CODE BEGIN ETH_MspInit 0 */
|
||||
|
||||
/* USER CODE END ETH_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_ETH1MAC_CLK_ENABLE();
|
||||
__HAL_RCC_ETH1TX_CLK_ENABLE();
|
||||
__HAL_RCC_ETH1RX_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
/**ETH GPIO Configuration
|
||||
PC1 ------> ETH_MDC
|
||||
PA1 ------> ETH_REF_CLK
|
||||
PA2 ------> ETH_MDIO
|
||||
PA7 ------> ETH_CRS_DV
|
||||
PC4 ------> ETH_RXD0
|
||||
PC5 ------> ETH_RXD1
|
||||
PB13 ------> ETH_TXD1
|
||||
PG11 ------> ETH_TX_EN
|
||||
PG13 ------> ETH_TXD0
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_13;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF11_ETH;
|
||||
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
||||
|
||||
/* ETH interrupt Init */
|
||||
HAL_NVIC_SetPriority(ETH_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(ETH_IRQn);
|
||||
/* USER CODE BEGIN ETH_MspInit 1 */
|
||||
|
||||
/* USER CODE END ETH_MspInit 1 */
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ETH MSP De-Initialization
|
||||
* This function freeze the hardware resources used in this example
|
||||
* @param heth: ETH handle pointer
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETH_MspDeInit(ETH_HandleTypeDef* heth)
|
||||
{
|
||||
if(heth->Instance==ETH)
|
||||
{
|
||||
/* USER CODE BEGIN ETH_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END ETH_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_ETH1MAC_CLK_DISABLE();
|
||||
__HAL_RCC_ETH1TX_CLK_DISABLE();
|
||||
__HAL_RCC_ETH1RX_CLK_DISABLE();
|
||||
|
||||
/**ETH GPIO Configuration
|
||||
PC1 ------> ETH_MDC
|
||||
PA1 ------> ETH_REF_CLK
|
||||
PA2 ------> ETH_MDIO
|
||||
PA7 ------> ETH_CRS_DV
|
||||
PC4 ------> ETH_RXD0
|
||||
PC5 ------> ETH_RXD1
|
||||
PB13 ------> ETH_TXD1
|
||||
PG11 ------> ETH_TX_EN
|
||||
PG13 ------> ETH_TXD0
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOG, GPIO_PIN_11|GPIO_PIN_13);
|
||||
|
||||
/* ETH interrupt DeInit */
|
||||
HAL_NVIC_DisableIRQ(ETH_IRQn);
|
||||
/* USER CODE BEGIN ETH_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ETH_MspDeInit 1 */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
@@ -0,0 +1,259 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2026 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
#include "stm32h7xx_it.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern ETH_HandleTypeDef heth;
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
|
||||
/* USER CODE END MemoryManagement_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
|
||||
/* USER CODE END W1_MemoryManagement_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pre-fetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END BusFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
|
||||
/* USER CODE END W1_BusFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END UsageFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
/* USER CODE END W1_UsageFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SVCall_IRQn 0 */
|
||||
|
||||
/* USER CODE END SVCall_IRQn 0 */
|
||||
/* USER CODE BEGIN SVCall_IRQn 1 */
|
||||
|
||||
/* USER CODE END SVCall_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
||||
#endif
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* USER CODE END DebugMonitor_IRQn 0 */
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
|
||||
}
|
||||
#if 0
|
||||
/* USER CODE END DebugMonitor_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN PendSV_IRQn 0 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 0 */
|
||||
/* USER CODE BEGIN PendSV_IRQn 1 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
#endif
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
extern void xPortSysTickHandler( void );
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
xPortSysTickHandler();
|
||||
}
|
||||
#if 0
|
||||
// mask out the ETH_IRQ_Handler completely because it is provided
|
||||
// by the free rtos tcp ip stack template in NetworkInterface.c
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32H7xx Peripheral Interrupt Handlers */
|
||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||
/* For the available peripheral interrupt handler names, */
|
||||
/* please refer to the startup file (startup_stm32h7xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles Ethernet global interrupt.
|
||||
*/
|
||||
void ETH_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN ETH_IRQn 0 */
|
||||
|
||||
/* USER CODE END ETH_IRQn 0 */
|
||||
HAL_ETH_IRQHandler(&heth);
|
||||
/* USER CODE BEGIN ETH_IRQn 1 */
|
||||
|
||||
/* USER CODE END ETH_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles CM7 send event interrupt for CM4.
|
||||
*/
|
||||
void CM7_SEV_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN CM7_SEV_IRQn 0 */
|
||||
#endif
|
||||
void CM7_SEV_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE END CM7_SEV_IRQn 0 */
|
||||
/* USER CODE BEGIN CM7_SEV_IRQn 1 */
|
||||
|
||||
/* USER CODE END CM7_SEV_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles HSEM2 global interrupt.
|
||||
*/
|
||||
void HSEM2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HSEM2_IRQn 0 */
|
||||
|
||||
/* USER CODE END HSEM2_IRQn 0 */
|
||||
HAL_HSEM_IRQHandler();
|
||||
/* USER CODE BEGIN HSEM2_IRQn 1 */
|
||||
|
||||
/* USER CODE END HSEM2_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file syscalls.c
|
||||
* @author Auto-generated by STM32CubeIDE
|
||||
* @brief STM32CubeIDE Minimal System calls file
|
||||
*
|
||||
* For more information about which c-functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the Newlib libc-manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2020-2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes */
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
|
||||
/* Variables */
|
||||
extern int __io_putchar(int ch) __attribute__((weak));
|
||||
extern int __io_getchar(void) __attribute__((weak));
|
||||
|
||||
|
||||
char *__env[1] = { 0 };
|
||||
char **environ = __env;
|
||||
|
||||
|
||||
/* Functions */
|
||||
void initialise_monitor_handles()
|
||||
{
|
||||
}
|
||||
|
||||
int _getpid(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _kill(int pid, int sig)
|
||||
{
|
||||
(void)pid;
|
||||
(void)sig;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void _exit (int status)
|
||||
{
|
||||
_kill(status, -1);
|
||||
while (1) {} /* Make sure we hang here */
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _read(int file, char *ptr, int len)
|
||||
{
|
||||
(void)file;
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
*ptr++ = __io_getchar();
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _write(int file, char *ptr, int len)
|
||||
{
|
||||
(void)file;
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
__io_putchar(*ptr++);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int _close(int file)
|
||||
{
|
||||
(void)file;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int _fstat(int file, struct stat *st)
|
||||
{
|
||||
(void)file;
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _isatty(int file)
|
||||
{
|
||||
(void)file;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _lseek(int file, int ptr, int dir)
|
||||
{
|
||||
(void)file;
|
||||
(void)ptr;
|
||||
(void)dir;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _open(char *path, int flags, ...)
|
||||
{
|
||||
(void)path;
|
||||
(void)flags;
|
||||
/* Pretend like we always fail */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _wait(int *status)
|
||||
{
|
||||
(void)status;
|
||||
errno = ECHILD;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _unlink(char *name)
|
||||
{
|
||||
(void)name;
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _times(struct tms *buf)
|
||||
{
|
||||
(void)buf;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _stat(char *file, struct stat *st)
|
||||
{
|
||||
(void)file;
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _link(char *old, char *new)
|
||||
{
|
||||
(void)old;
|
||||
(void)new;
|
||||
errno = EMLINK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fork(void)
|
||||
{
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _execve(char *name, char **argv, char **env)
|
||||
{
|
||||
(void)name;
|
||||
(void)argv;
|
||||
(void)env;
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sysmem.c
|
||||
* @author Generated by STM32CubeIDE
|
||||
* @brief STM32CubeIDE System Memory calls file
|
||||
*
|
||||
* For more information about which C functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the newlib libc manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes */
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Pointer to the current high watermark of the heap usage
|
||||
*/
|
||||
static uint8_t *__sbrk_heap_end = NULL;
|
||||
|
||||
/**
|
||||
* @brief _sbrk() allocates memory to the newlib heap and is used by malloc
|
||||
* and others from the C library
|
||||
*
|
||||
* @verbatim
|
||||
* ############################################################################
|
||||
* # .data # .bss # newlib heap # MSP stack #
|
||||
* # # # # Reserved by _Min_Stack_Size #
|
||||
* ############################################################################
|
||||
* ^-- RAM start ^-- _end _estack, RAM end --^
|
||||
* @endverbatim
|
||||
*
|
||||
* This implementation starts allocating at the '_end' linker symbol
|
||||
* The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
|
||||
* The implementation considers '_estack' linker symbol to be RAM end
|
||||
* NOTE: If the MSP stack, at any point during execution, grows larger than the
|
||||
* reserved size, please increase the '_Min_Stack_Size'.
|
||||
*
|
||||
* @param incr Memory size
|
||||
* @return Pointer to allocated memory
|
||||
*/
|
||||
void *_sbrk(ptrdiff_t incr)
|
||||
{
|
||||
extern uint8_t _end; /* Symbol defined in the linker script */
|
||||
extern uint8_t _estack; /* Symbol defined in the linker script */
|
||||
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
|
||||
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
|
||||
const uint8_t *max_heap = (uint8_t *)stack_limit;
|
||||
uint8_t *prev_heap_end;
|
||||
|
||||
/* Initialize heap end at first call */
|
||||
if (NULL == __sbrk_heap_end)
|
||||
{
|
||||
__sbrk_heap_end = &_end;
|
||||
}
|
||||
|
||||
/* Protect heap from growing into the reserved MSP stack */
|
||||
if (__sbrk_heap_end + incr > max_heap)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return (void *)-1;
|
||||
}
|
||||
|
||||
prev_heap_end = __sbrk_heap_end;
|
||||
__sbrk_heap_end += incr;
|
||||
|
||||
return (void *)prev_heap_end;
|
||||
}
|
||||
Reference in new issue
Block a user