Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronize BSP with CMSIS 6 #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
288 changes: 19 additions & 269 deletions CMSIS/Driver/vio_STM32H7B3I-DK.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/******************************************************************************
* @file vio_STM32H7B3I-DK.c
* @brief Virtual I/O driver for STM32H7B3I-DK board
* @version V1.0.1
* @date 9. November 2022
* @version V2.0.0
* @date 9. October 2023
******************************************************************************/
/*
* Copyright (c) 2021-2022 Arm Limited (or its affiliates).
* Copyright (c) 2021-2023 Arm Limited (or its affiliates).
* All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -34,115 +34,33 @@ vioLED0 | vioSignalOut.0 | GPIO G.11: LD3 RED
vioLED1 | vioSignalOut.1 | GPIO G.2: LD2 BLUE |
*/

#include <stdio.h>
/* History:
* Version 2.0.0
* Updated to API 1.0.0
* Version 1.0.0
* Initial release
*/

#include <string.h>
#include <stdarg.h>
#include "cmsis_vio.h"

#include "RTE_Components.h"
#include "RTE_Components.h" // Component selection
#include CMSIS_device_header

#if !defined CMSIS_VOUT || !defined CMSIS_VIN
#include "stm32h7b3i_discovery.h"
#endif

// VIO input, output definitions
#define VIO_PRINT_MAX_SIZE 64U // maximum size of print memory
#define VIO_PRINTMEM_NUM 4U // number of print memories
#define VIO_VALUE_NUM 3U // number of values
#define VIO_VALUEXYZ_NUM 3U // number of XYZ values
#define VIO_IPV4_ADDRESS_NUM 2U // number of IPv4 addresses
#define VIO_IPV6_ADDRESS_NUM 2U // number of IPv6 addresses
#define VIO_VALUE_NUM 3U // Number of values

// VIO input, output variables
__USED uint32_t vioSignalIn; // Memory for incoming signal
__USED uint32_t vioSignalOut; // Memory for outgoing signal
__USED char vioPrintMem[VIO_PRINTMEM_NUM][VIO_PRINT_MAX_SIZE]; // Memory for the last value for each level
__USED int32_t vioValue [VIO_VALUE_NUM]; // Memory for value used in vioGetValue/vioSetValue
__USED vioValueXYZ_t vioValueXYZ[VIO_VALUEXYZ_NUM]; // Memory for XYZ value for 3-D vector
__USED vioAddrIPv4_t vioAddrIPv4[VIO_IPV4_ADDRESS_NUM]; // Memory for IPv4 address value used in vioSetIPv4/vioGetIPv4
__USED vioAddrIPv6_t vioAddrIPv6[VIO_IPV6_ADDRESS_NUM]; // Memory for IPv6 address value used in vioSetIPv6/vioGetIPv6
__USED uint32_t vioSignalIn; // Memory for incoming signal
__USED uint32_t vioSignalOut; // Memory for outgoing signal
__USED int32_t vioValue[VIO_VALUE_NUM]; // Memory for value used in vioGetValue/vioSetValue

#if !defined CMSIS_VOUT
// Global types, variables, functions
static char ip_ascii[40]; // string buffer for IP address conversion

/**
convert IP4 address to ASCII

\param[in] ip4_addr pointer to IP4 address.
\param[out] buf pointer to ascii buffer.
\param[in] buf_len length of a buffer (16 bytes)
*/
static void ip4_2a (const uint8_t *ip4_addr, char *buf, uint32_t buf_len) {
if (buf_len < 16U) {
return;
}
sprintf(buf, "%d.%d.%d.%d", ip4_addr[0], ip4_addr[1], ip4_addr[2], ip4_addr[3]);
}

