Skip to content

Commit

Permalink
Update the code to be compatible with gcc12
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuYanzhen1 committed Aug 8, 2023
1 parent 5dc9c4f commit d1b1335
Show file tree
Hide file tree
Showing 5 changed files with 714 additions and 611 deletions.
15 changes: 12 additions & 3 deletions program/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

# project settings
project(candleLight C ASM)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

#Uncomment for software floating point
Expand All @@ -29,7 +28,7 @@ add_compile_options(
-ffunction-sections -fdata-sections
-ffreestanding
-fno-move-loop-invariants
-Os -g3
-O2
-flto -ffat-lto-objects
--specs=nano.specs
--specs=nosys.specs
Expand All @@ -54,12 +53,22 @@ set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F072XB.ld)
add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
add_link_options(-mcpu=cortex-m0 -mthumb -mthumb-interwork)
add_link_options(
-mthumb -Wall -Wextra -g3
-mthumb -Wall -Wextra
-Xlinker --gc-sections
--specs=nano.specs
--specs=nosys.specs
)
add_link_options(-T ${LINKER_SCRIPT})

execute_process(
COMMAND ${CMAKE_C_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION_LOCAL
)
string(REGEX MATCH "[0-9]+" GCC_VERSION_LOCAL_MAJOR ${GCC_VERSION_LOCAL})
if (GCC_VERSION_LOCAL_MAJOR GREATER 11)
add_link_options(-Wl,--no-warn-rwx-segments)
endif ()

add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
add_dependencies(${PROJECT_NAME}.elf version_h)

Expand Down
4 changes: 2 additions & 2 deletions program/user/src/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ THE SOFTWARE.
*/

#include "can.h"
#include "config.h"

void can_init(can_data_t *hcan, CAN_TypeDef *instance) {
__HAL_RCC_CAN1_CLK_ENABLE();
Expand Down Expand Up @@ -70,7 +69,8 @@ void can_enable(can_data_t *hcan, bool loop_back, bool listen_only, bool one_sho
uint32_t mcr = CAN_MCR_INRQ
| CAN_MCR_ABOM
| CAN_MCR_AWUM
| CAN_MCR_TXFP;
| CAN_MCR_TXFP
| CAN_MCR_NART;

uint32_t btr = ((uint32_t) (hcan->sjw - 1)) << 24
| ((uint32_t) (hcan->phase_seg1 - 1)) << 16
Expand Down
50 changes: 21 additions & 29 deletions program/user/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ THE SOFTWARE.
*/

#include <stdlib.h>
#include <string.h>

#include "config.h"
#include "hal_include.h"
#include "usbd_def.h"
Expand Down Expand Up @@ -118,39 +116,36 @@ int main(void) {
}

if (can_is_rx_pending(&hCAN)) {
struct gs_host_frame *frame = queue_pop_front(q_frame_pool);
if (frame != 0) {
if (can_receive(&hCAN, frame)) {
struct gs_host_frame *tx_frame = queue_pop_front(q_frame_pool);
if (tx_frame != 0) {
if (can_receive(&hCAN, tx_frame)) {
received_count++;

frame->timestamp_us = timer_get();
frame->echo_id = 0xFFFFFFFF; // not a echo frame
frame->channel = 0;
frame->flags = 0;
frame->reserved = 0;

send_to_host_or_enqueue(frame);
tx_frame->timestamp_us = timer_get();
tx_frame->echo_id = 0xFFFFFFFF; // not a echo frame
tx_frame->channel = 0;
tx_frame->flags = 0;
tx_frame->reserved = 0;

send_to_host_or_enqueue(tx_frame);
led_indicate_trx(&hLED, led_1);
} else {
queue_push_back(q_frame_pool, frame);
}
} else
queue_push_back(q_frame_pool, tx_frame);
}
// If there are frames to receive, don't report any error frames. The
// best we can localize the errors to is "after the last successfully
// received frame", so wait until we get there. LEC will hold some error
// to report even if multiple pass by.
} else {
uint32_t can_err = can_get_error_status(&hCAN);
struct gs_host_frame *frame = queue_pop_front(q_frame_pool);
if (frame != 0) {
frame->timestamp_us = timer_get();
if (can_parse_error_status(can_err, last_can_error_status, &hCAN, frame)) {
send_to_host_or_enqueue(frame);
struct gs_host_frame *err_frame = queue_pop_front(q_frame_pool);
if (err_frame != 0) {
err_frame->timestamp_us = timer_get();
if (can_parse_error_status(can_err, last_can_error_status, &hCAN, err_frame)) {
send_to_host_or_enqueue(err_frame);
last_can_error_status = can_err;
} else {
queue_push_back(q_frame_pool, frame);
}
} else
queue_push_back(q_frame_pool, err_frame);
}
}

Expand Down Expand Up @@ -180,9 +175,7 @@ void SystemClock_Config(void) {
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
HAL_RCC_OscConfig(&RCC_OscInitStruct);

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_SYSCLK |
RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
Expand Down Expand Up @@ -219,10 +212,9 @@ void send_to_host() {
if (!frame)
return;

if (USBD_GS_CAN_SendFrame(&hUSB, frame) == USBD_OK) {
if (USBD_GS_CAN_SendFrame(&hUSB, frame) == USBD_OK)
queue_push_back(q_frame_pool, frame);
} else {
else
queue_push_front(q_to_host, frame);
}
}

147 changes: 147 additions & 0 deletions program/user/src/syscalls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/**
******************************************************************************
* @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-2023 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;
}

__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;
}
Loading

0 comments on commit d1b1335

Please sign in to comment.