Skip to content

Commit f50403a

Browse files
author
Cruz Monrreal
authored
Merge pull request #8905 from lrusinowicz/spi_fixes
SPI and deep sleep fixes for FUTURE_SEQUANA target.
2 parents 23022dd + ea5dcca commit f50403a

File tree

5 files changed

+48
-27
lines changed

5 files changed

+48
-27
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/i2c_api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static int i2c_convert_status(cy_en_scb_i2c_status_t status)
264264
/*
265265
* Callback function to handle into and out of deep sleep state transitions.
266266
*/
267-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
267+
#if DEVICE_SLEEP && DEVICE_LPTICKER
268268
static cy_en_syspm_status_t i2c_pm_callback(cy_stc_syspm_callback_params_t *callback_params)
269269
{
270270
cy_stc_syspm_callback_params_t params = *callback_params;
@@ -273,7 +273,7 @@ static cy_en_syspm_status_t i2c_pm_callback(cy_stc_syspm_callback_params_t *call
273273

274274
return Cy_SCB_I2C_DeepSleepCallback(&params);
275275
}
276-
#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
276+
#endif // DEVICE_SLEEP && DEVICE_LPTICKER
277277

278278

279279
void i2c_init(i2c_t *obj_in, PinName sda, PinName scl)
@@ -300,7 +300,7 @@ void i2c_init(i2c_t *obj_in, PinName sda, PinName scl)
300300
i2c_init_clock(obj, I2C_DEFAULT_SPEED);
301301
i2c_init_pins(obj);
302302
i2c_init_peripheral(obj);
303-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
303+
#if DEVICE_SLEEP && DEVICE_LPTICKER
304304
obj->pm_callback_handler.callback = i2c_pm_callback;
305305
obj->pm_callback_handler.type = CY_SYSPM_DEEPSLEEP;
306306
obj->pm_callback_handler.skipMode = 0;
@@ -310,7 +310,7 @@ void i2c_init(i2c_t *obj_in, PinName sda, PinName scl)
310310
if (!Cy_SysPm_RegisterCallback(&obj->pm_callback_handler)) {
311311
error("PM callback registration failed!");
312312
}
313-
#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
313+
#endif // DEVICE_SLEEP && DEVICE_LPTICKER
314314
} else {
315315
error("I2C pinout mismatch. Requested pins Rx and Tx can't be used for the same I2C communication.");
316316
}