/**
convert IP6 address to ASCII

\param[in] ip6_addr pointer to IP6 address.
\param[out] buf pointer to ascii buffer.
\param[in] buf_len length of a buffer (40 bytes)
*/
static void ip6_2a (const uint8_t *ip6_addr, char *buf, uint32_t buf_len) {
uint16_t v16[8];
int32_t i, j, nmax, idx;

if (buf_len < 40U) {
return;
}

/* Read IPv6 address in hextets */
for (i = 0; i < 16; i += 2) {
v16[i >> 1] = (uint16_t)(ip6_addr[i] << 8) | ip6_addr[i+1];
}

/* Find the largest block of consecutive zero hextets */
idx = 8;
for (i = nmax = 0; i < 8-1; i++) {
if (v16[i] != 0U) {
continue;
}
for (j = i; j < 8-1; j++) {
if (v16[j+1] != 0U) {
break;
}
}
if (i == j) {
continue;
}
if ((j - i) >= nmax) {
/* Remember position and count */
nmax = j - i + 1;
idx = i;
}
/* Skip already processed zero hextets */
i = j;
}
for (i = j = 0; i < idx; ) {
j += sprintf(&buf[j], "%x", v16[i]);
if (++i == idx) {
break;
}
buf[j++] = ':';
}
if (i < 8) {
/* Right-end not yet complete */
buf[j++] = ':';
for (i += nmax; i < 8; i++) {
j += sprintf(&buf[j], ":%x", v16[i]);
}
if (buf[j-1] == ':') {
buf[j++] = ':';
}
}
/* Make string null-terminated */
buf[j] = 0;
}
// Add global user types, variables, functions here:

#endif

