moved to stm32l4a6zg-f0x.at1 folder

This commit is contained in:
2024-10-15 21:10:31 +02:00
parent 2c8881338d
commit 420f22aa82
167 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,242 @@
/**
******************************************************************************
* @file commands.c
* @brief command.c file, the command interpreter, a generic one
******************************************************************************
* @author: Thomas Kuschel KW4NZ
* created 2022-06-04
*
******************************************************************************/
#include "main.h"
#include "at1_defines.h"
#include "cmsis_os.h"
#include <stdint.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h> //strchr
#include <stdlib.h> //bsearch
#include "helper.h" //ltrim
#include "si5351.h"
#include "commands.h"
/*
typedef struct command_ctx_s {
osThreadId_t thread_id;
osMutexId_t mutex;
char *last_cmd;
size_t last_cmd_size;
} command_ctx_t;
*/
typedef enum {
CMD_NO_FLAG = 0x00,
CMD_HIDDEN = 0x01, /*!< Not shown in help but listed with "help all" or with "?" */
CMD_SECRET = 0x02, /*!< Not shown in help - hidden and secret commands */
CMD_ADMIN = 0x04, /*!< Only an administrator or privileged person can use this command */
CMD_NOT_IMPLEMENTED = 0x80 /*!< A command which is not implemented yet */
} cmd_flags_t;
#define CMD_LENGTH 16
#define MAXLINELENGTH 40
typedef struct {
const char name[CMD_LENGTH]; /*!< command name */
const uint8_t significantlength; /*!< length of command for the compare function */
const uint8_t flag; /*!< command flags, i.e. CMD_HIDDEN, CMD_SECRET, CMD_ADMIN, etc. */
int (*func)(/*command_ctx_t *ctx,*/ char *args);
} cmd_table_t;
// the entries must be in alphabetical order due to the binary search
static const cmd_table_t cmd_table[] = {
{"admin", 2, CMD_ADMIN, do_test },
{"altitude", 1, CMD_NO_FLAG, do_test },
{"date", 1, CMD_NO_FLAG, do_time },
{"devid", 3, CMD_HIDDEN, do_devid },
{"help", 1, CMD_NO_FLAG, do_help },
{"hidden", 2, CMD_HIDDEN, do_test },
{"info", 1, CMD_NO_FLAG, do_info },
{"sinfo", 1, CMD_SECRET, do_sinfo },
{"time", 1, CMD_NO_FLAG, do_time },
};
int do_test(char *args) {
(void) *args;
printf("not implemented.\n");
return 0;
}
/*!
* @brief compares two strings up to n characters, and next gets the pointer to the 2nd word in the string s1
*
* @pre s1, s2 and n not allowed to be 0
*
* @param s1
* @param next
* @param s2
* @param n
* @return int if the s1 and s2 are the same till n characters its 0, if s1 > s2 it becomes 1, else -1
*/
int cmdncasecmp(const char *s1, char **next, const char *s2, size_t n)
{
if (n == 0 || s1 == NULL || s2 == NULL) {
if (next) *next = NULL;
if (s2 == NULL && s1 != NULL) return 1;
if (s1 == NULL && s2 != NULL) return -1;
return 0;
}
int ret;
while ((ret = ((unsigned char)tolower(*s1) - (unsigned char)tolower(*s2))) == 0
&& *s1 != ' ' && *s1 && *s2) {
if (n) n--;
s1++;
s2++;
}
if (next) *next = (char *) s1;
if (n == 0 && (*s1 == ' ' || !*s1))
return 0;
return ret;
}
static int compar(const void *a, const void *b)
{
cmd_table_t * cmd = (cmd_table_t *)b;
return cmdncasecmp(a, NULL, cmd->name, cmd->significantlength);
}
int cmd_interpreter(char * cmdline) {
char * ptr;
const cmd_table_t *entry;
int rv = 0;
ptr = strchr(cmdline, ' ');
if (ptr) {
*ptr = '\0';
ptr++;
ptr = ltrim(ptr);
}
entry = bsearch(cmdline, cmd_table, sizeof(cmd_table)/sizeof(cmd_table[0]), sizeof(cmd_table[0]), compar);
if (entry == NULL) {
printf("Command \"%s\" not found.\n", cmdline);
} else {
printf("Command \"%s\":\n", entry->name);
if (*ptr != '\0')
printf("called with parameter: \"%s\"\n", ptr);
rv = entry->func(ptr);
}
return rv;
}
int do_devid(char *args) {
(void)args;
union myUnion {
uint32_t myint[2];
char mychar[8];
} my;
//char lot[sizeof(my) + 1];
printf("DEVID: 0x%08lx\n", HAL_GetDEVID());
printf("REVID: 0x%08lx\n", HAL_GetREVID());
printf("UID: 0x%08lx %08lx %08lx\n", HAL_GetUIDw2(), HAL_GetUIDw1(), HAL_GetUIDw0());
my.myint[1] = HAL_GetUIDw2();
my.myint[0] = HAL_GetUIDw1();
//memcpy(lot, my.mychar, sizeof(my.mychar));
//lot[sizeof(my)] = '\0';
printf("=> Lot Number: %.8s\n", my.mychar);
printf("=> Wafer Number: %u\n", (uint8_t)(HAL_GetUIDw1() & 0xff));
return 0;
}
int do_info(char *args) {
(void)args;
print_system_info();
return 0;
}
int do_sinfo(char *args) {
int rv = 0;
(void)args;
si5351_inst_t inst = NULL;
rv = si5351_get_instance(&inst);
printf("%d Si5351 instance%s found.\n", rv, (rv==1)?"":"s");
while (rv > 0) {
printf("Si5351 Handle: 0x%08lx\n", (uint32_t)inst);
rv = si5351_get_instance(&inst);
}
return rv;
}
int do_time(char *args) {
HAL_StatusTypeDef status;
RTC_TimeTypeDef stime = {0};
RTC_DateTypeDef sdate = {0};
int rv = 0;
if (args) {
struct _tm_ tp;
rv = strtotime (args, &tp);
if (rv > 0) {
printf("%02d%02d-%02d-%02d %02d:%02d:%02d\n", (tp.year < DATE_COMPILE_YEAR) ? DATE_COMPILE_CENTURY + 1 : DATE_COMPILE_CENTURY, \
tp.year, tp.mon, tp.day, tp.hour, tp.min, tp.sec);
/** Initialize RTC and set the Time and Date */
stime.Hours = (uint8_t)tp.hour;
stime.Minutes = (uint8_t)tp.min;
stime.Seconds = (uint8_t)tp.sec;
stime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
stime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &stime, RTC_FORMAT_BIN) != HAL_OK) {
Error_Handler();
}
sdate.WeekDay = RTC_WEEKDAY_MONDAY;
sdate.Month = (uint8_t)tp.mon;
sdate.Date = (uint8_t)tp.day;
sdate.Year = (uint8_t)tp.year;
//uint8_t weekday;
//weekday = dayofweek((tp.year < DATE_COMPILE_YEAR) ? DATE_COMPILE_CENTURY + 1 : DATE_COMPILE_CENTURY, sdate.Year, sdate.Month, sdate.Date);
//printf("Wochentag: %d\n", weekday);
if (HAL_RTC_SetDate(&hrtc, &sdate, RTC_FORMAT_BIN) != HAL_OK) {
Error_Handler();
}
}
}
status = HAL_RTC_GetTime(&hrtc, &stime, RTC_FORMAT_BIN);
if (status != HAL_OK)
puts("HAL_RTC_GetTime problem...");
status = HAL_RTC_GetDate(&hrtc, &sdate, RTC_FORMAT_BIN);
printf("%02d%02d-%02d-%02d %02d:%02d:%02d\n", (sdate.Year < DATE_COMPILE_YEAR) ? DATE_COMPILE_CENTURY + 1 : DATE_COMPILE_CENTURY, \
sdate.Year, sdate.Month, sdate.Date, stime.Hours, stime.Minutes, stime.Seconds);
return rv;
}
int do_help(char *args) {
int all = cmdncasecmp(args, NULL, "all", 1);
const cmd_table_t *cmd = cmd_table;
int j = 0;
int n = 0;
int rv = 0;
puts("Commands:");
for (size_t i = 0; i < (sizeof(cmd_table)/sizeof(cmd_table[0])); i++, cmd++) {
if (cmd->flag != CMD_SECRET && (cmd->flag != CMD_HIDDEN || !all)) {
if (n >= MAXLINELENGTH) {
puts(",");
n = 0;
}
// n += printf("%s%s (%.*s)", n?", ":"", cmd->name, cmd->significantlength, cmd->name);
n += printf("%s(%.*s)%s", n?", ":"", cmd->significantlength, cmd->name, cmd->name + cmd->significantlength);
j++;
}
}
printf("\n%d commands found.\n", j);
return rv;
}

