Skip to content

Commit 60a87d9

Browse files
committed
Completed and added pwmout_api
1 parent c6f7c5d commit 60a87d9

File tree

12 files changed

+237
-73
lines changed

12 files changed

+237
-73
lines changed

libraries/mbed/targets/cmsis/TARGET_WIZNET/TARGET_W7500x/TARGET_WIZwiki_W7500/W7500x.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,15 @@ typedef struct
661661
#define PWM_CH6 ((PWM_CHn_TypeDef *) (W7500x_PWM_BASE + 0x600UL))
662662
#define PWM_CH7 ((PWM_CHn_TypeDef *) (W7500x_PWM_BASE + 0x700UL))
663663

664+
#define PWM_CH0_BASE (W7500x_PWM_BASE)
665+
#define PWM_CH1_BASE (W7500x_PWM_BASE + 0x100UL)
666+
#define PWM_CH2_BASE (W7500x_PWM_BASE + 0x200UL)
667+
#define PWM_CH3_BASE (W7500x_PWM_BASE + 0x300UL)
668+
#define PWM_CH4_BASE (W7500x_PWM_BASE + 0x400UL)
669+
#define PWM_CH5_BASE (W7500x_PWM_BASE + 0x500UL)
670+
#define PWM_CH6_BASE (W7500x_PWM_BASE + 0x600UL)
671+
#define PWM_CH7_BASE (W7500x_PWM_BASE + 0x700UL)
672+
664673
#define RNG ((RNG_TypeDef *) W7500x_RNG_BASE)
665674

666675
#define SSP0 ((SSP_TypeDef*) (SSP0_BASE))

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/PeripheralPins.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,8 @@ extern const PinMap PinMap_SPI_SCLK[];
5353
extern const PinMap PinMap_SPI_MOSI[];
5454
extern const PinMap PinMap_SPI_MISO[];
5555
extern const PinMap PinMap_SPI_SSEL[];
56+
57+
//*** PWM ***
58+
59+
extern const PinMap PinMap_PWM[];
5660
#endif

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/TARGET_WIZwiki_W7500/PeripheralNames.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ typedef enum {
6060
I2C_1 = (int)I2C1_BASE
6161
} I2CName;
6262