targets/TARGET_Cypress/TARGET_PSOC6/objects.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct serial_s {
8686
bool tx_pending;
8787
cy_israddress async_handler;
8888
#endif // DEVICE_SERIAL_ASYNCH
89-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
89+
#if DEVICE_SLEEP && DEVICE_LPTICKER
9090
cy_stc_syspm_callback_params_t pm_callback_params;
9191
cy_stc_syspm_callback_t pm_callback_handler;
9292
#endif
@@ -124,7 +124,7 @@ struct spi_s {
124124
void *tx_buffer;
125125
uint32_t tx_buffer_size;
126126
#endif // DEVICE_SPI_ASYNCH
127-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
127+
#if DEVICE_SLEEP && DEVICE_LPTICKER
128128
cy_stc_syspm_callback_params_t pm_callback_params;
129129
cy_stc_syspm_callback_t pm_callback_handler;
130130
#endif
@@ -160,7 +160,7 @@ struct i2c_s {
160160
uint16_t events;
161161
uint32_t handler;
162162
#endif // DEVICE_I2C_ASYNCH
163-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
163+
#if DEVICE_SLEEP && DEVICE_LPTICKER
164164
cy_stc_syspm_callback_params_t pm_callback_params;
165165
cy_stc_syspm_callback_t pm_callback_handler;
166166
#endif
@@ -178,7 +178,7 @@ struct pwmout_s {
178178
uint32_t period;
179179
uint32_t pulse_width;
180180
uint32_t prescaler;
181-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
181+
#if DEVICE_SLEEP && DEVICE_LPTICKER
182182
cy_stc_syspm_callback_params_t pm_callback_params;
183183
cy_stc_syspm_callback_t pm_callback_handler;
184184
#endif

targets/TARGET_Cypress/TARGET_PSOC6/pwmout_api.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static void pwm_start(pwmout_t *obj, uint32_t new_period, uint32_t new_pulse_wid
120120
/*
121121
* Callback handler to restart the timer after deep sleep.
122122
*/
123-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
123+
#if DEVICE_SLEEP && DEVICE_LPTICKER
124124
static cy_en_syspm_status_t pwm_pm_callback(cy_stc_syspm_callback_params_t *callback_params)
125125
{
126126
pwmout_t *obj = (pwmout_t *)callback_params->context;
@@ -145,7 +145,7 @@ static cy_en_syspm_status_t pwm_pm_callback(cy_stc_syspm_callback_params_t *call
145145

146146
return CY_SYSPM_SUCCESS;
147147
}
148-
#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
148+
#endif // DEVICE_SLEEP && DEVICE_LPTICKER
149149

150150

151151
void pwmout_init(pwmout_t *obj, PinName pin)
@@ -198,17 +198,17 @@ void pwmout_init(pwmout_t *obj, PinName pin)
198198
obj->period = 0;
199199
obj->pulse_width = 0;
200200
obj->prescaler = 0;
201-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
201+
#if DEVICE_SLEEP && DEVICE_LPTICKER
202202
obj->pm_callback_handler.callback = pwm_pm_callback;
203203
obj->pm_callback_handler.type = CY_SYSPM_DEEPSLEEP;
204-
obj->pm_callback_handler.skipMode = CY_SYSPM_SKIP_CHECK_READY | CY_SYSPM_SKIP_CHECK_FAIL;
204+
obj->pm_callback_handler.skipMode = 0;
205205
obj->pm_callback_handler.callbackParams = &obj->pm_callback_params;
206206
obj->pm_callback_params.base = obj->base;
207207
obj->pm_callback_params.context = obj;
208208
if (!Cy_SysPm_RegisterCallback(&obj->pm_callback_handler)) {
209209
error("PM callback registration failed!");
210210
}
211-
#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
211+
#endif // DEVICE_SLEEP && DEVICE_LPTICKER
212212

213213
} else {
214214
error("PWM OUT pinout mismatch.");

targets/TARGET_Cypress/TARGET_PSOC6/serial_api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static void serial_init_peripheral(serial_obj_t *obj)
345345
Cy_SCB_UART_Enable(obj->base);
346346
}
347347

348-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
348+
#if DEVICE_SLEEP && DEVICE_LPTICKER && SERIAL_PM_CALLBACK_ENABLED
349349
static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *params)
350350
{
351351
serial_obj_t *obj = (serial_obj_t *)params->context;
@@ -393,7 +393,7 @@ static cy_en_syspm_status_t serial_pm_callback(cy_stc_syspm_callback_params_t *p
393393
}
394394
return status;
395395
}
396-
#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
396+
#endif // DEVICE_SLEEP && DEVICE_LPTICKER
397397

398398
void serial_init(serial_t *obj_in, PinName tx, PinName rx)
399399
{
@@ -425,7 +425,7 @@ void serial_init(serial_t *obj_in, PinName tx, PinName rx)
425425
//Cy_GPIO_Write(Cy_GPIO_PortToAddr(CY_PORT(P13_6)), CY_PIN(P13_6), 1);
426426
serial_init_pins(obj);
427427
//Cy_GPIO_Write(Cy_GPIO_PortToAddr(CY_PORT(P13_6)), CY_PIN(P13_6), 0);
428-
#if DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
428+
#if DEVICE_SLEEP && DEVICE_LPTICKER && SERIAL_PM_CALLBACK_ENABLED
429429
obj->pm_callback_handler.callback = serial_pm_callback;
430430
obj->pm_callback_handler.type = CY_SYSPM_DEEPSLEEP;
431431
obj->pm_callback_handler.skipMode = 0;
@@ -435,7 +435,7 @@ void serial_init(serial_t *obj_in, PinName tx, PinName rx)
435435
if (!Cy_SysPm_RegisterCallback(&obj->pm_callback_handler)) {
436436
error("PM callback registration failed!");
437437
}
438-
#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
438+
#endif // DEVICE_SLEEP && DEVICE_LPTICKER
439439
if (is_stdio) {
440440
memcpy(&stdio_uart, obj_in, sizeof(serial_t));
441441
stdio_uart_inited = true;

targets/TARGET_Cypress/TARGET_PSOC6/spi_api.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,36 @@ static cy_en_sysclk_status_t spi_init_clock(spi_obj_t *obj, uint32_t frequency)
170170
*/
171171
static void spi_init_pins(spi_obj_t *obj)
172172
{
173-
if (cy_reserve_io_pin(obj->pin_sclk) ||
174-
cy_reserve_io_pin(obj->pin_mosi) ||
175-
cy_reserve_io_pin(obj->pin_miso) ||
176-
cy_reserve_io_pin(obj->pin_ssel)) {
173+
bool conflict = false;
174+
conflict = cy_reserve_io_pin(obj->pin_sclk);
175+
if (!conflict) {
176+
pin_function(obj->pin_sclk, pinmap_function(obj->pin_sclk, PinMap_SPI_SCLK));
177+
}
178+
if (obj->pin_mosi != NC) {
179+
if (!cy_reserve_io_pin(obj->pin_mosi)) {
180+
pin_function(obj->pin_mosi, pinmap_function(obj->pin_mosi, PinMap_SPI_MOSI));
181+
} else {
182+
conflict = true;
183+
}
184+
}
185+
if (obj->pin_miso != NC) {
186+
if (!cy_reserve_io_pin(obj->pin_miso)) {
187+
pin_function(obj->pin_miso, pinmap_function(obj->pin_miso, PinMap_SPI_MISO));
188+
} else {
189+
conflict = true;
190+
}
191+
}
192+
if (obj->pin_ssel != NC) {
193+
if (!cy_reserve_io_pin(obj->pin_ssel)) {
194+
pin_function(obj->pin_ssel, pinmap_function(obj->pin_ssel, PinMap_SPI_SSEL));
195+
} else {
196+
conflict = true;
197+
}
198+
}
199+
if (conflict) {
177200
error("SPI pin reservation conflict.");
178201
}
179-
pin_function(obj->pin_sclk, pinmap_function(obj->pin_sclk, PinMap_SPI_SCLK));
180-
pin_function(obj->pin_mosi, pinmap_function(obj->pin_mosi, PinMap_SPI_MOSI));
181-
pin_function(obj->pin_miso, pinmap_function(obj->pin_miso, PinMap_SPI_MISO));
182-
pin_function(obj->pin_ssel, pinmap_function(obj->pin_ssel, PinMap_SPI_SSEL));
202+
183203
// Pin configuration in PinMap defaults to Master mode; revert for Slave.
184204
if (obj->ms_mode == CY_SCB_SPI_SLAVE) {
185205
pin_mode(obj->pin_sclk, PullNone);
@@ -276,7 +296,7 @@ void spi_init(spi_t *obj_in, PinName mosi, PinName miso, PinName sclk, PinName s
276296
}
277297
#endif // DEVICE_SLEEP && DEVICE_LOWPOWERTIMER
278298
} else {
279-
error("Serial pinout mismatch. Requested pins Rx and Tx can't be used for the same Serial communication.");
299+
error("SPI pinout mismatch. Requested Rx and Tx pins can't be used for the same SPI communication.");
280300
}
281301
}
282302

@@ -367,9 +387,10 @@ int spi_master_block_write(spi_t *obj_in, const char *tx_buffer, int tx_length,
367387
++rx_count;
368388
}
369389
}
370-
// Read any ramaining bytes from the fifo.
390+
// Read any remaining bytes from the fifo.
371391
while (rx_count < rx_length) {
372392
*rx_buffer++ = (char)Cy_SCB_SPI_Read(obj->base);
393+
++rx_count;
373394
}
374395
// Clean up if we have read less bytes than available.
375396
Cy_SCB_SPI_ClearRxFifo(obj->base);

0 commit comments

Comments
 (0)