View File

@ -0,0 +1,59 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : freertos.c
* Description : Code for freertos applications
******************************************************************************
* @attention
*
* Copyright (c) 2022 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 "FreeRTOS.h"
#include "task.h"
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* 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 Variables */
/* USER CODE END Variables */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
/* USER CODE END FunctionPrototypes */
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
/* USER CODE END Application */

View File

@ -0,0 +1,150 @@
/*
* helper.c
*
* Created on: Jul 14, 2022
* Author: tom
*/
#include <string.h>
#include <ctype.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h> /* sscanf */
#include <at1_defines.h> /* include my defines from a global view, else */
#ifndef DATE_COMPILE_CENTURY
#define DATE_COMPILE_CENTURY (20)
#define DATE_COMPILE_YEAR (22)
#endif
#if !defined _SYS_ERRNO_H_ && !defined __ERRNO_H__ && !defined __AT1_ERROR_NUMBERS__
#include <errno.h>
#endif
/* do not use the #include <time.h> library */
#include "helper.h"
char *ltrim(char *s)
{
while(isspace((int)*s)) s++;
return s;
}
char *rtrim(char *s)
{
char* back = s + strlen(s);
while(isspace((int)*--back));
*(back+1) = '\0';
return s;
}
char *trim(char *s)
{
return rtrim(ltrim(s));
}
/* this is ISO 8601 2018-12-31 with separator == '-' */
int strtotime (char *s, struct _tm_ *tp) {
int rv = 0;
uint32_t tmp;
struct _tm_ tm = {0};
do {
/* Check for the day and/or year */
tmp = strtoul(s, &s, 10); /* base 10 */
/* Check of plausibility: Year must be within compilation year and max 10 centuries from now on, i.e. 3000 */
if (tmp >= (DATE_COMPILE_CENTURY * 100 + DATE_COMPILE_YEAR) && tmp < ((DATE_COMPILE_CENTURY + 10) * 100)) {
tm.year = (uint8_t)(tmp % 100UL);
} else {
rv = -EINVAL;
break;
}
rv = sscanf(s, "-%hu-%hu %hu:%hu:%hu", &tm.mon, &tm.day, &tm.hour, &tm.min, &tm.sec);
if (rv >= 3)
*tp = tm;
else
rv = -EINVAL;
} while(0);
return rv;
}
#if 0
while (*str == ' ') {
str++;
};
*args = str;
return CMD_OK;
} else {
separator = '/';
if (tmp > 0 && tmp < 32)
timeinfo.tm_mday = tmp;
else
goto error;
}
str++;
/* Read the month */
tmp = strtoul(str, &str, 10);
if (*str != separator || tmp == 0 || tmp > 12)
goto error;
timeinfo.tm_mon = tmp - 1; /* the month is interpreted from 0..11 */
str++;
/* Check either the day or the four-digit year */
tmp = strtoul(str, &str, 10);
/* there should either spaces or a T between date and time info */
if ((toupper(*str) != 'T' && *str != ' ') || tmp == 0 || tmp >= 2106)
goto error;
if (separator == '-') {
timeinfo.tm_mday = tmp;
} else if (tmp >= FW_VERSION_YEAR) {
timeinfo.tm_year = tmp - 1900;
} else {
goto error;
}
do {
str++;
} while (*str == ' ');
/* the hour have to be 0..23 */
tmp = strtoul(str, &str, 10);
if (*str != ':' || tmp > 23)
goto error;
timeinfo.tm_hour = tmp;
str++;
/* the minute have to be 0..59 */
tmp = strtoul(str, &str, 10);
if (tmp > 59)
goto error;
timeinfo.tm_min = tmp;
if (*str == ':') {
str++;
tmp = strtoul(str, &str, 10);
} else {
tmp = 0;
}
if (tmp > 59)
goto error;
timeinfo.tm_sec = tmp;
while (*str == ' ')
str++;
if (*str != '\0' && (flags & ARG_LAST))
goto error;
/* Try to create the time stamp */
{
time_t tmp_unixtime = mktime(&timeinfo);
if (tmp_unixtime == (unsigned)-1) {
goto error;
}
*args = str;
*unixtime = tmp_unixtime;
}
return CMD_OK;
error:
*args = str;
return CMD_ERROR_PARAMETERS;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,311 @@
/**
******************************************************************************
* @file ringbuf.c
* @brief driver for a ring buffer used for UART RX
******************************************************************************
* @author: Thomas Kuschel KW4NZ
* created 2022-07-12
*
* A description can be found in the header file ringbuf.h
******************************************************************************/
#include <stdint.h>
#include <stddef.h>
#include <limits.h>
#include <stdlib.h> /* malloc */
#include <stdio.h> /* printf */
#include <string.h> /* memcpy */
#include "ringbuf.h"
/* macros */
#define MEM_USED(b) ((b->size + b->head - b->tail) % b->size)
#define MEM_FREE(b) ((b->size + b->tail - b->head - 1) % b->size + 1)
#if RING_STATISTICS_ENABLED
typedef struct stat {
uint32_t overflows;
uint32_t reads;
uint32_t writes;
} stat_t;
#endif
typedef struct ringbuf {
#if RING_STATISTICS_ENABLED
stat_t statistics;
#endif
ringbuf_rcv_cb_t rcv_callback;
void *rcv_cb_data;
uint8_t *buf;
uint16_t size;
uint16_t head;
uint16_t tail;
uint16_t delimiterfound;
uint16_t max_read_len;
unsigned full :1; // not implemented yet
unsigned halffull:1; // not implemented yet
unsigned overflow:1;
unsigned allowoverwrite:1;
} ringbuf_t;
struct ringbuf * ringbuf_create(size_t size, ringbuf_param_t param) {
struct ringbuf * rb;
if (size == 0 || size > USHRT_MAX)
return NULL;
// rb = malloc(sizeof(ringbuf_t) + size * sizeof(uint8_t));
rb = calloc(1, sizeof(ringbuf_t) + size * sizeof(uint8_t));
if (rb == NULL) {
puts("Memory not allocated.");
exit(0);
} else {
//puts("Memory successfully allocated.");
// the data area is connected to the structure
rb->buf = (uint8_t *)rb + sizeof(ringbuf_t);
rb->size = (uint16_t)size;
// rb->head = rb->tail = rb->halffull = rb->overflow 0;
if (param & RINGBUF_ALLOWOVERWRITE)
rb->allowoverwrite = 1;
rb->max_read_len = RINGBUF_MAX_READ_LEN;
}
return rb;
}
void ringbuf_destroy(struct ringbuf *ring) {
if (ring != 0)
free(ring);
}
int ringbuf_dump(struct ringbuf *ring) {
if (ring == NULL)
return -EINVAL;
printf("Buffer: 0x%08x\n", (unsigned int) ring);
printf("Start: 0x%08x\n", (unsigned int) ring->buf);
printf("Size: total: %d used: %d free: %d\n", ring->size, MEM_USED(ring), MEM_FREE(ring));
printf("Head: %d\n", ring->head);
printf("Tail: %d\n", ring->tail);
printf("Empty: %s\n", (ring->head == ring->tail) ? "yes" : "no");
printf("Max read length: %d\n", ring->max_read_len);
for (size_t i = 0; i < ring->size; i += 16 ) {
for (size_t j = 0; j < 16 && (j + i) < ring->size; j++) {
//printf("%02x%s", *(ring->buf +i), ((i%4)==3)?(((i%16)==15)?"\n":" "):"");
printf("%02x%s", *(ring->buf + i + j), ((j%4)==3)?" ":"");
}
putchar(' ');
for (size_t j = 0; j < 16 && (j + i) < ring->size; j++) {
uint8_t b = *(ring->buf + i + j);
printf("%c", ((b >= ' ') && (b < 127))? b: '.');
}
puts("");
}
return 0;
}
int ringbuf_push(struct ringbuf *ring, const uint8_t *data, size_t size) {
size_t delimiterpos;
size_t delimiterfound = 0;
uint16_t head;
uint8_t *ptr;
if (ring == NULL || size == 0 || data == NULL || size > USHRT_MAX)
return -EINVAL;
if (size >= ring->size)
return -ENOMEM;
if (size >= (size_t)MEM_FREE(ring)) { // no free space available, but overwrite ?
#if RING_STATISTICS_ENABLED
ring->statistics.overflows++;
#endif
if (ring->allowoverwrite)
ring->overflow = 1;
else
return -ENOMEM;
}
head = ring->head;
if (head + size > ring->size) {
uint16_t remaining = ring->size - head;
memcpy(ring->buf + head, data, remaining);
ring->head = (uint16_t)(size - remaining);
memcpy(ring->buf, data + remaining, ring->head);
} else {
memcpy(ring->buf + head, data, size);
ring->head += (uint16_t)size;
}
for (delimiterpos = 0; delimiterpos < size; delimiterpos++) {
if (data[delimiterpos] == '\n' || data[delimiterpos] == 0 ) {
delimiterfound++;
ptr = ring->buf + ((head + delimiterpos) % ring->size);
*ptr = 0;
}
}
ring->head %= ring->size;
#if RING_STATISTICS_ENABLED
ring->statistics.writes +=size;
#endif
ring->delimiterfound = (uint16_t)delimiterfound;
//call registered callback function
if (ring->delimiterfound && ring->rcv_callback != NULL)
ring->rcv_callback(ring->delimiterfound, ring->rcv_cb_data);
return (int)size;
}
int ringbuf_clear(struct ringbuf *ring) {
if (ring == NULL)
return -EINVAL;
ring->tail = ring->head;
ring->full = ring->halffull = ring->overflow = 0;
return 0;
}
int ringbuf_is_empty(struct ringbuf *ring) {
if (ring == NULL)
return -EINVAL;
return (ring->tail == ring->head);
}
int ringbuf_pull(struct ringbuf *ring, uint8_t *data, size_t maxsize) {
size_t datasize;
if (ring == NULL || maxsize == 0 || data == NULL || maxsize > USHRT_MAX)
return -EINVAL;
datasize = min(maxsize, (size_t)MEM_USED(ring));
if (datasize > ring->size)
return -ENOMEM;
if ((ring->head > ring->tail) /*|| ring->full*/) {
memcpy(data, ring->buf + ring->tail, datasize);
ring->tail += (uint16_t)datasize;
} else {
if (ring->head < ring->tail) {
size_t remaining = ring->size -ring->tail;
if (datasize < remaining) {
memcpy(data, ring->buf + ring->tail, datasize);
ring->tail += (uint16_t)datasize;
} else {
memcpy(data, ring->buf + ring->tail, remaining);
ring->tail = (uint16_t)(datasize - remaining);
memcpy(data + remaining, ring->buf, ring->tail);
}
}
}
#if RING_STATISTICS_ENABLED
ring->statistics.reads += datasize;
#endif
ring->overflow = 0;
return (int)datasize;
}
int ringbuf_read(struct ringbuf *ring, char *str) {
int len = 0;
uint16_t tail = 0;
if (ring == NULL || str == NULL)
return -EINVAL;
*str = '\0';
if (ring->head == ring->tail){
return 0;
}
tail = ring->tail;
if (ring->head > ring->tail) {
if (ring->max_read_len < 2)
return -ENOMEM;
strncpy(str, (char *)(ring->buf + ring->tail), ring->max_read_len);
str[ring->max_read_len] = '\0';
for (int i = ring->tail; i < ring->head; i++) {
if (*(ring->buf + i) == 0) {
ring->tail = (uint16_t)i + 1;
break;
}
}
if (ring->tail == tail) {
// no \0 found
return 0;
}
} else {
int continu = 1;
int tail = 0;
strncpy(str, (char *)(ring->buf + ring->tail),(size_t)min(ring->size - ring->tail, ring->max_read_len));
str[ring->max_read_len] = '\0';
len = (int)strlen(str);
for (int i = ring->tail; i < ring->size; i++) {
if (*(ring->buf + i) == 0) {
tail = i + 1;
continu = 0;
break;
}
}
if (continu) {
strncpy(str + ring->size - ring->tail, (char *)ring->buf, (size_t)(ring->max_read_len - ring->size + ring->tail));
str[ring->max_read_len] = '\0';
continu = 1;
for (int i = 0; i < ring->head; i++) {
if (*(ring->buf + i) == 0) {
tail = i + 1;
continu = 0;
break;
}
}
if (continu)
return -EINVAL;
}
ring->tail = (uint16_t)tail;
}
len = (int)strlen(str);
ring->tail = ring->tail % ring->size;
#if RING_STATISTICS_ENABLED
ring->statistics.reads += (uint32_t)len + 1;
#endif
return len;
}
int ringbuf_write(struct ringbuf *ring, char *str) {
size_t len = 0;
len = (size_t)strlen(str);
if (len > 0)
return ringbuf_push(ring, (uint8_t *)str, len + 1);
else
return -EINVAL;
}
#if RING_STATISTICS_ENABLED
int ringbuf_statistics(struct ringbuf *ring) {
if (ring == NULL)
return -EINVAL;
puts("Ring Buffer Statistics:");
printf(" Bytes written: %ld\n", ring->statistics.writes);
printf(" Bytes read: %ld\n", ring->statistics.reads);
printf("# of overflows: %ld\n", ring->statistics.overflows);
return 0;
}
int ringbuf_stat_writes(struct ringbuf *ring) {
if (ring == NULL)
return -EINVAL;
return (int)ring->statistics.writes;
}
int ringbuf_stat_reads(struct ringbuf *ring) {
if (ring == NULL)
return -EINVAL;
return (int)ring->statistics.reads;
}
int ringbuf_stat_overflow(struct ringbuf *ring) {
if (ring == NULL)
return -EINVAL;
return (int)ring->statistics.overflows;
}
#endif
int ringbuf_callback_register(struct ringbuf *ring, ringbuf_rcv_cb_t cb_func, void *cb_data) {
if (ring == NULL)
return -EINVAL;
ring->rcv_callback = cb_func;
ring->rcv_cb_data = cb_data;
return 0;
}

