Skip to content

Commit fde2a5c

Browse files
committed
STM32 : enable MBED trace for QSPI
1 parent d847f9f commit fde2a5c

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

targets/TARGET_STM/qspi_api.c

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
/* mbed Microcontroller Library
2-
* Copyright (c) 2017, ARM Limited
3-
* All rights reserved.
1+
/*
2+
* Copyright (c) 2017, Arm Limited and affiliates.
3+
* Copyright (c) 2017, STMicroelectronics.
4+
* SPDX-License-Identifier: Apache-2.0
45
*
5-
* Redistribution and use in source and binary forms, with or without
6-
* modification, are permitted provided that the following conditions are met:
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
79
*
8-
* 1. Redistributions of source code must retain the above copyright notice,
9-
* this list of conditions and the following disclaimer.
10-
* 2. Redistributions in binary form must reproduce the above copyright notice,
11-
* this list of conditions and the following disclaimer in the documentation
12-
* and/or other materials provided with the distribution.
13-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
14-
* may be used to endorse or promote products derived from this software
15-
* without specific prior written permission.
10+
* http://www.apache.org/licenses/LICENSE-2.0
1611
*
17-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
2717
*/
2818

2919
#if DEVICE_QSPI
@@ -35,6 +25,14 @@
3525
#include "pinmap.h"
3626
#include "PeripheralPins.h"
3727

28+
#include "mbed_trace.h"
29+
30+
#if defined(OCTOSPI1)
31+
#define TRACE_GROUP "ST_OSPI"
32+
#else
33+
#define TRACE_GROUP "ST_QSPI"
34+
#endif /* OCTOSPI1 */
35+
3836
// activate / de-activate debug
3937
#define qspi_api_c_debug 0
4038

@@ -390,7 +388,7 @@ static qspi_status_t _qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap,
390388
#endif
391389
{
392390
OSPIM_CfgTypeDef OSPIM_Cfg_Struct = {0};
393-
debug_if(qspi_api_c_debug, "qspi_init mode %u\n", mode);
391+
tr_info("qspi_init mode %u", mode);
394392

395393
// Reset handle internal state
396394
obj->handle.State = HAL_OSPI_STATE_RESET;
@@ -479,7 +477,7 @@ static qspi_status_t _qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap,
479477
}
480478

