Skip to content

Commit 2e69ddd

Browse files
authored
Merge pull request #6202 from maximmbed/fix-max32625mbed
Fix max32625mbed
2 parents 772a857 + 390ba40 commit 2e69ddd

File tree

8 files changed

+103
-35
lines changed

8 files changed

+103
-35
lines changed

targets/TARGET_Maxim/TARGET_MAX32625/PeripheralPins.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ const PinMap PinMap_ADC[] = {
163163
{ AIN_3, ADC, ADC_CH_3 },
164164
{ AIN_4, ADC, ADC_CH_0_DIV_5 },
165165
{ AIN_5, ADC, ADC_CH_1_DIV_5 },
166+
{ AIN_6, ADC, ADC_CH_VDDB_DIV_4 },
167+
{ AIN_7, ADC, ADC_CH_VDD18 },
168+
{ AIN_8, ADC, ADC_CH_VDD12 },
169+
{ AIN_9, ADC, ADC_CH_VRTC_DIV_2 },
166170
{ NC, NC, 0 }
167171
};
168172

targets/TARGET_Maxim/TARGET_MAX32625/TARGET_MAX32625MBED/PinNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef enum {
6060
P4_0 = (4 << PORT_SHIFT), P4_1, P4_2, P4_3, P4_4, P4_5, P4_6, P4_7,
6161

6262
// Analog input pins
63-
AIN_0 = (0xA << PORT_SHIFT), AIN_1, AIN_2, AIN_3, AIN_4, AIN_5,
63+
AIN_0 = (0xA << PORT_SHIFT), AIN_1, AIN_2, AIN_3, AIN_4, AIN_5, AIN_6, AIN_7, AIN_8, AIN_9,
6464

6565
LED_GREEN = P3_1,
6666
LED_RED = P3_0,

targets/TARGET_Maxim/TARGET_MAX32625/TARGET_MAX32625NEXPAQ/PinNames.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef enum {
6060
P4_0 = (4 << PORT_SHIFT), P4_1, P4_2, P4_3, P4_4, P4_5, P4_6, P4_7,
6161

6262
// Analog input pins
63-
AIN_0 = (0xA << PORT_SHIFT), AIN_1, AIN_2, AIN_3, AIN_4, AIN_5,
63+
AIN_0 = (0xA << PORT_SHIFT), AIN_1, AIN_2, AIN_3, AIN_4, AIN_5, AIN_6, AIN_7, AIN_8, AIN_9,
6464

6565
// LEDs
6666
LED1 = P2_4,

targets/TARGET_Maxim/TARGET_MAX32625/analogin_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ float analogin_read(analogin_t *obj)
6565
float result;
6666

6767
// Start conversion with no input scaling and no input buffer bypass
68-
ADC_StartConvert(obj->channel, 0, 0);
68+
ADC_StartConvert(obj->channel, 1, 0);
6969

7070
if (ADC_GetData(&tmp) == E_OVERFLOW) {
7171
result = FLOAT_FULL_SCALE;
@@ -83,7 +83,7 @@ uint16_t analogin_read_u16(analogin_t *obj)
8383
uint16_t result;
8484

8585
// Start conversion with no input scaling and no input buffer bypass
86-
ADC_StartConvert(obj->channel, 0, 0);
86+
ADC_StartConvert(obj->channel, 1, 0);
8787

8888
if (ADC_GetData(&tmp) == E_OVERFLOW) {
8989
result = INT_FULL_SCALE;

targets/TARGET_Maxim/TARGET_MAX32625/i2c_api.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ int i2c_stop(i2c_t *obj)
101101
//******************************************************************************
102102
int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
103103
{
104-
MBED_ASSERT(stop != 0);
105104
return I2CM_Read(obj->i2c, address >> 1, NULL, 0, (uint8_t *)data, length);
106105
}
107106

@@ -147,11 +146,6 @@ int i2c_byte_read(i2c_t *obj, int last)
147146
if (I2CM_WriteTxFifo(i2cm, fifo, MXC_S_I2CM_TRANS_TAG_RXDATA_NACK) != E_NO_ERROR) {
148147
goto byte_write_err;
149148
}
150-
151-
// Send the stop condition
152-
if (I2CM_WriteTxFifo(i2cm, fifo, MXC_S_I2CM_TRANS_TAG_STOP) != E_NO_ERROR) {
153-
goto byte_write_err;
154-
}
155149
} else {
156150
if (I2CM_WriteTxFifo(i2cm, fifo, MXC_S_I2CM_TRANS_TAG_RXDATA_COUNT) != E_NO_ERROR) {
157151
goto byte_write_err;

targets/TARGET_Maxim/TARGET_MAX32625/serial_api.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
MXC_F_UART_INTFL_RX_FIFO_OVERFLOW)
4949

5050
// Variables for managing the stdio UART
51-
int stdio_uart_inited;
52-
serial_t stdio_uart;
51+
int stdio_uart_inited = 0;
52+
serial_t stdio_uart = {0};
5353

5454
// Variables for interrupt driven
5555
static uart_irq_handler irq_handler;
@@ -75,12 +75,6 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
7575
obj->index = MXC_UART_GET_IDX(obj->uart);
7676
obj->fifo = (mxc_uart_fifo_regs_t*)MXC_UART_GET_BASE_FIFO(obj->index);
7777

78-
// Manage stdio UART
79-
if (uart == STDIO_UART) {
80-
stdio_uart_inited = 1;
81-
memcpy(&stdio_uart, obj, sizeof(serial_t));
82-
}
83-
8478
// Record the pins requested
8579
obj->tx = tx;
8680
obj->rx = rx;
@@ -111,6 +105,12 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
111105
obj->cfg.size = UART_DATA_SIZE_8_BITS;
112106
obj->cfg.parity = UART_PARITY_DISABLE;
113107

108+
// Manage stdio UART
109+
if (uart == STDIO_UART) {
110+
stdio_uart_inited = 1;
111+
stdio_uart = *obj;
112+
}
113+
114114
int retval = UART_Init(obj->uart, &obj->cfg, &obj->sys_cfg);
115115
MBED_ASSERT(retval == E_NO_ERROR);
116116
}
@@ -181,7 +181,16 @@ void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_b
181181
void uart_handler(serial_t *obj)
182182
{
183183
if (obj && obj->id) {
184-
irq_handler(obj->id, RxIrq);
184+
// Check for errors or RX Threshold
185+
if (obj->uart->intfl & (MXC_F_UART_INTFL_RX_FIFO_NOT_EMPTY | UART_ERRORS)) {
186+
irq_handler(obj->id, RxIrq);
187+
obj->uart->intfl = (MXC_F_UART_INTFL_RX_FIFO_NOT_EMPTY | UART_ERRORS);
188+
}
189+
// Check for TX Threshold
190+
if (obj->uart->intfl & MXC_F_UART_INTFL_TX_FIFO_AE) {
191+
irq_handler(obj->id, TxIrq);
192+
obj->uart->intfl = MXC_F_UART_INTFL_TX_FIFO_AE;
193+
}
185194
}
186195
}
187196

@@ -199,6 +208,9 @@ void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
199208
//******************************************************************************
200209
void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
201210
{
211+
MBED_ASSERT(obj->index < MXC_CFG_UART_INSTANCES);
212+
objs[obj->index] = obj;
213+
202214
switch (obj->index) {
203215
case 0:
204216
NVIC_SetVector(UART0_IRQn, (uint32_t)uart0_handler);
@@ -250,7 +262,7 @@ void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
250262
//******************************************************************************
251263
int serial_getc(serial_t *obj)
252264
{
253-
int c = 0;
265+
int c = -1;
254266

255267
if (obj->rx != NC) {
256268
// Wait for data to be available

targets/TARGET_Maxim/TARGET_MAX32625/spi_api.c

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,58 @@ int spi_master_write(spi_t *obj, int value)
167167
return *req.rx_data;
168168
}
169169

170-
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length,
171-
char *rx_buffer, int rx_length, char write_fill) {
172-
int total = (tx_length > rx_length) ? tx_length : rx_length;
173-
174-
for (int i = 0; i < total; i++) {
175-
char out = (i < tx_length) ? tx_buffer[i] : write_fill;
176-
char in = spi_master_write(obj, out);
177-
if (i < rx_length) {
178-
rx_buffer[i] = in;
170+
//******************************************************************************
171+
int spi_master_block_write(spi_t *obj, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, char write_fill)
172+
{
173+
spim_req_t req;
174+
175+
if (!(tx_length | rx_length) ||
176+
(tx_length < 0) ||
177+
(rx_length < 0)) {
178+
return 0;
179+
}
180+
181+
req.width = SPIM_WIDTH_1;
182+
req.ssel = 0;
183+
req.deass = 1;
184+
req.callback = NULL;
185+
186+
core_util_critical_section_enter();
187+
if (tx_length == rx_length) {
188+
req.tx_data = (uint8_t *)tx_buffer;
189+
req.rx_data = (uint8_t *)rx_buffer;
190+
req.len = tx_length;
191+
SPIM_Trans(obj->spi, &req);
192+
} else if (tx_length < rx_length) {
193+
req.tx_data = (tx_length > 0) ? (uint8_t *)tx_buffer : NULL;
194+
req.rx_data = (uint8_t *)rx_buffer;
195+
req.len = (tx_length > 0) ? tx_length : rx_length;
196+
SPIM_Trans(obj->spi, &req);
197+
198+
if (tx_length) {
199+
req.tx_data = NULL;
200+
req.rx_data = (uint8_t *)(rx_buffer + tx_length);
201+
req.len = rx_length - tx_length;
202+
SPIM_Trans(obj->spi, &req);
203+
}
204+
} else {
205+
req.tx_data = (uint8_t *)tx_buffer;
206+
req.rx_data = (rx_length > 0) ? (uint8_t *)rx_buffer : NULL;
207+
req.len = (rx_length > 0) ? rx_length : tx_length;
208+
SPIM_Trans(obj->spi, &req);
209+
210+
if (rx_length) {
211+
req.tx_data = (uint8_t *)(tx_buffer + rx_length);
212+
req.rx_data = NULL;
213+
req.len = tx_length - rx_length;
214+
SPIM_Trans(obj->spi, &req);
179215
}
180216
}
217+
core_util_critical_section_exit();
218+
219+
while (SPIM_Busy(obj->spi));
181220

182-
return total;
221+
return tx_length > rx_length ? tx_length : rx_length;
183222
}
184223

185224
//******************************************************************************
@@ -193,4 +232,3 @@ uint8_t spi_get_module(spi_t *obj)
193232
{
194233
return obj->index;
195234
}
196-

targets/TARGET_Maxim/TARGET_MAX32625/us_ticker.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333

3434
#include <stddef.h>
3535
#include "mbed_error.h"
36+
#include "mbed_critical.h"
3637
#include "us_ticker_api.h"
3738
#include "PeripheralNames.h"
3839
#include "tmr.h"
40+
#include "assert.h"
3941

4042
#define US_TIMER MXC_TMR0
4143
#define US_TIMER_IRQn TMR0_0_IRQn
@@ -49,7 +51,7 @@ static volatile uint64_t event_cnt; // Holds the value of the next event
4951
#define MAX_TICK_VAL ((uint64_t)0xFFFFFFFF * ticks_per_us)
5052

5153
//******************************************************************************
52-
static inline void inc_current_cnt(uint32_t inc)
54+
static inline void inc_current_cnt_no_crit(uint32_t inc)
5355
{
5456
// Overflow the ticker when the us ticker overflows
5557
current_cnt += inc;
@@ -58,6 +60,14 @@ static inline void inc_current_cnt(uint32_t inc)
5860
}
5961
}
6062

63+
//******************************************************************************
64+
static inline void inc_current_cnt(uint32_t inc)
65+
{
66+
core_util_critical_section_enter();
67+
inc_current_cnt_no_crit(inc);
68+
core_util_critical_section_exit();
69+
}
70+
6171
//******************************************************************************
6272
static inline int event_passed(uint64_t current, uint64_t event)
6373
{
@@ -89,11 +99,12 @@ static void tmr_handler(void)
8999
{
90100
uint32_t cmp = TMR32_GetCompare(US_TIMER);
91101
TMR32_SetCompare(US_TIMER, 0xFFFFFFFF); // reset to max value to prevent further interrupts
102+
if (TMR32_GetFlag(US_TIMER)) {
103+
inc_current_cnt_no_crit(cmp);
104+
}
92105
TMR32_ClearFlag(US_TIMER);
93106
NVIC_ClearPendingIRQ(US_TIMER_IRQn);
94107

95-
inc_current_cnt(cmp);
96-
97108
if (event_passed(current_cnt + TMR32_GetCount(US_TIMER), event_cnt)) {
98109
// the timestamp has expired
99110
event_cnt = 0xFFFFFFFFFFFFFFFFULL; // reset to max value
@@ -162,6 +173,7 @@ uint32_t us_ticker_read(void)
162173
uint64_t current_cnt1, current_cnt2;
163174
uint32_t cmp, cnt;
164175
uint32_t flag1, flag2;
176+
static uint32_t last = 0;
165177

166178
if (!us_ticker_inited) {
167179
us_ticker_init();
@@ -179,12 +191,19 @@ uint32_t us_ticker_read(void)
179191

180192
// Account for an unserviced interrupt
181193
if (flag1) {
194+
// Clear peripheral interrupt flag; leaving NVIC pending set
195+
TMR32_ClearFlag(US_TIMER);
196+
// Advance global count
197+
inc_current_cnt(cmp + cnt);
198+
182199
current_cnt1 += cmp;
183200
}
184201

185202
current_cnt1 += cnt;
186203

187-
return (current_cnt1 / ticks_per_us);
204+
assert(last <= (current_cnt1 / ticks_per_us));
205+
last = (current_cnt1 / ticks_per_us);
206+
return last;
188207
}
189208

190209
//******************************************************************************
@@ -228,6 +247,7 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
228247
TMR32_Start(US_TIMER);
229248
}
230249

250+
//******************************************************************************
231251
void us_ticker_fire_interrupt(void)
232252
{
233253
TMR32_SetCompare(US_TIMER, 1);

0 commit comments

Comments
 (0)