Skip to content

Commit

Permalink
fix: fix uart && shell string buffer bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
libdriver committed Jan 27, 2023
1 parent 1805dac commit 09628e7
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 2,020 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ void adxl345_interface_delay_ms(uint32_t ms)
void adxl345_interface_debug_print(const char *const fmt, ...)
{
char str[256];
uint8_t len;
uint16_t len;
va_list args;

memset((char *)str, 0, sizeof(char) * 256);
va_start(args, fmt);
vsnprintf((char *)str, 256, (char const *)fmt, args);
vsnprintf((char *)str, 255, (char const *)fmt, args);
va_end(args);

len = strlen((char *)str);
Expand Down
12 changes: 6 additions & 6 deletions project/raspberrypi4b/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
{"times", required_argument, NULL, 4},
{NULL, 0, NULL, 0},
};
char type[32] = "unknow";
char type[33] = "unknow";
uint32_t times = 3;
uint32_t mask = 15;
adxl345_address_t addr = ADXL345_ADDRESS_ALT_0;
Expand Down Expand Up @@ -171,7 +171,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
case 'h' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "h");

break;
Expand All @@ -181,7 +181,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
case 'i' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "i");

break;
Expand All @@ -191,7 +191,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
case 'p' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "p");

break;
Expand All @@ -201,7 +201,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
case 'e' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "e_%s", optarg);

break;
Expand All @@ -211,7 +211,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
case 't' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "t_%s", optarg);

break;
Expand Down
1,971 changes: 3 additions & 1,968 deletions project/stm32f407/EW/stm32f407.dep

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions project/stm32f407/driver/src/stm32f407_driver_adxl345_interface.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2015 - present LibDriver All rights reserved
*
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -19,7 +19,7 @@
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* SOFTWARE.
*
* @file stm32f407_driver_adxl345_interface.c
* @brief stm32f407 driver adxl345 interface source file
Expand Down Expand Up @@ -80,11 +80,11 @@ uint8_t adxl345_interface_iic_deinit(void)
uint8_t adxl345_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
{
uint8_t res;

__set_BASEPRI(1);
res = iic_read(addr, reg, buf, len);
__set_BASEPRI(0);

return res;
}

Expand All @@ -102,11 +102,11 @@ uint8_t adxl345_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint
uint8_t adxl345_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
{
uint8_t res;

__set_BASEPRI(1);
res = iic_write(addr, reg, buf, len);
__set_BASEPRI(0);

return res;
}

