Skip to content

Commit

Permalink
[FIXED]:Compiler optimization may cause 32-bit overflow
Browse files Browse the repository at this point in the history
Such as:
ADC_MK_MASK(32),the expected outcome is 0xffffffff,but in reality it is 0  or other outliers
  • Loading branch information
Inchips-zb committed Apr 9, 2024
1 parent 4956ad0 commit 158224b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/FWlib/peripheral_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ uint16_t ADC_ReadChannelData(const uint8_t channel_id)
#include "eflash.h"
#define ADC_LEFT_SHIFT(v, s) ((v) << (s))
#define ADC_RIGHT_SHIFT(v, s) ((v) >> (s))
#define ADC_MK_MASK(b) ((ADC_LEFT_SHIFT(1, b)) - (1))
#define ADC_MK_MASK(b) ((ADC_LEFT_SHIFT(1ULL, b)) - (1))
#define ADC_REG_VAL(reg) ((*((volatile uint32_t *)((APB_SARADC_BASE) + (reg)))))
#define REG_CLR(reg, b, s) ((ADC_REG_VAL(reg)) & (~(ADC_LEFT_SHIFT(ADC_MK_MASK(b), s))))
#define REG_OR(v, s) ((ADC_REG_VAL(reg)) | (ADC_LEFT_SHIFT(v, s)))
Expand Down

0 comments on commit 158224b

Please sign in to comment.