@@ -49,9 +49,9 @@ using namespace mbed;
49
49
#define SPINAND_STATUS_BIT_ERASE_FAIL 0x4 // Erase failed
50
50
#define SPINAND_STATUS_BIT_PROGRAM_FAIL 0x8 // Program failed
51
51
#define SPINAND_STATUS_BIT_ECC_STATUS_MASK 0x30 // ECC status
52
- #define SPINAND_STATUS_ECC_STATUS_NO_ERR 0x00
53
- #define SPINAND_STATUS_ECC_STATUS_ERR_COR 0x00
54
- #define SPINAND_STATUS_ECC_STATUS_ERR_NO_COR 0x00
52
+ #define SPINAND_STATUS_ECC_STATUS_NO_ERR 0x00
53
+ #define SPINAND_STATUS_ECC_STATUS_ERR_COR 0x00
54
+ #define SPINAND_STATUS_ECC_STATUS_ERR_NO_COR 0x00
55
55
56
56
// Secure OTP Register Bits
57
57
#define SPINAND_SECURE_BIT_QE 0x01 // Quad enable
@@ -61,12 +61,12 @@ using namespace mbed;
61
61
62
62
// Block Protection Register Bits
63
63
#define SPINAND_BLOCK_PROT_BIT_SP 0x01
64
- #define SPINAND_BLOCK_PROT_BIT_COMPLE 0x02
64
+ #define SPINAND_BLOCK_PROT_BIT_COMPLE 0x02
65
65
#define SPINAND_BLOCK_PROT_BIT_INVERT 0x04
66
- #define SPINAND_BLOCK_PROT_BIT_BP0 0x08
67
- #define SPINAND_BLOCK_PROT_BIT_BP1 0x10
68
- #define SPINAND_BLOCK_PROT_BIT_BP2 0x20
69
- #define SPINAND_BLOCK_PROT_BIT_BPRWD 0x80
66
+ #define SPINAND_BLOCK_PROT_BIT_BP0 0x08
67
+ #define SPINAND_BLOCK_PROT_BIT_BP1 0x10
68
+ #define SPINAND_BLOCK_PROT_BIT_BP2 0x20
69
+ #define SPINAND_BLOCK_PROT_BIT_BPRWD 0x80
70
70
#define SPINAND_BLOCK_PROT_BIT_BP_MASK 0x38
71
71
72
72
#define SPINAND_BLOCK_PROT_BP_OFFSET 3
@@ -209,7 +209,7 @@ int SPINANDBlockDevice::init()
209
209
}
210
210
211
211
if (_read_instruction == SPINAND_INST_READ_CACHE4) {
212
- if (QSPI_STATUS_OK !=_set_quad_enable ()) {
212
+ if (QSPI_STATUS_OK != _set_quad_enable ()) {
213
213
tr_error (" SPI NAND Set Quad enable Failed" );
214
214
status = SPINAND_BD_ERROR_DEVICE_ERROR;
215
215
goto exit_point;
@@ -269,7 +269,7 @@ int SPINANDBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
269
269
bd_size_t read_bytes = 0 ;
270
270
271
271
tr_debug (" Read Inst: 0x%xh" , _read_instruction);
272
-
272
+
273
273
while (size > 0 ) {
274
274
// Read on _page_size_bytes boundaries (Default 2048 bytes a page)
275
275
offset = addr % MBED_CONF_SPINAND_SPINAND_PAGE_SIZE;
@@ -385,7 +385,7 @@ int SPINANDBlockDevice::erase(bd_addr_t addr, bd_size_t size)
385
385
}
386
386
387
387
addr += SPINAND_BLOCK_OFFSET;
388
- if (size > MBED_CONF_SPINAND_SPINAND_BLOCK_SIZE) {
388
+ if (size > MBED_CONF_SPINAND_SPINAND_BLOCK_SIZE) {
389
389
size -= MBED_CONF_SPINAND_SPINAND_BLOCK_SIZE;
390
390
} else {
391
391
size = 0 ;
@@ -519,19 +519,19 @@ int SPINANDBlockDevice::_set_quad_enable()
519
519
520
520
if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_GET_FEATURE, FEATURES_ADDR_SECURE_OTP,
521
521
NULL , 0 , (char *) &secur_reg, 1 )) {
522
- tr_error (" Reading Security Register failed" );
523
- }
522
+ tr_error (" Reading Security Register failed" );
523
+ }
524
524
525
525
secur_reg |= SPINAND_SECURE_BIT_QE;
526
526
527
527
if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_SET_FEATURE, FEATURES_ADDR_SECURE_OTP,
528
528
(char *) &secur_reg, 1 , NULL , 0 )) {
529
- tr_error (" Writing Security Register failed" );
530
- }
529
+ tr_error (" Writing Security Register failed" );
530
+ }
531
531
if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_GET_FEATURE, FEATURES_ADDR_SECURE_OTP,
532
532
NULL , 0 , (char *) &secur_reg, 1 )) {
533
- tr_error (" Reading Security Register failed" );
534
- }
533
+ tr_error (" Reading Security Register failed" );
534
+ }
535
535
if (false == _is_mem_ready ()) {
536
536
tr_error (" Device not ready, set quad enable failed" );
537
537
return -1 ;
@@ -551,19 +551,19 @@ int SPINANDBlockDevice::_clear_block_protection()
551
551
552
552
if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_GET_FEATURE, FEATURES_ADDR_BLOCK_PROTECTION,
553
553
NULL , 0 , (char *) &block_protection_reg, 1 )) {
554
- tr_error (" Reading Block Protection Register failed" );
555
- }
554
+ tr_error (" Reading Block Protection Register failed" );
555
+ }
556
556
557
557
block_protection_reg &= ~SPINAND_BLOCK_PROT_BIT_BP_MASK;
558
558
559
559
if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_SET_FEATURE, FEATURES_ADDR_BLOCK_PROTECTION,
560
560
(char *) &block_protection_reg, 1 , NULL , 0 )) {
561
- tr_error (" Writing Block Protection Register failed" );
562
- }
561
+ tr_error (" Writing Block Protection Register failed" );
562
+ }
563
563
if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_GET_FEATURE, FEATURES_ADDR_BLOCK_PROTECTION,
564
564
NULL , 0 , (char *) &block_protection_reg, 1 )) {
565
- tr_error (" Reading Block Protection Register failed" );
566
- }
565
+ tr_error (" Reading Block Protection Register failed" );
566
+ }
567
567
if (false == _is_mem_ready ()) {
568
568
tr_error (" Device not ready, clearing block protection failed" );
569
569
return -1 ;
@@ -588,7 +588,7 @@ int SPINANDBlockDevice::_set_write_enable()
588
588
tr_error (" Device not ready, write failed" );
589
589
break ;
590
590
}
591
-
591
+
592
592
if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_GET_FEATURE, FEATURES_ADDR_STATUS,
593
593
NULL , 0 ,
594
594
(char *) &status_value, 1 )) { // store received value in status_value
@@ -612,7 +612,7 @@ bool SPINANDBlockDevice::_is_mem_ready()
612
612
uint8_t status_value = 0 ;
613
613
int retries = 0 ;
614
614
bool mem_ready = true ;
615
-
615
+
616
616
do {
617
617
rtos::ThisThread::sleep_for (1ms);
618
618
retries++;
@@ -649,7 +649,7 @@ qspi_status_t SPINANDBlockDevice::_qspi_send_read_command(qspi_inst_t read_inst,
649
649
// Send read command to device driver
650
650
// Read commands use the best bus mode supported by the part
651
651
qspi_status_t status = _qspi.configure_format (_inst_width, _address_width, SPI_NAND_COLUMN_ADDR_SIZE, // Alt width should be the same as address width
652
- _address_width,_alt_size, _data_width, 0 );
652
+ _address_width, _alt_size, _data_width, 0 );
653
653
if (QSPI_STATUS_OK != status) {
654
654
tr_error (" _qspi_configure_format failed" );
655
655
return status;
@@ -668,7 +668,7 @@ qspi_status_t SPINANDBlockDevice::_qspi_send_read_command(qspi_inst_t read_inst,
668
668
669
669
if (false == _is_mem_ready ()) {
670
670
tr_error (" Device not ready, clearing block protection failed" );
671
- // return -1;
671
+ return -1 ;
672
672
}
673
673
674
674
status = _qspi.configure_format (_inst_width, _address_width, SPI_NAND_ROW_ADDR_SIZE, _address_width, // Alt width should be the same as address width
@@ -701,7 +701,7 @@ qspi_status_t SPINANDBlockDevice::_qspi_send_program_command(qspi_inst_t prog_in
701
701
bd_addr_t addr, bd_size_t *size)
702
702
{
703
703
tr_debug (" Inst: 0x%xh, addr: %llu, size: %llu" , prog_inst, addr, *size);
704
-
704
+
705
705
// Program load commands need 16 bit row address
706
706
qspi_status_t status = _qspi.configure_format (_inst_width, _address_width, SPI_NAND_ROW_ADDR_SIZE, // Alt width should be the same as address width
707
707
_address_width, _alt_size, QSPI_CFG_BUS_QUAD, 0 );
@@ -725,7 +725,7 @@ qspi_status_t SPINANDBlockDevice::_qspi_send_program_command(qspi_inst_t prog_in
725
725
return format_status;
726
726
}
727
727
728
- // Program execute command
728
+ // Program execute command
729
729
if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_PROGRAM_EXEC, addr >> 12 , NULL , 0 , NULL , 0 )) {
730
730
tr_error (" Read page from array failed" );
731
731
}
@@ -737,18 +737,18 @@ qspi_status_t SPINANDBlockDevice::_qspi_send_program_command(qspi_inst_t prog_in
737
737
return status;
738
738
}
739
739
uint8_t status_value = 0 ;
740
- if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_GET_FEATURE, FEATURES_ADDR_STATUS,
741
- NULL , 0 ,
742
- (char *) &status_value, 1 )) { // store received value in status_value
743
- tr_error (" Reading Status Register failed" );
744
- }
740
+ if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_GET_FEATURE, FEATURES_ADDR_STATUS,
741
+ NULL , 0 ,
742
+ (char *) &status_value, 1 )) { // store received value in status_value
743
+ tr_error (" Reading Status Register failed" );
744
+ }
745
745
return QSPI_STATUS_OK;
746
746
}
747
747
748
748
qspi_status_t SPINANDBlockDevice::_qspi_send_erase_command (qspi_inst_t erase_inst, bd_addr_t addr, bd_size_t size)
749
749
{
750
750
tr_debug (" Inst: 0x%xh, addr: %llu, size: %llu" , erase_inst, addr, size);
751
-
751
+
752
752
qspi_status_t status = _qspi.configure_format (_inst_width, _address_width, SPI_NAND_COLUMN_ADDR_SIZE,// Alt width should be the same as address width
753
753
_address_width, _alt_size, _data_width, 0 );
754
754
if (QSPI_STATUS_OK != status) {
@@ -757,7 +757,7 @@ qspi_status_t SPINANDBlockDevice::_qspi_send_erase_command(qspi_inst_t erase_ins
757
757
}
758
758
759
759
// Send erase command to driver
760
- status = _qspi.command_transfer (erase_inst, (int ) (addr >> 12 ), NULL , 0 , NULL , 0 );
760
+ status = _qspi.command_transfer (erase_inst, (int )(addr >> 12 ), NULL , 0 , NULL , 0 );
761
761
762
762
if (QSPI_STATUS_OK != status) {
763
763
tr_error (" QSPI Erase failed" );
@@ -771,11 +771,11 @@ qspi_status_t SPINANDBlockDevice::_qspi_send_erase_command(qspi_inst_t erase_ins
771
771
return status;
772
772
}
773
773
uint8_t status_value = 0 ;
774
- if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_GET_FEATURE, FEATURES_ADDR_STATUS,
775
- NULL , 0 ,
776
- (char *) &status_value, 1 )) { // store received value in status_value
777
- tr_error (" Reading Status Register failed" );
778
- }
774
+ if (QSPI_STATUS_OK != _qspi_send_general_command (SPINAND_INST_GET_FEATURE, FEATURES_ADDR_STATUS,
775
+ NULL , 0 ,
776
+ (char *) &status_value, 1 )) { // store received value in status_value
777
+ tr_error (" Reading Status Register failed" );
778
+ }
779
779
return QSPI_STATUS_OK;
780
780
}
781
781
0 commit comments