Skip to content

Commit 0c2ffe5

Browse files
author
Cruz Monrreal
authored
Merge pull request #7519 from Wiznet/master
Wiznet: fix us_ticker & gpio bug
2 parents 21dbbc5 + 8b54856 commit 0c2ffe5

File tree

4 files changed

+49
-40
lines changed

4 files changed

+49
-40
lines changed

targets/TARGET_WIZNET/TARGET_W7500x/W7500x_Peripheral_Library/W7500x_gpio.c

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ void HAL_GPIO_DeInit(GPIO_TypeDef* GPIOx)
1212

1313
/* DeInit GPIOx Registers */
1414
GPIOx->DATA = 0x0000;
15-
GPIOx->DATAOUT = 0x0000;
16-
//GPIOx->OUTENSET = 0x0000;
17-
GPIOx->OUTENCLR = 0xFFFF;
18-
//GPIOx->INTENSET = 0x0000;
15+
GPIOx->DATAOUT = 0x0000;
16+
GPIOx->OUTENCLR = 0xFFFF;
1917
GPIOx->INTENCLR = 0xFFFF;
20-
//GPIOx->INTTYPESET = 0x0000;
21-
GPIOx->INTTYPECLR = 0xFFFF;
22-
//GPIOx->INTPOLSET = 0x0000;
23-
GPIOx->INTPOLCLR = 0xFFFF;
24-
18+
GPIOx->INTTYPESET = 0x0000;
2519

2620
/* DeInit GPIOx
2721
* Pad Control Register
@@ -65,9 +59,8 @@ void HAL_GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
6559

6660
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
6761
assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
68-
// assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
69-
70-
GPIOx->INTTYPESET = 0x00FF;
62+
assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Mode));
63+
assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
7164

7265
if (GPIOx == GPIOA) px_pcr = PA_PCR;
7366
else if (GPIOx == GPIOB) px_pcr = PB_PCR;
@@ -117,16 +110,6 @@ void HAL_GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
117110
px_pcr->Port[pinpos] &= ~(Px_PCR_DS_HIGH);
118111
}
119112

120-
// Configure Open Drain selections bit
121-
if(GPIO_InitStruct->GPIO_Pad & Px_PCR_OD)
122-
{
123-
px_pcr->Port[pinpos] |= Px_PCR_OD;
124-
}
125-
else
126-
{
127-
px_pcr->Port[pinpos] &= ~(Px_PCR_OD);
128-
}
129-
130113
// Configure Input buffer enable selection bit
131114
if(GPIO_InitStruct->GPIO_Pad & Px_PCR_IE)
132115
{
@@ -154,7 +137,7 @@ void HAL_GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
154137
{
155138
GPIO_InitStruct->GPIO_Pin = GPIO_Pin_All;
156139
GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
157-
GPIO_InitStruct->GPIO_Pad = (GPIOPad_TypeDef)(GPIO_PuPd_UP);
140+
GPIO_InitStruct->GPIO_Pad = (GPIOPad_TypeDef)(GPIO_SUMMIT|GPIO_IE|GPIO_PuPd_UP);
158141
}
159142

160143

@@ -232,13 +215,27 @@ void HAL_GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
232215

233216
void HAL_GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
234217
{
218+
uint32_t temp_gpio_lb;
219+
uint32_t temp_gpio_ub;
220+
235221
/* Check the parameters */
236222
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
237223
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
238224
assert_param(IS_GPIO_BIT_ACTION(BitVal));
239-
240-
(GPIOx->LB_MASKED[(uint8_t)(GPIO_Pin)]) = BitVal;
241-
(GPIOx->UB_MASKED[(uint8_t)((GPIO_Pin)>>8)]) = BitVal;
225+
226+
temp_gpio_lb = (GPIOx->LB_MASKED[(uint8_t)(GPIO_Pin)]);
227+
temp_gpio_ub = (GPIOx->UB_MASKED[(uint8_t)((GPIO_Pin)>>8)]);
228+
229+
if( BitVal == Bit_SET)
230+
{
231+
(GPIOx->LB_MASKED[(uint8_t)(GPIO_Pin)]) = (temp_gpio_lb | GPIO_Pin);
232+
(GPIOx->UB_MASKED[(uint8_t)((GPIO_Pin)>>8)]) = (temp_gpio_ub | GPIO_Pin);
233+
}
234+
else
235+
{
236+
(GPIOx->LB_MASKED[(uint8_t)(GPIO_Pin)]) = (temp_gpio_lb & ~(GPIO_Pin));
237+
(GPIOx->UB_MASKED[(uint8_t)((GPIO_Pin)>>8)]) = (temp_gpio_ub & ~(GPIO_Pin));
238+
}
242239
}
243240