481479
if (HAL_OSPIM_Config(&obj->handle, &OSPIM_Cfg_Struct, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
482-
debug_if(qspi_api_c_debug, "HAL_OSPIM_Config error\n");
480+
tr_error("HAL_OSPIM_Config error");
483481
return QSPI_STATUS_ERROR;
484482
}
485483

@@ -525,7 +523,7 @@ qspi_status_t qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap, uint32_
525523
static qspi_status_t _qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap, uint32_t hz, uint8_t mode)
526524
#endif
527525
{
528-
debug_if(qspi_api_c_debug, "qspi_init mode %u\n", mode);
526+
tr_info("qspi_init mode %u", mode);
529527
// Enable interface clock for QSPI
530528
__HAL_RCC_QSPI_CLK_ENABLE();
531529

@@ -622,7 +620,7 @@ qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinN
622620
#if defined(OCTOSPI1)
623621
qspi_status_t qspi_free(qspi_t *obj)
624622
{
625-
debug_if(qspi_api_c_debug, "qspi_free\n");
623+
tr_info("qspi_free");
626624
if (HAL_OSPI_DeInit(&obj->handle) != HAL_OK) {
627625
return QSPI_STATUS_ERROR;
628626
}
@@ -654,6 +652,8 @@ qspi_status_t qspi_free(qspi_t *obj)
654652
#else /* OCTOSPI */
655653
qspi_status_t qspi_free(qspi_t *obj)
656654
{
655+
tr_info("qspi_free");
656+
657657
if (HAL_QSPI_DeInit(&obj->handle) != HAL_OK) {
658658
return QSPI_STATUS_ERROR;
659659
}
@@ -689,7 +689,7 @@ qspi_status_t qspi_free(qspi_t *obj)
689689
#if defined(OCTOSPI1)
690690
qspi_status_t qspi_frequency(qspi_t *obj, int hz)
691691
{
692-
debug_if(qspi_api_c_debug, "qspi_frequency hz %d\n", hz);
692+
tr_info("qspi_frequency hz %d", hz);
693693
qspi_status_t status = QSPI_STATUS_OK;
694694

695695
/* HCLK drives QSPI. QSPI clock depends on prescaler value:
@@ -711,7 +711,7 @@ qspi_status_t qspi_frequency(qspi_t *obj, int hz)
711711
obj->handle.Init.ClockPrescaler = div;
712712

713713
if (HAL_OSPI_Init(&obj->handle) != HAL_OK) {
714-
debug_if(qspi_api_c_debug, "HAL_OSPI_Init error\n");
714+
tr_error("HAL_OSPI_Init error");
715715
status = QSPI_STATUS_ERROR;
716716
}
717717

@@ -720,7 +720,7 @@ qspi_status_t qspi_frequency(qspi_t *obj, int hz)
720720
#else /* OCTOSPI */
721721
qspi_status_t qspi_frequency(qspi_t *obj, int hz)
722722
{
723-
debug_if(qspi_api_c_debug, "qspi_frequency hz %d\n", hz);
723+
tr_info("qspi_frequency hz %d", hz);
724724
qspi_status_t status = QSPI_STATUS_OK;
725725

726726
/* HCLK drives QSPI. QSPI clock depends on prescaler value:
@@ -764,11 +764,11 @@ qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void
764764
st_command.NbData = *length;
765765

766766
if (HAL_OSPI_Command(&obj->handle, &st_command, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
767-
debug_if(qspi_api_c_debug, "HAL_OSPI_Command error\n");
767+
tr_error("HAL_OSPI_Command error");
768768
status = QSPI_STATUS_ERROR;
769769
} else {
770770
if (HAL_OSPI_Transmit(&obj->handle, (uint8_t *)data, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
771-
debug_if(qspi_api_c_debug, "HAL_OSPI_Transmit error\n");
771+
tr_error("HAL_OSPI_Transmit error");
772772
status = QSPI_STATUS_ERROR;
773773
}
774774
}
@@ -778,6 +778,8 @@ qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void
778778
#else /* OCTOSPI */
779779
qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void *data, size_t *length)
780780
{
781+
debug_if(qspi_api_c_debug, "qspi_write size %u\n", *length);
782+
781783
QSPI_CommandTypeDef st_command;
782784
qspi_status_t status = qspi_prepare_command(command, &st_command);
783785
if (status != QSPI_STATUS_OK) {
@@ -813,11 +815,11 @@ qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data,
813815
st_command.NbData = *length;
814816

815817
if (HAL_OSPI_Command(&obj->handle, &st_command, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
816-
debug_if(qspi_api_c_debug, "HAL_OSPI_Command error\n");
818+
tr_error("HAL_OSPI_Command error");
817819
status = QSPI_STATUS_ERROR;
818820
} else {
819821
if (HAL_OSPI_Receive(&obj->handle, data, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
820-
debug_if(qspi_api_c_debug, "HAL_OSPI_Receive error\n");
822+
tr_error("HAL_OSPI_Receive error %d", obj->handle.ErrorCode);
821823
status = QSPI_STATUS_ERROR;
822824
}
823825
}
@@ -855,7 +857,8 @@ qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data,
855857
#if defined(OCTOSPI1)
856858
qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command, const void *tx_data, size_t tx_size, void *rx_data, size_t rx_size)
857859
{
858-
debug_if(qspi_api_c_debug, "qspi_command_transfer tx %u rx %u command %x\n", tx_size, rx_size, command->instruction.value);
860+
tr_info("qspi_command_transfer tx %u rx %u command %#04x", tx_size, rx_size, command->instruction.value);
861+
859862
qspi_status_t status = QSPI_STATUS_OK;
860863

861864
if ((tx_data == NULL || tx_size == 0) && (rx_data == NULL || rx_size == 0)) {
@@ -870,7 +873,7 @@ qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command,
870873
st_command.DataMode = HAL_OSPI_DATA_NONE; /* Instruction only */
871874
if (HAL_OSPI_Command(&obj->handle, &st_command, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
872875
status = QSPI_STATUS_ERROR;
873-
debug_if(qspi_api_c_debug, "HAL_OSPI_Command error\n");
876+
tr_error("HAL_OSPI_Command error");
874877
return status;
875878
}
876879
} else {
@@ -879,23 +882,22 @@ qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command,
879882
size_t tx_length = tx_size;
880883
status = qspi_write(obj, command, tx_data, &tx_length);
881884
if (status != QSPI_STATUS_OK) {
882-
debug_if(qspi_api_c_debug, "qspi_write error\n");
885+
tr_error("qspi_write error");
883886
return status;
884887
}
885888
}
886889

887890
if (rx_data != NULL && rx_size) {
888891
size_t rx_length = rx_size;
889892
status = qspi_read(obj, command, rx_data, &rx_length);
890-
// debug_if(qspi_api_c_debug, "qspi_read %d\n", status);
891893
}
892894
}
893895
return status;
894896
}
895897
#else /* OCTOSPI */
896898
qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command, const void *tx_data, size_t tx_size, void *rx_data, size_t rx_size)
897899
{
898-
debug_if(qspi_api_c_debug, "qspi_command_transfer tx %u rx %u command %x\n", tx_size, rx_size, command->instruction.value);
900+
tr_info("qspi_command_transfer tx %u rx %u command %#04x", tx_size, rx_size, command->instruction.value);
899901
qspi_status_t status = QSPI_STATUS_OK;
900902

901903
if ((tx_data == NULL || tx_size == 0) && (rx_data == NULL || rx_size == 0)) {

0 commit comments

Comments
 (0)