Skip to content

Commit 94c8081

Browse files
committed
PSOC6: update the HAL implementation to latest PDL
Integrate the latest fixes to the PSoC 6 HAL.
1 parent 32bf0e6 commit 94c8081

File tree

17 files changed

+1006
-597
lines changed

17 files changed

+1006
-597
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/analogin_api.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "device.h"
1919
#include "analogin_api.h"
2020
#include "cy_sar.h"
21+
#include "cy_sysanalog.h"
2122
#include "psoc6_utils.h"
2223
#include "mbed_assert.h"
2324
#include "mbed_error.h"
@@ -106,10 +107,14 @@ static void sar_init(analogin_t *obj)
106107
}
107108
Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_8_BIT,
108109
sar_clock_divider,
109-
((CY_CLK_PERICLK_FREQ_HZ + SAR_BASE_CLOCK_HZ / 2) / SAR_BASE_CLOCK_HZ) - 1);
110+
((cy_PeriClkFreqHz + SAR_BASE_CLOCK_HZ / 2) / SAR_BASE_CLOCK_HZ) - 1);
110111
Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_8_BIT, sar_clock_divider);
111112
Cy_SysClk_PeriphAssignDivider(obj->clock, CY_SYSCLK_DIV_8_BIT, sar_clock_divider);
112113

114+
/* Init and Enable the Analog Reference for SAR ADC operation */
115+
Cy_SysAnalog_Init(&Cy_SysAnalog_Fast_Local);
116+
Cy_SysAnalog_Enable();
117+
113118
Cy_SAR_Init(obj->base, &sar_config);
114119
Cy_SAR_Enable(obj->base);
115120
}
@@ -126,18 +131,22 @@ void analogin_init(analogin_t *obj, PinName pin)
126131

127132
sar = pinmap_peripheral(pin, PinMap_ADC);
128133
if (sar != (uint32_t)NC) {
129-
if (cy_reserve_io_pin(pin)) {
134+
135+
if ((0 != cy_reserve_io_pin(pin)) && !sar_initialized) {
130136
error("ANALOG IN pin reservation conflict.");
131137
}
132-
obj->base = (SAR_Type*)CY_PERIPHERAL_BASE(sar);
138+
139+
/* Initialize object */
140+
obj->base = (SAR_Type*) CY_PERIPHERAL_BASE(sar);
133141
obj->pin = pin;
134142
obj->channel_mask = 1 << CY_PIN(pin);
135143

136-
// Configure clock.
144+
/* Configure SAR hardware */
137145
sar_function = pinmap_function(pin, PinMap_ADC);
138146
obj->clock = CY_PIN_CLOCK(sar_function);
139147
sar_init(obj);
140148
pin_function(pin, sar_function);
149+
141150
} else {
142151
error("ANALOG IN pinout mismatch.");
143152
}

targets/TARGET_Cypress/TARGET_PSOC6/analogout_api.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ static void ctdac_init(dac_t *obj)
6666
dac_clock_divider = cy_clk_allocate_divider(CY_SYSCLK_DIV_8_BIT);
6767
if (dac_clock_divider == CY_INVALID_DIVIDER) {
6868
error("CTDAC clock divider allocation failed.");
69-
return;
7069
}
7170
Cy_SysClk_PeriphSetDivider(CY_SYSCLK_DIV_8_BIT,
7271
dac_clock_divider,
73-
((CY_CLK_PERICLK_FREQ_HZ + CTDAC_BASE_CLOCK_HZ / 2) / CTDAC_BASE_CLOCK_HZ) - 1);
72+
((cy_PeriClkFreqHz + CTDAC_BASE_CLOCK_HZ / 2) / CTDAC_BASE_CLOCK_HZ) - 1);
7473
Cy_SysClk_PeriphEnableDivider(CY_SYSCLK_DIV_8_BIT, dac_clock_divider);
7574
Cy_SysClk_PeriphAssignDivider(obj->clock, CY_SYSCLK_DIV_8_BIT, dac_clock_divider);
7675