63-
typedef enum {
64-
PWM_1 = 0
65-
// PWM_1 = (int)TIM1_BASE,
66-
// PWM_3 = (int)TIM3_BASE,
67-
// PWM_14 = (int)TIM14_BASE,
68-
// PWM_15 = (int)TIM15_BASE,
69-
// PWM_16 = (int)TIM16_BASE,
70-
// PWM_17 = (int)TIM17_BASE
63+
typedef enum {
64+
PWM_0 = (int)PWM_CH0_BASE,
65+
PWM_1 = (int)PWM_CH1_BASE,
66+
PWM_2 = (int)PWM_CH2_BASE,
67+
PWM_3 = (int)PWM_CH3_BASE,
68+
PWM_4 = (int)PWM_CH4_BASE,
69+
PWM_5 = (int)PWM_CH5_BASE,
70+
PWM_6 = (int)PWM_CH6_BASE,
71+
PWM_7 = (int)PWM_CH7_BASE
7172
} PWMName;
7273

7374
#ifdef __cplusplus

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/TARGET_WIZwiki_W7500/PeripheralPins.c

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,34 +72,56 @@ const PinMap PinMap_I2C_SCL[] = {
7272
//*** SPI ***
7373

7474
const PinMap PinMap_SPI_SCLK[] = {
75-
{PA_6 , SPI_0, 0},
76-
{PB_1 , SPI_1, 0},
77-
{PC_12, SPI_0, 3},
78-
{PA_12, SPI_1, 3},
75+
{PA_6 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)},
76+
{PB_1 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)},
77+
{PC_12, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
78+
{PA_12, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
7979
{NC , NC , 0}
8080
};
8181

8282
const PinMap PinMap_SPI_MOSI[] = {
83-
{PA_8 , SPI_0, 0},
84-
{PB_3 , SPI_1, 0},
85-
{PC_10, SPI_0, 3},
86-
{PA_14, SPI_1, 3},
83+
{PA_8 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)},
84+
{PB_3 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)},
85+
{PC_10, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
86+
{PA_14, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
8787
{NC , NC , 0}
8888
};
8989

9090
const PinMap PinMap_SPI_MISO[] = {
91-
{PA_7 , SPI_0, 0},
92-
{PB_2 , SPI_1, 0},
93-
{PC_11, SPI_0, 3},
94-
{PA_13, SPI_1, 3},
91+
{PA_7 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)},
92+
{PB_2 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)},
93+
{PC_11, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
94+
{PA_13, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
9595
{NC , NC , 0}
9696
};
9797

9898
const PinMap PinMap_SPI_SSEL[] = {
99-
{PA_5 , SPI_0, 0},
100-
{PB_0 , SPI_1, 0},
101-
{PC_13, SPI_0, 3},
102-
{PA_11, SPI_1, 3},
99+
{PA_5 , SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)},
100+
{PB_0 , SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)},
101+
{PC_13, SPI_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
102+
{PA_11, SPI_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
103103
{NC , NC , 0}
104104
};
105105

106+
const PinMap PinMap_PWM[] = {
107+
{PA_0 , PWM_6, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)},
108+
{PA_1 , PWM_7, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)},
109+
{PA_5 , PWM_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
110+
{PA_6 , PWM_3, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
111+
{PA_7 , PWM_4, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
112+
{PA_8 , PWM_5, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
113+
{PA_9 , PWM_6, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
114+
{PA_10, PWM_7, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF3)},
115+
{PC_0 , PWM_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)},
116+
{PC_1 , PWM_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)},
117+
{PC_2 , PWM_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)},
118+
{PC_3 , PWM_3, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)},
119+
{PC_4 , PWM_4, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)},
120+
{PC_5 , PWM_5, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)},
121+
{PC_8 , PWM_0, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)},
122+
{PC_9 , PWM_1, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)},
123+
{PC_10, PWM_2, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)},
124+
{PC_11, PWM_3, WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF2)},
125+
{NC , NC , WIZ_PIN_DATA(WIZ_MODE_AF, WIZ_GPIO_NOPULL, Px_AFSR_AF0)}
126+
};
127+

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/TARGET_WIZwiki_W7500/PinNames.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ extern "C" {
3939

4040

4141
// See W7500x_hal_gpio.h for values of MODE, PUPD and AFNUM
42-
#define WIZ_PIN_DATA(MODE, PUPD, AFNUM) ((int)(((AFNUM) << 8) | ((PUPD) << 4) | ((MODE) << 0)))
43-
#define WIZ_PIN_MODE(X) (((X) >> 0) & 0x0F)
42+
#define WIZ_PIN_DATA(MODE, PUPD, AFNUM) ((int)(((MODE) << 8) | ((PUPD) << 4) | ((AFNUM) << 0)))
4443
#define WIZ_PIN_PUPD(X) (((X) >> 4) & 0x0F)
45-
#define WIZ_PIN_AFNUM(X) (((X) >> 8) & 0x0F)
44+
#define WIZ_PIN_AFNUM(X) (((X) >> 0) & 0x0F)
45+
#define WIZ_PIN_MODE(X) (((X) >> 8) & 0x0F)
4646
#define WIZ_MODE_INPUT (0)
4747
#define WIZ_MODE_OUTPUT (1)
4848
#define WIZ_MODE_AF (2)
@@ -65,8 +65,7 @@ typedef enum {
6565

6666

6767
typedef enum {
68-
// W7500x Pin Names (AF[9:8] + PORT[5:4] + PIN[3:0])
69-
68+
// W7500x PORT[5:4] + PIN[3:0])
7069
PA_0 = 0x000,
7170
PA_1 = 0x001,
7271
PA_2 = 0x002,
@@ -83,7 +82,7 @@ typedef enum {
8382
PA_13 = 0x00D,
8483
PA_14 = 0x00E,
8584
PA_15 = 0x00F,
86-
85+
8786
PB_0 = 0x010, //SSEL1/SD_SEL
8887
PB_1 = 0x011, //SCLK1/SD_CLK
8988
PB_2 = 0x012, //MISO1/SD_MISO
@@ -185,7 +184,6 @@ typedef enum {
185184
PullNone = 0,
186185
PullDown = 1,
187186
PullUp = 2,
188-
OpenDrain = 3,
189187
PullDefault = PullNone
190188
} PinMode;
191189

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/TARGET_WIZwiki_W7500/device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
#define DEVICE_RTC 0
5252

53-
#define DEVICE_PWMOUT 0
53+
#define DEVICE_PWMOUT 1
5454

5555
#define DEVICE_SLEEP 0
5656

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/TARGET_WIZwiki_W7500/objects.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ struct i2c_s {
8787
};
8888

8989
struct pwmout_s {
90-
PWMName pwm;
90+
PWM_CHn_TypeDef * PWM_CHx;
9191
PinName pin;
9292
uint32_t period;
9393
uint32_t pulse;
94+
uint32_t PrescalerValue;
9495
};
9596

9697
#include "gpio_object.h"

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/gpio_api.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,13 @@ void gpio_init(gpio_t *obj, PinName pin)
5959
void gpio_mode(gpio_t *obj, PinMode mode)
6060
{
6161
pin_mode(obj->pin, mode);
62+
obj->mode = mode;
6263
}
6364

6465
void gpio_dir(gpio_t *obj, PinDirection direction)
6566
{
6667
MBED_ASSERT(obj->pin != (PinName)NC);
6768
obj->direction = direction;
6869

69-
if (direction == PIN_OUTPUT) {
70-
pin_function(obj->pin, WIZ_PIN_DATA(WIZ_MODE_OUTPUT, WIZ_GPIO_NOPULL, 1));
71-
} else { // PIN_INPUT
72-
pin_function(obj->pin, WIZ_PIN_DATA(WIZ_MODE_INPUT, WIZ_GPIO_NOPULL, 1));
73-
}
70+
pin_function(obj->pin, WIZ_PIN_DATA(obj->direction, obj->mode, 1));
7471
}

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/gpio_object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct {
4242
uint32_t pin_index;
4343
uint32_t port_num;
4444
uint32_t direction;
45+
uint32_t mode;
4546
__IO uint32_t *reg_data_in;
4647
} gpio_t;
4748

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/i2c_api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
6363
// Configure I2C pins
6464
pinmap_pinout(sda, PinMap_I2C_SDA);
6565
pinmap_pinout(scl, PinMap_I2C_SCL);
66-
pin_mode(sda, OpenDrain);
67-
pin_mode(scl, OpenDrain);
66+
pin_mode(sda, PullUp);
67+
pin_mode(scl, PullUp);
6868
}
6969

7070
// Enable I2C2 clock and pinout if not done
@@ -73,8 +73,8 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
7373
// Configure I2C pins
7474
pinmap_pinout(sda, PinMap_I2C_SDA);
7575
pinmap_pinout(scl, PinMap_I2C_SCL);
76-
pin_mode(sda, OpenDrain);
77-
pin_mode(scl, OpenDrain);
76+
pin_mode(sda, PullUp);
77+
pin_mode(scl, PullUp);
7878
}
7979

8080
// Reset to clear pending flags if any

libraries/mbed/targets/hal/TARGET_WIZNET/TARGET_W7500x/pinmap.c

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,9 @@
3131
#include "mbed_assert.h"
3232
#include "pinmap.h"
3333
#include "PortNames.h"
34+
#include "mbed_error.h"
3435

3536

36-
// GPIO mode look-up table
37-
// It have to same with PinMode index in "PinNames.h"
38-
static const uint32_t gpio_pupd[4] = {
39-
GPIO_NO_PUPD, // PullNone
40-
GPIO_PuPd_DOWN, // PullDown
41-
GPIO_PuPd_UP, // PullUp
42-
GPIO_OD // OpenDrain
43-
};
44-
4537
uint32_t Get_GPIO_BaseAddress(uint32_t port_idx)
4638
{
4739
uint32_t gpio_add = 0;
@@ -65,7 +57,6 @@ uint32_t Get_GPIO_BaseAddress(uint32_t port_idx)
6557
return gpio_add;
6658
}
6759

68-
6960
/**
7061
* Configure pin (input, output, alternate function or analog) + output speed + AF
7162
*/
@@ -79,24 +70,23 @@ void pin_function(PinName pin, int data) {
7970

8071
uint32_t port_num = WIZ_PORT(pin);
8172
uint32_t pin_index = WIZ_PIN_INDEX(pin);
82-
83-
uint32_t gpio_add = Get_GPIO_BaseAddress(port_num);
84-
GPIO_TypeDef *gpio = (GPIO_TypeDef *)gpio_add;
73+
74+
GPIO_TypeDef *gpio;
8575

8676
// Configure Alternate Function
8777
// Warning: Must be done before the GPIO is initialized
8878
switch (afnum) {
8979
case 0:
90-
HAL_PAD_AFConfig(port_num, pin_index,Px_AFSR_AF0);
80+
HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF0);
9181
break;
9282
case 1:
93-
HAL_PAD_AFConfig(port_num, pin_index,Px_AFSR_AF1);
83+
HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF1);
9484
break;
9585
case 2:
96-
HAL_PAD_AFConfig(port_num, pin_index,Px_AFSR_AF2);
86+
HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF2);
9787
break;
9888
case 3:
99-
HAL_PAD_AFConfig(port_num, pin_index,Px_AFSR_AF3);
89+
HAL_PAD_AFConfig((PAD_Type)port_num, (uint16_t)pin_index, (PAD_AF_TypeDef)Px_AFSR_AF3);
10090
break;
10191
default:
10292
break;
@@ -106,10 +96,12 @@ void pin_function(PinName pin, int data) {
10696
return;
10797

10898
// Configure GPIO
99+
gpio = (GPIO_TypeDef *)Get_GPIO_BaseAddress(port_num);
100+
109101
GPIO_InitTypeDef GPIO_InitStructure;
110102
GPIO_InitStructure.GPIO_Pin = pin_index;
111-
GPIO_InitStructure.GPIO_Mode = mode;
112-
GPIO_InitStructure.GPIO_Pad = gpio_pupd[pupd];
103+
GPIO_InitStructure.GPIO_Mode = (GPIOMode_TypeDef)mode;
104+
GPIO_InitStructure.GPIO_Pad = (GPIOPad_TypeDef)pupd;
113105
HAL_GPIO_Init(gpio, &GPIO_InitStructure);
114106
}
115107

@@ -119,30 +111,25 @@ void pin_function(PinName pin, int data) {
119111
void pin_mode(PinName pin, PinMode pupd)
120112
{
121113
MBED_ASSERT(pin != (PinName)NC);
122-
123-
P_Port_Def *px_pcr;
124-
114+
125115
uint32_t port_num = WIZ_PORT(pin);
116+
uint32_t pin_num = WIZ_PIN_NUM(pin);
126117

127118
switch(port_num) {
128119
case PortA:
129-
px_pcr = PA_PCR;
120+
PA_PCR->Port[pin_num] |= pupd;
130121
break;
131122
case PortB:
132-
px_pcr = PB_PCR;
123+
PB_PCR->Port[pin_num] |= pupd;
133124
break;
134125
case PortC:
135-
px_pcr = PC_PCR;
126+
PC_PCR->Port[pin_num] |= pupd;
136127
break;
137128
case PortD:
138-
px_pcr = (P_Port_Def*)PD_PCR;
129+
PD_PCR->Port[pin_num] |= pupd;
139130
break;
140131
default:
141-
error("Pinmap error: wrong port number.");
132+
error("Pinmap error: wrong port number.");
142133
return;
143134
}
144-
145-
px_pcr->Port[port_num] &= ~(Px_PCR_PUPD_DOWN|Px_PCR_PUPD_UP|Px_PCR_DS_HIGH| \
146-
Px_PCR_OD | Px_PCR_IE | Px_PCR_CS_SUMMIT);
147-
px_pcr->Port[port_num] |= gpio_pupd[pupd];
148135
}

0 commit comments

Comments
 (0)