finally find the problem of code disappearing
4
Software/.vscode/settings.json
vendored
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"cortex-debug.armToolchainPath": "/home/chiangni/.config/VSCodium/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/arm-none-eabi-gcc/13.2.1-1.1.1/.content/bin",
|
"cortex-debug.armToolchainPath": "/home/chiangni/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/arm-none-eabi-gcc/13.3.1-1.1.1/.content/bin",
|
||||||
"cortex-debug.openocdPath": "/home/chiangni/Documents/STM32/OpenOCD/xpacks/@xpack-dev-tools/openocd/.content/bin/openocd"
|
"cortex-debug.openocdPath": "/home/chiangni/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/openocd/0.12.0-4.1/.content/bin/openocd"
|
||||||
}
|
}
|
9
Software/Core/Inc/adc.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#ifndef INC_ADC
|
||||||
|
#define INC_ADC
|
||||||
|
#include "stm32f0xx_hal_adc.h"
|
||||||
|
|
||||||
|
void adc_init(ADC_HandleTypeDef* hadc);
|
||||||
|
void adc_loop(ADC_HandleTypeDef* hadc);
|
||||||
|
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
|
||||||
|
|
||||||
|
#endif
|
@ -73,7 +73,7 @@
|
|||||||
* (when HSE is used as system clock source, directly or through the PLL).
|
* (when HSE is used as system clock source, directly or through the PLL).
|
||||||
*/
|
*/
|
||||||
#if !defined (HSE_VALUE)
|
#if !defined (HSE_VALUE)
|
||||||
#define HSE_VALUE ((uint32_t)12000000) /*!< Value of the External oscillator in Hz */
|
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
|
||||||
#endif /* HSE_VALUE */
|
#endif /* HSE_VALUE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +51,6 @@ void HardFault_Handler(void);
|
|||||||
void SVC_Handler(void);
|
void SVC_Handler(void);
|
||||||
void PendSV_Handler(void);
|
void PendSV_Handler(void);
|
||||||
void SysTick_Handler(void);
|
void SysTick_Handler(void);
|
||||||
void ADC1_IRQHandler(void);
|
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
|
||||||
/* USER CODE END EFP */
|
/* USER CODE END EFP */
|
||||||
|
77
Software/Core/Lib/can-halal/README.md
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# FaSTTUBe CAN HAL Abstraction Layer
|
||||||
|
|
||||||
|
This repository contains an abstraction layer to provide a simplified & unified
|
||||||
|
interface to the STM32 bxCAN and FDCAN peripherals.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Simply add the repository to your `Core/Lib` directory. You can also add it as a
|
||||||
|
git submodule:
|
||||||
|
|
||||||
|
mkdir -p Core/Lib
|
||||||
|
cd Core/Lib
|
||||||
|
git submodule add ssh://git@git.fasttube.de:313/FaSTTUBe/can-halal.git
|
||||||
|
|
||||||
|
The library needs to be told what STM family you're using, so make sure one of
|
||||||
|
the following symbols is defined when `can-halal.c` is compiled or `can-halal.h`
|
||||||
|
is included:
|
||||||
|
|
||||||
|
- `STM32F3`
|
||||||
|
- `STM32H7`
|
||||||
|
|
||||||
|
When using the FDCAN peripheral (H7 series), you also need to define
|
||||||
|
`FTCAN_NUM_FILTERS` (and set it to the value of "Std Filters Nbr" you configured
|
||||||
|
in your `.ioc`).
|
||||||
|
|
||||||
|
If you use
|
||||||
|
[VSCode with the stm-32-for-vscode extension](https://podio.com/fasttubede/modulubergreifend/apps/tech-tutorials/items/57),
|
||||||
|
you can add these definitions in the `STM32-for-VSCode-config.yaml` file, e.g.:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# Compiler definitions. The -D prefix for the compiler will be automatically added.
|
||||||
|
cDefinitions:
|
||||||
|
- STM32H7
|
||||||
|
- FTCAN_NUM_FILTERS=32
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
1. Include `can-halal.h`
|
||||||
|
2. Call `ftcan_init()` with the appropriate handle
|
||||||
|
3. Call `ftcan_add_filter()` with all your filters
|
||||||
|
4. To transmit messages, call `ftcan_transmit()`
|
||||||
|
5. When a message is received, `ftcan_msg_received_cb()` is called. It has a
|
||||||
|
default empty implementation, which you can simply override.
|
||||||
|
|
||||||
|
## Enabling CAN in STM32CubeMX
|
||||||
|
|
||||||
|
This isn't specific to `can-halal`, but for completeness sake is included here.
|
||||||
|
|
||||||
|
### bxCAN (e.g. STM32F3xx)
|
||||||
|
|
||||||
|
1. Enable the CAN peripheral
|
||||||
|

|
||||||
|
2. Setup the [bit timings](http://bittiming.can-wiki.info/).
|
||||||
|
**Note:** the baud rate depends on your system clock, so make sure that is
|
||||||
|
setup correctly first!
|
||||||
|

|
||||||
|
3. Make sure the CAN_RX0 interrupt is enabled
|
||||||
|

|
||||||
|
|
||||||
|
### FDCAN (e.g. STM32H7xx)
|
||||||
|
|
||||||
|
1. Enable the CAN peripheral
|
||||||
|

|
||||||
|
2. Setup the frame format, nominal SJW, filters, and FIFOs. The numbers for
|
||||||
|
filters/FIFOs in the screenshot are examples.
|
||||||
|
**Note:** You need to tell `can-halal` about the number of filters by
|
||||||
|
defining `FTCAN_NUM_FILTERS` (see above).
|
||||||
|

|
||||||
|
3. Setup the [bit timings](http://bittiming.can-wiki.info/). We only use CAN in
|
||||||
|
classic mode, not FD mode, so we only need to worry about the nominal bit
|
||||||
|
timings
|
||||||
|
**Note:** the baud rate depends on your system clock, so make sure that is
|
||||||
|
setup correctly first!
|
||||||
|

|
||||||
|
4. Make sure the interrupts are enabled
|
||||||
|

|
@ -2,7 +2,7 @@
|
|||||||
#define CAN_HALAL_H
|
#define CAN_HALAL_H
|
||||||
|
|
||||||
// Define family macros if none are defined and we recognize a chip macro
|
// Define family macros if none are defined and we recognize a chip macro
|
||||||
#if !defined(STM32F3) && !defined(STM32H7)
|
#if !defined(STM32F3) && !defined(STM32H7) && !defined(STM32F0)
|
||||||
#if defined(STM32F302x6) || defined(STM32F302x8) || defined(STM32F302xB) || \
|
#if defined(STM32F302x6) || defined(STM32F302x8) || defined(STM32F302xB) || \
|
||||||
defined(STM32F302xC)
|
defined(STM32F302xC)
|
||||||
#define STM32F3
|
#define STM32F3
|
||||||
@ -10,17 +10,27 @@
|
|||||||
#if defined(STM32H7A3xx)
|
#if defined(STM32H7A3xx)
|
||||||
#define STM32H7
|
#define STM32H7
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(STM32F042x6)
|
||||||
|
#define STM32F0
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(STM32F3)
|
#if defined(STM32F3)
|
||||||
#include "stm32f3xx_hal.h"
|
#include "stm32f3xx_hal.h"
|
||||||
#define FTCAN_IS_BXCAN
|
#define FTCAN_IS_BXCAN
|
||||||
#define FTCAN_NUM_FILTERS 13
|
#define FTCAN_NUM_FILTERS 13
|
||||||
#elif defined(STM32H7)
|
#elif defined(STM32H7)
|
||||||
#include "stm32h7xx_hal.h"
|
#include "stm32h7xx_hal.h"
|
||||||
#define FTCAN_IS_FDCAN
|
#define FTCAN_IS_FDCAN
|
||||||
|
#ifndef FTCAN_NUM_FILTERS
|
||||||
|
#error "Please configure the number of filters in CubeMX, and then add a compiler define for FTCAN_NUM_FILTERS"
|
||||||
|
#endif
|
||||||
|
#elif defined(STM32F0)
|
||||||
|
#include "stm32f0xx_hal.h"
|
||||||
|
#define FTCAN_IS_BXCAN
|
||||||
|
#define FTCAN_NUM_FILTERS 13
|
||||||
#else
|
#else
|
||||||
#error "Couldn't detect STM family"
|
#error "Couldn't detect STM family"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(FTCAN_IS_BXCAN)
|
#if defined(FTCAN_IS_BXCAN)
|
BIN
Software/Core/Lib/can-halal/doc/bxcan-activate.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
Software/Core/Lib/can-halal/doc/bxcan-bittimings.png
Normal file
After Width: | Height: | Size: 41 KiB |
BIN
Software/Core/Lib/can-halal/doc/bxcan-interrupt.png
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
Software/Core/Lib/can-halal/doc/fdcan-activate.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
Software/Core/Lib/can-halal/doc/fdcan-basic.png
Normal file
After Width: | Height: | Size: 45 KiB |
BIN
Software/Core/Lib/can-halal/doc/fdcan-bittimings.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
Software/Core/Lib/can-halal/doc/fdcan-interrupt.png
Normal file
After Width: | Height: | Size: 17 KiB |
@ -0,0 +1,24 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "can-halal.h"
|
||||||
|
#include "stm32f0xx_hal_adc.h"
|
||||||
|
|
||||||
|
int16_t id = 0x200;
|
||||||
|
int32_t adcRes = 0;
|
||||||
|
|
||||||
|
void adc_init(ADC_HandleTypeDef* hadc){
|
||||||
|
HAL_ADCEx_Calibration_Start(hadc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void adc_loop(ADC_HandleTypeDef* hadc){
|
||||||
|
HAL_ADC_Start_IT(hadc);
|
||||||
|
static uint8_t data[8];
|
||||||
|
ftcan_marshal_unsigned(data, adcRes, 4);
|
||||||
|
ftcan_transmit(id, data, sizeof(data));
|
||||||
|
HAL_Delay(5);
|
||||||
|
//testing gitignore
|
||||||
|
}
|
||||||
|
|
||||||
|
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){
|
||||||
|
adcRes = HAL_ADC_GetValue(hadc);
|
||||||
|
}
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "adc.h"
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
@ -71,7 +71,6 @@ static void MX_TIM2_Init(void);
|
|||||||
*/
|
*/
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
@ -98,7 +97,7 @@ int main(void)
|
|||||||
MX_CAN_Init();
|
MX_CAN_Init();
|
||||||
MX_TIM2_Init();
|
MX_TIM2_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
adc_init(&hadc);
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
@ -108,7 +107,7 @@ int main(void)
|
|||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
ADCMeasureLooooop();
|
adc_loop(&hadc);
|
||||||
}
|
}
|
||||||
/* USER CODE END 3 */
|
/* USER CODE END 3 */
|
||||||
}
|
}
|
||||||
@ -125,14 +124,12 @@ void SystemClock_Config(void)
|
|||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
* in the RCC_OscInitTypeDef structure.
|
* in the RCC_OscInitTypeDef structure.
|
||||||
*/
|
*/
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI14|RCC_OSCILLATORTYPE_HSE;
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
|
||||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
|
RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
|
||||||
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
RCC_OscInitStruct.HSI14CalibrationValue = 16;
|
RCC_OscInitStruct.HSI14CalibrationValue = 16;
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
||||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
|
|
||||||
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV3;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
@ -142,7 +139,7 @@ void SystemClock_Config(void)
|
|||||||
*/
|
*/
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
|RCC_CLOCKTYPE_PCLK1;
|
|RCC_CLOCKTYPE_PCLK1;
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||||
|
|
||||||
@ -230,15 +227,15 @@ static void MX_CAN_Init(void)
|
|||||||
|
|
||||||
/* USER CODE END CAN_Init 1 */
|
/* USER CODE END CAN_Init 1 */
|
||||||
hcan.Instance = CAN;
|
hcan.Instance = CAN;
|
||||||
hcan.Init.Prescaler = 2;
|
hcan.Init.Prescaler = 16;
|
||||||
hcan.Init.Mode = CAN_MODE_NORMAL;
|
hcan.Init.Mode = CAN_MODE_NORMAL;
|
||||||
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
||||||
hcan.Init.TimeSeg1 = CAN_BS1_13TQ;
|
hcan.Init.TimeSeg1 = CAN_BS1_1TQ;
|
||||||
hcan.Init.TimeSeg2 = CAN_BS2_2TQ;
|
hcan.Init.TimeSeg2 = CAN_BS2_1TQ;
|
||||||
hcan.Init.TimeTriggeredMode = DISABLE;
|
hcan.Init.TimeTriggeredMode = DISABLE;
|
||||||
hcan.Init.AutoBusOff = ENABLE;
|
hcan.Init.AutoBusOff = DISABLE;
|
||||||
hcan.Init.AutoWakeUp = DISABLE;
|
hcan.Init.AutoWakeUp = DISABLE;
|
||||||
hcan.Init.AutoRetransmission = ENABLE;
|
hcan.Init.AutoRetransmission = DISABLE;
|
||||||
hcan.Init.ReceiveFifoLocked = DISABLE;
|
hcan.Init.ReceiveFifoLocked = DISABLE;
|
||||||
hcan.Init.TransmitFifoPriority = DISABLE;
|
hcan.Init.TransmitFifoPriority = DISABLE;
|
||||||
if (HAL_CAN_Init(&hcan) != HAL_OK)
|
if (HAL_CAN_Init(&hcan) != HAL_OK)
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
@ -64,7 +65,6 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
|||||||
*/
|
*/
|
||||||
void HAL_MspInit(void)
|
void HAL_MspInit(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN MspInit 0 */
|
/* USER CODE BEGIN MspInit 0 */
|
||||||
|
|
||||||
/* USER CODE END MspInit 0 */
|
/* USER CODE END MspInit 0 */
|
||||||
@ -106,9 +106,6 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
|
|||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* ADC1 interrupt Init */
|
|
||||||
HAL_NVIC_SetPriority(ADC1_IRQn, 0, 0);
|
|
||||||
HAL_NVIC_EnableIRQ(ADC1_IRQn);
|
|
||||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
/* USER CODE BEGIN ADC1_MspInit 1 */
|
||||||
|
|
||||||
/* USER CODE END ADC1_MspInit 1 */
|
/* USER CODE END ADC1_MspInit 1 */
|
||||||
@ -138,8 +135,6 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
|
|||||||
*/
|
*/
|
||||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1);
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1);
|
||||||
|
|
||||||
/* ADC1 interrupt DeInit */
|
|
||||||
HAL_NVIC_DisableIRQ(ADC1_IRQn);
|
|
||||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||||
|
|
||||||
/* USER CODE END ADC1_MspDeInit 1 */
|
/* USER CODE END ADC1_MspDeInit 1 */
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/* External variables --------------------------------------------------------*/
|
/* External variables --------------------------------------------------------*/
|
||||||
extern ADC_HandleTypeDef hadc;
|
|
||||||
/* USER CODE BEGIN EV */
|
/* USER CODE BEGIN EV */
|
||||||
|
|
||||||
/* USER CODE END EV */
|
/* USER CODE END EV */
|
||||||
@ -140,20 +140,6 @@ void SysTick_Handler(void)
|
|||||||
/* please refer to the startup file (startup_stm32f0xx.s). */
|
/* please refer to the startup file (startup_stm32f0xx.s). */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function handles ADC interrupt.
|
|
||||||
*/
|
|
||||||
void ADC1_IRQHandler(void)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN ADC1_IRQn 0 */
|
|
||||||
|
|
||||||
/* USER CODE END ADC1_IRQn 0 */
|
|
||||||
HAL_ADC_IRQHandler(&hadc);
|
|
||||||
/* USER CODE BEGIN ADC1_IRQn 1 */
|
|
||||||
|
|
||||||
/* USER CODE END ADC1_IRQn 1 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
|
@ -1,176 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file syscalls.c
|
|
||||||
* @author Auto-generated by STM32CubeMX
|
|
||||||
* @brief 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;
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
/**
|
|
||||||
******************************************************************************
|
|
||||||
* @file sysmem.c
|
|
||||||
* @author Generated by STM32CubeMX
|
|
||||||
* @brief 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;
|
|
||||||
}
|
|