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
4
5
*
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
7
9
*
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
16
11
*
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.
27
17
*/
28
18
29
19
#if DEVICE_QSPI
35
25
#include "pinmap.h"
36
26
#include "PeripheralPins.h"
37
27
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
+
38
36
// activate / de-activate debug
39
37
#define qspi_api_c_debug 0
40
38
@@ -390,7 +388,7 @@ static qspi_status_t _qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap,
390
388
#endif
391
389
{
392
390
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 );
394
392
395
393
// Reset handle internal state
396
394
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,
479
477
}
480
478
481
479
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" );
483
481
return QSPI_STATUS_ERROR ;
484
482
}
485
483
@@ -525,7 +523,7 @@ qspi_status_t qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap, uint32_
525
523
static qspi_status_t _qspi_init_direct (qspi_t * obj , const qspi_pinmap_t * pinmap , uint32_t hz , uint8_t mode )
526
524
#endif
527
525
{
528
- debug_if ( qspi_api_c_debug , "qspi_init mode %u\n " , mode );
526
+ tr_info ( "qspi_init mode %u" , mode );
529
527
// Enable interface clock for QSPI
530
528
__HAL_RCC_QSPI_CLK_ENABLE ();
531
529
@@ -622,7 +620,7 @@ qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinN
622
620
#if defined(OCTOSPI1 )
623
621
qspi_status_t qspi_free (qspi_t * obj )
624
622
{
625
- debug_if ( qspi_api_c_debug , "qspi_free\n " );
623
+ tr_info ( "qspi_free" );
626
624
if (HAL_OSPI_DeInit (& obj -> handle ) != HAL_OK ) {
627
625
return QSPI_STATUS_ERROR ;
628
626
}
@@ -654,6 +652,8 @@ qspi_status_t qspi_free(qspi_t *obj)
654
652
#else /* OCTOSPI */
655
653
qspi_status_t qspi_free (qspi_t * obj )
656
654
{
655
+ tr_info ("qspi_free" );
656
+
657
657
if (HAL_QSPI_DeInit (& obj -> handle ) != HAL_OK ) {
658
658
return QSPI_STATUS_ERROR ;
659
659
}
@@ -689,7 +689,7 @@ qspi_status_t qspi_free(qspi_t *obj)
689
689
#if defined(OCTOSPI1 )
690
690
qspi_status_t qspi_frequency (qspi_t * obj , int hz )
691
691
{
692
- debug_if ( qspi_api_c_debug , "qspi_frequency hz %d\n " , hz );
692
+ tr_info ( "qspi_frequency hz %d" , hz );
693
693
qspi_status_t status = QSPI_STATUS_OK ;
694
694
695
695
/* HCLK drives QSPI. QSPI clock depends on prescaler value:
@@ -711,7 +711,7 @@ qspi_status_t qspi_frequency(qspi_t *obj, int hz)
711
711
obj -> handle .Init .ClockPrescaler = div ;
712
712
713
713
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" );
715
715
status = QSPI_STATUS_ERROR ;
716
716
}
717
717
@@ -720,7 +720,7 @@ qspi_status_t qspi_frequency(qspi_t *obj, int hz)
720
720
#else /* OCTOSPI */
721
721
qspi_status_t qspi_frequency (qspi_t * obj , int hz )
722
722
{
723
- debug_if ( qspi_api_c_debug , "qspi_frequency hz %d\n " , hz );
723
+ tr_info ( "qspi_frequency hz %d" , hz );
724
724
qspi_status_t status = QSPI_STATUS_OK ;
725
725
726
726
/* 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
764
764
st_command .NbData = * length ;
765
765
766
766
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" );
768
768
status = QSPI_STATUS_ERROR ;
769
769
} else {
770
770
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" );
772
772
status = QSPI_STATUS_ERROR ;
773
773
}
774
774
}
@@ -778,6 +778,8 @@ qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void
778
778
#else /* OCTOSPI */
779
779
qspi_status_t qspi_write (qspi_t * obj , const qspi_command_t * command , const void * data , size_t * length )
780
780
{
781
+ debug_if (qspi_api_c_debug , "qspi_write size %u\n" , * length );
782
+
781
783
QSPI_CommandTypeDef st_command ;
782
784
qspi_status_t status = qspi_prepare_command (command , & st_command );
783
785
if (status != QSPI_STATUS_OK ) {
@@ -813,11 +815,11 @@ qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data,
813
815
st_command .NbData = * length ;
814
816
815
817
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" );
817
819
status = QSPI_STATUS_ERROR ;
818
820
} else {
819
821
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 );
821
823
status = QSPI_STATUS_ERROR ;
822
824
}
823
825
}
@@ -855,7 +857,8 @@ qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data,
855
857
#if defined(OCTOSPI1 )
856
858
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 )
857
859
{
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
+
859
862
qspi_status_t status = QSPI_STATUS_OK ;
860
863
861
864
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,
870
873
st_command .DataMode = HAL_OSPI_DATA_NONE ; /* Instruction only */
871
874
if (HAL_OSPI_Command (& obj -> handle , & st_command , HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK ) {
872
875
status = QSPI_STATUS_ERROR ;
873
- debug_if ( qspi_api_c_debug , "HAL_OSPI_Command error\n " );
876
+ tr_error ( "HAL_OSPI_Command error" );
874
877
return status ;
875
878
}
876
879
} else {
@@ -879,23 +882,22 @@ qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command,
879
882
size_t tx_length = tx_size ;
880
883
status = qspi_write (obj , command , tx_data , & tx_length );
881
884
if (status != QSPI_STATUS_OK ) {
882
- debug_if ( qspi_api_c_debug , "qspi_write error\n " );
885
+ tr_error ( "qspi_write error" );
883
886
return status ;
884
887
}
885
888
}
886
889
887
890
if (rx_data != NULL && rx_size ) {
888
891
size_t rx_length = rx_size ;
889
892
status = qspi_read (obj , command , rx_data , & rx_length );
890
- // debug_if(qspi_api_c_debug, "qspi_read %d\n", status);
891
893
}
892
894
}
893
895
return status ;
894
896
}
895
897
#else /* OCTOSPI */
896
898
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 )
897
899
{
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 );
899
901
qspi_status_t status = QSPI_STATUS_OK ;
900
902
901
903
if ((tx_data == NULL || tx_size == 0 ) && (rx_data == NULL || rx_size == 0 )) {
0 commit comments