Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions generator/C/include_v2.0/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
#define MAVLINK_STACK_BUFFER 0
#endif

/* aligned buffer macro for platforms that require it */
#ifndef MAVLINK_ALIGNED_BUF
#if defined(__GNUC__) && (defined(__arm__) || defined(__XTENSA__))
// ESP32 (Xtensa) and ARM platforms need aligned buffers for float/int access
#include <stdalign.h>
#define MAVLINK_ALIGNED_BUF(name, size) alignas(4) char name[size]
#else
// Default: no special alignment needed
#define MAVLINK_ALIGNED_BUF(name, size) char name[size]
#endif
#endif

#ifndef MAVLINK_AVOID_GCC_STACK_BUG
# define MAVLINK_AVOID_GCC_STACK_BUG defined(__GNUC__)
#endif
Expand Down
8 changes: 4 additions & 4 deletions generator/mavgen_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def generate_message_h(directory, m):
${{arg_fields: ${array_const}${type} ${array_prefix}${name},}})
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char buf[MAVLINK_MSG_ID_${name}_LEN];
MAVLINK_ALIGNED_BUF(buf, MAVLINK_MSG_ID_${name}_LEN);
${{scalar_fields: _mav_put_${type}(buf, ${wire_offset}, ${putname});
}}
${{array_fields: _mav_put_${type}_array(buf, ${wire_offset}, ${name}, ${array_length});
Expand Down Expand Up @@ -251,7 +251,7 @@ def generate_message_h(directory, m):
${{arg_fields: ${array_const}${type} ${array_prefix}${name},}})
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char buf[MAVLINK_MSG_ID_${name}_LEN];
MAVLINK_ALIGNED_BUF(buf, MAVLINK_MSG_ID_${name}_LEN);
${{scalar_fields: _mav_put_${type}(buf, ${wire_offset}, ${putname});
}}
${{array_fields: _mav_put_${type}_array(buf, ${wire_offset}, ${name}, ${array_length});
Expand Down Expand Up @@ -289,7 +289,7 @@ def generate_message_h(directory, m):
${{arg_fields:${array_const}${type} ${array_prefix}${name},}})
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char buf[MAVLINK_MSG_ID_${name}_LEN];
MAVLINK_ALIGNED_BUF(buf, MAVLINK_MSG_ID_${name}_LEN);
${{scalar_fields: _mav_put_${type}(buf, ${wire_offset}, ${putname});
}}
${{array_fields: _mav_put_${type}_array(buf, ${wire_offset}, ${name}, ${array_length});
Expand Down Expand Up @@ -361,7 +361,7 @@ def generate_message_h(directory, m):
static inline void mavlink_msg_${name_lower}_send(mavlink_channel_t chan,${{arg_fields: ${array_const}${type} ${array_prefix}${name},}})
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
char buf[MAVLINK_MSG_ID_${name}_LEN];
MAVLINK_ALIGNED_BUF(buf, MAVLINK_MSG_ID_${name}_LEN);
${{scalar_fields: _mav_put_${type}(buf, ${wire_offset}, ${putname});
}}
${{array_fields: _mav_put_${type}_array(buf, ${wire_offset}, ${name}, ${array_length});
Expand Down
Loading