View File

@ -0,0 +1,144 @@
/*
* ringbuf_test.c
*
* Created on: Jul 14, 2022
* Author: tom
*/
#include <assert.h>
#include <stdio.h>
#include "ringbuf.h"
#include <malloc.h>
void ringbuf_test(void) {
size_t usable_size = 0;
fprintf(stderr, "\n");
malloc_stats();
assert(1);
// assert(0); // ... assertion "0" failed: ...blabla bla
//1. Test Initialization
hring rb1 = ringbuf_create(512, RINGBUF_PARAM_NONE);
usable_size = malloc_usable_size(rb1);
fprintf(stdout, "Malloc Usable Size: %d\n", usable_size);
hring rb2 = ringbuf_create(512, RINGBUF_ALLOWOVERWRITE);
assert(rb1 != NULL);
assert(rb2 != NULL);
hring rb3 = ringbuf_create(512, RINGBUF_ALLOWOVERWRITE);
hring rb4 = ringbuf_create(512, RINGBUF_ALLOWOVERWRITE);
printf("Malloc Usable Size of rb1: %d\n", malloc_usable_size(rb1));
printf("Malloc Usable Size of rb2: %d\n", malloc_usable_size(rb2));
printf("Malloc Usable Size of rb3: %d\n", malloc_usable_size(rb3));
printf("Malloc Usable Size of rb4: %d\n", malloc_usable_size(rb4));
ringbuf_destroy(rb4);
malloc_stats();
ringbuf_destroy(rb3);
malloc_stats();
malloc_stats();
ringbuf_destroy(rb2);
malloc_stats();
ringbuf_destroy(rb1);
malloc_stats();
printf("rb1 after destroy is: 0x%08X\n", (unsigned int) rb1);
}
#if 0
volatile int ret = 0;
ring = ringbuf_create(64,RINGBUF_ALLOWOVERWRITE);
if (ring == NULL)
printf("we have some problems ...\n");
uint8_t data[1024];
char str[1024]={0};
strcpy(str, "KW4NZ");
ret = ringbuf_dump(ring);
ret = ringbuf_write(ring, str);
printf("Writing string: %s\n", str);
ret = ringbuf_dump(ring);
ret = ringbuf_push(ring, (uint8_t *)"Ich gehe spazieren.", sizeof("Ich gehe spazieren."));
ret = ringbuf_dump(ring);
ret = ringbuf_push(ring, (uint8_t *)"NOCHMALS GEHE ICH RAUS.", sizeof("NOCHMALS GEHE ICH RAUS."));
ret = ringbuf_dump(ring);
ret = ringbuf_read(ring, str);
printf("STRING: %s\n", str);
ret = ringbuf_dump(ring);
ret = ringbuf_read(ring, str);
printf("STRING: %s\n", str);
ret = ringbuf_dump(ring);
ret = ringbuf_read(ring, str);
printf("STRING: %s\n", str);
ret = ringbuf_dump(ring);
strcpy(str, "OE3TKT,OE1TKT,OE7TKT");
ret = ringbuf_write(ring, str);
ret = ringbuf_dump(ring);
ret = ringbuf_read(ring, str);
printf("STRING: %s\n", str);
ret = ringbuf_dump(ring);
strcpy(str, "OE1TKT,OE3TKT,OE7TKT");
ret = ringbuf_write(ring, str);
strcpy(str, "KW4NZ");
ret = ringbuf_write(ring, str);
ret = ringbuf_dump(ring);
ret = ringbuf_read(ring, str);
printf("STRING: %s (OE1TKT,OE3TKT,OE7TKT)\n", str);
ret = ringbuf_read(ring, str);
printf("STRING: %s (KW4NZ)\n", str);
ret = ringbuf_pull(ring, data, 1024);
printf("Read %d bytes...\n", ret);
for (int i = 0; i < ret; i++)
putchar(data[i]);
puts("");
ringbuf_dump(ring);
ret = ringbuf_push(ring, (uint8_t *)"Eine 128-tägige Reise ist zu gewinnen!", sizeof("Eine 128-tägige Reise ist zu gewinnen!"));
ringbuf_dump(ring);
// ret = ringbuf_push(ring, (uint8_t *)"Eine 100-tägige Reise ist zu gewinnen!", sizeof("Eine 128-tägige Reise ist zu gewinnen!"));
// ret = ringbuf_push(ring, (uint8_t *)"Eine 90-tägige Reise ist zu gewinnen!", sizeof("Eine 90-tägige Reise ist zu gewinnen!"));
ret = ringbuf_push(ring, (uint8_t *)"ENDENDENDENDEND", sizeof("ENDENDENDENDEND"));
ringbuf_dump(ring);
ret = ringbuf_push(ring, (uint8_t *)"Vereinbarungen treffen zu.", sizeof("Vereinbarungen treffen zu."));
ringbuf_dump(ring);
ret = ringbuf_read(ring, str);
printf("String: %s (length: %d)\n", str, ret);
ret = ringbuf_dump(ring);
ret = ringbuf_read(ring, str);
printf("String: %s (length: %d)\n", str, ret);
ret = ringbuf_read(ring, str);
printf("String: %s (length: %d)\n", str, ret);
ret = ringbuf_pull(ring, data, 1024);
printf("Read %d bytes...\n", ret);
for (int i = 0; i < ret; i++)
putchar(data[i]);
puts("");
ringbuf_dump(ring);
ringbuf_clear(ring);
ringbuf_dump(ring);
#if RING_STATISTICS_ENABLED
ringbuf_statistics(ring);
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,319 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32l4xx_hal_msp.c
* @brief This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @attention
*
* Copyright (c) 2022 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 */
extern DMA_HandleTypeDef hdma_lpuart_rx;
/* 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();
__HAL_RCC_PWR_CLK_ENABLE();
/* System interrupt init*/
/* PendSV_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/**
* @brief I2C MSP Initialization
* This function configures the hardware resources used in this example
* @param hi2c: I2C handle pointer
* @retval None
*/
void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(hi2c->Instance==I2C1)
{
/* USER CODE BEGIN I2C1_MspInit 0 */
/* USER CODE END I2C1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
__HAL_RCC_GPIOB_CLK_ENABLE();
/**I2C1 GPIO Configuration
PB8 ------> I2C1_SCL
PB9 ------> I2C1_SDA
*/
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_I2C1_CLK_ENABLE();
/* USER CODE BEGIN I2C1_MspInit 1 */
/* USER CODE END I2C1_MspInit 1 */
}
}
/**
* @brief I2C MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hi2c: I2C handle pointer
* @retval None
*/
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
{
if(hi2c->Instance==I2C1)
{
/* USER CODE BEGIN I2C1_MspDeInit 0 */
/* USER CODE END I2C1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_I2C1_CLK_DISABLE();
/**I2C1 GPIO Configuration
PB8 ------> I2C1_SCL
PB9 ------> I2C1_SDA
*/
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8);
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9);
/* USER CODE BEGIN I2C1_MspDeInit 1 */
/* USER CODE END I2C1_MspDeInit 1 */
}
}
/**
* @brief UART MSP Initialization
* This function configures the hardware resources used in this example
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(huart->Instance==LPUART1)
{
/* USER CODE BEGIN LPUART1_MspInit 0 */
/* USER CODE END LPUART1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_LPUART1;
PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_LPUART1_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
HAL_PWREx_EnableVddIO2();
/**LPUART1 GPIO Configuration
PG7 ------> LPUART1_TX
PG8 ------> LPUART1_RX
*/
GPIO_InitStruct.Pin = STLK_RX_Pin|STLK_TX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
/* LPUART1 DMA Init */
/* LPUART_RX Init */
hdma_lpuart_rx.Instance = DMA2_Channel7;
hdma_lpuart_rx.Init.Request = DMA_REQUEST_4;
hdma_lpuart_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_lpuart_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_lpuart_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_lpuart_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_lpuart_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_lpuart_rx.Init.Mode = DMA_NORMAL;
hdma_lpuart_rx.Init.Priority = DMA_PRIORITY_LOW;
if (HAL_DMA_Init(&hdma_lpuart_rx) != HAL_OK)
{
Error_Handler();
}
__HAL_LINKDMA(huart,hdmarx,hdma_lpuart_rx);
/* LPUART1 interrupt Init */
HAL_NVIC_SetPriority(LPUART1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(LPUART1_IRQn);
/* USER CODE BEGIN LPUART1_MspInit 1 */
/* USER CODE END LPUART1_MspInit 1 */
}
}
/**
* @brief UART MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param huart: UART handle pointer
* @retval None
*/
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==LPUART1)
{
/* USER CODE BEGIN LPUART1_MspDeInit 0 */
/* USER CODE END LPUART1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_LPUART1_CLK_DISABLE();
/**LPUART1 GPIO Configuration
PG7 ------> LPUART1_TX
PG8 ------> LPUART1_RX
*/
HAL_GPIO_DeInit(GPIOG, STLK_RX_Pin|STLK_TX_Pin);
/* LPUART1 DMA DeInit */
HAL_DMA_DeInit(huart->hdmarx);
/* LPUART1 interrupt DeInit */
HAL_NVIC_DisableIRQ(LPUART1_IRQn);
/* USER CODE BEGIN LPUART1_MspDeInit 1 */
/* USER CODE END LPUART1_MspDeInit 1 */
}
}
/**
* @brief RTC MSP Initialization
* This function configures the hardware resources used in this example
* @param hrtc: RTC handle pointer
* @retval None
*/
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
{
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspInit 0 */
/* USER CODE END RTC_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_RTC_ENABLE();
/* USER CODE BEGIN RTC_MspInit 1 */
/* USER CODE END RTC_MspInit 1 */
}
}
/**
* @brief RTC MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hrtc: RTC handle pointer
* @retval None
*/
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc)
{
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspDeInit 0 */
/* USER CODE END RTC_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_RTC_DISABLE();
/* USER CODE BEGIN RTC_MspDeInit 1 */
/* USER CODE END RTC_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

View File

@ -0,0 +1,136 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32l4xx_hal_timebase_TIM.c
* @brief HAL time base based on the hardware TIM.
******************************************************************************
* @attention
*
* Copyright (c) 2022 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 "stm32l4xx_hal.h"
#include "stm32l4xx_hal_tim.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim6;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief This function configures the TIM6 as a time base source.
* The time source is configured to have 1ms time base with a dedicated
* Tick interrupt priority.
* @note This function is called automatically at the beginning of program after
* reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
* @param TickPriority: Tick interrupt priority.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock, uwAPB1Prescaler;
uint32_t uwPrescalerValue;
uint32_t pFLatency;
HAL_StatusTypeDef status = HAL_OK;
/* Enable TIM6 clock */
__HAL_RCC_TIM6_CLK_ENABLE();
/* Get clock configuration */
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
/* Get APB1 prescaler */
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
/* Compute TIM6 clock */
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
{
uwTimclock = HAL_RCC_GetPCLK1Freq();
}
else
{
uwTimclock = 2UL * HAL_RCC_GetPCLK1Freq();
}
/* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
/* Initialize TIM6 */
htim6.Instance = TIM6;
/* Initialize TIMx peripheral as follow:
+ Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
+ Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
+ ClockDivision = 0
+ Counter direction = Up
*/
htim6.Init.Period = (1000000U / 1000U) - 1U;
htim6.Init.Prescaler = uwPrescalerValue;
htim6.Init.ClockDivision = 0;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
status = HAL_TIM_Base_Init(&htim6);
if (status == HAL_OK)
{
/* Start the TIM time Base generation in interrupt mode */
status = HAL_TIM_Base_Start_IT(&htim6);
if (status == HAL_OK)
{
/* Enable the TIM6 global Interrupt */
HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
/* Configure the SysTick IRQ priority */
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
{
/* Configure the TIM IRQ priority */
HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U);
uwTickPrio = TickPriority;
}
else
{
status = HAL_ERROR;
}
}
}
/* Return function status */
return status;
}
/**
* @brief Suspend Tick increment.
* @note Disable the tick increment by disabling TIM6 update interrupt.
* @param None
* @retval None
*/
void HAL_SuspendTick(void)
{
/* Disable TIM6 update Interrupt */
__HAL_TIM_DISABLE_IT(&htim6, TIM_IT_UPDATE);
}
/**
* @brief Resume Tick increment.
* @note Enable the tick increment by Enabling TIM6 update interrupt.
* @param None
* @retval None
*/
void HAL_ResumeTick(void)
{
/* Enable TIM6 Update interrupt */
__HAL_TIM_ENABLE_IT(&htim6, TIM_IT_UPDATE);
}