Expand All @@ -165,11 +83,7 @@ void vioInit (void) {
vioSignalIn = 0U;
vioSignalOut = 0U;

memset(vioPrintMem, 0, sizeof(vioPrintMem));
memset(vioValue, 0, sizeof(vioValue));
memset(vioValueXYZ, 0, sizeof(vioValueXYZ));
memset(vioAddrIPv4, 0, sizeof(vioAddrIPv4));
memset(vioAddrIPv6, 0, sizeof(vioAddrIPv6));
memset(vioValue, 0, sizeof(vioValue));

#if !defined CMSIS_VOUT
// Initialize LEDs pins
Expand All @@ -185,35 +99,6 @@ void vioInit (void) {
}

// Print formatted string to test terminal.
int32_t vioPrint (uint32_t level, const char *format, ...) {
va_list args;
int32_t ret;
#if !defined CMSIS_VOUT
// Add user variables here:

#endif

if (level > vioLevelError) {
return (-1);
}

if (level > VIO_PRINTMEM_NUM) {
return (-1);
}

va_start(args, format);

ret = vsnprintf((char *)vioPrintMem[level], sizeof(vioPrintMem[level]), format, args);

va_end(args);

#if !defined CMSIS_VOUT
// Add user code here:

#endif

return (ret);
}

// Set signal output.
void vioSetSignal (uint32_t mask, uint32_t signal) {
Expand Down Expand Up @@ -264,9 +149,9 @@ uint32_t vioGetSignal (uint32_t mask) {
}
#endif

signal = vioSignalIn;
signal = vioSignalIn & mask;

return (signal & mask);
return signal;
}

// Set value output.
Expand Down Expand Up @@ -312,138 +197,3 @@ int32_t vioGetValue (uint32_t id) {

return value;
}

// Set XYZ value output.
void vioSetXYZ (uint32_t id, vioValueXYZ_t valueXYZ) {
uint32_t index = id;
#if !defined CMSIS_VOUT
// Add user variables here:

#endif

if (index >= VIO_VALUEXYZ_NUM) {
return; /* return in case of out-of-range index */
}

vioValueXYZ[index] = valueXYZ;

#if !defined CMSIS_VOUT
// Add user code here:

#endif
}

// Get XYZ value input.
vioValueXYZ_t vioGetXYZ (uint32_t id) {
uint32_t index = id;
vioValueXYZ_t valueXYZ = {0, 0, 0};
#if !defined CMSIS_VIN
// Add user variables here:

#endif

if (index >= VIO_VALUEXYZ_NUM) {
return valueXYZ; /* return default in case of out-of-range index */
}

#if !defined CMSIS_VIN
// Add user code here:

// vioValueXYZ[index] = ...;
#endif

valueXYZ = vioValueXYZ[index];

return valueXYZ;
}

// Set IPv4 address output.
void vioSetIPv4 (uint32_t id, vioAddrIPv4_t addrIPv4) {
uint32_t index = id;
#if !defined CMSIS_VOUT
// Add user variables here:

#endif

if (index >= VIO_IPV4_ADDRESS_NUM) {
return; /* return in case of out-of-range index */
}

vioAddrIPv4[index] = addrIPv4;

#if !defined CMSIS_VOUT
// Convert IP4 address to ASCII
ip4_2a((uint8_t *)&vioAddrIPv4[index], ip_ascii, sizeof(ip_ascii));

#endif
}

// Get IPv4 address input.
vioAddrIPv4_t vioGetIPv4 (uint32_t id) {
uint32_t index = id;
vioAddrIPv4_t addrIPv4 = { {0U, 0U, 0U, 0U} };
#if !defined CMSIS_VIN
// Add user variables here:

#endif

if (index >= VIO_IPV4_ADDRESS_NUM) {
return addrIPv4; /* return default in case of out-of-range index */
}

#if !defined CMSIS_VIN
// Add user code here:

// vioAddrIPv4[index] = ...;
#endif

addrIPv4 = vioAddrIPv4[index];

return addrIPv4;
}

// Set IPv6 address output.
void vioSetIPv6 (uint32_t id, vioAddrIPv6_t addrIPv6) {
uint32_t index = id;
#if !defined CMSIS_VOUT
// Add user variables here:

#endif

if (index >= VIO_IPV6_ADDRESS_NUM) {
return; /* return in case of out-of-range index */
}

vioAddrIPv6[index] = addrIPv6;

#if !defined CMSIS_VOUT
// Convert IP6 address to ASCII
ip6_2a((uint8_t *)&vioAddrIPv6[index], ip_ascii, sizeof(ip_ascii));

#endif
}

// Get IPv6 address input.
vioAddrIPv6_t vioGetIPv6 (uint32_t id) {
uint32_t index = id;
vioAddrIPv6_t addrIPv6 = { {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U,
0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U} };
#if !defined CMSIS_VIN
// Add user variables here:

#endif

if (index >= VIO_IPV6_ADDRESS_NUM) {
return addrIPv6; /* return default in case of out-of-range index */
}

#if !defined CMSIS_VIN
// Add user code here:

// vioAddrIPv6[index] = ...;
#endif

addrIPv6 = vioAddrIPv6[index];

return addrIPv6;
}
13 changes: 12 additions & 1 deletion Keil.STM32H7B3I-DK_BSP.pdsc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
<license>LICENSE</license>

<releases>
<release version="1.1.0-dev0">
Drivers:
- CMSIS-Driver VIO:
-- Update VIO to API 1.0.0
Example projects:
- Update projects to CMSIS 6
- Migrate Event Recorder component (from Compiler to CMSIS-View pack)
- Platform:
-- Migrate STDIO components (from Compiler to CMSIS-Compiler pack)
-- Update README.md
</release>
<release version="1.0.1-dev2">
Pack Description:
- Add LICENSE file
Expand Down Expand Up @@ -303,7 +314,7 @@
</bundle>

<!-- STM32H7B3I-DK Board VIO driver -->
<component Cclass="CMSIS Driver" Cgroup="VIO" Csub="Board" Cvariant="STM32H7B3I-DK" Cversion="1.0.1" Capiversion="0.1.0" condition="STM32H7B3-DK VIO">
<component Cclass="CMSIS Driver" Cgroup="VIO" Csub="Board" Cvariant="STM32H7B3I-DK" Cversion="2.0.0" Capiversion="1.0.0" condition="STM32H7B3-DK VIO">
<description>STMicroelectronics STM32H7B3I-DK Board Virtual I/O driver</description>
<RTE_Components_h>
#define RTE_VIO_BOARD
Expand Down
2 changes: 0 additions & 2 deletions Projects/Blinky/Blinky.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ __NO_RETURN static void thrButton (void *arg) {
static void app_main (void *argument) {
(void)argument;

vioPrint(vioLevelHeading, "Blinky");

tid_thrLED = osThreadNew(thrLED, NULL, NULL); // Create LED thread
if (tid_thrLED == NULL) { /* add error handling */ }

Expand Down
Loading