Expand All @@ -130,7 +130,7 @@ uint8_t adxl345_interface_spi_init(void)
* @note none
*/
uint8_t adxl345_interface_spi_deinit(void)
{
{
return spi_deinit();
}

Expand All @@ -147,11 +147,11 @@ uint8_t adxl345_interface_spi_deinit(void)
uint8_t adxl345_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
{
uint8_t res;

__set_BASEPRI(1);
res = spi_read(reg, buf, len);
__set_BASEPRI(0);

return res;
}

Expand All @@ -168,12 +168,12 @@ uint8_t adxl345_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t adxl345_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
{
uint8_t res;

__set_BASEPRI(1);
res = spi_write(reg, buf, len);
__set_BASEPRI(0);
return 0;

return res;
}

/**
Expand All @@ -194,14 +194,14 @@ void adxl345_interface_delay_ms(uint32_t ms)
void adxl345_interface_debug_print(const char *const fmt, ...)
{
char str[256];
uint8_t len;
uint16_t len;
va_list args;
memset((char *)str, 0, sizeof(char) * 256);

memset((char *)str, 0, sizeof(char) * 256);
va_start(args, fmt);
vsnprintf((char *)str, 256, (char const *)fmt, args);
vsnprintf((char *)str, 255, (char const *)fmt, args);
va_end(args);

len = strlen((char *)str);
(void)uart_write((uint8_t *)str, len);
}
Expand All @@ -218,55 +218,55 @@ void adxl345_interface_receive_callback(uint8_t type)
case ADXL345_INTERRUPT_DATA_READY :
{
adxl345_interface_debug_print("adxl345: irq data ready.\n");

break;
}
case ADXL345_INTERRUPT_SINGLE_TAP :
{
adxl345_interface_debug_print("adxl345: irq single tap.\n");

break;
}
case ADXL345_INTERRUPT_DOUBLE_TAP :
{
adxl345_interface_debug_print("adxl345: irq double tap.\n");

break;
}
case ADXL345_INTERRUPT_ACTIVITY :
{
adxl345_interface_debug_print("adxl345: irq activity.\n");

break;
}
case ADXL345_INTERRUPT_INACTIVITY :
{
adxl345_interface_debug_print("adxl345: irq inactivity.\n");

break;
}
case ADXL345_INTERRUPT_FREE_FALL :
{
adxl345_interface_debug_print("adxl345: irq free fall.\n");

break;
}
case ADXL345_INTERRUPT_WATERMARK :
{
adxl345_interface_debug_print("adxl345: irq water mark.\n");

break;
}
case ADXL345_INTERRUPT_OVERRUN :
{
adxl345_interface_debug_print("adxl345: irq overrun.\n");

break;
}
default :
{
adxl345_interface_debug_print("adxl345: unknown code.\n");

break;
}
}
Expand Down
11 changes: 6 additions & 5 deletions project/stm32f407/interface/inc/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ typedef enum
} spi_mode_t;

/**
* @brief spi bus init
* @return status code
* - 0 success
* - 1 init failed
* @note SCLK is PA5, MOSI is PA7 MISO is PA6 and CS is PA4
* @brief spi bus init
* @param[in] mode is the spi mode
* @return status code
* - 0 success
* - 1 init failed
* @note SCLK is PA5, MOSI is PA7 MISO is PA6 and CS is PA4
*/
uint8_t spi_init(spi_mode_t mode);

Expand Down
11 changes: 6 additions & 5 deletions project/stm32f407/interface/src/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ static uint8_t a_spi_cs_init(void)
}

/**
* @brief spi bus init
* @return status code
* - 0 success
* - 1 init failed
* @note SCLK is PA5, MOSI is PA7 MISO is PA6 and CS is PA4
* @brief spi bus init
* @param[in] mode is the spi mode
* @return status code
* - 0 success
* - 1 init failed
* @note SCLK is PA5, MOSI is PA7 MISO is PA6 and CS is PA4
*/
uint8_t spi_init(spi_mode_t mode)
{
Expand Down
4 changes: 2 additions & 2 deletions project/stm32f407/interface/src/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ uint16_t uart_flush(void)
uint16_t uart_print(const char *const fmt, ...)
{
char str[256];
uint8_t len;
uint16_t len;
va_list args;

/* print to the buffer */
memset((char *)str, 0, sizeof(char) * 256);
va_start(args, fmt);
vsnprintf((char *)str, 256, (char const *)fmt, args);
vsnprintf((char *)str, 255, (char const *)fmt, args);
va_end(args);

/* send the data */
Expand Down
12 changes: 6 additions & 6 deletions project/stm32f407/usr/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
{"times", required_argument, NULL, 4},
{NULL, 0, NULL, 0},
};
char type[32] = "unknow";
char type[33] = "unknow";
uint32_t times = 3;
uint32_t mask = 15;
adxl345_address_t addr = ADXL345_ADDRESS_ALT_0;
Expand Down Expand Up @@ -203,7 +203,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
case 'h' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "h");

break;
Expand All @@ -213,7 +213,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
case 'i' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "i");

break;
Expand All @@ -223,7 +223,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
case 'p' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "p");

break;
Expand All @@ -233,7 +233,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
case 'e' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "e_%s", optarg);

break;
Expand All @@ -243,7 +243,7 @@ uint8_t adxl345(uint8_t argc, char **argv)
case 't' :
{
/* set the type */
memset(type, 0, sizeof(char) * 32);
memset(type, 0, sizeof(char) * 33);
snprintf(type, 32, "t_%s", optarg);

break;
Expand Down

0 comments on commit 09628e7

Please sign in to comment.