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
38
- // activate / de-activate debug
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
+
36
+ // activate / de-activate extra debug
39
37
#define qspi_api_c_debug 0
40
38
41
39
/* Max amount of flash size is 4Gbytes */
@@ -389,7 +387,7 @@ qspi_status_t qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap, uint32_
389
387
static qspi_status_t _qspi_init_direct (qspi_t * obj , const qspi_pinmap_t * pinmap , uint32_t hz , uint8_t mode )
390
388
#endif
391
389
{
392
- debug_if ( qspi_api_c_debug , "qspi_init mode %u\n " , mode );
390
+ tr_info ( "qspi_init mode %u" , mode );
393
391
394
392
// Reset handle internal state
395
393
obj -> handle .State = HAL_OSPI_STATE_RESET ;
@@ -488,7 +486,7 @@ static qspi_status_t _qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap,
488
486
}
489
487
490
488
if (HAL_OSPIM_Config (& obj -> handle , & OSPIM_Cfg_Struct , HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK ) {
491
- debug_if ( qspi_api_c_debug , "HAL_OSPIM_Config error\n " );
489
+ tr_error ( "HAL_OSPIM_Config error" );
492
490
return QSPI_STATUS_ERROR ;
493
491
}
494
492
#endif
@@ -535,7 +533,7 @@ qspi_status_t qspi_init_direct(qspi_t *obj, const qspi_pinmap_t *pinmap, uint32_
535
533
static qspi_status_t _qspi_init_direct (qspi_t * obj , const qspi_pinmap_t * pinmap , uint32_t hz , uint8_t mode )
536
534
#endif
537
535
{
538
- debug_if ( qspi_api_c_debug , "qspi_init mode %u\n " , mode );
536
+ tr_info ( "qspi_init mode %u" , mode );
539
537
// Enable interface clock for QSPI
540
538
__HAL_RCC_QSPI_CLK_ENABLE ();
541
539
@@ -632,7 +630,7 @@ qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinN
632
630
#if defined(OCTOSPI1 )
633
631
qspi_status_t qspi_free (qspi_t * obj )
634
632
{
635
- debug_if ( qspi_api_c_debug , "qspi_free\n " );
633
+ tr_info ( "qspi_free" );
636
634
if (HAL_OSPI_DeInit (& obj -> handle ) != HAL_OK ) {
637
635
return QSPI_STATUS_ERROR ;
638
636
}
@@ -664,6 +662,8 @@ qspi_status_t qspi_free(qspi_t *obj)
664
662
#else /* OCTOSPI */
665
663
qspi_status_t qspi_free (qspi_t * obj )
666
664
{
665
+ tr_info ("qspi_free" );
666
+
667
667
if (HAL_QSPI_DeInit (& obj -> handle ) != HAL_OK ) {
668
668
return QSPI_STATUS_ERROR ;
669
669
}
@@ -699,7 +699,7 @@ qspi_status_t qspi_free(qspi_t *obj)
699
699
#if defined(OCTOSPI1 )
700
700
qspi_status_t qspi_frequency (qspi_t * obj , int hz )
701
701
{
702
- debug_if ( qspi_api_c_debug , "qspi_frequency hz %d\n " , hz );
702
+ tr_info ( "qspi_frequency hz %d" , hz );
703
703
qspi_status_t status = QSPI_STATUS_OK ;
704
704
705
705
/* HCLK drives QSPI. QSPI clock depends on prescaler value:
@@ -721,7 +721,7 @@ qspi_status_t qspi_frequency(qspi_t *obj, int hz)
721
721
obj -> handle .Init .ClockPrescaler = div ;
722
722
723
723
if (HAL_OSPI_Init (& obj -> handle ) != HAL_OK ) {
724
- debug_if ( qspi_api_c_debug , "HAL_OSPI_Init error\n " );
724
+ tr_error ( "HAL_OSPI_Init error" );
725
725
status = QSPI_STATUS_ERROR ;
726
726
}
727
727
@@ -730,7 +730,7 @@ qspi_status_t qspi_frequency(qspi_t *obj, int hz)
730
730
#else /* OCTOSPI */
731
731
qspi_status_t qspi_frequency (qspi_t * obj , int hz )
732
732
{
733
- debug_if ( qspi_api_c_debug , "qspi_frequency hz %d\n " , hz );
733
+ tr_info ( "qspi_frequency hz %d" , hz );
734
734
qspi_status_t status = QSPI_STATUS_OK ;
735
735
736
736
/* HCLK drives QSPI. QSPI clock depends on prescaler value:
@@ -774,11 +774,11 @@ qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void
774
774
st_command .NbData = * length ;
775
775
776
776
if (HAL_OSPI_Command (& obj -> handle , & st_command , HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK ) {
777
- debug_if ( qspi_api_c_debug , "HAL_OSPI_Command error\n " );
777
+ tr_error ( "HAL_OSPI_Command error" );
778
778
status = QSPI_STATUS_ERROR ;
779
779
} else {
780
780
if (HAL_OSPI_Transmit (& obj -> handle , (uint8_t * )data , HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK ) {
781
- debug_if ( qspi_api_c_debug , "HAL_OSPI_Transmit error\n " );
781
+ tr_error ( "HAL_OSPI_Transmit error" );
782
782
status = QSPI_STATUS_ERROR ;
783
783
}
784
784
}
@@ -788,6 +788,8 @@ qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void
788
788
#else /* OCTOSPI */
789
789
qspi_status_t qspi_write (qspi_t * obj , const qspi_command_t * command , const void * data , size_t * length )
790
790
{
791
+ debug_if (qspi_api_c_debug , "qspi_write size %u\n" , * length );
792
+
791
793
QSPI_CommandTypeDef st_command ;
792
794
qspi_status_t status = qspi_prepare_command (command , & st_command );
793
795
if (status != QSPI_STATUS_OK ) {
@@ -823,11 +825,11 @@ qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data,
823
825
st_command .NbData = * length ;
824
826
825
827
if (HAL_OSPI_Command (& obj -> handle , & st_command , HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK ) {
826
- debug_if ( qspi_api_c_debug , "HAL_OSPI_Command error\n " );
828
+ tr_error ( "HAL_OSPI_Command error" );
827
829
status = QSPI_STATUS_ERROR ;
828
830
} else {
829
831
if (HAL_OSPI_Receive (& obj -> handle , data , HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK ) {
830
- debug_if ( qspi_api_c_debug , "HAL_OSPI_Receive error\n" );
832
+ tr_error ( "HAL_OSPI_Receive error %d" , obj -> handle . ErrorCode );
831
833
status = QSPI_STATUS_ERROR ;
832
834
}
833
835
}
@@ -865,7 +867,8 @@ qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data,
865
867
#if defined(OCTOSPI1 )
866
868
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 )
867
869
{
868
- debug_if (qspi_api_c_debug , "qspi_command_transfer tx %u rx %u command %x\n" , tx_size , rx_size , command -> instruction .value );
870
+ tr_info ("qspi_command_transfer tx %u rx %u command %#04x" , tx_size , rx_size , command -> instruction .value );
871
+
869
872
qspi_status_t status = QSPI_STATUS_OK ;
870
873
871
874
if ((tx_data == NULL || tx_size == 0 ) && (rx_data == NULL || rx_size == 0 )) {
@@ -880,7 +883,7 @@ qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command,
880
883
st_command .DataMode = HAL_OSPI_DATA_NONE ; /* Instruction only */
881
884
if (HAL_OSPI_Command (& obj -> handle , & st_command , HAL_OSPI_TIMEOUT_DEFAULT_VALUE ) != HAL_OK ) {
882
885
status = QSPI_STATUS_ERROR ;
883
- debug_if ( qspi_api_c_debug , "HAL_OSPI_Command error\n " );
886
+ tr_error ( "HAL_OSPI_Command error" );
884
887
return status ;
885
888
}
886
889
} else {
@@ -889,23 +892,22 @@ qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command,
889
892
size_t tx_length = tx_size ;
890
893
status = qspi_write (obj , command , tx_data , & tx_length );
891
894
if (status != QSPI_STATUS_OK ) {
892
- debug_if ( qspi_api_c_debug , "qspi_write error\n " );
895
+ tr_error ( "qspi_write error" );
893
896
return status ;
894
897
}
895
898
}
896
899
897
900
if (rx_data != NULL && rx_size ) {
898
901
size_t rx_length = rx_size ;
899
902
status = qspi_read (obj , command , rx_data , & rx_length );
900
- // debug_if(qspi_api_c_debug, "qspi_read %d\n", status);
901
903
}
902
904
}
903
905
return status ;
904
906
}
905
907
#else /* OCTOSPI */
906
908
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 )
907
909
{
908
- debug_if ( qspi_api_c_debug , "qspi_command_transfer tx %u rx %u command %x\n " , tx_size , rx_size , command -> instruction .value );
910
+ tr_info ( "qspi_command_transfer tx %u rx %u command %#04x " , tx_size , rx_size , command -> instruction .value );
909
911
qspi_status_t status = QSPI_STATUS_OK ;
910
912
911
913
if ((tx_data == NULL || tx_size == 0 ) && (rx_data == NULL || rx_size == 0 )) {
0 commit comments