@@ -90,25 +89,37 @@ void analogout_init(dac_t *obj, PinName pin)
9089

9190
dac = pinmap_peripheral(pin, PinMap_DAC);
9291
if (dac != (uint32_t)NC) {
93-
if (cy_reserve_io_pin(pin)) {
92+
93+
if ((0 != cy_reserve_io_pin(pin)) && !ctdac_initialized) {
9494
error("ANALOG OUT pin reservation conflict.");
9595
}
96+
97+
/* Initialize object */
9698
obj->base = (CTDAC_Type*)CY_PERIPHERAL_BASE(dac);
9799
obj->pin = pin;
98100

99-
// Configure clock.
101+
/* Configure CTDAC hardware */
100102
dac_function = pinmap_function(pin, PinMap_DAC);
101103
obj->clock = CY_PIN_CLOCK(dac_function);
102104
pin_function(pin, dac_function);
105+
106+
if (P9_6 != pin) {
107+
const PinName directOutput = P9_6;
108+
109+
/* Connect P9_6 to the AMUXA bus to drive output */
110+
Cy_GPIO_SetHSIOM(Cy_GPIO_PortToAddr(CY_PORT(directOutput)), CY_PIN(directOutput), HSIOM_SEL_AMUXA);
111+
}
112+
103113
ctdac_init(obj);
114+
104115
} else {
105116
error("ANALOG OUT pinout mismatch.");
106117
}
107118
}
108119

109120
void analogout_free(dac_t *obj)
110121
{
111-
// Not supported yet.
122+
/* MBED AnalogIn driver does not call this function in destructor */
112123
}
113124

114125
void analogout_write(dac_t *obj, float value)

targets/TARGET_Cypress/TARGET_PSOC6/flash_api.c

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

1717
#include "device.h"
1818
#include "flash_api.h"
19-
#include "drivers/peripheral/flash/cy_flash.h"
19+
#include "cy_flash.h"
2020

2121
#if DEVICE_FLASH
2222

targets/TARGET_Cypress/TARGET_PSOC6/gpio_api.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,14 @@ void gpio_init(gpio_t *obj, PinName pin)
6060

6161
MBED_ASSERT(CY_PIN(obj->pin) < 8); // PSoC6 architecture supports 8 pins per port.
6262

63-
/*
64-
* Perform i/o reservation only if this is called outside of critical section/interrupt context.
65-
* This is a workaround for mbed_die() implementation, which configures LED1 inside critical section.
66-
* Normally user is advised to perform all of the i/o configuration at the program beginning,
67-
* or elsewhere in the running thread context. when we detect that we are in the wrong context here,
68-
* we assume it's explicitly called from mbed_die() or other fault handling, so eventual forcing
69-
* of the pin mode is deliberate and should not cause more problems.
70-
*/
63+
/* Ignore pin reservation result because there is not possibility to release
64+
* reserved HW resource. The MBED does not provide proper destructors for
65+
* doing that.
66+
*/
7167
if (!(IsIrqMode() || IsIrqMasked())) {
72-
if (cy_reserve_io_pin(pin)) {
73-
error("GPIO pin reservation conflict.");
74-
}
68+
(void) cy_reserve_io_pin(pin);
7569
}
70+
7671
obj->port = Cy_GPIO_PortToAddr(CY_PORT(obj->pin));
7772

7873
const uint32_t outputVal = 0;

targets/TARGET_Cypress/TARGET_PSOC6/gpio_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "PinNamesTypes.h"
2323
#include "PinNames.h"
2424

25-
#include "drivers/peripheral/gpio/cy_gpio.h"
25+
#include "cy_gpio.h"
2626

2727
#ifdef __cplusplus
2828
extern "C" {

0 commit comments

Comments
 (0)