244241
void HAL_GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
@@ -254,6 +251,7 @@ void HAL_PAD_AFConfig(PAD_Type Px, uint16_t GPIO_Pin, PAD_AF_TypeDef P_AF)
254251
int i;
255252
uint16_t idx =0x1;
256253
assert_param(IS_PAD_Type(Px));
254+
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
257255

258256
for(i=0;i<16;i++)
259257
{
@@ -262,29 +260,25 @@ void HAL_PAD_AFConfig(PAD_Type Px, uint16_t GPIO_Pin, PAD_AF_TypeDef P_AF)
262260
if(Px == PAD_PA)
263261
{
264262
assert_param(IS_PA_NUM(i));
265-
//PA_AFSR->Port[i] &= ~(0x03ul);
266-
//PA_AFSR->Port[i] |= P_AF;
263+
PA_AFSR->Port[i] &= ~(0x03ul);
267264
PA_AFSR->Port[i] = P_AF;
268265
}
269266
else if(Px == PAD_PB)
270267
{
271268
assert_param(IS_PB_NUM(i));
272-
//PB_AFSR->Port[i] &= ~(0x03ul);
273-
//PB_AFSR->Port[i] |= P_AF;
269+
PB_AFSR->Port[i] &= ~(0x03ul);
274270
PB_AFSR->Port[i] = P_AF;
275271
}
276272
else if(Px == PAD_PC)
277273
{
278274
assert_param(IS_PC_NUM(i));
279-
//PC_AFSR->Port[i] &= ~(0x03ul);
280-
//PC_AFSR->Port[i] |= P_AF;
275+
PC_AFSR->Port[i] &= ~(0x03ul);
281276
PC_AFSR->Port[i] = P_AF;
282277
}
283278
else
284279
{
285280
assert_param(IS_PD_NUM(i));
286-
//PD_AFSR->Port[i] &= ~(0x03ul);
287-
//PD_AFSR->Port[i] |= P_AF;
281+
PD_AFSR->Port[i] &= ~(0x03ul);
288282
PD_AFSR->Port[i] = P_AF;
289283
}
290284
}

targets/TARGET_WIZNET/TARGET_W7500x/W7500x_Peripheral_Library/W7500x_gpio.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,40 @@ typedef enum
6868
GPIO_PuPd_UP = Px_PCR_PUPD_UP,
6969
GPIO_PuPd_DOWN = Px_PCR_PUPD_DOWN,
7070
GPIO_PuPd_Default = 0x0ul,
71+
GPIO_DS = Px_PCR_DS_HIGH,
72+
GPIO_IE = Px_PCR_IE,
73+
GPIO_SUMMIT = Px_PCR_CS_SUMMIT
7174
}GPIOPad_TypeDef;
7275

76+
#define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_UP) || ((PUPD) == GPIO_PuPd_DOWN))
77+
7378
typedef struct
7479
{
7580
uint32_t GPIO_Pin;
7681
GPIOMode_TypeDef GPIO_Mode;
7782
GPIOPad_TypeDef GPIO_Pad;
7883
}GPIO_InitTypeDef;
7984

85+
typedef enum
86+
{
87+
Falling = 0,
88+
Rising = 1
89+
}GPIOPol_TypeDef;
90+
91+
typedef enum
92+
{
93+
Reset = 0,
94+
Set = 1
95+
}GPIOSet_TypeDef;
96+
8097
typedef enum
8198
{
8299
Bit_RESET = 0,
83100
Bit_SET
84101
}BitAction;
85102

86103

87-
#define IS_PAD_TYPE(Px) (((Px) == PAD_PA) || ((Px) == PAD_PB) \
104+
#define IS_PAD_TYPE(Px) (((Px) == PAD_PA) || ((Px) == PAD_PB) || \
88105
((Px) == PAD_PC) || ((Px) == PAD_PD))
89106

90107
#define IS_PA_NUM(NUM) (((NUM)>=0) && ((NUM)<16))

targets/TARGET_WIZNET/TARGET_W7500x/mbed_overrides.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ void mbed_sdk_init()
3535
{
3636
// Update the SystemCoreClock variable.
3737
SystemInit();
38+
SysTick_Config((GetSystemClock()/1000));
3839
}

targets/TARGET_WIZNET/TARGET_W7500x/us_ticker.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ extern "C"{
5151

5252
void DUALTIMER0_Handler(void)
5353
{
54-
if(DUALTIMER_GetIntStatus(DUALTIMER0_0))
55-
{
56-
DUALTIMER_IntClear(DUALTIMER0_0);
57-
us_ticker_irq_handler();
58-
}
54+
DUALTIMER_IntClear(DUALTIMER0_0);
55+
us_ticker_irq_handler();
5956
}
6057

6158
#ifdef __cplusplus

0 commit comments

Comments
 (0)