View File

@ -0,0 +1,208 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32l4xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* Copyright (c) 2022 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 "stm32l4xx_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 DMA_HandleTypeDef hdma_lpuart_rx;
extern UART_HandleTypeDef hlpuart1;
extern TIM_HandleTypeDef htim6;
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M4 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 */
//printf("something went wrong -> HardFault_Handler called\n");
/* 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 Prefetch 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 */
/* USER CODE END W1_UsageFault_IRQn 0 */
}
}
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
/* USER CODE END DebugMonitor_IRQn 0 */
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
/* USER CODE END DebugMonitor_IRQn 1 */
}
/******************************************************************************/
/* STM32L4xx 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_stm32l4xx.s). */
/******************************************************************************/
/**
* @brief This function handles TIM6 global interrupt, DAC channel1 and channel2 underrun error interrupts.
*/
void TIM6_DAC_IRQHandler(void)
{
/* USER CODE BEGIN TIM6_DAC_IRQn 0 */
/* USER CODE END TIM6_DAC_IRQn 0 */
HAL_TIM_IRQHandler(&htim6);
/* USER CODE BEGIN TIM6_DAC_IRQn 1 */
/* USER CODE END TIM6_DAC_IRQn 1 */
}
/**
* @brief This function handles DMA2 channel7 global interrupt.
*/
void DMA2_Channel7_IRQHandler(void)
{
/* USER CODE BEGIN DMA2_Channel7_IRQn 0 */
/* USER CODE END DMA2_Channel7_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_lpuart_rx);
/* USER CODE BEGIN DMA2_Channel7_IRQn 1 */
/* USER CODE END DMA2_Channel7_IRQn 1 */
}
/**
* @brief This function handles LPUART1 global interrupt.
*/
void LPUART1_IRQHandler(void)
{
/* USER CODE BEGIN LPUART1_IRQn 0 */
/* USER CODE END LPUART1_IRQn 0 */
HAL_UART_IRQHandler(&hlpuart1);
/* USER CODE BEGIN LPUART1_IRQn 1 */
/* USER CODE END LPUART1_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

View File

@ -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) 2022 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)
{
int DataIdx;
(void)file;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
*ptr++ = (char)__io_getchar();
}
return len;
}
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;
(void)file;
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;
}

View File

@ -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) 2022 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;
}

View File

@ -0,0 +1,332 @@
/**
******************************************************************************
* @file system_stm32l4xx.c
* @author MCD Application Team
* @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File
*
* This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32l4xx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
* After each device reset the MSI (4 MHz) is used as system clock source.
* Then SystemInit() function is called, in "startup_stm32l4xx.s" file, to
* configure the system clock before to branch to main program.
*
* This file configures the system clock as follows:
*=============================================================================
*-----------------------------------------------------------------------------
* System Clock source | MSI
*-----------------------------------------------------------------------------
* SYSCLK(Hz) | 4000000
*-----------------------------------------------------------------------------
* HCLK(Hz) | 4000000
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB1 Prescaler | 1
*-----------------------------------------------------------------------------
* APB2 Prescaler | 1
*-----------------------------------------------------------------------------
* PLL_M | 1
*-----------------------------------------------------------------------------
* PLL_N | 8
*-----------------------------------------------------------------------------
* PLL_P | 7
*-----------------------------------------------------------------------------
* PLL_Q | 2
*-----------------------------------------------------------------------------
* PLL_R | 2
*-----------------------------------------------------------------------------
* PLLSAI1_P | NA
*-----------------------------------------------------------------------------
* PLLSAI1_Q | NA
*-----------------------------------------------------------------------------
* PLLSAI1_R | NA
*-----------------------------------------------------------------------------
* PLLSAI2_P | NA
*-----------------------------------------------------------------------------
* PLLSAI2_Q | NA
*-----------------------------------------------------------------------------
* PLLSAI2_R | NA
*-----------------------------------------------------------------------------
* Require 48MHz for USB OTG FS, | Disabled
* SDIO and RNG clock |
*-----------------------------------------------------------------------------
*=============================================================================
******************************************************************************
* @attention
*
* Copyright (c) 2017 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.
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32l4xx_system
* @{
*/
/** @addtogroup STM32L4xx_System_Private_Includes
* @{
*/
#include "stm32l4xx.h"
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_Defines
* @{
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (MSI_VALUE)
#define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/
#endif /* MSI_VALUE */
#if !defined (HSI_VALUE)
#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/* Note: Following vector table addresses must be defined in line with linker
configuration. */
/*!< Uncomment the following line if you need to relocate the vector table
anywhere in Flash or Sram, else the vector table is kept at the automatic
remap of boot address selected */
/* #define USER_VECT_TAB_ADDRESS */
#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM1_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
/******************************************************************************/
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_Variables
* @{
*/
/* The SystemCoreClock variable is updated in three ways:
1) by calling CMSIS function SystemCoreClockUpdate()
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
Note: If you use this function to configure the system clock; then there
is no need to call the 2 first functions listed above, since SystemCoreClock
variable is updated automatically.
*/
uint32_t SystemCoreClock = 4000000U;
const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U};
const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U};
const uint32_t MSIRangeTable[12] = {100000U, 200000U, 400000U, 800000U, 1000000U, 2000000U, \
4000000U, 8000000U, 16000000U, 24000000U, 32000000U, 48000000U};
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @addtogroup STM32L4xx_System_Private_Functions
* @{
*/
/**
* @brief Setup the microcontroller system.
* @retval None
*/
void SystemInit(void)
{
#if defined(USER_VECT_TAB_ADDRESS)
/* Configure the Vector Table location -------------------------------------*/
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
#endif
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 20U)|(3UL << 22U)); /* set CP10 and CP11 Full Access */
#endif
}
/**
* @brief Update SystemCoreClock variable according to Clock Register Values.
* The SystemCoreClock variable contains the core clock (HCLK), it can
* be used by the user application to setup the SysTick timer or configure
* other parameters.
*
* @note Each time the core clock (HCLK) changes, this function must be called
* to update SystemCoreClock variable value. Otherwise, any configuration
* based on this variable will be incorrect.
*
* @note - The system frequency computed by this function is not the real
* frequency in the chip. It is calculated based on the predefined
* constant and the selected clock source:
*
* - If SYSCLK source is MSI, SystemCoreClock will contain the MSI_VALUE(*)
*
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
*
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
*
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***)
* or HSI_VALUE(*) or MSI_VALUE(*) multiplied/divided by the PLL factors.
*
* (*) MSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
* 4 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (**) HSI_VALUE is a constant defined in stm32l4xx_hal.h file (default value
* 16 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (***) HSE_VALUE is a constant defined in stm32l4xx_hal.h file (default value
* 8 MHz), user has to ensure that HSE_VALUE is same as the real
* frequency of the crystal used. Otherwise, this function may
* have wrong result.
*
* - The result of this function could be not correct when using fractional
* value for HSE crystal.
*
* @retval None
*/
void SystemCoreClockUpdate(void)
{
uint32_t tmp, msirange, pllvco, pllsource, pllm, pllr;
/* Get MSI Range frequency--------------------------------------------------*/
if ((RCC->CR & RCC_CR_MSIRGSEL) == 0U)
{ /* MSISRANGE from RCC_CSR applies */
msirange = (RCC->CSR & RCC_CSR_MSISRANGE) >> 8U;
}
else
{ /* MSIRANGE from RCC_CR applies */
msirange = (RCC->CR & RCC_CR_MSIRANGE) >> 4U;
}
/*MSI frequency range in HZ*/
msirange = MSIRangeTable[msirange];
/* Get SYSCLK source -------------------------------------------------------*/
switch (RCC->CFGR & RCC_CFGR_SWS)
{
case 0x00: /* MSI used as system clock source */
SystemCoreClock = msirange;
break;
case 0x04: /* HSI used as system clock source */
SystemCoreClock = HSI_VALUE;
break;
case 0x08: /* HSE used as system clock source */
SystemCoreClock = HSE_VALUE;
break;
case 0x0C: /* PLL used as system clock source */
/* PLL_VCO = (HSE_VALUE or HSI_VALUE or MSI_VALUE/ PLLM) * PLLN
SYSCLK = PLL_VCO / PLLR
*/
pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC);
pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4U) + 1U ;
switch (pllsource)
{
case 0x02: /* HSI used as PLL clock source */
pllvco = (HSI_VALUE / pllm);
break;
case 0x03: /* HSE used as PLL clock source */
pllvco = (HSE_VALUE / pllm);
break;
default: /* MSI used as PLL clock source */
pllvco = (msirange / pllm);
break;
}
pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8U);
pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25U) + 1U) * 2U;
SystemCoreClock = pllvco/pllr;
break;
default:
SystemCoreClock = msirange;
break;
}
/* Compute HCLK clock frequency --------------------------------------------*/
/* Get HCLK prescaler */
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
/* HCLK clock frequency */
SystemCoreClock >>= tmp;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/